mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-02 23:07:36 +02:00
Code cleanup
This commit is contained in:
parent
a31788b874
commit
0200e871c3
@ -32,6 +32,8 @@
|
||||
#include "AIGateway.h"
|
||||
#include "Goals/Goals.h"
|
||||
|
||||
static tbb::task_arena executeActionAsyncArena;
|
||||
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
@ -596,7 +598,7 @@ void AIGateway::yourTurn(QueryID queryID)
|
||||
ScopedThreadName guard("NKAI::makingTurn");
|
||||
makeTurn();
|
||||
});
|
||||
tbb::this_task_arena::enqueue([this](){asyncTasks->wait();});
|
||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
||||
}
|
||||
|
||||
void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
||||
@ -876,7 +878,7 @@ void AIGateway::makeTurn()
|
||||
}
|
||||
#if NKAI_TRACE_LEVEL == 0
|
||||
}
|
||||
catch (const TerminationRequestedException & e)
|
||||
catch (const TerminationRequestedException &)
|
||||
{
|
||||
logAi->debug("Making turn thread has been interrupted. We'll end without calling endTurn.");
|
||||
return;
|
||||
@ -891,7 +893,7 @@ void AIGateway::makeTurn()
|
||||
{
|
||||
endTurn();
|
||||
}
|
||||
catch (const TerminationRequestedException & e)
|
||||
catch (const TerminationRequestedException &)
|
||||
{
|
||||
logAi->debug("Making turn thread has been interrupted. We'll end without calling endTurn.");
|
||||
return;
|
||||
@ -1614,7 +1616,7 @@ void AIGateway::executeActionAsync(const std::string & description, const std::f
|
||||
std::shared_lock gsLock(CGameState::mutex);
|
||||
whatToDo();
|
||||
});
|
||||
tbb::this_task_arena::enqueue([this](){asyncTasks->wait();});
|
||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
||||
}
|
||||
|
||||
void AIGateway::lostHero(HeroPtr h)
|
||||
|
@ -37,6 +37,8 @@
|
||||
|
||||
#include "AIhelper.h"
|
||||
|
||||
static tbb::task_arena executeActionAsyncArena;
|
||||
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
const double SAFE_ATTACK_CONSTANT = 1.5;
|
||||
@ -470,7 +472,7 @@ void VCAI::showHillFortWindow(const CGObjectInstance * object, const CGHeroInsta
|
||||
LOG_TRACE(logAi);
|
||||
NET_EVENT_HANDLER;
|
||||
|
||||
executeActionAsync("showHillFortWindow", [=]()
|
||||
executeActionAsync("showHillFortWindow", [visitor]()
|
||||
{
|
||||
makePossibleUpgrades(visitor);
|
||||
});
|
||||
@ -656,7 +658,7 @@ void VCAI::yourTurn(QueryID queryID)
|
||||
ScopedThreadName guard("VCAI::makingTurn");
|
||||
makeTurn();
|
||||
});
|
||||
tbb::this_task_arena::enqueue([this](){asyncTasks->wait();});
|
||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
||||
}
|
||||
|
||||
void VCAI::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
||||
@ -853,7 +855,7 @@ void VCAI::makeTurn()
|
||||
logAi->info("Hero %s has %d MP left", h->getNameTranslated(), h->movementPointsRemaining());
|
||||
}
|
||||
}
|
||||
catch (const TerminationRequestedException & e)
|
||||
catch (const TerminationRequestedException &)
|
||||
{
|
||||
logAi->debug("Making turn thread has been interrupted. We'll end without calling endTurn.");
|
||||
return;
|
||||
@ -1009,7 +1011,7 @@ void VCAI::mainLoop()
|
||||
goalToRealize->accept(this); //visitor pattern
|
||||
makingTurnInterrupption.interruptionPoint();
|
||||
}
|
||||
catch (const TerminationRequestedException & e)
|
||||
catch (const TerminationRequestedException &)
|
||||
{
|
||||
logAi->debug("Player %d: Making turn thread received an interruption!", playerID);
|
||||
throw; //rethrow, we want to truly end this thread
|
||||
@ -2374,7 +2376,7 @@ void VCAI::striveToGoal(Goals::TSubgoal basicGoal)
|
||||
elementarGoal->accept(this); //visitor pattern
|
||||
makingTurnInterrupption.interruptionPoint();
|
||||
}
|
||||
catch (const TerminationRequestedException & e)
|
||||
catch (const TerminationRequestedException &)
|
||||
{
|
||||
logAi->debug("Player %d: Making turn thread received an interruption!", playerID);
|
||||
throw; //rethrow, we want to truly end this thread
|
||||
@ -2506,6 +2508,8 @@ void VCAI::finish()
|
||||
|
||||
void VCAI::executeActionAsync(const std::string & description, const std::function<void()> & whatToDo)
|
||||
{
|
||||
|
||||
|
||||
if (!asyncTasks)
|
||||
throw std::runtime_error("Attempt to execute task on shut down AI state!");
|
||||
|
||||
@ -2516,7 +2520,7 @@ void VCAI::executeActionAsync(const std::string & description, const std::functi
|
||||
std::shared_lock gsLock(CGameState::mutex);
|
||||
whatToDo();
|
||||
});
|
||||
tbb::this_task_arena::enqueue([this](){asyncTasks->wait();});
|
||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
||||
}
|
||||
|
||||
void VCAI::lostHero(HeroPtr h)
|
||||
|
@ -256,6 +256,8 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
|
||||
|
||||
SDLImageShared::SDLImageShared(const SDLImageShared * from, int integerScaleFactor, EScalingAlgorithm algorithm)
|
||||
{
|
||||
static tbb::task_arena upscalingArena;
|
||||
|
||||
upscalingInProgress = true;
|
||||
|
||||
auto scaler = std::make_shared<SDLImageScaler>(from->surf, Rect(from->margins, from->fullSize), true);
|
||||
@ -271,7 +273,7 @@ SDLImageShared::SDLImageShared(const SDLImageShared * from, int integerScaleFact
|
||||
};
|
||||
|
||||
if(settings["video"]["asyncUpscaling"].Bool())
|
||||
tbb::this_task_arena::enqueue(scalingTask);
|
||||
upscalingArena.enqueue(scalingTask);
|
||||
else
|
||||
scalingTask();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user