protected override void LoadContent()
        {
            // Adds services to global container, easy access
            serviceContainer.AddService(GraphicsDevice);
            serviceContainer.AddService(Content);

            // New BackgroundManager
            bm = new BackgroundManager();

            // New Random
            Random r = new Random();

            // Generates tiles with a random meta on the entire game screen
            for (byte x = 0; x < (GraphicsDevice.Viewport.Width / 32); x++)
            {
                for (byte y = 0; y < (GraphicsDevice.Viewport.Height / 32); y++)
                {
                    bm.AddTile(x, y, r.Next(0, 4));
                }
            }

            // New Entity Manager
            em = new EntityManager();
            em.SpawnPlayer(new Vector2(10, 10), 2.5f);


            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
Beispiel #2
0
        protected override void Initialize()
        {
            IsFixedTimeStep = true;
            IsMouseVisible  = false;

            GameSettings.Initialize(Graphics, Game.VirtualResolution);

            var Services = new GameServiceContainer();

            Services.AddService(typeof(IGraphicsDeviceService), Graphics);
            Services.AddService(typeof(ISkipContent), this);

            InputProvider = new UserInputProvider();
            StackEngine   = new StackEngine(Game, Services, InputProvider, GameSettings);

            if (GameSettings.Debug)
            {
                InputProvider.Handler += HandleDebugInputEvent;
            }

            InputProvider.Handler += HandleSkipInputEvent;

            StackEngine.OnExit += Exit;

            Counter = new FrameRateCounter();
            SetSpeed(GameSpeed.Default);

            base.Initialize();
        }
Beispiel #3
0
        //=============================

        public void Initialize(IGraphicsDeviceService graphics)
        {
            Graphics = graphics.GraphicsDevice;
            Content  = new ContentManager(container, "Content");
            //
            container.AddService(typeof(IGraphicsDeviceService), graphics);
            container.AddService(typeof(ContentManager), Content);
        }
Beispiel #4
0
        internal XNAWinFormsHostAppWrapper(XNALogic logic, Application parent, WinFormsHostControl host)
        {
            this.parent = parent;
            this.logic  = logic;

            this.control = host;

            System.Windows.Forms.Control parentControl = this.control;
            while (parentControl != null)
            {
                if (parentControl is System.Windows.Forms.Form)
                {
                    this.parentForm = (System.Windows.Forms.Form)parentControl;
                    break;
                }
                parentControl = parentControl.Parent;
            }
            if (parentForm == null)
            {
                throw new ArgumentException("Unable to find Parent Form for display handle");
            }

            parentForm.MouseWheel += new System.Windows.Forms.MouseEventHandler(parentControl_MouseWheel);
            parentForm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(parentForm_FormClosed);

            formsDeviceService = new WinFormsHostGraphicsDeviceService(this, this.control.ClientSize.Width, this.control.ClientSize.Height);

            services = new GameServiceContainer();
            services.AddService(typeof(IGraphicsDeviceService), formsDeviceService);
            services.AddService(typeof(IGraphicsDeviceManager), formsDeviceService);

            presentation = RenderTargetUsage.PlatformContents;
            content      = new ContentManager(services);

            int           width  = 0;
            int           height = 0;
            SurfaceFormat format = SurfaceFormat.Color;

            width  = control.ClientSize.Width;
            height = control.ClientSize.Height;

            parent.SetWindowSizeAndFormat(width, height, format, DepthFormat.Depth24Stencil8);

            parent.SetupGraphicsDeviceManager(null, ref presentation);

            formsDeviceService.CreateDevice(presentation, host);

            host.SetApplication(parent, this, formsDeviceService);

            host.BeginInvoke((EventHandler) delegate
            {
                parent.SetGraphicsDevice(GraphicsDevice);
                logic.Initialise();
                logic.LoadContent();
            });
        }
        public void AddServiceAndGetServiceTest()
        {
            string s = "Hello";

            services.AddService(typeof(string), s);

            string s2 = (string)services.GetService(typeof(string));

            Assert.AreSame(s, s2, "Service was not correctly added");
        }
Beispiel #6
0
        /// <summary>
        /// Initializes the services.
        /// </summary>
        private void InitializeServices(GameServiceContainer services)
        {
            AlmiranteEngine.ResourceContents = new ResourceContentManager(services, "Content");
            services.AddService(typeof(ResourceContentManager), AlmiranteEngine.ResourceContents);

            AlmiranteEngine.Time = new TimeManager();
            services.AddService(typeof(TimeManager), AlmiranteEngine.Time);

            AlmiranteEngine.Camera = new CameraManager();
            services.AddService(typeof(CameraManager), AlmiranteEngine.Camera);

            AlmiranteEngine.Audio = new AudioManager();
            services.AddService(typeof(AudioManager), AlmiranteEngine.Audio);

            if (!windows)
            {
                AlmiranteEngine.DeviceManager = new GraphicsDeviceManager(Application);
                services.AddService(typeof(GraphicsDeviceManager), AlmiranteEngine.DeviceManager);
            }

            AlmiranteEngine.Settings = new Settings();
            services.AddService(typeof(Settings), AlmiranteEngine.Settings);

            AlmiranteEngine.Resources = new ResourceManager(AlmiranteEngine.ResourceContents);
            services.AddService(typeof(ResourceManager), AlmiranteEngine.Resources);

            AlmiranteEngine.Input = new InputManager();
            services.AddService(typeof(InputManager), AlmiranteEngine.Input);

            AlmiranteEngine.Scenes = new SceneManager();
            services.AddService(typeof(SceneManager), AlmiranteEngine.Scenes);

            this.InitializeExports();
        }
Beispiel #7
0
        public void TestInitialization()
        {
            var gameServices = new GameServiceContainer();

            gameServices.AddService(
                typeof(IGraphicsDeviceService), this.mockedGraphicsDeviceService
                );
            gameServices.AddService(
                typeof(IInputService), this.mockedInputService
                );

            using (GuiManager guiManager = new GuiManager(gameServices)) {
                (guiManager as IGameComponent).Initialize();
            }
        }
        public static void LoadEditorContent()
        {
            //Start by creating a MonoGame Content Manager
            //We create a dummy game service so we can load up a content manager.
            var container = new GameServiceContainer();

            container.AddService(
                typeof(IGraphicsDeviceService), new DummyGraphicsDeviceManager(Core.Graphics.GetGraphicsDevice())
                );

            sContentManger = new ContentManager(container, "");
            LoadEntities();
            LoadSpells();
            LoadAnimations();
            LoadImages();
            LoadFogs();
            LoadResources();
            LoadPaperdolls();
            LoadGui();
            LoadFaces();
            LoadItems();
            LoadMisc();
            LoadShaders();
            LoadSounds();
            LoadMusic();
        }
 /// <summary>
 /// Adds an object of a type to the container.
 /// </summary>
 /// <typeparam name="T">The type of the object that needs to be added.</typeparam>
 /// <param name="service">The object to add.</param>
 public static void Add <T>(T service)
 {
     if (_container.GetService(typeof(T)) == null)
     {
         _container.AddService(typeof(T), service);
     }
 }
Beispiel #10
0
        private void InitializeGFX(IGraphicsDeviceService graphics)
        {
            services = new GameServiceContainer();
            services.AddService <IGraphicsDeviceService>(graphics);
            this.graphics = graphics.GraphicsDevice;

            Content     = new ContentManager(services, "Content");
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            Pixel = new Texture2D(graphics.GraphicsDevice, 1, 1);
            Pixel.SetData(new[] { Color.White });

            Format = new System.Globalization.NumberFormatInfo();
            Format.CurrencyDecimalSeparator = ".";

            Cam          = new Camera2D();
            Cam.Position = new Vector2(
                graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);
#if DX
            InternContent = new ResourceContentManager(services, DX.Properties.Resources.ResourceManager);

            GetRenderTargetManager  = new RenderTargetManager(this);
            AntialisingRenderTarget = GetRenderTargetManager.CreateNewRenderTarget2D("MSAA", true);

            RenderTargetTimer          = new Timer();
            RenderTargetTimer.Interval = 500;
            RenderTargetTimer.Elapsed += (sender, e) => OnRenderTargetTimeOutEnd();
#elif GL
            InternContent = new ResourceContentManager(services, GL.Properties.Resources.ResourceManager);
#endif
            Font       = InternContent.Load <SpriteFont>("Font");
            FontHeight = Font.MeasureString("A").Y;

            FrameworkDispatcher.Update();
        }
Beispiel #11
0
        public virtual void Initialize(IGraphicsDeviceService deviceSvc)
        {
            graphicsDevice = deviceSvc.GraphicsDevice;
            Services.AddService(typeof(IGraphicsDeviceService), deviceSvc);
            deviceSvc.DeviceReset += new EventHandler <EventArgs>(deviceSvc_DeviceReset);

            content = new Gnomic.Core.ContentTracker(Services);
            Content.RootDirectory = "Content";
#if WINDOWS
            ((Gnomic.Core.ContentTracker)content).UseSourceAssets = true;
#endif

            audio = new AudioManager(Content);

            spriteBatch = new SpriteBatch(graphicsDevice);

            Input.Initialize(graphicsDevice);

            foreach (GameScreen gs in this.ActiveScreens)
            {
                if (!gs.IsInitialized)
                {
                    gs.Initialize(this);
                }
            }
        }
Beispiel #12
0
        /// <summary>Initializes a new shared content manager</summary>
        /// <param name="gameServices">
        ///   Game service container to use for accessing other game components
        ///   like the graphics device service. The shared content manager also
        ///   registers itself (under <see cref="ISharedContentService" />) herein.
        /// </param>
        public SharedContentManager(GameServiceContainer gameServices)
        {
            this.serviceProvider = gameServices;

            // Register ourselfes as the shared content service for the game to allow
            // other component to access the assets managed by us.
            gameServices.AddService(typeof(ISharedContentService), this);
        }
Beispiel #13
0
        /// <summary>
        /// Initialisation de XNA et du SharedGraphicsManager
        /// </summary>
        private void InitializeXNA()
        {
            Services = new GameServiceContainer();
            Services.AddService(typeof(IGraphicsDeviceService), new SharedGraphicsDeviceManager());

            Content = new ContentManager(Services);
            Content.RootDirectory = "Content";
        }
Beispiel #14
0
 public static void Add <T>(T Service)
 {
     if (Container == null)
     {
         Container = new GameServiceContainer();
     }
     Container.AddService(typeof(T), Service);
 }
            /// <summary>
            ///   Creates a new game service container containing the specified graphics device
            ///   service only.
            /// </summary>
            /// <param name="graphicsDeviceService">Service to add to the service container</param>
            /// <returns>A service container with the specified graphics device service</returns>
            private static IServiceProvider makePrivateServiceContainer(
                IGraphicsDeviceService graphicsDeviceService
                )
            {
                GameServiceContainer gameServices = new GameServiceContainer();

                gameServices.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService);
                return(gameServices);
            }
        public EditorHostGame(ICoreGame coreGame, ISharedRendererClientFactory sharedRendererClientFactory)
        {
            _coreGame         = coreGame;
            _serviceContainer = new GameServiceContainer();

            _graphicsDeviceService = new EditorGraphicsDeviceService(sharedRendererClientFactory);
            _serviceContainer.AddService <IGraphicsDeviceService>(_graphicsDeviceService);
            _editorGameWindow = new EditorGameWindow(this);
            _contentManager   = new ContentManager(_serviceContainer, "Content");
        }
Beispiel #17
0
        /// <summary>Initializes a new game state manager</summary>
        /// <param name="gameServices">
        ///   Services container the game state manager will add itself to
        /// </param>
        public GameStateManager(GameServiceContainer gameServices) :
            base(gameServices)
        {
            this.gameServices     = gameServices;
            this.activeGameStates = new Stack <GameState>();

            // Register ourselves as a service
            gameServices.AddService(typeof(IGameStateService), this);
            inputService = getInputService(gameServices);
        }
        public EditorHostGame(ICoreGame coreGame)
        {
            _coreGame         = coreGame;
            _serviceContainer = new GameServiceContainer();

            _graphicsDeviceService = new EditorGraphicsDeviceService();
            _serviceContainer.AddService <IGraphicsDeviceService>(_graphicsDeviceService);
            _editorGameWindow = new EditorGameWindow(this);
            _contentManager   = new ContentManager(_serviceContainer, "Content");
        }
        public void SoundEffectFromContent(string filename, long durationTicks)
        {
            var services = new GameServiceContainer();

            services.AddService <IGraphicsDeviceService>(new GraphicsDeviceProxy());
            var content     = new ContentManagerProxy(services);
            var soundEffect = content.Load <SoundEffect>(Paths.Audio(filename));

            Assert.AreEqual(durationTicks, soundEffect.Duration.Ticks);
        }
 public void TestInitialization() {
   GameServiceContainer gameServices = new GameServiceContainer();
   MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService();
   gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics);
   using(
     SharedContentManager contentManager = new SharedContentManager(gameServices)
   ) {
     contentManager.Initialize();
   }
 }
Beispiel #21
0
        public Game()
        {
            _instance = this;
            _services = new GameServiceContainer();

            Platform              = GamePlatform.PlatformCreate(this); //创建移动平台
            Platform.Activated   += OnActivated;
            Platform.Deactivated += OnDeactivated;
            _services.AddService(typeof(GamePlatform), Platform);
        }
Beispiel #22
0
        public void TestAssignScreenAfterInitialize()
        {
            var gameServices = new GameServiceContainer();

            gameServices.AddService(
                typeof(IGraphicsDeviceService), this.mockedGraphicsDeviceService
                );
            gameServices.AddService(
                typeof(IInputService), this.mockedInputService
                );

            using (GuiManager guiManager = new GuiManager(gameServices)) {
                Screen screen = new Screen();

                (guiManager as IGameComponent).Initialize();
                guiManager.Screen = screen;

                Assert.AreSame(screen, guiManager.Screen);
            }
        }
Beispiel #23
0
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService();

            GameServiceContainer services = new GameServiceContainer();

            services.AddService(
                typeof(IGraphicsDeviceService), this.mockedGraphicsDeviceService
                );
            this.testComponent = new GraphicsDeviceDrawableComponent(services);
        }
        /// <summary>
        ///   Creates a service provider containing only the graphics device service
        /// </summary>
        /// <param name="graphicsDeviceService">
        ///   Graphics device service that will be provided by the service provider
        /// </param>
        /// <returns>
        ///   A new service provider that provides the graphics device service
        /// </returns>
        public static IServiceProvider MakePrivateServiceProvider(
            IGraphicsDeviceService graphicsDeviceService
            )
        {
            GameServiceContainer serviceContainer = new GameServiceContainer();

            serviceContainer.AddService(
                typeof(IGraphicsDeviceService), graphicsDeviceService
                );
            return(serviceContainer);
        }
Beispiel #25
0
        /// <exception cref="ArgumentNullException">service</exception>
        public static void AddService(this GameServiceContainer services, object service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            var serviceType = service.GetType();

            services.AddService(serviceType, service);
        }
Beispiel #26
0
        protected void AddServiceToGame(Type i_Type)
        {
            GameServiceContainer gameServices = this.Game.Services;

            if (gameServices.GetService(i_Type) != null)
            {
                gameServices.RemoveService(i_Type);
            }

            gameServices.AddService(i_Type, this);
        }
Beispiel #27
0
        /// <summary>
        ///   Initializes a new GUI manager using the XNA service container
        /// </summary>
        /// <param name="gameServices">
        ///   Game service container the GuiManager will register itself in and
        ///   to take the services it consumes from.
        /// </param>
        public GuiManager(GameServiceContainer gameServices)
        {
            this.gameServices = gameServices;

            gameServices.AddService(typeof(IGuiService), this);

            // Do not look for the consumed services yet. XNA uses a two-stage
            // initialization where in the first stage all managers register themselves
            // before seeking out the services they use in the second stage, marked
            // by a call to the Initialize() method.
        }
 public void TestConstructor() {
   GameServiceContainer gameServices = new GameServiceContainer();
   MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService();
   gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics);
   using(
     SharedContentManager contentManager = new SharedContentManager(gameServices)
   ) {
     // Nonsense, but avoids compiler warning about unused variable :)
     Assert.IsNotNull(contentManager);
   }
 }
 public void TestThrowOnLoadAssetBeforeInitialization() {
   GameServiceContainer gameServices = new GameServiceContainer();
   MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService();
   gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics);
   using(
     TestSharedContentManager contentManager = new TestSharedContentManager(gameServices)
   ) {
     Assert.Throws<InvalidOperationException>(
       delegate() { contentManager.Load<BadImageFormatException>("I'm a funny asset"); }
     );
   }
 }
 public void TestInitializationWithExistingGraphicsDevice() {
   GameServiceContainer gameServices = new GameServiceContainer();
   MockedGraphicsDeviceService mockedGraphics = new MockedGraphicsDeviceService();
   gameServices.AddService(typeof(IGraphicsDeviceService), mockedGraphics);
   using(IDisposable keeper = mockedGraphics.CreateDevice()) {
     using(
       SharedContentManager contentManager = new SharedContentManager(gameServices)
     ) {
       contentManager.Initialize();
     }
   }
 }