Пример #1
0
        public static GameRunner GetGameRunner(IContainer container, IConfigSection config, bool bootstrap = true)
        {
            // this three service should be registered before game runner is started
            container.Register(Component.For <ITrace>().Use <ConsoleTrace>().Singleton());
            container.Register(Component.For <IPathResolver>().Use <TestPathResolver>().Singleton());
            container.Register(Component.For <IMessageBus>().Use <MessageBus>().Singleton());
            container.Register(Component.For <IFileSystemService>().Use <FileSystemService>().Singleton());

            var runner = new GameRunner(container, config)
                         .RegisterPlugin <TestBootstrapperPlugin>("test");

            return(bootstrap ? runner.Bootstrap() : runner);
        }
Пример #2
0
        void OnEnable()
        {
            Assert.raiseExceptions = true;

            Centre = new GeoCoordinate(CentreLatitude, CentreLongitude);

            Scheduler.MainThread = UnityMainThreadScheduler.MainThread;

            m_container  = new Container();
            m_messageBus = new MessageBus();
            m_trace      = new UnityTrace();

            UnityMainThreadDispatcher.RegisterUnhandledExceptionCallback(
                ex => m_trace.Error("Fatal", ex, "Unhandled exception"));

            m_container.RegisterInstance(this);
            m_container.RegisterInstance(new MapGenTileExporter(this));
            m_container.RegisterInstance <ITrace>(m_trace);
            m_container.RegisterInstance <IPathResolver>(new PathResolver());
            m_container.RegisterInstance(m_messageBus);
            m_container.Register(Component.For <IFileSystemService>().Use <FileSystemService>().Singleton());

            Config = ConfigBuilder.GetDefault()
                     .SetTileSettings(TileSize, 40)
                     .SetRenderOptions(
                RenderMode.Scene,
                new Rectangle2d(0, 0, TileSize, TileSize))
                     .Build();

            m_gameRunner = new GameRunner(m_container, Config);
            m_gameRunner.RegisterPlugin <MapGenBootstrapper>("mapgen", this);
            m_gameRunner.Bootstrap();

            Observable.Start(
                () => {
                m_tileController = GetService <ITileController>();
                m_gameRunner.RunGame(Centre);
                IsInitialized = true;
            },
                Scheduler.ThreadPool);
        }