Skip to content

Commit 1136e1b

Browse files
committed
Updated pathfind grid node size, and added rudimentary debug rendering
1 parent ba6dd73 commit 1136e1b

File tree

6 files changed

+54
-30
lines changed

6 files changed

+54
-30
lines changed

Source/Entities/Scene.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ namespace RTE {
705705
/// @return Pointer to preview bitmap.
706706
BITMAP* GetPreviewBitmap() const { return m_pPreviewBitmap; };
707707

708+
/// Gets the pathfinder for a given team.
709+
/// @param team The team to get the pathfinder for. NoTeam is valid, and will give a shared pathfinder.
710+
/// @return A reference to the pathfinder for the given team.
711+
PathFinder& GetPathFinder(Activity::Teams team);
712+
708713
/// Protected member variable and method declarations
709714
protected:
710715
// Member variables
@@ -789,11 +794,6 @@ namespace RTE {
789794

790795
/// Private member variable and method declarations
791796
private:
792-
/// Gets the pathfinder for a given team.
793-
/// @param team The team to get the pathfinder for. NoTeam is valid, and will give a shared pathfinder.
794-
/// @return A reference to the pathfinder for the given team.
795-
PathFinder& GetPathFinder(Activity::Teams team);
796-
797797
/// Serializes the SceneObject via the Writer. Necessary because full serialization doesn't know how to deal with duplicate properties.
798798
/// @param writer The Writer being used for serialization.
799799
/// @param sceneObjectToSave The SceneObject to save.

Source/Managers/SceneMan.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,9 @@ void SceneMan::Draw(BITMAP* targetBitmap, BITMAP* targetGUIBitmap, const Vector&
25912591
if (!m_pCurrentScene) {
25922592
return;
25932593
}
2594+
25942595
SLTerrain* terrain = m_pCurrentScene->GetTerrain();
2596+
25952597
// Set up the target box to draw to on the target bitmap, if it is larger than the scene in either dimension.
25962598
Box targetBox(Vector(), static_cast<float>(targetBitmap->w), static_cast<float>(targetBitmap->h));
25972599

@@ -2643,24 +2645,30 @@ void SceneMan::Draw(BITMAP* targetBitmap, BITMAP* targetGUIBitmap, const Vector&
26432645
g_ActivityMan.GetActivity()->DrawGUI(targetGUIBitmap, targetPos, m_LastUpdatedScreen);
26442646
}
26452647

2646-
#ifdef DRAW_NOGRAV_BOXES
2647-
if (Scene::Area* noGravArea = m_pCurrentScene->GetArea("NoGravityArea")) {
2648-
const std::vector<Box>& boxList = noGravArea->GetBoxes();
2649-
g_FrameMan.SetTransTableFromPreset(TransparencyPreset::MoreTrans);
2650-
drawing_mode(DRAW_MODE_TRANS, 0, 0, 0);
2651-
2652-
std::list<Box> wrappedBoxes;
2653-
for (std::vector<Box>::const_iterator bItr = boxList.begin(); bItr != boxList.end(); ++bItr) {
2654-
wrappedBoxes.clear();
2655-
g_SceneMan.WrapBox(*bItr, wrappedBoxes);
2656-
2657-
for (std::list<Box>::iterator wItr = wrappedBoxes.begin(); wItr != wrappedBoxes.end(); ++wItr) {
2658-
Vector adjCorner = (*wItr).GetCorner() - targetPos;
2659-
rectfill(targetBitmap, adjCorner.m_X, adjCorner.m_Y, adjCorner.m_X + (*wItr).GetWidth(), adjCorner.m_Y + (*wItr).GetHeight(), g_RedColor);
2648+
static bool s_drawNoGravBoxes = false;
2649+
if (s_drawNoGravBoxes) {
2650+
if (Scene::Area* noGravArea = m_pCurrentScene->GetArea("NoGravityArea")) {
2651+
const std::vector<Box>& boxList = noGravArea->GetBoxes();
2652+
g_FrameMan.SetTransTableFromPreset(TransparencyPreset::MoreTrans);
2653+
drawing_mode(DRAW_MODE_TRANS, 0, 0, 0);
2654+
2655+
std::list<Box> wrappedBoxes;
2656+
for (std::vector<Box>::const_iterator bItr = boxList.begin(); bItr != boxList.end(); ++bItr) {
2657+
wrappedBoxes.clear();
2658+
g_SceneMan.WrapBox(*bItr, wrappedBoxes);
2659+
2660+
for (std::list<Box>::iterator wItr = wrappedBoxes.begin(); wItr != wrappedBoxes.end(); ++wItr) {
2661+
Vector adjCorner = (*wItr).GetCorner() - targetPos;
2662+
rectfill(targetBitmap, adjCorner.m_X, adjCorner.m_Y, adjCorner.m_X + (*wItr).GetWidth(), adjCorner.m_Y + (*wItr).GetHeight(), g_RedColor);
2663+
}
26602664
}
26612665
}
26622666
}
2663-
#endif
2667+
2668+
static int s_drawPathfinderDebugForTeam = -2;
2669+
if (s_drawPathfinderDebugForTeam > -2) {
2670+
m_pCurrentScene->GetPathFinder(static_cast<Activity::Teams>(s_drawPathfinderDebugForTeam)).DebugRender(targetBitmap, targetPos, m_LastUpdatedScreen);
2671+
}
26642672

26652673
if (m_pDebugLayer) {
26662674
m_pDebugLayer->Draw(targetBitmap, targetBox);

Source/Managers/SceneMan.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,9 @@ namespace RTE {
874874
/// @param screenId Which screen to update for. (default: 0)
875875
void Update(int screenId = 0);
876876

877-
/// Draws this SceneMan's current graphical representation to a
878-
/// BITMAP of choice.
879-
/// @param targetBitmap A pointer to a BITMAP to draw on, appropriately sized for the split
880-
/// screen segment.
881-
/// @param targetGUIBitmap The offset into the scene where the target bitmap's upper left corner
882-
/// is located.
877+
/// Draws this SceneMan's current graphical representation to a BITMAP of choice.
878+
/// @param targetBitmap A pointer to a BITMAP to draw on, appropriately sized for the split screen segment.
879+
/// @param targetGUIBitmap The offset into the scene where the target bitmap's upper left corner is located.
883880
void Draw(BITMAP* targetBitmap, BITMAP* targetGUIBitmap, const Vector& targetPos = Vector(), bool skipBackgroundLayers = false, bool skipTerrain = false);
884881

885882
/// Clears the color MO layer. Should be done every frame.

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 = SCENEGRIDSIZE;
51+
m_PathFinderGridNodeSize = 18;
5252
m_AIUpdateInterval = 2;
5353

5454
m_NumberOfLuaStatesOverride = -1;

Source/System/PathFinder.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PathFinder::~PathFinder() {
5555

5656
void PathFinder::Clear() {
5757
m_NodeGrid.clear();
58-
m_NodeDimension = SCENEGRIDSIZE;
58+
m_NodeDimension = 18;
5959
m_Offset = Vector();
6060
}
6161

@@ -567,7 +567,7 @@ RTE::PathNode* PathFinder::GetPathNodeAtGridCoords(int x, int y) {
567567
return nodeId != -1 ? &m_NodeGrid[nodeId] : nullptr;
568568
}
569569

570-
int PathFinder::ConvertCoordsToNodeId(int x, int y) {
570+
int PathFinder::ConvertCoordsToNodeId(int x, int y) const {
571571
if (m_WrapsX) {
572572
x = x % m_GridWidth;
573573
x = x < 0 ? x + m_GridWidth : x;
@@ -584,3 +584,17 @@ int PathFinder::ConvertCoordsToNodeId(int x, int y) {
584584

585585
return (y * m_GridWidth) + x;
586586
}
587+
588+
void PathFinder::DebugRender(BITMAP* targetBitmap, const Vector& targetPos, int whichScreen) const {
589+
for (int x = 0; x < m_GridWidth; ++x) {
590+
Vector startPos = (m_NodeGrid[ConvertCoordsToNodeId(x, 0)].Pos - m_Offset) - targetPos;
591+
Vector endPos = startPos + Vector(0.0F, m_NodeDimension * m_GridHeight);
592+
line(targetBitmap, startPos.GetX(), startPos.GetY(), endPos.GetX(), endPos.GetY(), g_BlackColor);
593+
}
594+
595+
for (int y = 0; y < m_GridHeight; ++y) {
596+
Vector startPos = (m_NodeGrid[ConvertCoordsToNodeId(0, y)].Pos - m_Offset) - targetPos;
597+
Vector endPos = startPos + Vector(m_NodeDimension * m_GridWidth, 0.0F);
598+
line(targetBitmap, startPos.GetX(), startPos.GetY(), endPos.GetX(), endPos.GetY(), g_BlackColor);
599+
}
600+
}

Source/System/PathFinder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ namespace RTE {
167167
/// Since void* aren't really human readable, this will print out some concise info without an ending newline.
168168
/// @param state The state to print out info about.
169169
void PrintStateInfo(void* state) override {}
170+
171+
/// Draws a debug rendering for this pathfinder to a BITMAP of choice.
172+
/// @param targetBitmap A pointer to a BITMAP to draw on.
173+
/// @param targetGUIBitmap The offset into the scene where the target bitmap's upper left corner is located.
174+
void DebugRender(BITMAP* targetBitmap, const Vector& targetPos = Vector(), int whichScreen = 0) const;
170175
#pragma endregion
171176

172177
private:
@@ -230,7 +235,7 @@ namespace RTE {
230235
/// @param x The X coordinate, in PathNodes.
231236
/// @param y The Y coordinate, in PathNodes.
232237
/// @return The PathNode id at the given coordinates.
233-
int ConvertCoordsToNodeId(int x, int y);
238+
int ConvertCoordsToNodeId(int x, int y) const;
234239

235240
/// Clears all the member variables of this PathFinder, effectively resetting the members of this abstraction level only.
236241
void Clear();

0 commit comments

Comments
 (0)