ManaPlus
particle.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2006-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 #ifndef PARTICLE_PARTICLE_H
24 #define PARTICLE_PARTICLE_H
25 
26 #include "being/actor.h"
27 
30 
32 
34 
35 #include "localconsts.h"
36 
37 class Image;
38 class ParticleEmitter;
39 class SimpleAnimation;
40 
44 class Particle notfinal : public Actor
45 {
46  public:
47  friend class ParticleEngine;
48 
49  Particle();
50 
52 
53 
56  ~Particle() override;
57 
61  void clear() restrict2;
62 
67  bool update() restrict2;
68 
72  void draw(Graphics *restrict const graphics,
73  const int offsetX,
74  const int offsetY) const restrict2 override A_NONNULL(2);
75 
79  int getPixelY() const restrict2 override A_WARN_UNUSED
80  { return CAST_S32(mPos.y) - 16; }
81 
86  { return CAST_S32(mPos.y) - 16; }
87 
92  Particle *addEffect(const std::string &restrict particleEffectFile,
93  const int pixelX,
94  const int pixelY,
95  const int rotation) restrict2;
96 
100  void addEmitter(ParticleEmitter *const emitter) restrict2 A_NONNULL(2)
101  { mChildEmitters.push_back(emitter); }
102 
106  void moveTo(const Vector &restrict pos) restrict2
107  { moveBy(pos - mPos); }
108 
112  void moveTo(const float x, const float y) restrict2;
113 
117  void moveBy(const Vector &restrict change) restrict2;
118 
122  void setLifetime(const int lifetime) restrict2 noexcept2
123  { mLifetimeLeft = lifetime; mLifetimePast = 0; }
124 
129  void setFadeOut(const int fadeOut) restrict2 noexcept2
130  { mFadeOut = fadeOut; }
131 
136  void setFadeIn(const int fadeIn) restrict2 noexcept2
137  { mFadeIn = fadeIn; }
138 
142  void setVelocity(const float x,
143  const float y,
144  const float z) restrict2 noexcept2
145  { mVelocity.x = x; mVelocity.y = y; mVelocity.z = z; }
146 
150  void setGravity(const float gravity) restrict2 noexcept2
151  { mGravity = gravity; }
152 
156  void setRandomness(const int r) restrict2 noexcept2
157  { mRandomness = r; }
158 
163  void setBounce(const float bouncieness) restrict2 noexcept2
164  { mBounce = bouncieness; }
165 
169  void setFollow(const bool follow) restrict2 noexcept2
170  { mFollow = follow; }
171 
175  bool doesFollow() const restrict2 noexcept2 A_WARN_UNUSED
176  { return mFollow; }
177 
182  void setDestination(Particle *restrict const target,
183  const float accel,
184  const float moment) restrict2 noexcept2
185  A_NONNULL(2)
186  { mTarget = target; mAcceleration = accel; mMomentum = moment; }
187 
193  void setDieDistance(const float dist) restrict2
194  { mInvDieDistance = 1.0F / dist; }
195 
200  void adjustEmitterSize(const int w, const int h) restrict2;
201 
202  void setAllowSizeAdjust(const bool adjust) restrict2 noexcept2
203  { mAllowSizeAdjust = adjust; }
204 
205  bool isAlive() const restrict2 noexcept2 A_WARN_UNUSED
206  { return mAlive == AliveStatus::ALIVE; }
207 
208  void prepareToDie() restrict2;
209 
213  bool isExtinct() const restrict2 noexcept2 A_WARN_UNUSED
214  { return !isAlive() && mChildParticles.empty(); }
215 
219  void kill() restrict2 noexcept2
221 
226  void disableAutoDelete() restrict2 noexcept2
227  { mAutoDelete = false; }
228 
230  int getNumberOfLayers() const restrict2 override final
231  { return 1; }
232 
233  float getAlpha() const restrict2 override final
234  { return 1.0F; }
235 
236  void setAlpha(const float alpha A_UNUSED) restrict2 override
237  { }
238 
239  virtual void setDeathEffect(const std::string &restrict effectFile,
240  const signed char conditions) restrict2
241  { mDeathEffect = effectFile; mDeathEffectConditions = conditions; }
242 
243  void setActor(const BeingId actor)
244  { mActor = actor; }
245 
246  protected:
247  void updateSelf() restrict2;
248 
249  // Opacity of the graphical representation of the particle
250  float mAlpha;
251 
252  // Lifetime left in game ticks
254 
255  // Age of the particle in game ticks
257 
258  // Lifetime in game ticks left where fading out begins
259  int mFadeOut;
260 
261  // Age in game ticks where fading in is finished
262  int mFadeIn;
263 
264  // Speed in pixels per game-tick.
266 
267  // Is the particle supposed to be drawn and updated?
269 
271 
274 
277 
279 
280  private:
281  // List of child emitters.
283 
284  // List of particles controlled by this particle
286 
288 
289  // Particle effect file to be spawned when the particle dies
290  std::string mDeathEffect;
291 
292  // dynamic particle
293  // Downward acceleration in pixels per game-tick.
294  float mGravity;
295 
296  // How much the particle bounces off when hitting the ground
297  float mBounce;
298 
299  // Acceleration towards the target particle in pixels per game-tick
301 
302  // Distance in pixels from the target particle that causes
303  // the destruction of the particle
305 
306  // How much speed the particle retains after each game tick
307  float mMomentum;
308 
309  // The particle that attracts this particle
311 
312  // Ammount of random vector change
314 
315  // Bitfield of death conditions which trigger spawning
316  // of the death particle
318 
319  // May the particle request its deletion by the parent particle?
321 
322  // Can the effect size be adjusted by the object props in the map file?
324 
325  // is this particle moved when its parent particle moves?
326  bool mFollow;
327 };
328 
329 #endif // PARTICLE_PARTICLE_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
std::list< Particle * > Particles
void setRandomness(const int r)
Definition: particle.h:156
void setVelocity(const float x, const float y, const float z)
Definition: particle.h:142
bool isAlive() const
Definition: particle.h:205
virtual void setDeathEffect(const std::string &effectFile, const signed char conditions)
Definition: particle.h:239
Vector mVelocity
Definition: particle.h:265
Particle()
Definition: particle.cpp:58
void setAlpha(const float alpha)
Definition: particle.h:236
Definition: vector.h:38
void clear()
Definition: particle.cpp:581
void setAllowSizeAdjust(const bool adjust)
Definition: particle.h:202
int mRandomness
Definition: particle.h:313
void prepareToDie()
Definition: particle.cpp:564
#define A_WARN_UNUSED
Definition: localconsts.h:172
int getNumberOfLayers() const
Definition: particle.h:230
Vector mPos
Definition: actor.h:139
#define final
Definition: localconsts.h:45
float mGravity
Definition: particle.h:294
int BeingId
Definition: beingid.h:29
void updateSelf()
Definition: particle.cpp:129
std::string mDeathEffect
Definition: particle.h:290
void setBounce(const float bouncieness)
Definition: particle.h:163
float mInvDieDistance
Definition: particle.h:304
#define A_NONNULL(...)
Definition: localconsts.h:179
void kill()
Definition: particle.h:219
int getPixelY() const
Definition: particle.h:79
int mLifetimeLeft
Definition: particle.h:253
ParticleTypeT mType
Definition: particle.h:270
BeingId mActor
Definition: particle.h:278
bool isExtinct() const
Definition: particle.h:213
#define CAST_S32
Definition: cast.h:29
void setFadeIn(const int fadeIn)
Definition: particle.h:136
void moveTo(const Vector &pos)
Definition: particle.h:106
bool mAutoDelete
Definition: particle.h:320
float mAlpha
Definition: particle.h:250
float mMomentum
Definition: particle.h:307
bool doesFollow() const
Definition: particle.h:175
int getSortPixelY() const
Definition: particle.h:85
float mAcceleration
Definition: particle.h:300
#define notfinal
Definition: localconsts.h:289
Image * mImage
Definition: particle.h:276
void setFadeOut(const int fadeOut)
Definition: particle.h:129
SimpleAnimation * mAnimation
Definition: particle.h:273
bool update()
Definition: particle.cpp:253
~Particle()
Definition: particle.cpp:90
void setFollow(const bool follow)
Definition: particle.h:169
bool mAllowSizeAdjust
Definition: particle.h:323
void setGravity(const float gravity)
Definition: particle.h:150
AliveStatus ::T AliveStatusT
Definition: alivestatus.h:38
float x
Definition: vector.h:208
float mBounce
Definition: particle.h:297
void setActor(const BeingId actor)
Definition: particle.h:243
#define A_UNUSED
Definition: localconsts.h:171
int mLifetimePast
Definition: particle.h:256
void addEmitter(ParticleEmitter *const emitter)
Definition: particle.h:100
void setDestination(Particle *const target, const float accel, const float moment)
Definition: particle.h:182
float y
Definition: vector.h:208
Definition: actor.h:40
Definition: image.h:61
Particles mChildMoveParticles
Definition: particle.h:287
Particle * addEffect(const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
Definition: particle.cpp:410
Emitters mChildEmitters
Definition: particle.h:282
#define restrict
Definition: localconsts.h:176
void setLifetime(const int lifetime)
Definition: particle.h:122
std::list< ParticleEmitter * > Emitters
void setDieDistance(const float dist)
Definition: particle.h:193
#define override
Definition: localconsts.h:46
int mFadeOut
Definition: particle.h:259
void moveBy(const Vector &change)
Definition: particle.cpp:396
Particles mChildParticles
Definition: particle.h:285
float getAlpha() const
Definition: particle.h:233
void disableAutoDelete()
Definition: particle.h:226
ParticleType ::T ParticleTypeT
Definition: particletype.h:34
#define noexcept2
Definition: localconsts.h:49
Particle * mTarget
Definition: particle.h:310
void draw(Graphics *const graphics, const int offsetX, const int offsetY) const
Definition: particle.cpp:123
#define restrict2
Definition: localconsts.h:177
void adjustEmitterSize(const int w, const int h)
Definition: particle.cpp:555
int mFadeIn
Definition: particle.h:262
signed char mDeathEffectConditions
Definition: particle.h:317
bool mFollow
Definition: particle.h:326
float z
Definition: vector.h:208
AliveStatusT mAlive
Definition: particle.h:268