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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "particle/particlelist.h"
25 
26 #include "utils/foreach.h"
27 
28 #include "particle/particle.h"
29 
30 #include "debug.h"
31 
32 typedef std::list<Particle *>::iterator ParticleListIter;
33 typedef std::list<Particle *>::const_iterator ParticleListCIter;
34 
36  const bool delParent) :
37  ParticleContainer(parent, delParent),
38  mElements(),
39  mSize(0U)
40 {}
41 
43 {
44 }
45 
46 void ParticleList::addLocally(Particle *const particle)
47 {
48  if (particle != nullptr)
49  {
50  mElements.push_back(particle);
51  mSize ++;
52  }
53 }
54 
55 void ParticleList::removeLocally(const Particle *const particle)
56 {
57  for (std::list<Particle *>::iterator it = mElements.begin();
58  it != mElements.end(); )
59  {
60  Particle *const p = *it;
61  if (p == particle)
62  {
63  p->kill();
64  p->prepareToDie();
65  it = mElements.erase(it);
66  mSize --;
67  }
68  else
69  {
70  ++it;
71  }
72  }
73 }
74 
76 {
78  {
79  (*it)->kill();
80  (*it)->prepareToDie();
81  }
82 
83  mElements.clear();
84  mSize = 0U;
85 }
86 
87 void ParticleList::moveTo(const float x, const float y)
88 {
90 
91  for (std::list<Particle *>::iterator it = mElements.begin();
92  it != mElements.end(); )
93  {
94  Particle *const p = *it;
95  p->moveTo(x, y);
96  if (p->isExtinct())
97  {
98  p->kill();
99  it = mElements.erase(it);
100  mSize --;
101  }
102  else
103  {
104  ++it;
105  }
106  }
107 }
virtual void moveTo(const float x, const float y)
void addLocally(Particle *const particle)
void clearLocally()
size_t mSize
Definition: particlelist.h:67
std::list< Particle * > mElements
Definition: particlelist.h:66
ParticleList(ParticleContainer *const parent, const bool delParent)
void moveTo(const float x, const float y)
void removeLocally(const Particle *const particle)
void kill()
Definition: particle.h:220
void prepareToDie()
Definition: particle.cpp:565
bool isExtinct() const
Definition: particle.h:214
void moveTo(const Vector &pos)
Definition: particle.h:107
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
std::list< Particle * >::iterator ParticleListIter
std::list< Particle * >::const_iterator ParticleListCIter