Skip to content

Commit

Permalink
Fix #4965
Browse files Browse the repository at this point in the history
  • Loading branch information
Alayan-stk-2 committed Dec 14, 2023
1 parent 6d38bfe commit f8db600
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/karts/ghost_kart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GhostKart::GhostKart(const std::string& ident, unsigned int world_kart_id,
m_replay_data(rd), m_last_egg_idx(0)
{
m_graphical_y_offset = 0;
m_finish_computed = false;
} // GhostKart

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -271,7 +272,18 @@ void GhostKart::computeFinishTime()
* Track::getCurrentTrack()->getTrackLength();
m_finish_time = getTimeForDistance(full_distance);
}
}
m_finish_computed = true;
} // computeFinishTime

// ------------------------------------------------------------------------
/** Returns the finish time for a ghost kart. */
float GhostKart::getGhostFinishTime()
{
if (!m_finish_computed)
computeFinishTime();

return m_finish_time;
} // getGhostFinishTime

// ----------------------------------------------------------------------------
/** Returns the time at which the kart was at a given distance.
Expand Down
6 changes: 3 additions & 3 deletions src/karts/ghost_kart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GhostKart : public Kart

unsigned int m_last_egg_idx;

bool m_finish_computed;

// ----------------------------------------------------------------------------
/** Compute the time at which the ghost finished the race */
void computeFinishTime();
Expand Down Expand Up @@ -84,11 +86,9 @@ class GhostKart : public Kart
// ------------------------------------------------------------------------
/** Returns the speed of the kart in meters/second. */
virtual float getSpeed() const OVERRIDE;

// ------------------------------------------------------------------------
/** Returns the finished time for a ghost kart. */
float getGhostFinishTime() { computeFinishTime(); return m_finish_time; }

float getGhostFinishTime();
// ------------------------------------------------------------------------
/** Returns the time at which the kart was at a given distance.
* Returns -1.0f if none */
Expand Down

0 comments on commit f8db600

Please sign in to comment.