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