From 04b6f67573eb067ba538d97cb5dde7ef939daf76 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sat, 31 Mar 2018 19:42:08 -0400 Subject: [PATCH 1/5] FIx #3167 attempt --- src/tracks/track_sector.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index d42e82d89..b29bf30b1 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -66,6 +66,8 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) m_on_road ? test_nodes : NULL, ignore_vertical); m_on_road = m_current_graph_node != Graph::UNKNOWN_SECTOR; + bool isValidQuad = true; + // If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of // the road, so we have to use search for the closest graph node. if(m_current_graph_node == Graph::UNKNOWN_SECTOR) @@ -90,6 +92,7 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) else { //bool has_prerequisite = false; + isValidQuad = false; for (unsigned int i=0; ispatialToTrack(&m_current_track_coords, xyz, - m_current_graph_node); + if (isValidQuad || 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, + m_last_valid_graph_node); + } } // update // ---------------------------------------------------------------------------- From 19338482a80a378848aff77023d03a2d5a9c965b Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sat, 31 Mar 2018 20:38:09 -0400 Subject: [PATCH 2/5] Improve 3167 patch --- src/tracks/track_sector.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index b29bf30b1..36e640185 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -74,6 +74,8 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) { m_current_graph_node = Graph::get()->findOutOfRoadSector(xyz, prev_sector, test_nodes, ignore_vertical); + isValidQuad = false; + // ArenaGraph (battle and soccer mode) doesn't need the code below if (ag) return; } From 9fe4e2c30e61b8ebc09309195db1c32cb784f65c Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sat, 31 Mar 2018 20:49:45 -0400 Subject: [PATCH 3/5] Improve 3167 patch --- src/tracks/track_sector.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index 36e640185..a00aec681 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -74,7 +74,23 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) { m_current_graph_node = Graph::get()->findOutOfRoadSector(xyz, prev_sector, test_nodes, ignore_vertical); + + // keep the current quad as the latest valid one IF the player has one + // of the required checklines + const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node); + const std::vector& checkline_requirements = dn->getChecklineRequirements(); + isValidQuad = false; + for (unsigned int i = 0; i Date: Sat, 31 Mar 2018 21:03:56 -0400 Subject: [PATCH 4/5] Improve 3167 patch --- src/tracks/track_sector.cpp | 65 +++++++++++++------------------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/src/tracks/track_sector.cpp b/src/tracks/track_sector.cpp index a00aec681..acd38ce19 100644 --- a/src/tracks/track_sector.cpp +++ b/src/tracks/track_sector.cpp @@ -66,66 +66,45 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical) m_on_road ? test_nodes : NULL, ignore_vertical); m_on_road = m_current_graph_node != Graph::UNKNOWN_SECTOR; - bool isValidQuad = true; - // If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of // the road, so we have to use search for the closest graph node. - if(m_current_graph_node == Graph::UNKNOWN_SECTOR) + if (m_current_graph_node == Graph::UNKNOWN_SECTOR) { m_current_graph_node = Graph::get()->findOutOfRoadSector(xyz, prev_sector, test_nodes, ignore_vertical); + } - // keep the current quad as the latest valid one IF the player has one - // of the required checklines - const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node); - const std::vector& checkline_requirements = dn->getChecklineRequirements(); + // ArenaGraph (battle and soccer mode) doesn't need the code below + if (ag) return; - isValidQuad = false; - for (unsigned int i = 0; igetNode(m_current_graph_node); + const std::vector& checkline_requirements = dn->getChecklineRequirements(); + + bool isValidQuad = false; + if (checkline_requirements.size() == 0) + { + isValidQuad = true; + if (m_on_road) + m_last_valid_graph_node = m_current_graph_node; + } + else + { + for (unsigned int i=0; igetNode(m_current_graph_node); - const std::vector& checkline_requirements = dn->getChecklineRequirements(); + // TODO: show a message when we detect a user cheated. - if (checkline_requirements.size() == 0) - { - m_last_valid_graph_node = m_current_graph_node; - } - else - { - //bool has_prerequisite = false; - isValidQuad = false; - - for (unsigned int i=0; i Date: Sun, 8 Apr 2018 20:47:24 -0400 Subject: [PATCH 5/5] 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(); }