Merge remote-tracking branch 'origin/Sound+Particles'
Conflicts: src/GameWorld.cpp
This commit is contained in:
+1
-1
Submodule assets updated: cc30e5fb5c...78ba667b37
@@ -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;
|
||||
|
||||
+10
-1
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
+3
-2
@@ -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())));
|
||||
|
||||
@@ -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<Events::PlaySFX>(e);
|
||||
|
||||
|
||||
+33
-28
@@ -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<EntityID, FMOD_CHANNEL*>::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<Components::Transform>(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<Components::SoundEmitter>(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<Components::Transform>(eEntity);
|
||||
eTransform->Position = event.Position;
|
||||
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(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<Sound>("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<Sound>("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);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
std::vector<EntityID> m_Listeners;
|
||||
std::map<EntityID, FMOD_CHANNEL*> m_Channels;
|
||||
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
|
||||
std::map<EntityID, FMOD_SOUND*> m_Sounds;
|
||||
//std::map<EntityID, FMOD_SOUND*> m_Sounds;
|
||||
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
|
||||
|
||||
@@ -90,12 +90,48 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
auto cloneTransform = m_World->GetComponent<Components::Transform>(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<float>() / 2, glm::vec3(1,0,0));
|
||||
e.Speed = 1.7;
|
||||
e.SpreadAngle = glm::pi<float>()/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<float>();
|
||||
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<Components::Physics>(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<Components::TankShell>(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)
|
||||
{
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -194,6 +194,9 @@
|
||||
<Filter Include="Base\Events">
|
||||
<UniqueIdentifier>{3cbe68d9-2446-45ee-8637-ffb805997dcd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Rendering\Events">
|
||||
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Game\Events">
|
||||
<UniqueIdentifier>{9702064a-02a2-4b3c-a2ab-47c23a9cf49c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -556,6 +559,9 @@
|
||||
<ClInclude Include="..\..\src\Components\Rotate.h">
|
||||
<Filter>Base\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\BlendMap.h">
|
||||
<Filter>Rendering\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
|
||||
<Filter>GUI</Filter>
|
||||
</ClInclude>
|
||||
|
||||
Reference in New Issue
Block a user