Наследование: IComponent
Пример #1
0
        /// <summary>
        /// Initializes SGL.
        /// </summary>
        /// <param name="configurator">The Configurator.</param>
        public static void Initialize(IConfigurator configurator)
        {
            if (State != EngineState.NotInitialized)
            {
                return;
            }

            State        = EngineState.Initializing;
            Components   = new ComponentManager();
            GameInstance = configurator.GameInstance;
            Components.Add(configurator.RenderTarget);
            GraphicsDevice = new GraphicsDevice(configurator.RenderTarget)
            {
                BackBuffer = configurator.BackBuffer,
                ClearColor = Color.CornflowerBlue
            };
            configurator.RenderTarget.Window.Size = new Vector2(configurator.BackBuffer.Width,
                                                                configurator.BackBuffer.Height);
            var gameLoop = new GameLoop {
                TargetTime = 1000 / (float)configurator.TargetFrameRate
            };

            Components.Add(gameLoop);
            GameInstance.Input         = new InputManager();
            GameInstance.Content       = new ContentManager();
            GameInstance.SceneManager  = new SceneManager();
            GraphicsDevice.RefreshRate = configurator.TargetFrameRate;
            Components.Add(GameInstance.Content);
            Components.Add(GraphicsDevice);
            Components.Add(GameInstance);
            Components.Add(GameInstance.SceneManager);
            Components.Add(GameInstance.Input);
            Components.Get <GameLoop>().Subscribe((IDrawable)GameInstance);
            Components.Get <GameLoop>().Subscribe((IUpdateable)GameInstance);
            Components.Get <GameLoop>().Subscribe(GameInstance.Input);

            //prepare game services
            var gameServices = new GameServiceContainer();

            gameServices.Add(new AchievementProvider());
            gameServices.Add(new Gamer());
            gameServices.Add(new LaunchParameters());

            GameInstance.GameServices = gameServices;

            Components.Add(new ExceptionHandler());

            EngineConfiguration engineConfiguration =
                GameInstance.OnInitialize(GameInstance.GameServices.GetService <LaunchParameters>());

            State = EngineState.Initialized;
            Run(engineConfiguration);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new DebugDisplay class.
        /// </summary>
        /// <param name="entityComposer">The EntityComposer.</param>
        public DebugDisplay(EntityComposer entityComposer)
        {
            _currentEntityComposer = entityComposer;
            _gameLoop = SGL.QueryComponents<GameLoop>();

            _font = new Font("Segoe UI", 12, TypefaceStyle.Regular);
            _cpuWatcher = new CpuWatcher();
            _memoryWatcher = new MemoryWatcher();
            _threadWatcher = new ThreadWatcher();
            _display = new Rectangle(0, 0, 800, 480);
            _debugMessage = "Query information ...";
            _pen = new Pen(Color.Green, 1);
            _pen2 = new Pen(Color.Red, 1);
            _pen3 = new Pen(Color.Blue, 1);

            _cpuWatcher.Start();
            _memoryWatcher.Start();
            _threadWatcher.Start();
        }