Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Runs SGL based on the specific initialized options.
        /// </summary>
        /// <param name="engineConfiguration">The EngineConfiguration.</param>
        private static void Run(EngineConfiguration engineConfiguration)
        {
            Components.Add(engineConfiguration);
            GraphicsManager           = engineConfiguration.GraphicsManager;
            GameInstance.AudioManager = new AudioManager(engineConfiguration.AudioInitializer);
            Components.Add(GameInstance.AudioManager);
            Components.Construct();
            Components.Get <GameLoop>().Start();

            Logger.Engine("SGL ({0}) is sucessfully running.", Version);

            State = EngineState.Running;
        }