Använder Eventbaserade OnComponentCreated funktionen

This commit is contained in:
Stiffly
2014-05-25 04:02:08 +02:00
parent 072e4d4dbb
commit e3e0d549f5
3 changed files with 61 additions and 69 deletions
+37 -31
View File
@@ -54,6 +54,19 @@ void GameWorld::Initialize()
auto cameraComp = AddComponent<Components::Camera>(camera);
cameraComp->FarClip = 2000.f;
auto freeSteering = AddComponent<Components::FreeSteering>(camera);
{
auto se1 = CreateEntity(camera);
auto transform = AddComponent<Components::Transform>(se1);
transform->Position = glm::vec3(0,10,0);
transform->Scale = glm::vec3(3);
auto emitterComponent = AddComponent<Components::SoundEmitter>(se1);
emitterComponent->Path = "Sounds/WUB.mp3";
emitterComponent->MinDistance = 1.f;
emitterComponent->MaxDistance = 10000.f;
emitterComponent->Gain = 1;
// auto model = AddComponent<Components::Model>(se1);
// model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
}
}
CommitEntity(camera);
@@ -660,6 +673,8 @@ void GameWorld::Initialize()
CommitEntity(particleEntity);
}
CommitEntity(tank);
}
@@ -1076,6 +1091,8 @@ void GameWorld::Initialize()
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
CommitEntity(tank);
@@ -1105,7 +1122,7 @@ void GameWorld::Initialize()
CommitEntity(entity);
}*/
for(int i = 0; i < 1; i++)
/*for(int i = 0; i < 1; i++)
{
for (int y = 0; y < 15; y++)
{
@@ -1136,37 +1153,26 @@ void GameWorld::Initialize()
CommitEntity(brick);
}
}
}
}*/
{
auto se1 = CreateEntity();
auto transform = AddComponent<Components::Transform>(se1);
transform->Position = glm::vec3(0,10,0);
transform->Scale = glm::vec3(3);
auto emitterComponent = AddComponent<Components::SoundEmitter>(se1);
emitterComponent->Path = "Sounds/WUB.mp3";
emitterComponent->MinDistance = 1.f;
emitterComponent->MaxDistance = 50.f;
emitterComponent->Gain = 1;
auto model = AddComponent<Components::Model>(se1);
model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
CommitEntity(se1);
}
{
auto se2 = CreateEntity();
auto transform = AddComponent<Components::Transform>(se2);
transform->Position = glm::vec3(100,10,0);
transform->Scale = glm::vec3(3);
auto emitterComponent = AddComponent<Components::SoundEmitter>(se2);
emitterComponent->Path = "Sounds/DarkHorse.mp3";
emitterComponent->Gain = 1;
emitterComponent->MinDistance = 1.f;
emitterComponent->MaxDistance = 50.f;
auto model = AddComponent<Components::Model>(se2);
model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
CommitEntity(se2);
}
// {
//
// }
//
// {
// auto se2 = CreateEntity();
// auto transform = AddComponent<Components::Transform>(se2);
// transform->Position = glm::vec3(100,10,0);
// transform->Scale = glm::vec3(3);
// auto emitterComponent = AddComponent<Components::SoundEmitter>(se2);
// emitterComponent->Path = "Sounds/DarkHorse.mp3";
// emitterComponent->Gain = 1;
// emitterComponent->MinDistance = 1.f;
// emitterComponent->MaxDistance = 50.f;
// auto model = AddComponent<Components::Model>(se2);
// model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
// CommitEntity(se2);
// }
/*for (int x = 0; x < 5; x++)
+21 -34
View File
@@ -4,6 +4,7 @@
void Systems::SoundSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
/*FMOD_RESULT result;
result = FMOD::System_Create(&m_FmodSystem);
result = m_FmodSystem->init(32, FMOD_INIT_NORMAL, 0);
@@ -88,54 +89,40 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
}
}
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &event)
{
// if(type == typeid(Components::Listener).name())
// {
// m_Listeners.push_back(component->Entity);
// }
//
// if (type == typeid(Components::SoundEmitter).name())
// {
// //std::shared_ptr<Components::SoundEmitter> eComponent = std::dynamic_pointer_cast<Components::SoundEmitter>(component);
//
// FMOD_CHANNEL* channel;
// m_Channels.insert(std::pair<EntityID, FMOD_CHANNEL*>(component->Entity, channel));
//
// LoadSound("Sounds/DarkHorse.mp3", 100, 30, false, 1, 0);
// }
}
void Systems::SoundSystem::OnEntityCommit(EntityID entity)
{
//TEMP ska slängas in i OnComponentCreated
auto lComponent = m_World->GetComponent<Components::Listener>(entity);
if(lComponent)
auto listener = std::dynamic_pointer_cast<Components::Listener>(event.Component);
if(listener)
{
m_Listeners.push_back(entity);
m_Listeners.push_back(listener->Entity);
}
auto eCompoonent = m_World->GetComponent<Components::SoundEmitter>(entity);
if(eCompoonent)
auto emitter = std::dynamic_pointer_cast<Components::SoundEmitter>(event.Component);
if(emitter)
{
FMOD_CHANNEL* channel;
FMOD_SOUND* sound;
std::string path = eCompoonent->Path;
float volume = eCompoonent->Gain;
bool loop = eCompoonent->Loop;
float maxDist = eCompoonent->MaxDistance;
float minDist = eCompoonent->MinDistance;
float pitch = eCompoonent->Pitch;
std::string path = emitter->Path;
float volume = emitter->Gain;
bool loop = emitter->Loop;
float maxDist = emitter->MaxDistance;
float minDist = emitter->MinDistance;
float pitch = emitter->Pitch;
if(LoadSound(sound, path, maxDist, minDist, loop, volume, pitch) != FMOD_OK)
LOG_ERROR("FMOD did not load sound file");
m_Channels.insert(std::make_pair(entity, channel));
m_Sounds.insert(std::make_pair(entity, sound));
std::cout<<path<<std::endl;
m_Channels.insert(std::make_pair(emitter->Entity, channel));
m_Sounds.insert(std::make_pair(emitter->Entity, sound));
}
return true;
}
FMOD_RESULT Systems::SoundSystem::LoadSound(FMOD_SOUND* &sound, std::string filePath, float maxDist, float minDist, bool loop, float volume, float pitch)
{
FMOD_RESULT result = FMOD_System_CreateSound(m_System, filePath.c_str(), FMOD_3D , 0, &sound);
+3 -4
View File
@@ -8,6 +8,7 @@
#include "Components/Transform.h"
#include "Components/SoundEmitter.h"
#include "Components/Listener.h"
#include "Events/ComponentCreated.h"
#include "Events/PlaySound.h"
#include "Sound.h"
@@ -25,13 +26,11 @@ public:
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
void OnEntityCommit(EntityID entity) override;
private:
// Events
EventRelay<SoundSystem, Events::ComponentCreated> m_EComponentCreated;
bool OnComponentCreated(const Events::ComponentCreated &event);
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float);