TDME2  1.9.200
PointsParticleSystem.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
8 #include <tdme/engine/Engine.h>
10 #include <tdme/engine/Transform.h>
11 
12 using std::string;
13 
20 
21 PointsParticleSystem::PointsParticleSystem(const string& id, ParticleEmitter* emitter, int32_t maxPoints, float pointSize, bool autoEmit, Texture* texture, int32_t textureHorizontalSprites, int32_t textureVerticalSprites, float fps) :
22  PointsParticleSystemInternal(id, emitter, maxPoints, pointSize, autoEmit, texture, textureHorizontalSprites, textureVerticalSprites, fps)
23 {
24 }
25 
27 {
28  PointsParticleSystemInternal::initialize();
29 }
30 
32 {
33  PointsParticleSystemInternal::setTransform(transform);
34  //
35  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
36 }
37 
39 {
40  //
41  PointsParticleSystemInternal::update();
42  //
43  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
44 }
45 
47 {
48  // return if enable state has not changed
49  if (this->enabled == enabled) return;
50  // frustum if root entity
51  if (parentEntity == nullptr) {
52  // frustum culling enabled?
53  if (frustumCulling == true) {
54  // yeo, add or remove from partition
55  if (enabled == true) {
56  if (engine != nullptr) engine->partition->addEntity(this);
57  } else {
58  if (engine != nullptr) engine->partition->removeEntity(this);
59  }
60  }
61  }
62  // call parent class::setEnabled()
63  PointsParticleSystemInternal::setEnabled(enabled);
64 }
65 
67 {
68  PointsParticleSystemInternal::updateParticles();
69  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
70 }
71 
73  return frustumCulling;
74 }
75 
76 void PointsParticleSystem::setFrustumCulling(bool frustumCulling) {
77  // check if enabled and engine attached
78  if (enabled == true && engine != nullptr) {
79  // had frustum culling
80  if (this->frustumCulling == true) {
81  // yep, remove if set to false now
82  if (frustumCulling == false) engine->partition->removeEntity(this);
83  } else {
84  // yep, add if set to true now
85  if (frustumCulling == true) engine->partition->addEntity(this);
86  }
87  }
88  this->frustumCulling = frustumCulling;
89  // delegate change to engine
90  engine->registerEntity(this);
91 }
92 
93 void PointsParticleSystem::setAutoEmit(bool autoEmit) {
94  if (this->isAutoEmit() == autoEmit) return;
95  // delegate to base class
96  PointsParticleSystemInternal::setAutoEmit(autoEmit);
97  // delegate change to engine
98  engine->registerEntity(this);
99 }
100 
102 {
103  PointsParticleSystemInternal::dispose();
104 }
105 
107 {
108  if (this->engine != nullptr) this->engine->deregisterEntity(this);
109  this->engine = engine;
110  if (engine != nullptr) engine->registerEntity(this);
111  PointsParticleSystemInternal::setEngine(engine);
112 }
113 
115 {
116  PointsParticleSystemInternal::setRenderer(renderer);
117 }
118 
Engine main class.
Definition: Engine.h:131
unique_ptr< Partition > partition
Definition: Engine.h:289
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
Definition: Engine.cpp:382
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Definition: Engine.cpp:437
Entity * parentEntity
Definition: Entity.h:39
Point particle system entity to be used with engine class.
void updateParticles() override
Updates the particle entity.
void dispose() override
Dispose this entity.
void initialize() override
Initiates this entity.
void update() override
Update transform.
void setTransform(const Transform &transform) override
Set transform.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setAutoEmit(bool autoEmit) override
Set auto emit.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
void setRenderer(Renderer *renderer) override
Set up renderer.
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Partition interface.
Definition: Partition.h:18