mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Replaced boost::thread_specific_ptr with thread_local
This commit is contained in:
parent
142889e3a5
commit
87957e74c1
@ -34,26 +34,26 @@ const float RETREAT_THRESHOLD = 0.3f;
|
||||
const double RETREAT_ABSOLUTE_THRESHOLD = 10000.;
|
||||
|
||||
//one thread may be turn of AI and another will be handling a side effect for AI2
|
||||
boost::thread_specific_ptr<CCallback> cb;
|
||||
boost::thread_specific_ptr<AIGateway> ai;
|
||||
thread_local CCallback * cb = nullptr;
|
||||
thread_local AIGateway * ai = nullptr;
|
||||
|
||||
//helper RAII to manage global ai/cb ptrs
|
||||
struct SetGlobalState
|
||||
{
|
||||
SetGlobalState(AIGateway * AI)
|
||||
{
|
||||
assert(!ai.get());
|
||||
assert(!cb.get());
|
||||
assert(!ai);
|
||||
assert(!cb);
|
||||
|
||||
ai.reset(AI);
|
||||
cb.reset(AI->myCb.get());
|
||||
ai = AI;
|
||||
cb = AI->myCb.get();
|
||||
}
|
||||
~SetGlobalState()
|
||||
{
|
||||
//TODO: how to handle rm? shouldn't be called after ai is destroyed, hopefully
|
||||
//TODO: to ensure that, make rm unique_ptr
|
||||
ai.release();
|
||||
cb.release();
|
||||
ai = nullptr;
|
||||
cb = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1472,6 +1472,8 @@ void AIGateway::requestActionASAP(std::function<void()> whatToDo)
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||
whatToDo();
|
||||
});
|
||||
|
||||
newThread.detach();
|
||||
}
|
||||
|
||||
void AIGateway::lostHero(HeroPtr h)
|
||||
|
@ -25,10 +25,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
//extern static const int3 dirs[8];
|
||||
|
||||
const CGObjectInstance * ObjectIdRef::operator->() const
|
||||
{
|
||||
return cb->getObj(id, false);
|
||||
|
@ -57,6 +57,7 @@ using dwellingContent = std::pair<ui32, std::vector<CreatureID>>;
|
||||
namespace NKAI
|
||||
{
|
||||
struct creInfo;
|
||||
class AIGateway;
|
||||
class Nullkiller;
|
||||
|
||||
const int GOLD_MINE_PRODUCTION = 1000, WOOD_ORE_MINE_PRODUCTION = 2, RESOURCE_MINE_PRODUCTION = 1;
|
||||
@ -67,7 +68,8 @@ const int ALLOWED_ROAMING_HEROES = 8;
|
||||
extern const float SAFE_ATTACK_CONSTANT;
|
||||
extern const int GOLD_RESERVE;
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern thread_local CCallback * cb;
|
||||
extern thread_local AIGateway * ai;
|
||||
|
||||
enum HeroRole
|
||||
{
|
||||
@ -201,7 +203,7 @@ void foreach_tile_pos(CCallback * cbp, const Func & foo) // avoid costly retriev
|
||||
template<class Func>
|
||||
void foreach_neighbour(const int3 & pos, const Func & foo)
|
||||
{
|
||||
CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer
|
||||
CCallback * cbp = cb; // avoid costly retrieval of thread-specific pointer
|
||||
for(const int3 & dir : int3::getDirs())
|
||||
{
|
||||
const int3 n = pos + dir;
|
||||
|
@ -20,9 +20,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string BuildingBehavior::toString() const
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string BuyArmyBehavior::toString() const
|
||||
|
@ -19,9 +19,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
template <typename T>
|
||||
|
@ -19,9 +19,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string ClusterBehavior::toString() const
|
||||
|
@ -25,9 +25,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
const float TREAT_IGNORE_RATIO = 2;
|
||||
|
||||
using namespace Goals;
|
||||
|
@ -23,9 +23,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string GatherArmyBehavior::toString() const
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string RecruitHeroBehavior::toString() const
|
||||
|
@ -21,9 +21,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string StartupBehavior::toString() const
|
||||
|
@ -24,9 +24,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
void DeepDecomposer::reset()
|
||||
|
@ -20,8 +20,6 @@ namespace NKAI
|
||||
#define MIN_AI_STRENGTH (0.5f) //lower when combat AI gets smarter
|
||||
#define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
|
||||
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
engineBase::engineBase()
|
||||
{
|
||||
rules = new fl::RuleBlock();
|
||||
|
@ -24,9 +24,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
@ -341,7 +338,7 @@ void Nullkiller::executeTask(Goals::TTask task)
|
||||
|
||||
try
|
||||
{
|
||||
task->accept(ai.get());
|
||||
task->accept(ai);
|
||||
logAi->trace("Task %s completed in %lld", taskDescr, timeElapsed(start));
|
||||
}
|
||||
catch(goalFulfilledException &)
|
||||
|
@ -15,9 +15,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
TSubgoal Goals::sptr(const AbstractGoal & tmp)
|
||||
|
@ -14,9 +14,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool AdventureSpellCast::operator==(const AdventureSpellCast & other) const
|
||||
|
@ -15,9 +15,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool BuildBoat::operator==(const BuildBoat & other) const
|
||||
|
@ -17,12 +17,8 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
|
||||
BuildThis::BuildThis(BuildingID Bid, const CGTownInstance * tid)
|
||||
: ElementarGoal(Goals::BUILD_STRUCTURE)
|
||||
{
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool BuyArmy::operator==(const BuyArmy & other) const
|
||||
|
@ -18,8 +18,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool CaptureObject::operator==(const CaptureObject & other) const
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool isKeyMaster(const QuestInfo & q)
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool Composition::operator==(const Composition & other) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool DigAtTile::operator==(const DigAtTile & other) const
|
||||
|
@ -14,9 +14,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool DismissHero::operator==(const DismissHero & other) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
ExchangeSwapTownHeroes::ExchangeSwapTownHeroes(
|
||||
|
@ -15,9 +15,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
ExecuteHeroChain::ExecuteHeroChain(const AIPath & path, const CGObjectInstance * obj)
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
std::string RecruitHero::toString() const
|
||||
|
@ -15,9 +15,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool SaveResources::operator==(const SaveResources & other) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
ArmyUpgrade::ArmyUpgrade(const AIPath & upgradePath, const CGObjectInstance * upgrader, const ArmyUpgradeInfo & upgrade)
|
||||
|
@ -17,9 +17,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool HeroExchange::operator==(const HeroExchange & other) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool UnlockCluster::operator==(const UnlockCluster & other) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
namespace AIPathfinding
|
||||
{
|
||||
void BattleAction::execute(const CGHeroInstance * hero) const
|
||||
|
@ -20,14 +20,11 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
namespace AIPathfinding
|
||||
{
|
||||
void BuildBoatAction::execute(const CGHeroInstance * hero) const
|
||||
{
|
||||
return Goals::BuildBoat(shipyard).accept(ai.get());
|
||||
return Goals::BuildBoat(shipyard).accept(ai);
|
||||
}
|
||||
|
||||
Goals::TSubgoal BuildBoatAction::decompose(const CGHeroInstance * hero) const
|
||||
@ -80,7 +77,7 @@ namespace AIPathfinding
|
||||
|
||||
void SummonBoatAction::execute(const CGHeroInstance * hero) const
|
||||
{
|
||||
Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT).accept(ai.get());
|
||||
Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT).accept(ai);
|
||||
}
|
||||
|
||||
const ChainActor * SummonBoatAction::getActor(const ChainActor * sourceActor) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
namespace AIPathfinding
|
||||
{
|
||||
void BuyArmyAction::execute(const CGHeroInstance * hero) const
|
||||
|
@ -16,9 +16,6 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
namespace AIPathfinding
|
||||
{
|
||||
bool QuestAction::canAct(const AIPathNode * node) const
|
||||
|
@ -18,9 +18,6 @@ namespace NKAI
|
||||
|
||||
using namespace AIPathfinding;
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||
|
||||
void TownPortalAction::execute(const CGHeroInstance * hero) const
|
||||
{
|
||||
auto goal = Goals::AdventureSpellCast(hero, SpellID::TOWN_PORTAL);
|
||||
@ -28,7 +25,7 @@ void TownPortalAction::execute(const CGHeroInstance * hero) const
|
||||
goal.town = target;
|
||||
goal.tile = target->visitablePos();
|
||||
|
||||
goal.accept(ai.get());
|
||||
goal.accept(ai);
|
||||
}
|
||||
|
||||
std::string TownPortalAction::toString() const
|
||||
|
@ -21,12 +21,8 @@
|
||||
#include "../../lib/mapObjects/CQuest.h"
|
||||
#include "../../lib/mapping/CMapDefines.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
//extern static const int3 dirs[8];
|
||||
|
||||
const CGObjectInstance * ObjectIdRef::operator->() const
|
||||
{
|
||||
return cb->getObj(id, false);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "../../CCallback.h"
|
||||
|
||||
class VCAI;
|
||||
class CCallback;
|
||||
struct creInfo;
|
||||
|
||||
@ -33,7 +34,8 @@ const int ALLOWED_ROAMING_HEROES = 8;
|
||||
extern const double SAFE_ATTACK_CONSTANT;
|
||||
extern const int GOLD_RESERVE;
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern thread_local CCallback * cb;
|
||||
extern thread_local VCAI * ai;
|
||||
|
||||
//provisional class for AI to store a reference to an owned hero object
|
||||
//checks if it's valid on access, should be used in place of const CGHeroInstance*
|
||||
@ -192,7 +194,7 @@ void foreach_tile_pos(CCallback * cbp, const Func & foo) // avoid costly retriev
|
||||
template<class Func>
|
||||
void foreach_neighbour(const int3 & pos, const Func & foo)
|
||||
{
|
||||
CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer
|
||||
CCallback * cbp = cb; // avoid costly retrieval of thread-specific pointer
|
||||
for(const int3 & dir : int3::getDirs())
|
||||
{
|
||||
const int3 n = pos + dir;
|
||||
|
@ -18,9 +18,6 @@
|
||||
#define MIN_AI_STRENGTH (0.5f) //lower when combat AI gets smarter
|
||||
#define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
|
||||
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
engineBase::engineBase()
|
||||
{
|
||||
rules = new fl::RuleBlock();
|
||||
|
@ -23,9 +23,6 @@
|
||||
|
||||
FuzzyHelper * fh;
|
||||
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
|
||||
Goals::TSubgoal FuzzyHelper::chooseSolution(Goals::TGoalVec vec)
|
||||
{
|
||||
if(vec.empty())
|
||||
@ -216,7 +213,7 @@ void FuzzyHelper::setPriority(Goals::TSubgoal & g) //calls evaluate - Visitor pa
|
||||
|
||||
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor)
|
||||
{
|
||||
return evaluateDanger(tile, visitor, ai.get());
|
||||
return evaluateDanger(tile, visitor, ai);
|
||||
}
|
||||
|
||||
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai)
|
||||
|
@ -51,3 +51,5 @@ public:
|
||||
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai);
|
||||
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor);
|
||||
};
|
||||
|
||||
extern FuzzyHelper * fh;
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include "../BuildingManager.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
TSubgoal Goals::sptr(const AbstractGoal & tmp)
|
||||
|
@ -14,10 +14,6 @@
|
||||
#include "../AIhelper.h"
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool AdventureSpellCast::operator==(const AdventureSpellCast & other) const
|
||||
|
@ -19,11 +19,6 @@
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
TGoalVec Build::getAllPossibleSubgoals()
|
||||
|
@ -13,10 +13,6 @@
|
||||
#include "../FuzzyHelper.h"
|
||||
#include "../AIhelper.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool BuildBoat::operator==(const BuildBoat & other) const
|
||||
|
@ -18,11 +18,6 @@
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool BuildThis::operator==(const BuildThis & other) const
|
||||
|
@ -13,11 +13,6 @@
|
||||
#include "../AIhelper.h"
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool BuyArmy::operator==(const BuyArmy & other) const
|
||||
|
@ -16,11 +16,6 @@
|
||||
#include "../FuzzyHelper.h"
|
||||
#include "../AIhelper.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool ClearWayTo::operator==(const ClearWayTo & other) const
|
||||
|
@ -18,11 +18,6 @@
|
||||
#include "../../../lib/mapObjects/CGMarket.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool CollectRes::operator==(const CollectRes & other) const
|
||||
|
@ -14,10 +14,6 @@
|
||||
#include "../AIhelper.h"
|
||||
#include "../../../lib/mapObjects/CQuest.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool CompleteQuest::operator==(const CompleteQuest & other) const
|
||||
|
@ -17,11 +17,6 @@
|
||||
#include "../BuildingManager.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool Conquer::operator==(const Conquer & other) const
|
||||
|
@ -13,11 +13,6 @@
|
||||
#include "../VCAI.h"
|
||||
#include "../AIUtility.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool DigAtTile::operator==(const DigAtTile & other) const
|
||||
|
@ -18,10 +18,6 @@
|
||||
#include "../../../lib/StringConstants.h"
|
||||
#include "../../../lib/CPlayerState.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
namespace Goals
|
||||
@ -41,8 +37,8 @@ namespace Goals
|
||||
|
||||
ExplorationHelper(HeroPtr h, bool gatherArmy)
|
||||
{
|
||||
cbp = cb.get();
|
||||
aip = ai.get();
|
||||
cbp = cb;
|
||||
aip = ai;
|
||||
hero = h;
|
||||
ts = cbp->getPlayerTeam(ai->playerID);
|
||||
sightRadius = hero->getSightRadius();
|
||||
|
@ -14,10 +14,6 @@
|
||||
#include "../VCAI.h"
|
||||
#include "../AIUtility.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool FindObj::operator==(const FindObj & other) const
|
||||
|
@ -18,11 +18,6 @@
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool GatherArmy::operator==(const GatherArmy & other) const
|
||||
|
@ -18,11 +18,6 @@
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool GatherTroops::operator==(const GatherTroops & other) const
|
||||
|
@ -13,11 +13,6 @@
|
||||
#include "../VCAI.h"
|
||||
#include "../AIUtility.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool GetArtOfType::operator==(const GetArtOfType & other) const
|
||||
@ -28,4 +23,4 @@ bool GetArtOfType::operator==(const GetArtOfType & other) const
|
||||
TSubgoal GetArtOfType::whatToDoToAchieve()
|
||||
{
|
||||
return sptr(FindObj(Obj::ARTIFACT, aid));
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,6 @@
|
||||
#include "../BuildingManager.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
TSubgoal RecruitHero::whatToDoToAchieve()
|
||||
|
@ -18,10 +18,6 @@
|
||||
#include "../ResourceManager.h"
|
||||
#include "../BuildingManager.h"
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool VisitHero::operator==(const VisitHero & other) const
|
||||
|
@ -17,11 +17,6 @@
|
||||
#include "../BuildingManager.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool VisitObj::operator==(const VisitObj & other) const
|
||||
|
@ -17,11 +17,6 @@
|
||||
#include "../BuildingManager.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
bool VisitTile::operator==(const VisitTile & other) const
|
||||
|
@ -19,11 +19,6 @@
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../../../lib/StringConstants.h"
|
||||
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
||||
extern boost::thread_specific_ptr<VCAI> ai;
|
||||
extern FuzzyHelper * fh;
|
||||
|
||||
using namespace Goals;
|
||||
|
||||
TSubgoal Win::whatToDoToAchieve()
|
||||
|
@ -38,8 +38,8 @@ extern FuzzyHelper * fh;
|
||||
const double SAFE_ATTACK_CONSTANT = 1.5;
|
||||
|
||||
//one thread may be turn of AI and another will be handling a side effect for AI2
|
||||
boost::thread_specific_ptr<CCallback> cb;
|
||||
boost::thread_specific_ptr<VCAI> ai;
|
||||
thread_local CCallback * cb = nullptr;
|
||||
thread_local VCAI * ai = nullptr;
|
||||
|
||||
//std::map<int, std::map<int, int> > HeroView::infosCount;
|
||||
|
||||
@ -48,18 +48,18 @@ struct SetGlobalState
|
||||
{
|
||||
SetGlobalState(VCAI * AI)
|
||||
{
|
||||
assert(!ai.get());
|
||||
assert(!cb.get());
|
||||
assert(!ai);
|
||||
assert(!cb);
|
||||
|
||||
ai.reset(AI);
|
||||
cb.reset(AI->myCb.get());
|
||||
ai = AI;
|
||||
cb = AI->myCb.get();
|
||||
}
|
||||
~SetGlobalState()
|
||||
{
|
||||
//TODO: how to handle rm? shouldn't be called after ai is destroyed, hopefully
|
||||
//TODO: to ensure that, make rm unique_ptr
|
||||
ai.release();
|
||||
cb.release();
|
||||
ai = nullptr;
|
||||
cb = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@ -2497,6 +2497,8 @@ void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||
whatToDo();
|
||||
});
|
||||
|
||||
newThread.detach();
|
||||
}
|
||||
|
||||
void VCAI::lostHero(HeroPtr h)
|
||||
|
@ -562,7 +562,9 @@ void CSimpleJoinScreen::startConnectThread(const std::string & addr, ui16 port)
|
||||
// https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md#threads-and-the-java-vm
|
||||
CVCMIServer::reuseClientJNIEnv(SDL_AndroidGetJNIEnv());
|
||||
#endif
|
||||
boost::thread(&CSimpleJoinScreen::connectThread, this, addr, port);
|
||||
boost::thread connector(&CSimpleJoinScreen::connectThread, this, addr, port);
|
||||
|
||||
connector.detach();
|
||||
}
|
||||
|
||||
void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
|
||||
|
@ -92,8 +92,6 @@ set(test_HEADERS
|
||||
|
||||
spells/targetConditions/TargetConditionItemFixture.h
|
||||
|
||||
vcai/ResourceManagerTest.h
|
||||
|
||||
mock/BattleFake.h
|
||||
mock/mock_BonusBearer.h
|
||||
mock/mock_IGameCallback.h
|
||||
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* ResourceManagerTest.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern boost::thread_specific_ptr<CCallback> cb;
|
@ -12,7 +12,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "../AI/VCAI/VCAI.h"
|
||||
#include "ResourceManagerTest.h"
|
||||
#include "../AI/VCAI/Goals/Goals.h"
|
||||
#include "mock_VCAI_CGoal.h"
|
||||
#include "mock_VCAI.h"
|
||||
|
Loading…
Reference in New Issue
Block a user