fix: nav: overlap between occupied node check and player avoid distance

fix: bot: debug overlay flickering in some situations
This commit is contained in:
jeefo 2023-07-06 14:00:48 +03:00
commit 7a7a9c3146
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
5 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -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 <int32_t, StringRef> 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);
}
}

View file

@ -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;

View file

@ -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];

View file

@ -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 ();