ManaPlus
particlelist.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
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
12  * any later version.
13  *
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.
18  *
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/>.
21  */
22 
23 #include "particle/particlelist.h"
24 
25 #include "utils/foreach.h"
26 
27 #include "particle/particle.h"
28 
29 #include "debug.h"
30 
31 typedef std::list<Particle *>::iterator ParticleListIter;
32 typedef std::list<Particle *>::const_iterator ParticleListCIter;
33 
35  const bool delParent) :
36  ParticleContainer(parent, delParent),
37  mElements(),
38  mSize(0U)
39 {}
40 
42 {
43 }
44 
45 void ParticleList::addLocally(Particle *const particle)
46 {
47  if (particle != nullptr)
48  {
49  mElements.push_back(particle);
50  mSize ++;
51  }
52 }
53 
54 void ParticleList::removeLocally(const Particle *const particle)
55 {
56  for (std::list<Particle *>::iterator it = mElements.begin();
57  it != mElements.end(); )
58  {
59  Particle *const p = *it;
60  if (p == particle)
61  {
62  p->kill();
63  p->prepareToDie();
64  it = mElements.erase(it);
65  mSize --;
66  }
67  else
68  {
69  ++it;
70  }
71  }
72 }
73 
75 {
77  {
78  (*it)->kill();
79  (*it)->prepareToDie();
80  }
81 
82  mElements.clear();
83  mSize = 0U;
84 }
85 
86 void ParticleList::moveTo(const float x, const float y)
87 {
89 
90  for (std::list<Particle *>::iterator it = mElements.begin();
91  it != mElements.end(); )
92  {
93  Particle *const p = *it;
94  p->moveTo(x, y);
95  if (p->isExtinct())
96  {
97  p->kill();
98  it = mElements.erase(it);
99  mSize --;
100  }
101  else
102  {
103  ++it;
104  }
105  }
106 }
void addLocally(Particle *const particle)
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void prepareToDie()
Definition: particle.cpp:564
void kill()
Definition: particle.h:219
size_t mSize
Definition: particlelist.h:66
void clearLocally()
bool isExtinct() const
Definition: particle.h:213
virtual void moveTo(const float x, const float y)
void moveTo(const Vector &pos)
Definition: particle.h:106
std::list< Particle * > mElements
Definition: particlelist.h:65
void moveTo(const float x, const float y)
std::list< Particle * >::iterator ParticleListIter
ParticleList(ParticleContainer *const parent, const bool delParent)
void removeLocally(const Particle *const particle)
std::list< Particle * >::const_iterator ParticleListCIter