Fixed crash sometimes occurring while zbot map analyzing (#844)

This commit is contained in:
Dmitry Novikov 2023-09-05 10:53:05 +07:00 committed by GitHub
parent facc2be534
commit e8bff71475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 27 deletions

View File

@ -42,9 +42,6 @@ enum
BOT_PROGGRESS_HIDE, // hide status bar progress
};
extern int _navAreaCount;
extern int _currentIndex;
class CCSBot;
class BotChatterInterface;
@ -970,7 +967,6 @@ private:
const CNavNode *m_navNodeList;
CNavNode *m_currentNode;
NavDirType m_generationDir;
NavAreaList::iterator m_analyzeIter;
enum ProcessType
{

View File

@ -30,8 +30,7 @@
const float updateTimesliceDuration = 0.5f;
int _navAreaCount = 0;
int _currentIndex = 0;
unsigned int _generationIndex = 0; // used for iterating nav areas during generation process
inline CNavNode *LadderEndSearch(CBaseEntity *pEntity, const Vector *pos, NavDirType mountDir)
{
@ -385,11 +384,8 @@ void CCSBot::UpdateLearnProcess()
void CCSBot::StartAnalyzeAlphaProcess()
{
m_processMode = PROCESS_ANALYZE_ALPHA;
m_analyzeIter = TheNavAreaList.begin();
_navAreaCount = TheNavAreaList.size();
_currentIndex = 0;
m_processMode = PROCESS_ANALYZE_ALPHA;
_generationIndex = 0;
ApproachAreaAnalysisPrep();
DestroyHidingSpots();
@ -400,15 +396,18 @@ void CCSBot::StartAnalyzeAlphaProcess()
bool CCSBot::AnalyzeAlphaStep()
{
_currentIndex++;
if (m_analyzeIter == TheNavAreaList.end())
_generationIndex++;
if (_generationIndex < 0 || _generationIndex >= TheNavAreaList.size())
return false;
CNavArea *area = (*m_analyzeIter);
// TODO: Pretty ugly and very slow way to access element by index
// There is no reason not to use a vector instead of a linked list
const NavAreaList::const_iterator &iter = std::next(TheNavAreaList.begin(), _generationIndex - 1);
CNavArea *area = (*iter);
area->ComputeHidingSpots();
area->ComputeApproachAreas();
m_analyzeIter++;
return true;
}
@ -426,29 +425,30 @@ void CCSBot::UpdateAnalyzeAlphaProcess()
}
}
float progress = (double(_currentIndex) / double(_navAreaCount)) * 0.5f;
float progress = (double(_generationIndex) / double(TheNavAreaList.size())) * 0.5f;
drawProgressMeter(progress, "#CZero_AnalyzingHidingSpots");
}
void CCSBot::StartAnalyzeBetaProcess()
{
m_processMode = PROCESS_ANALYZE_BETA;
m_analyzeIter = TheNavAreaList.begin();
_navAreaCount = TheNavAreaList.size();
_currentIndex = 0;
m_processMode = PROCESS_ANALYZE_BETA;
_generationIndex = 0;
}
bool CCSBot::AnalyzeBetaStep()
{
_currentIndex++;
if (m_analyzeIter == TheNavAreaList.end())
_generationIndex++;
if (_generationIndex < 0 || _generationIndex >= TheNavAreaList.size())
return false;
CNavArea *area = (*m_analyzeIter);
// TODO: Pretty ugly and very slow way to access element by index
// There is no reason not to use a vector instead of a linked list
const NavAreaList::const_iterator &iter = std::next(TheNavAreaList.begin(), _generationIndex - 1);
CNavArea *area = (*iter);
area->ComputeSpotEncounters();
area->ComputeSniperSpots();
m_analyzeIter++;
return true;
}
@ -466,7 +466,7 @@ void CCSBot::UpdateAnalyzeBetaProcess()
}
}
float progress = (double(_currentIndex) / double(_navAreaCount) + 1.0f) * 0.5f;
float progress = (double(_generationIndex) / double(TheNavAreaList.size()) + 1.0f) * 0.5f;
drawProgressMeter(progress, "#CZero_AnalyzingApproachPoints");
}