public void TestCompressedContentLoading()
        {
            // Extract the .xnb test file for the unit test and compress it
            {
                string path = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb");
                writeBytesToFile(
                    Resources.UnitTestResources.UnitTestEffect,
                    path
                    );
                LzmaContentCompressor.CompressContentFile(path);
                File.Delete(path);
            }

            // Now try to load the compressed file
            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
Пример #2
0
        /// <summary>Loads the graphics resources of the component</summary>
        protected override void LoadContent()
        {
            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(GraphicsDeviceService),
#if WINDOWS_PHONE
                Resources.Phone7DebugDrawerResources.ResourceManager
#else
                Resources.DebugDrawerResources.ResourceManager
#endif
                );

            // The effect will be managed by our content manager and only needs to be
            // reloaded when the graphics device has been totally shut down or is
            // starting up for the first time.
#if WINDOWS_PHONE
            this.fillEffect = new BasicEffect(GraphicsDevice);
#else
            this.fillEffect = this.contentManager.Load <Effect>("SolidColorEffect");
#endif
            this.drawContext = new EffectDrawContext(this.fillEffect);

            // Create the sprite batch we're using for text rendering
            this.font            = this.contentManager.Load <SpriteFont>("LucidaSpriteFont");
            this.fontSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a new vertex buffer and its matching vertex declaration for
            // holding the geometry data of our debug overlays.
            this.batchDrawer = PrimitiveBatch <VertexPositionColor> .GetDefaultBatchDrawer(
                GraphicsDevice
                );
        }
Пример #3
0
        /// <summary>Creates a new solid color screen mask</summary>
        /// <param name="graphicsDevice">
        ///   Graphics device the screen mask will be draw with
        /// </param>
        /// <param name="createDelegate">
        ///   Factory method that will be used to instantiate the mask
        /// </param>
        /// <returns>The newly created solid color screen mask</returns>
        internal static ColorScreenMask Create(
            GraphicsDevice graphicsDevice, CreateDelegate createDelegate
            )
        {
            // Fake up a service provider with a graphics device service so we can
            // create a content manager without the huge rat-tail of references
            IServiceProvider serviceProvider;

            serviceProvider = GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService(graphicsDevice)
                );

            // Create a resource content manager to load the default effect and hand
            // everything to the new screen mask instance, which will then be responsible
            // for freeing those resources again.
            ResourceContentManager contentManager = new ResourceContentManager(
                serviceProvider, Resources.ScreenMaskResources.ResourceManager
                );

            try {
                Effect effect = contentManager.Load <Effect>("ScreenMaskEffect");
                try {
                    return(createDelegate(graphicsDevice, contentManager, effect));
                }
                catch (Exception) {
                    effect.Dispose();
                    throw;
                }
            }
            catch (Exception) {
                contentManager.Dispose();
                throw;
            }
        }
        public void TestPackagedContentReplacementWhenNoPackageExists()
        {
            string packagePath = Path.Combine(
                this.tempDirectory.Path, "PackagedUnitTestEffect.package"
                );

            writeBytesToFile(
                Resources.UnitTestResources.UnitTestEffect,
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                // The package doesn't even exist, but because replacement is allowed,
                // no error should occur if the requested asset is available directly
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        public void TestPackagedContentLoading()
        {
            // Extract the .xnb test file for the unit test and compress it
            string packagePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.package");

            {
                string filePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb");
                writeBytesToFile(
                    Resources.UnitTestResources.UnitTestEffect,
                    filePath
                    );

                LzmaPackageBuilder.Build(
                    packagePath, new LzmaPackageBuilder.PackageFile(filePath, "UnitTestEffect")
                    );

                File.Delete(filePath);
            }

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = Path.GetDirectoryName(packagePath);
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        public void TestCompressedContentReplacement()
        {
            // If the replacement doesn't work, the test will load this file which,
            // as the observant programmer might notice, contains 'Crap' :-)
            writeBytesToFile(
                new byte[] { (byte)'C', (byte)'r', (byte)'a', (byte)'p' },
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.lzma")
                );

            // Write the real file the test should be loading
            writeBytesToFile(
                Resources.UnitTestResources.UnitTestEffect,
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                // The .lzma file contains 'Crap' (literally :D), so if the content manager
                // didn't see the replacement file, it would fall on its nose here!
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
Пример #7
0
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(DeviceType.Reference);
            this.mockedGraphicsDeviceService.CreateDevice();

            serviceProvider = GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                this.mockedGraphicsDeviceService
                );
        }
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(DeviceType.Reference);
            this.mockedGraphicsDeviceService.CreateDevice();

            MockedGraphicsDeviceService mockedService = this.mockedGraphicsDeviceService;

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(mockedService),
                Resources.UnitTestResources.ResourceManager
                );
        }
Пример #9
0
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService();
            this.mockedGraphicsDeviceService.CreateDevice();

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                    this.mockedGraphicsDeviceService
                    ),
                Resources.UnitTestResources.ResourceManager
                );
            this.vectorFont = this.contentManager.Load <VectorFont>("UnitTestVectorFont");
        }
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(DeviceType.Reference);
            this.mockedGraphicsDeviceService.CreateDevice();

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                    this.mockedGraphicsDeviceService
                    ),
                Resources.ScreenMaskResources.ResourceManager
                );
            this.effect = this.contentManager.Load <Effect>("ScreenMaskEffect");
        }
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService();
            this.mockedGraphicsDeviceService.CreateDevice();

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                    this.mockedGraphicsDeviceService
                    ),
                Resources.TextBatchResources.ResourceManager
                );
            this.effect = this.contentManager.Load <Effect>("DefaultTextEffect");
        }
Пример #12
0
        public void TestVectorFontReading()
        {
            MockedGraphicsDeviceService service = new MockedGraphicsDeviceService();

            using (IDisposable keeper = service.CreateDevice()) {
                using (
                    ResourceContentManager contentManager = new ResourceContentManager(
                        GraphicsDeviceServiceHelper.MakePrivateServiceProvider(service),
                        Resources.UnitTestResources.ResourceManager
                        )
                    ) {
                    VectorFont font = contentManager.Load <VectorFont>("UnitTestVectorFont");
                    Assert.IsNotNull(font);
                }
            }
        }
Пример #13
0
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(DeviceType.Reference);
            this.mockedGraphicsDeviceService.CreateDevice();

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                    this.mockedGraphicsDeviceService
                    ),
                Resources.ScreenMaskResources.ResourceManager
                );
            this.effect = this.contentManager.Load <Effect>("ScreenMaskEffect");

            this.vertexDeclaration = new VertexDeclaration(
                this.mockedGraphicsDeviceService.GraphicsDevice, SimpleParticle.VertexElements
                );
        }
Пример #14
0
        public void Setup()
        {
            this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService();
            this.mockedGraphicsDeviceService.CreateDevice();

            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                    this.mockedGraphicsDeviceService
                    ),
                Resources.UnitTestResources.ResourceManager
                );
            this.vectorFont = this.contentManager.Load <VectorFont>("UnitTestVectorFont");

            char character      = getFirstVisibleCharacter();
            int  characterIndex = this.vectorFont.CharacterMap[character];

            this.vectorCharacter = this.vectorFont.Characters[characterIndex];
        }
        public void TestThrowOnMissingCompressedAsset()
        {
            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Assert.Throws <ArgumentException>(
                    delegate() {
                    contentManager.Load <Effect>("DoesNotExist");
                }
                    );
            }
        }
Пример #16
0
        /// <summary>Initializes a new text batch for rendering</summary>
        /// <param name="graphicsDevice">Graphics device to render to</param>
        public TextBatch(GraphicsDevice graphicsDevice)
        {
            this.dummyService = GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService(
                graphicsDevice
                );
#if WINDOWS_PHONE
            // Windows Phone doesn't expose programmable shaders to XNA
            this.solidColorEffect = new BasicEffect(graphicsDevice);
#else
            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(this.dummyService),
                Resources.TextBatchResources.ResourceManager
                );

            // Create the default effect we're going to use for rendering
            this.solidColorEffect = this.contentManager.Load <Effect>("DefaultTextEffect");
#endif
#if XNA_3
            // Create a new vertex declaration for the internally used primitive batch
            this.vertexDeclaration = new VertexDeclaration(
                graphicsDevice, VertexPositionNormalTexture.VertexElements
                );
#endif

            // Set up our internal primitive batch. We delegate the vertex batching
            // methods to this class and just make it our responsibility to present
            // a clean interface to the user.
            this.primitiveBatch = new PrimitiveBatch <VertexPositionNormalTexture>(
                graphicsDevice
#if XNA_3
                , this.vertexDeclaration, VertexPositionNormalTexture.SizeInBytes
#endif
                );

            // Set up a view matrix that provides a 1:1 transformation of pixels to
            // world units. Unless the user sets his own ViewProjection matrix, this will
            // allow us to expose similar behavior to the XNA SpriteBatch class.
            this.viewProjection = new Matrix(
                2.0f / (float)graphicsDevice.Viewport.Width, 0.0f, 0.0f, 0.0f,
                0.0f, 2.0f / (float)graphicsDevice.Viewport.Height, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, 0.0f, 1.0f
                );
        }
        public void TestPackagedContentReplacement()
        {
            // Extract the .xnb test file for the unit test and compress it
            string packagePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.package");

            {
                string filePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb");

                // We will compress this nonsense file so that if the replacement isn't
                // honored, the content manager will fail.
                writeBytesToFile(
                    new byte[] { (byte)'C', (byte)'r', (byte)'a', (byte)'p' }, filePath
                    );
                LzmaPackageBuilder.Build(
                    packagePath, new LzmaPackageBuilder.PackageFile(filePath, "UnitTestEffect")
                    );
                File.Delete(filePath);

                // Now write the replacement, which actually contains valid data
                writeBytesToFile(
                    Resources.UnitTestResources.UnitTestEffect,
                    filePath
                    );
            }

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                // This only works if the content manager loads the replacement instead
                // of the packaged file
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        public void TestThrowsOnMissingPackagedAsset()
        {
            string packagePath = Path.Combine(
                this.tempDirectory.Path, "PackagedUnitTestEffect.package"
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Assert.Throws <ArgumentException>(
                    delegate() {
                    contentManager.Load <Effect>("DoesNotExist");
                }
                    );
            }
        }
        public void TestCleanupAfterException()
        {
            string packagePath = Path.Combine(
                this.tempDirectory.Path, "PackagedUnitTestEffect.package"
                );

            writeBytesToFile(BitConverter.GetBytes(-1), packagePath);

            Assert.Throws <ArgumentOutOfRangeException>(
                delegate() {
                using (
                    LzmaContentManager contentManager = new LzmaContentManager(
                        GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                            this.mockedGraphicsDeviceService
                            ),
                        packagePath
                        )
                    ) { }
            }
                );

            // If the package is left open due to the exception, a follow-up error
            // will happen in the Teardown() method.
        }
Пример #20
0
 /// <summary>
 ///   Initializes a new embedded content manager using a directly specified
 ///   graphics device service for the resources.
 /// </summary>
 /// <param name="graphicsDeviceService">
 ///   Graphics device service to load the content asset in
 /// </param>
 public MemoryContentManager(IGraphicsDeviceService graphicsDeviceService) :
     this(
         GraphicsDeviceServiceHelper.MakePrivateServiceProvider(graphicsDeviceService)
         )
 {
 }