From 7a7a9c3146a87211f4d773e22d6906d0ede0bfd1 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 6 Jul 2023 14:00:48 +0300 Subject: [PATCH] fix: nav: overlap between occupied node check and player avoid distance fix: bot: debug overlay flickering in some situations --- inc/yapb.h | 1 + src/botlib.cpp | 18 ++++++++++-------- src/manager.cpp | 1 + src/navigate.cpp | 2 +- src/planner.cpp | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/inc/yapb.h b/inc/yapb.h index b0a42b9..5764d82 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -302,6 +302,7 @@ private: float m_changeViewTime {}; // timestamp to change look at while at freezetime float m_breakableTime {}; // breakable acquired time float m_stuckTimestamp {}; // last time was stuck + float m_timeDebugUpdateTime {}; // time to update last debug timestamp bool m_moveToGoal {}; // bot currently moving to goal?? bool m_isStuck {}; // bot is stuck diff --git a/src/botlib.cpp b/src/botlib.cpp index 4afe732..c62655a 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -3098,7 +3098,6 @@ void Bot::showDebugOverlay () { if (!displayDebugOverlay) { return; } - static float timeDebugUpdate = 0.0f; static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, tid = 0; static HashMap tasks { @@ -3149,8 +3148,9 @@ void Bot::showDebugOverlay () { if (m_tasks.empty ()) { return; } + const auto drawTime = globals->frametime * 500.0f; - if (tid != getCurrentTaskId () || index != m_currentNodeIndex || goal != getTask ()->data || timeDebugUpdate < game.time ()) { + if (tid != getCurrentTaskId () || index != m_currentNodeIndex || goal != getTask ()->data || m_timeDebugUpdateTime < game.time ()) { tid = getCurrentTaskId (); index = m_currentNodeIndex; goal = getTask ()->data; @@ -3198,22 +3198,24 @@ void Bot::showDebugOverlay () { .writeByte (0) .writeShort (MessageWriter::fu16 (0.0f, 8.0f)) .writeShort (MessageWriter::fu16 (0.0f, 8.0f)) - .writeShort (MessageWriter::fu16 (0.15f, 8.0f)) + .writeShort (MessageWriter::fu16 (drawTime, 8.0f)) .writeString (debugData.chars ()); - timeDebugUpdate = game.time () + 0.1f; + m_timeDebugUpdateTime = game.time () + drawTime; } // green = destination origin // blue = ideal angles // red = view angles - game.drawLine (overlayEntity, getEyesPos (), m_destOrigin, 10, 0, { 0, 255, 0 }, 250, 5, 1, DrawLine::Arrow); - game.drawLine (overlayEntity, getEyesPos () - Vector (0.0f, 0.0f, 16.0f), getEyesPos () + m_idealAngles.forward () * 300.0f, 10, 0, { 0, 0, 255 }, 250, 5, 1, DrawLine::Arrow); - game.drawLine (overlayEntity, getEyesPos () - Vector (0.0f, 0.0f, 32.0f), getEyesPos () + pev->v_angle.forward () * 300.0f, 10, 0, { 255, 0, 0 }, 250, 5, 1, DrawLine::Arrow); + const auto lifeTime = 1; + + game.drawLine (overlayEntity, getEyesPos (), m_destOrigin, 10, 0, { 0, 255, 0 }, 250, 5, lifeTime, DrawLine::Arrow); + game.drawLine (overlayEntity, getEyesPos () - Vector (0.0f, 0.0f, 16.0f), getEyesPos () + m_idealAngles.forward () * 300.0f, 10, 0, { 0, 0, 255 }, 250, 5, lifeTime, DrawLine::Arrow); + game.drawLine (overlayEntity, getEyesPos () - Vector (0.0f, 0.0f, 32.0f), getEyesPos () + pev->v_angle.forward () * 300.0f, 10, 0, { 255, 0, 0 }, 250, 5, lifeTime, DrawLine::Arrow); // now draw line from source to destination for (size_t i = 0; i < m_pathWalk.length () && i + 1 < m_pathWalk.length (); ++i) { - game.drawLine (overlayEntity, graph[m_pathWalk.at (i)].origin, graph[m_pathWalk.at (i + 1)].origin, 15, 0, { 255, 100, 55 }, 200, 5, 1, DrawLine::Arrow); + game.drawLine (overlayEntity, graph[m_pathWalk.at (i)].origin, graph[m_pathWalk.at (i + 1)].origin, 15, 0, { 255, 100, 55 }, 200, 5, lifeTime, DrawLine::Arrow); } } diff --git a/src/manager.cpp b/src/manager.cpp index 7919b37..5d7db4d 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1325,6 +1325,7 @@ void Bot::newRound () { m_defuseNotified = false; m_duckDefuse = false; m_duckDefuseCheckTime = 0.0f; + m_timeDebugUpdateTime = 0.0f; m_numFriendsLeft = 0; m_numEnemiesLeft = 0; diff --git a/src/navigate.cpp b/src/navigate.cpp index 4f869c4..35d4da7 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -3044,7 +3044,7 @@ bool Bot::isOccupiedNode (int index, bool needZeroVelocity) { } const auto length = client.origin.distanceSq (graph[index].origin); - if (length < cr::clamp (cr::sqrf (graph[index].radius) * 2.0f, cr::sqrf (40.0f), cr::sqrf (90.0f))) { + if (length < cr::clamp (cr::sqrf (graph[index].radius) * 2.0f, cr::sqrf (90.0f), cr::sqrf (120.0f))) { return true; } auto bot = bots[client.ent]; diff --git a/src/planner.cpp b/src/planner.cpp index 0d8643f..e4f24de 100644 --- a/src/planner.cpp +++ b/src/planner.cpp @@ -252,7 +252,7 @@ AStarResult AStarAlgo::find (int botTeam, int srcIndex, int destIndex, NodeAdder m_routeQue.clear (); m_routeQue.emplace (srcIndex, srcRoute->g); - bool postSmoothPath = cv_path_astar_post_smooth.bool_ () && vistab.isReady (); + const bool postSmoothPath = cv_path_astar_post_smooth.bool_ () && vistab.isReady (); // always clear constructed path m_constructedPath.clear ();