Använder Eventbaserade OnComponentCreated funktionen
This commit is contained in:
+37
-31
@@ -54,6 +54,19 @@ void GameWorld::Initialize()
|
|||||||
auto cameraComp = AddComponent<Components::Camera>(camera);
|
auto cameraComp = AddComponent<Components::Camera>(camera);
|
||||||
cameraComp->FarClip = 2000.f;
|
cameraComp->FarClip = 2000.f;
|
||||||
auto freeSteering = AddComponent<Components::FreeSteering>(camera);
|
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);
|
CommitEntity(camera);
|
||||||
|
|
||||||
@@ -660,6 +673,8 @@ void GameWorld::Initialize()
|
|||||||
CommitEntity(particleEntity);
|
CommitEntity(particleEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CommitEntity(tank);
|
CommitEntity(tank);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1076,6 +1091,8 @@ void GameWorld::Initialize()
|
|||||||
emitterComponent->ParticleTemplate = particleEntity;
|
emitterComponent->ParticleTemplate = particleEntity;
|
||||||
|
|
||||||
CommitEntity(particleEntity);
|
CommitEntity(particleEntity);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommitEntity(tank);
|
CommitEntity(tank);
|
||||||
@@ -1105,7 +1122,7 @@ void GameWorld::Initialize()
|
|||||||
CommitEntity(entity);
|
CommitEntity(entity);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
for(int i = 0; i < 1; i++)
|
/*for(int i = 0; i < 1; i++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < 15; y++)
|
for (int y = 0; y < 15; y++)
|
||||||
{
|
{
|
||||||
@@ -1136,37 +1153,26 @@ void GameWorld::Initialize()
|
|||||||
CommitEntity(brick);
|
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);
|
// auto se2 = CreateEntity();
|
||||||
emitterComponent->Path = "Sounds/WUB.mp3";
|
// auto transform = AddComponent<Components::Transform>(se2);
|
||||||
emitterComponent->MinDistance = 1.f;
|
// transform->Position = glm::vec3(100,10,0);
|
||||||
emitterComponent->MaxDistance = 50.f;
|
// transform->Scale = glm::vec3(3);
|
||||||
emitterComponent->Gain = 1;
|
// auto emitterComponent = AddComponent<Components::SoundEmitter>(se2);
|
||||||
auto model = AddComponent<Components::Model>(se1);
|
// emitterComponent->Path = "Sounds/DarkHorse.mp3";
|
||||||
model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
|
// emitterComponent->Gain = 1;
|
||||||
CommitEntity(se1);
|
// emitterComponent->MinDistance = 1.f;
|
||||||
}
|
// emitterComponent->MaxDistance = 50.f;
|
||||||
|
// auto model = AddComponent<Components::Model>(se2);
|
||||||
{
|
// model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
|
||||||
auto se2 = CreateEntity();
|
// CommitEntity(se2);
|
||||||
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++)
|
/*for (int x = 0; x < 5; x++)
|
||||||
|
|||||||
+21
-34
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
void Systems::SoundSystem::Initialize()
|
void Systems::SoundSystem::Initialize()
|
||||||
{
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
|
||||||
/*FMOD_RESULT result;
|
/*FMOD_RESULT result;
|
||||||
result = FMOD::System_Create(&m_FmodSystem);
|
result = FMOD::System_Create(&m_FmodSystem);
|
||||||
result = m_FmodSystem->init(32, FMOD_INIT_NORMAL, 0);
|
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)
|
||||||
{
|
{
|
||||||
|
auto listener = std::dynamic_pointer_cast<Components::Listener>(event.Component);
|
||||||
// if(type == typeid(Components::Listener).name())
|
if(listener)
|
||||||
// {
|
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
m_Listeners.push_back(entity);
|
m_Listeners.push_back(listener->Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eCompoonent = m_World->GetComponent<Components::SoundEmitter>(entity);
|
auto emitter = std::dynamic_pointer_cast<Components::SoundEmitter>(event.Component);
|
||||||
if(eCompoonent)
|
if(emitter)
|
||||||
{
|
{
|
||||||
FMOD_CHANNEL* channel;
|
FMOD_CHANNEL* channel;
|
||||||
FMOD_SOUND* sound;
|
FMOD_SOUND* sound;
|
||||||
|
|
||||||
std::string path = eCompoonent->Path;
|
std::string path = emitter->Path;
|
||||||
float volume = eCompoonent->Gain;
|
float volume = emitter->Gain;
|
||||||
bool loop = eCompoonent->Loop;
|
bool loop = emitter->Loop;
|
||||||
float maxDist = eCompoonent->MaxDistance;
|
float maxDist = emitter->MaxDistance;
|
||||||
float minDist = eCompoonent->MinDistance;
|
float minDist = emitter->MinDistance;
|
||||||
float pitch = eCompoonent->Pitch;
|
float pitch = emitter->Pitch;
|
||||||
|
|
||||||
if(LoadSound(sound, path, maxDist, minDist, loop, volume, pitch) != FMOD_OK)
|
if(LoadSound(sound, path, maxDist, minDist, loop, volume, pitch) != FMOD_OK)
|
||||||
LOG_ERROR("FMOD did not load sound file");
|
LOG_ERROR("FMOD did not load sound file");
|
||||||
m_Channels.insert(std::make_pair(entity, channel));
|
std::cout<<path<<std::endl;
|
||||||
m_Sounds.insert(std::make_pair(entity, sound));
|
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 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);
|
FMOD_RESULT result = FMOD_System_CreateSound(m_System, filePath.c_str(), FMOD_3D , 0, &sound);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/SoundEmitter.h"
|
#include "Components/SoundEmitter.h"
|
||||||
#include "Components/Listener.h"
|
#include "Components/Listener.h"
|
||||||
|
#include "Events/ComponentCreated.h"
|
||||||
#include "Events/PlaySound.h"
|
#include "Events/PlaySound.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
@@ -25,13 +26,11 @@ public:
|
|||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) 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:
|
private:
|
||||||
// Events
|
// Events
|
||||||
|
EventRelay<SoundSystem, Events::ComponentCreated> m_EComponentCreated;
|
||||||
|
bool OnComponentCreated(const Events::ComponentCreated &event);
|
||||||
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
|
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
|
||||||
|
|
||||||
FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float);
|
FMOD_RESULT LoadSound(FMOD_SOUND*&, std::string, float, float, bool, float, float);
|
||||||
|
|||||||
Reference in New Issue
Block a user