Skylicht Engine
Loading...
Searching...
No Matches
CParticleComponent.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 "Components/CComponentSystem.h"
28#include "Particles/CFactory.h"
29#include "CParticleBufferData.h"
30
31namespace Skylicht
32{
33 namespace Particle
34 {
65 class COMPONENT_API CParticleComponent : public CComponentSystem
66 {
67 protected:
72
77
81 std::string m_sourcePath;
82
87
88 public:
89 CParticleComponent();
90
91 virtual ~CParticleComponent();
92
96 virtual void initComponent();
97
101 virtual void startComponent();
102
106 virtual void updateComponent();
107
112
117
118 public:
119
125 {
126 return &m_factory;
127 }
128
134 {
135 return m_data;
136 }
137
143
149
156
161 {
162 return m_data->Groups.size();
163 }
164
168 inline CGroup* getGroup(int i)
169 {
170 return m_data->Groups[i];
171 }
172
177
183 void updateParticleCountByPercentage(float f, bool includeSubGroup = false);
184
188 void Play();
189
193 void Stop();
194
198 bool IsPlaying();
199
204
209
213 inline const char* getSourcePath()
214 {
215 return m_sourcePath.c_str();
216 }
217
221 inline void setSourcePath(const char* path)
222 {
223 m_sourcePath = path;
224 }
225
230 bool load();
231
236 bool save();
237
241 inline int getFrameUpdated()
242 {
243 return m_frameUpdate;
244 }
245
250
255
256 DECLARE_GETTYPENAME(CParticleComponent)
257
258 protected:
259
264
269
274
279
284
289
294
299 };
300 }
301}
Definition CObjectSerializable.h:36
Base class for particle emitters.
Definition CEmitter.h:88
Factory class for creating emitters, zones, and renderers.
Definition CFactory.h:61
Represents a group of particles with shared settings, emitters, and a renderer.
Definition CGroup.h:132
ECS data structure holding particle groups for an entity.
Definition CParticleBufferData.h:43
void setGroupTransform(const core::matrix4 &world)
Updates the transform of all particle groups.
void setSourcePath(const char *path)
Sets the .particle file path.
Definition CParticleComponent.h:221
void clearParticles()
Immediately removes all active particles across all groups.
CGroup * getGroup(int i)
Retrieves a specific group by index.
Definition CParticleComponent.h:168
void loadGroup(Particle::CGroup *group, CObjectSerializable *object)
Internal serialization loading helper for a specific group.
bool load()
Loads the particle system configuration from m_sourcePath.
void Stop()
Stops all emitters and clears immortal particles.
CFactory * getParticleFactory()
Gets the internal particle factory.
Definition CParticleComponent.h:124
CGroup * duplicateGroup(CGroup *group)
Clones a particle group.
virtual void loadSerializable(CObjectSerializable *object)
Loads properties from a serializable object.
void Play()
Resets all emitters and starts playback.
virtual void updateComponent()
Updates the internal frame counter.
bool save()
Saves the current particle system configuration to m_sourcePath.
u32 getNumOfGroup()
Gets the number of top-level groups.
Definition CParticleComponent.h:160
CGroup * createParticleGroup()
Creates a new top-level particle group managed by this component.
CFactory m_factory
Internal factory for creating particle objects.
Definition CParticleComponent.h:76
int getFrameUpdated()
Gets the current frame update count.
Definition CParticleComponent.h:241
CSubGroup * createParticleSubGroup(CGroup *group)
Creates a sub-group attached to a parent group.
void loadEmitters(Particle::CGroup *group, io::IXMLReader *reader)
Internal XML loading helper for emitters.
virtual void initComponent()
Initializes component data and required ECS systems.
void loadGroup(Particle::CGroup *group, io::IXMLReader *reader)
Internal XML loading helper for a specific group.
bool IsPlaying()
Checks if any particle is currently alive.
virtual CObjectSerializable * createSerializable()
Creates a serializable object for property editing.
u32 getTotalParticle()
Gets the total count of active particles in all groups.
CParticleBufferData * m_data
Cached pointer to the ECS entity data.
Definition CParticleComponent.h:71
void updateParticleCountByPercentage(float f, bool includeSubGroup=false)
Dynamically adjusts the emission rate of all emitters.
CEmitter * duplicateEmitter(CGroup *group, CEmitter *emitter)
Clones an emitter within a group.
virtual void startComponent()
Starts the component, loading the particle source if set.
void removeParticleGroup(CGroup *group)
Removes a specific group from the component.
void loadSubGroups(Particle::CGroup *group, io::IXMLReader *reader)
Internal XML loading helper for sub-groups.
int m_frameUpdate
Frame counter for update synchronization.
Definition CParticleComponent.h:86
void saveGroup(Particle::CGroup *group, CObjectSerializable *object)
Internal serialization helper for a specific group.
void loadRenderer(Particle::CGroup *group, io::IXMLReader *reader)
Internal XML loading helper for renderers.
std::string m_sourcePath
Path to the .particle source file.
Definition CParticleComponent.h:81
const char * getSourcePath()
Gets the current .particle file path.
Definition CParticleComponent.h:213
CParticleBufferData * getData()
Gets the ECS entity data holding particle groups.
Definition CParticleComponent.h:133
void saveGroups(CObjectSerializable *groups)
Internal serialization helper.
void loadModels(Particle::CGroup *group, io::IXMLReader *reader)
Internal XML loading helper for models.
A particle group that spawns particles from the positions of particles in a parent group.
Definition CSubGroup.h:50
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
IIrrXMLReader< wchar_t, IReferenceCounted > IXMLReader
An xml reader for wide characters, derived from IReferenceCounted.
Definition IXMLReader.h:19
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58