public void TestManyVertexTypes()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                manager.AddParticleSystem(
                    new ParticleSystem <SimpleParticle>(100),
                    dontPrune, new DummyRenderer <SimpleParticle>()
                    );
                manager.AddParticleSystem(
                    new ParticleSystem <Sky.SkyboxVertex>(100),
                    dontPrune, new DummyRenderer <Sky.SkyboxVertex>()
                    );
                manager.AddParticleSystem(
                    new ParticleSystem <Water.WaterVertex>(100),
                    dontPrune, new DummyRenderer <Water.WaterVertex>()
                    );
                manager.AddParticleSystem(
                    new ParticleSystem <Masks.PositionVertex>(100),
                    dontPrune, new DummyRenderer <Masks.PositionVertex>()
                    );
                manager.AddParticleSystem(
                    new ParticleSystem <Trails.TrailVertex>(100),
                    dontPrune, new DummyRenderer <Trails.TrailVertex>()
                    );

                manager.Draw(new GameTime());
            }
        }
        public void TestAsynchronousPrune()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                // Add one particle system where there's stuff to do
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(16);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }
                manager.AddParticleSystem(test, slowPrune, new DummyRenderer <SimpleParticle>());

                // Add 16 other particle systems
                for (int index = 0; index < 16; ++index)
                {
                    manager.AddParticleSystem(
                        new ParticleSystem <SimpleParticle>(100),
                        dontPrune, new DummyRenderer <SimpleParticle>()
                        );
                }

                // Now update everything
                for (int repetition = 0; repetition < 2; ++repetition)
                {
                    IAsyncResult asyncResult = manager.BeginPrune(null, null);
                    manager.EndPrune(asyncResult);
                }
            }
        }
        public void TestThrowDuringAsynchronousPrune()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(4096);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }

                manager.AddParticleSystem(
                    test,
                    delegate(ref SimpleParticle particle) { throw new ArithmeticException(); },
                    new DummyRenderer <SimpleParticle>()
                    );

                IAsyncResult asyncResult = manager.BeginPrune(null, null);
                Assert.Throws <ArithmeticException>(
                    delegate() { manager.EndPrune(asyncResult); }
                    );
            }
        }
Example #4
0
        public void TestLateVertexRegistration()
        {
            using (
                VertexDeclaration vertexDeclaration = new VertexDeclaration(
                    this.mockedGraphicsDeviceService.GraphicsDevice, SimpleParticle.VertexElements
                    )
                ) {
                using (
                    ParticleSystemManager manager = new ParticleSystemManager(
                        this.mockedGraphicsDeviceService
                        )
                    ) {
                    manager.AddParticleSystem(
                        new ParticleSystem <SimpleParticle>(100), dontPrune, new DummyDrawContext()
                        );

                    // This should replace the auto-generated vertex declaration
                    manager.RegisterVertex <SimpleParticle>(
                        vertexDeclaration, SimpleParticle.SizeInBytes, true
                        );

                    // This should restore the auto-generated vertex declaration
                    // (since there's still a particle system that requires this vertex)
                    manager.UnregisterVertex <SimpleParticle>();
                }
            }
        }
Example #5
0
        public void TestAddParticleSystem()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(100);
#if !XNA_4
                // Add and remove the particle system using the default point sprite renderer
                manager.AddParticleSystem(test, dontPrune, this.effect);
                manager.RemoveParticleSystem(test);
#endif
                // Add and remove the particle system using a user-defined renderer
                manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>());
                manager.RemoveParticleSystem(test);
            }
        }
 public void TestThrowOnAddParticleSystemWithNullRenderer()
 {
     using (
         ParticleSystemManager manager = new ParticleSystemManager(
             this.mockedGraphicsDeviceService
             )
         ) {
         IParticleRenderer <SimpleParticle> nullRenderer = null;
         Assert.Throws <ArgumentException>(
             delegate() {
             manager.AddParticleSystem(
                 new ParticleSystem <SimpleParticle>(100), dontPrune, nullRenderer
                 );
         }
             );
     }
 }
        public void TestDraw()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                // Add one particle system where there's stuff to do
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(4096);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }
                manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>());

                manager.Draw(new GameTime());
            }
        }
        public void TestPrune()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                for (int index = 0; index < 2; ++index)
                {
                    manager.AddParticleSystem(
                        new ParticleSystem <SimpleParticle>(100),
                        dontPrune, new DummyRenderer <SimpleParticle>()
                        );
                }

                manager.Prune();
            }
        }
 public void TestThrowDuringPrimitiveBatchCreation()
 {
     using (
         ParticleSystemManager manager = new ParticleSystemManager(
             this.mockedGraphicsDeviceService
             )
         ) {
         manager.InducePrimitiveBatchErrorDelegate = delegate() {
             throw new ArithmeticException("Simulated error");
         };
         Assert.Throws <ArithmeticException>(
             delegate() {
             manager.AddParticleSystem(
                 new ParticleSystem <SimpleParticle>(100),
                 dontPrune, new DummyRenderer <SimpleParticle>()
                 );
         }
             );
     }
 }
        public void TestThrowDuringAsynchronousUpdate()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(4096);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }
                test.Affectors.Add(new ExceptionThrowingAffector());

                manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>());

                IAsyncResult asyncResult = manager.BeginUpdate(1, 1, null, null);
                Assert.Throws <ArithmeticException>(
                    delegate() { manager.EndUpdate(asyncResult); }
                    );
            }
        }