fix: crash on predicted node index use after wiped

refactor: reworked prediction to calc prediction for all bots at one job, instead of firing it for every bot
This commit is contained in:
jeefo 2023-06-29 20:17:46 +03:00
commit 93d9187f6d
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
12 changed files with 205 additions and 182 deletions

View file

@ -1623,17 +1623,12 @@ void Bot::overrideConditions () {
}
}
void Bot::syncUpdatePredictedIndex () {
void Bot::updatePredictedIndex () {
auto wipePredict = [this] () {
m_lastPredictIndex = kInvalidNodeIndex;
m_lastPredictLength = kInfiniteDistanceLong;
};
if (!m_predictLock.tryLock ()) {
return; // allow only single instance of search per-bot
}
ScopedUnlock <Mutex> unlock (m_predictLock);
const auto lastEnemyOrigin = m_lastEnemyOrigin;
const auto currentNodeIndex = m_currentNodeIndex;
const auto &botOrigin = pev->origin;
@ -1671,15 +1666,6 @@ void Bot::syncUpdatePredictedIndex () {
wipePredict ();
}
void Bot::updatePredictedIndex () {
if (m_lastEnemyOrigin.empty ()) {
return; // do not run task if no last enemy
}
worker.enqueue ([this] () {
syncUpdatePredictedIndex ();
});
}
void Bot::refreshEnemyPredict () {
if (game.isNullEntity (m_enemy) && !game.isNullEntity (m_lastEnemy) && !m_lastEnemyOrigin.empty ()) {
const auto distanceToLastEnemySq = m_lastEnemyOrigin.distanceSq (pev->origin);
@ -1693,10 +1679,6 @@ void Bot::refreshEnemyPredict () {
m_aimFlags |= AimFlags::LastEnemy;
}
}
if (m_aimFlags & AimFlags::PredictPath) {
updatePredictedIndex ();
}
}
void Bot::setConditions () {