From 99d8ad8ac1958be6964bb93857bade793ce9d117 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 30 Mar 2018 22:46:32 +1100 Subject: [PATCH] Properly fix #3159 (Wrong direction text is displayed twice). When this is merged with master, the current work around in #3159 can be reverted. --- src/karts/abstract_kart.hpp | 4 +-- src/karts/kart.cpp | 2 +- src/karts/kart.hpp | 10 +++--- src/modes/easter_egg_hunt.cpp | 3 +- src/modes/easter_egg_hunt.hpp | 2 +- src/modes/linear_world.cpp | 60 +++++++++++++++++++++++------------ src/modes/linear_world.hpp | 3 +- 7 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index 84cc4212f..ec36ea854 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -459,8 +459,8 @@ public: virtual void setOnScreenText(const wchar_t *text) = 0; // ------------------------------------------------------------------------- /** Counter which is used for displaying wrong way message after a delay */ - virtual int getWrongwayCounter() = 0; - virtual void setWrongwayCounter(int counter) = 0; + virtual float getWrongwayTimer() = 0; + virtual void setWrongwayTimer(float timer) = 0; // ------------------------------------------------------------------------ /** Returns whether this kart wins or loses. */ virtual bool getRaceResult() const = 0; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 844064d8e..7447f4724 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -141,7 +141,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id, m_is_jumping = false; m_min_nitro_ticks = 0; m_fire_clicked = 0; - m_wrongway_counter = 0; + m_wrongway_timer = 0; m_type = RaceManager::KT_AI; m_view_blocked_by_plunger = 0; diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 7aa7adee5..ac7f7f67a 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -158,8 +158,8 @@ protected: /** True if fire button was pushed and not released */ bool m_fire_clicked; - /** Counter which is used for displaying wrong way message after a delay */ - int m_wrongway_counter; + /** Timer which is used for displaying wrong way message after a delay */ + float m_wrongway_timer; // Bullet physics parameters @@ -463,10 +463,10 @@ public: /** For debugging only: check if a kart is flying. */ bool isFlying() const { return m_flying; } // ------------------------------------------------------------------------ - /** Counter which is used for displaying wrong way message after a delay */ - int getWrongwayCounter() { return m_wrongway_counter; } + /** Timer which is used for displaying wrong way message after a delay */ + float getWrongwayTimer() { return m_wrongway_timer; } // ------------------------------------------------------------------------ - void setWrongwayCounter(int counter) { m_wrongway_counter = counter; } + void setWrongwayTimer(float timer) { m_wrongway_timer = timer; } // ------------------------------------------------------------------------ /** Returns whether this kart wins or loses. */ virtual bool getRaceResult() const { return m_race_result; } diff --git a/src/modes/easter_egg_hunt.cpp b/src/modes/easter_egg_hunt.cpp index 2f9935d28..12ec0fe8a 100644 --- a/src/modes/easter_egg_hunt.cpp +++ b/src/modes/easter_egg_hunt.cpp @@ -208,8 +208,9 @@ void EasterEggHunt::getKartsDisplayInfo( /** Override the base class method to change behavior. We don't want wrong * direction messages in the easter egg mode since there is no direction there. * \param i Kart id. + * \param dt Time step size. */ -void EasterEggHunt::checkForWrongDirection(unsigned int i, int ticks) +void EasterEggHunt::checkForWrongDirection(unsigned int i, float dt) { } // checkForWrongDirection diff --git a/src/modes/easter_egg_hunt.hpp b/src/modes/easter_egg_hunt.hpp index 9b095b7ca..29b4a1c49 100644 --- a/src/modes/easter_egg_hunt.hpp +++ b/src/modes/easter_egg_hunt.hpp @@ -65,7 +65,7 @@ public: void collectedEasterEgg(const AbstractKart *kart); void readData(const std::string &filename); - virtual void checkForWrongDirection(unsigned int i, int ticks) OVERRIDE; + virtual void checkForWrongDirection(unsigned int i, float dt) OVERRIDE; virtual float estimateFinishTimeForKart(AbstractKart* kart) OVERRIDE; }; // EasterEggHunt diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 73f5f1220..0530096dc 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -96,7 +96,7 @@ void LinearWorld::reset() for(unsigned int i=0; isetWrongwayCounter(0); + m_karts[i]->setWrongwayTimer(0); } // next kart // At the moment the last kart would be the one that is furthest away @@ -158,13 +158,6 @@ void LinearWorld::update(int ticks) // especially updates the kart positions. WorldWithRank::update(ticks); - if (m_last_lap_sfx_playing && - m_last_lap_sfx->getStatus() != SFXBase::SFX_PLAYING) - { - music_manager->resetTemporaryVolume(); - m_last_lap_sfx_playing = false; - } - const unsigned int kart_amount = getNumKarts(); // Do stuff specific to this subtype of race. @@ -213,7 +206,6 @@ void LinearWorld::update(int ticks) m_kart_info[i].m_estimated_finish = estimateFinishTimeForKart(m_karts[i]); } - checkForWrongDirection(i, ticks); } #ifdef DEBUG @@ -242,6 +234,33 @@ void LinearWorld::update(int ticks) #endif } // update +//----------------------------------------------------------------------------- +/** This updates all only graphical elements.It is only called once per +* rendered frame, not once per time step. +* float dt Time since last rame. +*/ +void LinearWorld::updateGraphics(float dt) +{ + if (m_last_lap_sfx_playing && + m_last_lap_sfx->getStatus() != SFXBase::SFX_PLAYING) + { + music_manager->resetTemporaryVolume(); + m_last_lap_sfx_playing = false; + } + + const unsigned int kart_amount = getNumKarts(); + for (unsigned int i = 0; ihasFinishedRace() && + !m_karts[i]->isEliminated()) + { + checkForWrongDirection(i, dt); + } + } // for i getController()->isLocalPlayerController()) return; - int wrongway_counter = m_karts[i]->getWrongwayCounter(); + float wrongway_timer = m_karts[i]->getWrongwayTimer(); const AbstractKart *kart=m_karts[i]; // If the kart can go in more than one directions from the current track @@ -875,23 +895,23 @@ void LinearWorld::checkForWrongDirection(unsigned int i, int ticks) kart->getVelocityLC().getY() > 0.0f && !kart->hasFinishedRace()) { - wrongway_counter += ticks; + wrongway_timer += dt; - if (wrongway_counter > stk_config->time2Ticks(2.0f)) - wrongway_counter = stk_config->time2Ticks(2.0f); + if (wrongway_timer > 2.0f) + wrongway_timer = 2.0f; } else { - wrongway_counter -= ticks; + wrongway_timer -= dt; - if (wrongway_counter < 0) - wrongway_counter = 0; + if (wrongway_timer < 0) + wrongway_timer = 0; } if (kart->getKartAnimation()) - wrongway_counter = 0; + wrongway_timer = 0; - if (wrongway_counter > stk_config->time2Ticks(1.0f)) + if (wrongway_timer > 1.0f) { m_race_gui->cleanupMessages(0.0f); m_race_gui->addMessage(_("WRONG WAY!"), kart, @@ -901,7 +921,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, int ticks) /*big font*/ true); } // if angle is too big - m_karts[i]->setWrongwayCounter(wrongway_counter); + m_karts[i]->setWrongwayTimer(wrongway_timer); } // checkForWrongDirection //----------------------------------------------------------------------------- diff --git a/src/modes/linear_world.hpp b/src/modes/linear_world.hpp index eac46cf18..4afecebf1 100644 --- a/src/modes/linear_world.hpp +++ b/src/modes/linear_world.hpp @@ -101,7 +101,7 @@ protected: */ AlignedArray m_kart_info; - virtual void checkForWrongDirection(unsigned int i, int ticks); + virtual void checkForWrongDirection(unsigned int i, float dt); void updateRacePosition(); virtual float estimateFinishTimeForKart(AbstractKart* kart) OVERRIDE; @@ -114,6 +114,7 @@ public: virtual ~LinearWorld(); virtual void update(int ticks) OVERRIDE; + virtual void updateGraphics(float dt) OVERRIDE; float getDistanceDownTrackForKart(const int kart_id) const; float getDistanceToCenterForKart(const int kart_id) const; float getEstimatedFinishTime(const int kart_id) const;