3
* Copyright (C) 2008-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include "particlecontainer.h"
28
typedef std::list<Particle *>::iterator ParticleListIter;
29
typedef std::list<Particle *>::const_iterator ParticleListCIter;
31
ParticleContainer::ParticleContainer(ParticleContainer *const parent,
32
const bool delParent):
38
ParticleContainer::~ParticleContainer()
48
void ParticleContainer::clear()
55
void ParticleContainer::moveTo(const float x, const float y)
61
// -- particle list ----------------------------------------
63
ParticleList::ParticleList(ParticleContainer *const parent,
64
const bool delParent) :
65
ParticleContainer(parent, delParent),
69
ParticleList::~ParticleList()
72
void ParticleList::addLocally(Particle *const particle)
76
// The effect may not die without the beings permission or we segfault
77
particle->disableAutoDelete();
78
mElements.push_back(particle);
82
void ParticleList::removeLocally(const Particle *const particle)
84
for (std::list<Particle *>::iterator it = mElements.begin();
85
it != mElements.end(); )
87
Particle *const p = *it;
91
it = mElements.erase(it);
100
void ParticleList::clearLocally()
102
FOR_EACH (ParticleListCIter, it, mElements)
108
void ParticleList::moveTo(const float x, const float y)
110
ParticleContainer::moveTo(x, y);
112
for (std::list<Particle *>::iterator it = mElements.begin();
113
it != mElements.end(); )
115
Particle *const p = *it;
120
it = mElements.erase(it);
129
// -- particle vector ----------------------------------------
131
ParticleVector::ParticleVector(ParticleContainer *const parent,
132
const bool delParent) :
133
ParticleContainer(parent, delParent),
137
ParticleVector::~ParticleVector()
140
void ParticleVector::setLocally(const int index, Particle *const particle)
147
if (mIndexedElements.size() <= static_cast<unsigned>(index))
148
mIndexedElements.resize(index + 1, nullptr);
151
particle->disableAutoDelete();
152
mIndexedElements[index] = particle;
155
void ParticleVector::delLocally(const int index)
160
if (mIndexedElements.size() <= static_cast<unsigned>(index))
163
Particle *const p = mIndexedElements[index];
166
mIndexedElements[index] = nullptr;
171
void ParticleVector::clearLocally()
173
for (unsigned int i = 0; i < mIndexedElements.size(); i++)
177
void ParticleVector::moveTo(const float x, const float y)
179
ParticleContainer::moveTo(x, y);
181
for (std::vector<Particle *>::iterator it = mIndexedElements.begin();
182
it != mIndexedElements.end(); ++it)
184
Particle *const p = *it;