Skylicht Engine
Loading...
Searching...
No Matches
CEmitter.h
1/*
2!@
3MIT License
4
5Copyright (c) 2020 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "ParticleSystem/Particles/CParticleSerializable.h"
28
29namespace Skylicht
30{
31 namespace Particle
32 {
33 class CZone;
34 class CParticle;
35 class CGroup;
36
43 {
44 Random,
45 Straight,
46 Spheric,
47 Normal,
48 NumOfEmitter,
49 };
50
57 struct SBornData
58 {
60 float LifeTime;
64 float WaitDelay;
66 float Fraction;
68 s32 Tank;
69
70 SBornData()
71 {
72 LifeTime = 0.0f;
73 FlowLifeTime = 0.0f;
74 WaitDelay = 0.0f;
75 Fraction = 0.0f;
76 Tank = 0;
77 }
78 };
79
87 class COMPONENT_API CEmitter : public CParticleSerializable
88 {
89 protected:
90 int m_lastTank;
91 int m_defaultTank;
93 int m_tank;
95 float m_flow;
96 float m_lastFlow;
97 float m_defaultFlow;
104 float m_fraction;
109
111 float m_delay;
116
118 float m_reset;
123
126
129
130 protected:
131
133 core::array<SBornData> m_bornData;
134
135 public:
136 CEmitter(EEmitter type);
137
138 virtual ~CEmitter();
139
141
143
145 virtual bool haveDirection()
146 {
147 return false;
148 }
149
151 inline CZone* setZone(CZone* z)
152 {
153 m_zone = z;
154 return m_zone;
155 }
156
158 inline CZone* getZone()
159 {
160 return m_zone;
161 }
162
164 inline void stop()
165 {
166 m_tank = 0;
167 m_flow = 0;
168 m_lifeTime = 0.0f;
169 m_reset = 0.0f;
170 }
171
173 inline void setTank(int tank)
174 {
175 m_tank = tank;
176 m_lastTank = tank;
177 }
178
180 void resetTank();
181
183 inline int getTank()
184 {
185 return m_tank;
186 }
187
189 inline int getLastTank()
190 {
191 return m_lastTank;
192 }
193
195 inline void setTankValue(int tank)
196 {
197 m_lastTank = tank;
198 }
199
201 inline int getDefaultTank()
202 {
203 return m_defaultTank;
204 }
205
207 inline float getDefaultFlow()
208 {
209 return m_defaultFlow;
210 }
211
213 inline void setFlow(float flow)
214 {
215 m_flow = flow;
216 if (m_flow <= 0)
217 m_flow = 0;
218 m_lastFlow = flow;
219 }
220
222 inline float getFlow()
223 {
224 return m_flow;
225 }
226
228 inline void setActive(bool b)
229 {
230 m_active = b;
231 }
232
234 inline bool isActive()
235 {
236 return m_active;
237 }
238
240 inline void setDelay(float timeSecond)
241 {
242 m_delay = timeSecond;
243 m_waitDelay = timeSecond;
244 }
245
247 inline void setForce(float min, float max)
248 {
249 if (min > max)
250 {
251 m_forceMin = max;
252 m_forceMax = min;
253 }
254 else
255 {
256 m_forceMin = min;
257 m_forceMax = max;
258 }
259 }
260
262 inline float getForceMin()
263 {
264 return m_forceMin;
265 }
266
268 inline float getForceMax()
269 {
270 return m_forceMax;
271 }
272
274 inline void setResetTankInterval(float min, float max)
275 {
276 if (min > max)
277 {
278 m_resetIntervalMin = max;
279 m_resetIntervalMax = min;
280 }
281 else
282 {
283 m_resetIntervalMin = min;
284 m_resetIntervalMax = max;
285 }
286 }
287
289 inline void setEmitFullZone(bool b)
290 {
291 m_emitFullZone = b;
292 }
293
295 inline bool isEmitFullZone()
296 {
297 return m_emitFullZone;
298 }
299
302 {
303 return m_type;
304 }
305
307 const wchar_t* getName();
308
310 virtual u32 updateNumber(float deltaTime);
311
313 virtual void setBornData(SBornData& data);
314
316 inline u32 updateBornData(u32 index, float deltaTime)
317 {
318 return updateBornData(m_bornData[index], deltaTime);
319 }
320
322 virtual u32 updateBornData(SBornData& data, float deltaTime);
323
325 inline void clearBornData()
326 {
327 m_bornData.clear();
328 }
329
331 void generateVelocity(CParticle& particle, CZone* zone, CGroup* group);
332
334 void emitParticle(CParticle& particle, CZone* zone, CGroup* group);
335
337 virtual void generateVelocity(CParticle& particle, float speed, CZone* zone, CGroup* group) = 0;
338
341
343 void swapBornData(int index1, int index2);
344
347
348 DECLARE_GETTYPENAME(CEmitter)
349 };
350 }
351}
Definition CObjectSerializable.h:36
virtual u32 updateNumber(float deltaTime)
Calculates how many particles should be born this frame.
bool m_active
Active status.
Definition CEmitter.h:106
const wchar_t * getName()
Gets display name.
virtual u32 updateBornData(SBornData &data, float deltaTime)
Internal: core logic for sub-emitter birth calculation.
CZone * getZone()
Gets the current spawn zone.
Definition CEmitter.h:158
void setFlow(float flow)
Sets continuous birth rate (particles per second).
Definition CEmitter.h:213
int getTank()
Gets current tank value.
Definition CEmitter.h:183
void setEmitFullZone(bool b)
Sets volume spawn mode.
Definition CEmitter.h:289
EEmitter m_type
Type of the emitter.
Definition CEmitter.h:128
virtual CObjectSerializable * createSerializable()
Creates a serializable object for property editing or saving.
float m_resetIntervalMin
Min interval for auto-resetting the tank.
Definition CEmitter.h:120
float getForceMin()
Gets min force.
Definition CEmitter.h:262
void deleteBornData()
Removes a sub-emitter record.
void emitParticle(CParticle &particle, CZone *zone, CGroup *group)
Full emission logic: generates position and velocity.
int getLastTank()
Gets last set tank value.
Definition CEmitter.h:189
u32 updateBornData(u32 index, float deltaTime)
Internal: updates birth calculation for a specific sub-group particle index.
Definition CEmitter.h:316
void clearBornData()
Clears sub-emitter birth records.
Definition CEmitter.h:325
float m_delay
Configured delay.
Definition CEmitter.h:111
float getFlow()
Gets current flow rate.
Definition CEmitter.h:222
void setForce(float min, float max)
Sets initial velocity force range.
Definition CEmitter.h:247
EEmitter getType()
Gets emitter type.
Definition CEmitter.h:301
bool isActive()
Checks if emitter is active.
Definition CEmitter.h:234
float m_resetIntervalMax
Max interval for auto-resetting the tank.
Definition CEmitter.h:122
float m_waitDelay
Current waiting time for delay.
Definition CEmitter.h:113
bool isEmitFullZone()
Checks volume spawn mode.
Definition CEmitter.h:295
void setActive(bool b)
Enables or disables the emitter.
Definition CEmitter.h:228
void setResetTankInterval(float min, float max)
Sets interval for automatic tank resets.
Definition CEmitter.h:274
void stop()
Stops the emitter immediately.
Definition CEmitter.h:164
core::array< SBornData > m_bornData
Internal: birth data for sub-emitters.
Definition CEmitter.h:133
float getForceMax()
Gets max force.
Definition CEmitter.h:268
CZone * m_zone
The spawn zone assigned to this emitter.
Definition CEmitter.h:125
int getDefaultTank()
Gets default tank from serializable data.
Definition CEmitter.h:201
void setTankValue(int tank)
Updates the persistent tank value without immediate reset.
Definition CEmitter.h:195
void generateVelocity(CParticle &particle, CZone *zone, CGroup *group)
Generates initial velocity for a particle.
float m_forceMax
Maximum magnitude of initial velocity.
Definition CEmitter.h:103
u32 addBornData()
Adds a new sub-emitter record.
virtual bool haveDirection()
Returns true if this emitter has a primary direction.
Definition CEmitter.h:145
int m_tank
Current particles remaining in the tank.
Definition CEmitter.h:93
float m_lifeTime
Total time elapsed since start.
Definition CEmitter.h:115
virtual void loadSerializable(CObjectSerializable *object)
Loads properties from a serializable object.
bool m_emitFullZone
Whether to spawn particles randomly within the zone volume.
Definition CEmitter.h:108
void setTank(int tank)
Sets the tank capacity and current value.
Definition CEmitter.h:173
void setDelay(float timeSecond)
Sets start delay in seconds.
Definition CEmitter.h:240
virtual void setBornData(SBornData &data)
Initializes birth data for sub-emitters.
float m_flowLifeTime
Duration of the flow logic before it stops.
Definition CEmitter.h:99
virtual void generateVelocity(CParticle &particle, float speed, CZone *zone, CGroup *group)=0
Implementation-specific velocity generation.
float getDefaultFlow()
Gets default flow from serializable data.
Definition CEmitter.h:207
void swapBornData(int index1, int index2)
Swaps sub-emitter records (for array reordering).
CZone * setZone(CZone *z)
Sets the spawn zone.
Definition CEmitter.h:151
float m_reset
Current reset timer.
Definition CEmitter.h:118
float m_flow
Current birth rate (particles per second).
Definition CEmitter.h:95
float m_forceMin
Minimum magnitude of initial velocity.
Definition CEmitter.h:101
void resetTank()
Resets the tank and flow logic.
Represents a group of particles with shared settings, emitters, and a renderer.
Definition CGroup.h:132
Individual particle data structure.
Definition CParticle.h:65
Base class for zones where particles can be spawned.
Definition CZone.h:66
EEmitter
Available particle emitter types.
Definition CEmitter.h:43
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Internal data for managing particle birth rates for sub-emitters.
Definition CEmitter.h:58
s32 Tank
Remaining particles to be spawned from the "tank".
Definition CEmitter.h:68
float LifeTime
Accumulated life time of the emitter logic.
Definition CEmitter.h:60
float Fraction
Fraction for sub-frame birth calculations.
Definition CEmitter.h:66
float WaitDelay
Initial delay before birth starts.
Definition CEmitter.h:64
float FlowLifeTime
Maximum duration for the flow logic.
Definition CEmitter.h:62