ManaPlus
Public Member Functions | Protected Attributes
ParticleVector Class Reference

#include <particlevector.h>

Inheritance diagram for ParticleVector:
ParticleContainer

Public Member Functions

 ParticleVector (ParticleContainer *const parent, const bool delParent)
 
 ~ParticleVector ()
 
void setLocally (const int index, Particle *const particle)
 
void delLocally (const int index)
 
void clearLocally ()
 
void moveTo (const float x, const float y)
 
size_t size () const
 
size_t usedSize () const
 
- Public Member Functions inherited from ParticleContainer
 ParticleContainer (ParticleContainer *const parent, const bool delParent)
 
virtual ~ParticleContainer ()
 
void clear ()
 

Protected Attributes

std::vector< Particle * > mIndexedElements
 
- Protected Attributes inherited from ParticleContainer
ParticleContainermNext
 
bool mDelParent
 

Detailed Description

Particle container with indexing facilities

Definition at line 38 of file particlevector.h.

Constructor & Destructor Documentation

◆ ParticleVector()

ParticleVector::ParticleVector ( ParticleContainer *const  parent,
const bool  delParent 
)

Definition at line 29 of file particlevector.cpp.

30  :
31  ParticleContainer(parent, delParent),
33 {}
ParticleContainer(ParticleContainer *const parent, const bool delParent)
std::vector< Particle * > mIndexedElements

◆ ~ParticleVector()

ParticleVector::~ParticleVector ( )

Definition at line 35 of file particlevector.cpp.

36 {}

Member Function Documentation

◆ clearLocally()

void ParticleVector::clearLocally ( )
virtual

Kills and removes all particle effects (only in this container)

Reimplemented from ParticleContainer.

Definition at line 69 of file particlevector.cpp.

70 {
71  for (unsigned int i = 0;
72  i < CAST_U32(mIndexedElements.size());
73  i++)
74  {
75  delLocally(i);
76  }
77 }
#define CAST_U32
Definition: cast.h:31
void delLocally(const int index)

References CAST_U32, delLocally(), and mIndexedElements.

◆ delLocally()

void ParticleVector::delLocally ( const int  index)

Removes a particle at a specified index

Definition at line 53 of file particlevector.cpp.

54 {
55  if (index < 0)
56  return;
57 
58  if (mIndexedElements.size() <= CAST_SIZE(index))
59  return;
60 
61  Particle *const p = mIndexedElements[index];
62  if (p != nullptr)
63  {
64  mIndexedElements[index] = nullptr;
65  p->kill();
66  }
67 }
#define CAST_SIZE
Definition: cast.h:34
void kill()
Definition: particle.h:220

References CAST_SIZE, Particle::kill(), and mIndexedElements.

Referenced by clearLocally(), ActorSprite::handleStatusEffect(), and setLocally().

◆ moveTo()

void ParticleVector::moveTo ( const float  x,
const float  y 
)
virtual

Sets the positions of all elements

Reimplemented from ParticleContainer.

Definition at line 79 of file particlevector.cpp.

80 {
82 
83  for (STD_VECTOR<Particle *>::iterator it = mIndexedElements.begin();
84  it != mIndexedElements.end(); ++it)
85  {
86  Particle *const p = *it;
87  if (p != nullptr)
88  {
89  p->moveTo(x, y);
90 
91  if (p->isExtinct())
92  {
93  p->kill();
94  *it = nullptr;
95  }
96  }
97  }
98 }
virtual void moveTo(const float x, const float y)
bool isExtinct() const
Definition: particle.h:214
void moveTo(const Vector &pos)
Definition: particle.h:107

References Particle::isExtinct(), Particle::kill(), mIndexedElements, ParticleContainer::moveTo(), Particle::moveTo(), x, and y.

◆ setLocally()

void ParticleVector::setLocally ( const int  index,
Particle *const  particle 
)

Sets a particle at a specified index. Kills the previous particle there, if needed.

Definition at line 38 of file particlevector.cpp.

39 {
40  if (index < 0)
41  return;
42 
43  delLocally(index);
44 
45  if (mIndexedElements.size() <= CAST_SIZE(index))
46  mIndexedElements.resize(index + 1, nullptr);
47 
48  if (particle != nullptr)
49  particle->disableAutoDelete();
50  mIndexedElements[index] = particle;
51 }
void disableAutoDelete()
Definition: particle.h:227

References CAST_SIZE, delLocally(), Particle::disableAutoDelete(), and mIndexedElements.

Referenced by ActorSprite::handleStatusEffect().

◆ size()

size_t ParticleVector::size ( ) const
inline

Definition at line 63 of file particlevector.h.

64  { return mIndexedElements.size(); }

References mIndexedElements.

◆ usedSize()

size_t ParticleVector::usedSize ( ) const

Definition at line 100 of file particlevector.cpp.

101 {
102  size_t cnt = 0;
103  for (STD_VECTOR<Particle *>::const_iterator it = mIndexedElements.begin();
104  it != mIndexedElements.end(); ++it)
105  {
106  if (*it != nullptr)
107  cnt ++;
108  }
109  return cnt;
110 }

References mIndexedElements.

Referenced by ActorSprite::getParticlesCount().

Field Documentation

◆ mIndexedElements

std::vector<Particle *> ParticleVector::mIndexedElements
protected

Definition at line 69 of file particlevector.h.

Referenced by clearLocally(), delLocally(), moveTo(), setLocally(), size(), and usedSize().


The documentation for this class was generated from the following files: