Added some comments.

This commit is contained in:
stiffly
2016-02-05 18:04:36 +01:00
parent becb197feb
commit 09fb3a6571
2 changed files with 19 additions and 11 deletions
+8 -3
View File
@@ -14,19 +14,24 @@ public:
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) override;
virtual void Update(double dt) override;
private:
// The logic for making the sound play when player is moving
void playerStep(double dt);
EntityWrapper m_LocalPlayer = EntityWrapper();
World* m_World = nullptr;
EventBroker* m_EventBroker = nullptr;
// Logic for playing a sound when a player jumps
void playerJumps();
// TODO: WIP Update this
// Walking logic
// Keeps track of how far the player has walked within this "key press session".
float m_DistanceMoved = 0.0f;
const float m_PlayerStepLength = 2.0f;
// How far a step is (How often the step sound will be played).
const float m_PlayerStepLength = 1.75f;
// To get a difference when calculating the walking state.
glm::vec3 m_LastPosition = glm::vec3();
// Determine what sound file to play.
bool m_LeftFoot = false;
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
+11 -8
View File
@@ -20,6 +20,7 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp
void SoundSystem::Update(double dt)
{
playerStep(dt);
// Update listener and emitters.
SoundManager::Update(dt);
}
@@ -28,11 +29,13 @@ void SoundSystem::playerStep(double dt)
if (!m_LocalPlayer.Valid()) {
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"];
// Velocity of the local player, used to see if a player is airborne.
glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
glm::vec3 difference = pos - m_LastPosition;
m_DistanceMoved += glm::length(pos - m_LastPosition);
// Set the last position for next iteration
m_LastPosition = pos;
m_DistanceMoved += glm::length(difference);
bool isAirborne = vel.y != 0;
if (m_DistanceMoved > m_PlayerStepLength && !isAirborne) {
// Player moved a step's distance
@@ -56,11 +59,11 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
event.FilePath = "Audio/announcer/go.wav";
m_EventBroker->Publish(event);
// TEMP: starts bgm
// {
// Events::PlayBackgroundMusic ev;
// ev.FilePath = "Audio/bgm/ambient.wav";
// m_EventBroker->Publish(ev);
// }
{
Events::PlayBackgroundMusic ev;
ev.FilePath = "Audio/bgm/ambient.wav";
m_EventBroker->Publish(ev);
}
}
return true;
}
@@ -76,7 +79,7 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
if (e.Command == "Forward" || e.Command == "Right") {
if (e.Value == 0) {
// Key released
// Reset the distance moved
// Reset the distance moved (player walk logic)
m_DistanceMoved = 0.f;
}
}