ManaPlus
Public Member Functions | Private Attributes
EffectManager Class Reference

#include <effectmanager.h>

Public Member Functions

 EffectManager ()
 
 ~EffectManager ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
bool trigger (const int id, Being *const being, const int rotation)
 
bool triggerDirection (const int id, Being *const being, const SpriteDirection::Type &direction)
 
ParticletriggerReturn (const int id, Being *const being, const int rotation)
 
bool trigger (const int id, const int x, const int y, const time_t endTime, const int rotation)
 
void triggerDefault (int effectId, Being *const being, const int defaultEffectId)
 
void triggerDefault (int effectId, const int x, const int y, const time_t endTime, const int defaultEffectId)
 
void logic ()
 
void clear ()
 

Private Attributes

std::vector< EffectDescriptionmEffects
 
std::list< ParticleTimermTimers
 

Detailed Description

Definition at line 44 of file effectmanager.h.

Constructor & Destructor Documentation

◆ EffectManager()

EffectManager::EffectManager ( )

Definition at line 41 of file effectmanager.cpp.

41  :
42  mEffects(),
43  mTimers()
44 {
45  logger->log1("Effects are now loading");
47  loadXmlFile(paths.getStringValue("effectsPatchFile"), SkipError_true);
48  loadXmlDir("effectsPatchDir", loadXmlFile)
49 }
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
std::list< ParticleTimer > mTimers
Definition: effectmanager.h:97
void loadXmlFile(const std::string &fileName, const SkipError skipError)
std::vector< EffectDescription > mEffects
Definition: effectmanager.h:96
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, paths, SkipError_false, and SkipError_true.

◆ ~EffectManager()

EffectManager::~EffectManager ( )

Definition at line 84 of file effectmanager.cpp.

85 {
86 }

Member Function Documentation

◆ clear()

void EffectManager::clear ( )

Definition at line 262 of file effectmanager.cpp.

263 {
264  FOR_EACH (std::list<ParticleTimer>::iterator, it, mTimers)
265  {
266  Particle *const particle = (*it).particle;
267  if (particle != nullptr)
268  particle->kill();
269  }
270  mTimers.clear();
271 }
void kill()
Definition: particle.h:220
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, Particle::kill(), and mTimers.

Referenced by Game::~Game().

◆ loadXmlFile()

void EffectManager::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 51 of file effectmanager.cpp.

53 {
54  XML::Document doc(fileName, UseVirtFs_true, skipError);
55  XmlNodeConstPtrConst root = doc.rootNode();
56 
57  if ((root == nullptr) ||
58  !xmlNameEqual(root, "being-effects"))
59  {
60  logger->log("Error loading being effects file: " + fileName);
61  return;
62  }
63 
64  for_each_xml_child_node(node, root)
65  {
66  if (xmlNameEqual(node, "include"))
67  {
68  const std::string name = XML::getProperty(node, "name", "");
69  if (!name.empty())
70  loadXmlFile(name, skipError);
71  continue;
72  }
73  else if (xmlNameEqual(node, "effect"))
74  {
75  mEffects.push_back(EffectDescription(
76  XML::getProperty(node, "id", -1),
77  XML::getProperty(node, "particle", ""),
78  XML::getProperty(node, "audio", ""),
79  XML::getProperty(node, "sprite", "")));
80  }
81  }
82 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, XML::getProperty(), Logger::log(), logger, mEffects, XML::Document::rootNode(), and UseVirtFs_true.

Referenced by EffectManager().

◆ logic()

void EffectManager::logic ( )

Definition at line 239 of file effectmanager.cpp.

240 {
241  const time_t time = cur_time;
242  bool found(true);
243  while (found)
244  {
245  found = false;
246  FOR_EACH (std::list<ParticleTimer>::iterator, it, mTimers)
247  {
248  const ParticleTimer &timer = *it;
249  if (timer.endTime < time)
250  {
251  found = true;
252  Particle *const particle = timer.particle;
253  if (particle != nullptr)
254  particle->kill();
255  mTimers.erase(it);
256  break;
257  }
258  }
259  }
260 }
volatile time_t cur_time
Definition: timer.cpp:58
Particle *const particle
Definition: particletimer.h:40
const time_t endTime
Definition: particletimer.h:41

References cur_time, ParticleTimer::endTime, FOR_EACH, Particle::kill(), mTimers, and ParticleTimer::particle.

Referenced by Game::slowLogic().

◆ trigger() [1/2]

bool EffectManager::trigger ( const int  id,
Being *const  being,
const int  rotation 
)

Triggers a effect with the id, at the specified being.

Definition at line 119 of file effectmanager.cpp.

122 {
123  if ((being == nullptr) || (particleEngine == nullptr) || id == -1)
124  return false;
125 
126  BLOCK_START("EffectManager::trigger")
127  bool rValue = false;
128  FOR_EACH (STD_VECTOR<EffectDescription>::const_iterator, i, mEffects)
129  {
130  const EffectDescription &effect = *i;
131  if (effect.id == id)
132  {
133  rValue = true;
134  if (!effect.gfx.empty())
135  {
136  Particle *const selfFX = particleEngine->addEffect(
137  effect.gfx, 0, 0, rotation);
138  being->controlAutoParticle(selfFX);
139  }
140  if (!effect.sfx.empty())
141  soundManager.playSfx(effect.sfx, 0, 0);
142  if (!effect.sprite.empty())
143  being->addEffect(effect.sprite);
144  return rValue;
145  }
146  }
147  reportAlways("Missing effect %d", id)
148  BLOCK_END("EffectManager::trigger")
149  return rValue;
150 }
#define reportAlways(...)
Definition: checkutils.h:253
void controlAutoParticle(Particle *const particle)
void addEffect(const std::string &name)
Definition: being.cpp:4959
Particle * addEffect(const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
void playSfx(const std::string &path, const int x, const int y) const
ParticleEngine * particleEngine
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
SoundManager soundManager
#define STD_VECTOR
Definition: vector.h:30

References Being::addEffect(), ParticleEngine::addEffect(), BLOCK_END, BLOCK_START, ActorSprite::controlAutoParticle(), FOR_EACH, EffectDescription::gfx, EffectDescription::id, mEffects, particleEngine, SoundManager::playSfx(), reportAlways, EffectDescription::sfx, soundManager, and EffectDescription::sprite.

Referenced by EAthena::BeingRecv::processBeingSelfEffect(), TmwAthena::BeingRecv::processBeingSelfEffect(), EAthena::BeingRecv::processBeingSpecialEffect(), QuestsWindow::rebuild(), Being::setEmote(), Being::takeDamage(), triggerDefault(), and triggerDirection().

◆ trigger() [2/2]

bool EffectManager::trigger ( const int  id,
const int  x,
const int  y,
const time_t  endTime,
const int  rotation 
)

Triggers a effect with the id, at the specified x and y coordinate.

Definition at line 182 of file effectmanager.cpp.

186 {
187  if ((particleEngine == nullptr) || id == -1)
188  return false;
189 
190  bool rValue = false;
191  FOR_EACH (STD_VECTOR<EffectDescription>::const_iterator, i, mEffects)
192  {
193  const EffectDescription &effect = *i;
194  if (effect.id == id)
195  {
196  rValue = true;
197  if (!effect.gfx.empty())
198  {
199  Particle *const particle = particleEngine->addEffect(
200  effect.gfx,
201  x, y,
202  rotation);
203  if (particle != nullptr)
204  mTimers.push_back(ParticleTimer(particle, endTime));
205  }
206  if (!effect.sfx.empty())
207  soundManager.playSfx(effect.sfx, 0, 0);
208  return rValue;
209  }
210  }
211  reportAlways("Missing effect %d", id)
212  return rValue;
213 }

References ParticleEngine::addEffect(), FOR_EACH, EffectDescription::gfx, EffectDescription::id, mEffects, mTimers, particleEngine, SoundManager::playSfx(), reportAlways, EffectDescription::sfx, soundManager, x, and y.

◆ triggerDefault() [1/2]

void EffectManager::triggerDefault ( int  effectId,
Being *const  being,
const int  defaultEffectId 
)

Definition at line 215 of file effectmanager.cpp.

218 {
219  if (effectId == -1)
220  effectId = defaultEffectId;
221  if (effectId == -1)
222  return;
223  trigger(effectId, being, 0);
224 }
bool trigger(const int id, Being *const being, const int rotation)

References trigger().

Referenced by Being::handleSkill(), Being::handleSkillCasting(), SkillDialog::playCastingDstTileEffect(), SkillDialog::playRemoveEffect(), and SkillDialog::playUpdateEffect().

◆ triggerDefault() [2/2]

void EffectManager::triggerDefault ( int  effectId,
const int  x,
const int  y,
const time_t  endTime,
const int  defaultEffectId 
)

Definition at line 226 of file effectmanager.cpp.

231 {
232  if (effectId == -1)
233  effectId = defaultEffectId;
234  if (effectId == -1)
235  return;
236  trigger(effectId, x, y, endTime, 0);
237 }

References trigger(), x, and y.

◆ triggerDirection()

bool EffectManager::triggerDirection ( const int  id,
Being *const  being,
const SpriteDirection::Type direction 
)

Definition at line 88 of file effectmanager.cpp.

91 {
92  int rotation;
93  switch (direction)
94  {
100  default:
101  rotation = 0;
102  break;
104  rotation = 90;
105  break;
106  case SpriteDirection::UP:
109  rotation = 180;
110  break;
112  rotation = 270;
113  break;
114  }
115 
116  return trigger(id, being, rotation);
117 }

References SpriteDirection::DEFAULT, SpriteDirection::DOWN, SpriteDirection::DOWNLEFT, SpriteDirection::DOWNRIGHT, SpriteDirection::INVALID, SpriteDirection::LEFT, SpriteDirection::RIGHT, trigger(), SpriteDirection::UP, SpriteDirection::UPLEFT, and SpriteDirection::UPRIGHT.

Referenced by Being::setAction().

◆ triggerReturn()

Particle * EffectManager::triggerReturn ( const int  id,
Being *const  being,
const int  rotation 
)

Definition at line 152 of file effectmanager.cpp.

155 {
156  if ((being == nullptr) || (particleEngine == nullptr) || id == -1)
157  return nullptr;
158 
159  Particle *rValue = nullptr;
160  FOR_EACH (STD_VECTOR<EffectDescription>::const_iterator, i, mEffects)
161  {
162  const EffectDescription &effect = *i;
163  if (effect.id == id)
164  {
165  if (!effect.gfx.empty())
166  {
167  rValue = particleEngine->addEffect(
168  effect.gfx, 0, 0, rotation);
169  being->controlCustomParticle(rValue);
170  }
171  if (!effect.sfx.empty())
172  soundManager.playSfx(effect.sfx, 0, 0);
173  if (!effect.sprite.empty())
174  being->addEffect(effect.sprite);
175  return rValue;
176  }
177  }
178  reportAlways("Missing effect %d", id)
179  return rValue;
180 }
void controlCustomParticle(Particle *const particle)

References Being::addEffect(), ParticleEngine::addEffect(), ActorSprite::controlCustomParticle(), FOR_EACH, EffectDescription::gfx, EffectDescription::id, mEffects, particleEngine, SoundManager::playSfx(), reportAlways, EffectDescription::sfx, soundManager, and EffectDescription::sprite.

Referenced by Being::addSpecialEffect(), and Being::addSpiritBalls().

Field Documentation

◆ mEffects

std::vector<EffectDescription> EffectManager::mEffects
private

Definition at line 96 of file effectmanager.h.

Referenced by loadXmlFile(), trigger(), and triggerReturn().

◆ mTimers

std::list<ParticleTimer> EffectManager::mTimers
private

Definition at line 97 of file effectmanager.h.

Referenced by clear(), logic(), and trigger().


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