File: EffectTiming.h

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (81 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef FS2_OPEN_EFFECTTIMING_H
#define FS2_OPEN_EFFECTTIMING_H
#pragma once

#include "particle/ParticleSource.h"
#include "utils/RandomRange.h"

namespace particle {
namespace util {

/**
 * @defgroup particleUtils Particle Effect utilities
 *
 * @ingroup particleSystems
 */

/**
 * @brief The possible duration modes
 *
 * @ingroup particleUtils
 */
enum class Duration {
	Onetime, //!< The effect is active exactly once
	Range, //!< The effect is active within a specific time range
	Always //!< The effect is always active
};

/**
 * @brief Class for managing the timing of an effect
 *
 * This allows to use a random time range for the duration of an effect
 *
 * @ingroup particleUtils
 */
class EffectTiming {
 private:
	Duration m_duration;
	::util::UniformFloatRange m_delayRange;
	::util::UniformFloatRange m_durationRange;

	float m_particlesPerSecond = -1.f;
 public:
	struct TimingState {
		bool initial = true;
	};

	EffectTiming();

	/**
     * @brief Applies the timing information to a specific source
     * @param source The source to be modified
     */
	void applyToSource(ParticleSource* source) const;

	/**
     * @brief Determines if processing should continue
     * @param source The source which should be checked
     * @return @c true if processing should contine, @c false otherwise
     */
	bool continueProcessing(const ParticleSource* source) const;

	/**
	 * @brief Given the properties of this timing structure, determine if a new effect should be created for a source.
	 * @param source The source to check.
	 * @param localState Internal state used by this function that is needed multiple times. Default construct
	 * TimingState and then pass it to this function.
	 * @return @c true if a new effect should be created, @c false. This might return @c true multiple times per frame.
	 */
	bool shouldCreateEffect(ParticleSource* source, TimingState& localState) const;

	/**
     * @brief Parses an effect timing class
     * @return The parsed effect timing
     */
	static EffectTiming parseTiming();
};
}
}


#endif //FS2_OPEN_EFFECTTIMING_H