... even more event-based

This commit is contained in:
Stiffly
2014-05-27 07:09:22 +02:00
parent 5d53472286
commit 571edbc214
2 changed files with 20 additions and 37 deletions
+14 -34
View File
@@ -8,7 +8,7 @@ void Systems::ParticleSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
tempSpawnedExplosions = false;
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ParticleSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EExplosion, &ParticleSystem::CreateExplosion);
}
void Systems::ParticleSystem::Update(double dt)
@@ -225,53 +225,33 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect
alpha = spectrum[0] + dAlpha * timeProgress;
}
void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale)
bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e)
{
auto explosion = m_World->CreateEntity();
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
emitter->LifeTime = _lifeTime;
emitter->SpawnCount = _particlesToSpawn;
emitter->Speed = _speed;
emitter->SpreadAngle = _spreadAngle;
emitter->SpawnFrequency = _lifeTime + 20; //temp
// emitter->UseGoalVelocity = true;
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
emitter->LifeTime = e.LifeTime;
emitter->SpawnCount = e.ParticlesToSpawn;
emitter->Speed = e.Speed;
emitter->SpreadAngle = e.SpreadAngle;
emitter->SpawnFrequency = e.LifeTime + 20; //temp
// emitter->UseGoalVelocity = true;
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
m_World->CommitEntity(explosion);
auto particleEnt = m_World->CreateEntity();
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
spriteComponent->SpriteFile = _spritePath;
spriteComponent->SpriteFile = e.spritePath;
m_World->CommitEntity(particleEnt);
emitter->ParticleTemplate = particleEnt;
auto transform = m_World->AddComponent<Components::Transform>(explosion);
transform->Position = _pos;
transform->Orientation = _relativeUpOri;
transform->Position = e.Position;
transform->Orientation = e.RelativeUpOrientation;
SpawnParticles(explosion);
m_ExplosionEmitters[explosion] = glfwGetTime();
}
bool Systems::ParticleSystem::OnKeyUp(const Events::KeyUp &e)
{
if(!tempSpawnedExplosions)
{
if (e.KeyCode == GLFW_KEY_B)
{
tempSpawnedExplosions = true;
CreateExplosion(
glm::vec3(0, 10, 0),
0.5,
60,
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
40,
glm::pi<float>(),
0.5f
);
}
}
return true;
}
+6 -3
View File
@@ -9,6 +9,7 @@
#include "Components/Sprite.h"
#include "EventBroker.h"
#include "Events/KeyUp.h"
#include "Events/CreateExplosion.h"
#include "Color.h"
#include <GLFW/glfw3.h>
@@ -35,7 +36,7 @@ public:
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
void Initialize() override;
void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
//void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
virtual bool OnCommand(const Events::KeyUp &event) { return false; }
@@ -54,8 +55,10 @@ private:
bool tempSpawnedExplosions;
EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp &e);
// EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
// bool OnKeyUp(const Events::KeyUp &e);
EventRelay<ParticleSystem, Events::CreateExplosion> m_EExplosion;
bool CreateExplosion(const Events::CreateExplosion &e);
};