PlaySFX now uses Position instead of Emitter ID for playing a sound.
This commit is contained in:
+10
-1
@@ -9,8 +9,17 @@ namespace Events
|
||||
|
||||
struct PlaySFX : Event
|
||||
{
|
||||
EntityID Emitter;
|
||||
PlaySFX() :
|
||||
MinDistance(100.f),
|
||||
MaxDistance(10000.f),
|
||||
Volume(1.f),
|
||||
Loop (false) {}
|
||||
//EntityID Emitter;
|
||||
glm::vec3 Position;
|
||||
std::string Resource;
|
||||
float MinDistance;
|
||||
float MaxDistance;
|
||||
float Volume;
|
||||
bool Loop;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ bool Systems::DebugSystem::OnKeyDown(const Events::KeyDown &event)
|
||||
if (event.KeyCode == GLFW_KEY_ENTER)
|
||||
{
|
||||
Events::PlaySFX e;
|
||||
e.Emitter = 0;
|
||||
e.Position = glm::vec3(0);
|
||||
e.Resource = "Sounds/korvring.wav";
|
||||
EventBroker->Publish<Events::PlaySFX>(e);
|
||||
|
||||
|
||||
+19
-18
@@ -128,27 +128,28 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
|
||||
|
||||
bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
|
||||
{
|
||||
auto emitter = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
|
||||
if(!emitter)
|
||||
{
|
||||
LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter];
|
||||
return false;
|
||||
}
|
||||
// auto emitter = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
|
||||
// if(!emitter)
|
||||
// {
|
||||
// LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter];
|
||||
// return false;
|
||||
// }
|
||||
|
||||
auto eEntity = m_World->CreateEntity();
|
||||
auto eTransform = m_World->AddComponent<Components::Transform>(eEntity);
|
||||
eTransform->Position = event.Position;
|
||||
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(eEntity);
|
||||
eComponent->MinDistance = event.MinDistance;
|
||||
eComponent->MaxDistance= event.MaxDistance;
|
||||
eComponent->Loop = event.Loop;
|
||||
eComponent->Gain = event.Volume;
|
||||
|
||||
emitter->type = Components::SoundEmitter::SoundType::SOUND_3D;
|
||||
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
|
||||
Sound* sound = ResourceManager->Load<Sound>("Sound3D", event.Resource);
|
||||
m_Sounds[event.Emitter] = *sound;
|
||||
FMOD_Sound_Set3DMinMaxDistance(*sound, emitter->MinDistance, emitter->MaxDistance);
|
||||
m_Sounds[eEntity] = *sound;
|
||||
FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance);
|
||||
|
||||
PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop);
|
||||
FMOD_System_Update(m_System);
|
||||
|
||||
FMOD_BOOL isPlaying = false;
|
||||
FMOD_Channel_IsPlaying(m_Channels[event.Emitter], &isPlaying);
|
||||
if(!isPlaying)
|
||||
LOG_ERROR("FMOD: File %s is not playing", event.Resource.c_str());
|
||||
else
|
||||
LOG_INFO("Now playing sound %s", event.Resource.c_str());
|
||||
PlaySound(&m_Channels[eEntity], m_Sounds[eEntity], 1.0, eComponent->Loop);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
|
||||
Events::PlaySFX e;
|
||||
e.Resource = "Sounds/SFX/LongBoom.wav";
|
||||
e.Emitter = entity;
|
||||
e.Position = absoluteTransform.Position;
|
||||
e.Loop = false;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user