00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cassert>
00023
00024 #include "particle.h"
00025 #include "particlecontainer.h"
00026
00027
00028 ParticleContainer::ParticleContainer(ParticleContainer *parent,
00029 bool delParent):
00030 mDelParent(delParent),
00031 mNext(parent)
00032 {}
00033
00034 ParticleContainer::~ParticleContainer()
00035 {
00036 clearLocally();
00037 if (mDelParent)
00038 delete mNext;
00039 }
00040
00041 void ParticleContainer::clear()
00042 {
00043 clearLocally();
00044 if (mNext)
00045 mNext->clear();
00046 }
00047
00048 void ParticleContainer::moveTo(float x, float y)
00049 {
00050 if (mNext)
00051 mNext->moveTo(x, y);
00052 }
00053
00054
00055
00056 ParticleList::ParticleList(ParticleContainer *parent, bool delParent):
00057 ParticleContainer(parent, delParent)
00058 {}
00059
00060 ParticleList::~ParticleList()
00061 {}
00062
00063 void ParticleList::addLocally(Particle *particle)
00064 {
00065 if (particle)
00066 {
00067
00068 particle->disableAutoDelete();
00069 mElements.push_back(particle);
00070 }
00071 }
00072
00073 void ParticleList::removeLocally(Particle *particle)
00074 {
00075 for (std::list<Particle *>::iterator it = mElements.begin();
00076 it != mElements.end(); it++)
00077 {
00078 if (*it == particle) {
00079 (*it)->kill();
00080 mElements.erase(it);
00081 }
00082 }
00083 }
00084
00085 void ParticleList::clearLocally()
00086 {
00087 for (std::list<Particle *>::iterator it = mElements.begin();
00088 it != mElements.end(); it++)
00089 (*it)->kill();
00090
00091 mElements.clear();
00092 }
00093
00094 void ParticleList::moveTo(float x, float y)
00095 {
00096 ParticleContainer::moveTo(x, y);
00097
00098 for (std::list<Particle *>::iterator it = mElements.begin();
00099 it != mElements.end();)
00100 {
00101 (*it)->moveTo(x, y);
00102 if ((*it)->isExtinct())
00103 {
00104 (*it)->kill();
00105 it = mElements.erase(it);
00106 }
00107 else
00108 it++;
00109 }
00110 }
00111
00112
00113
00114 ParticleVector::ParticleVector(ParticleContainer *parent, bool delParent):
00115 ParticleContainer(parent, delParent)
00116 {}
00117
00118 ParticleVector::~ParticleVector()
00119 {}
00120
00121 void ParticleVector::setLocally(int index, Particle *particle)
00122 {
00123 assert(index >= 0);
00124
00125 delLocally(index);
00126
00127 if (mIndexedElements.size() <= (unsigned) index)
00128 mIndexedElements.resize(index + 1, NULL);
00129
00130 if (particle)
00131 particle->disableAutoDelete();
00132 mIndexedElements[index] = particle;
00133 }
00134
00135 void ParticleVector::delLocally(int index)
00136 {
00137 assert(index >= 0);
00138
00139 if (mIndexedElements.size() <= (unsigned) index)
00140 return;
00141
00142 Particle *p = mIndexedElements[index];
00143 if (p)
00144 {
00145 mIndexedElements[index] = NULL;
00146 p->kill();
00147 }
00148 }
00149
00150 void ParticleVector::clearLocally()
00151 {
00152 for (unsigned int i = 0; i < mIndexedElements.size(); i++)
00153 delLocally(i);
00154 }
00155
00156 void ParticleVector::moveTo(float x, float y)
00157 {
00158 ParticleContainer::moveTo(x, y);
00159
00160 for (std::vector<Particle *>::iterator it = mIndexedElements.begin();
00161 it != mIndexedElements.end(); it++) {
00162 if (*it)
00163 {
00164 (*it)->moveTo(x, y);
00165
00166 if ((*it)->isExtinct())
00167 {
00168 (*it)->kill();
00169 *it = NULL;
00170 }
00171 }
00172 }
00173 }
00174