diff --git a/assets/Sounds/Brick/brickBreak-bak1.wav b/assets/Sounds/Brick/brickBreak-bak1.wav new file mode 100644 index 0000000..31d62ff Binary files /dev/null and b/assets/Sounds/Brick/brickBreak-bak1.wav differ diff --git a/assets/Sounds/Brick/brickBreak.wav b/assets/Sounds/Brick/brickBreak.wav index 31d62ff..5b800eb 100644 Binary files a/assets/Sounds/Brick/brickBreak.wav and b/assets/Sounds/Brick/brickBreak.wav differ diff --git a/include/Core/Engine.h b/include/Core/Engine.h index e5398b3..a32c479 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -36,7 +36,7 @@ #include "CTemplate.h" #include "Rendering/CPointLight.h" #include "Transform/TransformSystem.h" -#include "Core/Sound.h" +#include "Sound/SoundSystem.h" #include "Game/LevelSystem.h" #include "Game/PadSystem.h" #include "Game/CBall.h" @@ -76,8 +76,8 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); - m_World->SystemFactory.Register([this]() { return new Systems::Sound(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); + m_World->SystemFactory.Register([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); m_World->ComponentFactory.Register(); @@ -416,8 +416,6 @@ private: std::shared_ptr m_InputManager; std::shared_ptr m_World; - //TODO: Delete this please - std::shared_ptr m_Sound; double m_LastTime; }; diff --git a/include/Core/World.h b/include/Core/World.h index 65b4d6a..5c66d52 100644 --- a/include/Core/World.h +++ b/include/Core/World.h @@ -36,7 +36,6 @@ #include "EventBroker.h" #include "EComponentCreated.h" #include "ResourceManager.h" -#include "Sound.h" namespace dd { diff --git a/include/Core/EPlaySFX.h b/include/Sound/EPlaySFX.h similarity index 100% rename from include/Core/EPlaySFX.h rename to include/Sound/EPlaySFX.h diff --git a/include/Core/Sound.h b/include/Sound/SoundSystem.h similarity index 82% rename from include/Core/Sound.h rename to include/Sound/SoundSystem.h index 66c6348..5066aca 100644 --- a/include/Core/Sound.h +++ b/include/Sound/SoundSystem.h @@ -25,19 +25,22 @@ #include "Core/System.h" #include "Core/World.h" #include "Core/EKeyDown.h" -#include "Core/EPlaySFX.h" +#include "Sound/EPlaySFX.h" #include "Physics/EContact.h" #include "Core/EventBroker.h" +#include +#include +#include namespace dd { namespace Systems { -class Sound : public System { +class SoundSystem : public System { public: - Sound(World *world, std::shared_ptr eventBroker) + SoundSystem(World *world, std::shared_ptr eventBroker) : System(world, eventBroker) { } - ~Sound(); + ~SoundSystem(); void Initialize() override; //void UpdateEntity(double dt, EntityID entity, EntityID parent) override; @@ -53,9 +56,9 @@ public: private: //Events - dd::EventRelay m_EKeyDown; - dd::EventRelay m_EPlaySFX; - dd::EventRelay m_EContact; + dd::EventRelay m_EKeyDown; + dd::EventRelay m_EPlaySFX; + dd::EventRelay m_EContact; bool OnKeyDown(const dd::Events::KeyDown &event); bool OnPlaySFX(const dd::Events::PlaySFX &event); diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 0c4fac6..562dad8 100755 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -71,6 +71,12 @@ file(GLOB SOURCE_FILES_Game ) source_group(Game FILES ${SOURCE_FILES_Game}) +file(GLOB SOURCE_FILES_Sound + "${INCLUDE_PATH}/Sound/*.h" + "Sound/*.cpp" +) +source_group(Sound FILES ${SOURCE_FILES_Sound}) + set(SOURCE_FILES ${SOURCE_FILES_Core} ${SOURCE_FILES_Core_Util} @@ -78,7 +84,8 @@ set(SOURCE_FILES ${SOURCE_FILES_Rendering} ${SOURCE_FILES_Transform} ${SOURCE_FILES_Physics} - ${SOURCE_FILES_Game}) + ${SOURCE_FILES_Game} + ${SOURCE_FILES_Sound}) if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") diff --git a/src/game/Core/Sound.cpp b/src/game/Sound/SoundSystem.cpp similarity index 83% rename from src/game/Core/Sound.cpp rename to src/game/Sound/SoundSystem.cpp index f5b3023..fab5712 100644 --- a/src/game/Core/Sound.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -16,18 +16,16 @@ along with Daydream Engine. If not, see . */ -#include -#include -#include -#include "PrecompiledHeader.h" -#include "Core/Sound.h" -dd::Systems::Sound::~Sound() +#include "PrecompiledHeader.h" +#include "Sound/SoundSystem.h" + +dd::Systems::SoundSystem::~SoundSystem() { //alDeleteSources(1, m_Source); } -void dd::Systems::Sound::Initialize() +void dd::Systems::SoundSystem::Initialize() { //initialize OpenAL ALCdevice* device = alcOpenDevice(NULL); ALCcontext* context; @@ -45,12 +43,12 @@ void dd::Systems::Sound::Initialize() alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); //Subscribe to events - EVENT_SUBSCRIBE_MEMBER(m_EContact, &Sound::OnContact); - EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown); - EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &Sound::OnPlaySFX); + EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact); + EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &SoundSystem::OnKeyDown); + EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySFX); } -void dd::Systems::Sound::Update(double dt) +void dd::Systems::SoundSystem::Update(double dt) { const ALfloat pos[3] = {0, 0, 0}; alListenerfv(AL_POSITION, pos); @@ -58,7 +56,7 @@ void dd::Systems::Sound::Update(double dt) alSourcefv(m_Source, AL_POSITION, pos); } -bool dd::Systems::Sound::OnPlaySFX(const dd::Events::PlaySFX &event) +bool dd::Systems::SoundSystem::OnPlaySFX(const dd::Events::PlaySFX &event) { m_Source = CreateSource(); ALuint buffer = LoadFile(event.path); @@ -67,7 +65,7 @@ bool dd::Systems::Sound::OnPlaySFX(const dd::Events::PlaySFX &event) alSourcePlay(m_Source); } -bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event) +bool dd::Systems::SoundSystem::OnKeyDown(const dd::Events::KeyDown &event) { // #define GLFW_KEY_S 83 /*if (event.KeyCode == 83) { @@ -78,7 +76,7 @@ bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event) } } -bool dd::Systems::Sound::OnContact(const dd::Events::Contact &event) +bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) { int localBallEntID = 0; //Make sure a ball is colliding @@ -105,13 +103,13 @@ bool dd::Systems::Sound::OnContact(const dd::Events::Contact &event) collObject = event.Entity1; } - /*auto collisionBrick = m_World->GetComponent(collObject); + auto collisionBrick = m_World->GetComponent(collObject); if (collisionBrick != NULL) { dd::Events::PlaySFX e; e.path = "Sounds/Brick/brickBreak.wav"; EventBroker->Publish(e); return true; - }*/ + } auto collisionPad = m_World->GetComponent(collObject); if (collisionPad != NULL) { @@ -122,7 +120,7 @@ bool dd::Systems::Sound::OnContact(const dd::Events::Contact &event) } } -ALuint dd::Systems::Sound::CreateSource() +ALuint dd::Systems::SoundSystem::CreateSource() { ALuint source; alGenSources((ALuint)1, &source); @@ -130,7 +128,7 @@ ALuint dd::Systems::Sound::CreateSource() return source; } -ALuint dd::Systems::Sound::LoadFile(std::string path) +ALuint dd::Systems::SoundSystem::LoadFile(std::string path) { if (m_BufferCache.find(path) != m_BufferCache.end()) { return m_BufferCache[path];