GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/particle/particle.h Lines: 0 31 0.0 %
Date: 2017-11-29 Branches: 0 4 0.0 %

Line Branch Exec Source
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-2017  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
28
#include "enums/particle/alivestatus.h"
29
#include "enums/particle/particletype.h"
30
31
#include "enums/simpletypes/beingid.h"
32
33
#include "particle/particleengine.h"
34
35
#include "localconsts.h"
36
37
class Image;
38
class ParticleEmitter;
39
class SimpleAnimation;
40
41
/**
42
 * A particle spawned by a ParticleEmitter.
43
 */
44
class Particle notfinal : public Actor
45
{
46
    public:
47
        friend class ParticleEngine;
48
49
        Particle();
50
51
        A_DELETE_COPY(Particle)
52
53
        /**
54
         * Destructor.
55
         */
56
        virtual ~Particle();
57
58
        /**
59
         * Deletes all child particles and emitters.
60
         */
61
        void clear() restrict2;
62
63
        /**
64
         * Updates particle position, returns false when the particle should
65
         * be deleted.
66
         */
67
        bool update() restrict2;
68
69
        /**
70
         * Draws the particle image.
71
         */
72
        void draw(Graphics *restrict const graphics,
73
                  const int offsetX,
74
                  const int offsetY) const restrict2 override
75
                  A_CONST A_NONNULL(2);
76
77
        /**
78
         * Necessary for sorting with the other sprites.
79
         */
80
        int getPixelY() const restrict2 override A_WARN_UNUSED
81
        { return CAST_S32(mPos.y) - 16; }
82
83
        /**
84
         * Necessary for sorting with the other sprites for sorting only.
85
         */
86
        int getSortPixelY() const restrict2 override A_WARN_UNUSED
87
        { return CAST_S32(mPos.y) - 16; }
88
89
        /**
90
         * Creates a child particle that hosts some emitters described in the
91
         * particleEffectFile.
92
         */
93
        Particle *addEffect(const std::string &restrict particleEffectFile,
94
                            const int pixelX, const int pixelY,
95
                            const int rotation = 0) restrict2;
96
97
        /**
98
         * Adds an emitter to the particle.
99
         */
100
        void addEmitter(ParticleEmitter *const emitter) restrict2 A_NONNULL(2)
101
        { mChildEmitters.push_back(emitter); }
102
103
        /**
104
         * Sets the position in 3 dimensional space in pixels relative to map.
105
         */
106
        void moveTo(const Vector &restrict pos) restrict2
107
        { moveBy(pos - mPos); }
108
109
        /**
110
         * Sets the position in 2 dimensional space in pixels relative to map.
111
         */
112
        void moveTo(const float x, const float y) restrict2;
113
114
        /**
115
         * Changes the particle position relative
116
         */
117
        void moveBy(const Vector &restrict change) restrict2;
118
119
        /**
120
         * Sets the time in game ticks until the particle is destroyed.
121
         */
122
        void setLifetime(const int lifetime) restrict2 noexcept2
123
        { mLifetimeLeft = lifetime; mLifetimePast = 0; }
124
125
        /**
126
         * Sets the age of the pixel in game ticks where the particle has
127
         * faded in completely.
128
         */
129
        void setFadeOut(const int fadeOut) restrict2 noexcept2
130
        { mFadeOut = fadeOut; }
131
132
        /**
133
         * Sets the remaining particle lifetime where the particle starts to
134
         * fade out.
135
         */
136
        void setFadeIn(const int fadeIn) restrict2 noexcept2
137
        { mFadeIn = fadeIn; }
138
139
        /**
140
         * Sets the current velocity in 3 dimensional space.
141
         */
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
147
        /**
148
         * Sets the downward acceleration.
149
         */
150
        void setGravity(const float gravity) restrict2 noexcept2
151
        { mGravity = gravity; }
152
153
        /**
154
         * Sets the ammount of random vector changes
155
         */
156
        void setRandomness(const int r) restrict2 noexcept2
157
        { mRandomness = r; }
158
159
        /**
160
         * Sets the ammount of velocity particles retain after
161
         * hitting the ground.
162
         */
163
        void setBounce(const float bouncieness) restrict2 noexcept2
164
        { mBounce = bouncieness; }
165
166
        /**
167
         * Sets the flag if the particle is supposed to be moved by its parent
168
         */
169
        void setFollow(const bool follow) restrict2 noexcept2
170
        { mFollow = follow; }
171
172
        /**
173
         * Gets the flag if the particle is supposed to be moved by its parent
174
         */
175
        bool doesFollow() const restrict2 noexcept2 A_WARN_UNUSED
176
        { return mFollow; }
177
178
        /**
179
         * Makes the particle move toward another particle with a
180
         * given acceleration and momentum
181
         */
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
188
        /**
189
         * Sets the distance in pixel the particle can come near the target
190
         * particle before it is destroyed. Does only make sense after a target
191
         * particle has been set using setDestination.
192
         */
193
        void setDieDistance(const float dist) restrict2
194
        { mInvDieDistance = 1.0F / dist; }
195
196
        /**
197
         * Changes the size of the emitters so that the effect fills a
198
         * rectangle of this size
199
         */
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
210
        /**
211
         * Determines whether the particle and its children are all dead
212
         */
213
        bool isExtinct() const restrict2 noexcept2 A_WARN_UNUSED
214
        { return !isAlive() && mChildParticles.empty(); }
215
216
        /**
217
         * Manually marks the particle for deletion.
218
         */
219
        void kill() restrict2 noexcept2
220
        { mAlive = AliveStatus::DEAD_OTHER; mAutoDelete = true; }
221
222
        /**
223
         * After calling this function the particle will only request
224
         * deletion when kill() is called
225
         */
226
        void disableAutoDelete() restrict2 noexcept2
227
        { mAutoDelete = false; }
228
229
        /** We consider particles (at least for now) to be one layer-sprites */
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
253
        int mLifetimeLeft;
254
255
        // Age of the particle in game ticks
256
        int mLifetimePast;
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.
265
        Vector mVelocity;
266
267
        // Is the particle supposed to be drawn and updated?
268
        AliveStatusT mAlive;
269
270
        ParticleTypeT mType;
271
272
        /**< Used animation for this particle */
273
        SimpleAnimation *restrict mAnimation;
274
275
        /**< The image used for this particle. */
276
        Image *restrict mImage;
277
278
        BeingId mActor;
279
280
    private:
281
        // List of child emitters.
282
        Emitters mChildEmitters;
283
284
        // List of particles controlled by this particle
285
        Particles mChildParticles;
286
287
        Particles mChildMoveParticles;
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
300
        float mAcceleration;
301
302
        // Distance in pixels from the target particle that causes
303
        // the destruction of the particle
304
        float mInvDieDistance;
305
306
        // How much speed the particle retains after each game tick
307
        float mMomentum;
308
309
        // The particle that attracts this particle
310
        Particle *restrict mTarget;
311
312
        // Ammount of random vector change
313
        int mRandomness;
314
315
        // Bitfield of death conditions which trigger spawning
316
        // of the death particle
317
        signed char mDeathEffectConditions;
318
319
        // May the particle request its deletion by the parent particle?
320
        bool mAutoDelete;
321
322
        // Can the effect size be adjusted by the object props in the map file?
323
        bool mAllowSizeAdjust;
324
325
        // is this particle moved when its parent particle moves?
326
        bool mFollow;
327
};
328
329
#endif  // PARTICLE_PARTICLE_H