Merge branch 'master' of github.com:teamfisk/TacticalZ

This commit is contained in:
2016-03-12 23:49:44 +01:00
23 changed files with 320 additions and 174 deletions
+1 -1
Submodule assets updated: 33455a9d10...bc6e7df04c
+1
View File
@@ -19,6 +19,7 @@ class Resource
protected: protected:
Resource() { } Resource() { }
virtual ~Resource() = default;
public: public:
//Should be thrown in a Resource's constructor if it cannot complete because another resource is still loading. //Should be thrown in a Resource's constructor if it cannot complete because another resource is still loading.
+2 -1
View File
@@ -3,6 +3,7 @@
#include "IRenderer.h" #include "IRenderer.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "PNG.h"
class CubeMapPass class CubeMapPass
{ {
@@ -21,7 +22,7 @@ private:
IRenderer* m_Renderer; IRenderer* m_Renderer;
std::string m_PreviusCubeMapTexture; std::string m_PreviusCubeMapTexture;
std::vector<Texture*> m_CubeMapTextures; std::vector<std::string> m_CubeMapTextures;
}; };
#endif #endif
+2
View File
@@ -3,6 +3,8 @@
struct Image struct Image
{ {
virtual ~Image() = default;
enum class ImageFormat enum class ImageFormat
{ {
Unknown, Unknown,
-2
View File
@@ -14,8 +14,6 @@ protected:
TextureSprite(std::string path); TextureSprite(std::string path);
public: public:
~TextureSprite();
void Bind(GLenum textureUnit = GL_TEXTURE0); void Bind(GLenum textureUnit = GL_TEXTURE0);
GLuint m_Texture = 0; GLuint m_Texture = 0;
+16
View File
@@ -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
+2 -1
View File
@@ -12,7 +12,8 @@ namespace Events
// Sound behavior is thereby specified in the SoundEmitter component. // Sound behavior is thereby specified in the SoundEmitter component.
struct PlaySoundOnEntity : public Event struct PlaySoundOnEntity : public Event
{ {
EntityID EmitterID = 0; EntityWrapper Emitter = EntityWrapper::Invalid;
float Gain = 1.f;
std::string FilePath = ""; std::string FilePath = "";
}; };
+16
View File
@@ -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 //
+35 -18
View File
@@ -9,32 +9,35 @@
#include "OpenAL/al.h" #include "OpenAL/al.h"
#include "OpenAL/alc.h" #include "OpenAL/alc.h"
#include "imgui/imgui.h" #include "../Engine/Core/World.h"
#include "../Engine/Core/EventBroker.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "../Engine/Core/ResourceManager.h" #include "../Engine/Core/ResourceManager.h"
#include "../Engine/Core/ConfigFile.h" #include "../Engine/Core/ConfigFile.h"
#include "Core/Transform.h" // Absolute transform #include "../Engine/Core/Transform.h"
#include "Sound/Sound.h" #include "../Engine/Sound/Sound.h"
#include "../Engine/Sound/EPlayQueueOnEntity.h" #include "../Engine/Sound/EPlayQueueOnEntity.h"
#include "Sound/EPlaySoundOnEntity.h" #include "../Engine/Sound/EPlaySoundOnEntity.h"
#include "Sound/EPlaySoundOnPosition.h" #include "../Engine/Sound/EPlaySoundOnPosition.h"
#include "Sound/EPlayBackgroundMusic.h" #include "../Engine/Sound/EPlayBackgroundMusic.h"
#include "Sound/EPauseSound.h" #include "../Engine/Sound/EPlayAnnouncerVoice.h"
#include "Sound/EContinueSound.h" #include "../Engine/Sound/EPauseSound.h"
#include "Sound/EStopSound.h" #include "../Engine/Sound/EContinueSound.h"
#include "Sound/ESetBGMGain.h" #include "../Engine/Sound/EStopSound.h"
#include "Sound/ESetSFXGain.h" #include "../Engine/Sound/ESetBGMGain.h"
#include "Core/EPause.h" #include "../Engine/Sound/ESetSFXGain.h"
#include "Core/EComponentAttached.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" #include "../Core/EPlayerSpawned.h"
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers; typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
enum class SoundType { enum class SoundType {
SFX, SFX,
BGM BGM,
Announcer
}; };
struct Source struct Source
@@ -43,6 +46,7 @@ struct Source
Sound* SoundResource = nullptr; Sound* SoundResource = nullptr;
ALuint ALsource; ALuint ALsource;
SoundType Type; SoundType Type;
float Duration;
}; };
class SoundManager class SoundManager
@@ -74,14 +78,20 @@ private:
ALenum getSourceState(ALuint source); ALenum getSourceState(ALuint source);
void setGain(Source* source, float gain); void setGain(Source* source, float gain);
void setSoundProperties(Source* source, ComponentWrapper* soundComponent); void setSoundProperties(Source* source, ComponentWrapper* soundComponent);
float getDurationSeconds(Source* source);
float getTimeOffsetSeconds(Source* source);
// Specific logic // Specific logic
void playSound(Source* source); 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 playQueue(QueuedBuffers qb);
void stopSound(Source* source); void stopSound(Source* source);
Source* createSource(std::string filePath); Source* createSource(std::string filePath);
std::unordered_map<EntityID, Source*> m_Sources; std::unordered_map<EntityID, Source*> m_Sources;
void matchBGMLoop();
Source* m_CurrentBGM = nullptr;
Source* m_CurrentBGMCombo = nullptr;
bool m_DrumLoopHasBeenStarted = false;
// Logic // Logic
World* m_World = nullptr; World* m_World = nullptr;
@@ -93,6 +103,7 @@ private:
float m_BGMVolumeChannel = 1.0f; float m_BGMVolumeChannel = 1.0f;
float m_SFXVolumeChannel = 1.0f; float m_SFXVolumeChannel = 1.0f;
float m_AnnouncerVolumeChannel = 1.0f;
EntityWrapper m_LocalPlayer = EntityWrapper(); EntityWrapper m_LocalPlayer = EntityWrapper();
// Events // Events
@@ -102,6 +113,8 @@ private:
bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e); bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e);
EventRelay<SoundManager, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic; EventRelay<SoundManager, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic;
bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e); bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e);
EventRelay<SoundManager, Events::PlayAnonuncerVoice> m_EPlayAnnouncerVoice;
bool OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e);
EventRelay<SoundManager, Events::PauseSound> m_EPauseSound; EventRelay<SoundManager, Events::PauseSound> m_EPauseSound;
bool OnPauseSound(const Events::PauseSound &e); bool OnPauseSound(const Events::PauseSound &e);
EventRelay<SoundManager, Events::StopSound> m_EStopSound; EventRelay<SoundManager, Events::StopSound> m_EStopSound;
@@ -112,6 +125,8 @@ private:
bool OnSetBGMGain(const Events::SetBGMGain &e); bool OnSetBGMGain(const Events::SetBGMGain &e);
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain; EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
bool OnSetSFXGain(const Events::SetSFXGain &e); bool OnSetSFXGain(const Events::SetSFXGain &e);
EventRelay<SoundManager, Events::SetAnnouncerGain> m_ESetAnnouncerGain;
bool OnSetAnnouncerGain(const Events::SetAnnouncerGain& e);
EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached; EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached;
bool OnComponentAttached(const Events::ComponentAttached &e); bool OnComponentAttached(const Events::ComponentAttached &e);
EventRelay<SoundManager, Events::Pause> m_EPause; EventRelay<SoundManager, Events::Pause> m_EPause;
@@ -122,6 +137,8 @@ private:
bool OnPlayerSpawned(const Events::PlayerSpawned &e); bool OnPlayerSpawned(const Events::PlayerSpawned &e);
EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity; EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity;
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
bool OnChangeBGM(const Events::ChangeBGM &e);
}; };
+1 -1
View File
@@ -33,7 +33,7 @@ private:
// Used to track afterimages for sprint effect. // Used to track afterimages for sprint effect.
float m_SprintEffectTimer; float m_SprintEffectTimer;
// The logic for making the sound play when player is moving // 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 // Spawn a hexagon at origin of an Entity
void spawnHexagon(EntityWrapper target); void spawnHexagon(EntityWrapper target);
+6 -12
View File
@@ -2,6 +2,7 @@
#define Systems_SoundSystem_h__ #define Systems_SoundSystem_h__
#include <random> #include <random>
#include <chrono>
#include "../Engine/Core/System.h" #include "../Engine/Core/System.h"
#include "../Engine/Core/ResourceManager.h" #include "../Engine/Core/ResourceManager.h"
@@ -20,9 +21,10 @@
#include "../Engine/Collision/ETrigger.h" #include "../Engine/Collision/ETrigger.h"
#include "../Engine/Sound/EPlaySoundOnEntity.h" #include "../Engine/Sound/EPlaySoundOnEntity.h"
#include "../Engine/Sound/EPlayBackgroundMusic.h" #include "../Engine/Sound/EPlayBackgroundMusic.h"
#include "../Engine/Sound/EPlayAnnouncerVoice.h"
#include "../Game/Events/EDoubleJump.h" #include "../Game/Events/EDoubleJump.h"
#include "../Game/Events/EDashAbility.h" #include "../Game/Events/EDashAbility.h"
#include "../Engine/Sound/EChangeBGM.h"
class SoundSystem : public PureSystem, ImpureSystem class SoundSystem : public PureSystem, ImpureSystem
{ {
@@ -33,14 +35,10 @@ public:
private: private:
std::string m_Announcer = ""; std::string m_Announcer = "";
// Logic for playing a sound when a player jumps // Logic for playing a sound when a player jumps
void playerJumps(); void playerJumps(EntityWrapper player);
// Temporary solution for play test. std::default_random_engine m_RandomGenerator;
bool m_DrumsIsPlaying = false; std::uniform_int_distribution<int> m_RandIntDistribution;
double m_DrumTimer = 0.0;
bool drumTimer(double dt);
std::default_random_engine generator;
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned; EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(const Events::PlayerSpawned &e); bool OnPlayerSpawned(const Events::PlayerSpawned &e);
@@ -48,10 +46,6 @@ private:
bool OnInputCommand(const Events::InputCommand &e); bool OnInputCommand(const Events::InputCommand &e);
EventRelay<SoundSystem, Events::DoubleJump> m_EDoubleJump; EventRelay<SoundSystem, Events::DoubleJump> m_EDoubleJump;
bool OnDoubleJump(const Events::DoubleJump &e); 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; EventRelay<SoundSystem, Events::Captured> m_ECaptured;
bool OnCaptured(const Events::Captured &e); bool OnCaptured(const Events::Captured &e);
EventRelay<SoundSystem, Events::PlayerDamage> m_EPlayerDamage; EventRelay<SoundSystem, Events::PlayerDamage> m_EPlayerDamage;
@@ -5,6 +5,7 @@
#include "Collision/Collision.h" #include "Collision/Collision.h"
#include "Core/EPlayerDamage.h" #include "Core/EPlayerDamage.h"
#include "Sound/EPlaySoundOnEntity.h" #include "Sound/EPlaySoundOnEntity.h"
#include "Sound/EPlaySoundOnEntity.h"
class DefenderWeaponBehaviour : public WeaponBehaviour<DefenderWeaponBehaviour> class DefenderWeaponBehaviour : public WeaponBehaviour<DefenderWeaponBehaviour>
{ {
+1
View File
@@ -39,6 +39,7 @@ ResourceLoading=true
[Sound] [Sound]
BGMVolume=1.0 BGMVolume=1.0
SFXVolume=1.0 SFXVolume=1.0
AnnouncerVolume=1.0
Announcer=female Announcer=female
[SSAO] [SSAO]
+2 -2
View File
@@ -4,7 +4,7 @@
<Gain>1.0</Gain> <Gain>1.0</Gain>
<Pitch>1.0</Pitch> <Pitch>1.0</Pitch>
<Loop>false</Loop> <Loop>false</Loop>
<MaxDistance>20.0</MaxDistance> <MaxDistance>220.0</MaxDistance>
<RollOffFactor>1.0</RollOffFactor> <RollOffFactor>10</RollOffFactor>
<ReferenceDistance>1.0</ReferenceDistance> <ReferenceDistance>1.0</ReferenceDistance>
</SoundEmitter> </SoundEmitter>
+8 -8
View File
@@ -6,18 +6,16 @@ CubeMapPass::CubeMapPass(IRenderer* renderer)
LoadTextures("Nevada"); LoadTextures("Nevada");
} }
void CubeMapPass::LoadTextures(std::string input) void CubeMapPass::LoadTextures(std::string cubemapName)
{ {
if (m_PreviusCubeMapTexture != input) { if (m_PreviusCubeMapTexture != cubemapName) {
m_CubeMapTextures.clear(); m_CubeMapTextures.clear();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
std::string str; std::string path = "Textures/Test/CubeMap/" + cubemapName + "/CubeMapTest0" + std::to_string(i) + ".png";
str = "Textures/Test/CubeMap/" + input + "/CubeMapTest0" + std::to_string(i) + ".png"; m_CubeMapTextures.push_back(path);
Texture* img = ResourceManager::Load<Texture>(str);
m_CubeMapTextures.push_back(img);
} }
GenerateCubeMapTexture(); GenerateCubeMapTexture();
m_PreviusCubeMapTexture = input; m_PreviusCubeMapTexture = cubemapName;
} }
} }
@@ -29,7 +27,9 @@ void CubeMapPass::GenerateCubeMapTexture()
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapTexture);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F, m_CubeMapTextures[0]->Width, m_CubeMapTextures[0]->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_CubeMapTextures[i]->Data); PNG* img = ResourceManager::Load<PNG>(m_CubeMapTextures[i]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F, img->Width, img->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->Data);
ResourceManager::Release("PNG", m_CubeMapTextures[i]);
} }
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+2 -1
View File
@@ -19,7 +19,6 @@ Texture::Texture(std::string path)
} }
// Construct the OpenGL texture // Construct the OpenGL texture
glGenTextures(1, &m_Texture); glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture); glBindTexture(GL_TEXTURE_2D, m_Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -30,6 +29,8 @@ Texture::Texture(std::string path)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLERROR("Texture load"); GLERROR("Texture load");
ResourceManager::Release("PNG", path);
} }
Texture::~Texture() Texture::~Texture()
+128 -12
View File
@@ -7,6 +7,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
m_World = world; m_World = world;
m_BGMVolumeChannel = config->Get<float>("Sound.BGMVolume", 1.f); m_BGMVolumeChannel = config->Get<float>("Sound.BGMVolume", 1.f);
m_SFXVolumeChannel = config->Get<float>("Sound.SFXVolume", 1.f); m_SFXVolumeChannel = config->Get<float>("Sound.SFXVolume", 1.f);
m_AnnouncerVolumeChannel = config->Get<float>("Sound.AnnouncerVolume", 1.f);
initOpenAL(); initOpenAL();
alSpeedOfSound(340.29f); alSpeedOfSound(340.29f);
@@ -16,16 +17,23 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition); EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition);
EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic); 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_EStopSound, &SoundManager::OnStopSound);
EVENT_SUBSCRIBE_MEMBER(m_EPauseSound, &SoundManager::OnPauseSound); EVENT_SUBSCRIBE_MEMBER(m_EPauseSound, &SoundManager::OnPauseSound);
EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound); EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound);
EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain); EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain);
EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain); 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_EPause, &SoundManager::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume); EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached); EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); 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() SoundManager::~SoundManager()
@@ -56,13 +64,11 @@ void SoundManager::stopEmitters()
void SoundManager::Update(double dt) void SoundManager::Update(double dt)
{ {
m_EventBroker->Process<SoundManager>(); m_EventBroker->Process<SoundManager>();
deleteInactiveEmitters(); // can be optimized with "EEntityDeleted" deleteInactiveEmitters();
updateEmitters(dt); updateEmitters(dt);
updateListener(dt); updateListener(dt);
if (m_DrumLoopHasBeenStarted)
// Editor debug info matchBGMLoop();
ImGui::SliderFloat("BGM", &m_BGMVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
ImGui::SliderFloat("SFX", &m_SFXVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
} }
void SoundManager::deleteInactiveEmitters() void SoundManager::deleteInactiveEmitters()
@@ -117,7 +123,7 @@ void SoundManager::updateEmitters(double dt)
// Calculate velocity // Calculate velocity
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt;
setSourcePos(it->second->ALsource, nextPos); 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"); auto emitter = m_World->GetComponent(it->first, "SoundEmitter");
setSoundProperties(it->second, &emitter); setSoundProperties(it->second, &emitter);
@@ -166,9 +172,34 @@ Source* SoundManager::createSource(std::string filePath)
Source* source = new Source(); Source* source = new Source();
source->ALsource = alSource; source->ALsource = alSource;
source->SoundResource = ResourceManager::Load<Sound>(filePath); source->SoundResource = ResourceManager::Load<Sound>(filePath);
source->Duration = getDurationSeconds(source);
return 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) void SoundManager::playSound(Source* source)
{ {
alSourcei(source->ALsource, AL_BUFFER, source->SoundResource->Buffer()); 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* source = createSource(e.FilePath);
source->Type = SoundType::SFX; 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, "Transform");
m_World->AttachComponent(child, "SoundEmitter"); auto cEmitter = m_World->AttachComponent(child, "SoundEmitter");
(double&)(float)cEmitter["Gain"] = e.Gain;
m_Sources[child] = source; m_Sources[child] = source;
setGain(source, cEmitter["Gain"]);
playSound(source); playSound(source);
return false; return false;
} }
@@ -242,7 +275,7 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
auto listenerComponents = m_World->GetComponents("Listener"); auto listenerComponents = m_World->GetComponents("Listener");
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) { for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
if ((*it).EntityID != m_LocalPlayer.ID) { if ((*it).EntityID != m_LocalPlayer.ID) {
break; continue;
} }
auto emitterChild = m_World->CreateEntity((*it).EntityID); auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
@@ -258,6 +291,28 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
return true; 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) bool SoundManager::OnSetBGMGain(const Events::SetBGMGain & e)
{ {
m_BGMVolumeChannel = e.Gain; m_BGMVolumeChannel = e.Gain;
@@ -270,6 +325,13 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e)
return true; return true;
} }
bool SoundManager::OnSetAnnouncerGain(const Events::SetAnnouncerGain& e)
{
m_AnnouncerVolumeChannel = e.Gain;
return true;
}
bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e) bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
{ {
if (e.Component.Info.Name == "SoundEmitter") { if (e.Component.Info.Name == "SoundEmitter") {
@@ -301,12 +363,20 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
{ {
if (e.PlayerID == -1) { // Local player if (e.PlayerID == -1) { // Local player
m_LocalPlayer = e.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 true;
} }
return false; return false;
} }
bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e) bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
{ {
Source* source = createSource(*e.FilePaths.begin()); Source* source = createSource(*e.FilePaths.begin());
@@ -321,6 +391,18 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
return true; 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 SoundManager::getSourceState(ALuint source)
{ {
ALenum state; ALenum state;
@@ -335,15 +417,49 @@ void SoundManager::setGain(Source * source, float gain)
void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundComponent) 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_GAIN, (float)(double)(*soundComponent)["Gain"] * gain);
alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]); 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_MAX_DISTANCE, (float)(double)(*soundComponent)["MaxDistance"]);
alSourcef(source->ALsource, AL_ROLLOFF_FACTOR, (float)(double)(*soundComponent)["RollOffFactor"]); alSourcef(source->ALsource, AL_ROLLOFF_FACTOR, (float)(double)(*soundComponent)["RollOffFactor"]);
alSourcef(source->ALsource, AL_REFERENCE_DISTANCE, (float)(double)(*soundComponent)["ReferenceDistance"]); 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() void SoundManager::initOpenAL()
{ {
// Initialize OpenAL // Initialize OpenAL
+4 -2
View File
@@ -53,7 +53,7 @@ Game::Game(int argc, char* argv[])
ResourceManager::RegisterType<RawModel>("RawModel"); ResourceManager::RegisterType<RawModel>("RawModel");
ResourceManager::RegisterType<Texture>("Texture"); ResourceManager::RegisterType<Texture>("Texture");
ResourceManager::RegisterType<TextureSprite>("TextureSprite"); ResourceManager::RegisterType<TextureSprite>("TextureSprite");
ResourceManager::RegisterType<PNG>("Png"); ResourceManager::RegisterType<PNG>("PNG");
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram"); ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
ResourceManager::RegisterType<EntityFile>("EntityFile"); ResourceManager::RegisterType<EntityFile>("EntityFile");
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile"); ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
@@ -223,7 +223,9 @@ void Game::Tick()
m_EventBroker->Swap(); m_EventBroker->Swap();
PerformanceTimer::StartTimerAndStopPrevious("SoundManager"); PerformanceTimer::StartTimerAndStopPrevious("SoundManager");
m_SoundManager->Update(dt); if (m_IsClient) {
m_SoundManager->Update(dt);
}
// Update network // Update network
PerformanceTimer::StartTimerAndStopPrevious("Network"); PerformanceTimer::StartTimerAndStopPrevious("Network");
+6 -7
View File
@@ -274,10 +274,9 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// TODO: Animations // TODO: Animations
} }
playerStep(dt, player);
controller->Reset(); controller->Reset();
} }
playerStep(dt);
} }
@@ -313,12 +312,12 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
position += velocity * (float)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; 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"]; glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"];
// Used to see if a player is airborne. // Used to see if a player is airborne.
bool grounded = (bool)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["IsOnGround"]; 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 // Player moved a step's distance
// Create footstep sound // Create footstep sound
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = m_LocalPlayer.ID; e.Emitter = m_LocalPlayer;
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav"; e.FilePath = m_LeftFoot ? "Audio/Footstep/Footstep2.wav" : "Audio/Footstep/Footstep3.wav";
m_LeftFoot = !m_LeftFoot; m_LeftFoot = !m_LeftFoot;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
m_DistanceMoved = 0.f; m_DistanceMoved = 0.f;
+56 -100
View File
@@ -6,45 +6,33 @@ SoundSystem::SoundSystem(SystemParams params)
{ {
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini"); ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
m_Announcer = ResourceManager::Load<ConfigFile>("Config.ini")->Get<std::string>("Sound.Announcer", "female"); m_Announcer = ResourceManager::Load<ConfigFile>("Config.ini")->Get<std::string>("Sound.Announcer", "female");
if (IsClient) { unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned); m_RandomGenerator = std::default_random_engine(seed);
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand); m_RandIntDistribution = std::uniform_int_distribution<int>(1, 12);
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility); EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &SoundSystem::OnPlayerDeath);
}
} }
void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt)
{ } { }
void SoundSystem::Update(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) bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
{ {
if (e.PlayerID == -1) { // Local player if (e.PlayerID == -1) { // Local player
m_World->AttachComponent(e.Player.ID, "Listener"); m_World->AttachComponent(e.Player.ID, "Listener");
Events::PlaySoundOnEntity go; Events::PlayAnonuncerVoice go;
go.EmitterID = LocalPlayer.ID; go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
go.FilePath = "Audio/announcer/" + m_Announcer + "/go.wav";
m_EventBroker->Publish(go); m_EventBroker->Publish(go);
// TEMP: starts bgm
{ {
Events::PlayBackgroundMusic ev; Events::ChangeBGM ev;
ev.FilePath = "Audio/bgm/ambient.wav"; ev.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
} }
} }
@@ -54,82 +42,67 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
bool SoundSystem::OnInputCommand(const Events::InputCommand & e) bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
{ {
if (e.Command == "Jump" && e.Value > 0) { if (e.Command == "Jump" && e.Value > 0) {
if (e.PlayerID == -1) { // local player if (e.PlayerID == -1) {
playerJumps(); playerJumps(LocalPlayer);
return true;
} }
return true;
} }
return false; return false;
} }
void SoundSystem::playerJumps() void SoundSystem::playerJumps(EntityWrapper player)
{ {
if (!LocalPlayer.Valid()) { if (!IsClient) { // Only play for clients
return; return;
} }
if(!player.HasComponent("Physics")) {
bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"]; return;
}
bool grounded = (bool)player["Physics"]["IsOnGround"];
if (grounded) { if (grounded) {
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = LocalPlayer.ID; e.Emitter = player;
e.FilePath = "Audio/jump/jump1.wav"; e.FilePath = "Audio/Jump/Jump1.wav";
m_EventBroker->Publish(e); 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) bool SoundSystem::OnCaptured(const Events::Captured & e)
{ {
if (!LocalPlayer.Valid()) { if (!IsClient) { // Only play for clients
return false; return false;
} }
int homeTeam = (int)m_World->GetComponent(e.CapturePointTakenID, "Team")["Team"]; int homeTeam = (int)m_World->GetComponent(e.CapturePointTakenID, "Team")["Team"];
int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"]; int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"];
Events::PlaySoundOnEntity ev; Events::PlayAnonuncerVoice ev;
if (team == homeTeam) { if (team == homeTeam) {
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_achieved.wav"; ev.FilePath = "Audio/Announcer/" + m_Announcer + "/ObjectiveAchieved.wav";
} else { } 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); m_EventBroker->Publish(ev);
// Temp for play test.
m_DrumsIsPlaying = false;
return false; return false;
} }
// Testing purposes atm...
bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
{ {
if (!IsClient) { // Only play for clients if (!IsClient) { // Only play for clients
return false; 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; return false;
} }
std::uniform_int_distribution<int> dist(1, 12);
int rand = dist(generator);
std::vector<std::string> paths; 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; Events::PlayQueueOnEntity ev;
ev.Emitter = LocalPlayer; ev.Emitter = e.Victim;
ev.FilePaths = paths; ev.FilePaths = paths;
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
@@ -137,7 +110,7 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
{ {
if (e.Player.ID != LocalPlayer.ID) { if (!e.Player.Valid()) {
return false; return false;
} }
if (!IsClient) { if (!IsClient) {
@@ -146,8 +119,9 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
// The local player is dead. The local player might be invalid? // The local player is dead. The local player might be invalid?
// Play the sound from the listener. // Play the sound from the listener.
// TODO: We might want to hear other players die. // TODO: We might want to hear other players die.
Events::PlayBackgroundMusic ev; Events::PlaySoundOnEntity ev;
ev.FilePath = "Audio/die/die2.wav"; ev.Emitter = e.Player;
ev.FilePath = "Audio/Die/Die2.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; return false;
} }
@@ -155,43 +129,25 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
{ {
Events::PlaySoundOnEntity ev; Events::PlaySoundOnEntity ev;
ev.EmitterID = LocalPlayer.ID; ev.Emitter = LocalPlayer;
ev.FilePath = "Audio/pickup/pickup2.wav"; ev.FilePath = "Audio/Pickup/Pickup2.wav";
m_EventBroker->Publish(ev); m_EventBroker->Publish(ev);
return false; 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) bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
{ {
Events::PlaySoundOnEntity ev; if (!m_World->ValidEntity(e.entityID)) {
ev.EmitterID = LocalPlayer.ID; return false;
ev.FilePath = "Audio/jump/jump2.wav"; }
m_EventBroker->Publish(ev); if (!IsClient) {
return false; return false;
} }
if (e.entityID == LocalPlayer.ID) {
bool SoundSystem::OnDashAbility(const Events::DashAbility &e) Events::PlaySoundOnEntity ev;
{ ev.Emitter = EntityWrapper(m_World, e.entityID);
Events::PlaySoundOnEntity ev; ev.FilePath = "Audio/Jump/Jump2.wav";
ev.EmitterID = LocalPlayer.ID; m_EventBroker->Publish(ev);
ev.FilePath = "Audio/jump/dash1.wav"; }
m_EventBroker->Publish(ev);
return false; return false;
} }
@@ -158,7 +158,7 @@ void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
// Sound // Sound
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = wi.Player.ID; e.Emitter = wi.Player;
e.FilePath = "Audio/weapon/Assault/AssaultWeaponReload.wav"; e.FilePath = "Audio/weapon/Assault/AssaultWeaponReload.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
@@ -234,7 +234,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
if (hitMarkerSpawner.Valid()) { if (hitMarkerSpawner.Valid()) {
SpawnerSystem::Spawn(hitMarkerSpawner, hitMarkerSpawner); SpawnerSystem::Spawn(hitMarkerSpawner, hitMarkerSpawner);
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = wi.Player.ID; e.Emitter = wi.Player;
e.FilePath = "Audio/weapon/hitclick.wav"; e.FilePath = "Audio/weapon/hitclick.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
@@ -253,7 +253,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
// Sound // Sound
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = wi.Player.ID; e.Emitter = wi.Player;
e.FilePath = "Audio/weapon/Assault/AssaultWeaponFire.wav"; e.FilePath = "Audio/weapon/Assault/AssaultWeaponFire.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
@@ -31,7 +31,7 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
magAmmo += 1; magAmmo += 1;
reloadTimer = reloadTime; reloadTimer = reloadTime;
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = wi.Player.ID; e.Emitter = wi.Player;
e.FilePath = "Audio/weapon/Zoom.wav"; e.FilePath = "Audio/weapon/Zoom.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} else { } else {
@@ -232,6 +232,13 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
} }
if (weaponModelEntity.Valid()) { if (weaponModelEntity.Valid()) {
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle"); 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) { for (auto& angles : pelletAngles) {
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1); 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); float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
@@ -250,7 +257,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
// Sound // Sound
Events::PlaySoundOnEntity e; Events::PlaySoundOnEntity e;
e.EmitterID = wi.Player.ID; e.Emitter = wi.Player;
e.FilePath = "Audio/weapon/Blast.wav"; e.FilePath = "Audio/weapon/Blast.wav";
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }