-
Notifications
You must be signed in to change notification settings - Fork 11
/
ParticleManager.cpp
64 lines (55 loc) · 1.54 KB
/
ParticleManager.cpp
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
#include "ParticleManager.h"
#include "RenderManager.h"
#include "Ogre.h"
ParticleManager::ParticleManager()
{
}
void ParticleManager::init()
{
MessageManager::getPtr()->subscribe<ShootEvent>(*this);
MessageManager::getPtr()->subscribe<ObjectDestroyed>(*this);
timeSinceLastDelete = 0;
particleSystems["explosion"] = new Particle("explosion","Supernova");
}
void ParticleManager::receive(const ShootEvent &evt)
{
if(evt.entity.valid())
{
entityx::Entity obj = evt.entity;
//TODO Bullet
}
}
void ParticleManager::receive(const ObjectDestroyed &evt)
{
if(evt.object.valid())
{
entityx::Entity obj = evt.object;
createEmitter("explosion", obj);
}
}
void ParticleManager::update(double dt)
{/*
timeSinceLastDelete += dt;
if(timeSinceLastDelete >= deleteInterval && !emitters.empty())
{
Ogre::ParticleEmitter *pe = emitters.front();
delete pe;
pe = 0;
emitters.erase(emitters.begin());
timeSinceLastDelete = 0;
}
*/
}
void ParticleManager::createEmitter(std::string name, entityx::Entity ent)
{
if(ent.valid())
{
Particle *part = particleSystems[name];
Ogre::ParticleEmitter *pe = part->partSys->addEmitter("Point");
part->partSys->getEmitter(0)->copyParametersTo(pe);
entityx::ptr<Position> pos = ent.component<Position>();
pe->setPosition(pos->position);
//emitters.push_back(pe);
part->partSys->setParticleQuota(part->originalQuota + part->partSys->getParticleQuota());
}
}