Properly fix #3159 (Wrong direction text is displayed twice).

When this is merged with master, the current work around
in #3159 can be reverted.
This commit is contained in:
hiker 2018-03-30 22:46:32 +11:00 committed by Benau
parent da7780a9e1
commit 99d8ad8ac1
7 changed files with 53 additions and 31 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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; }

View File

@ -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

View File

@ -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

View File

@ -96,7 +96,7 @@ void LinearWorld::reset()
for(unsigned int i=0; i<kart_amount; i++)
{
m_kart_info[i].reset();
m_karts[i]->setWrongwayCounter(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; i<kart_amount; i++)
{
// ---------- update rank ------
if (!m_karts[i]->hasFinishedRace() &&
!m_karts[i]->isEliminated())
{
checkForWrongDirection(i, dt);
}
} // for i <kart_amount
} // updateGraphics
//-----------------------------------------------------------------------------
/** Is called by check structures if a kart starts a new lap.
* \param kart_index Index of the kart.
@ -841,13 +860,14 @@ void LinearWorld::updateRacePosition()
/** Checks if a kart is going in the wrong direction. This is done only for
* player karts to display a message to the player.
* \param i Kart id.
* \param dt Time step size.
*/
void LinearWorld::checkForWrongDirection(unsigned int i, int ticks)
void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
{
if (!m_karts[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
//-----------------------------------------------------------------------------

View File

@ -101,7 +101,7 @@ protected:
*/
AlignedArray<KartInfo> 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;