Skip to content

Commit ba6dd73

Browse files
committed
Added offset to the pathing grid
1 parent 930bb5f commit ba6dd73

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Source/Managers/SettingsMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void SettingsMan::Clear() {
4848
m_SceneBackgroundAutoScaleMode = 1;
4949
m_DisableFactionBuyMenuThemes = false;
5050
m_DisableFactionBuyMenuThemeCursors = false;
51-
m_PathFinderGridNodeSize = 24;
51+
m_PathFinderGridNodeSize = SCENEGRIDSIZE;
5252
m_AIUpdateInterval = 2;
5353

5454
m_NumberOfLuaStatesOverride = -1;

Source/System/PathFinder.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ PathFinder::~PathFinder() {
5656
void PathFinder::Clear() {
5757
m_NodeGrid.clear();
5858
m_NodeDimension = SCENEGRIDSIZE;
59+
m_Offset = Vector();
5960
}
6061

6162
int PathFinder::Create(int nodeDimension) {
@@ -72,8 +73,10 @@ int PathFinder::Create(int nodeDimension) {
7273
m_WrapsX = g_SceneMan.SceneWrapsX();
7374
m_WrapsY = g_SceneMan.SceneWrapsY();
7475

76+
m_Offset = Vector(nodeDimension * 0.5f, nodeDimension * 0.5f);
77+
7578
// Create and assign scene coordinate positions for all nodes.
76-
Vector nodePos = Vector(static_cast<float>(nodeDimension) / 2.0F, static_cast<float>(nodeDimension) / 2.0F);
79+
Vector nodePos = Vector(static_cast<float>(nodeDimension) / 2.0F, static_cast<float>(nodeDimension) / 2.0F) + m_Offset;
7780
m_NodeGrid.reserve(m_GridWidth * m_GridHeight);
7881
for (int y = 0; y < m_GridHeight; ++y) {
7982
// Make sure no cell centers are off the scene (since they can overlap the far edge of the scene).
@@ -454,10 +457,10 @@ std::vector<int> PathFinder::GetNodeIdsInBox(Box box) {
454457
box.Unflip();
455458

456459
// Get the extents of the box's potential influence on PathNodes and their connecting edges.
457-
int firstX = static_cast<int>(std::floor((box.m_Corner.m_X / static_cast<float>(m_NodeDimension)) + 0.5F) - 1);
458-
int lastX = static_cast<int>(std::floor(((box.m_Corner.m_X + box.m_Width) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1);
459-
int firstY = static_cast<int>(std::floor((box.m_Corner.m_Y / static_cast<float>(m_NodeDimension)) + 0.5F) - 1);
460-
int lastY = static_cast<int>(std::floor(((box.m_Corner.m_Y + box.m_Height) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1);
460+
int firstX = static_cast<int>(std::floor( (box.m_Corner.m_X / static_cast<float>(m_NodeDimension)) + 0.5F) - 1);
461+
int lastX = static_cast<int>(std::floor(((box.m_Corner.m_X + box.m_Width) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1);
462+
int firstY = static_cast<int>(std::floor( (box.m_Corner.m_Y / static_cast<float>(m_NodeDimension)) + 0.5F) - 1);
463+
int lastY = static_cast<int>(std::floor(((box.m_Corner.m_Y + box.m_Height) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1);
461464

462465
// Only iterate through the grid where the box overlaps any edges.
463466
for (int nodeX = firstX; nodeX <= lastX; ++nodeX) {

Source/System/PathFinder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace RTE {
175175
MicroPather* m_Pather; //!< The actual pathing object that does the pathfinding work. Owned.
176176
std::vector<PathNode> m_NodeGrid; //!< The array of PathNodes representing the grid on the scene.
177177
unsigned int m_NodeDimension; //!< The width and height of each PathNode, in pixels on the scene.
178+
Vector m_Offset;
178179
int m_GridWidth; //!< The width of the pathing grid, in PathNodes.
179180
int m_GridHeight; //!< The height of the pathing grid, in PathNodes.
180181
bool m_WrapsX; //!< Whether the pathing grid wraps on the X axis.

0 commit comments

Comments
 (0)