Skip to content

Commit

Permalink
Fixed crash sometimes occurring while zbot map analyzing (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq authored Sep 5, 2023
1 parent facc2be commit e8bff71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
4 changes: 0 additions & 4 deletions regamedll/dlls/bot/cs_bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ enum
BOT_PROGGRESS_HIDE, // hide status bar progress
};

extern int _navAreaCount;
extern int _currentIndex;

class CCSBot;
class BotChatterInterface;

Expand Down Expand Up @@ -970,7 +967,6 @@ class CCSBot: public CBot
const CNavNode *m_navNodeList;
CNavNode *m_currentNode;
NavDirType m_generationDir;
NavAreaList::iterator m_analyzeIter;

enum ProcessType
{
Expand Down
46 changes: 23 additions & 23 deletions regamedll/dlls/bot/cs_bot_learn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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");
}

Expand Down

0 comments on commit e8bff71

Please sign in to comment.