diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 173c8c2..3edaff5 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -54,6 +54,19 @@ void GameWorld::Initialize() auto cameraComp = AddComponent(camera); cameraComp->FarClip = 2000.f; auto freeSteering = AddComponent(camera); + { + auto se1 = CreateEntity(camera); + auto transform = AddComponent(se1); + transform->Position = glm::vec3(0,10,0); + transform->Scale = glm::vec3(3); + auto emitterComponent = AddComponent(se1); + emitterComponent->Path = "Sounds/WUB.mp3"; + emitterComponent->MinDistance = 1.f; + emitterComponent->MaxDistance = 10000.f; + emitterComponent->Gain = 1; +// auto model = AddComponent(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(se1); - transform->Position = glm::vec3(0,10,0); - transform->Scale = glm::vec3(3); - auto emitterComponent = AddComponent(se1); - emitterComponent->Path = "Sounds/WUB.mp3"; - emitterComponent->MinDistance = 1.f; - emitterComponent->MaxDistance = 50.f; - emitterComponent->Gain = 1; - auto model = AddComponent(se1); - model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj"; - CommitEntity(se1); - } - - { - auto se2 = CreateEntity(); - auto transform = AddComponent(se2); - transform->Position = glm::vec3(100,10,0); - transform->Scale = glm::vec3(3); - auto emitterComponent = AddComponent(se2); - emitterComponent->Path = "Sounds/DarkHorse.mp3"; - emitterComponent->Gain = 1; - emitterComponent->MinDistance = 1.f; - emitterComponent->MaxDistance = 50.f; - auto model = AddComponent(se2); - model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj"; - CommitEntity(se2); - } +// { +// +// } +// +// { +// auto se2 = CreateEntity(); +// auto transform = AddComponent(se2); +// transform->Position = glm::vec3(100,10,0); +// transform->Scale = glm::vec3(3); +// auto emitterComponent = AddComponent(se2); +// emitterComponent->Path = "Sounds/DarkHorse.mp3"; +// emitterComponent->Gain = 1; +// emitterComponent->MinDistance = 1.f; +// emitterComponent->MaxDistance = 50.f; +// auto model = AddComponent(se2); +// model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj"; +// CommitEntity(se2); +// } /*for (int x = 0; x < 5; x++) diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 2a5aca7..f6cd57f 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -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) +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 eComponent = std::dynamic_pointer_cast(component); -// -// FMOD_CHANNEL* channel; -// m_Channels.insert(std::pair(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(entity); - if(lComponent) + auto listener = std::dynamic_pointer_cast(event.Component); + if(listener) { - m_Listeners.push_back(entity); + m_Listeners.push_back(listener->Entity); } - auto eCompoonent = m_World->GetComponent(entity); - if(eCompoonent) + auto emitter = std::dynamic_pointer_cast(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<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); diff --git a/src/Systems/SoundSystem.h b/src/Systems/SoundSystem.h index 63a5a88..8d9d25e 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -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) override; - void OnEntityCommit(EntityID entity) override; - - private: // Events + EventRelay m_EComponentCreated; + bool OnComponentCreated(const Events::ComponentCreated &event); EventRelay m_EPlaySound; FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float);