diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index 25eea629e..321b39559 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -39,10 +39,11 @@ TrackSector::TrackSector() // ---------------------------------------------------------------------------- void TrackSector::reset() { - m_current_graph_node = Graph::UNKNOWN_SECTOR; - m_last_valid_graph_node = Graph::UNKNOWN_SECTOR; - m_on_road = false; - m_last_triggered_checkline = -1; + m_current_graph_node = Graph::UNKNOWN_SECTOR; + m_last_valid_graph_node = Graph::UNKNOWN_SECTOR; + m_estimated_valid_graph_node = Graph::UNKNOWN_SECTOR; + m_on_road = false; + m_last_triggered_checkline = -1; } // reset // ---------------------------------------------------------------------------- @@ -84,12 +85,15 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) } // keep the current quad as the latest valid one IF the player has one - // of the required checklines + // of the required checklines AND is on road + // The on-road condition isn't required for the estimated valid node + // used for distances. const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node); const std::vector& checkline_requirements = dn->getChecklineRequirements(); if (checkline_requirements.size() == 0) { + m_estimated_valid_graph_node = m_current_graph_node; if (m_on_road) m_last_valid_graph_node = m_current_graph_node; } @@ -97,16 +101,17 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) { for (unsigned int i=0; i= checkline_requirements[i]) { //has_prerequisite = true; + m_estimated_valid_graph_node = m_current_graph_node; if (m_on_road) m_last_valid_graph_node = m_current_graph_node; break; } } - // TODO: show a message when we detect a user cheated. + // TODO: show a message when we detect a user missed a checkline. } @@ -120,6 +125,12 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) DriveGraph::get()->spatialToTrack(&m_latest_valid_track_coords, xyz, m_last_valid_graph_node); } + + if (m_estimated_valid_graph_node != Graph::UNKNOWN_SECTOR) + { + DriveGraph::get()->spatialToTrack(&m_estimated_valid_track_coords, xyz, + m_estimated_valid_graph_node); + } } // update // ---------------------------------------------------------------------------- @@ -139,6 +150,7 @@ void TrackSector::rescue() ->getPredecessor(0); m_last_valid_graph_node = DriveGraph::get()->getNode(m_current_graph_node) ->getPredecessor(0); + m_estimated_valid_graph_node = m_current_graph_node; } // rescue // ---------------------------------------------------------------------------- diff --git a/src/tracks/track_sector.hpp b/src/tracks/track_sector.hpp index 71d1434c2..c22747724 100644 --- a/src/tracks/track_sector.hpp +++ b/src/tracks/track_sector.hpp @@ -41,7 +41,10 @@ private: /** The graph node the object is on. */ int m_current_graph_node; - /** The index of the last valid graph node. */ + /** The index of the estimated valid graph node. Used for distance. */ + int m_estimated_valid_graph_node; + + /** The index of the last valid graph node. Used for rescue */ int m_last_valid_graph_node; /** The coordinates of this object on the track, i.e. how far from @@ -49,6 +52,8 @@ private: * of the center driveline. */ Vec3 m_current_track_coords; + Vec3 m_estimated_valid_track_coords; + Vec3 m_latest_valid_track_coords; /** True if the object is on the road (driveline), or not. */ @@ -64,10 +69,12 @@ public: float getRelativeDistanceToCenter() const; // ------------------------------------------------------------------------ /** Returns how far the the object is from the start line. */ - float getDistanceFromStart(bool account_for_checklines) const + float getDistanceFromStart(bool account_for_checklines, bool strict=false) const { - if (account_for_checklines) + if (account_for_checklines && strict) return m_latest_valid_track_coords.getZ(); + else if (account_for_checklines) + return m_estimated_valid_track_coords.getZ(); else return m_current_track_coords.getZ(); }