From 450a73f498f217aae5d2be801c26ce86d2a08955 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 15 Sep 2015 18:16:32 +0200 Subject: [PATCH] added a PlaySound Event. --- include/Core/Sound.h | 28 +++++++++++++++++++----- include/Core/Util/EPlaySound.h | 40 ++++++++++++++++++++++++++++++++++ src/game/Core/Sound.cpp | 36 +++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 include/Core/Util/EPlaySound.h diff --git a/include/Core/Sound.h b/include/Core/Sound.h index 8c7256d..6639147 100644 --- a/include/Core/Sound.h +++ b/include/Core/Sound.h @@ -1,17 +1,31 @@ -// -// Created by Adam on 2015-09-09. -// +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ #ifndef DAYDREAM_SOUND_H #define DAYDREAM_SOUND_H -#include #include "AL/al.h" #include "AL/alc.h" #include "Core/System.h" #include "Core/World.h" #include "Core/EKeyDown.h" +#include "Core/EPlaySound.h" #include "Core/EventBroker.h" namespace dd @@ -30,16 +44,20 @@ public: //void OnComponentCreated(std::string type, std::shared_ptr component) override; //void OnComponentRemoved(std::string type, Component* component) override; //void PlaySound(Components::SoundEmitter* emitter, std::string path); // Use if you want to play a temporary .wav file not from component - //void PlaySound(std::shared_ptr emitter); // Use if you want to play .wav file from component // imon no hate plx T.T + //void PlaySound(std::shared_ptr emitter); // Use if you want to play .wav file from component //void StopSound(std::shared_ptr emitter); private: + //Events dd::EventRelay m_EKeyDown; bool OnKeyDown(const dd::Events::KeyDown &event); + //dd::EventRelay m_EPlaySound; + //bool PlayASound(const dd::Events::PlaySound &event); + ALuint LoadFile(std::string fileName); ALuint CreateSource(); diff --git a/include/Core/Util/EPlaySound.h b/include/Core/Util/EPlaySound.h new file mode 100644 index 0000000..7cf0d32 --- /dev/null +++ b/include/Core/Util/EPlaySound.h @@ -0,0 +1,40 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef DAYDREAM_EPLAYSOUND_H +#define DAYDREAM_EPLAYSOUND_H + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct PlaySound : Event +{ + float volume; + std::string path; +}; + +} + +} + +#endif //DAYDREAM_EPLAYSOUND_H diff --git a/src/game/Core/Sound.cpp b/src/game/Core/Sound.cpp index fd5d649..d191452 100644 --- a/src/game/Core/Sound.cpp +++ b/src/game/Core/Sound.cpp @@ -1,12 +1,27 @@ -// -// Created by Adam on 2015-09-09. -// +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + #include "PrecompiledHeader.h" #include "Core/Sound.h" dd::Systems::Sound::~Sound() { - alDeleteSources(1, m_Source); + //alDeleteSources(1, m_Source); } void dd::Systems::Sound::Initialize() @@ -19,7 +34,7 @@ void dd::Systems::Sound::Initialize() alcMakeContextCurrent(context); } else { - LOG_ERROR("OMG OPEN AL FAIL"); + LOG_ERROR("OpenAL failed to initialize."); } alGetError(); @@ -28,6 +43,7 @@ void dd::Systems::Sound::Initialize() //Subscribe to events EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown); + //EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &Sound::PlayASound); } void dd::Systems::Sound::Update(double dt) @@ -38,9 +54,19 @@ void dd::Systems::Sound::Update(double dt) alSourcefv(m_Source, AL_POSITION, pos); } +/*bool dd::Systems::Sound::PlayASound(const dd::Events::PlaySound &event) +{ + +}*/ + bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event) { // #define GLFW_KEY_S 83 + /*if (event.KeyCode == 83) { + Events::PlaySound e; + e.path = "Sounds/screwed.wav"; + EventBroker->Publish(e); + }*/ if (event.KeyCode == 83) { m_Source = CreateSource(); ALuint buffer = LoadFile("Sounds/screwed.wav");