[Scummvm-git-logs] scummvm master -> 1097f4b5e5dd70e73f24236e992e3c84f2c51566

OMGPizzaGuy noreply at scummvm.org
Fri May 24 03:13:05 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1097f4b5e5 ULTIMA8: Fix pathfinder visual debug.


Commit: 1097f4b5e5dd70e73f24236e992e3c84f2c51566
    https://github.com/scummvm/scummvm/commit/1097f4b5e5dd70e73f24236e992e3c84f2c51566
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-05-23T22:12:39-05:00

Commit Message:
ULTIMA8: Fix pathfinder visual debug.
This feature is still behind a define macro.

Changed paths:
    engines/ultima/ultima8/misc/debugger.cpp
    engines/ultima/ultima8/misc/debugger.h
    engines/ultima/ultima8/world/actors/pathfinder.cpp
    engines/ultima/ultima8/world/actors/pathfinder.h


diff --git a/engines/ultima/ultima8/misc/debugger.cpp b/engines/ultima/ultima8/misc/debugger.cpp
index 01901cee019..25f54b29cbe 100644
--- a/engines/ultima/ultima8/misc/debugger.cpp
+++ b/engines/ultima/ultima8/misc/debugger.cpp
@@ -52,15 +52,11 @@
 #include "ultima/ultima8/world/item_factory.h"
 #include "ultima/ultima8/world/actors/quick_avatar_mover_process.h"
 #include "ultima/ultima8/world/actors/avatar_mover_process.h"
+#include "ultima/ultima8/world/actors/pathfinder.h"
 #include "ultima/ultima8/world/target_reticle_process.h"
 #include "ultima/ultima8/world/item_selection_process.h"
 #include "ultima/ultima8/world/actors/main_actor.h"
 
-#ifdef DEBUG
-#include "ultima/ultima8/world/actors/pathfinder.h"
-#endif
-
-
 namespace Ultima {
 namespace Ultima8 {
 
@@ -207,7 +203,7 @@ Debugger::Debugger() : GUI::Debugger() {
 	registerCmd("ShapeViewerGump::U8ShapeViewer", WRAP_METHOD(Debugger, cmdU8ShapeViewer));
 	registerCmd("RenderSurface::benchmark", WRAP_METHOD(Debugger, cmdBenchmarkRenderSurface));
 
-#ifdef DEBUG
+#ifdef DEBUG_PATHFINDER
 	registerCmd("Pathfinder::visualDebug", WRAP_METHOD(Debugger, cmdVisualDebugPathfinder));
 #endif
 }
@@ -1885,8 +1881,8 @@ bool Debugger::cmdBenchmarkRenderSurface(int argc, const char **argv) {
 	return true;
 }
 
-#ifdef DEBUG
 bool Debugger::cmdVisualDebugPathfinder(int argc, const char **argv) {
+#ifdef DEBUG_PATHFINDER
 	if (argc != 2) {
 		debugPrintf("Usage: Pathfinder::visualDebug objid\n");
 		debugPrintf("Specify objid -1 to stop tracing.\n");
@@ -1900,10 +1896,9 @@ bool Debugger::cmdVisualDebugPathfinder(int argc, const char **argv) {
 		Pathfinder::_visualDebugActor = (uint16)p;
 		debugPrintf("Pathfinder: visually tracing _actor %d\n", Pathfinder::_visualDebugActor);
 	}
-
+#endif
 	return true;
 }
-#endif
 
 } // End of namespace Ultima8
 } // End of namespace Ultima
diff --git a/engines/ultima/ultima8/misc/debugger.h b/engines/ultima/ultima8/misc/debugger.h
index a76f14f1da7..b0b649f77de 100644
--- a/engines/ultima/ultima8/misc/debugger.h
+++ b/engines/ultima/ultima8/misc/debugger.h
@@ -185,10 +185,7 @@ private:
 	bool cmdPlayMovie(int argc, const char **argv);
 	bool cmdPlayMusic(int argc, const char **argv);
 	bool cmdBenchmarkRenderSurface(int argc, const char **argv);
-
-#ifdef DEBUG
 	bool cmdVisualDebugPathfinder(int argc, const char **argv);
-#endif
 
 	void dumpCurrentMap(); // helper function
 
diff --git a/engines/ultima/ultima8/world/actors/pathfinder.cpp b/engines/ultima/ultima8/world/actors/pathfinder.cpp
index 69d4a4c5e6e..15006e49f7d 100644
--- a/engines/ultima/ultima8/world/actors/pathfinder.cpp
+++ b/engines/ultima/ultima8/world/actors/pathfinder.cpp
@@ -25,8 +25,8 @@
 #include "ultima/ultima8/world/actors/actor.h"
 #include "ultima/ultima8/world/actors/animation_tracker.h"
 
-#ifdef DEBUG
-#include "ultima/ultima8/graphics/render_surface.h"
+#ifdef DEBUG_PATHFINDER
+#include "graphics/screen.h"
 #include "ultima/ultima8/gumps/game_map_gump.h"
 #endif
 
@@ -34,7 +34,7 @@ namespace Ultima {
 namespace Ultima8 {
 
 
-#ifdef DEBUG
+#ifdef DEBUG_PATHFINDER
 ObjId Pathfinder::_visualDebugActor = 0xFFFF;
 #endif
 
@@ -243,17 +243,13 @@ unsigned int Pathfinder::costHeuristic(PathNode *node) const {
 	return node->heuristicTotalCost;
 }
 
+#ifdef DEBUG_PATHFINDER
 
-#ifdef DEBUG
-
-static void drawbox(const Item *item) {
-	RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
+static void drawbox(Graphics::ManagedSurface *screen, const Item *item) {
 	int32 cx, cy, cz;
-
 	Ultima8Engine::get_instance()->getGameMapGump()->GetCameraLocation(cx, cy, cz);
 
-	Rect d;
-	screen->GetSurfaceDims(d);
+	Common::Rect d = screen->getBounds();
 
 	int32 ix, iy, iz;
 	item->getLocation(ix, iy, iz);
@@ -279,38 +275,36 @@ static void drawbox(const Item *item) {
 	x3 = (d.width() / 2) + (ix - iy + yd) / 4;
 	y3 = (d.height() / 2) + (ix + iy - yd) / 8 - iz;
 
-	screen->fill32(TEX32_PACK_RGB(0x00, 0x00, 0xFF), x0 - 1, y0 - 1, 3, 3);
+	uint32 color = screen->format.RGBToColor(0x00, 0x00, 0xFF);
+	screen->fillRect(Common::Rect(x0 - 1, y0 - 1, x0 + 2, y0 + 2), color);
 
-	screen->drawLine32(TEX32_PACK_RGB(0x00, 0xFF, 0x00), x0, y0, x1, y1);
-	screen->drawLine32(TEX32_PACK_RGB(0x00, 0xFF, 0x00), x0, y0, x2, y2);
-	screen->drawLine32(TEX32_PACK_RGB(0x00, 0xFF, 0x00), x0, y0, x3, y3);
+	color = screen->format.RGBToColor(0x00, 0xFF, 0x00);
+	screen->drawLine(x0, y0, x1, y1, color);
+	screen->drawLine(x0, y0, x2, y2, color);
+	screen->drawLine(x0, y0, x3, y3, color);
 }
 
-static void drawdot(int32 x, int32 y, int32 Z, int size, uint32 rgb) {
-	RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
+static void drawdot(Graphics::ManagedSurface *screen, int32 x, int32 y, int32 Z, int size, uint32 rgb) {
 	int32 cx, cy, cz;
 
 	Ultima8Engine::get_instance()->getGameMapGump()->GetCameraLocation(cx, cy, cz);
 
-	Rect d;
-	screen->GetSurfaceDims(d);
+	Common::Rect d = screen->getBounds();
 	x -= cx;
 	y -= cy;
 	Z -= cz;
 	int32 x0, y0;
 	x0 = (d.width() / 2) + (x - y) / 4;
 	y0 = (d.height() / 2) + (x + y) / 8 - Z;
-	screen->Fill32(rgb, x0 - size, y0 - size, 2 * size + 1, 2 * size + 1);
+	screen->fillRect(Common::Rect(x0 - size, y0 - size, x0 + size + 1, y0 + size + 1), rgb);
 }
 
-static void drawedge(const PathNode *from, const PathNode *to, uint32 rgb) {
-	RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
+static void drawedge(Graphics::ManagedSurface *screen, const PathNode *from, const PathNode *to, uint32 rgb) {
 	int32 cx, cy, cz;
 
 	Ultima8Engine::get_instance()->getGameMapGump()->GetCameraLocation(cx, cy, cz);
 
-	Rect d;
-	screen->GetSurfaceDims(d);
+	Common::Rect d = screen->getBounds();
 
 	int32 x0, y0, x1, y1;
 
@@ -330,23 +324,25 @@ static void drawedge(const PathNode *from, const PathNode *to, uint32 rgb) {
 	x1 = (d.width() / 2) + (cx - cy) / 4;
 	y1 = (d.height() / 2) + (cx + cy) / 8 - cz;
 
-	screen->drawLine32(rgb, x0, y0, x1, y1);
+	screen->drawLine(x0, y0, x1, y1, rgb);
 }
 
-static void drawpath(PathNode *to, uint32 rgb, bool done) {
+static void drawpath(Graphics::ManagedSurface *screen, PathNode *to, uint32 rgb, bool done) {
 	PathNode *n1 = to;
 	PathNode *n2 = to->parent;
+	uint32 color1 = screen->format.RGBToColor(0xFF, 0x00, 0x00);
+	uint32 color2 = screen->format.RGBToColor(0xFF, 0xFF, 0xFF);
 
 	while (n2) {
-		drawedge(n1, n2, rgb);
+		drawedge(screen, n1, n2, rgb);
 
 		if (done && n1 == to)
-			drawdot(n1->state._x, n1->state._y, n1->state._z, 2, TEX32_PACK_RGB(0xFF, 0x00, 0x00));
+			drawdot(screen, n1->state._x, n1->state._y, n1->state._z, 2, color1);
 		else
-			drawdot(n1->state._x, n1->state._y, n1->state._z, 1, TEX32_PACK_RGB(0xFF, 0xFF, 0xFF));
+			drawdot(screen, n1->state._x, n1->state._y, n1->state._z, 1, color2);
 
 
-		drawdot(n2->state._x, n2->state._y, n2->state._z, 2, TEX32_PACK_RGB(0xFF, 0xFF, 0xFF));
+		drawdot(screen, n2->state._x, n2->state._y, n2->state._z, 2, color2);
 
 		n1 = n2;
 		n2 = n1->parent;
@@ -396,17 +392,17 @@ void Pathfinder::newNode(PathNode *oldnode, PathfindingState &state,
 		   oldnode->state._x, oldnode->state._y, newnode->state._x, newnode->state._y,
 		   newnode->cost, newnode->heuristicTotalCost);
 
-#ifdef DEBUG
+#ifdef DEBUG_PATHFINDER
 	if (_actor->getObjId() == _visualDebugActor) {
-		RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
-		screen->BeginPainting();
-		drawpath(newnode, TEX32_PACK_RGB(0xFF, 0xFF, 0x00), done);
-		screen->EndPainting();
+		Graphics::Screen *screen = Ultima8Engine::get_instance()->getScreen();
+		uint32 color = screen->format.RGBToColor(0xFF, 0xFF, 0x00);
+		drawpath(screen, newnode, color, done);
+		screen->update();
 		g_system->delayMillis(50);
 		if (!done) {
-			screen->BeginPainting();
-			drawpath(newnode, TEX32_PACK_RGB(0xB0, 0xB0, 0x00), done);
-			screen->EndPainting();
+			color = screen->format.RGBToColor(0xB0, 0xB0, 0x00);
+			drawpath(screen, newnode, color, done);
+			screen->update();
 		}
 	}
 #endif
@@ -505,15 +501,16 @@ bool Pathfinder::pathfind(Std::vector<PathfindingAction> &path) {
 		debugC(kDebugPath, "Actor %u pathfinding to (%d, %d, %d)", _actor->getObjId(), _targetX, _targetY, _targetZ);
 	}
 
-#ifdef DEBUG
+#ifdef DEBUG_PATHFINDER
 	if (_actor->getObjId() == _visualDebugActor) {
-		RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
-		screen->BeginPainting();
-		if (_targetItem)
-			drawbox(_targetItem);
-		else
-			drawdot(_targetX, _targetY, _targetZ, 2, TEX32_PACK_RGB(0x00, 0x00, 0xFF));
-		screen->EndPainting();
+		Graphics::Screen *screen = Ultima8Engine::get_instance()->getScreen();
+		if (_targetItem) {
+			drawbox(screen, _targetItem);
+		} else {
+			uint32 color = screen->format.RGBToColor(0x00, 0x00, 0xFF);
+			drawdot(screen, _targetX, _targetY, _targetZ, 2, color);
+		}
+		screen->update();
 	}
 #endif
 
diff --git a/engines/ultima/ultima8/world/actors/pathfinder.h b/engines/ultima/ultima8/world/actors/pathfinder.h
index ec0a3e5199e..2021b6f51c2 100644
--- a/engines/ultima/ultima8/world/actors/pathfinder.h
+++ b/engines/ultima/ultima8/world/actors/pathfinder.h
@@ -26,6 +26,8 @@
 #include "ultima/ultima8/misc/direction.h"
 #include "ultima/ultima8/world/actors/animation.h"
 
+//#define DEBUG_PATHFINDER
+
 namespace Ultima {
 namespace Ultima8 {
 
@@ -77,7 +79,7 @@ public:
 	//! pathfind. If true, the found path is returned in path
 	bool pathfind(Std::vector<PathfindingAction> &path);
 
-#ifdef DEBUG
+#ifdef DEBUG_PATHFINDER
 	static ObjId _visualDebugActor;
 #endif
 




More information about the Scummvm-git-logs mailing list