File size: 5,562 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
\brief Invokers for ParticleBase events, called from events
	@code
	void EnableOnEndPrint(ParticleBase psrc)
	{
		psrc.GetEvents().Event_OnParticleEnd.Insert(PrintParticleEnded);
	}
	
	void PrintParticleEnded(ParticleBase psrc)
	{
		Print(string.Format("%1 ended.", psrc.GetDebugNameNative());
	}
	@endcode
*/
class ParticleEvents
{
	/**
	\brief Called when particle starts playing
		\note Particle: Called when any Play method has been called
		\note ParticleSource: Called when PlayParticleNative is successful
	*/
	ref ScriptInvoker Event_OnParticleStart = new ScriptInvoker();
	/**
	\brief Called when particle stops playing
		\note Particle: Called when any Stop method has been called or when lifetime is over
		\note ParticleSource: Called when StopParticleNative is successful, when the particle ends and when the particle is destroyed while it is playing
	*/
	ref ScriptInvoker Event_OnParticleStop = new ScriptInvoker();
	/**
	\brief Called when particle is reset
		\note Particle: Not present, there is no reset functionality
		\note ParticleSource: Called when ResetParticleNative is successful
	*/
	ref ScriptInvoker Event_OnParticleReset = new ScriptInvoker();
	/**
	\brief Called when particle ends
		\note Particle: Called when lifetime is over and there are no emitors active anymore
		\note ParticleSource: Called when particle ends naturally or after the particle is stopped and there are no emitors active anymore
		\warning Looped never ends naturally and need to be stopped
	*/
	ref ScriptInvoker Event_OnParticleEnd = new ScriptInvoker();
	/**
	\brief Called when particle receives a parent
		\note Particle: Not present
	*/
	ref ScriptInvoker Event_OnParticleParented = new ScriptInvoker();
	/**
	\brief Called when particle is orphaned
		\note Particle: Not present
	*/
	ref ScriptInvoker Event_OnParticleUnParented = new ScriptInvoker();
}

/**
\brief Engine base class with internal functionality 
	\note Is NOT intended for direct creation
		* As this does not have an actual particle
		* Use either Particle or ParticleSource
*/
class ParticleBase : Entity
{
	//! Whether the particle is currently playing
	protected 	bool 	m_IsPlaying;
	
	//! Event invokers
	protected ref ParticleEvents m_EventInvokers;
	
	
	
	//! ctor
	void ParticleBase()
	{
		m_EventInvokers = new ParticleEvents();
	}
	
	
	
	//! Have script recognize this as a Particle without casting
	override bool IsParticle()
	{
		return true;
	}
	
	
	
	/** \name Playback
 		Methods regarding playing/stopping of particle
	*/
	//@{

	/**
	\brief Method to tell the particle to start playing
		\param particle_id \p int Particle ID registered in ParticleList to start playing
		\return \p bool Whether the particle successfully started
	*/
	void PlayParticle(int particle_id = -1)
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
	}
	
	/**
	\brief Method to tell the particle to start playing
		\param particle_id \p int Particle ID registered in ParticleList to start playing
		\param flags \p int Flags to pass to the playing
		\return \p bool Whether the particle successfully started
	*/
	bool PlayParticleEx(int particle_id = -1, int flags = 0)
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
		return false;
	}

	/**
	\brief Method to tell the particle to stop playing
		\param flags \p int Flags to pass to the stopping
		\return \p bool Whether the particle successfully stopped
	*/
	bool StopParticle(int flags = 0)
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
		return false;
	}
	
	/**
	\brief Method to tell the particle to reset
		\return \p bool Whether the particle successfully reset
	*/
	bool ResetParticle()
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
		return false;
	}

	/**
	\brief Method to tell the particle to restart (reset + play)
		\return \p bool Whether the particle successfully restarted
	*/
	bool RestartParticle()
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
		return false;
	}

	/**
	\brief Ask if the particle is still playing
		\return \p bool Whether the particle is playing
	*/
	bool IsParticlePlaying()
	{
		ErrorEx("Not implemented.", ErrorExSeverity.WARNING);
		return false;
	}
	
	//@}
	
	
	
	/**
	\brief Get the events
		\return \p ParticleEvents If there is any events set, this will return them so that additional functionality can be bound to them
	*/
	ParticleEvents GetEvents()
	{
		return m_EventInvokers;
	}
	
	
	
	/** \name Events
	*	ParticleBase events
	*	For ParticleSource, these are handed on C++ side
	*	For more information, read ParticleEvents
	*/
	//@{ 
	
	/**
	\brief Event when the particle starts
	*/
	protected void OnParticleStart()
	{
		m_IsPlaying = true;
		GetEvents().Event_OnParticleStart.Invoke(this);
	}
	
	/**
	\brief Event when the particle stops
	*/
	protected void OnParticleStop()
	{
		m_IsPlaying = false;
		GetEvents().Event_OnParticleStop.Invoke(this);
	}
	
	/**
	\brief Event when the particle is restarted
	*/
	protected void OnParticleReset()
	{
		GetEvents().Event_OnParticleReset.Invoke(this);
	}
	
	/**
	\brief Event when the particle ends
		\note Looping particles will never end
	*/
	protected void OnParticleEnd()
	{
		GetEvents().Event_OnParticleEnd.Invoke(this);
	}
	
	/**
	\brief Event when the particle receives a parent
	*/
	protected void OnParticleParented(IEntity parent)
	{
		GetEvents().Event_OnParticleParented.Invoke(this);
	}
	
	/**
	\brief Event when the particle is orphaned
	*/
	protected void OnParticleUnParented(IEntity parent)
	{
		GetEvents().Event_OnParticleUnParented.Invoke(this);
	}
	
	//@}
}