diff --git a/assets b/assets index cc30e5f..78ba667 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit cc30e5fb5c32068ef973a15d0142899c0d3b9cf4 +Subproject commit 78ba667b37a553c8387bc2717032c284dbd14aa9 diff --git a/src/Components/SoundEmitter.h b/src/Components/SoundEmitter.h index cc9b738..e969fba 100755 --- a/src/Components/SoundEmitter.h +++ b/src/Components/SoundEmitter.h @@ -10,13 +10,14 @@ namespace Components struct SoundEmitter : Component { + enum class SoundType { SOUND_3D, SOUND_2D }; - SoundEmitter() : Gain(1.f), MaxDistance(1.f), MinDistance(1.f), Pitch(1.f), Loop(false) {} + SoundEmitter() : Gain(1.f), MaxDistance(10000.f), MinDistance(1.f), Pitch(1.f), Loop(false) {} float Gain; float MaxDistance; float MinDistance; diff --git a/src/Events/PlaySFX.h b/src/Events/PlaySFX.h index e96f8cf..4df4ce3 100644 --- a/src/Events/PlaySFX.h +++ b/src/Events/PlaySFX.h @@ -9,8 +9,17 @@ namespace Events struct PlaySFX : Event { - EntityID Emitter; + PlaySFX() : + MinDistance(100.f), + MaxDistance(10000.f), + Volume(1.f), + Loop (false) {} + //EntityID Emitter; + glm::vec3 Position; std::string Resource; + float MinDistance; + float MaxDistance; + float Volume; bool Loop; }; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 381fde0..958fd1b 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -532,8 +532,9 @@ void Renderer::ForwardRendering(RenderQueue &rq) if (spriteJob) { glm::mat4 modelMatrix = spriteJob->ModelMatrix; - MVP = cameraMatrix * modelMatrix; - + glm::mat4 billboardingMatrix = glm::inverse(glm::toMat4(glm::inverse(m_Camera->Orientation()))); + MVP = cameraMatrix * modelMatrix * billboardingMatrix; + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP))); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix))); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4(m_Camera->ViewMatrix()))); diff --git a/src/Systems/DebugSystem.cpp b/src/Systems/DebugSystem.cpp index b8d6d28..ed4c0aa 100644 --- a/src/Systems/DebugSystem.cpp +++ b/src/Systems/DebugSystem.cpp @@ -20,7 +20,7 @@ bool Systems::DebugSystem::OnKeyDown(const Events::KeyDown &event) if (event.KeyCode == GLFW_KEY_ENTER) { Events::PlaySFX e; - e.Emitter = 0; + e.Position = glm::vec3(0); e.Resource = "Sounds/korvring.wav"; EventBroker->Publish(e); diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 7e0333e..5dd446b 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -20,7 +20,7 @@ void Systems::SoundSystem::Initialize() { LOG_INFO("FMOD initialized successfully"); } - FMOD_System_Set3DSettings(m_System, 1.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale + FMOD_System_Set3DSettings(m_System, 0.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale } @@ -44,20 +44,31 @@ 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); + FMOD_BOOL isPlaying = false; + FMOD_Channel_IsPlaying(it->second, &isPlaying); if(isPlaying) { it++; } else { - FMOD_Sound_Release(m_DeleteSounds[it->first]); - m_DeleteSounds.erase(it->first); +// FMOD_Sound_Release(m_DeleteSounds[it->first]); +// m_DeleteSounds.erase(it->first); it = m_DeleteChannels.erase(it); } } + //LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); + for (auto channel : m_Channels) + { + FMOD_BOOL isPlaying = false; + FMOD_Channel_IsPlaying(channel.second, &isPlaying); + if(!isPlaying) + { + m_Channels.erase(channel.first); + } + } + } void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -86,7 +97,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); @@ -121,34 +132,28 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev float pitch = emitter->Pitch; //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; } bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) { - auto emitter = m_World->GetComponent(event.Emitter); - if(!emitter) - { - LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter]; - return false; - } + auto eEntity = m_World->CreateEntity(); + auto eTransform = m_World->AddComponent(eEntity); + eTransform->Position = event.Position; + auto eComponent = m_World->AddComponent(eEntity); + eComponent->MinDistance = event.MinDistance; + eComponent->MaxDistance= event.MaxDistance; + eComponent->Loop = event.Loop; + eComponent->Gain = event.Volume; - emitter->type = Components::SoundEmitter::SoundType::SOUND_3D; + eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; Sound* sound = ResourceManager->Load("Sound3D", event.Resource); - m_Sounds[event.Emitter] = *sound; - FMOD_Sound_Set3DMinMaxDistance(*sound, emitter->MinDistance, emitter->MaxDistance); + //m_Sounds[eEntity] = *sound; + FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance); - PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop); - FMOD_System_Update(m_System); - - FMOD_BOOL isPlaying = false; - FMOD_Channel_IsPlaying(m_Channels[event.Emitter], &isPlaying); - if(!isPlaying) - LOG_ERROR("FMOD: File %s is not playing", event.Resource.c_str()); - else - LOG_INFO("Now playing sound %s", event.Resource.c_str()); + PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop); return true; } @@ -160,7 +165,7 @@ bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event) m_Channels[emitter] = m_BGMChannel; eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; Sound* sound = ResourceManager->Load("Sound2D", event.Resource); - m_Sounds[emitter] = *sound; + //m_Sounds[emitter] = *sound; FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]); return true; @@ -199,8 +204,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 3f0b426..66ef6bc 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -52,7 +52,7 @@ private: std::vector m_Listeners; std::map m_Channels; std::map m_DeleteChannels; - std::map m_Sounds; + //std::map m_Sounds; std::map m_DeleteSounds; std::shared_ptr m_TransformSystem; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 4bd4c91..88d05a3 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -90,12 +90,48 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit auto cloneTransform = m_World->GetComponent(clone); cloneTransform->Position = templateAbsoluteTransform.Position; cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation; + Events::SetVelocity eSetVelocity; eSetVelocity.Entity = clone; eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed); EventBroker->Publish(eSetVelocity); m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0; + { + Events::CreateExplosion e; + e.LifeTime = 1.5; + e.ParticleScale.push_back(0.6); + e.ParticleScale.push_back(1.8); + e.ParticlesToSpawn = 5; + e.Position = cloneTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 1.7; + e.SpreadAngle = glm::pi()/10; + e.spritePath = "Textures/Sprites/Smoke1.png"; + e.Color = glm::vec4(0.6,0.6,0.6,1); + EventBroker->Publish(e); + } + { + Events::CreateExplosion e; + e.LifeTime = 0.2; + e.ParticleScale.push_back(1); + //e.ParticleScale.push_back(2); + e.ParticlesToSpawn = 1; + e.Position = cloneTransform->Position; + e.Speed = 0; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/MuzzleFlash.png"; + e.Color = glm::vec4(2, 2, 2, 0.2); + EventBroker->Publish(e); + } + + { +// Events::PlaySFX e; +// e.Resource = "Sounds/SFX/TankShot.mp3"; +// e.Position = absoluteTransform.Position; +// e.Loop = false; +// EventBroker->Publish(e); + } auto clonePhysicsComponent = m_World->GetComponent(clone); //1,670m/s @@ -109,6 +145,15 @@ 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) @@ -179,6 +224,13 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) e.Color = glm::vec4(2, 2, 2, 0.2); EventBroker->Publish(e); } + { +// Events::PlaySFX e; +// e.MinDistance = 150.f; +// e.Position = shellTransform->Position; +// e.Resource = "Sounds/SFX/Explosion.wav"; +// EventBroker->Publish(e); + } for (auto &physComponent : *physicsComponents) { diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 981c650..7035825 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -29,6 +29,9 @@ #include "Components/TriggerExplosion.h" #include "Components/FrameTimer.h" +#include "Events/PlaySFX.h" +#include "Events/PlayBGM.h" + #include "Events/Damage.h" #include "Components/Vehicle.h" #include "Components/Player.h" diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 24209c6..fed4ecf 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -194,6 +194,9 @@ {3cbe68d9-2446-45ee-8637-ffb805997dcd} + + {a025d51e-594d-4844-983b-f683726bf1bf} + {9702064a-02a2-4b3c-a2ab-47c23a9cf49c} @@ -556,6 +559,9 @@ Base\Components + + Rendering\Components + GUI