Coverage Report

Created: 2026-11-20 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreParticleEmitter.cpp
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
(Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#include "OgreStableHeaders.h"
29
30
#include "OgreParticleEmitter.h"
31
#include "OgreParticleEmitterFactory.h"
32
#include "OgreParticleEmitterCommands.h"
33
34
namespace Ogre
35
{
36
    // Command object for setting / getting parameters
37
    static EmitterCommands::CmdAngle msAngleCmd;
38
    static EmitterCommands::CmdColour msColourCmd;
39
    static EmitterCommands::CmdColourRangeStart msColourRangeStartCmd;
40
    static EmitterCommands::CmdColourRangeEnd msColourRangeEndCmd;
41
    static EmitterCommands::CmdDirection msDirectionCmd;
42
    static EmitterCommands::CmdUp msUpCmd;
43
    static EmitterCommands::CmdDirPositionRef msDirPositionRefCmd;
44
    static EmitterCommands::CmdEmissionRate msEmissionRateCmd;
45
    static EmitterCommands::CmdMaxTTL msMaxTTLCmd;
46
    static EmitterCommands::CmdMaxVelocity msMaxVelocityCmd;
47
    static EmitterCommands::CmdMinTTL msMinTTLCmd;
48
    static EmitterCommands::CmdMinVelocity msMinVelocityCmd;
49
    static EmitterCommands::CmdPosition msPositionCmd;
50
    static EmitterCommands::CmdTTL msTTLCmd;
51
    static EmitterCommands::CmdVelocity msVelocityCmd;
52
    static EmitterCommands::CmdDuration msDurationCmd;
53
    static EmitterCommands::CmdMinDuration msMinDurationCmd;
54
    static EmitterCommands::CmdMaxDuration msMaxDurationCmd;
55
    static EmitterCommands::CmdRepeatDelay msRepeatDelayCmd;
56
    static EmitterCommands::CmdMinRepeatDelay msMinRepeatDelayCmd;
57
    static EmitterCommands::CmdMaxRepeatDelay msMaxRepeatDelayCmd;
58
    static EmitterCommands::CmdName msNameCmd;
59
    static EmitterCommands::CmdEmittedEmitter msEmittedEmitterCmd;
60
61
62
    //-----------------------------------------------------------------------
63
    ParticleEmitter::ParticleEmitter(ParticleSystem* psys)
64
0
      : mParent(psys),
65
0
        mUseDirPositionRef(false),
66
0
        mDirPositionRef(Vector3::ZERO),
67
0
        mStartTime(0),
68
0
        mDurationMin(0),
69
0
        mDurationMax(0),
70
0
        mDurationRemain(0),
71
0
        mRepeatDelayMin(0),
72
0
        mRepeatDelayMax(0),
73
0
        mRepeatDelayRemain(0)
74
0
    {
75
76
        // Reasonable defaults
77
0
        mAngle = 0;
78
0
        setDirection(Vector3::UNIT_X);
79
0
        mEmissionRate = 10;
80
0
        mMaxSpeed = mMinSpeed = 1;
81
0
        mMaxTTL = mMinTTL = 5;
82
0
        mPosition = Vector3::ZERO;
83
0
        mColourRangeStart = mColourRangeEnd = ColourValue::White;
84
0
        mEnabled = true;
85
0
        mRemainder = 0;
86
0
        mName = BLANKSTRING;
87
0
        mEmittedEmitter = BLANKSTRING;
88
0
        mEmitted = false;
89
0
    }
90
    //-----------------------------------------------------------------------
91
    ParticleEmitter::~ParticleEmitter() 
92
0
    {
93
0
    }
94
    //-----------------------------------------------------------------------
95
    void ParticleEmitter::setPosition(const Vector3& pos) 
96
0
    { 
97
0
        mPosition = pos; 
98
0
    }
99
    //-----------------------------------------------------------------------
100
    const Vector3& ParticleEmitter::getPosition(void) const 
101
0
    { 
102
0
        return mPosition; 
103
0
    }
104
    //-----------------------------------------------------------------------
105
    void ParticleEmitter::setDirection(const Vector3& inDirection) 
106
0
    { 
107
0
        mDirection = inDirection; 
108
0
        mDirection.normalise();
109
        // Generate a default up vector.
110
0
        mUp = mDirection.perpendicular();
111
0
        mUp.normalise();
112
0
    }
113
    //-----------------------------------------------------------------------
114
    const Vector3& ParticleEmitter::getDirection(void) const
115
0
    { 
116
0
        return mDirection; 
117
0
    }
118
    //-----------------------------------------------------------------------
119
    void ParticleEmitter::setUp(const Vector3& inUp) 
120
0
    {
121
0
        mUp = inUp; 
122
0
        mUp.normalise();
123
0
    }
124
    //-----------------------------------------------------------------------
125
    const Vector3& ParticleEmitter::getUp(void) const
126
0
    { 
127
0
        return mUp; 
128
0
    }
129
    //-----------------------------------------------------------------------
130
    void ParticleEmitter::setDirPositionReference( const Vector3& nposition, bool enable )
131
0
    { 
132
0
    mUseDirPositionRef  = enable;
133
0
        mDirPositionRef     = nposition;
134
0
    }
135
    //-----------------------------------------------------------------------
136
    const Vector3& ParticleEmitter::getDirPositionReference() const
137
0
    {
138
0
        return mDirPositionRef;
139
0
    }
140
    //-----------------------------------------------------------------------
141
    bool ParticleEmitter::getDirPositionReferenceEnabled() const
142
0
    {
143
0
        return mUseDirPositionRef;
144
0
    }
145
    //-----------------------------------------------------------------------
146
    void ParticleEmitter::setAngle(const Radian& angle)
147
0
    {
148
        // Store as radians for efficiency
149
        // anything above 180 degrees already covers the whole sphere
150
0
        mAngle = std::min(angle, Radian(Math::PI));
151
0
    }
152
    //-----------------------------------------------------------------------
153
    const Radian& ParticleEmitter::getAngle(void) const
154
0
    {
155
0
        return mAngle;
156
0
    }
157
    //-----------------------------------------------------------------------
158
    void ParticleEmitter::setParticleVelocity(Real speed)
159
0
    {
160
0
        assert(std::isfinite(speed));
161
0
        mMinSpeed = mMaxSpeed = speed;
162
0
    }
163
    //-----------------------------------------------------------------------
164
    void ParticleEmitter::setParticleVelocity(Real min, Real max)
165
0
    {
166
0
        assert(std::isfinite(min) && std::isfinite(max));
167
0
        mMinSpeed = min;
168
0
        mMaxSpeed = max;
169
0
    }
170
    //-----------------------------------------------------------------------
171
    void ParticleEmitter::setEmissionRate(Real particlesPerSecond) 
172
0
    { 
173
0
        mEmissionRate = particlesPerSecond; 
174
0
    }
175
    //-----------------------------------------------------------------------
176
    Real ParticleEmitter::getEmissionRate(void) const 
177
0
    { 
178
0
        return mEmissionRate; 
179
0
    }
180
    //-----------------------------------------------------------------------
181
    void ParticleEmitter::setTimeToLive(Real ttl)
182
0
    {
183
0
        assert (ttl >= 0 && "Time to live can not be negative");
184
0
        mMinTTL = mMaxTTL = ttl;
185
0
    }
186
    //-----------------------------------------------------------------------
187
    void ParticleEmitter::setTimeToLive(Real minTtl, Real maxTtl)
188
0
    {
189
0
        assert (minTtl >= 0 && "Time to live can not be negative");
190
0
        assert (maxTtl >= 0 && "Time to live can not be negative");
191
0
        mMinTTL = minTtl;
192
0
        mMaxTTL = maxTtl;
193
0
    }
194
    //-----------------------------------------------------------------------
195
    void ParticleEmitter::setColour(const ColourValue& inColour)
196
0
    {
197
0
        mColourRangeStart = mColourRangeEnd = inColour;
198
0
    }
199
    //-----------------------------------------------------------------------
200
    void ParticleEmitter::setColour(const ColourValue& colourStart, const ColourValue& colourEnd)
201
0
    {
202
0
        mColourRangeStart = colourStart;
203
0
        mColourRangeEnd = colourEnd;
204
0
    }
205
    //-----------------------------------------------------------------------
206
    const String& ParticleEmitter::getName(void) const
207
0
    {
208
0
        return mName;
209
0
    }
210
    //-----------------------------------------------------------------------
211
    void ParticleEmitter::setName(const String& newName)
212
0
    {
213
0
        mName = newName;
214
0
    }
215
    //-----------------------------------------------------------------------
216
    const String& ParticleEmitter::getEmittedEmitter(void) const
217
0
    {
218
0
        return mEmittedEmitter;
219
0
    }
220
    //-----------------------------------------------------------------------
221
    void ParticleEmitter::setEmittedEmitter(const String& emittedEmitter)
222
0
    {
223
0
        mEmittedEmitter = emittedEmitter;
224
0
    }
225
    //-----------------------------------------------------------------------
226
    bool ParticleEmitter::isEmitted(void) const
227
0
    {
228
0
        return mEmitted;
229
0
    }
230
    //-----------------------------------------------------------------------
231
    void ParticleEmitter::setEmitted(bool emitted)
232
0
    {
233
0
        mEmitted = emitted;
234
0
    }
235
    //-----------------------------------------------------------------------
236
    static float sampleSphereUniform(const float& maxAngle)
237
0
    {
238
0
        float cosMax = -std::cos(maxAngle) + 1; // for maxAngle = pi, cosMax = 2
239
        // see https://corysimon.github.io/articles/uniformdistn-on-sphere/
240
0
        return std::acos(1 - cosMax * Math::UnitRandom());
241
0
    }
242
243
    void ParticleEmitter::genEmissionDirection( const Vector3 &particlePos, Vector3& destVector )
244
0
    {
245
0
        if( mUseDirPositionRef )
246
0
        {
247
0
            Vector3 particleDir = particlePos - mDirPositionRef;
248
0
            particleDir.normalise();
249
250
0
            if (mAngle != Radian(0))
251
0
            {
252
                // Randomise angle
253
0
                Radian angle(sampleSphereUniform(mAngle.valueRadians()));
254
255
                // Randomise direction
256
0
                destVector = particleDir.randomDeviant( angle );
257
0
            }
258
0
            else
259
0
            {
260
                // Constant angle
261
0
                destVector = particleDir;
262
0
            }
263
0
        }
264
0
        else
265
0
        {
266
0
            if (mAngle != Radian(0))
267
0
            {
268
                // Randomise angle
269
0
                Radian angle(sampleSphereUniform(mAngle.valueRadians()));
270
271
                // Randomise direction
272
0
                destVector = mDirection.randomDeviant(angle, mUp);
273
0
            }
274
0
            else
275
0
            {
276
                // Constant angle
277
0
                destVector = mDirection;
278
0
            }
279
0
        }
280
281
        // Don't normalise, we can assume that it will still be a unit vector since
282
        // both direction and 'up' are.
283
0
    }
284
    //-----------------------------------------------------------------------
285
    void ParticleEmitter::genEmissionVelocity(Vector3& destVector)
286
0
    {
287
0
        Real scalar;
288
0
        if (mMinSpeed != mMaxSpeed)
289
0
        {
290
0
            scalar = Math::RangeRandom(mMinSpeed, mMaxSpeed);
291
0
        }
292
0
        else
293
0
        {
294
0
            scalar = mMinSpeed;
295
0
        }
296
297
0
        destVector *= scalar;
298
0
    }
299
    //-----------------------------------------------------------------------
300
    Real ParticleEmitter::genEmissionTTL(void)
301
0
    {
302
0
        if (mMaxTTL != mMinTTL)
303
0
        {
304
0
            return Math::RangeRandom(mMinTTL, mMaxTTL);
305
0
        }
306
0
        else
307
0
        {
308
0
            return mMinTTL;
309
0
        }
310
0
    }
311
    //-----------------------------------------------------------------------
312
    unsigned short ParticleEmitter::genConstantEmissionCount(Real timeElapsed)
313
0
    {
314
0
        if (mEnabled)
315
0
        {
316
0
            if(mDurationMax < 0)
317
0
            {
318
                // single-shot burst
319
0
                setEnabled(false);
320
0
                return mEmissionRate;
321
0
            }
322
323
0
            unsigned short intRequest = (unsigned short)mRemainder;
324
0
            mRemainder -= intRequest;
325
326
            // Keep fractions, otherwise a high frame rate will result in zero emissions!
327
0
            mRemainder += mEmissionRate * timeElapsed;
328
329
            // Check duration
330
0
            if (mDurationMax)
331
0
            {
332
0
                mDurationRemain -= timeElapsed;
333
0
                if (mDurationRemain <= 0) 
334
0
                {
335
                    // Disable, duration is out (takes effect next time)
336
0
                    setEnabled(false);
337
0
                }
338
0
            }
339
0
            return intRequest;
340
0
        }
341
0
        else
342
0
        {
343
            // Check repeat
344
0
            if (mRepeatDelayMax)
345
0
            {
346
0
                mRepeatDelayRemain -= timeElapsed;
347
0
                if (mRepeatDelayRemain <= 0)
348
0
                {
349
                    // Enable, repeat delay is out (takes effect next time)
350
0
                    setEnabled(true);
351
0
                }
352
0
            }
353
0
            if(mStartTime)
354
0
            {
355
0
                mStartTime -= timeElapsed;
356
0
                if(mStartTime <= 0)
357
0
                {
358
0
                    setEnabled(true);
359
0
                    mStartTime = 0;
360
0
                }
361
0
            }
362
0
            return 0;
363
0
        }
364
365
0
    }
366
    //-----------------------------------------------------------------------
367
    void ParticleEmitter::genEmissionColour(RGBA& destColour)
368
0
    {
369
0
        if (mColourRangeStart != mColourRangeEnd)
370
0
        {
371
            // Randomise
372
0
            ColourValue t(Math::UnitRandom(), Math::UnitRandom(), Math::UnitRandom(), Math::UnitRandom());
373
0
            destColour = Math::lerp(mColourRangeStart, mColourRangeEnd, t).getAsBYTE();
374
0
        }
375
0
        else
376
0
        {
377
0
            destColour = mColourRangeStart.getAsBYTE();
378
0
        }
379
0
    }
380
    //-----------------------------------------------------------------------
381
    void ParticleEmitter::addBaseParameters(void)    
382
0
    {
383
0
        ParamDictionary* dict = getParamDictionary();
384
385
0
        dict->addParameter(ParameterDef("angle", 
386
0
            "The angle up to which particles may vary in their initial direction "
387
0
            "from the emitters direction, in degrees." , PT_REAL),
388
0
            &msAngleCmd);
389
390
0
        dict->addParameter(ParameterDef("colour", 
391
0
            "The colour of emitted particles.", PT_COLOURVALUE),
392
0
            &msColourCmd);
393
394
0
        dict->addParameter(ParameterDef("colour_range_start", 
395
0
            "The start of a range of colours to be assigned to emitted particles.", PT_COLOURVALUE),
396
0
            &msColourRangeStartCmd);
397
398
0
        dict->addParameter(ParameterDef("colour_range_end", 
399
0
            "The end of a range of colours to be assigned to emitted particles.", PT_COLOURVALUE),
400
0
            &msColourRangeEndCmd);
401
402
0
        dict->addParameter(ParameterDef("direction", 
403
0
            "The base direction of the emitter." , PT_VECTOR3),
404
0
            &msDirectionCmd);
405
406
0
        dict->addParameter(ParameterDef("up", 
407
0
            "The up vector of the emitter." , PT_VECTOR3),
408
0
            &msUpCmd);
409
410
0
        dict->addParameter(ParameterDef("direction_position_reference", 
411
0
            "The reference position to calculate the direction of emitted particles "
412
0
            "based on their position. Good for explosions and implosions (use negative velocity)" , PT_COLOURVALUE),
413
0
            &msDirPositionRefCmd);
414
415
0
        dict->addParameter(ParameterDef("emission_rate", 
416
0
            "The number of particles emitted per second." , PT_REAL),
417
0
            &msEmissionRateCmd);
418
419
0
        dict->addParameter(ParameterDef("position", 
420
0
            "The position of the emitter relative to the particle system center." , PT_VECTOR3),
421
0
            &msPositionCmd);
422
423
0
        dict->addParameter(ParameterDef("velocity", 
424
0
            "The initial velocity to be assigned to every particle, in world units per second." , PT_REAL),
425
0
            &msVelocityCmd);
426
427
0
        dict->addParameter(ParameterDef("velocity_min", 
428
0
            "The minimum initial velocity to be assigned to each particle." , PT_REAL),
429
0
            &msMinVelocityCmd);
430
431
0
        dict->addParameter(ParameterDef("velocity_max", 
432
0
            "The maximum initial velocity to be assigned to each particle." , PT_REAL),
433
0
            &msMaxVelocityCmd);
434
435
0
        dict->addParameter(ParameterDef("time_to_live", 
436
0
            "The lifetime of each particle in seconds." , PT_REAL),
437
0
            &msTTLCmd);
438
439
0
        dict->addParameter(ParameterDef("time_to_live_min", 
440
0
            "The minimum lifetime of each particle in seconds." , PT_REAL),
441
0
            &msMinTTLCmd);
442
443
0
        dict->addParameter(ParameterDef("time_to_live_max", 
444
0
            "The maximum lifetime of each particle in seconds." , PT_REAL),
445
0
            &msMaxTTLCmd);
446
447
0
        dict->addParameter(ParameterDef("duration", 
448
0
            "The length of time in seconds which an emitter stays enabled for." , PT_REAL),
449
0
            &msDurationCmd);
450
451
0
        dict->addParameter(ParameterDef("duration_min", 
452
0
            "The minimum length of time in seconds which an emitter stays enabled for." , PT_REAL),
453
0
            &msMinDurationCmd);
454
455
0
        dict->addParameter(ParameterDef("duration_max", 
456
0
            "The maximum length of time in seconds which an emitter stays enabled for." , PT_REAL),
457
0
            &msMaxDurationCmd);
458
459
0
        dict->addParameter(ParameterDef("repeat_delay", 
460
0
            "If set, after disabling an emitter will repeat (reenable) after this many seconds." , PT_REAL),
461
0
            &msRepeatDelayCmd);
462
463
0
        dict->addParameter(ParameterDef("repeat_delay_min", 
464
0
            "If set, after disabling an emitter will repeat (reenable) after this minimum number of seconds." , PT_REAL),
465
0
            &msMinRepeatDelayCmd);
466
467
0
        dict->addParameter(ParameterDef("repeat_delay_max", 
468
0
            "If set, after disabling an emitter will repeat (reenable) after this maximum number of seconds." , PT_REAL),
469
0
            &msMaxRepeatDelayCmd);
470
471
0
        dict->addParameter(ParameterDef("name", 
472
0
            "This is the name of the emitter" , PT_STRING),
473
0
            &msNameCmd);
474
        
475
0
        dict->addParameter(ParameterDef("emit_emitter", 
476
0
            "If set, this emitter will emit other emitters instead of visual particles" , PT_STRING),
477
0
            &msEmittedEmitterCmd);
478
0
    }
479
    //-----------------------------------------------------------------------
480
    Real ParticleEmitter::getParticleVelocity(void) const
481
0
    {
482
0
        return mMinSpeed;
483
0
    }
484
    //-----------------------------------------------------------------------
485
    Real ParticleEmitter::getMinParticleVelocity(void) const
486
0
    {
487
0
        return mMinSpeed;
488
0
    }
489
    //-----------------------------------------------------------------------
490
    Real ParticleEmitter::getMaxParticleVelocity(void) const
491
0
    {
492
0
        return mMaxSpeed;
493
0
    }
494
    //-----------------------------------------------------------------------
495
    void ParticleEmitter::setMinParticleVelocity(Real min)
496
0
    {
497
0
        assert(std::isfinite(min));
498
0
        mMinSpeed = min;
499
0
    }
500
    //-----------------------------------------------------------------------
501
    void ParticleEmitter::setMaxParticleVelocity(Real max)
502
0
    {
503
0
        assert(std::isfinite(max));
504
0
        mMaxSpeed = max;
505
0
    }
506
    //-----------------------------------------------------------------------
507
    Real ParticleEmitter::getTimeToLive(void) const
508
0
    {
509
0
        return mMinTTL;
510
0
    }
511
    //-----------------------------------------------------------------------
512
    Real ParticleEmitter::getMinTimeToLive(void) const
513
0
    {
514
0
        return mMinTTL;
515
0
    }
516
    //-----------------------------------------------------------------------
517
    Real ParticleEmitter::getMaxTimeToLive(void) const
518
0
    {
519
0
        return mMaxTTL;
520
0
    }
521
    //-----------------------------------------------------------------------
522
    void ParticleEmitter::setMinTimeToLive(Real min)
523
0
    {
524
0
        mMinTTL = min;
525
0
    }
526
    //-----------------------------------------------------------------------
527
    void ParticleEmitter::setMaxTimeToLive(Real max)
528
0
    {
529
0
        mMaxTTL = max;
530
0
    }
531
    //-----------------------------------------------------------------------
532
    const ColourValue& ParticleEmitter::getColour(void) const
533
0
    {
534
0
        return mColourRangeStart;
535
0
    }
536
    //-----------------------------------------------------------------------
537
    const ColourValue& ParticleEmitter::getColourRangeStart(void) const
538
0
    {
539
0
        return mColourRangeStart;
540
0
    }
541
    //-----------------------------------------------------------------------
542
    const ColourValue& ParticleEmitter::getColourRangeEnd(void) const
543
0
    {
544
0
        return mColourRangeEnd;
545
0
    }
546
    //-----------------------------------------------------------------------
547
    void ParticleEmitter::setColourRangeStart(const ColourValue& val)
548
0
    {
549
0
        mColourRangeStart = val;
550
0
    }
551
    //-----------------------------------------------------------------------
552
    void ParticleEmitter::setColourRangeEnd(const ColourValue& val )
553
0
    {
554
0
        mColourRangeEnd = val;
555
0
    }
556
    //-----------------------------------------------------------------------
557
    void ParticleEmitter::setEnabled(bool enabled)
558
0
    {
559
0
        mEnabled = enabled;
560
0
        mRemainder = 1.0f; // make sure we emit a particle on next update. Turns emission rate to (t0;r] interval
561
        // Reset duration & repeat
562
0
        initDurationRepeat();
563
0
    }
564
    //-----------------------------------------------------------------------
565
    bool ParticleEmitter::getEnabled(void) const
566
0
    {
567
0
        return mEnabled;
568
0
    }
569
    //-----------------------------------------------------------------------
570
    void ParticleEmitter::setStartTime(Real startTime)
571
0
    {
572
0
        setEnabled(false);
573
0
        mStartTime = startTime;
574
0
    }
575
    //-----------------------------------------------------------------------
576
    Real ParticleEmitter::getStartTime(void) const
577
0
    {
578
0
        return mStartTime;
579
0
    }
580
    //-----------------------------------------------------------------------
581
    void ParticleEmitter::setDuration(Real duration)
582
0
    {
583
0
        setDuration(duration, duration);
584
0
    }
585
    //-----------------------------------------------------------------------
586
    Real ParticleEmitter::getDuration(void) const
587
0
    {
588
0
        return mDurationMin;
589
0
    }
590
    //-----------------------------------------------------------------------
591
    void ParticleEmitter::setDuration(Real min, Real max)
592
0
    {
593
0
        mDurationMin = min;
594
0
        mDurationMax = max;
595
0
        initDurationRepeat();
596
0
    }
597
    //-----------------------------------------------------------------------
598
    void ParticleEmitter::setMinDuration(Real min)
599
0
    {
600
0
        mDurationMin = min;
601
0
        initDurationRepeat();
602
0
    }
603
    //-----------------------------------------------------------------------
604
    void ParticleEmitter::setMaxDuration(Real max)
605
0
    {
606
0
        mDurationMax = max;
607
0
        initDurationRepeat();
608
0
    }
609
    //-----------------------------------------------------------------------
610
    void ParticleEmitter::initDurationRepeat(void)
611
0
    {
612
0
        if (mEnabled)
613
0
        {
614
0
            if (mDurationMin == mDurationMax)
615
0
            {
616
0
                mDurationRemain = mDurationMin;
617
0
            }
618
0
            else
619
0
            {
620
0
                mDurationRemain = Math::RangeRandom(mDurationMin, mDurationMax);
621
0
            }
622
0
        }
623
0
        else
624
0
        {
625
            // Reset repeat
626
0
            if (mRepeatDelayMin == mRepeatDelayMax)
627
0
            {
628
0
                mRepeatDelayRemain = mRepeatDelayMin;
629
0
            }
630
0
            else
631
0
            {
632
0
                mRepeatDelayRemain = Math::RangeRandom(mRepeatDelayMax, mRepeatDelayMin);
633
0
            }
634
635
0
        }
636
0
    }
637
    //-----------------------------------------------------------------------
638
    void ParticleEmitter::setRepeatDelay(Real delay)
639
0
    {
640
0
        setRepeatDelay(delay, delay);
641
0
    }
642
    //-----------------------------------------------------------------------
643
    Real ParticleEmitter::getRepeatDelay(void) const
644
0
    {
645
0
        return mRepeatDelayMin;
646
0
    }
647
    //-----------------------------------------------------------------------
648
    void ParticleEmitter::setRepeatDelay(Real min, Real max)
649
0
    {
650
0
        mRepeatDelayMin = min;
651
0
        mRepeatDelayMax = max;
652
0
        initDurationRepeat();
653
0
    }
654
    //-----------------------------------------------------------------------
655
    void ParticleEmitter::setMinRepeatDelay(Real min)
656
0
    {
657
0
        mRepeatDelayMin = min;
658
0
        initDurationRepeat();
659
0
    }
660
    //-----------------------------------------------------------------------
661
    void ParticleEmitter::setMaxRepeatDelay(Real max)
662
0
    {
663
0
        mRepeatDelayMax = max;
664
0
        initDurationRepeat();
665
0
    }
666
    //-----------------------------------------------------------------------
667
    Real ParticleEmitter::getMinDuration(void) const
668
0
    {
669
0
        return mDurationMin;
670
0
    }
671
    //-----------------------------------------------------------------------
672
    Real ParticleEmitter::getMaxDuration(void) const
673
0
    {
674
0
        return mDurationMax;
675
0
    }
676
    //-----------------------------------------------------------------------
677
    Real ParticleEmitter::getMinRepeatDelay(void) const
678
0
    {
679
0
        return mRepeatDelayMin;    
680
0
    }
681
    //-----------------------------------------------------------------------
682
    Real ParticleEmitter::getMaxRepeatDelay(void) const
683
0
    {
684
0
        return mRepeatDelayMax;    
685
0
    }
686
687
    //-----------------------------------------------------------------------
688
    ParticleEmitterFactory::~ParticleEmitterFactory()
689
0
    {
690
0
        OGRE_IGNORE_DEPRECATED_BEGIN
691
        // Destroy all emitters
692
0
        for (auto& e : mEmitters)
693
0
        {
694
0
            OGRE_DELETE e;
695
0
        }
696
            
697
0
        mEmitters.clear();
698
0
        OGRE_IGNORE_DEPRECATED_END
699
0
    }
700
    //-----------------------------------------------------------------------
701
    void ParticleEmitterFactory::destroyEmitter(ParticleEmitter* e)        
702
0
    {
703
0
        delete e;
704
0
        OGRE_IGNORE_DEPRECATED_BEGIN
705
0
        auto i = std::find(std::begin(mEmitters), std::end(mEmitters), e);
706
0
        if (i != std::end(mEmitters)) {
707
0
            mEmitters.erase(i);
708
0
        }
709
0
        OGRE_IGNORE_DEPRECATED_END
710
0
    }
711
712
    //-----------------------------------------------------------------------
713
}
714