Beispiel #1
0
        public void OnInit(DictionaryAtom initAtom)
        {
            try
            {
                NinjectKernel = initAtom.GetObject("Ninject.Kernel").CastAs <IKernel>();
                initAtom.Set("Logger", Logger);
                InitBooleanSet = new BooleanSet("OnGameInitialize", Game_OnInitializationComplete);

                NinjectKernel.Load(_ninjectGameModules.Select(
                                       moduleType => (NinjectGameModule)Activator.CreateInstance(moduleType, initAtom, InitBooleanSet)));

                EventMgr  = (EventManager)NinjectKernel.Get <IEventManager>();
                LuaMgr    = (LuaManager)NinjectKernel.Get <ILuaManager>();
                DbMgr     = (DatabaseManager)NinjectKernel.Get <IDatabaseManager>();
                StaticMgr = (StaticDataManager)NinjectKernel.Get <IStaticDataManager>();
                EntityMgr = (EntityManager)NinjectKernel.Get <IEntityManager>();
                EntityMgr.EntityInitializer.RegisterEntityTypes(_entityTypes);
                ChannelMgr = (ChannelManager)NinjectKernel.Get <IChannelManager>();
                CmdMgr     = (CommandManager)NinjectKernel.Get <ICommandManager>();
                PathMgr    = (PathManager)NinjectKernel.Get <IPathManager>();
                TimeMgr    = (TimeManager)NinjectKernel.Get <ITimeManager>();
                NetMgr     = (NetworkManager)NinjectKernel.Get <INetworkManager>();
                // todo DataManager?
                // todo CombatManager ?
                LoopProcessor = (GameLoopProcessor)NinjectKernel.Get <ILoopProcessor>();

                Contexts = new List <IContext> {
                    new PropertyContext(this)
                };

                // Everything that needs early initialization done before this line
                // Now, lets begin regular setup (this will include game data)
                Logger.Debug("Completed initialization of Managers, throwing OnGameInitialize event.");
                EventMgr.ThrowEvent <OnGameInitialize>(this, new EventTable
                {
                    { "BooleanSet", InitBooleanSet },
                    { "InitAtom", initAtom }
                });
            }
            catch (Exception ex)
            {
                ex.Handle <InitializationException>(ExceptionHandlingOptions.RecordAndThrow, Logger);
            }
        }
Beispiel #2
0
        private void DoStartup(StartupEventArgs e)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(GetBasePath())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);

            var configuration = builder.Build();

            var logLevel  = configuration.GetSection(nameof(LogLevel));
            var logLevels = logLevel
                            .GetChildren()
                            .ToDictionary(cs => cs.Key, cs => LogLevel.FromString(cs.Value));

            RVis.Base.Logging.Configure(logLevels);

            var rvisUI = configuration.GetSection(nameof(RVisUI));

            RVisUI.MainWindow.ShowFrameRate = rvisUI.GetValue <bool>(
                nameof(RVisUI.MainWindow.ShowFrameRate)
                );
            DocRoot = rvisUI.GetValue <string>(
                nameof(DocRoot)
                );

            var doSaveSettings = false;

            if (Settings.Default.UpgradeRequired)
            {
                Settings.Default.Upgrade();
                Settings.Default.UpgradeRequired = false;
                doSaveSettings = true; // TODO: do it here?
            }

            Settings.Default.ApplyTheme();

            if (0 == Settings.Default.RThrottlingUseCores)
            {
                Settings.Default.RThrottlingUseCores = Environment.ProcessorCount - 1;
                doSaveSettings = true;
            }

            if (doSaveSettings)
            {
                Settings.Default.Save();
            }

            NinjectKernel.Load(new AppModule());

            ViewModelLocator.SubscribeToServiceTypes(
                GetType().Assembly,
                $"{nameof(RVisUI)}.{nameof(Ioc)}.{nameof(Mvvm)}"
                );

            ConfigureDiagnostics();

            Exit += HandleExit;

            AppService.Initialize();

            var appState = new AppState(AppSettings, AppService);

            NinjectKernel.Bind <IAppState>().ToConstant(appState);

            try
            {
                appState.Initialize(e.Args);
            }
            catch (Exception ex)
            {
                AppService.Notify(
                    nameof(AppState),
                    "Start-up",
                    ex
                    );
                Log.Error(ex);
                Shutdown(1);
            }
        }