From 0afd2cf7ecbd591188fd65ba7b456b929e8b493f Mon Sep 17 00:00:00 2001 From: James Turk Date: Thu, 10 Jul 2003 23:45:08 +0000 Subject: [PATCH] various fixes --- include/ZE_ZBaseParticleSystem.h | 111 ++++++++++++++++++++++++----- include/ZE_ZSimpleParticleSystem.h | 18 ++++- 2 files changed, 110 insertions(+), 19 deletions(-) diff --git a/include/ZE_ZBaseParticleSystem.h b/include/ZE_ZBaseParticleSystem.h index 1f8b50a..c409151 100755 --- a/include/ZE_ZBaseParticleSystem.h +++ b/include/ZE_ZBaseParticleSystem.h @@ -14,7 +14,7 @@ Definition and implementation file for ZEngine particle system class ZBaseParticleSystem. Due to problems with template classes the template implementation needs to be in the same file as the declaration. -
$Id: ZE_ZBaseParticleSystem.h,v 1.2 2003/07/10 19:20:56 cozman Exp $
+
$Id: ZE_ZBaseParticleSystem.h,v 1.3 2003/07/10 23:45:08 cozman Exp $
\author James Turk **/ @@ -75,6 +75,8 @@ class ZBaseParticleSystem unsigned int rNumParticlesPerSec; //! Millisecond format time of last update. Uint32 rLastUpdate; + //! Boolean value indicating if system is paused. + bool rPaused; /*! \brief Adds a new particle. @@ -133,9 +135,46 @@ class ZBaseParticleSystem \brief Updates status of particle system. Updates entire particle system, calling update on every particle, emitting necessary new - particles, removing particles which have an energy <= 0 or are off the screen. + particles, removing particles which have an energy <= 0 or are off the screen. Virtual for + special cases, but generally should not be overridden. **/ - void Update(); + virtual void Update(); + + /*! + \brief Empties particle system of all particles. + + Empties particle system of all particles, does not alter paused state. + **/ + void Clear(); + + /*! + \brief Pauses particle system. + + Pauses particle system, particles may still be drawn but particles are not updated. + **/ + void Pause(); + + /*! + \brief Unpauses particle system. + + Returns particle system to active state, system starts unpaused. + **/ + void Unpause(); + + /*! + \brief Clears system and pauses it. + + Same as calling Clear() and then Pause(), use unpause to restart system. + **/ + void Stop(); + + /*! + \brief Detect if particle system is currently paused. + + Returns bool indicating if the particle system is currently paused. + \return true if paused, false if active + **/ + bool Paused(); /*! \brief Sets max particles allowed in system. @@ -172,6 +211,7 @@ ZBaseParticleSystem::ZBaseParticleSystem() rParticles = NULL; rMaxParticles = rCurParticles = rNumParticlesPerSec = 0; rLastUpdate = rEngine->GetTime(); + rPaused = false; } template @@ -198,28 +238,63 @@ void ZBaseParticleSystem::Update() double emitAmount; static double overflow=0; - //update every particle and remove dead particles - for(unsigned int i=0; i < rCurParticles; ++i) + if(!rPaused) { - UpdateParticle(i,elapsed); - if(rParticles[i].xPos < 0 || rParticles[i].xPos > rEngine->Width() - || rParticles[i].yPos < 0 || rParticles[i].yPos > rEngine->Height() || rParticles[i].energy <= 0) + //update every particle and remove dead particles + for(unsigned int i=0; i < rCurParticles; ++i) { - rParticles[i] = rParticles[--rCurParticles]; - --i; //go back one to process that particle + UpdateParticle(i,elapsed); + if(rParticles[i].xPos < 0 || rParticles[i].xPos > rEngine->Width() + || rParticles[i].yPos < 0 || rParticles[i].yPos > rEngine->Height() || rParticles[i].energy <= 0) + { + rParticles[i] = rParticles[--rCurParticles]; + --i; //go back one to process that particle + } + } + + emitAmount = elapsed*rNumParticlesPerSec; + overflow += emitAmount - static_cast(emitAmount); //only floating point portion of emitAmount + Emit(static_cast(emitAmount)); + if(overflow >= .95) //a little lower than one, for tolerance + { + Emit(1); + overflow = 0; //dump & clear overflow } } rLastUpdate = rEngine->GetTime(); +} - emitAmount = elapsed*rNumParticlesPerSec; - overflow += emitAmount - static_cast(emitAmount); //only floating point portion of emitAmount - Emit(static_cast(emitAmount)); - if(overflow >= .95) //a little lower than one, for tolerance - { - Emit(1); - overflow = 0; //dump & clear overflow - } + +template +void ZBaseParticleSystem::Clear() +{ + rCurParticles = 0; +} + +template +void ZBaseParticleSystem::Pause() +{ + rPaused = true; +} + +template +void ZBaseParticleSystem::Unpause() +{ + rPaused = false; +} + +template +void ZBaseParticleSystem::Stop() +{ + Clear(); + Pause(); +} + +template +bool ZBaseParticleSystem::Paused() +{ + return rPaused; } template diff --git a/include/ZE_ZSimpleParticleSystem.h b/include/ZE_ZSimpleParticleSystem.h index 5e0a069..52f2a8d 100755 --- a/include/ZE_ZSimpleParticleSystem.h +++ b/include/ZE_ZSimpleParticleSystem.h @@ -14,7 +14,7 @@ Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem. Due to problems with template classes the template implementation needs to be in the same file as the declaration. -
$Id: ZE_ZSimpleParticleSystem.h,v 1.2 2003/07/10 19:21:36 cozman Exp $
+
$Id: ZE_ZSimpleParticleSystem.h,v 1.3 2003/07/10 23:45:09 cozman Exp $
\author James Turk **/ @@ -162,6 +162,13 @@ class ZSimpleParticleSystem : public ZBaseParticleSystem **/ virtual void Render(); + /*! + \brief Reload image. + + Reload image if mode is DS_IMAGE, usage is same as ZImage::Reload. + **/ + void ReloadImage(); + /*! \brief Sets ParticleDrawStyle for this system. @@ -272,6 +279,8 @@ void ZSimpleParticleSystem::UpdateParticle(int index, float elapse rParticles[index].yPos += rParticles[index].yVel*elapsedTime; rParticles[index].size += rParticles[index].sizeDelta*elapsedTime; rParticles[index].energy += rParticles[index].energyDelta*elapsedTime; + if(rParticles[index].size <= 0) + rParticles[index].energy = 0; } template @@ -323,6 +332,13 @@ void ZSimpleParticleSystem::Render() } } +template +void ZSimpleParticleSystem::ReloadImage() +{ + if(rStyle == DS_IMAGE) + rImage.Reload(); +} + template void ZSimpleParticleSystem::SetDrawStyle(ParticleDrawStyle style) {