sparrowParticles

SparrowParticles is a very basic, generic attempt for particles.

Summary
sparrowParticlesSparrowParticles is a very basic, generic attempt for particles.
Types
spParticleStruct for one partcle.
Macros
Events for the particle bunch update function
Functions
spParticleCreateCreates a bunch of a fixed number of particles.
spParticleUpdateUpdates all particles of the particles bunch and connected bunches.
spParticleDrawDraws all particles of the particles bunch and connected bunches.
spParticleDeleteDeletes all particles of the particles bunch and connected bunches.
spParticleFromSpriteThis special function creates a particle bunch out of a sprite.

Types

spParticle

Struct for one partcle.

Variables

x,y,z (Sint32)position of the particle
dx,dy,dz (Sint32)velocity of the particle
status (Sint32)status of the particle.  < 0 means death, >= 0 means alive
data (union)first element is color, but can be used in any way with the 9 reserved fields.

Macros

Events for the particle bunch update function

SP_PARTICLE_DRAWthe particles shall be drawn
SP_PARTICLE_UPDATEthe particles shall be updated
SP_PARTICLE_CLEAN_UPif the particles e.g. allocated memory, free it NOW

Functions

spParticleCreate

PREFIX spParticleBunchPointer spParticleCreate(
   int count,
   int ( *feedback )( spParticleBunchPointer bunch, Sint32 action, Sint32 extra_data),
   spParticleBunchPointer *addBunch
)

Creates a bunch of a fixed number of particles.  In every update or draw step the feedback function will be called ONCE for all particles of the bunch (which is faster than doing this for every particle).

Parameters

countnumber of particles.  It is not possible to add particles later, but to create a new particle bunch and add it to this bunch (see last parameter)
feedbacka feedback function, which shall have the parameters spParticleBunchPointer bunch, Sint32 action and Sint32 extra_data.  The bunch is the bunch returned by this function, action tells the feedback function, what to do (see also Events for the particle bunch update function) and extra_data gives some extra data for some actions, e.g. the time since the last frame in ms if the action is SP_PARTICLE_UPDATE.
addBunchif not NULL, this new created particle bunch will be added to the given bunch.  Usefull to keep your particle bunches in meta particle bunches and to call spParticleUpdate, spParticleDraw and spParticleDelete just once.

Returns

Pointer of spParticleBunchpointer to the created particle bunch, but be carful!  The data are unset!  It is up to you to fill the bunch with positions, velocities, colours and other metadata (see also spParticle)!

spParticleUpdate

PREFIX void spParticleUpdate(spParticleBunchPointer *firstBunch,
int steps)

Updates all particles of the particles bunch and connected bunches.  It does this by calling the feedback function of the bunches with the action SP_PARTICLE_UPDATE!

Parameters

firstBunchthe first bunch to update it’s particles
stepsthe time since the last frame to pass to the feedback function

spParticleDraw

PREFIX void spParticleDraw(spParticleBunchPointer firstBunch)

Draws all particles of the particles bunch and connected bunches.  It does this by calling the feedback function of the bunches with the action SP_PARTICLE_DRAW!

Parameters

firstBunchthe first bunch to update it’s particles

spParticleDelete

PREFIX void spParticleDelete(spParticleBunchPointer *firstBunch)

Deletes all particles of the particles bunch and connected bunches.  Right before deleting, it calls the feedback function one last time with the action SP_PARTICLE_CLEAN_UP, which tells the feedback function clean up stuff if necessary.

Parameters

firstBunchthe first bunch to update it’s particles

spParticleFromSprite

PREFIX spParticleBunchPointer spParticleFromSprite(
   spSpritePointer sprite,
   int ( *feedback )( spParticleBunchPointer bunch, Sint32 action, Sint32 extra_data),
   spParticleBunchPointer *addBunch
)

This special function creates a particle bunch out of a sprite.  Useful for sprites, which shall explode.  Every particle stand for a pixel of the sprite.

Parameters

spritespSpritePointer to use
feedbackfeedback function for this bunch.  See alo spParticleCreate.
addBunchoptional meta bunch to add this bunch to.  See also spParticleCreate.

Returns

Pointer of spParticleBunchpointer to the created particle bunch.  But be careful!  The positions and colours of the sprite are set, furthermore an “exploding” velocity, but keep in mind to scale this data to your system.  ;)
PREFIX spParticleBunchPointer spParticleCreate(
   int count,
   int ( *feedback )( spParticleBunchPointer bunch, Sint32 action, Sint32 extra_data),
   spParticleBunchPointer *addBunch
)
Creates a bunch of a fixed number of particles.
PREFIX void spParticleUpdate(spParticleBunchPointer *firstBunch,
int steps)
Updates all particles of the particles bunch and connected bunches.
PREFIX void spParticleDraw(spParticleBunchPointer firstBunch)
Draws all particles of the particles bunch and connected bunches.
PREFIX void spParticleDelete(spParticleBunchPointer *firstBunch)
Deletes all particles of the particles bunch and connected bunches.
PREFIX spParticleBunchPointer spParticleFromSprite(
   spSpritePointer sprite,
   int ( *feedback )( spParticleBunchPointer bunch, Sint32 action, Sint32 extra_data),
   spParticleBunchPointer *addBunch
)
This special function creates a particle bunch out of a sprite.
Struct for one partcle.
Close