mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fix autocombat AI threading
This commit is contained in:
@@ -786,6 +786,9 @@ void CPlayerInterface::activeStack(const CStack * stack) //called when it's turn
|
|||||||
{
|
{
|
||||||
if (isAutoFightOn)
|
if (isAutoFightOn)
|
||||||
{
|
{
|
||||||
|
//FIXME: we want client rendering to proceed while AI is making actions
|
||||||
|
// so unlock mutex while AI is busy since this might take quite a while, especially if hero has many spells
|
||||||
|
auto unlockPim = vstd::makeUnlockGuard(*pim);
|
||||||
autofightingAI->activeStack(stack);
|
autofightingAI->activeStack(stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -701,8 +701,6 @@ void BattleInterface::requestAutofightingAIToTakeAction()
|
|||||||
{
|
{
|
||||||
assert(curInt->isAutoFightOn);
|
assert(curInt->isAutoFightOn);
|
||||||
|
|
||||||
boost::thread aiThread([&]()
|
|
||||||
{
|
|
||||||
if(curInt->cb->battleIsFinished())
|
if(curInt->cb->battleIsFinished())
|
||||||
{
|
{
|
||||||
return; // battle finished with spellcast
|
return; // battle finished with spellcast
|
||||||
@@ -723,13 +721,19 @@ void BattleInterface::requestAutofightingAIToTakeAction()
|
|||||||
|
|
||||||
// If enemy is moving, activeStack can be null
|
// If enemy is moving, activeStack can be null
|
||||||
if (activeStack)
|
if (activeStack)
|
||||||
curInt->autofightingAI->activeStack(activeStack);
|
{
|
||||||
|
|
||||||
stacksController->setActiveStack(nullptr);
|
stacksController->setActiveStack(nullptr);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// FIXME: unsafe
|
||||||
|
// Run task in separate thread to avoid UI lock while AI is making turn (which might take some time)
|
||||||
|
// HOWEVER this thread won't atttempt to lock game state, potentially leading to races
|
||||||
|
boost::thread aiThread([&]()
|
||||||
|
{
|
||||||
|
curInt->autofightingAI->activeStack(activeStack);
|
||||||
|
});
|
||||||
aiThread.detach();
|
aiThread.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleInterface::castThisSpell(SpellID spellID)
|
void BattleInterface::castThisSpell(SpellID spellID)
|
||||||
|
Reference in New Issue
Block a user