예제 #1
0
        /// <summary>
        /// Creates a new Director instance using the specified Game.
        /// </summary>
        /// <param name="game">Game instance for the Director to use.</param>
        /// <param name="preferredResolution">Preferred resolution for game graphics.</param>
        /// <remarks>Protected to prevent instantiating Director instances outside of the static SharedDirector property.</remarks>
        protected Director(Game game, Vector2 preferredResolution)
            : base(game)
        {
            if (preferredResolution == null)
            {
                throw new ArgumentNullException("defaultResolution");
            }

            PreferredResolution = preferredResolution;
            DisplaySize = preferredResolution;
            DisplayCenter = new Vector2(DisplaySize.X / 2.0f, DisplaySize.Y / 2.0f);
            ResolutionIndependent = false;
            TransformationMatrix = new Matrix();

            EntityWorld = new EntityWorld(game);
            RenderSystem renderSystem = EntityWorld.SystemManager.SetSystem<RenderSystem>(new RenderSystem(), SystemExecutionType.Draw);
            AnimationSystem animationSystem = EntityWorld.SystemManager.SetSystem<AnimationSystem>(new AnimationSystem(), SystemExecutionType.Update);
            MovementSystem movementSystem = EntityWorld.SystemManager.SetSystem<MovementSystem>(new MovementSystem(), SystemExecutionType.Update);
            ControlSystem controlSystem = EntityWorld.SystemManager.SetSystem<ControlSystem>(new ControlSystem(), SystemExecutionType.Update);

            MessageBoard = new MessageBoard(game);
            GameStateManager = new GameStateManager(game.Services);
            InputManager = new InputManager(game.Services);
            InputBindingManager = new InputBindingManager(game);
            TextureManager = new TextureManager(game.Content);
            FontManager = new FontManager(game.Content);
            GuiManager = new GuiManager(game.Services);

            game.Components.Add(EntityWorld);
            game.Components.Add(MessageBoard);
            game.Components.Add(InputManager);
            game.Components.Add(InputBindingManager);

            game.Services.AddService(typeof(IEntityWorld), EntityWorld);
            game.Services.AddService(typeof(IMessageBoard), MessageBoard);
            game.Services.AddService(typeof(IInputBindingManager), InputBindingManager);
            game.Services.AddService(typeof(ITextureManager), TextureManager);
            game.Services.AddService(typeof(IFontManager), FontManager);
            #if DEBUG
            DebugDisplay = new DebugDisplay(game);
            game.Components.Add(DebugDisplay);
            game.Services.AddService(typeof(IDebugDisplay), DebugDisplay);
            #endif
        }
예제 #2
0
        /// <summary>
        /// Creates a new Director instance using the specified Game.
        /// </summary>
        /// <param name="game">Game instance for the Director to use.</param>
        /// <param name="preferredResolution">Preferred resolution for game graphics.</param>
        /// <remarks>Protected to prevent instantiating Director instances outside of the static SharedDirector property.</remarks>
        protected Director(Game game, Vector2 preferredResolution)
            : base(game)
        {
            if (preferredResolution == null)
            {
                throw new ArgumentNullException("defaultResolution");
            }

            PreferredResolution   = preferredResolution;
            DisplaySize           = preferredResolution;
            DisplayCenter         = new Vector2(DisplaySize.X / 2.0f, DisplaySize.Y / 2.0f);
            ResolutionIndependent = false;
            TransformationMatrix  = new Matrix();

            EntityWorld = new EntityWorld(game);
            RenderSystem    renderSystem    = EntityWorld.SystemManager.SetSystem <RenderSystem>(new RenderSystem(), SystemExecutionType.Draw);
            AnimationSystem animationSystem = EntityWorld.SystemManager.SetSystem <AnimationSystem>(new AnimationSystem(), SystemExecutionType.Update);
            MovementSystem  movementSystem  = EntityWorld.SystemManager.SetSystem <MovementSystem>(new MovementSystem(), SystemExecutionType.Update);
            ControlSystem   controlSystem   = EntityWorld.SystemManager.SetSystem <ControlSystem>(new ControlSystem(), SystemExecutionType.Update);

            MessageBoard        = new MessageBoard(game);
            GameStateManager    = new GameStateManager(game.Services);
            InputManager        = new InputManager(game.Services);
            InputBindingManager = new InputBindingManager(game);
            TextureManager      = new TextureManager(game.Content);
            FontManager         = new FontManager(game.Content);
            GuiManager          = new GuiManager(game.Services);

            game.Components.Add(EntityWorld);
            game.Components.Add(MessageBoard);
            game.Components.Add(InputManager);
            game.Components.Add(InputBindingManager);

            game.Services.AddService(typeof(IEntityWorld), EntityWorld);
            game.Services.AddService(typeof(IMessageBoard), MessageBoard);
            game.Services.AddService(typeof(IInputBindingManager), InputBindingManager);
            game.Services.AddService(typeof(ITextureManager), TextureManager);
            game.Services.AddService(typeof(IFontManager), FontManager);
#if DEBUG
            DebugDisplay = new DebugDisplay(game);
            game.Components.Add(DebugDisplay);
            game.Services.AddService(typeof(IDebugDisplay), DebugDisplay);
#endif
        }