Using ResourceManager for cached laoding of sounds.
This commit is contained in:
@@ -42,14 +42,14 @@ void InputManager::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
// if(m_CurrentKeyState[GLFW_KEY_Z]) //TEMP
|
||||
// {
|
||||
// Events::PlaySound e;
|
||||
// e.Resource = "Sounds/BGM/WUB.mp3";
|
||||
// e.Emitter = 66;
|
||||
// e.Loop = true;
|
||||
// EventBroker->Publish(e);
|
||||
// }
|
||||
if(m_CurrentKeyState[GLFW_KEY_Z]) //TEMP
|
||||
{
|
||||
Events::PlaySound e;
|
||||
e.Resource = "Sounds/BGM/WUB.mp3";
|
||||
e.Emitter = 66;
|
||||
e.Loop = true;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
// Mouse buttons
|
||||
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include "Events/LockMouse.h"
|
||||
#include "Events/GamepadAxis.h"
|
||||
#include "Events/GamepadButton.h"
|
||||
//#include "Events/PlaySound.h" //Temp
|
||||
#include "Events/PlaySound.h" //Temp
|
||||
|
||||
class InputManager
|
||||
{
|
||||
|
||||
+8
-2
@@ -1,7 +1,13 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Sound.h"
|
||||
|
||||
Sound::Sound(std::string path)
|
||||
{
|
||||
|
||||
Sound::Sound(std::string path, FMOD_SYSTEM* system)
|
||||
{
|
||||
FMOD_System_CreateSound(system, path.c_str(), FMOD_3D, NULL, &m_Sound);
|
||||
}
|
||||
|
||||
Sound::~Sound()
|
||||
{
|
||||
|
||||
}
|
||||
+9
-1
@@ -2,11 +2,19 @@
|
||||
#define Sound_h__
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include <fmod.h>
|
||||
#include <fmod_errors.h>
|
||||
|
||||
class Sound : public Resource
|
||||
{
|
||||
public:
|
||||
Sound(std::string path);
|
||||
Sound(std::string path, FMOD_SYSTEM* system);
|
||||
~Sound();
|
||||
|
||||
operator FMOD_SOUND*() const { return m_Sound; }
|
||||
|
||||
private:
|
||||
FMOD_SOUND* m_Sound;
|
||||
};
|
||||
|
||||
#endif // Sound_h__
|
||||
|
||||
@@ -30,7 +30,7 @@ void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
|
||||
|
||||
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
{
|
||||
rm->RegisterType("Sound", [](std::string resourceName) { return new Sound(resourceName); });
|
||||
rm->RegisterType("Sound", [this](std::string resourceName) { return new Sound(resourceName, this->m_System); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::Update(double dt)
|
||||
@@ -132,12 +132,9 @@ bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event)
|
||||
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;
|
||||
}
|
||||
|
||||
// if(emitter->Path != event.Resource) //Caching sound file
|
||||
// {
|
||||
LoadSound(m_Sounds[event.Emitter], event.Resource, 1000.f, 1.f);
|
||||
// emitter->Path = event.Resource;
|
||||
// }
|
||||
Sound* sound = m_World->GetResourceManager()->Load<Sound>("Sound", event.Resource);
|
||||
m_Sounds[event.Emitter] = *sound;
|
||||
//LoadSound(m_Sounds[event.Emitter], event.Resource, 1000.f, 1.f);
|
||||
|
||||
PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop);
|
||||
FMOD_System_Update(m_System);
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentRemoved(std::string type, Component* component);
|
||||
|
||||
FMOD_SYSTEM* GetFMODSystem() const { return m_System; }
|
||||
private:
|
||||
// Events
|
||||
EventRelay<SoundSystem, Events::ComponentCreated> m_EComponentCreated;
|
||||
|
||||
Reference in New Issue
Block a user