From d4f1f280708162fe3e88c966466fdf276296da6f Mon Sep 17 00:00:00 2001 From: Antonius Riha Date: Mon, 2 May 2016 11:32:04 +0200 Subject: [PATCH 1/3] Support disabling race intro and start sounds --- src/modes/cutscene_world.cpp | 3 ++- src/modes/world_status.cpp | 11 ++++++----- src/modes/world_status.hpp | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index ce283a6fd..61008088c 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -58,7 +58,8 @@ CutsceneWorld::CutsceneWorld() : World() m_aborted = false; WorldStatus::setClockMode(CLOCK_NONE); m_use_highscores = false; - m_play_racestart_sounds = false; + m_play_track_intro_sound = false; + m_play_ready_set_go_sounds = false; m_fade_duration = 1.0f; } // CutsceneWorld diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 578f13a0e..3e32a642c 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -39,7 +39,8 @@ WorldStatus::WorldStatus() m_start_sound = SFXManager::get()->createSoundSource("start_race"); m_track_intro_sound = SFXManager::get()->createSoundSource("track_intro"); - m_play_racestart_sounds = true; + m_play_track_intro_sound = UserConfigParams::m_music; + m_play_ready_set_go_sounds = true; IrrlichtDevice *device = irr_driver->getDevice(); @@ -149,7 +150,7 @@ void WorldStatus::update(const float dt) m_auxiliary_timer = 0.0f; m_phase = TRACK_INTRO_PHASE; - if (m_play_racestart_sounds) + if (m_play_track_intro_sound) { m_track_intro_sound->play(); } @@ -186,7 +187,7 @@ void WorldStatus::update(const float dt) m_auxiliary_timer = 0.0f; - if (m_play_racestart_sounds) + if (m_play_ready_set_go_sounds) m_prestart_sound->play(); m_phase = READY_PHASE; @@ -200,7 +201,7 @@ void WorldStatus::update(const float dt) case READY_PHASE: if (m_auxiliary_timer > 1.0) { - if (m_play_racestart_sounds) + if (m_play_ready_set_go_sounds) { m_prestart_sound->play(); } @@ -224,7 +225,7 @@ void WorldStatus::update(const float dt) { // set phase is over, go to the next one m_phase = GO_PHASE; - if (m_play_racestart_sounds) + if (m_play_ready_set_go_sounds) { m_start_sound->play(); } diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index 270ca5a44..86c82a29f 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -97,7 +97,8 @@ protected: double m_time; ClockType m_clock_mode; - bool m_play_racestart_sounds; + bool m_play_track_intro_sound; + bool m_play_ready_set_go_sounds; private: Phase m_phase; From 342b4f299e5e5d05cf5f4389e5ca2ecf118f17a9 Mon Sep 17 00:00:00 2001 From: Antonius Riha Date: Mon, 2 May 2016 21:53:34 +0200 Subject: [PATCH 2/3] Delay start for 3s when intro sound is off To bridge the silence before ready-set-go, the engines are started earlier than normal if intro sound is off. --- src/modes/world_status.cpp | 30 ++++++++++++++++++++++++++---- src/modes/world_status.hpp | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 3e32a642c..880a18175 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -30,6 +30,21 @@ #include +//----------------------------------------------------------------------------- +/** Starts the kart engines. + */ +void WorldStatus::startEngines() +{ + if (m_engines_started) + return; + + m_engines_started = true; + for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++) + { + World::getWorld()->getKart(i)->startEngineSFX(); + } +} + //----------------------------------------------------------------------------- WorldStatus::WorldStatus() { @@ -55,6 +70,9 @@ void WorldStatus::reset() { m_time = 0.0f; m_auxiliary_timer = 0.0f; + + m_engines_started = false; + // Using SETUP_PHASE will play the track into sfx first, and has no // other side effects. m_phase = UserConfigParams::m_race_now ? MUSIC_PHASE : SETUP_PHASE; @@ -184,6 +202,13 @@ void WorldStatus::update(const float dt) // Wait before ready phase if sounds are disabled if (!UserConfigParams::m_sfx && m_auxiliary_timer < 3.0f) return; + + if (!m_play_track_intro_sound) + { + startEngines(); + if (m_auxiliary_timer < 3.0f) + return; + } m_auxiliary_timer = 0.0f; @@ -192,10 +217,7 @@ void WorldStatus::update(const float dt) m_phase = READY_PHASE; - for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++) - { - World::getWorld()->getKart(i)->startEngineSFX(); - } + startEngines(); break; case READY_PHASE: diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index 86c82a29f..736dcfb6b 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -114,6 +114,8 @@ private: */ float m_auxiliary_timer; + bool m_engines_started; + void startEngines(); public: WorldStatus(); virtual ~WorldStatus(); From bf64ce9ec0b5f991ade58df030616735b969fcaa Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 3 May 2016 15:44:44 +0800 Subject: [PATCH 3/3] Avoid negative square root Which seems to happen if a kart is going backward --- src/items/flyable.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index c456e3136..02a2fd24f 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -317,7 +317,14 @@ void Flyable::getLinearKartItemIntersection (const Vec3 &origin, * (dx * cosf(target_kart_heading) - dz * sinf(target_kart_heading) ); - float fire_th = (dx*dist - dz * sqrtf(dx*dx + dz*dz - dist*dist)) + float f = dx*dx + dz*dz - dist*dist; + // Avoid negative square root + if(f>0) + f = sqrtf(f); + else + f = 0.0f; + + float fire_th = (dx*dist - dz * f) / (dx*dx + dz*dz); if(fire_th>1) fire_th = 1.0f;