From 61469a6806e907937cabf1588b5c254b2063e134 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sun, 8 Apr 2018 20:47:24 -0400 Subject: [PATCH] Mitigate AI-related edge cases of original fx --- src/items/rubber_ball.cpp | 4 ++-- src/main_loop.cpp | 2 +- src/modes/linear_world.cpp | 10 +++++----- src/modes/linear_world.hpp | 2 +- src/states_screens/race_gui_base.cpp | 2 +- src/tracks/check_lap.cpp | 2 +- src/tracks/track_sector.cpp | 12 +++++------- src/tracks/track_sector.hpp | 10 +++++++++- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index 11a51f1a4..fac76ff4b 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -636,8 +636,8 @@ void RubberBall::updateDistanceToTarget() const LinearWorld *world = dynamic_cast(World::getWorld()); float target_distance = - world->getDistanceDownTrackForKart(m_target->getWorldKartId()); - float ball_distance = getDistanceFromStart(); + world->getDistanceDownTrackForKart(m_target->getWorldKartId(), true); + float ball_distance = getDistanceFromStart(true); m_distance_to_target = target_distance - ball_distance; if(m_distance_to_target < 0) diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 51e40d3c0..894e29449 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -94,7 +94,7 @@ float MainLoop::getLimitedDt() { Log::verbose("fps", "time %f distance %f dt %f fps %f", lw->getTime(), - lw->getDistanceDownTrackForKart(0), + lw->getDistanceDownTrackForKart(0, true), dt*0.001f, 1000.0f / dt); } else diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 54d073148..f2ed16f7b 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -108,7 +108,7 @@ void LinearWorld::reset() for(unsigned int i=0; iupdate(kart->getFrontXYZ()); kart_info.m_overall_distance = kart_info.m_race_lap * Track::getCurrentTrack()->getTrackLength() - + getDistanceDownTrackForKart(kart->getWorldKartId()); + + getDistanceDownTrackForKart(kart->getWorldKartId(), true); } // for n // Update all positions. This must be done after _all_ karts have @@ -281,7 +281,7 @@ void LinearWorld::newLap(unsigned int kart_index) m_kart_info[kart_index].m_overall_distance = m_kart_info[kart_index].m_race_lap * Track::getCurrentTrack()->getTrackLength() - + getDistanceDownTrackForKart(kart->getWorldKartId()); + + getDistanceDownTrackForKart(kart->getWorldKartId(), true); } // Last lap message (kart_index's assert in previous block already) if (raceHasLaps() && kart_info.m_race_lap+1 == lap_count) @@ -390,9 +390,9 @@ void LinearWorld::newLap(unsigned int kart_index) * crossing the start line.. * \param kart_id Index of the kart. */ -float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const +float LinearWorld::getDistanceDownTrackForKart(const int kart_id, bool account_for_checklines) const { - return getTrackSector(kart_id)->getDistanceFromStart(); + return getTrackSector(kart_id)->getDistanceFromStart(account_for_checklines); } // getDistanceDownTrackForKart //----------------------------------------------------------------------------- diff --git a/src/modes/linear_world.hpp b/src/modes/linear_world.hpp index 7b3e4e987..6addd0675 100644 --- a/src/modes/linear_world.hpp +++ b/src/modes/linear_world.hpp @@ -114,7 +114,7 @@ public: virtual ~LinearWorld(); virtual void update(float delta) OVERRIDE; - float getDistanceDownTrackForKart(const int kart_id) const; + float getDistanceDownTrackForKart(const int kart_id, bool account_for_checklines) const; float getDistanceToCenterForKart(const int kart_id) const; float getEstimatedFinishTime(const int kart_id) const; int getLapForKart(const int kart_id) const; diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index 92d393f1c..9343ab781 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -770,7 +770,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin) { LinearWorld *linear_world = (LinearWorld*)(World::getWorld()); - float distance = linear_world->getDistanceDownTrackForKart(kart_id) + float distance = linear_world->getDistanceDownTrackForKart(kart_id, true) + Track::getCurrentTrack()->getTrackLength()*lap; if ((position>1) && (previous_distance-distancegetDistanceDownTrackForKart(kart_index); + float current_distance = lin_world->getDistanceDownTrackForKart(kart_index, false); bool result = (m_previous_distance[kart_index]>0.95f*track_length && current_distance<7.0f); diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index acd38ce19..b57fe5fb5 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -109,14 +109,12 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) // Now determine the 'track' coords, i.e. ow far from the start of the // track, and how far to the left or right of the center driveline. - if (isValidQuad || m_last_valid_graph_node == Graph::UNKNOWN_SECTOR) + DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz, + m_current_graph_node); + + if (m_last_valid_graph_node != Graph::UNKNOWN_SECTOR) { - DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz, - m_current_graph_node); - } - else - { - DriveGraph::get()->spatialToTrack(&m_current_track_coords, xyz, + DriveGraph::get()->spatialToTrack(&m_latest_valid_track_coords, xyz, m_last_valid_graph_node); } } // update diff --git a/src/tracks/track_sector.hpp b/src/tracks/track_sector.hpp index f10716dd0..08e60ef32 100644 --- a/src/tracks/track_sector.hpp +++ b/src/tracks/track_sector.hpp @@ -48,6 +48,8 @@ private: * of the center driveline. */ Vec3 m_current_track_coords; + Vec3 m_latest_valid_track_coords; + /** True if the object is on the road (driveline), or not. */ bool m_on_road; @@ -61,7 +63,13 @@ public: float getRelativeDistanceToCenter() const; // ------------------------------------------------------------------------ /** Returns how far the the object is from the start line. */ - float getDistanceFromStart() const { return m_current_track_coords.getZ();} + float getDistanceFromStart(bool account_for_checklines) const + { + if (account_for_checklines) + return m_latest_valid_track_coords.getZ(); + else + return m_current_track_coords.getZ(); + } // ------------------------------------------------------------------------ /** Returns the distance to the centre driveline. */ float getDistanceToCenter() const { return m_current_track_coords.getX(); }