Made a Sound folder. Rename class Sound to SoundSystem.

Also awesome Cmakeness.
This commit is contained in:
Stiffly
2015-09-17 14:42:33 +02:00
parent 250e70ff50
commit 6671136a08
8 changed files with 37 additions and 32 deletions
Binary file not shown.
Binary file not shown.
+3 -5
View File
@@ -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<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->SystemFactory.Register<Systems::Sound>([this]() { return new Systems::Sound(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::Sound>();
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::SoundSystem>();
m_World->ComponentFactory.Register<Components::Sprite>();
@@ -416,8 +416,6 @@ private:
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
//TODO: Delete this please
std::shared_ptr<dd::Systems::Sound> m_Sound;
double m_LastTime;
};
-1
View File
@@ -36,7 +36,6 @@
#include "EventBroker.h"
#include "EComponentCreated.h"
#include "ResourceManager.h"
#include "Sound.h"
namespace dd
{
@@ -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 <Game/CBall.h>
#include <Game/CBrick.h>
#include <Game/CPad.h>
namespace dd
{
namespace Systems
{
class Sound : public System {
class SoundSystem : public System {
public:
Sound(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
SoundSystem(World *world, std::shared_ptr<dd::EventBroker> 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<Sound, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<Sound, dd::Events::PlaySFX> m_EPlaySFX;
dd::EventRelay<Sound, dd::Events::Contact> m_EContact;
dd::EventRelay<SoundSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<SoundSystem, dd::Events::PlaySFX> m_EPlaySFX;
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnPlaySFX(const dd::Events::PlaySFX &event);
+8 -1
View File
@@ -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")
@@ -16,18 +16,16 @@
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Game/CBall.h>
#include <Game/CBrick.h>
#include <Game/CPad.h>
#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<Components::Brick>(collObject);
auto collisionBrick = m_World->GetComponent<Components::Brick>(collObject);
if (collisionBrick != NULL) {
dd::Events::PlaySFX e;
e.path = "Sounds/Brick/brickBreak.wav";
EventBroker->Publish(e);
return true;
}*/
}
auto collisionPad = m_World->GetComponent<Components::Pad>(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];