diff --git a/src/karts/ghost_kart.cpp b/src/karts/ghost_kart.cpp index 99f92a55e..e58225c62 100644 --- a/src/karts/ghost_kart.cpp +++ b/src/karts/ghost_kart.cpp @@ -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 // ---------------------------------------------------------------------------- @@ -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. diff --git a/src/karts/ghost_kart.hpp b/src/karts/ghost_kart.hpp index 4f580252a..34afb2df7 100644 --- a/src/karts/ghost_kart.hpp +++ b/src/karts/ghost_kart.hpp @@ -50,6 +50,8 @@ private: unsigned int m_last_egg_idx; + bool m_finish_computed; + // ---------------------------------------------------------------------------- /** Compute the time at which the ghost finished the race */ void computeFinishTime(); @@ -84,11 +86,9 @@ public: // ------------------------------------------------------------------------ /** 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 */