From 2ef5d49f7e4554e1b247a1c8f2c965a5dea1cc6b Mon Sep 17 00:00:00 2001 From: Stiffly Date: Wed, 4 Jun 2014 15:21:05 +0200 Subject: [PATCH 1/4] Added Destructor. (improved StopSound and PlayBGM events) --- assets | 2 +- src/GameWorld.cpp | 7 ++++ src/InputManager.cpp | 22 ++++++++++ src/InputManager.h | 3 ++ src/Systems/SoundSystem.cpp | 42 ++++++++++++------- src/Systems/SoundSystem.h | 5 +-- .../Returngeance/Returngeance.vcxproj.filters | 12 ++---- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/assets b/assets index e09ebf5..cfda101 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit e09ebf5a29f007cb8ee884f48dc600926f0665bc +Subproject commit cfda101f676fde45f9fd362b99fcec4f99e79cf1 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index acf8db1..1dcb922 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -8,6 +8,13 @@ void GameWorld::Initialize() ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj"); + //Background Music + { + Events::PlayBGM e; + e.Resource = "Sounds/BGM/RideoftheValkyries.mp3"; + EventBroker->Publish(e); + } + // Interface BindKey(GLFW_KEY_A, "interface_horizontal", -1.f); BindKey(GLFW_KEY_D, "interface_horizontal", 1.f); diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 01d61ba..97494c8 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,6 +85,28 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } + + if(m_CurrentKeyState[GLFW_KEY_P]) + { + Events::StopSound e; + e.Emitter = 1; + EventBroker->Publish(e); + } + if(m_CurrentKeyState[GLFW_KEY_L]) + { + Events::PlayBGM e; + e.Resource = "Sounds/BGM/WilliamTellOverture.mp3"; + e.Loop = true; + EventBroker->Publish(e); + } + if(m_CurrentKeyState[GLFW_KEY_O]) + { + Events::PlayBGM e; + e.Resource = "Sounds/BGM/DiesIrae.mp3"; + e.Loop = true; + EventBroker->Publish(e); + } + // // Lock mouse while holding LMB // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) diff --git a/src/InputManager.h b/src/InputManager.h index 69827ba..bb30918 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -13,6 +13,9 @@ #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" +#include "Events/StopSound.h" +#include "Events/PlayBGM.h" + class InputManager { public: diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 1617078..cfb104e 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -2,13 +2,18 @@ #include "SoundSystem.h" #include "World.h" +Systems::SoundSystem::~SoundSystem() +{ + FMOD_System_Release(m_System); +} + void Systems::SoundSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX); EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound); - + m_isPlaying = false; m_TransformSystem = m_World->GetSystem(); FMOD_System_Create(&m_System); FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_ENABLE_PROFILE, 0); @@ -44,9 +49,8 @@ void Systems::SoundSystem::Update(double dt) std::map::iterator it; for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();) { - FMOD_BOOL isPlaying = false; - FMOD_Channel_IsPlaying(it->second, &isPlaying); - if(isPlaying) + FMOD_Channel_IsPlaying(it->second, &m_isPlaying); + if(m_isPlaying) { it++; } @@ -58,13 +62,12 @@ void Systems::SoundSystem::Update(double dt) } } - //LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); + LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); for(it = m_Channels.begin(); it != m_Channels.end();) { - FMOD_BOOL isPlaying = false; - FMOD_Channel_IsPlaying(it->second, &isPlaying); - if(!isPlaying) + FMOD_Channel_IsPlaying(it->second, &m_isPlaying); + if(!m_isPlaying) { it = m_Channels.erase(it); } @@ -163,21 +166,28 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) { - auto emitter = m_World->CreateEntity(); - auto eTransform = m_World->AddComponent(emitter); - auto eComponent = m_World->AddComponent(emitter); - m_Channels[emitter] = m_BGMChannel; - eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; + + FMOD_Channel_Stop(m_BGMChannel); Sound* sound = ResourceManager->Load("Sound2D", event.Resource); - //m_Sounds[emitter] = *sound; - FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]); + FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel); + FMOD_Channel_SetMode(m_BGMChannel, FMOD_LOOP_NORMAL); + FMOD_Sound_SetLoopCount(*sound, -1); + return true; } bool Systems::SoundSystem::StopSound(const Events::StopSound &event) { - FMOD_Channel_Stop(m_Channels[event.Emitter]); + auto eComp = m_World->GetComponent(event.Emitter); + if(eComp) + { + FMOD_Channel_Stop(m_Channels[event.Emitter]); + } + else + { + FMOD_Channel_Stop(m_BGMChannel); + } return true; } diff --git a/src/Systems/SoundSystem.h b/src/Systems/SoundSystem.h index 66ef6bc..6d3b48d 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -24,13 +24,12 @@ public: SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) : System(world, eventBroker, resourceManager) { } - + ~SoundSystem(); void RegisterComponents(ComponentFactory* cf) override; void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override; void Initialize() override; void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - //void OnComponentRemoved(std::string type, Component* component); void OnComponentRemoved(EntityID entity, std::string type, Component* component) override; FMOD_SYSTEM* GetFMODSystem() const { return m_System; } private: @@ -48,11 +47,11 @@ private: void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop); FMOD_SYSTEM* m_System; + FMOD_BOOL m_isPlaying; FMOD_CHANNEL* m_BGMChannel; std::vector m_Listeners; std::map m_Channels; std::map m_DeleteChannels; - //std::map m_Sounds; std::map m_DeleteSounds; std::shared_ptr m_TransformSystem; diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index fed4ecf..1c02897 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -78,15 +78,13 @@ Game\Systems - - Gameplay\Systems - Game\Systems Audio + @@ -526,9 +524,6 @@ Rendering\Components - - Gameplay\Systems - Physics\Events @@ -565,9 +560,6 @@ GUI - - Gameplay\Events - Game\Events @@ -577,6 +569,8 @@ Game\Components + + From 6e9eeaf99127bd1d6710cae2c755bfc72344a98e Mon Sep 17 00:00:00 2001 From: Stiffly Date: Wed, 4 Jun 2014 18:15:47 +0200 Subject: [PATCH 2/4] Dust particles from tank wheels. --- assets | 2 +- src/Components/ParticleEmitter.h | 2 +- src/GameWorld.cpp | 2 +- src/Systems/SoundSystem.cpp | 2 +- src/Systems/TankSteeringSystem.cpp | 182 +++++++++++++++++------------ src/Systems/TankSteeringSystem.h | 2 +- 6 files changed, 111 insertions(+), 81 deletions(-) diff --git a/assets b/assets index cfda101..d013629 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit cfda101f676fde45f9fd362b99fcec4f99e79cf1 +Subproject commit d013629690347939068dcf44726c08aa252a72ae diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index edd92b5..c403b6d 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -21,7 +21,7 @@ struct ParticleEmitter : Component , LifeTime(0) , TimeSinceLastSpawn(100) , Emitting(false) - , Color(glm::vec4(0)) { } + , Color(glm::vec4(1)) { } EntityID ParticleTemplate; float SpawnFrequency; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 03ca2b2..a0e6373 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -11,7 +11,7 @@ void GameWorld::Initialize() //Background Music { Events::PlayBGM e; - e.Resource = "Sounds/BGM/RideoftheValkyries.mp3"; + e.Resource = "Sounds/SFX/WUB.mp3"; EventBroker->Publish(e); } diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index cfb104e..dbf5ff3 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -62,7 +62,7 @@ void Systems::SoundSystem::Update(double dt) } } - LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); + //LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); for(it = m_Channels.begin(); it != m_Channels.end();) { diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 1e55ecf..4f8c2b3 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -30,6 +30,32 @@ void Systems::TankSteeringSystem::Update(double dt) void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { + auto pEmitter = m_World->GetComponent(entity); + if(pEmitter) + { + if(!m_World->GetComponent(parent)) + return; + auto tankTransform = m_World->GetComponent(parent); + glm::vec2 velXZ = glm::vec2(tankTransform->Velocity.x, tankTransform->Velocity.z); + float speedMPDT = glm::length(velXZ); + if(speedMPDT < 1) + { + pEmitter->Emitting = false; + return; + } + else + { + pEmitter->Emitting = true; + pEmitter->ScaleSpectrum.erase(pEmitter->ScaleSpectrum.begin()); + float scale = speedMPDT / 20; + scale = glm::clamp(scale, 0.3f, 20.f); + pEmitter->ScaleSpectrum.push_back(glm::vec3(speedMPDT / 20)); + float spawnFrequency = 1 / speedMPDT; + spawnFrequency = glm::clamp(spawnFrequency, 0.1f, 2.f); + pEmitter->SpawnFrequency = 1 / speedMPDT; + } + } + auto tankSteeringComponent = m_World->GetComponent(entity); if(!tankSteeringComponent) return; @@ -147,15 +173,6 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit m_TimeSinceLastShot[tankSteeringComponent->Barrel] += dt; } - -// auto shot = m_World->GetComponent(entity); -// if(shot) -// { -// if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5) -// { -// -// } -// } } bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) @@ -194,66 +211,66 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) //auto otherTransform = m_World->GetComponent(otherEntity); { + Events::CreateExplosion e; + e.LifeTime = 3; + e.ParticleScale.push_back(8); + e.ParticlesToSpawn = 20; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Smoke1.png"; + e.Color = glm::vec4(0.6,0.6,0.6,1); + EventBroker->Publish(e); + e.LifeTime = 0.7; + e.ParticleScale.push_back(12); + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 17; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + e.LifeTime = 0.2; + e.ParticleScale.push_back(1); + e.ParticleScale.push_back(15); + e.ParticlesToSpawn = 5; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 6; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Blast1.png"; + e.Color = glm::vec4(2, 2, 2, 0.2); + EventBroker->Publish(e); + // Events::CreateExplosion e; -// e.LifeTime = 3; -// e.ParticleScale.push_back(8); +// e.LifeTime = 1.5; +// e.ParticleScale.push_back(1); +// e.ParticleScale.push_back(6); // e.ParticlesToSpawn = 20; // e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 3; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Smoke1.png"; -// e.Color = glm::vec4(0.6,0.6,0.6,1); +// e.SpreadAngle = glm::radians(180) / 4; +// e.RelativeUpOrientation = glm::angleAxis(glm::radians(90), glm::vec3(1,0,0)); +// e.UseGoalVector = true; +// e.GoalVelocity = glm::vec3(0,-12,0); +// e.Speed = 12; +// e.spritePath = "Textures/Sprites/Splash.png"; +// e.Color = glm::vec4(5.f,5.f,5.f,1); +// // EventBroker->Publish(e); -// e.LifeTime = 0.7; -// e.ParticleScale.push_back(12); -// e.ParticlesToSpawn = 10; -// e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 17; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Fire.png"; -// EventBroker->Publish(e); -// e.LifeTime = 0.2; +// e.LifeTime = 1.5; // e.ParticleScale.push_back(1); -// e.ParticleScale.push_back(15); -// e.ParticlesToSpawn = 5; +// e.ParticleScale.push_back(6); +// e.ParticlesToSpawn = 20; // e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 6; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Blast1.png"; -// e.Color = glm::vec4(2, 2, 2, 0.2); +// e.SpreadAngle = glm::radians(180)/ 4; +// e.RelativeUpOrientation = glm::angleAxis(glm::radians(90), glm::vec3(1,0,0)); +// e.UseGoalVector = true; +// e.GoalVelocity = glm::vec3(0,-12,0); +// e.Speed = 12; +// e.spritePath = "Textures/Sprites/Splash.png"; +// e.Color = glm::vec4(1.f,1.f,1.f,1); // EventBroker->Publish(e); - - Events::CreateExplosion e; - e.LifeTime = 1.5; - e.ParticleScale.push_back(1); - e.ParticleScale.push_back(6); - e.ParticlesToSpawn = 20; - e.Position = shellTransform->Position; - e.SpreadAngle = glm::radians(180) / 4; - e.RelativeUpOrientation = glm::angleAxis(glm::radians(90), glm::vec3(1,0,0)); - e.UseGoalVector = true; - e.GoalVelocity = glm::vec3(0,-12,0); - e.Speed = 12; - e.spritePath = "Textures/Sprites/Splash.png"; - e.Color = glm::vec4(5.f,5.f,5.f,1); - - EventBroker->Publish(e); - e.LifeTime = 1.5; - e.ParticleScale.push_back(1); - e.ParticleScale.push_back(6); - e.ParticlesToSpawn = 20; - e.Position = shellTransform->Position; - e.SpreadAngle = glm::radians(180)/ 4; - e.RelativeUpOrientation = glm::angleAxis(glm::radians(90), glm::vec3(1,0,0)); - e.UseGoalVector = true; - e.GoalVelocity = glm::vec3(0,-12,0); - e.Speed = 12; - e.spritePath = "Textures/Sprites/Splash.png"; - e.Color = glm::vec4(1.f,1.f,1.f,1); - EventBroker->Publish(e); } { Events::PlaySFX e; @@ -431,7 +448,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) auto health = m_World->AddComponent(tank); health->Amount = 100.f; m_World->AddComponent(tank); - + + { auto shape = m_World->CreateEntity(tank); auto transform = m_World->AddComponent(shape); @@ -565,31 +583,43 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false); #pragma endregion +#pragma region DustParticles + + std::vector ePos; + ePos.push_back(glm::vec3(-2, -1.7, 2.0)); + ePos.push_back(glm::vec3(2, -1.7, 2.0)); + ePos.push_back(glm::vec3(2, -1.7, -2.0)); + ePos.push_back(glm::vec3(-2, -1.7, -2.0)); + + for (int i = 0; i < 4; i++) { auto entity = m_World->CreateEntity(tank); auto transformComponent = m_World->AddComponent(entity); - transformComponent->Position = glm::vec3(-2, -1.7, 2.0); + transformComponent->Position = ePos[i]; transformComponent->Scale = glm::vec3(3, 3, 3); transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); auto emitterComponent = m_World->AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; + emitterComponent->SpawnCount = 1; + emitterComponent->SpawnFrequency = 0.1; emitterComponent->SpreadAngle = glm::pi(); emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - m_World->CommitEntity(entity); - + emitterComponent->LifeTime = 0.3; + emitterComponent->Speed = 3; + emitterComponent->Emitting = true; + emitterComponent->Fade = true; + emitterComponent->ScaleSpectrum.push_back(glm::vec3(1)); + //emitterComponent->Color = glm::vec4(1); auto particleEntity = m_World->CreateEntity(entity); - auto TEMP = m_World->AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); + m_World->AddComponent(particleEntity); + m_World->AddComponent(particleEntity); auto spriteComponent = m_World->AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - + spriteComponent->SpriteFile = "Textures/Sprites/Dirt.png"; m_World->CommitEntity(particleEntity); + emitterComponent->ParticleTemplate = particleEntity; + m_World->CommitEntity(entity); } +#pragma endregion + m_World->CommitEntity(tank); diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 3f2ee51..78ad3e4 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -1,5 +1,4 @@ #include - #include "System.h" #include "Events/TankSteer.h" #include "Events/SetVelocity.h" @@ -23,6 +22,7 @@ #include "Components/TankShell.h" #include "Components/SphereShape.h" #include "Components/Listener.h" +#include "Components/SoundEmitter.h" #include "Events/EnableCollisions.h" #include "Events/DisableCollisions.h" From 09971b2d77b2c6f42067fb4a404a760c349a7d5e Mon Sep 17 00:00:00 2001 From: Stiffly Date: Thu, 5 Jun 2014 03:14:45 +0200 Subject: [PATCH 3/4] Publishes some bgm sounds --- assets | 2 +- src/GUI/GameFrame.h | 6 +++--- src/GUI/MainMenuFrame.h | 12 ++++++++++-- src/Systems/GameStateSystem.cpp | 9 ++++++--- src/Systems/GameStateSystem.h | 1 + src/Systems/SoundSystem.cpp | 10 +++++++--- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/assets b/assets index d013629..5357a0c 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d013629690347939068dcf44726c08aa252a72ae +Subproject commit 5357a0c4e1020317bb8745a057d6da62ab6c6504 diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 56d0391..1b520d9 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -41,10 +41,10 @@ public: m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World); m_FreeCamViewport->Hide(); } - //m_WorldFrame->Hide(); - //m_MainMenuFrame = new MainMenuFrame(this, "MainMenu"); - + m_WorldFrame->Hide(); m_World->Initialize(); + + m_MainMenuFrame = new MainMenuFrame(this, "MainMenu"); } private: diff --git a/src/GUI/MainMenuFrame.h b/src/GUI/MainMenuFrame.h index ff43254..076d6f9 100644 --- a/src/GUI/MainMenuFrame.h +++ b/src/GUI/MainMenuFrame.h @@ -5,6 +5,7 @@ #include "GUI/HealthOverlay.h" #include "Events/GameStart.h" +#include "Events/PlayBGM.h" namespace GUI { @@ -27,6 +28,10 @@ public: m_TargetCoordinate = m_CurrentCoordinate; m_Buttons->X = m_CurrentCoordinate.x; m_Buttons->Y = m_CurrentCoordinate.y; + + Events::PlayBGM e; + e.Resource = "Sounds/BGM/DiesIrae.mp3"; + EventBroker->Publish(e); } void Update(double dt) override @@ -74,8 +79,11 @@ protected: if (m_CurrentSelection == 0) { Hide(); - Events::GameStart e; - EventBroker->Publish(e); + Events::GameStart e1; + EventBroker->Publish(e1); + Events::PlayBGM e2; + e2.Resource = "Sounds/BGM/FlightOfTheBumblebee.mp3"; + EventBroker->Publish(e2); } // Quit else if (m_CurrentSelection == 1) diff --git a/src/Systems/GameStateSystem.cpp b/src/Systems/GameStateSystem.cpp index ca17bd3..54b87b9 100644 --- a/src/Systems/GameStateSystem.cpp +++ b/src/Systems/GameStateSystem.cpp @@ -11,9 +11,12 @@ bool Systems::GameStateSystem::OnFlagCaptured(const Events::FlagCaptured &event) { m_InGame = false; - Events::GameOver e; - e.Winner = event.Player; - EventBroker->Publish(e); + Events::GameOver e1; + e1.Winner = event.Player; + EventBroker->Publish(e1); + Events::PlayBGM e2; + e2.Resource = "Sounds/BGM/WilliamTellOverture.mp3"; + EventBroker->Publish(e2); return true; } \ No newline at end of file diff --git a/src/Systems/GameStateSystem.h b/src/Systems/GameStateSystem.h index ac9d46e..d24f0a6 100644 --- a/src/Systems/GameStateSystem.h +++ b/src/Systems/GameStateSystem.h @@ -8,6 +8,7 @@ #include "Components/Player.h" #include "Events/FlagCaptured.h" #include "Events/GameOver.h" +#include "Events/PlayBGM.h" namespace Systems { diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index dbf5ff3..c60a36a 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -166,11 +166,15 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) { - - FMOD_Channel_Stop(m_BGMChannel); + FMOD_RESULT result; + result = FMOD_Channel_Stop(m_BGMChannel); + if(result != FMOD_OK) + LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result)); Sound* sound = ResourceManager->Load("Sound2D", event.Resource); - FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel); + result = FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel); + if(result != FMOD_OK) + LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result)); FMOD_Channel_SetMode(m_BGMChannel, FMOD_LOOP_NORMAL); FMOD_Sound_SetLoopCount(*sound, -1); From ccc2c4931795ee662491785e300eb152e6100cc0 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Thu, 5 Jun 2014 05:11:04 +0200 Subject: [PATCH 4/4] Vehicle component has "CurrentRPM" --- src/Components/Vehicle.h | 3 ++- src/Systems/PhysicsSystem.cpp | 3 ++- src/Systems/SoundSystem.cpp | 16 +++++++++------- src/Systems/SoundSystem.h | 1 + src/Systems/TankSteeringSystem.cpp | 7 ++++++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 9f6cfac..431d7b4 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -12,7 +12,7 @@ struct Vehicle : Component Vehicle() : MaxTorque(1000.0f), MinRPM(200.0f), OptimalRPM(3000.0f), MaxRPM(6000.0f), MaxSteeringAngle(35), TopSpeed(90.0f), MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(5500.0f), DownshiftRPM(1000.0f), - gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f){ } + gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f), currentRPM(0.0f){ } float MaxTorque; float MinRPM; float OptimalRPM; @@ -29,6 +29,7 @@ struct Vehicle : Component float gearsRatio1; float gearsRatio2; float gearsRatio3; + float currentRPM; Vehicle* Clone() const override { return new Vehicle(*this); } }; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 3db178b..4633ace 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -253,7 +253,8 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p } }*/ - + auto vehicleComponent = m_World->GetComponent(car); + vehicleComponent->currentRPM = m_Vehicles[car]->calcRPM(); m_Vehicles[car]->getChassis()->activate(); diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index c60a36a..b0cb49e 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -57,7 +57,7 @@ void Systems::SoundSystem::Update(double dt) else { // FMOD_Sound_Release(m_DeleteSounds[it->first]); -// m_DeleteSounds.erase(it->first); + m_DeleteSounds.erase(it->first); it = m_DeleteChannels.erase(it); } @@ -104,7 +104,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par if(emitter) { FMOD_CHANNEL* channel = m_Channels[entity]; - //FMOD_SOUND* sound = m_Sounds[entity]; + FMOD_SOUND* sound = m_Sounds[entity]; auto eTransform = m_World->GetComponent(entity); glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity); @@ -137,9 +137,9 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev float maxDist = emitter->MaxDistance; float minDist = emitter->MinDistance; float pitch = emitter->Pitch; - //LoadSound(sound, path, maxDist, minDist); + LoadSound(sound, path, maxDist, minDist); m_Channels.insert(std::make_pair(emitter->Entity, channel)); -// m_Sounds.insert(std::make_pair(emitter->Entity, sound)); + m_Sounds.insert(std::make_pair(emitter->Entity, sound)); } return true; } @@ -157,7 +157,7 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; Sound* sound = ResourceManager->Load("Sound3D", event.Resource); - //m_Sounds[eEntity] = *sound; + m_Sounds[eEntity] = *sound; FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance); PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop); @@ -181,6 +181,8 @@ bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) return true; } + + bool Systems::SoundSystem::StopSound(const Events::StopSound &event) { auto eComp = m_World->GetComponent(event.Emitter); @@ -222,8 +224,8 @@ void Systems::SoundSystem::OnComponentRemoved(EntityID entity, std::string type, if(emitter) { m_DeleteChannels.insert(std::make_pair(entity, m_Channels[entity])); - //m_DeleteSounds.insert(std::make_pair(entity, m_Sounds[entity])); + m_DeleteSounds.insert(std::make_pair(entity, m_Sounds[entity])); m_Channels.erase(entity); - //m_Sounds.erase(entity); + m_Sounds.erase(entity); } } \ No newline at end of file diff --git a/src/Systems/SoundSystem.h b/src/Systems/SoundSystem.h index 6d3b48d..8803e0e 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -53,6 +53,7 @@ private: std::map m_Channels; std::map m_DeleteChannels; std::map m_DeleteSounds; + std::map m_Sounds; std::shared_ptr m_TransformSystem; }; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 4f8c2b3..dec2d67 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -445,9 +445,12 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) player->ID = playerID; auto tankSteering = m_World->AddComponent(tank); m_World->AddComponent(tank); + m_World->AddComponent(tank); auto health = m_World->AddComponent(tank); health->Amount = 100.f; - m_World->AddComponent(tank); + + + { @@ -535,6 +538,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f)); auto cameraComp = m_World->AddComponent(cameraTower); cameraComp->FarClip = 2000.f; + + /*auto follow = m_World->AddComponent(cameraTower); follow->Entity = barrel; follow->Distance = 15.f;