/// <summary> /// Initializes a new asynchronous result for particle system prunes /// </summary> /// <param name="manager">Particle system manager being pruned</param> public PruneAsyncResult(ParticleSystemManager manager) { this.manager = manager; this.completed = true; this.stepCompletedDelegate = new AsyncCallback(stepCompleted); }
public void TestThrowOnRegisterVertexTwice() { using ( VertexDeclaration vertexDeclaration = new VertexDeclaration( this.mockedGraphicsDeviceService.GraphicsDevice, SimpleParticle.VertexElements ) ) { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { // Normal registration manager.RegisterVertex <SimpleParticle>( vertexDeclaration, SimpleParticle.SizeInBytes ); // Registering the vertex on top of another registration Assert.Throws <ArgumentException>( delegate() { manager.RegisterVertex <SimpleParticle>( vertexDeclaration, SimpleParticle.SizeInBytes ); } ); } } }
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); } ); } }
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>(); } } }
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()); } }
/// <summary>Initializes a new primitive batch holder</summary> /// <param name="manager">Particle system manager the holder belongs to</param> /// <param name="ownedVertexDeclaration"> /// Vertex declaration if the particle system manager took ownership of it /// </param> public PrimitiveBatchHolder( ParticleSystemManager manager, VertexDeclaration ownedVertexDeclaration ) { this.Manager = manager; this.ReferenceCount = 1; this.OwnedVertexDeclaration = ownedVertexDeclaration; }
public void TestConstructor() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { Assert.IsNotNull(manager); // nonsense; prevents compiler warning } }
public void TestThrowOnVertexRegistrationErrors() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { Assert.Throws <ArgumentException>( delegate() { manager.UnregisterVertex <SimpleParticle>(); } ); } }
public void TestThrowOnRemoveNotAddedParticleSystem() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { Assert.Throws <ArgumentException>( delegate() { manager.RemoveParticleSystem(new ParticleSystem <SimpleParticle>(100)); } ); } }
public void TestAddParticleSystem() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(100); // Add and remove the particle system using a user-defined renderer manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>()); manager.RemoveParticleSystem(test); } }
public void TestAsynchronousPruneCallback() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { CallbackReceiver receiver = new CallbackReceiver(); object state = new object(); IAsyncResult asyncResult = manager.BeginPrune(receiver.Callback, state); manager.EndPrune(asyncResult); Assert.AreSame(state, receiver.State); Assert.IsFalse(asyncResult.CompletedSynchronously); } }
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 TestThrowOnWrongAsyncResultInEndPrune() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { IAsyncResult asyncResult = manager.BeginPrune(null, null); try { Assert.Throws <ArgumentException>( delegate() { manager.EndPrune(null); } ); } finally { manager.EndPrune(asyncResult); } } }
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 TestVertexRegistration() { using ( VertexDeclaration vertexDeclaration = new VertexDeclaration( this.mockedGraphicsDeviceService.GraphicsDevice, SimpleParticle.VertexElements ) ) { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { manager.RegisterVertex <SimpleParticle>( vertexDeclaration, SimpleParticle.SizeInBytes ); manager.UnregisterVertex <SimpleParticle>(); } } }
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); } ); } }
/// <summary>Initializes a new primitive batch holder</summary> /// <param name="manager">Particle system manager the holder belongs to</param> public PrimitiveBatchHolder(ParticleSystemManager manager) { this.Manager = manager; this.ReferenceCount = 1; }