2
0
Эх сурвалжийг харах

Reduce size of CGPathNode and AIPathNode

Ivan Savenko 1 жил өмнө
parent
commit
04a81fee87

+ 1 - 2
AI/Nullkiller/Pathfinding/AINodeStorage.cpp

@@ -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;

+ 8 - 5
AI/Nullkiller/Pathfinding/AINodeStorage.h

@@ -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();

+ 14 - 13
lib/pathfinder/CGPathNode.h

@@ -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

+ 1 - 3
lib/pathfinder/CPathfinder.cpp

@@ -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;
 }