1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #4268 from IvanSavenko/pathnode_reduce

Reduce size of CGPathNode and AIPathNode
This commit is contained in:
Ivan Savenko 2024-07-17 13:08:05 +03:00 committed by GitHub
commit 1072356002
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 23 deletions

View File

@ -25,7 +25,7 @@ namespace NKAI
{
std::shared_ptr<boost::multi_array<AIPathNode, 4>> AISharedStorage::shared;
uint64_t AISharedStorage::version = 0;
uint32_t AISharedStorage::version = 0;
boost::mutex AISharedStorage::locker;
std::set<int3> committedTiles;
std::set<int3> committedTilesInitial;
@ -224,7 +224,6 @@ std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
AIPathNode * initialNode = allocated.value();
initialNode->inPQ = false;
initialNode->pq = nullptr;
initialNode->turns = actor->initialTurn;
initialNode->moveRemains = actor->initialMovement;

View File

@ -44,14 +44,17 @@ enum DayFlags : ui8
struct AIPathNode : public CGPathNode
{
std::shared_ptr<const SpecialAction> 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<const SpecialAction> specialAction;
const ChainActor * actor;
uint64_t version;
void addSpecialAction(std::shared_ptr<const SpecialAction> action);
@ -152,7 +155,7 @@ class AISharedStorage
std::shared_ptr<boost::multi_array<AIPathNode, 4>> nodes;
public:
static boost::mutex locker;
static uint64_t version;
static uint32_t version;
AISharedStorage(int3 mapSize);
~AISharedStorage();

View File

@ -59,18 +59,22 @@ enum class EPathNodeAction : ui8
struct DLL_LINKAGE CGPathNode
{
using TFibHeap = boost::heap::fibonacci_heap<CGPathNode *, boost::heap::compare<NodeComparer<CGPathNode>>>;
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<float>::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<CGPathNode *, boost::heap::compare<NodeComparer<CGPathNode>>>;
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

View File

@ -82,9 +82,8 @@ CPathfinder::CPathfinder(CGameState * _gs, std::shared_ptr<PathfinderConfig> 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;
}