ManaPlus
Public Member Functions | Protected Attributes
ParticleVector Class Reference

#include <particlevector.h>

Inheritance diagram for ParticleVector:
ParticleContainer

Public Member Functions

 ParticleVector (ParticleContainer *const parent=0, const bool delParent=true)
 
 ~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=0, const bool delParent=true)
 
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 37 of file particlevector.h.

Constructor & Destructor Documentation

◆ ParticleVector()

ParticleVector::ParticleVector ( ParticleContainer *const  parent = 0,
const bool  delParent = true 
)
explicit

Definition at line 28 of file particlevector.cpp.

29  :
30  ParticleContainer(parent, delParent),
32 {}
ParticleContainer(ParticleContainer *const parent=0, const bool delParent=true)
std::vector< Particle * > mIndexedElements

◆ ~ParticleVector()

ParticleVector::~ParticleVector ( )

Definition at line 34 of file particlevector.cpp.

35 {}

Member Function Documentation

◆ clearLocally()

void ParticleVector::clearLocally ( )
virtual

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

Reimplemented from ParticleContainer.

Definition at line 68 of file particlevector.cpp.

References CAST_U32, delLocally(), and mIndexedElements.

69 {
70  for (unsigned int i = 0;
71  i < CAST_U32(mIndexedElements.size());
72  i++)
73  {
74  delLocally(i);
75  }
76 }
#define CAST_U32
Definition: cast.h:30
std::vector< Particle * > mIndexedElements
void delLocally(const int index)

◆ delLocally()

void ParticleVector::delLocally ( const int  index)

Removes a particle at a specified index

Definition at line 52 of file particlevector.cpp.

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

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

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

◆ moveTo()

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

Sets the positions of all elements

Reimplemented from ParticleContainer.

Definition at line 78 of file particlevector.cpp.

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

79 {
81 
82  for (STD_VECTOR<Particle *>::iterator it = mIndexedElements.begin();
83  it != mIndexedElements.end(); ++it)
84  {
85  Particle *const p = *it;
86  if (p != nullptr)
87  {
88  p->moveTo(x, y);
89 
90  if (p->isExtinct())
91  {
92  p->kill();
93  *it = nullptr;
94  }
95  }
96  }
97 }
void kill()
Definition: particle.h:219
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::vector< Particle * > mIndexedElements

◆ 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 37 of file particlevector.cpp.

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

Referenced by ActorSprite::handleStatusEffect().

38 {
39  if (index < 0)
40  return;
41 
42  delLocally(index);
43 
44  if (mIndexedElements.size() <= CAST_SIZE(index))
45  mIndexedElements.resize(index + 1, nullptr);
46 
47  if (particle != nullptr)
48  particle->disableAutoDelete();
49  mIndexedElements[index] = particle;
50 }
std::vector< Particle * > mIndexedElements
#define CAST_SIZE
Definition: cast.h:33
void disableAutoDelete()
Definition: particle.h:226
void delLocally(const int index)

◆ size()

size_t ParticleVector::size ( ) const
inline

Definition at line 62 of file particlevector.h.

References mIndexedElements, and usedSize().

63  { return mIndexedElements.size(); }
std::vector< Particle * > mIndexedElements

◆ usedSize()

size_t ParticleVector::usedSize ( ) const

Definition at line 99 of file particlevector.cpp.

References mIndexedElements.

Referenced by ActorSprite::getParticlesCount(), and size().

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

Field Documentation

◆ mIndexedElements

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

Definition at line 68 of file particlevector.h.

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


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