public PostProcessingGraphicsScreen(IServiceLocator services) : base(services.GetInstance<IGraphicsService>()) { _sampleFramework = services.GetInstance<SampleFramework>(); _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); _clearGBufferRenderer = new ClearGBufferRenderer(GraphicsService); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); _meshRenderer = new MeshRenderer(); _skyRenderer = new SkyRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); Scene = new Scene(); PostProcessors = new PostProcessorChain(GraphicsService); // Use 2D texture for reticle. var contentManager = services.GetInstance<ContentManager>(); _reticle = contentManager.Load<Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance<ContentManager>("UIContent"); var spriteFont = uiContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; }
public PostProcessingGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _sampleFramework = services.GetInstance <SampleFramework>(); _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); _clearGBufferRenderer = new ClearGBufferRenderer(GraphicsService); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); _meshRenderer = new MeshRenderer(); _skyRenderer = new SkyRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); Scene = new Scene(); PostProcessors = new PostProcessorChain(GraphicsService); // Use 2D texture for reticle. var contentManager = services.GetInstance <ContentManager>(); _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; }
protected Sample(Microsoft.Xna.Framework.Game game) : base(game) { // Get services from the global service container. var services = (ServiceContainer)ServiceLocator.Current; SampleFramework = services.GetInstance <SampleFramework>(); ContentManager = services.GetInstance <ContentManager>(); UIContentManager = services.GetInstance <ContentManager>("UIContent"); InputService = services.GetInstance <IInputService>(); AnimationService = services.GetInstance <IAnimationService>(); Simulation = services.GetInstance <Simulation>(); ParticleSystemService = services.GetInstance <IParticleSystemService>(); GraphicsService = services.GetInstance <IGraphicsService>(); GameObjectService = services.GetInstance <IGameObjectService>(); UIService = services.GetInstance <IUIService>(); // Create a local service container which can be modified in samples: // The local service container is a child container, i.e. it inherits the // services of the global service container. Samples can add new services // or override existing entries without affecting the global services container // or other samples. Services = services.CreateChildContainer(); // Store a copy of the original graphics screens. _originalGraphicsScreens = GraphicsService.Screens.ToArray(); // Mouse is visible by default. SampleFramework.IsMouseVisible = true; }
protected Sample(Microsoft.Xna.Framework.Game game) : base(game) { // Get services from the global service container. var services = (ServiceContainer)ServiceLocator.Current; SampleFramework = services.GetInstance<SampleFramework>(); ContentManager = services.GetInstance<ContentManager>(); UIContentManager = services.GetInstance<ContentManager>("UIContent"); InputService = services.GetInstance<IInputService>(); AnimationService = services.GetInstance<IAnimationService>(); Simulation = services.GetInstance<Simulation>(); ParticleSystemService = services.GetInstance<IParticleSystemService>(); GraphicsService = services.GetInstance<IGraphicsService>(); GameObjectService = services.GetInstance<IGameObjectService>(); UIService = services.GetInstance<IUIService>(); // Create a local service container which can be modified in samples: // The local service container is a child container, i.e. it inherits the // services of the global service container. Samples can add new services // or override existing entries without affecting the global services container // or other samples. Services = services.CreateChildContainer(); // Store a copy of the original graphics screens. _originalGraphicsScreens = GraphicsService.Screens.ToArray(); // Mouse is visible by default. SampleFramework.IsMouseVisible = true; }
public SampleGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _sampleFramework = services.GetInstance <SampleFramework>(); Name = "SampleScreen"; ClearBackground = false; BackgroundColor = new Color(220, 220, 220); DrawReticle = false; UseFixedWidthFont = false; // Use 2D texture for reticle. var contentManager = services.GetInstance <ContentManager>(); _reticle = contentManager.Load <Texture2D>("Reticle"); // Get the sprite fonts used in the UI theme. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); _defaultFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); _fixedWidthFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Console"); // Set up 2D camera such that (0, 0) is upper, left corner of screen and // (screenWidth, screenHeight) is lower, right corner of screen. var graphicsDevice = GraphicsService.GraphicsDevice; int screenWidth = graphicsDevice.PresentationParameters.BackBufferWidth; int screenHeight = graphicsDevice.PresentationParameters.BackBufferHeight; var projection = new OrthographicProjection { Near = 0, Far = 2000, Left = 0, Right = screenWidth, Top = 0, Bottom = screenHeight, }; var camera = new Camera(projection); _cameraNode2D = new CameraNode(camera) { PoseWorld = new Pose(new Vector3F(0, 0, 1000)), }; // Initialize renderers. _spriteBatch = new SpriteBatch(graphicsDevice); _meshRenderer = new MeshRenderer(); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); DebugRenderer2D = new DebugRenderer(GraphicsService, _defaultFont) { SpriteFont = _defaultFont, DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10) }; DebugRenderer = new DebugRenderer(GraphicsService, _defaultFont) { SpriteFont = _defaultFont, DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10) }; Scene = new Scene(); }
public SampleGraphicsScreen(IServiceLocator services) : base(services.GetInstance<IGraphicsService>()) { _sampleFramework = services.GetInstance<SampleFramework>(); Name = "SampleScreen"; ClearBackground = false; BackgroundColor = new Color(220, 220, 220); DrawReticle = false; UseFixedWidthFont = false; // Use 2D texture for reticle. var contentManager = services.GetInstance<ContentManager>(); _reticle = contentManager.Load<Texture2D>("Reticle"); // Get the sprite fonts used in the UI theme. var uiContentManager = services.GetInstance<ContentManager>("UIContent"); _defaultFont = uiContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default"); _fixedWidthFont = uiContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Console"); // Set up 2D camera such that (0, 0) is upper, left corner of screen and // (screenWidth, screenHeight) is lower, right corner of screen. var graphicsDevice = GraphicsService.GraphicsDevice; int screenWidth = graphicsDevice.PresentationParameters.BackBufferWidth; int screenHeight = graphicsDevice.PresentationParameters.BackBufferHeight; var projection = new OrthographicProjection { Near = 0, Far = 2000, Left = 0, Right = screenWidth, Top = 0, Bottom = screenHeight, }; var camera = new Camera(projection); _cameraNode2D = new CameraNode(camera) { PoseWorld = new Pose(new Vector3F(0, 0, 1000)), }; // Initialize renderers. _spriteBatch = new SpriteBatch(graphicsDevice); _meshRenderer = new MeshRenderer(); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); DebugRenderer2D = new DebugRenderer(GraphicsService, _defaultFont) { SpriteFont = _defaultFont, DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10) }; DebugRenderer = new DebugRenderer(GraphicsService, _defaultFont) { SpriteFont = _defaultFont, DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10) }; Scene = new Scene(); }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public DeferredGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _sampleFramework = services.GetInstance <SampleFramework>(); var contentManager = services.GetInstance <ContentManager>(); SpriteBatch = GraphicsService.GetSpriteBatch(); // Let's create the necessary scene node renderers: #if !XBOX360 TerrainRenderer = new TerrainRenderer(GraphicsService); #endif MeshRenderer = new MeshRenderer(); // The _opaqueMeshSceneRenderer combines all renderers for opaque // (= not alpha blended) meshes. _opaqueMeshSceneRenderer = new SceneRenderer(); #if !XBOX360 _opaqueMeshSceneRenderer.Renderers.Add(TerrainRenderer); #endif _opaqueMeshSceneRenderer.Renderers.Add(MeshRenderer); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, // If you have an extreme amount of particles that cover the entire screen, // you can turn on offscreen rendering to improve performance. //EnableOffscreenRendering = true, }; // The AlphaBlendSceneRenderer combines all renderers for transparent // (= alpha blended) objects. AlphaBlendSceneRenderer = new SceneRenderer(); AlphaBlendSceneRenderer.Renderers.Add(MeshRenderer); AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer); AlphaBlendSceneRenderer.Renderers.Add(new WaterRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new VolumetricLightRenderer(GraphicsService)); #if !XBOX360 // Update terrain clipmaps. (Only necessary if TerrainNodes are used.) _terrainClipmapRenderer = new TerrainClipmapRenderer(GraphicsService); #endif // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.) _cloudMapRenderer = new CloudMapRenderer(GraphicsService); // Renderer for SceneCaptureNodes. See also SceneCapture2DSample. // In the constructor we specify a method which is called in SceneCaptureRenderer.Render() // when the scene must be rendered for the SceneCaptureNodes. SceneCaptureRenderer = new SceneCaptureRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); // Render scene (with post-processing, with lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, true, true, false, false); }); // Renderer for PlanarReflectionNodes. See also PlanarReflectionSample. // In the constructor we specify a method which is called in PlanarReflectionRenderer.Render() // to create the reflection images. _planarReflectionRenderer = new PlanarReflectionRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); var planarReflectionNode = (PlanarReflectionNode)context.ReferenceNode; // Planar reflections are often for WaterNodes. These nodes should not be rendered // into their own reflection map because when the water surface is displaced by waves, // some waves could be visible in the reflection. // --> Remove the water node from the renderable nodes. (In our samples, the water // node is the parent of the reflection node.) if (planarReflectionNode.Parent is WaterNode) { var index = sceneQuery.RenderableNodes.IndexOf(planarReflectionNode.Parent); if (index >= 0) { sceneQuery.RenderableNodes[index] = null; } } // Render scene (no post-processing, no lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, false, false, false, false); }); _waterWavesRenderer = new WaterWavesRenderer(GraphicsService); // The shadow map renderer renders a depth image from the viewpoint of the light and // stores it in LightNode.Shadow.ShadowMap. ShadowMapRenderer = new ShadowMapRenderer(context => { var query = context.Scene.Query <ShadowCasterQuery>(context.CameraNode, context); if (query.ShadowCasters.Count == 0) { return(false); } _opaqueMeshSceneRenderer.Render(query.ShadowCasters, context); return(true); }); // The shadow mask renderer evaluates the shadow maps, does shadow filtering // and stores the resulting shadow factor in a screen space image //(see LightNode.Shadow.ShadowMask/ShadowMaskChannel). ShadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); // Optionally, we can blur the shadow mask to make the shadows smoother. var blur = new Blur(GraphicsService) { IsAnisotropic = false, IsBilateral = true, EdgeSoftness = 0.05f, Scale = 1f, Enabled = false, // Disable blur by default. }; blur.InitializeGaussianBlur(11, 3, true); ShadowMaskRenderer.Filter = blur; // Renderers which create the intermediate render targets: // Those 2 renderers are implemented in this sample. Those functions could // be implemented directly in this class but we have created separate classes // to make the code more readable. _gBufferRenderer = new GBufferRenderer(GraphicsService, _opaqueMeshSceneRenderer, _decalRenderer); LightBufferRenderer = new LightBufferRenderer(GraphicsService); // Other specialized renderers: _lensFlareRenderer = new LensFlareRenderer(GraphicsService); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); // This screen needs a HDR filter to map high dynamic range values back to // low dynamic range (LDR). PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { EnableBlueShift = true, BlueShiftCenter = 0.0004f, BlueShiftRange = 0.5f, //BlueShiftColor = new Vector3F(1.05f / 4f, 0.97f / 4f, 1.27f / 4f), // Default physically-based blue-shift BlueShiftColor = new Vector3F(0.25f, 0.25f, 0.7f), // More dramatic blue-shift MinExposure = 0, MaxExposure = 10, BloomIntensity = 1, BloomThreshold = 0.6f, }); _underwaterPostProcessor = new UnderwaterPostProcessor(GraphicsService, contentManager); PostProcessors.Add(_underwaterPostProcessor); // Use 2D texture for reticle. _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; EnableLod = true; }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public DeferredGraphicsScreen(IServiceLocator services) : base(services.GetInstance<IGraphicsService>()) { _sampleFramework = services.GetInstance<SampleFramework>(); var contentManager = services.GetInstance<ContentManager>(); SpriteBatch = GraphicsService.GetSpriteBatch(); // Let's create the necessary scene node renderers: #if !XBOX360 TerrainRenderer = new TerrainRenderer(GraphicsService); #endif MeshRenderer = new MeshRenderer(); // The _opaqueMeshSceneRenderer combines all renderers for opaque // (= not alpha blended) meshes. _opaqueMeshSceneRenderer = new SceneRenderer(); #if !XBOX360 _opaqueMeshSceneRenderer.Renderers.Add(TerrainRenderer); #endif _opaqueMeshSceneRenderer.Renderers.Add(MeshRenderer); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, // If you have an extreme amount of particles that cover the entire screen, // you can turn on offscreen rendering to improve performance. //EnableOffscreenRendering = true, }; // The AlphaBlendSceneRenderer combines all renderers for transparent // (= alpha blended) objects. AlphaBlendSceneRenderer = new SceneRenderer(); AlphaBlendSceneRenderer.Renderers.Add(MeshRenderer); AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer); AlphaBlendSceneRenderer.Renderers.Add(new WaterRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new VolumetricLightRenderer(GraphicsService)); #if !XBOX360 // Update terrain clipmaps. (Only necessary if TerrainNodes are used.) _terrainClipmapRenderer = new TerrainClipmapRenderer(GraphicsService); #endif // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.) _cloudMapRenderer = new CloudMapRenderer(GraphicsService); // Renderer for SceneCaptureNodes. See also SceneCapture2DSample. // In the constructor we specify a method which is called in SceneCaptureRenderer.Render() // when the scene must be rendered for the SceneCaptureNodes. SceneCaptureRenderer = new SceneCaptureRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query<CustomSceneQuery>(context.CameraNode, context); // Render scene (with post-processing, with lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, true, true, false, false); }); // Renderer for PlanarReflectionNodes. See also PlanarReflectionSample. // In the constructor we specify a method which is called in PlanarReflectionRenderer.Render() // to create the reflection images. _planarReflectionRenderer = new PlanarReflectionRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query<CustomSceneQuery>(context.CameraNode, context); var planarReflectionNode = (PlanarReflectionNode)context.ReferenceNode; // Planar reflections are often for WaterNodes. These nodes should not be rendered // into their own reflection map because when the water surface is displaced by waves, // some waves could be visible in the reflection. // --> Remove the water node from the renderable nodes. (In our samples, the water // node is the parent of the reflection node.) if (planarReflectionNode.Parent is WaterNode) { var index = sceneQuery.RenderableNodes.IndexOf(planarReflectionNode.Parent); if (index >= 0) sceneQuery.RenderableNodes[index] = null; } // Render scene (no post-processing, no lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, false, false, false, false); }); _waterWavesRenderer = new WaterWavesRenderer(GraphicsService); // The shadow map renderer renders a depth image from the viewpoint of the light and // stores it in LightNode.Shadow.ShadowMap. ShadowMapRenderer = new ShadowMapRenderer(context => { var query = context.Scene.Query<ShadowCasterQuery>(context.CameraNode, context); if (query.ShadowCasters.Count == 0) return false; _opaqueMeshSceneRenderer.Render(query.ShadowCasters, context); return true; }); // The shadow mask renderer evaluates the shadow maps, does shadow filtering // and stores the resulting shadow factor in a screen space image //(see LightNode.Shadow.ShadowMask/ShadowMaskChannel). ShadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); // Optionally, we can blur the shadow mask to make the shadows smoother. var blur = new Blur(GraphicsService) { IsAnisotropic = false, IsBilateral = true, EdgeSoftness = 0.05f, Scale = 1f, Enabled = false, // Disable blur by default. }; blur.InitializeGaussianBlur(11, 3, true); ShadowMaskRenderer.Filter = blur; // Renderers which create the intermediate render targets: // Those 2 renderers are implemented in this sample. Those functions could // be implemented directly in this class but we have created separate classes // to make the code more readable. _gBufferRenderer = new GBufferRenderer(GraphicsService, _opaqueMeshSceneRenderer, _decalRenderer); LightBufferRenderer = new LightBufferRenderer(GraphicsService); // Other specialized renderers: _lensFlareRenderer = new LensFlareRenderer(GraphicsService); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); // This screen needs a HDR filter to map high dynamic range values back to // low dynamic range (LDR). PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { EnableBlueShift = true, BlueShiftCenter = 0.0004f, BlueShiftRange = 0.5f, //BlueShiftColor = new Vector3F(1.05f / 4f, 0.97f / 4f, 1.27f / 4f), // Default physically-based blue-shift BlueShiftColor = new Vector3F(0.25f, 0.25f, 0.7f), // More dramatic blue-shift MinExposure = 0, MaxExposure = 10, BloomIntensity = 1, BloomThreshold = 0.6f, }); _underwaterPostProcessor = new UnderwaterPostProcessor(GraphicsService, contentManager); PostProcessors.Add(_underwaterPostProcessor); // Use 2D texture for reticle. _reticle = contentManager.Load<Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance<ContentManager>("UIContent"); var spriteFont = uiContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; EnableLod = true; }
// Initializes services and adds game components. protected override void Initialize() { #if WINDOWS || WINDOWS_UWP || XBOX if (GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach) { throw new NotSupportedException( "The DigitalRune Samples and Content for Windows, Universal Windows Apps and Xbox 360 are " + "designed for the HiDef graphics profile. A graphics cards supporting DirectX 10.0 or better " + "is required."); } #endif // ----- Service Container // The DigitalRune ServiceContainer is an "inversion of control" container. // All game services (such as input, graphics, physics, etc.) are registered // in this container. Other game components can access these services via lookup // in the service container. // The DigitalRune ServiceContainer replaces the XNA GameServiceContainer (see // property Game.Services). // Note: The DigitalRune libraries do not require the use of the ServiceContainer // or any other IoC container. The ServiceContainer is only used in the sample // for convenience - but it is not mandatory. _services = new ServiceContainer(); // The service container is either passed directly to the game components // or accessed through the global variable ServiceLocator.Current. // The following call makes the service container publicly available in // ServiceLocator.Current. ServiceLocator.SetLocatorProvider(() => _services); // ----- Storage // For XNA the assets are stored in the following folders: // // <gameLocation>/ // Content/ // DigitalRune/ // ... DigitalRune assets ... // ... other assets ... // // For MonoGame the assets (*.xnb files) are stored in ZIP packages. The // sample assets are stored in "Content/Content.zip" and the DigitalRune // assets are stored in "Content/DigitalRune.zip". // // <gameLocation>/ // Content/ // Content.zip // DigitalRune.zip // // DigitalRune introduces the concept of "storages". Storages can be used // to access files on disk or files stored in packages (e.g. ZIP archives). // These storages can be mapped into a "virtual file system", which makes // it easier to write portable code. (The game logic can read the files // from the virtual file system and does not need to know the specifics // about the platform.) // // The virtual files system should look like this: // // / <-- root of virtual file system // DigitalRune/ // ... DigitalRune assets ... // ... other assets ... // The VfsStorage creates a virtual file system. var vfsStorage = new VfsStorage(); // The TitleStorage reads files from the game's default storage location. // --> Create a TitleStorage that reads files from "<gameLocation>/Content". var titleStorage = new TitleStorage("Content"); #if MONOGAME // A ZipStorage can be used to access files inside a ZIP archive. // --> Mount the sample assets to the root of the virtual file system. var assetsStorage = new ZipStorage(titleStorage, "Content.zip"); vfsStorage.MountInfos.Add(new VfsMountInfo(assetsStorage, null)); #if !ANDROID && !IOS && !LINUX && !MACOS // --> Mount the DigitalRune assets to the root of the virtual file system. var drStorage = new ZipStorage(titleStorage, "DigitalRune.zip"); vfsStorage.MountInfos.Add(new VfsMountInfo(drStorage, null)); #endif #endif // Finally, map the TitleStorage to the root of the virtual file system. // (The TitleStorage is added as the last mount point. The ZIP archives // have priority.) vfsStorage.MountInfos.Add(new VfsMountInfo(titleStorage, null)); // Register the virtual file system as a service. _services.Register(typeof(IStorage), null, vfsStorage); // ----- Content Managers // The GraphicsDeviceManager needs to be registered in the service container. // (This is required by the XNA content managers.) _services.Register(typeof(IGraphicsDeviceService), null, _graphicsDeviceManager); _services.Register(typeof(GraphicsDeviceManager), null, _graphicsDeviceManager); // Register a default, shared content manager. // The new StorageContentManager can be used to read assets from the virtual // file system. (Replaces the content manager stored in Game.Content.) Content = new StorageContentManager(_services, vfsStorage); _services.Register(typeof(ContentManager), null, Content); // Create and register content manager that will be used to load the GUI. #if !MONOGAME var uiContentManager = new ContentManager(_services, "Content"); #else var uiContentManager = new StorageContentManager(_services, assetsStorage); #endif _services.Register(typeof(ContentManager), "UIContent", uiContentManager); // Create content manager that will be used exclusively by the graphics service // to load the pre-built effects and resources of DigitalRune.Graphics. (We // could use Game.Content, but it is recommended to separate the content. This // allows to unload the content of the samples without unloading the other // content.) var graphicsContentManager = new StorageContentManager(_services, vfsStorage); // ----- Initialize Services // Register the game class. _services.Register(typeof(Microsoft.Xna.Framework.Game), null, this); _services.Register(typeof(SampleGame), null, this); #if XBOX // On Xbox, we use the XNA gamer services (e.g. for text input). Components.Add(new GamerServicesComponent(this)); #endif // Input #if XBOX const bool useGamerServices = true; #else const bool useGamerServices = false; #endif _inputManager = new InputManager(useGamerServices); _services.Register(typeof(IInputService), null, _inputManager); // Graphics _graphicsManager = new GraphicsManager(GraphicsDevice, Window, graphicsContentManager); _services.Register(typeof(IGraphicsService), null, _graphicsManager); // GUI _uiManager = new UIManager(this, _inputManager); _services.Register(typeof(IUIService), null, _uiManager); // Animation _animationManager = new AnimationManager(); _services.Register(typeof(IAnimationService), null, _animationManager); // Particle simulation _particleSystemManager = new ParticleSystemManager(); _services.Register(typeof(IParticleSystemService), null, _particleSystemManager); // Physics simulation ResetPhysicsSimulation(); // Game logic _gameObjectManager = new GameObjectManager(); _services.Register(typeof(IGameObjectService), null, _gameObjectManager); // Profiler _profiler = new HierarchicalProfiler("Main"); _services.Register(typeof(HierarchicalProfiler), "Main", _profiler); // Initialize delegates for running tasks in parallel. // (Creating delegates allocates memory, therefore we do this only once and // cache the delegates.) _updateAnimation = () => _animationManager.Update(_deltaTime); _updatePhysics = () => _simulation.Update(_deltaTime); _updateParticles = () => _particleSystemManager.Update(_deltaTime); // SampleFramework // The SampleFramework automatically discovers all samples using reflection, provides // controls for switching samples and starts the initial sample. #if KINECT var initialSample = typeof(Kinect.KinectSkeletonMappingSample); #elif WINDOWS || WINDOWS_UWP var initialSample = typeof(Graphics.DeferredLightingSample); #else var initialSample = typeof(Graphics.BasicEffectSample); #endif _sampleFramework = new SampleFramework(this, initialSample); _services.Register(typeof(SampleFramework), null, _sampleFramework); base.Initialize(); }