DPSF by Daniel Schroeder

<PackageReference Include="DPSF" Version="2.5.0" />

.NET API 168,448 bytes

 IDPSFParticleSystem

public interface IDPSFParticleSystem
Interface implemented by all Particle Systems. Variables of this type can point to any type of Particle System.

The Settings used to control the Automatic Memory Manager.

string ClassName { get; }

Get the Name of the Class that this Particle System is using. This can be used to check what type of Particle System this is at run-time.

ContentManager ContentManager { get; set; }

Get / Set the Content Manager to use to load Textures and Effects.

string DeserializationEffectPath { get; set; }

The path used to load the Effect when the InitializeNonSerializableProperties() function is called.

NOTE: This is automatically set when the SetEffectAndTechnique(string, string) function is called.

string DeserializationTechniqueName { get; set; }

The Name of the Technique to use when the InitializeNonSerializableProperties() function is called.

NOTE: This is automatically set when the SetEffectAndTechnique() and SetTechnique() functions are called.

string DeserializationTexturePath { get; set; }

The path used to load the Texture when the InitializeNonSerializableProperties() function is called.

NOTE: This is automatically set when the SetTexture() function is called.

int DrawOrder { get; set; }

The Order in which the Particle System should be Drawn relative to other DPSF Particle Systems in the same Particle System Manager. Particle Systems are Drawn in ascending order according to their Draw Order (i.e. lowest first)

Effect Effect { get; set; }

Get / Set the Effect to use to draw the Particles

ParticleEmitter Emitter { get; set; }

The Emitter is used to automatically generate new Particles.

NOTE: This is just a pointer to one of the ParticleEmitters in the Emitters ParticleEmitterCollection.

NOTE: If you set this to a ParticleEmitter that is not in the Emitters collection, it will be added to it.

During the particle system Update() this Emitter property is updated to point to the ParticleEmitter in the Emitters collection that is being updated.

The Emitters used to automatically generate new Particles for this Particle System.

Each particle system Update() will loop through all Emitters in this collection and add their new particles to this particle system.

During the particle system Update() the Emitter property is updated to point to the ParticleEmitter in this collection that is being updated.

bool Enabled { get; set; }

Get / Set if this Particle System should Update itself and its Particles or not.

NOTE: Setting this to false causes the Update() function to not update anything.

Game Game { get; }

Get the Game object set in the constructor, if one was given.

GraphicsDevice GraphicsDevice { get; }

Get the Graphics Device to draw to

int ID { get; }

Get the unique ID of this Particle System.

NOTE: Each Particle System is automatically assigned a unique ID when it is instantiated.

Get if the Particle System is inheriting from DrawableGameComponent or not.

If inheriting from DrawableGameComponent, the Particle Systems are automatically added to the given Game object's Components and the Update() and Draw() functions are automatically called by the Game object when it updates and draws the rest of its Components. If the Update() and Draw() functions are called by the user anyways, they will exit without performing any operations, so it is suggested to include them anyways to make switching between inheriting and not inheriting from DrawableGameComponent seamless; just be aware that the updates and draws are actually being performed when the Game object is told to update and draw (i.e. when base.Update() and base.Draw() are called), not when these functions are being called.

float InternalSimulationSpeed { get; set; }

Get / Set how fast the Particle System Simulation should run to look "normal".

1.0 = normal speed, 0.5 = half speed, 2.0 = double speed.

This is provided as a way of speeding up / slowing down the simulation to have it look as desired, without having to rescale all of the particle velocities, etc. This allows you to use the exact same particle system class to create two particle systems, and then have one run slower or faster than the other, creating two different effects. If you then wanted to speed up or slow down both effects (i.e. particle systems), you could adjust the SimulationSpeed property on both particle systems without having to worry about adjusting this property at all to get the effects back to normal speed; just reset the SimulationSpeed property you changed back to 1.0.

NOTE: If a negative value is specified, the Internal Simulation Speed is set to zero (pauses the simulation; has the same effect as Enabled = false).

bool IsInitialized { get; }

Returns true if the Particle System is Initialized, false if not.

int MaxNumberOfParticlesAllowed { get; set; }

Get / Set the Max Number of Particles this Particle System is Allowed to contain at any given time.

NOTE: The Automatic Memory Manager will never allocate space for more Particles than this.

NOTE: This value must be greater than or equal to zero.

Get the number of Particles that are currently Active.

Get / Set the absolute Number of Particles to Allocate Memory for.

NOTE: This value must be greater than or equal to zero.

NOTE: Even if this many particles aren't used, the space for this many Particles is still allocated in memory.

Get the number of Particles being Drawn. That is, how many Particles are both Active AND Visible.

Get the number of Particles that may still be added before reaching the Max Number Of Particles Allowed. If the Max Number Of Particles Allowed is greater than the Number Of Particles Allocated In Memory AND the Auto Memory Manager is set to not increase the amount of Allocated Memory, than this returns the number of Particles that may still be added before running out of Memory.

The Particle System Manager whose properties (SimulationSpeed and UpdatesPerSecond) this particle system should follow.

NOTE: This Particle System's properties will only clone the Manager's properties if the Manager's properties are Enabled. For example, the Manager's SimulationSpeed will only be copied to this Particle System if the Manager's SimulationSpeedIsEnabled property is true.

NOTE: This value is automatically set to the last Particle System Manager this Particle System is added to.

Get the type of Particles that this Particle System should draw.

bool PerformanceProfilingIsEnabled { get; set; }

Get / Set if performance timings should be measured or not, such as how long it takes to perform updates and draws.

This should be disabled before building a release version of your application.

Note: Performance profiling is not available on the Reach profile, so this will always return False on the Reach profile.

Get how long (in milliseconds) it took to perform the last Draw() function call.

Returns 0 if Performance Profiling is not Enabled.

Get how long (in milliseconds) it took to perform the last Update() function call.

Returns 0 if Performance Profiling is not Enabled.

Matrix Projection { get; set; }

Get / Set the Projection Matrix to use for drawing 3D Particles.

Get a Random object used to generate Random Numbers.

Get the render properties used to draw the particles.

float SimulationSpeed { get; set; }

Get / Set how fast the Particle System Simulation should run.

1.0 = normal speed, 0.5 = half speed, 2.0 = double speed.

NOTE: If a negative value is specified, the Speed Scale is set to zero (pauses the simulation; has same effect as Enabled = false).

SpriteBatch SpriteBatch { get; }

Returns the SpriteBatch used to draw the Sprite particles.

NOTE: If this is not a Sprite particle system, this will return null.

The Sprite Batch drawing Settings used in the Sprite Batch's Begin() function call.

NOTE: These settings only have effect if this is a Sprite particle system.

EffectTechnique Technique { get; set; }

Get / Set which Technique of the current Effect to use to draw the Particles

Texture2D Texture { get; set; }

Get / Set the Texture to use to draw the Particles

Get the number of particles that are currently Active, in both this particle system and any particle systems contained within this one.

NOTE: Because a particle system may contain other particle systems, this is a virtual function that may be overridden to return the NumberOfActiveParticles for both this particle system and any child particle systems that are contained within this one.

NOTE: By default this just returns this particle system's NumberOfActiveParticles.

Get the number of particles that memory has been allocated for, for both this particle system and any particle systems contained within this one.

NOTE: Because a particle system may contain other particle systems, this is a virtual function that may be overridden to return the NumberOfParticlesAllocatedInMemory for both this particle system and any child particle systems that are contained within this one.

NOTE: By default this just returns this particle system's NumberOfParticlesAllocatedInMemory.

Get the number of particles that are being Drawn, in both this particle system and any particle systems contained within this one.

NOTE: Because a particle system may contain other particle systems, this is a virtual function that may be overridden to return the NumberOfParticlesBeingDrawn for both this particle system and any child particle systems that are contained within this one.

NOTE: By default this just returns this particle system's NumberOfParticlesBeingDrawn.

int Type { get; set; }

Get / Set the Type of Particle System this is.

int UpdateOrder { get; set; }

The Order in which the Particle System should be Updated relative to other DPSF Particle Systems in the same Particle System Manager. Particle Systems are Updated in ascending order according to their Update Order (i.e. lowest first).

int UpdatesPerSecond { get; set; }

Specify how often the Particle System should be Updated.

NOTE: Specifying a value of zero (default) will cause the Particle System to be Updated every time the Update() function is called (i.e. as often as possible).

NOTE: If the Update() function is not called often enough to keep up with this specified Update rate, the Update function updates the Particle Systems as often as possible.

Returns if this particle system is dependent on an external Sprite Batch to draw its particles or not.

If false, the particle system will use its own SpriteBatch to draw its particles.

If true, then you must call SpriteBatch.Begin() before calling ParticleSystem.Draw() to draw the particle system, and then call SpriteBatch.End() when done drawing the particle system, where the SpriteBatch referred to here is the one you passed into the InitializeSpriteParticleSystem() function.

NOTE: This property only applies to Sprite particle systems.

Matrix View { get; set; }

Get / Set the View Matrix to use for drawing 3D Particles.

bool Visible { get; set; }

Get / Set if this Particle System should Draw its Particles or not.

NOTE: Setting this to false causes the Draw() function to not draw anything.

Matrix World { get; set; }

Get / Set the World Matrix to use for drawing 3D Particles.

Matrix WorldViewProjection { get; }

Gets the result of multiplying the World, View, and Projection matrices.

Event Handler that is raised when the DrawOrder of the Particle System is changed

Event Handler that is raised when the Enabled status of the Particle System is changed

Event Handler that is raised when the UpdateOrder of the Particle System is changed

Event Handler that is raised when the Visible status of the Particle System is changed

bool AddParticle()

Adds a new Particle to the particle system, at the start of the Active Particle List. This new Particle is initialized using the particle system's Particle Initialization Function

int AddParticles(int iNumberOfParticlesToAdd)

Adds the specified number of new Particles to the particle system. These new Particles are initialized using the particle systems Particle Initialization Function

void AutoInitialize(GraphicsDevice cGraphicsDevice, ContentManager cContentManager, SpriteBatch cSpriteBatch)

Virtual function to Initialize the Particle System with default values. Particle system properties should not be set until after this is called, as they are likely to be reset to their default values.

void Destroy()

Release all resources used by the Particle System and reset all properties to their default values

void Draw()

Draws all of the Active Particles to the Graphics Device

void DrawForced()

Draws all of the Active Particles to the Graphics Device, even if the the Particle Systems inherits from DrawableGameComponent.

NOTE: If inheriting from DrawableGameComponent and this is called, the Particle System will be drawn twice per frame; once when it is called here, and again when automatically called by the Game object. If not inheriting from DrawableGameComponent, this acts the same as calling Draw().

void InitializeNonSerializableProperties(Game cGame, GraphicsDevice cGraphicsDevice, ContentManager cContentManager)

This function should be called immediately after deserializing a particle system in order to reinitialize the properties that could not be serialized.

NOTE: If this type of particle system requires a Texture, this function will attempt to load the Texture specified by the DeserializationTexturePath property. If it is unable to load a texture, a DPSFArgumentNullException will be thrown, so this function should be wrapped in a try block, and when a DPSFArgumentNullException is caught then the particle system's texture should be manually set.

NOTE: This will attempt to load the Effect and Technique specified by the DeserializationEffectPath and DeserializationTechniqueName properties. If either of these are null, the DPSFDefaultEffect will be used, and the default Technique for this type of particle system will be loaded.

Removes all Active Particles from the Active Particle List and adds them to the Inactive Particle List

void SetCameraPosition(Vector3 cameraPosition)

Sets the Camera Position of the particle system, so that the particles know how to make themselves face the camera if needed. This virtual function does not do anything unless overridden, and all it should do is set an internal Vector3 variable (e.g. public Vector3 CameraPosition { get; set; }) to match the given Vector3.

Sets the Effect to be the DPSFDefaultEffect, and the Technique to be the default technique for this type of particle system. This is done automatically when the particle system is initialized.

void SetEffectAndTechnique(string sEffect, string sTechnique)

Sets the Effect and Technique to use to draw the Particles

void SetEffectAndTechnique(Effect cEffect, string sTechnique)

Sets the Effect and Technique to use to draw the Particles

void SetTechnique(string sTechnique)

Set which Technique of the current Effect to use to draw the Particles

void SetTexture(string sTexture)

Set the Texture to use to draw the Particles

void SetWorldViewProjectionMatrices(Matrix cWorld, Matrix cView, Matrix cProjection)

Set the World, View, and Projection matrices for this Particle System.

void Update(float fElapsedTimeInSeconds)

Updates the Particle System. This involves executing the Particle System Events, updating all Active Particles according to the Particle Events, and adding new Particles according to the Emitter settings.

void UpdateForced(float fElapsedTimeInSeconds)

Updates the Particle System, even if the the Particle Systems inherits from DrawableGameComponent.

Updating the Particle System involves executing the Particle System Events, updating all Active Particles according to the Particle Events, and adding new Particles according to the Emitter settings.

NOTE: If inheriting from DrawableGameComponent and this is called, the Particle System will be updated twice per frame; once when it is called here, and again when automatically called by the Game object. If not inheriting from DrawableGameComponent, this acts the same as calling Update().