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