Merge pull request #208 from teamfisk/Kill-streak-sounds
Various sound improvements/additions
This commit is contained in:
+1
-1
Submodule assets updated: 33455a9d10...bc6e7df04c
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_ChangeBGM_h__
|
||||
#define Events_ChangeBGM_h__
|
||||
|
||||
#include <string>
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ChangeBGM : Event
|
||||
{
|
||||
std::string FilePath = "";
|
||||
};
|
||||
|
||||
}
|
||||
#endif // Events_ChangeBGM_h__
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef Events_PlayAnnouncerVoice_h__
|
||||
#define Events_PlayAnnouncerVoice_h__
|
||||
|
||||
#include <string>
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct PlayAnonuncerVoice : public Event
|
||||
{
|
||||
std::string FilePath = "";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,8 @@ namespace Events
|
||||
// Sound behavior is thereby specified in the SoundEmitter component.
|
||||
struct PlaySoundOnEntity : public Event
|
||||
{
|
||||
EntityID EmitterID = 0;
|
||||
EntityWrapper Emitter = EntityWrapper::Invalid;
|
||||
float Gain = 1.f;
|
||||
std::string FilePath = "";
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_SetAnnouncerGain_h__
|
||||
#define Events_SetAnnouncerGain_h__
|
||||
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct SetAnnouncerGain : public Event
|
||||
{
|
||||
float Gain = 1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //
|
||||
@@ -9,32 +9,35 @@
|
||||
#include "OpenAL/al.h"
|
||||
#include "OpenAL/alc.h"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "../Engine/Core/World.h"
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
#include "../Engine/Core/ResourceManager.h"
|
||||
#include "../Engine/Core/ConfigFile.h"
|
||||
#include "Core/Transform.h" // Absolute transform
|
||||
#include "Sound/Sound.h"
|
||||
#include "../Engine/Core/Transform.h"
|
||||
#include "../Engine/Sound/Sound.h"
|
||||
#include "../Engine/Sound/EPlayQueueOnEntity.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "Sound/EPlaySoundOnPosition.h"
|
||||
#include "Sound/EPlayBackgroundMusic.h"
|
||||
#include "Sound/EPauseSound.h"
|
||||
#include "Sound/EContinueSound.h"
|
||||
#include "Sound/EStopSound.h"
|
||||
#include "Sound/ESetBGMGain.h"
|
||||
#include "Sound/ESetSFXGain.h"
|
||||
#include "Core/EPause.h"
|
||||
#include "Core/EComponentAttached.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnPosition.h"
|
||||
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||
#include "../Engine/Sound/EPlayAnnouncerVoice.h"
|
||||
#include "../Engine/Sound/EPauseSound.h"
|
||||
#include "../Engine/Sound/EContinueSound.h"
|
||||
#include "../Engine/Sound/EStopSound.h"
|
||||
#include "../Engine/Sound/ESetBGMGain.h"
|
||||
#include "../Engine/Sound/ESetSFXGain.h"
|
||||
#include "../Engine/Sound/ESetAnnouncerGain.h"
|
||||
#include "../Engine/Sound/EChangeBGM.h"
|
||||
#include "../Engine/Core/EPause.h"
|
||||
#include "../Engine/Core/EComponentAttached.h"
|
||||
#include "../Core/EPlayerSpawned.h"
|
||||
|
||||
|
||||
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
||||
|
||||
enum class SoundType {
|
||||
SFX,
|
||||
BGM
|
||||
BGM,
|
||||
Announcer
|
||||
};
|
||||
|
||||
struct Source
|
||||
@@ -43,6 +46,7 @@ struct Source
|
||||
Sound* SoundResource = nullptr;
|
||||
ALuint ALsource;
|
||||
SoundType Type;
|
||||
float Duration;
|
||||
};
|
||||
|
||||
class SoundManager
|
||||
@@ -74,14 +78,20 @@ private:
|
||||
ALenum getSourceState(ALuint source);
|
||||
void setGain(Source* source, float gain);
|
||||
void setSoundProperties(Source* source, ComponentWrapper* soundComponent);
|
||||
float getDurationSeconds(Source* source);
|
||||
float getTimeOffsetSeconds(Source* source);
|
||||
|
||||
// Specific logic
|
||||
void playSound(Source* source);
|
||||
// Need to be the same format (sample rate etc)
|
||||
// Needs to be the same format (sample rate etc)
|
||||
void playQueue(QueuedBuffers qb);
|
||||
void stopSound(Source* source);
|
||||
Source* createSource(std::string filePath);
|
||||
std::unordered_map<EntityID, Source*> m_Sources;
|
||||
void matchBGMLoop();
|
||||
Source* m_CurrentBGM = nullptr;
|
||||
Source* m_CurrentBGMCombo = nullptr;
|
||||
bool m_DrumLoopHasBeenStarted = false;
|
||||
|
||||
// Logic
|
||||
World* m_World = nullptr;
|
||||
@@ -93,6 +103,7 @@ private:
|
||||
|
||||
float m_BGMVolumeChannel = 1.0f;
|
||||
float m_SFXVolumeChannel = 1.0f;
|
||||
float m_AnnouncerVolumeChannel = 1.0f;
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper();
|
||||
|
||||
// Events
|
||||
@@ -102,6 +113,8 @@ private:
|
||||
bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e);
|
||||
EventRelay<SoundManager, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic;
|
||||
bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e);
|
||||
EventRelay<SoundManager, Events::PlayAnonuncerVoice> m_EPlayAnnouncerVoice;
|
||||
bool OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e);
|
||||
EventRelay<SoundManager, Events::PauseSound> m_EPauseSound;
|
||||
bool OnPauseSound(const Events::PauseSound &e);
|
||||
EventRelay<SoundManager, Events::StopSound> m_EStopSound;
|
||||
@@ -112,6 +125,8 @@ private:
|
||||
bool OnSetBGMGain(const Events::SetBGMGain &e);
|
||||
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
|
||||
bool OnSetSFXGain(const Events::SetSFXGain &e);
|
||||
EventRelay<SoundManager, Events::SetAnnouncerGain> m_ESetAnnouncerGain;
|
||||
bool OnSetAnnouncerGain(const Events::SetAnnouncerGain& e);
|
||||
EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached;
|
||||
bool OnComponentAttached(const Events::ComponentAttached &e);
|
||||
EventRelay<SoundManager, Events::Pause> m_EPause;
|
||||
@@ -122,6 +137,8 @@ private:
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||
EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity;
|
||||
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
|
||||
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
|
||||
bool OnChangeBGM(const Events::ChangeBGM &e);
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
// Used to track afterimages for sprint effect.
|
||||
float m_SprintEffectTimer;
|
||||
// The logic for making the sound play when player is moving
|
||||
void playerStep(double dt);
|
||||
void playerStep(double dt, EntityWrapper player);
|
||||
// Spawn a hexagon at origin of an Entity
|
||||
void spawnHexagon(EntityWrapper target);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define Systems_SoundSystem_h__
|
||||
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
|
||||
#include "../Engine/Core/System.h"
|
||||
#include "../Engine/Core/ResourceManager.h"
|
||||
@@ -20,9 +21,10 @@
|
||||
#include "../Engine/Collision/ETrigger.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||
#include "../Engine/Sound/EPlayAnnouncerVoice.h"
|
||||
#include "../Game/Events/EDoubleJump.h"
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
|
||||
#include "../Engine/Sound/EChangeBGM.h"
|
||||
|
||||
class SoundSystem : public PureSystem, ImpureSystem
|
||||
{
|
||||
@@ -33,14 +35,10 @@ public:
|
||||
private:
|
||||
std::string m_Announcer = "";
|
||||
// Logic for playing a sound when a player jumps
|
||||
void playerJumps();
|
||||
|
||||
// Temporary solution for play test.
|
||||
bool m_DrumsIsPlaying = false;
|
||||
double m_DrumTimer = 0.0;
|
||||
bool drumTimer(double dt);
|
||||
void playerJumps(EntityWrapper player);
|
||||
|
||||
std::default_random_engine generator;
|
||||
std::default_random_engine m_RandomGenerator;
|
||||
std::uniform_int_distribution<int> m_RandIntDistribution;
|
||||
|
||||
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||
@@ -48,10 +46,6 @@ private:
|
||||
bool OnInputCommand(const Events::InputCommand &e);
|
||||
EventRelay<SoundSystem, Events::DoubleJump> m_EDoubleJump;
|
||||
bool OnDoubleJump(const Events::DoubleJump &e);
|
||||
EventRelay<SoundSystem, Events::DashAbility> m_EDashAbility;
|
||||
bool OnDashAbility(const Events::DashAbility &e);
|
||||
EventRelay<SoundSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||
bool OnTriggerTouch(const Events::TriggerTouch &e);
|
||||
EventRelay<SoundSystem, Events::Captured> m_ECaptured;
|
||||
bool OnCaptured(const Events::Captured &e);
|
||||
EventRelay<SoundSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Collision/Collision.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
|
||||
class DefenderWeaponBehaviour : public WeaponBehaviour<DefenderWeaponBehaviour>
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@ ResourceLoading=true
|
||||
[Sound]
|
||||
BGMVolume=1.0
|
||||
SFXVolume=1.0
|
||||
AnnouncerVolume=1.0
|
||||
Announcer=female
|
||||
|
||||
[SSAO]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<Gain>1.0</Gain>
|
||||
<Pitch>1.0</Pitch>
|
||||
<Loop>false</Loop>
|
||||
<MaxDistance>20.0</MaxDistance>
|
||||
<RollOffFactor>1.0</RollOffFactor>
|
||||
<MaxDistance>220.0</MaxDistance>
|
||||
<RollOffFactor>10</RollOffFactor>
|
||||
<ReferenceDistance>1.0</ReferenceDistance>
|
||||
</SoundEmitter>
|
||||
@@ -7,6 +7,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
m_World = world;
|
||||
m_BGMVolumeChannel = config->Get<float>("Sound.BGMVolume", 1.f);
|
||||
m_SFXVolumeChannel = config->Get<float>("Sound.SFXVolume", 1.f);
|
||||
m_AnnouncerVolumeChannel = config->Get<float>("Sound.AnnouncerVolume", 1.f);
|
||||
|
||||
initOpenAL();
|
||||
alSpeedOfSound(340.29f);
|
||||
@@ -16,16 +17,23 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayAnnouncerVoice, &SoundManager::OnPlayAnnouncerVoice);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundManager::OnStopSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPauseSound, &SoundManager::OnPauseSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetAnnouncerGain, &SoundManager::OnSetAnnouncerGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
|
||||
|
||||
Events::ChangeBGM e;
|
||||
e.FilePath = "Audio/bgm/MenuMusic.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
@@ -56,13 +64,11 @@ void SoundManager::stopEmitters()
|
||||
void SoundManager::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<SoundManager>();
|
||||
deleteInactiveEmitters(); // can be optimized with "EEntityDeleted"
|
||||
deleteInactiveEmitters();
|
||||
updateEmitters(dt);
|
||||
updateListener(dt);
|
||||
|
||||
// Editor debug info
|
||||
ImGui::SliderFloat("BGM", &m_BGMVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
|
||||
ImGui::SliderFloat("SFX", &m_SFXVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
|
||||
if (m_DrumLoopHasBeenStarted)
|
||||
matchBGMLoop();
|
||||
}
|
||||
|
||||
void SoundManager::deleteInactiveEmitters()
|
||||
@@ -117,7 +123,7 @@ void SoundManager::updateEmitters(double dt)
|
||||
// Calculate velocity
|
||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt;
|
||||
setSourcePos(it->second->ALsource, nextPos);
|
||||
setSourceVel(it->second->ALsource, velocity);
|
||||
//setSourceVel(it->second->ALsource, glm::vec3(0));
|
||||
|
||||
auto emitter = m_World->GetComponent(it->first, "SoundEmitter");
|
||||
setSoundProperties(it->second, &emitter);
|
||||
@@ -166,9 +172,34 @@ Source* SoundManager::createSource(std::string filePath)
|
||||
Source* source = new Source();
|
||||
source->ALsource = alSource;
|
||||
source->SoundResource = ResourceManager::Load<Sound>(filePath);
|
||||
source->Duration = getDurationSeconds(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
void SoundManager::matchBGMLoop()
|
||||
{
|
||||
if (m_CurrentBGMCombo == nullptr)
|
||||
return;
|
||||
auto cCapturePoints = m_World->GetComponents("CapturePoint");
|
||||
for (auto it = cCapturePoints->begin(); it != cCapturePoints->end(); it++) {
|
||||
float timeCaptured = (float)(double)(*it)["CaptureTimer"];
|
||||
float maxTimer = (float)(double)(*it)["CapturePointMaxTimer"];
|
||||
int capturePointIndex = (int)(*it)["CapturePointNumber"];
|
||||
|
||||
if (capturePointIndex == 0) { // Home for red team
|
||||
if (timeCaptured < 0 && glm::abs(timeCaptured) < maxTimer) {
|
||||
float gain = glm::abs(timeCaptured) / maxTimer;
|
||||
setGain(m_CurrentBGMCombo, gain);
|
||||
}
|
||||
} else if (capturePointIndex == 4) { // Home for blue team
|
||||
if (timeCaptured > 0 && timeCaptured < maxTimer) {
|
||||
float gain = timeCaptured / maxTimer;
|
||||
setGain(m_CurrentBGMCombo, gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::playSound(Source* source)
|
||||
{
|
||||
alSourcei(source->ALsource, AL_BUFFER, source->SoundResource->Buffer());
|
||||
@@ -192,10 +223,12 @@ bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e)
|
||||
{
|
||||
Source* source = createSource(e.FilePath);
|
||||
source->Type = SoundType::SFX;
|
||||
EntityID child = m_World->CreateEntity(e.EmitterID);
|
||||
EntityID child = m_World->CreateEntity(e.Emitter.ID);
|
||||
m_World->AttachComponent(child, "Transform");
|
||||
m_World->AttachComponent(child, "SoundEmitter");
|
||||
auto cEmitter = m_World->AttachComponent(child, "SoundEmitter");
|
||||
(double&)(float)cEmitter["Gain"] = e.Gain;
|
||||
m_Sources[child] = source;
|
||||
setGain(source, cEmitter["Gain"]);
|
||||
playSound(source);
|
||||
return false;
|
||||
}
|
||||
@@ -242,7 +275,7 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
|
||||
auto listenerComponents = m_World->GetComponents("Listener");
|
||||
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||
if ((*it).EntityID != m_LocalPlayer.ID) {
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
auto emitterChild = m_World->CreateEntity((*it).EntityID);
|
||||
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
|
||||
@@ -258,6 +291,28 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e)
|
||||
{
|
||||
auto listenerComponents = m_World->GetComponents("Listener");
|
||||
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||
if ((*it).EntityID != m_LocalPlayer.ID) {
|
||||
continue;
|
||||
}
|
||||
auto emitterChild = m_World->CreateEntity((*it).EntityID);
|
||||
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
|
||||
(bool&)emitter["Loop"] = false;
|
||||
(std::string&)emitter["FilePath"] = e.FilePath;
|
||||
m_World->AttachComponent(emitterChild, "Transform");
|
||||
Source* source = createSource(e.FilePath);
|
||||
source->Type = SoundType::Announcer;
|
||||
setSoundProperties(source, &emitter);
|
||||
m_Sources[emitterChild] = source;
|
||||
playSound(source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnSetBGMGain(const Events::SetBGMGain & e)
|
||||
{
|
||||
m_BGMVolumeChannel = e.Gain;
|
||||
@@ -270,6 +325,13 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnSetAnnouncerGain(const Events::SetAnnouncerGain& e)
|
||||
{
|
||||
m_AnnouncerVolumeChannel = e.Gain;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
|
||||
{
|
||||
if (e.Component.Info.Name == "SoundEmitter") {
|
||||
@@ -301,12 +363,20 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
{
|
||||
if (e.PlayerID == -1) { // Local player
|
||||
m_LocalPlayer = e.Player;
|
||||
if (m_DrumLoopHasBeenStarted) {
|
||||
return true;
|
||||
}
|
||||
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
|
||||
m_CurrentBGMCombo->Type = SoundType::BGM;
|
||||
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
|
||||
setGain(m_CurrentBGMCombo, 0);
|
||||
playSound(m_CurrentBGMCombo);
|
||||
m_DrumLoopHasBeenStarted = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
||||
{
|
||||
Source* source = createSource(*e.FilePaths.begin());
|
||||
@@ -321,6 +391,18 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
||||
{
|
||||
if (m_CurrentBGM != nullptr) {
|
||||
stopSound(m_CurrentBGM);
|
||||
}
|
||||
m_CurrentBGM = createSource(e.FilePath);
|
||||
m_CurrentBGM->Type = SoundType::BGM;
|
||||
alSourcei(m_CurrentBGM->ALsource, AL_LOOPING, 1);
|
||||
playSound(m_CurrentBGM);
|
||||
return true;
|
||||
}
|
||||
|
||||
ALenum SoundManager::getSourceState(ALuint source)
|
||||
{
|
||||
ALenum state;
|
||||
@@ -335,15 +417,49 @@ void SoundManager::setGain(Source * source, float gain)
|
||||
|
||||
void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundComponent)
|
||||
{
|
||||
float gain = (source->Type == SoundType::SFX) ? m_SFXVolumeChannel : m_BGMVolumeChannel;
|
||||
float gain;
|
||||
switch (source->Type) {
|
||||
case SoundType::SFX:
|
||||
gain = m_SFXVolumeChannel;
|
||||
break;
|
||||
case SoundType::BGM:
|
||||
gain = m_BGMVolumeChannel;
|
||||
break;
|
||||
case SoundType::Announcer:
|
||||
gain = m_AnnouncerVolumeChannel;
|
||||
break;
|
||||
default:
|
||||
gain = 1.f;
|
||||
break;
|
||||
}
|
||||
alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain);
|
||||
alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]);
|
||||
alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]); // YOLO
|
||||
alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]);
|
||||
alSourcef(source->ALsource, AL_MAX_DISTANCE, (float)(double)(*soundComponent)["MaxDistance"]);
|
||||
alSourcef(source->ALsource, AL_ROLLOFF_FACTOR, (float)(double)(*soundComponent)["RollOffFactor"]);
|
||||
alSourcef(source->ALsource, AL_REFERENCE_DISTANCE, (float)(double)(*soundComponent)["ReferenceDistance"]);
|
||||
}
|
||||
|
||||
float SoundManager::getDurationSeconds(Source* source)
|
||||
{
|
||||
ALuint buffer = source->SoundResource->Buffer();
|
||||
ALint sizeBytes, channels, bits, frequenzy;
|
||||
alGetBufferi(buffer, AL_SIZE, &sizeBytes);
|
||||
alGetBufferi(buffer, AL_CHANNELS, &channels);
|
||||
alGetBufferi(buffer, AL_BITS, &bits);
|
||||
alGetBufferi(buffer, AL_FREQUENCY, &frequenzy);
|
||||
float sampleLength = (float)sizeBytes * 8 / (channels * bits);
|
||||
return (sampleLength / frequenzy);
|
||||
}
|
||||
|
||||
|
||||
float SoundManager::getTimeOffsetSeconds(Source* source)
|
||||
{
|
||||
float time;
|
||||
alGetSourcef(source->ALsource, AL_SEC_OFFSET, &time);
|
||||
return time;
|
||||
}
|
||||
|
||||
void SoundManager::initOpenAL()
|
||||
{
|
||||
// Initialize OpenAL
|
||||
|
||||
+3
-1
@@ -223,7 +223,9 @@ void Game::Tick()
|
||||
m_EventBroker->Swap();
|
||||
|
||||
PerformanceTimer::StartTimerAndStopPrevious("SoundManager");
|
||||
m_SoundManager->Update(dt);
|
||||
if (m_IsClient) {
|
||||
m_SoundManager->Update(dt);
|
||||
}
|
||||
|
||||
// Update network
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Network");
|
||||
|
||||
@@ -274,10 +274,9 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
|
||||
// TODO: Animations
|
||||
}
|
||||
|
||||
playerStep(dt, player);
|
||||
controller->Reset();
|
||||
}
|
||||
playerStep(dt);
|
||||
}
|
||||
|
||||
|
||||
@@ -313,12 +312,12 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
|
||||
position += velocity * (float)dt;
|
||||
}
|
||||
|
||||
void PlayerMovementSystem::playerStep(double dt)
|
||||
void PlayerMovementSystem::playerStep(double dt, EntityWrapper player)
|
||||
{
|
||||
if (!m_LocalPlayer.Valid()) {
|
||||
// Position of the local player, used see how far a player has moved.
|
||||
if(!IsClient) {
|
||||
return;
|
||||
}
|
||||
// Position of the local player, used see how far a player has moved.
|
||||
glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"];
|
||||
// Used to see if a player is airborne.
|
||||
bool grounded = (bool)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["IsOnGround"];
|
||||
@@ -329,8 +328,8 @@ void PlayerMovementSystem::playerStep(double dt)
|
||||
// Player moved a step's distance
|
||||
// Create footstep sound
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = m_LocalPlayer.ID;
|
||||
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
|
||||
e.Emitter = m_LocalPlayer;
|
||||
e.FilePath = m_LeftFoot ? "Audio/Footstep/Footstep2.wav" : "Audio/Footstep/Footstep3.wav";
|
||||
m_LeftFoot = !m_LeftFoot;
|
||||
m_EventBroker->Publish(e);
|
||||
m_DistanceMoved = 0.f;
|
||||
|
||||
@@ -6,45 +6,33 @@ SoundSystem::SoundSystem(SystemParams params)
|
||||
{
|
||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_Announcer = ResourceManager::Load<ConfigFile>("Config.ini")->Get<std::string>("Sound.Announcer", "female");
|
||||
if (IsClient) {
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath);
|
||||
}
|
||||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
||||
m_RandomGenerator = std::default_random_engine(seed);
|
||||
m_RandIntDistribution = std::uniform_int_distribution<int>(1, 12);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath);
|
||||
}
|
||||
|
||||
void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt)
|
||||
{ }
|
||||
|
||||
void SoundSystem::Update(double dt)
|
||||
{
|
||||
if (!IsClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Temp for play test.
|
||||
if (m_DrumsIsPlaying) {
|
||||
m_DrumsIsPlaying = !drumTimer(dt);
|
||||
}
|
||||
}
|
||||
{ }
|
||||
|
||||
bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
{
|
||||
if (e.PlayerID == -1) { // Local player
|
||||
m_World->AttachComponent(e.Player.ID, "Listener");
|
||||
Events::PlaySoundOnEntity go;
|
||||
go.EmitterID = LocalPlayer.ID;
|
||||
go.FilePath = "Audio/announcer/" + m_Announcer + "/go.wav";
|
||||
Events::PlayAnonuncerVoice go;
|
||||
go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
|
||||
m_EventBroker->Publish(go);
|
||||
// TEMP: starts bgm
|
||||
{
|
||||
Events::PlayBackgroundMusic ev;
|
||||
ev.FilePath = "Audio/bgm/ambient.wav";
|
||||
Events::ChangeBGM ev;
|
||||
ev.FilePath = "Audio/BGM/Layer1.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
}
|
||||
}
|
||||
@@ -54,82 +42,67 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
|
||||
{
|
||||
if (e.Command == "Jump" && e.Value > 0) {
|
||||
if (e.PlayerID == -1) { // local player
|
||||
playerJumps();
|
||||
return true;
|
||||
}
|
||||
if (e.PlayerID == -1) {
|
||||
playerJumps(LocalPlayer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SoundSystem::playerJumps()
|
||||
void SoundSystem::playerJumps(EntityWrapper player)
|
||||
{
|
||||
if (!LocalPlayer.Valid()) {
|
||||
if (!IsClient) { // Only play for clients
|
||||
return;
|
||||
}
|
||||
|
||||
bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"];
|
||||
if(!player.HasComponent("Physics")) {
|
||||
return;
|
||||
}
|
||||
bool grounded = (bool)player["Physics"]["IsOnGround"];
|
||||
if (grounded) {
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = LocalPlayer.ID;
|
||||
e.FilePath = "Audio/jump/jump1.wav";
|
||||
e.Emitter = player;
|
||||
e.FilePath = "Audio/Jump/Jump1.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool SoundSystem::drumTimer(double dt)
|
||||
{
|
||||
m_DrumTimer += dt;
|
||||
if (m_DrumTimer > 15) {
|
||||
m_DrumTimer = 0.0;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SoundSystem::OnCaptured(const Events::Captured & e)
|
||||
{
|
||||
if (!LocalPlayer.Valid()) {
|
||||
if (!IsClient) { // Only play for clients
|
||||
return false;
|
||||
}
|
||||
int homeTeam = (int)m_World->GetComponent(e.CapturePointTakenID, "Team")["Team"];
|
||||
int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"];
|
||||
Events::PlaySoundOnEntity ev;
|
||||
Events::PlayAnonuncerVoice ev;
|
||||
if (team == homeTeam) {
|
||||
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_achieved.wav";
|
||||
ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveAchieved.wav";
|
||||
} else {
|
||||
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_failed.wav"; // have not been tested
|
||||
ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveFailed.wav";
|
||||
}
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
m_EventBroker->Publish(ev);
|
||||
// Temp for play test.
|
||||
m_DrumsIsPlaying = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Testing purposes atm...
|
||||
bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||
{
|
||||
if (!IsClient) { // Only play for clients
|
||||
return false;
|
||||
}
|
||||
if (LocalPlayer.ID = e.Victim.ID) { // You're local player was the one who took dmg
|
||||
if (!e.Victim.Valid() || !e.Inflictor.Valid()) {
|
||||
return false;
|
||||
}
|
||||
auto victimTeam = m_World->GetComponent(e.Victim.ID, "Team");
|
||||
auto inflictorTeam = m_World->GetComponent(e.Inflictor.ID, "Team");
|
||||
if ((int)victimTeam["Team"] == (int)inflictorTeam["Team"]) {
|
||||
// Victim and inflictor are the same team, should not play "hurt" sound.
|
||||
return false;
|
||||
}
|
||||
std::uniform_int_distribution<int> dist(1, 12);
|
||||
int rand = dist(generator);
|
||||
std::vector<std::string> paths;
|
||||
paths.push_back("Audio/hurt/hurt" + std::to_string(rand) + ".wav");
|
||||
paths.push_back("Audio/Hurt/Hurt" + std::to_string(m_RandIntDistribution(m_RandomGenerator)) + ".wav");
|
||||
|
||||
// // Breathe
|
||||
// int ammountOfbreaths = (static_cast<int>(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit
|
||||
// for (int i = 0; i < ammountOfbreaths; i++) {
|
||||
// paths.push_back("Audio/exhausted/breath.wav");
|
||||
// }
|
||||
Events::PlayQueueOnEntity ev;
|
||||
ev.Emitter = LocalPlayer;
|
||||
ev.Emitter = e.Victim;
|
||||
ev.FilePaths = paths;
|
||||
m_EventBroker->Publish(ev);
|
||||
return false;
|
||||
@@ -137,7 +110,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||
|
||||
bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
|
||||
{
|
||||
if (e.Player.ID != LocalPlayer.ID) {
|
||||
if (!e.Player.Valid()) {
|
||||
return false;
|
||||
}
|
||||
if (!IsClient) {
|
||||
@@ -146,8 +119,9 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
|
||||
// The local player is dead. The local player might be invalid?
|
||||
// Play the sound from the listener.
|
||||
// TODO: We might want to hear other players die.
|
||||
Events::PlayBackgroundMusic ev;
|
||||
ev.FilePath = "Audio/die/die2.wav";
|
||||
Events::PlaySoundOnEntity ev;
|
||||
ev.Emitter = e.Player;
|
||||
ev.FilePath = "Audio/Die/Die2.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
return false;
|
||||
}
|
||||
@@ -155,43 +129,25 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
|
||||
bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
|
||||
{
|
||||
Events::PlaySoundOnEntity ev;
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
ev.FilePath = "Audio/pickup/pickup2.wav";
|
||||
ev.Emitter = LocalPlayer;
|
||||
ev.FilePath = "Audio/Pickup/Pickup2.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e)
|
||||
{
|
||||
// Temp for play test.
|
||||
if (m_DrumsIsPlaying) {
|
||||
return false;
|
||||
}
|
||||
if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) {
|
||||
Events::PlaySoundOnEntity ev; // should be BGM
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
ev.FilePath = "Audio/bgm/drumstest.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
// Temp for play test.
|
||||
m_DrumsIsPlaying = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
|
||||
{
|
||||
Events::PlaySoundOnEntity ev;
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
ev.FilePath = "Audio/jump/jump2.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SoundSystem::OnDashAbility(const Events::DashAbility &e)
|
||||
{
|
||||
Events::PlaySoundOnEntity ev;
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
ev.FilePath = "Audio/jump/dash1.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
if (!m_World->ValidEntity(e.entityID)) {
|
||||
return false;
|
||||
}
|
||||
if (!IsClient) {
|
||||
return false;
|
||||
}
|
||||
if (e.entityID == LocalPlayer.ID) {
|
||||
Events::PlaySoundOnEntity ev;
|
||||
ev.Emitter = EntityWrapper(m_World, e.entityID);
|
||||
ev.FilePath = "Audio/Jump/Jump2.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
|
||||
|
||||
// Sound
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = wi.Player.ID;
|
||||
e.Emitter = wi.Player;
|
||||
e.FilePath = "Audio/weapon/Assault/AssaultWeaponReload.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
if (hitMarkerSpawner.Valid()) {
|
||||
SpawnerSystem::Spawn(hitMarkerSpawner, hitMarkerSpawner);
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = wi.Player.ID;
|
||||
e.Emitter = wi.Player;
|
||||
e.FilePath = "Audio/weapon/hitclick.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
|
||||
// Sound
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = wi.Player.ID;
|
||||
e.Emitter = wi.Player;
|
||||
e.FilePath = "Audio/weapon/Assault/AssaultWeaponFire.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
|
||||
magAmmo += 1;
|
||||
reloadTimer = reloadTime;
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = wi.Player.ID;
|
||||
e.Emitter = wi.Player;
|
||||
e.FilePath = "Audio/weapon/Zoom.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
@@ -232,6 +232,13 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
}
|
||||
if (weaponModelEntity.Valid()) {
|
||||
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.Emitter = weaponModelEntity;
|
||||
e.FilePath = "Audio/weapon/Shotgun/ShotgunFire.wav";
|
||||
e.Gain = 1.f;
|
||||
if (IsClient) {
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
for (auto& angles : pelletAngles) {
|
||||
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
|
||||
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
|
||||
@@ -250,7 +257,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
|
||||
// Sound
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = wi.Player.ID;
|
||||
e.Emitter = wi.Player;
|
||||
e.FilePath = "Audio/weapon/Blast.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user