diff --git a/assets b/assets index c61526f..588da9c 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit c61526f5fc5caf2773d61296727ecea29df51a2c +Subproject commit 588da9ca0d0e6a3dd08f4373e03468f79082b359 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 2708b2e..698e6f6 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -590,7 +590,7 @@ void GameWorld::Initialize() { EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); } - + #pragma endregion Region for all wall creations /*EntityID tank1 = CreateTank(1); @@ -616,7 +616,7 @@ void GameWorld::Initialize() EventBroker->Publish(e); }*/ - CreateGarage(glm::vec3(-3.93076, -49, 0), 1); + CreateGarage(glm::vec3(-3.93076, 0, 0), 1); { auto flag = CreateEntity(); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 480e3dd..fd0eca3 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -531,7 +531,20 @@ void Renderer::ForwardRendering(RenderQueue &rq) if (spriteJob) { glm::mat4 modelMatrix = spriteJob->ModelMatrix; - MVP = cameraMatrix * modelMatrix; + MVP = cameraMatrix * modelMatrix * glm::inverse(glm::toMat4(glm::inverse(m_Camera->Orientation()))); + + + //auto spriteComponent = m_World->GetComponent(entity); + //if (transformComponent && spriteComponent) + //{ + // //TEMP + // Texture* texture = m_World->ResourceManager->Load("Texture", spriteComponent->SpriteFile); + // //glBindTexture(GL_TEXTURE_2D, texture); + // auto transform = m_World->GetComponent(spriteComponent->Entity); + // glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1)); + // m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale); + //} + 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))); diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index b66d5d4..5dd446b 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -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,20 +132,13 @@ 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; @@ -146,10 +150,10 @@ 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], m_Sounds[eEntity], 1.0, eComponent->Loop); + PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop); return true; } @@ -161,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; @@ -200,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 429be74..4034939 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -97,7 +97,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0; Events::PlaySFX e; - e.Resource = "Sounds/SFX/LongBoom.wav"; + e.Resource = "Sounds/SFX/TankShot.mp3"; e.Position = absoluteTransform.Position; e.Loop = false; EventBroker->Publish(e); @@ -193,6 +193,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) {