diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp index b113e27ae..da7abceba 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp @@ -25,7 +25,7 @@ namespace NKAI { std::shared_ptr> AISharedStorage::shared; -uint64_t AISharedStorage::version = 0; +uint32_t AISharedStorage::version = 0; boost::mutex AISharedStorage::locker; std::set committedTiles; std::set committedTilesInitial; @@ -224,7 +224,6 @@ std::vector AINodeStorage::getInitialNodes() AIPathNode * initialNode = allocated.value(); - initialNode->inPQ = false; initialNode->pq = nullptr; initialNode->turns = actor->initialTurn; initialNode->moveRemains = actor->initialMovement; diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.h b/AI/Nullkiller/Pathfinding/AINodeStorage.h index 7a44de1dd..9e18bd7bd 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.h +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.h @@ -44,14 +44,17 @@ enum DayFlags : ui8 struct AIPathNode : public CGPathNode { + std::shared_ptr specialAction; + + const AIPathNode * chainOther; + const ChainActor * actor; + uint64_t danger; uint64_t armyLoss; + uint32_t version; + int16_t manaCost; DayFlags dayFlags; - const AIPathNode * chainOther; - std::shared_ptr specialAction; - const ChainActor * actor; - uint64_t version; void addSpecialAction(std::shared_ptr action); @@ -152,7 +155,7 @@ class AISharedStorage std::shared_ptr> nodes; public: static boost::mutex locker; - static uint64_t version; + static uint32_t version; AISharedStorage(int3 mapSize); ~AISharedStorage(); diff --git a/lib/pathfinder/CGPathNode.h b/lib/pathfinder/CGPathNode.h index a850761b1..2598633cc 100644 --- a/lib/pathfinder/CGPathNode.h +++ b/lib/pathfinder/CGPathNode.h @@ -59,18 +59,22 @@ enum class EPathNodeAction : ui8 struct DLL_LINKAGE CGPathNode { + using TFibHeap = boost::heap::fibonacci_heap>>; using ELayer = EPathfindingLayer; + TFibHeap::handle_type pqHandle; + TFibHeap * pq; CGPathNode * theNodeBefore; + int3 coord; //coordinates ELayer layer; + + float cost; //total cost of the path to this tile measured in turns with fractions int moveRemains; //remaining movement points after hero reaches the tile ui8 turns; //how many turns we have to wait before reaching the tile - 0 means current turn - EPathAccessibility accessible; EPathNodeAction action; bool locked; - bool inPQ; CGPathNode() : coord(-1), @@ -89,9 +93,14 @@ struct DLL_LINKAGE CGPathNode cost = std::numeric_limits::max(); turns = 255; theNodeBefore = nullptr; - action = EPathNodeAction::UNKNOWN; - inPQ = false; pq = nullptr; + action = EPathNodeAction::UNKNOWN; + } + + STRONG_INLINE + bool inPQ() const + { + return pq != nullptr; } STRONG_INLINE @@ -109,7 +118,7 @@ struct DLL_LINKAGE CGPathNode bool getUpNode = value < cost; cost = value; // If the node is in the heap, update the heap. - if(inPQ && pq != nullptr) + if(inPQ()) { if(getUpNode) { @@ -155,14 +164,6 @@ struct DLL_LINKAGE CGPathNode return true; } - - using TFibHeap = boost::heap::fibonacci_heap>>; - - TFibHeap::handle_type pqHandle; - TFibHeap* pq; - -private: - float cost; //total cost of the path to this tile measured in turns with fractions }; struct DLL_LINKAGE CGPath diff --git a/lib/pathfinder/CPathfinder.cpp b/lib/pathfinder/CPathfinder.cpp index a4a725d35..cefb55673 100644 --- a/lib/pathfinder/CPathfinder.cpp +++ b/lib/pathfinder/CPathfinder.cpp @@ -82,9 +82,8 @@ CPathfinder::CPathfinder(CGameState * _gs, std::shared_ptr con void CPathfinder::push(CGPathNode * node) { - if(node && !node->inPQ) + if(node && !node->inPQ()) { - node->inPQ = true; node->pq = &this->pq; auto handle = pq.push(node); node->pqHandle = handle; @@ -96,7 +95,6 @@ CGPathNode * CPathfinder::topAndPop() auto * node = pq.top(); pq.pop(); - node->inPQ = false; node->pq = nullptr; return node; }