added a PlaySound Event.

This commit is contained in:
Stiffly
2015-09-15 18:16:32 +02:00
parent aec694359c
commit 450a73f498
3 changed files with 94 additions and 10 deletions
+23 -5
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef DAYDREAM_SOUND_H
#define DAYDREAM_SOUND_H
#include <fstream>
#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> 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<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T
//void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component
//void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
private:
//Events
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const dd::Events::KeyDown &event);
//dd::EventRelay<Sound, dd::Events::PlaySound> m_EPlaySound;
//bool PlayASound(const dd::Events::PlaySound &event);
ALuint LoadFile(std::string fileName);
ALuint CreateSource();
+40
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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
+31 -5
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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");