added a PlaySound Event.
This commit is contained in:
+23
-5
@@ -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
|
#ifndef DAYDREAM_SOUND_H
|
||||||
#define DAYDREAM_SOUND_H
|
#define DAYDREAM_SOUND_H
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include "AL/al.h"
|
#include "AL/al.h"
|
||||||
#include "AL/alc.h"
|
#include "AL/alc.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/EKeyDown.h"
|
#include "Core/EKeyDown.h"
|
||||||
|
#include "Core/EPlaySound.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -30,16 +44,20 @@ public:
|
|||||||
//void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
//void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||||
//void OnComponentRemoved(std::string type, 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(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);
|
//void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//Events
|
||||||
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
|
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
|
||||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
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 LoadFile(std::string fileName);
|
||||||
ALuint CreateSource();
|
ALuint CreateSource();
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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 "PrecompiledHeader.h"
|
||||||
#include "Core/Sound.h"
|
#include "Core/Sound.h"
|
||||||
|
|
||||||
dd::Systems::Sound::~Sound()
|
dd::Systems::Sound::~Sound()
|
||||||
{
|
{
|
||||||
alDeleteSources(1, m_Source);
|
//alDeleteSources(1, m_Source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::Sound::Initialize()
|
void dd::Systems::Sound::Initialize()
|
||||||
@@ -19,7 +34,7 @@ void dd::Systems::Sound::Initialize()
|
|||||||
alcMakeContextCurrent(context);
|
alcMakeContextCurrent(context);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_ERROR("OMG OPEN AL FAIL");
|
LOG_ERROR("OpenAL failed to initialize.");
|
||||||
}
|
}
|
||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
@@ -28,6 +43,7 @@ void dd::Systems::Sound::Initialize()
|
|||||||
|
|
||||||
//Subscribe to events
|
//Subscribe to events
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown);
|
||||||
|
//EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &Sound::PlayASound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::Sound::Update(double dt)
|
void dd::Systems::Sound::Update(double dt)
|
||||||
@@ -38,9 +54,19 @@ void dd::Systems::Sound::Update(double dt)
|
|||||||
alSourcefv(m_Source, AL_POSITION, pos);
|
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)
|
bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event)
|
||||||
{
|
{
|
||||||
// #define GLFW_KEY_S 83
|
// #define GLFW_KEY_S 83
|
||||||
|
/*if (event.KeyCode == 83) {
|
||||||
|
Events::PlaySound e;
|
||||||
|
e.path = "Sounds/screwed.wav";
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}*/
|
||||||
if (event.KeyCode == 83) {
|
if (event.KeyCode == 83) {
|
||||||
m_Source = CreateSource();
|
m_Source = CreateSource();
|
||||||
ALuint buffer = LoadFile("Sounds/screwed.wav");
|
ALuint buffer = LoadFile("Sounds/screwed.wav");
|
||||||
|
|||||||
Reference in New Issue
Block a user