diff --git a/Source/Contents/MovementRoute.cpp b/Source/Contents/MovementRoute.cpp index a8c878b1..f14751dc 100644 --- a/Source/Contents/MovementRoute.cpp +++ b/Source/Contents/MovementRoute.cpp @@ -8,15 +8,15 @@ MovementRouteInterpolation::MovementRouteInterpolation() : segment(0), startX(0) // OFFSET: 0x00AD87A0 // FUNCTION: fn_17867 -void BuildMovementRoute(std::uint32_t tick, const MovementPathNode* last, int stepDuration, MovementRouteInterpolation& route) { +void BuildMovementRoute(std::uint32_t tick, const PathNode* last, int stepDuration, MovementRouteInterpolation& route) { std::uint32_t count = 0; - for (const MovementPathNode* node = last; node; node = node->parent) { + for (const PathNode* node = last; node; node = node->parent) { ++count; } route.points.resize(count); if (static_cast(count) > 1) { - const MovementPathNode* node = last; + const PathNode* node = last; for (std::uint32_t index = count; index != 0;) { --index; route.points[index].x = node->x; diff --git a/Source/Contents/MovementRouteInterpolation.h b/Source/Contents/MovementRouteInterpolation.h index 4242eb35..bc561d3e 100644 --- a/Source/Contents/MovementRouteInterpolation.h +++ b/Source/Contents/MovementRouteInterpolation.h @@ -5,17 +5,17 @@ #include #include -struct MovementPathNode { +struct PathNode { /* 0000 */ std::int32_t x; /* 0004 */ std::int32_t y; - /* 0008 */ MovementPathNode* parent; + /* 0008 */ PathNode* parent; /* 000C */ int cost; /* 0010 */ int estimatedCost; /* 0014 */ int state; /* 0018 */ int metadata; }; -struct MovementRoutePoint { +struct PathCell { /* 0000 */ std::int32_t x; /* 0004 */ std::int32_t y; /* 0008 */ int metadata; @@ -25,7 +25,7 @@ struct MovementRoutePoint { struct MovementRouteInterpolation { MovementRouteInterpolation(); - /* 0000 */ std::vector points; + /* 0000 */ std::vector points; /* 000C */ std::uint32_t segment; /* 0010 */ float startX; /* 0014 */ float startY; @@ -38,12 +38,12 @@ struct MovementRouteInterpolation { std::uint32_t Segment() const; }; -void BuildMovementRoute(std::uint32_t tick, const MovementPathNode* last, int stepDuration, MovementRouteInterpolation& route); +void BuildMovementRoute(std::uint32_t tick, const PathNode* last, int stepDuration, MovementRouteInterpolation& route); -static_assert(sizeof(MovementRoutePoint) == 16); +static_assert(sizeof(PathCell) == 16); #if defined(_WIN32) && !defined(_WIN64) -static_assert(sizeof(MovementPathNode) == 28); -static_assert(offsetof(MovementPathNode, metadata) == 0x18); +static_assert(sizeof(PathNode) == 28); +static_assert(offsetof(PathNode, metadata) == 0x18); static_assert(sizeof(MovementRouteInterpolation) == 24); static_assert(offsetof(MovementRouteInterpolation, segment) == 0xC); static_assert(offsetof(MovementRouteInterpolation, startX) == 0x10); diff --git a/Source/Contents/NavigationRoute.cpp b/Source/Contents/NavigationRoute.cpp index d09a894a..cd308bce 100644 --- a/Source/Contents/NavigationRoute.cpp +++ b/Source/Contents/NavigationRoute.cpp @@ -120,7 +120,7 @@ bool CNavigationManager::BuildRoute(int startX, int startY, int destX, int destY int offsetX; int offsetY; const float scale = this->FitToSquare(&offsetX, &offsetY, width, height, 126.0f); - for (const MovementRoutePoint& point : this->movementRoute.points) { + for (const PathCell& point : this->movementRoute.points) { NaviCell cell; cell.x = static_cast(point.x * scale + offsetX); cell.y = static_cast(126.0f - (point.y * scale + offsetY)); diff --git a/Source/Contents/TerrainPathSearch.cpp b/Source/Contents/TerrainPathSearch.cpp index dce6ff93..ead4de5a 100644 --- a/Source/Contents/TerrainPathSearch.cpp +++ b/Source/Contents/TerrainPathSearch.cpp @@ -26,19 +26,19 @@ bool CPathFinder::FindPath( this->Reset(); this->nodeCount = 0; - MovementPathNode* start = this->FindOrCreateNode(startX, startY); + PathNode* start = this->FindOrCreateNode(startX, startY); start->state = 1; start->parent = nullptr; start->cost = 0; start->estimatedCost = 10 * (std::abs(startX - this->destinationX) + std::abs(startY - this->destinationY)); - std::vector& open = this->openList.Nodes(); + std::vector& open = this->openList.Nodes(); open.push_back(start); - std::push_heap(open.begin(), open.end(), MovementPathNodeCompare()); + std::push_heap(open.begin(), open.end(), NodeTotalGreater()); while (!open.empty()) { - MovementPathNode* current = open.front(); - std::pop_heap(open.begin(), open.end(), MovementPathNodeCompare()); + PathNode* current = open.front(); + std::pop_heap(open.begin(), open.end(), NodeTotalGreater()); open.pop_back(); if (current->x == destX && current->y == destY) { @@ -91,7 +91,7 @@ bool CPathFinder::FindPath( // OFFSET: 0x00AD9030 // FUNCTION: fn_17875 -MovementPathNode* CPathFinder::FindOrCreateNode(int x, int y) { +PathNode* CPathFinder::FindOrCreateNode(int x, int y) { const int width = this->attr->width; const int key = y * width + x; auto found = this->nodeMap.find(key); @@ -99,7 +99,7 @@ MovementPathNode* CPathFinder::FindOrCreateNode(int x, int y) { return found->second; } - MovementPathNode* node; + PathNode* node; if (this->useNodePool) { const int count = static_cast(this->nodePool.size()); if (this->nodeCount >= count - 1) { @@ -155,9 +155,9 @@ bool CPathFinder::CanMove(int startX, int startY, int targetX, int targetY, char // OFFSET: 0x00AD9610 // FUNCTION: fn_17882 -bool CPathFinder::AddNeighbor(MovementPathNode* current, int cost, int nextX, int nextY, int metadata) { +bool CPathFinder::AddNeighbor(PathNode* current, int cost, int nextX, int nextY, int metadata) { const int totalCost = current->cost + cost; - MovementPathNode* next = this->FindOrCreateNode(nextX, nextY); + PathNode* next = this->FindOrCreateNode(nextX, nextY); if (!next) { return false; } @@ -179,10 +179,10 @@ bool CPathFinder::AddNeighbor(MovementPathNode* current, int cost, int nextX, in next->metadata = metadata; if (next->state == 1) { - std::vector& open = this->openList.Nodes(); + std::vector& open = this->openList.Nodes(); for (auto it = open.begin(); it != open.end(); ++it) { if ((*it)->x == next->x && (*it)->y == next->y) { - std::push_heap(open.begin(), it + 1, MovementPathNodeCompare()); + std::push_heap(open.begin(), it + 1, NodeTotalGreater()); return true; } } @@ -196,9 +196,9 @@ bool CPathFinder::AddNeighbor(MovementPathNode* current, int cost, int nextX, in // OFFSET: 0x00AD9760 // FUNCTION: fn_17883 -void MovementOpenList::Push(MovementPathNode* node) { +void CPriorityQueue::Push(PathNode* node) { this->nodes.push_back(node); - std::push_heap(this->nodes.begin(), this->nodes.end(), MovementPathNodeCompare()); + std::push_heap(this->nodes.begin(), this->nodes.end(), NodeTotalGreater()); } // OFFSET: 0x00AD97C0 @@ -216,6 +216,6 @@ void CPathFinder::Clear() { void CPathFinder::Reset() { this->nodePool.erase(this->nodePool.begin(), this->nodePool.end()); this->nodeMap.erase(this->nodeMap.begin(), this->nodeMap.end()); - std::vector& open = this->openList.Nodes(); + std::vector& open = this->openList.Nodes(); open.erase(open.begin(), open.end()); } diff --git a/Source/Contents/TerrainPathSearch.h b/Source/Contents/TerrainPathSearch.h index 70b0d34a..01bb8dbc 100644 --- a/Source/Contents/TerrainPathSearch.h +++ b/Source/Contents/TerrainPathSearch.h @@ -10,20 +10,20 @@ #include #include -struct MovementPathNodeCompare { - bool operator()(const MovementPathNode* left, const MovementPathNode* right) const { +struct NodeTotalGreater { + bool operator()(const PathNode* left, const PathNode* right) const { return left->estimatedCost > right->estimatedCost; } }; -class MovementOpenList { +class CPriorityQueue { public: - std::vector& Nodes() { + std::vector& Nodes() { return this->nodes; } - void Push(MovementPathNode* node); + void Push(PathNode* node); - /* 0000 */ std::vector nodes; + /* 0000 */ std::vector nodes; }; class CPathFinder { @@ -35,18 +35,18 @@ public: /* 0004 */ int destinationX; /* 0008 */ int destinationY; /* 000C */ int nodeCount; - /* 0010 */ MovementPathNode nodes[150]; + /* 0010 */ PathNode nodes[150]; /* 1078 */ std::map attrCache; /* 1080 */ bool useNodePool; - /* 1084 */ std::vector nodePool; - /* 1090 */ std::map nodeMap; - /* 1098 */ MovementOpenList openList; + /* 1084 */ std::vector nodePool; + /* 1090 */ std::map nodeMap; + /* 1098 */ CPriorityQueue openList; void Clear(); void Reset(); bool CanMove(int startX, int startY, int targetX, int targetY, char flag) const; - MovementPathNode* FindOrCreateNode(int x, int y); - bool AddNeighbor(MovementPathNode* current, int cost, int nextX, int nextY, int metadata); + PathNode* FindOrCreateNode(int x, int y); + bool AddNeighbor(PathNode* current, int cost, int nextX, int nextY, int metadata); bool FindPath( int startTick, int startX, int startY, int currentFractionX, int currentFractionY, int destX, int destY, int speed, MovementRouteInterpolation& route, char flag @@ -62,7 +62,7 @@ static_assert(offsetof(CPathFinder, attrCache) == 0x1078); static_assert(offsetof(CPathFinder, nodePool) == 0x1084); static_assert(offsetof(CPathFinder, nodeMap) == 0x1090); static_assert(offsetof(CPathFinder, openList) == 0x1098); -static_assert(sizeof(MovementOpenList) == 0x0C); +static_assert(sizeof(CPriorityQueue) == 0x0C); static_assert(sizeof(CPathFinder) == 0x10A4); #endif