[Scummvm-git-logs] scummvm master -> 6ffa76bb7f4023272a1a0a37627bc1df21bfd88c

somaen noreply at scummvm.org
Fri Sep 20 21:41:23 UTC 2024


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

Summary:
9e0711c213 WATCHMAKER: Refactor bounds loading slightly.
05fa9fe7eb WATCHMAKER: Refactor points in t3dPan to use PointXZ struct
ef9f200019 WATCHMAKER: Use PointXZ in t3dPATHNODE
023731a9cc WATCHMAKER: Remove unused global variable y3d
2b0a2b2f7a WATCHMAKER: Change t3dWALK::Look{X,Z} and t3dWalk::Cur{X,Z} into PointXZ
6ffa76bb7f WATCHMAKER: Remove global variables for returning from IntersLineLine


Commit: 9e0711c213ab6250f7b5e564f2ae31f0b2a2849d
    https://github.com/scummvm/scummvm/commit/9e0711c213ab6250f7b5e564f2ae31f0b2a2849d
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:31+02:00

Commit Message:
WATCHMAKER: Refactor bounds loading slightly.

Changed paths:
    engines/watchmaker/3d/t3d_body.cpp
    engines/watchmaker/walk/act.cpp


diff --git a/engines/watchmaker/3d/t3d_body.cpp b/engines/watchmaker/3d/t3d_body.cpp
index 0912e462c15..a6996830e07 100644
--- a/engines/watchmaker/3d/t3d_body.cpp
+++ b/engines/watchmaker/3d/t3d_body.cpp
@@ -254,14 +254,10 @@ void LoadCameras(WorkDirs &workDirs, const char *pname, t3dBODY *b) {
 }
 
 /* -----------------10/06/99 16.03-------------------
- *                      LoadBounds
+ *                      loadBounds
  * --------------------------------------------------*/
-void LoadBounds(WorkDirs &workDirs, const char *pname, t3dBODY *b) {
-	/*  FILE *f;*/
-	uint16  i, j, npan, nlev;
-	uint8   ver;
-
-	for (i = 0; i < T3D_MAX_LEVELS; i++)
+void loadBounds(WorkDirs &workDirs, const char *pname, t3dBODY *b) {
+	for (int i = 0; i < T3D_MAX_LEVELS; i++)
 		b->Panel[i] = nullptr;
 	b->CurLevel = 0;
 
@@ -270,22 +266,25 @@ void LoadBounds(WorkDirs &workDirs, const char *pname, t3dBODY *b) {
 		warning("File %s not found", pname);
 		return ;
 	}
-	if ((ver = stream->readByte()) != BNDFILEVERSION) {
+	uint8 ver = stream->readByte();
+	if (ver != BNDFILEVERSION) {
 		warning("BND File Version Error: loaded %d.\tRequired %d", ver, BNDFILEVERSION);
-		return ;
+		return;
 	}
-	b->NumLevels = nlev = stream->readSint16LE();
+	uint16 nlev = stream->readSint16LE();
+	b->NumLevels = nlev;
 	if (nlev > T3D_MAX_LEVELS) {
 		warning("Too much Floor Levels in %s: %d instead of %d", pname, b->NumLevels, T3D_MAX_LEVELS);
 		b->NumLevels = nlev = T3D_MAX_LEVELS;
 	}
 
-	for (j = 0; j < nlev; j++) {
-		b->NumPanels[j] = npan = stream->readSint16LE();
+	for (int j = 0; j < nlev; j++) {
+		uint16 npan = stream->readSint16LE();
+		b->NumPanels[j] = npan;
 		b->PanelHeight[j] = stream->readFloatLE() * SCALEFACTOR;
-		b->Panel[j] = new t3dPAN[npan + 4 * T3D_MAX_CHARACTERS];        // lascia anche un po' di spazio per eventuali aggiunte
+		b->Panel[j] = new t3dPAN[npan + 4 * T3D_MAX_CHARACTERS];        // also leave some space for any additions
 
-		for (i = 0; i < npan; i++) {
+		for (int i = 0; i < npan; i++) {
 			b->Panel[j][i].x1 = stream->readFloatLE() * SCALEFACTOR;
 			b->Panel[j][i].z1 = stream->readFloatLE() * SCALEFACTOR;
 			b->Panel[j][i].x2 = stream->readFloatLE() * SCALEFACTOR;
@@ -552,15 +551,7 @@ t3dBODY *t3dBODY::loadFromStream(WGame &game, const Common::String &pname, Commo
 	//decodeLoaderFlags(_LoaderFlags);
 	if (!(_LoaderFlags & T3D_NOBOUNDS)) {                                                        // Carica Bounds
 		auto bndName = workdirs.join(workdirs._bndDir, pname, "bnd");
-		/*
-		strcpy(Name, workdirs._bndDir.c_str());
-		strcat(Name, pname);
-		len = strlen(Name);
-		Name[len - 3] = 'b';
-		Name[len - 2] = 'n';
-		Name[len - 1] = 'd';
-		 */
-		LoadBounds(game.workDirs, bndName.c_str(), this);
+		loadBounds(game.workDirs, bndName.c_str(), this);
 	}
 	if (!(_LoaderFlags & T3D_NOCAMERAS)) {                                                       // Carica Camere
 		auto cameraName = constructPath(workdirs._camDir, pname, "cam");
diff --git a/engines/watchmaker/walk/act.cpp b/engines/watchmaker/walk/act.cpp
index 11e2c4d8fe2..ff9859c3647 100644
--- a/engines/watchmaker/walk/act.cpp
+++ b/engines/watchmaker/walk/act.cpp
@@ -585,7 +585,7 @@ int32 CheckPathNodes(int32 oc) {
  * --------------------------------------------------*/
 bool CheckCharacterWithBounds(WGame &game, int32 oc, t3dV3F *Pos, uint8 dp, uint8 back) {
 	t3dCHARACTER *Char = Character[oc];
-	int32 i, j, st;
+	int32 st;
 	t3dV3F tmp;
 	t3dPAN *p;
 
@@ -605,11 +605,11 @@ bool CheckCharacterWithBounds(WGame &game, int32 oc, t3dV3F *Pos, uint8 dp, uint
 		CurFloorY = t3dCurRoom->PanelHeight[t3dCurRoom->CurLevel];
 	}
 
-	for (i = 0; i < T3D_MAX_CHARACTERS; i++) {
-//		Se il personaggio non e' nascosto e ha pannelli, li aggiunge
+	for (int i = 0; i < T3D_MAX_CHARACTERS; i++) {
+		// If the character is not hidden and has panels, adds them
 		if (Character[i] && (Character[i] != Char) && !(Character[i]->Flags & (T3D_CHARACTER_HIDE | T3D_CHARACTER_BNDHIDE)) && (p = Character[i]->Body->Panel[0])) {
 			st = Char->Walk.PanelNum;
-			for (j = 0; j < Character[i]->Body->NumPanels[0]; j++, p++, Char->Walk.PanelNum++) {
+			for (int j = 0; j < Character[i]->Body->NumPanels[0]; j++, p++, Char->Walk.PanelNum++) {
 				tmp.x = p->x1;
 				tmp.y = CurFloorY;
 				tmp.z = p->z1;


Commit: 05fa9fe7ebb26d9b3051139f35292a229273a78f
    https://github.com/scummvm/scummvm/commit/05fa9fe7ebb26d9b3051139f35292a229273a78f
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:32+02:00

Commit Message:
WATCHMAKER: Refactor points in t3dPan to use PointXZ struct

Changed paths:
    engines/watchmaker/3d/geometry.cpp
    engines/watchmaker/3d/t3d_body.cpp
    engines/watchmaker/t3d.h
    engines/watchmaker/walk/act.cpp
    engines/watchmaker/walk/walk.cpp
    engines/watchmaker/walk/walkutil.cpp
    engines/watchmaker/walk/walkutil.h


diff --git a/engines/watchmaker/3d/geometry.cpp b/engines/watchmaker/3d/geometry.cpp
index 6d6c724aedf..3f056b510d4 100644
--- a/engines/watchmaker/3d/geometry.cpp
+++ b/engines/watchmaker/3d/geometry.cpp
@@ -1477,33 +1477,33 @@ void t3dShowBounds(t3dPAN *p, uint32 numpan) {
 	rBuildLinesViewMatrix(t3dCurViewMatrix, tmp);
 
 	for (j = 0; j < numpan; j++) {
-		VertPointer->x = p[j].x1;
+		VertPointer->x = p[j].a.x;
 		VertPointer->y = CurFloorY + 1.0f;
-		VertPointer->z = p[j].z1;
+		VertPointer->z = p[j].a.z;
 		VertPointer->diffuse = RGBA_MAKE(250, 0, 0, 255);
 		rAddPointArray();
 		VertPointer++;
 //		t3dNumVertices++;
 
-		VertPointer->x = p[j].x2;
+		VertPointer->x = p[j].b.x;
 		VertPointer->y = CurFloorY + 1.0f;
-		VertPointer->z = p[j].z2;
+		VertPointer->z = p[j].b.z;
 		VertPointer->diffuse = RGBA_MAKE(250, 0, 0, 255);
 		rAddPointArray();
 		VertPointer++;
 //		t3dNumVertices++;
 
-		VertPointer->x = p[j].bx1;
+		VertPointer->x = p[j].backA.x;
 		VertPointer->y = CurFloorY + 1.0f;
-		VertPointer->z = p[j].bz1;
+		VertPointer->z = p[j].backA.z;
 		VertPointer->diffuse = RGBA_MAKE(250, 0, 0, 255);
 		rAddPointArray();
 		VertPointer++;
 //		t3dNumVertices++;
 
-		VertPointer->x = p[j].bx2;
+		VertPointer->x = p[j].backB.x;
 		VertPointer->y = CurFloorY + 1.0f;
-		VertPointer->z = p[j].bz2;
+		VertPointer->z = p[j].backB.z;
 		VertPointer->diffuse = RGBA_MAKE(250, 0, 0, 255);
 		rAddPointArray();
 		VertPointer++;
diff --git a/engines/watchmaker/3d/t3d_body.cpp b/engines/watchmaker/3d/t3d_body.cpp
index a6996830e07..e13263e4f33 100644
--- a/engines/watchmaker/3d/t3d_body.cpp
+++ b/engines/watchmaker/3d/t3d_body.cpp
@@ -285,14 +285,14 @@ void loadBounds(WorkDirs &workDirs, const char *pname, t3dBODY *b) {
 		b->Panel[j] = new t3dPAN[npan + 4 * T3D_MAX_CHARACTERS];        // also leave some space for any additions
 
 		for (int i = 0; i < npan; i++) {
-			b->Panel[j][i].x1 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].z1 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].x2 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].z2 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].bx1 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].bz1 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].bx2 = stream->readFloatLE() * SCALEFACTOR;
-			b->Panel[j][i].bz2 = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].a.x = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].a.z = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].b.x = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].b.z = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].backA.x = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].backA.z = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].backB.x = stream->readFloatLE() * SCALEFACTOR;
+			b->Panel[j][i].backB.z = stream->readFloatLE() * SCALEFACTOR;
 			b->Panel[j][i].near1 = stream->readSint16LE();
 			b->Panel[j][i].near2 = stream->readSint16LE();
 		}
diff --git a/engines/watchmaker/t3d.h b/engines/watchmaker/t3d.h
index 7ee819d406e..07d6e5ff56a 100644
--- a/engines/watchmaker/t3d.h
+++ b/engines/watchmaker/t3d.h
@@ -325,11 +325,13 @@ public:
 	explicit t3dPLIGHT(Common::SeekableReadStream &stream);
 };
 
+struct PointXZ {
+	float x = 0.0f, z = 0.0f;
+};
+
 struct t3dPAN {
-	t3dF32 x1 = 0.0f, z1 = 0.0f;            // point A position
-	t3dF32 x2 = 0.0f, z2 = 0.0f;            // point B position
-	t3dF32 bx1 = 0.0f, bz1 = 0.0f;          // back to point A
-	t3dF32 bx2 = 0.0f, bz2 = 0.0f;          // back to point B
+	PointXZ a, b;                           // point A / B position
+	PointXZ backA, backB;                   // back to point A / B
 	uint16 near1 = 0;                       // panel near to A
 	uint16 near2 = 0;                       // panel near to B
 };
diff --git a/engines/watchmaker/walk/act.cpp b/engines/watchmaker/walk/act.cpp
index ff9859c3647..26001839ce8 100644
--- a/engines/watchmaker/walk/act.cpp
+++ b/engines/watchmaker/walk/act.cpp
@@ -60,10 +60,10 @@ void SlideChar(int32 oc) {
 	v.y = 0.0f;
 	v.z = w->LookZ;
 
-	x1 = w->Panel[w->CurPanel].x1;
-	z1 = w->Panel[w->CurPanel].z1;
-	x2 = w->Panel[w->CurPanel].x2;
-	z2 = w->Panel[w->CurPanel].z2;
+	x1 = w->Panel[w->CurPanel].a.x;
+	z1 = w->Panel[w->CurPanel].a.z;
+	x2 = w->Panel[w->CurPanel].b.x;
+	z2 = w->Panel[w->CurPanel].b.z;
 	if ((len = (x1 - x2) * (x1 - x2) + (z1 - z2) * (z1 - z2)) == 0) {
 		CharStop(oc);
 		return ;
@@ -565,8 +565,9 @@ int32 CheckPathNodes(int32 oc) {
 //	se interseca almeno un baffo si ferma!!
 	for (i = 1; i < w->NumPathNodes; i++) {
 		for (b = 0; b < w->PanelNum; b++) {
-			if (IntersLineLine(w->Panel[b].bx1, w->Panel[b].bz1, w->Panel[b].bx2, w->Panel[b].bz2,
-			                   w->PathNode[i - 1].x, w->PathNode[i - 1].z, w->PathNode[i].x, w->PathNode[i].z)) {
+			if (IntersLineLine(w->Panel[b].backA, w->Panel[b].backB,
+			                   w->PathNode[i - 1].x, w->PathNode[i - 1].z,
+			                   w->PathNode[i].x, w->PathNode[i].z)) {
 				w->NumPathNodes = i - 1;
 				w->CurPanel = w->PathNode[i - 1].curp;
 				w->NumSteps = 0;
@@ -610,37 +611,37 @@ bool CheckCharacterWithBounds(WGame &game, int32 oc, t3dV3F *Pos, uint8 dp, uint
 		if (Character[i] && (Character[i] != Char) && !(Character[i]->Flags & (T3D_CHARACTER_HIDE | T3D_CHARACTER_BNDHIDE)) && (p = Character[i]->Body->Panel[0])) {
 			st = Char->Walk.PanelNum;
 			for (int j = 0; j < Character[i]->Body->NumPanels[0]; j++, p++, Char->Walk.PanelNum++) {
-				tmp.x = p->x1;
+				tmp.x = p->a.x;
 				tmp.y = CurFloorY;
-				tmp.z = p->z1;
+				tmp.z = p->a.z;
 				t3dVectTransform(&tmp, &tmp, &Character[i]->Mesh->Matrix);
 				t3dVectAdd(&tmp, &tmp, &Character[i]->Mesh->Trasl);
-				Char->Walk.Panel[Char->Walk.PanelNum].x1 = tmp.x;
-				Char->Walk.Panel[Char->Walk.PanelNum].z1 = tmp.z;
+				Char->Walk.Panel[Char->Walk.PanelNum].a.x = tmp.x;
+				Char->Walk.Panel[Char->Walk.PanelNum].a.z = tmp.z;
 
-				tmp.x = p->x2;
+				tmp.x = p->b.x;
 				tmp.y = CurFloorY;
-				tmp.z = p->z2;
+				tmp.z = p->b.z;
 				t3dVectTransform(&tmp, &tmp, &Character[i]->Mesh->Matrix);
 				t3dVectAdd(&tmp, &tmp, &Character[i]->Mesh->Trasl);
-				Char->Walk.Panel[Char->Walk.PanelNum].x2 = tmp.x;
-				Char->Walk.Panel[Char->Walk.PanelNum].z2 = tmp.z;
+				Char->Walk.Panel[Char->Walk.PanelNum].b.x = tmp.x;
+				Char->Walk.Panel[Char->Walk.PanelNum].b.z = tmp.z;
 
-				tmp.x = p->bx1;
+				tmp.x = p->backA.x;
 				tmp.y = CurFloorY;
-				tmp.z = p->bz1;
+				tmp.z = p->backA.z;
 				t3dVectTransform(&tmp, &tmp, &Character[i]->Mesh->Matrix);
 				t3dVectAdd(&tmp, &tmp, &Character[i]->Mesh->Trasl);
-				Char->Walk.Panel[Char->Walk.PanelNum].bx1 = tmp.x;
-				Char->Walk.Panel[Char->Walk.PanelNum].bz1 = tmp.z;
+				Char->Walk.Panel[Char->Walk.PanelNum].backA.x = tmp.x;
+				Char->Walk.Panel[Char->Walk.PanelNum].backA.z = tmp.z;
 
-				tmp.x = p->bx2;
+				tmp.x = p->backB.x;
 				tmp.y = CurFloorY;
-				tmp.z = p->bz2;
+				tmp.z = p->backB.z;
 				t3dVectTransform(&tmp, &tmp, &Character[i]->Mesh->Matrix);
 				t3dVectAdd(&tmp, &tmp, &Character[i]->Mesh->Trasl);
-				Char->Walk.Panel[Char->Walk.PanelNum].bx2 = tmp.x;
-				Char->Walk.Panel[Char->Walk.PanelNum].bz2 = tmp.z;
+				Char->Walk.Panel[Char->Walk.PanelNum].backB.x = tmp.x;
+				Char->Walk.Panel[Char->Walk.PanelNum].backB.z = tmp.z;
 
 				Char->Walk.Panel[Char->Walk.PanelNum].near1 = p->near1 + st;
 				Char->Walk.Panel[Char->Walk.PanelNum].near2 = p->near2 + st;
diff --git a/engines/watchmaker/walk/walk.cpp b/engines/watchmaker/walk/walk.cpp
index a00afffd3f6..defb48b1e65 100644
--- a/engines/watchmaker/walk/walk.cpp
+++ b/engines/watchmaker/walk/walk.cpp
@@ -110,7 +110,7 @@ int FindAttachedPanel(int32 oc, int srcp, int destp) {
 void PointOut(int32 oc, t3dCAMERA *Camera) {
 	t3dCHARACTER *Act = Character[oc];
 	t3dWALK *w = &Act->Walk;
-	float x = 0, z = 0;
+	PointXZ p;
 	float inters;
 	float temp;
 	float nx, nz;
@@ -124,8 +124,8 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 	if (w->CurPanel < 0)
 		return;
 
-	nx = w->Panel[w->CurPanel].z1 - w->Panel[w->CurPanel].z2;
-	nz = w->Panel[w->CurPanel].x2 - w->Panel[w->CurPanel].x1;
+	nx = w->Panel[w->CurPanel].a.z - w->Panel[w->CurPanel].b.z;
+	nz = w->Panel[w->CurPanel].b.x - w->Panel[w->CurPanel].a.x;
 	temp = (t3dF32)sqrt(nx * nx + nz * nz);
 	nx /= temp;
 	nz /= temp;
@@ -137,50 +137,48 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 //			( Panel[b].flags & (Panel[CurPanel].flags & 0x7FFFFFFF) ) )
 		{
 			// controlla pto 1
-			temp = DistF(w->CurX, w->CurZ, w->Panel[b].x1, w->Panel[b].z1);
+			temp = DistF(w->CurX, w->CurZ, w->Panel[b].a.x, w->Panel[b].a.z);
 
 			if (temp < inters) {
 				inters = temp;
 				w->CurPanel = b;
-				x = w->Panel[b].x1;
-				z = w->Panel[b].z1;
+				p = w->Panel[b].a;
 			}
 
 			// controlla pto 2
-			temp = DistF(w->CurX, w->CurZ, w->Panel[b].x2, w->Panel[b].z2);
+			temp = DistF(w->CurX, w->CurZ, w->Panel[b].b.x, w->Panel[b].b.z);
 
 			if (temp < inters) {
 				inters = temp;
 				w->CurPanel = b;
-				x = w->Panel[b].x2;
-				z = w->Panel[b].z2;
+				p = w->Panel[b].b;
 			}
 
 			// controlla intersezione con camera
-			if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1,
-			                   w->Panel[b].x2, w->Panel[b].z2,
-			                   Camera->Source.x, Camera->Source.z, w->CurX, w->CurZ)) {
+			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                   Camera->Source.x, Camera->Source.z,
+			                   w->CurX, w->CurZ)) {
 				temp = DistF(w->CurX, w->CurZ, x3d, z3d);
 
 				if (temp < inters) {
 					inters = temp;
 					w->CurPanel = b;
-					x = x3d;
-					z = z3d;
+					p.x = x3d;
+					p.z = z3d;
 				}
 			}
 
 			// controlla intersezione con omino
-			if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1,
-			                   w->Panel[b].x2, w->Panel[b].z2,
-			                   Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ)) {
+			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                   Act->Pos.x, Act->Pos.z,
+			                   w->CurX, w->CurZ)) {
 				temp = DistF(w->CurX, w->CurZ, x3d, z3d);
 
 				if (temp < inters) {
 					inters = temp;
 					w->CurPanel = b;
-					x = x3d;
-					z = z3d;
+					p.x = x3d;
+					p.z = z3d;
 				}
 			}
 
@@ -204,8 +202,8 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 		}
 	}
 
-	w->CurX = x;
-	w->CurZ = z;
+	w->CurX = p.x;
+	w->CurZ = p.z;
 
 #undef LARGEVAL
 }
@@ -213,10 +211,11 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 /*-----------------15/10/96 14.23-------------------
             Valuta lunghezza percorso
 --------------------------------------------------*/
-float EvalPath(int32 oc, int a, float destx, float destz, int nearp) {
+float EvalPath(int32 oc, int a, PointXZ dest, int nearp) {
 	t3dCHARACTER *Act = Character[oc];
 	t3dWALK *w = &Act->Walk;
-	float curx, curz, len;
+	float len;
+	PointXZ cur;
 	int b;
 	int curp;
 
@@ -225,13 +224,13 @@ float EvalPath(int32 oc, int a, float destx, float destz, int nearp) {
 	len = 0.0;
 
 	curp = w->PathNode[a].curp;
-	curx = w->PathNode[a].x;
-	curz = w->PathNode[a].z;
+	cur.x = w->PathNode[a].x;
+	cur.z = w->PathNode[a].z;
 
 	for (;;) {
 		// se raggiunge il pto esce
 		if (curp == w->PathNode[a + 1].curp) {
-			len += DistF(curx, curz, w->PathNode[a + 1].x, w->PathNode[a + 1].z);
+			len += DistF(cur.x, cur.z, w->PathNode[a + 1].x, w->PathNode[a + 1].z);
 			break;
 		}
 
@@ -246,25 +245,21 @@ float EvalPath(int32 oc, int a, float destx, float destz, int nearp) {
 		// se nearp e' attacato a curp col vertice 1
 		if (w->Panel[nearp].near1 == curp) {
 			// vai al vertice 2 la prossima volta
-			len += DistF(curx, curz, destx, destz);
+			len += DistF(cur, dest);
 
-			curx = destx;
-			curz = destz;
+			cur = dest;
 
-			destx = w->Panel[nearp].x2;
-			destz = w->Panel[nearp].z2;
+			dest = w->Panel[nearp].b;
 
 			curp  = nearp;
 			nearp = w->Panel[curp].near2;
 		} else {
 			// vai al vertice 1 la prossima volta
-			len += DistF(curx, curz, destx, destz);
+			len += DistF(cur, dest);
 
-			curx = destx;
-			curz = destz;
+			cur = dest;
 
-			destx = w->Panel[nearp].x1;
-			destz = w->Panel[nearp].z1;
+			dest = w->Panel[nearp].a;
 
 			curp  = nearp;
 			nearp = w->Panel[curp].near1;
@@ -286,9 +281,9 @@ void FindShortPath(int32 oc) {
 	t3dPATHNODE TempPath[T3D_MAX_PATHNODES];
 	int    count = 0, inters;
 	float  len1, len2;
-	float  curx, curz;
+	PointXZ cur;
 	int    curp, nearp, oldp;
-	float  destx, destz;
+	PointXZ dest;
 	signed int    a, b, c, fail = 0;
 
 	count = 0;
@@ -313,25 +308,23 @@ void FindShortPath(int32 oc) {
 			continue;
 
 		// aggira l'ostacolo partendo da near1
-		len1 = EvalPath(oc, a, w->Panel[curp].x1, w->Panel[curp].z1, w->Panel[curp].near1) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].x1, w->Panel[curp].z1);
+		len1 = EvalPath(oc, a, w->Panel[curp].a, w->Panel[curp].near1) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].a.x, w->Panel[curp].a.z);
 
 		// aggira l'ostacolo partendo da near2
-		len2 = EvalPath(oc, a, w->Panel[curp].x2, w->Panel[curp].z2, w->Panel[curp].near2) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].x2, w->Panel[curp].z2);
+		len2 = EvalPath(oc, a, w->Panel[curp].b, w->Panel[curp].near2) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].b.x, w->Panel[curp].b.z);
 
 		// guarda quale starda era piu' breve e se esiste una strada
 		if ((len1 < 320000.0) && (len2 < 320000.0)) {
 			if (len1 < len2) {
-				destx = w->Panel[curp].x1;
-				destz = w->Panel[curp].z1;
+				dest = w->Panel[curp].a;
 				nearp = w->Panel[curp].near1;
 			} else {
-				destx = w->Panel[curp].x2;
-				destz = w->Panel[curp].z2;
+				dest = w->Panel[curp].b;
 				nearp = w->Panel[curp].near2;
 			}
 
-			curx = w->PathNode[a].x;
-			curz = w->PathNode[a].z;
+			cur.x = w->PathNode[a].x;
+			cur.z = w->PathNode[a].z;
 			oldp = curp;
 
 			b = 0;
@@ -339,8 +332,8 @@ void FindShortPath(int32 oc) {
 			// salva percorso piu corto
 			for (;;) {
 
-				TempPath[count].x = curx;
-				TempPath[count].z = curz;
+				TempPath[count].x = cur.x;
+				TempPath[count].z = cur.z;
 				TempPath[count].oldp = oldp;
 				TempPath[count].curp = curp;
 				count ++;
@@ -366,22 +359,18 @@ void FindShortPath(int32 oc) {
 				// se nearp e' attacato a curp col vertice 1
 				if (w->Panel[nearp].near1 == curp) {
 					// vai al vertice 2 la prossima volta
-					curx = destx;
-					curz = destz;
+					cur = dest;
 
-					destx = w->Panel[nearp].x2;
-					destz = w->Panel[nearp].z2;
+					dest = w->Panel[nearp].b;
 
 					oldp  = curp;
 					curp  = nearp;
 					nearp = w->Panel[curp].near2;
 				} else {
 					// vai al vertice 1 la prossima volta
-					curx = destx;
-					curz = destz;
+					cur = dest;
 
-					destx = w->Panel[nearp].x1;
-					destz = w->Panel[nearp].z1;
+					dest = w->Panel[nearp].a;
 
 					oldp  = curp;
 					curp  = nearp;
@@ -438,14 +427,12 @@ void FindShortPath(int32 oc) {
 				// non deve intersecare pannello stretto mai
 //				if( !( w->Panel[c].flags & 0x80000000 ) )
 				{
-					if (IntersLineLine(w->Panel[c].bx1, w->Panel[c].bz1,
-					                   w->Panel[c].bx2, w->Panel[c].bz2,
+					if (IntersLineLine(w->Panel[c].backA, w->Panel[c].backB,
 					                   TempPath[a].x, TempPath[a].z,
 					                   TempPath[b].x, TempPath[b].z))
 						inters ++;
 
-					if (IntersLineLine(w->Panel[c].x1, w->Panel[c].z1,
-					                   w->Panel[c].bx1, w->Panel[c].bz1,
+					if (IntersLineLine(w->Panel[c].a, w->Panel[c].backA,
 					                   TempPath[a].x, TempPath[a].z,
 					                   TempPath[b].x, TempPath[b].z)) {
 						len2 = DistF(x3d, z3d, TempPath[a].x, TempPath[a].z);
@@ -456,8 +443,7 @@ void FindShortPath(int32 oc) {
 							inters ++;
 					}
 
-					if (IntersLineLine(w->Panel[c].x2, w->Panel[c].z2,
-					                   w->Panel[c].bx2, w->Panel[c].bz2,
+					if (IntersLineLine(w->Panel[c].b, w->Panel[c].backB,
 					                   TempPath[a].x, TempPath[a].z,
 					                   TempPath[b].x, TempPath[b].z)) {
 						len2 = DistF(x3d, z3d, TempPath[a].x, TempPath[a].z);
@@ -533,10 +519,10 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 	        // dietro il pannello di partenza
 	        ((PointInside(oc, b = w->OldPanel, (double)w->CurX, (double)w->CurZ)) ||
 	         // dietro il pannello angolo1
-	         ((DistF(w->Panel[w->OldPanel].x1, w->Panel[w->OldPanel].z1, Act->Pos.x, Act->Pos.z) < EPSILON) &&
+	         ((DistF(w->Panel[w->OldPanel].a.x, w->Panel[w->OldPanel].a.z, Act->Pos.x, Act->Pos.z) < EPSILON) &&
 	          (PointInside(oc, b = w->Panel[w->OldPanel].near1, (double)w->CurX, (double)w->CurZ))) ||
 	         // dietro il pannello angolo2
-	         ((DistF(w->Panel[w->OldPanel].x2, w->Panel[w->OldPanel].z2, Act->Pos.x, Act->Pos.z) < EPSILON) &&
+	         ((DistF(w->Panel[w->OldPanel].b.x, w->Panel[w->OldPanel].b.z, Act->Pos.x, Act->Pos.z) < EPSILON) &&
 	          (PointInside(oc, b = w->Panel[w->OldPanel].near2, (double)w->CurX, (double)w->CurZ))))) {
 		w->CurX = Act->Pos.x;
 		w->CurZ = Act->Pos.z;
@@ -553,11 +539,11 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 //		return ;
 
 	for (b = 0; b < w->PanelNum; b++) {
-		if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1,
-		                   w->Panel[b].x2, w->Panel[b].z2,
-		                   Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ)) {
+		if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+		                   Act->Pos.x, Act->Pos.z,
+		                   w->CurX, w->CurZ)) {
 			inters ++;
-			DebugLogFile("Inters %d: %f %f %f %f", b, w->Panel[b].x1, w->Panel[b].z1, w->Panel[b].x2, w->Panel[b].z2);
+			DebugLogFile("Inters %d: %f %f %f %f", b, w->Panel[b].a.x, w->Panel[b].a.z, w->Panel[b].b.x, w->Panel[b].b.z);
 
 			w->PathNode[w->NumPathNodes].x    = x3d;
 			w->PathNode[w->NumPathNodes].z    = z3d;
@@ -674,24 +660,21 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			// conto intersezioni con pannelli stretti
 			// e con unione pannelli larghi con pannelli stretti
 			for (b = 0; b < w->PanelNum; b++) {
-				if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1,
-				                   w->Panel[b].x2, w->Panel[b].z2,
+				if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
 				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
 				                   w->CurX, w->CurZ))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
 					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
 						inters ++;
 
-				if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1,
-				                   w->Panel[b].bx1, w->Panel[b].bz1,
+				if (IntersLineLine(w->Panel[b].a, w->Panel[b].backA,
 				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
 				                   w->CurX, w->CurZ))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
 					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
 						inters ++;
 
-				if (IntersLineLine(w->Panel[b].x2, w->Panel[b].z2,
-				                   w->Panel[b].bx2, w->Panel[b].bz2,
+				if (IntersLineLine(w->Panel[b].b, w->Panel[b].backB,
 				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
 				                   w->CurX, w->CurZ))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
@@ -788,8 +771,9 @@ void ForceAnimInBounds(int32 oc) {
 				DebugLogFile("Aggiorno CurPanel %d", b);
 			}
 //			Se un punto interseca pannello slida
-			if (IntersLineLine(w->Panel[b].x1, w->Panel[b].z1, w->Panel[b].x2, w->Panel[b].z2,
-			                   Trasl[0].x, Trasl[0].z, Trasl[a].x, Trasl[a].z)) {
+			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                   Trasl[0].x, Trasl[0].z,
+			                   Trasl[a].x, Trasl[a].z)) {
 				inters ++;
 
 				Trasl[a].x = x3d;
diff --git a/engines/watchmaker/walk/walkutil.cpp b/engines/watchmaker/walk/walkutil.cpp
index 68b15b4b3f6..2dc003af9ea 100644
--- a/engines/watchmaker/walk/walkutil.cpp
+++ b/engines/watchmaker/walk/walkutil.cpp
@@ -76,16 +76,16 @@ int PointInside(int32 oc, int32 pan, double x, double z) {
 	if (pan < 0)
 		return FALSE;
 
-	pgon[0][0] = (double)w->Panel[pan].x1;
-	pgon[0][1] = (double)w->Panel[pan].z1;
-	pgon[3][0] = (double)w->Panel[pan].x2;
-	pgon[3][1] = (double)w->Panel[pan].z2;
+	pgon[0][0] = (double)w->Panel[pan].a.x;
+	pgon[0][1] = (double)w->Panel[pan].a.z;
+	pgon[3][0] = (double)w->Panel[pan].b.x;
+	pgon[3][1] = (double)w->Panel[pan].b.z;
 
-	pgon[1][0] = (double)w->Panel[pan].bx1;
-	pgon[1][1] = (double)w->Panel[pan].bz1;
+	pgon[1][0] = (double)w->Panel[pan].backA.x;
+	pgon[1][1] = (double)w->Panel[pan].backA.z;
 
-	pgon[2][0] = (double)w->Panel[pan].bx2;
-	pgon[2][1] = (double)w->Panel[pan].bz2;
+	pgon[2][0] = (double)w->Panel[pan].backB.x;
+	pgon[2][1] = (double)w->Panel[pan].backB.z;
 
 	ox = pgon[3][0] - pgon[0][0];
 	oz = pgon[3][1] - pgon[0][1];
@@ -113,6 +113,10 @@ int PointInside(int32 oc, int32 pan, double x, double z) {
 /*-----------------07/10/96 11.14-------------------
             Distanza falsa tra 2 punti 2D
 --------------------------------------------------*/
+float DistF(PointXZ a, PointXZ b) {
+	return DistF(a.x, a.z, b.x, b.z);
+}
+
 float DistF(float x1, float y1, float x2, float y2) {
 	float d1 = (float)fabs(x1 - x2);
 	float d2 = (float)fabs(y1 - y2);
@@ -131,6 +135,9 @@ float DistF(float x1, float y1, float x2, float y2) {
 /*-----------------07/10/96 11.21-------------------
         Interseca linea 2D con linea 2D
 --------------------------------------------------*/
+int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd) {
+	return IntersLineLine(a.x, a.z, b.x, b.z, xc, yc, xd, yd);
+}
 int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) {
 	float r, s, divisor;
 
diff --git a/engines/watchmaker/walk/walkutil.h b/engines/watchmaker/walk/walkutil.h
index cb9a547f550..353623ddec7 100644
--- a/engines/watchmaker/walk/walkutil.h
+++ b/engines/watchmaker/walk/walkutil.h
@@ -31,7 +31,9 @@ t3dF32 SinCosAngle(t3dF32 sinus, t3dF32 cosinus);
 t3dF32 t3dVectAngle(t3dV3F *n, t3dV3F *o);
 int PointInside(int32 oc, int32 pan, double x, double z);
 bool PointInside2DRectangle(double pgon[4][2], double x, double z);
+float DistF(PointXZ a, PointXZ b);
 float DistF(float x1, float y1, float x2, float y2);
+int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd);
 int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
 int PathCompare(const void *arg1, const void *arg2);
 void SortPath(int32 oc);


Commit: ef9f200019db53b2b4e4220c824214c8be591463
    https://github.com/scummvm/scummvm/commit/ef9f200019db53b2b4e4220c824214c8be591463
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:32+02:00

Commit Message:
WATCHMAKER: Use PointXZ in t3dPATHNODE

Changed paths:
    engines/watchmaker/t3d.h
    engines/watchmaker/walk/act.cpp
    engines/watchmaker/walk/walk.cpp
    engines/watchmaker/walk/walkutil.cpp
    engines/watchmaker/walk/walkutil.h


diff --git a/engines/watchmaker/t3d.h b/engines/watchmaker/t3d.h
index 07d6e5ff56a..2f961b0730e 100644
--- a/engines/watchmaker/t3d.h
+++ b/engines/watchmaker/t3d.h
@@ -337,7 +337,7 @@ struct t3dPAN {
 };
 
 struct t3dPATHNODE {
-	float x = 0.0f, z = 0.0f;                   // path node position
+	PointXZ pos;                                // path node position
 	float dist = 0.0f;                          // distance from start
 	short oldp = 0;                             // last panel hit
 	short curp = 0;                             // cur panel hit
diff --git a/engines/watchmaker/walk/act.cpp b/engines/watchmaker/walk/act.cpp
index 26001839ce8..64796646f8d 100644
--- a/engines/watchmaker/walk/act.cpp
+++ b/engines/watchmaker/walk/act.cpp
@@ -274,8 +274,8 @@ void CheckCharacterWithoutBounds(WGame &game, int32 oc, const uint8 *dpl, uint8
 	t3dVectCopy(&Char->Pos, &Char->Mesh->Trasl);
 
 	w->NumPathNodes = 0;
-	w->PathNode[w->NumPathNodes].x = Char->Pos.x;
-	w->PathNode[w->NumPathNodes].z = Char->Pos.z;
+	w->PathNode[w->NumPathNodes].pos.x = Char->Pos.x;
+	w->PathNode[w->NumPathNodes].pos.z = Char->Pos.z;
 	w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 	w->PathNode[w->NumPathNodes].curp = -1;
 	w->PathNode[w->NumPathNodes].dist = 0.0f;
@@ -286,8 +286,8 @@ void CheckCharacterWithoutBounds(WGame &game, int32 oc, const uint8 *dpl, uint8
 	dp = 0;
 	while (*dpl && GetLightPosition(&tmp, *dpl)) {
 		dp = *dpl++;
-		w->PathNode[w->NumPathNodes].x = tmp.x;
-		w->PathNode[w->NumPathNodes].z = tmp.z;
+		w->PathNode[w->NumPathNodes].pos.x = tmp.x;
+		w->PathNode[w->NumPathNodes].pos.z = tmp.z;
 		w->PathNode[w->NumPathNodes].oldp = -1;
 		w->PathNode[w->NumPathNodes].curp = -1;
 		w->PathNode[w->NumPathNodes].dist = t3dVectDistance(&tmp, &Char->Pos);
@@ -361,12 +361,12 @@ void BuildStepList(int32 oc, uint8 dp, uint8 back) {
 	lastangle = SinCosAngle(Ch->Dir.x, Ch->Dir.z);
 //	calcola lunghezza totale del percorso
 	for (i = 0; i < w->NumPathNodes - 1; i++) {
-		st.x = w->PathNode[i].x;
+		st.x = w->PathNode[i].pos.x;
 		st.y = 0.0;
-		st.z = w->PathNode[i].z;
-		en.x = w->PathNode[i + 1].x;
+		st.z = w->PathNode[i].pos.z;
+		en.x = w->PathNode[i + 1].pos.x;
 		en.y = 0.0;
-		en.z = w->PathNode[i + 1].z;
+		en.z = w->PathNode[i + 1].pos.z;
 
 		len += t3dVectDistance(&st, &en);               // dist of two points
 	}
@@ -375,7 +375,7 @@ void BuildStepList(int32 oc, uint8 dp, uint8 back) {
 
 //	Cerca di capire se gli conviene andare avanti o indietro
 	if (back >= 10) {
-		t3dVectInit(&st, w->PathNode[1].x - w->PathNode[0].x, 0.0f, w->PathNode[1].z - w->PathNode[0].z);
+		t3dVectInit(&st, w->PathNode[1].pos.x - w->PathNode[0].pos.x, 0.0f, w->PathNode[1].pos.z - w->PathNode[0].pos.z);
 
 		if (!(w->Check & LONGPATH) && (fabs(t3dVectAngle(&Ch->Dir, &st)) > 145.0f)) {        // devo andare dietro
 //			DebugFile("Back %f\n%f %f | %f %f\n",t3dVectAngle( &Ch->Dir, &st ),Ch->Dir.x,Ch->Dir.z,st.x,st.z);
@@ -447,18 +447,18 @@ void BuildStepList(int32 oc, uint8 dp, uint8 back) {
 	w->CurrentStep = 0;
 
 	w->WalkSteps[w->NumSteps].Angle = lastangle;
-	w->WalkSteps[w->NumSteps].Pos.x = w->PathNode[0].x;
+	w->WalkSteps[w->NumSteps].Pos.x = w->PathNode[0].pos.x;
 	w->WalkSteps[w->NumSteps].Pos.y = CurFloorY;
-	w->WalkSteps[w->NumSteps].Pos.z = w->PathNode[0].z;
+	w->WalkSteps[w->NumSteps].Pos.z = w->PathNode[0].pos.z;
 	w->WalkSteps[w->NumSteps++].curp = w->OldPanel;
 
 	for (i = 0; i < w->NumPathNodes - 1; i++) {
-		st.x = w->PathNode[i].x;
+		st.x = w->PathNode[i].pos.x;
 		st.y = 0.0;
-		st.z = w->PathNode[i].z;
-		en.x = w->PathNode[i + 1].x;
+		st.z = w->PathNode[i].pos.z;
+		en.x = w->PathNode[i + 1].pos.x;
 		en.y = 0.0;
-		en.z = w->PathNode[i + 1].z;
+		en.z = w->PathNode[i + 1].pos.z;
 
 		len += t3dVectDistance(&st, &en);               // dist of two points
 		t3dVectSub(&direction, &en, &st);
@@ -566,8 +566,7 @@ int32 CheckPathNodes(int32 oc) {
 	for (i = 1; i < w->NumPathNodes; i++) {
 		for (b = 0; b < w->PanelNum; b++) {
 			if (IntersLineLine(w->Panel[b].backA, w->Panel[b].backB,
-			                   w->PathNode[i - 1].x, w->PathNode[i - 1].z,
-			                   w->PathNode[i].x, w->PathNode[i].z)) {
+			                   w->PathNode[i - 1].pos, w->PathNode[i].pos)) {
 				w->NumPathNodes = i - 1;
 				w->CurPanel = w->PathNode[i - 1].curp;
 				w->NumSteps = 0;
diff --git a/engines/watchmaker/walk/walk.cpp b/engines/watchmaker/walk/walk.cpp
index defb48b1e65..7fa7ef68bdb 100644
--- a/engines/watchmaker/walk/walk.cpp
+++ b/engines/watchmaker/walk/walk.cpp
@@ -224,13 +224,12 @@ float EvalPath(int32 oc, int a, PointXZ dest, int nearp) {
 	len = 0.0;
 
 	curp = w->PathNode[a].curp;
-	cur.x = w->PathNode[a].x;
-	cur.z = w->PathNode[a].z;
+	cur = w->PathNode[a].pos;
 
 	for (;;) {
 		// se raggiunge il pto esce
 		if (curp == w->PathNode[a + 1].curp) {
-			len += DistF(cur.x, cur.z, w->PathNode[a + 1].x, w->PathNode[a + 1].z);
+			len += DistF(cur, w->PathNode[a + 1].pos);
 			break;
 		}
 
@@ -288,8 +287,8 @@ void FindShortPath(int32 oc) {
 
 	count = 0;
 	// aggiunge partenza
-	TempPath[count].x = Act->Pos.x;
-	TempPath[count].z = Act->Pos.z;
+	TempPath[count].pos.x = Act->Pos.x;
+	TempPath[count].pos.z = Act->Pos.z;
 	TempPath[count].dist = 0.0;
 	TempPath[count].oldp = w->OldPanel;
 	TempPath[count].curp = w->OldPanel;
@@ -308,10 +307,10 @@ void FindShortPath(int32 oc) {
 			continue;
 
 		// aggira l'ostacolo partendo da near1
-		len1 = EvalPath(oc, a, w->Panel[curp].a, w->Panel[curp].near1) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].a.x, w->Panel[curp].a.z);
+		len1 = EvalPath(oc, a, w->Panel[curp].a, w->Panel[curp].near1) + DistF(w->PathNode[a].pos, w->Panel[curp].a);
 
 		// aggira l'ostacolo partendo da near2
-		len2 = EvalPath(oc, a, w->Panel[curp].b, w->Panel[curp].near2) + DistF(w->PathNode[a].x, w->PathNode[a].z, w->Panel[curp].b.x, w->Panel[curp].b.z);
+		len2 = EvalPath(oc, a, w->Panel[curp].b, w->Panel[curp].near2) + DistF(w->PathNode[a].pos,w->Panel[curp].b);
 
 		// guarda quale starda era piu' breve e se esiste una strada
 		if ((len1 < 320000.0) && (len2 < 320000.0)) {
@@ -323,8 +322,7 @@ void FindShortPath(int32 oc) {
 				nearp = w->Panel[curp].near2;
 			}
 
-			cur.x = w->PathNode[a].x;
-			cur.z = w->PathNode[a].z;
+			cur = w->PathNode[a].pos;
 			oldp = curp;
 
 			b = 0;
@@ -332,8 +330,7 @@ void FindShortPath(int32 oc) {
 			// salva percorso piu corto
 			for (;;) {
 
-				TempPath[count].x = cur.x;
-				TempPath[count].z = cur.z;
+				TempPath[count].pos = cur;
 				TempPath[count].oldp = oldp;
 				TempPath[count].curp = curp;
 				count ++;
@@ -390,15 +387,15 @@ void FindShortPath(int32 oc) {
 	}
 
 	// aggiunge arrivo
-	TempPath[count].x = w->CurX;
-	TempPath[count].z = w->CurZ;
+	TempPath[count].pos.x = w->CurX;
+	TempPath[count].pos.z = w->CurZ;
 	TempPath[count].dist = 0.0;
 	TempPath[count].oldp = w->CurPanel;
 	TempPath[count].curp = w->CurPanel;
 	count ++;
 
 	for (b = 0; b < count; b++)
-		DebugLogFile("FSP %d: %f %f | %d %d", b, TempPath[b].x, TempPath[b].z, TempPath[b].oldp, TempPath[b].curp);
+		DebugLogFile("FSP %d: %f %f | %d %d", b, TempPath[b].pos.x, TempPath[b].pos.z, TempPath[b].oldp, TempPath[b].curp);
 	// dopo che ha aggirato tutti gli ostacoli ottimizza
 
 //	memcpy( w->PathNode, TempPath, sizeof( struct SPathNode )*count );
@@ -413,7 +410,7 @@ void FindShortPath(int32 oc) {
 
 		// prima leva tutti i nodi attaccati
 		for (b = (count - 1); b >= a; b--)
-			if (DistF(TempPath[b].x, TempPath[b].z, TempPath[a].x, TempPath[a].z) < EPSILON)
+			if (DistF(TempPath[b].pos, TempPath[a].pos) < EPSILON)
 				break;
 		DebugLogFile("Da %d passo a %d\n", a, b);
 		a = b;
@@ -428,15 +425,13 @@ void FindShortPath(int32 oc) {
 //				if( !( w->Panel[c].flags & 0x80000000 ) )
 				{
 					if (IntersLineLine(w->Panel[c].backA, w->Panel[c].backB,
-					                   TempPath[a].x, TempPath[a].z,
-					                   TempPath[b].x, TempPath[b].z))
+					                   TempPath[a].pos, TempPath[b].pos))
 						inters ++;
 
 					if (IntersLineLine(w->Panel[c].a, w->Panel[c].backA,
-					                   TempPath[a].x, TempPath[a].z,
-					                   TempPath[b].x, TempPath[b].z)) {
-						len2 = DistF(x3d, z3d, TempPath[a].x, TempPath[a].z);
-						len1 = DistF(x3d, z3d, TempPath[b].x, TempPath[b].z);
+					                   TempPath[a].pos, TempPath[b].pos)) {
+						len2 = DistF(x3d, z3d, TempPath[a].pos.x, TempPath[a].pos.z);
+						len1 = DistF(x3d, z3d, TempPath[b].pos.x, TempPath[b].pos.z);
 
 						// interseca in un pto distante da partenza e arrivo
 						if ((len1 > EPSILON) && (len2 > EPSILON))
@@ -444,10 +439,9 @@ void FindShortPath(int32 oc) {
 					}
 
 					if (IntersLineLine(w->Panel[c].b, w->Panel[c].backB,
-					                   TempPath[a].x, TempPath[a].z,
-					                   TempPath[b].x, TempPath[b].z)) {
-						len2 = DistF(x3d, z3d, TempPath[a].x, TempPath[a].z);
-						len1 = DistF(x3d, z3d, TempPath[b].x, TempPath[b].z);
+					                   TempPath[a].pos, TempPath[b].pos)) {
+						len2 = DistF(x3d, z3d, TempPath[a].pos.x, TempPath[a].pos.z);
+						len1 = DistF(x3d, z3d, TempPath[b].pos.x, TempPath[b].pos.z);
 
 						// interseca in un pto distante da partenza e arrivo
 						if ((len1 > EPSILON) && (len2 > EPSILON))
@@ -480,7 +474,7 @@ void FindShortPath(int32 oc) {
 		}
 	}
 	for (b = 0; b < w->NumPathNodes; b++)
-		DebugLogFile("SSP %d: %f %f | %d %d", b, w->PathNode[b].x, w->PathNode[b].z, w->PathNode[b].oldp, w->PathNode[b].curp);
+		DebugLogFile("SSP %d: %f %f | %d %d", b, w->PathNode[b].pos.x, w->PathNode[b].pos.z, w->PathNode[b].oldp, w->PathNode[b].curp);
 }
 
 /* -----------------04/02/98 15.48-------------------
@@ -545,8 +539,8 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			inters ++;
 			DebugLogFile("Inters %d: %f %f %f %f", b, w->Panel[b].a.x, w->Panel[b].a.z, w->Panel[b].b.x, w->Panel[b].b.z);
 
-			w->PathNode[w->NumPathNodes].x    = x3d;
-			w->PathNode[w->NumPathNodes].z    = z3d;
+			w->PathNode[w->NumPathNodes].pos.x = x3d;
+			w->PathNode[w->NumPathNodes].pos.z = z3d;
 			w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, x3d, z3d);
 			w->PathNode[w->NumPathNodes].oldp = b;
 			w->PathNode[w->NumPathNodes].curp = b;
@@ -589,8 +583,8 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		else if (b == w->OldPanel) {
 			inters ++;
 
-			w->PathNode[w->NumPathNodes].x    = Act->Pos.x;
-			w->PathNode[w->NumPathNodes].z    = Act->Pos.z;
+			w->PathNode[w->NumPathNodes].pos.x = Act->Pos.x;
+			w->PathNode[w->NumPathNodes].pos.z = Act->Pos.z;
 			w->PathNode[w->NumPathNodes].dist = 0.0;
 			w->PathNode[w->NumPathNodes].oldp = w->OldPanel;
 			w->PathNode[w->NumPathNodes].curp = w->OldPanel;
@@ -600,8 +594,8 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		} else if (b == w->CurPanel) {
 			inters ++;
 
-			w->PathNode[w->NumPathNodes].x    = w->CurX;
-			w->PathNode[w->NumPathNodes].z    = w->CurZ;
+			w->PathNode[w->NumPathNodes].pos.x = w->CurX;
+			w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
 			w->PathNode[w->NumPathNodes].dist = dist;
 			w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 			w->PathNode[w->NumPathNodes].curp = w->CurPanel;
@@ -637,10 +631,10 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 
 			PointOut(oc, Camera);        // tira fuori il pto trovato
 
-			w->PathNode[w->NumPathNodes].x    = w->CurX;
-			w->PathNode[w->NumPathNodes].z    = w->CurZ;
-			w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
-			w->PathNode[w->NumPathNodes].curp = w->CurPanel;
+			w->PathNode[w->NumPathNodes].pos.x = w->CurX;
+			w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
+			w->PathNode[w->NumPathNodes].oldp  = w->CurPanel;
+			w->PathNode[w->NumPathNodes].curp  = w->CurPanel;
 
 			UpdateLook(oc);
 
@@ -661,23 +655,23 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			// e con unione pannelli larghi con pannelli stretti
 			for (b = 0; b < w->PanelNum; b++) {
 				if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
+				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
 				                   w->CurX, w->CurZ))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
+					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
 					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
 						inters ++;
 
 				if (IntersLineLine(w->Panel[b].a, w->Panel[b].backA,
-				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
+				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
 				                   w->CurX, w->CurZ))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
+					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
 					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
 						inters ++;
 
 				if (IntersLineLine(w->Panel[b].b, w->Panel[b].backB,
-				                   w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z,
+				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
 				                   w->CurX, w->CurZ))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].x, w->PathNode[w->NumPathNodes - 1].z) > EPSILON) &&
+					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
 					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
 						inters ++;
 
@@ -690,8 +684,8 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 				w->CurPanel = w->PathNode[w->NumPathNodes - 1].curp;
 
 				PointOut(oc, Camera);        // tira fuori il pto trovato
-				w->PathNode[w->NumPathNodes].x    = w->CurX;
-				w->PathNode[w->NumPathNodes].z    = w->CurZ;
+				w->PathNode[w->NumPathNodes].pos.x = w->CurX;
+				w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
 				w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 				w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 
@@ -706,15 +700,15 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		DebugLogFile("CP: %d || OP: %d || %f %f || I: %d || C: %d || NPN: %d", w->CurPanel, w->OldPanel, w->CurX, w->CurZ, inters, check, w->NumPathNodes);
 //DebugText("CP: %d || OP: %d || I: %d || C: %d || PI: %d || NPN: %d", CurPanel, OldPanel, inters, check, PointInside( OldPanel, CurX, CurZ ), NumPathNodes );
 
-		w->PathNode[w->NumPathNodes].x    = w->CurX;
-		w->PathNode[w->NumPathNodes].z    = w->CurZ;
+		w->PathNode[w->NumPathNodes].pos.x = w->CurX;
+		w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
 		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
 		w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 		w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 		w->NumPathNodes ++;
 
 		for (b = 0; b < w->NumPathNodes; b++)
-			DebugLogFile("FP %d: %f %f | %d %d", b, w->PathNode[b].x, w->PathNode[b].z, w->PathNode[b].oldp, w->PathNode[b].curp);
+			DebugLogFile("FP %d: %f %f | %d %d", b, w->PathNode[b].pos.x, w->PathNode[b].pos.z, w->PathNode[b].oldp, w->PathNode[b].curp);
 
 		FindShortPath(oc);
 
@@ -722,15 +716,15 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 	} else {        // altrimenti starda diretta
 		DebugLogFile("NOI CP: %d || OP: %d || I: %d || C: %d || NPN: %d", w->CurPanel, w->OldPanel, inters, check, w->NumPathNodes);
 //DebugText("NOI CP: %d || OP: %d || I: %d || C: %d || PI: %d || NPN: %d", CurPanel, OldPanel, inters, check, PointInside( OldPanel, CurX, CurZ ), NumPathNodes );
-		w->PathNode[w->NumPathNodes].x    = Act->Pos.x;
-		w->PathNode[w->NumPathNodes].z    = Act->Pos.z;
+		w->PathNode[w->NumPathNodes].pos.x = Act->Pos.x;
+		w->PathNode[w->NumPathNodes].pos.z = Act->Pos.z;
 		w->PathNode[w->NumPathNodes].dist = 0.0;
 		w->PathNode[w->NumPathNodes].oldp = w->OldPanel;
 		w->PathNode[w->NumPathNodes].curp = w->OldPanel;
 		w->NumPathNodes ++;
 
-		w->PathNode[w->NumPathNodes].x    = w->CurX;
-		w->PathNode[w->NumPathNodes].z    = w->CurZ;
+		w->PathNode[w->NumPathNodes].pos.x = w->CurX;
+		w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
 		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
 		w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 		w->PathNode[w->NumPathNodes].curp = w->CurPanel;
diff --git a/engines/watchmaker/walk/walkutil.cpp b/engines/watchmaker/walk/walkutil.cpp
index 2dc003af9ea..eb3ddda01a0 100644
--- a/engines/watchmaker/walk/walkutil.cpp
+++ b/engines/watchmaker/walk/walkutil.cpp
@@ -135,6 +135,9 @@ float DistF(float x1, float y1, float x2, float y2) {
 /*-----------------07/10/96 11.21-------------------
         Interseca linea 2D con linea 2D
 --------------------------------------------------*/
+int IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d) {
+	return IntersLineLine(a.x, a.z, b.x, b.z, c.x, c.z, d.x, d.z);
+}
 int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd) {
 	return IntersLineLine(a.x, a.z, b.x, b.z, xc, yc, xd, yd);
 }
diff --git a/engines/watchmaker/walk/walkutil.h b/engines/watchmaker/walk/walkutil.h
index 353623ddec7..8d6c36b3b5f 100644
--- a/engines/watchmaker/walk/walkutil.h
+++ b/engines/watchmaker/walk/walkutil.h
@@ -34,6 +34,7 @@ bool PointInside2DRectangle(double pgon[4][2], double x, double z);
 float DistF(PointXZ a, PointXZ b);
 float DistF(float x1, float y1, float x2, float y2);
 int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd);
+int IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d);
 int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
 int PathCompare(const void *arg1, const void *arg2);
 void SortPath(int32 oc);


Commit: 023731a9cc48662d3ff36f01df63f302eae88ca4
    https://github.com/scummvm/scummvm/commit/023731a9cc48662d3ff36f01df63f302eae88ca4
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:32+02:00

Commit Message:
WATCHMAKER: Remove unused global variable y3d

Changed paths:
    engines/watchmaker/walk/walk.cpp
    engines/watchmaker/walk/walkutil.cpp


diff --git a/engines/watchmaker/walk/walk.cpp b/engines/watchmaker/walk/walk.cpp
index 7fa7ef68bdb..a89b3b73527 100644
--- a/engines/watchmaker/walk/walk.cpp
+++ b/engines/watchmaker/walk/walk.cpp
@@ -32,7 +32,7 @@
 namespace Watchmaker {
 
 // locals
-float  x3d, y3d, z3d;
+float  x3d, z3d;
 /*
 WALK60      0   225 0
 WALKBACK    4   162 226
diff --git a/engines/watchmaker/walk/walkutil.cpp b/engines/watchmaker/walk/walkutil.cpp
index eb3ddda01a0..c796fafc609 100644
--- a/engines/watchmaker/walk/walkutil.cpp
+++ b/engines/watchmaker/walk/walkutil.cpp
@@ -28,7 +28,7 @@
 
 namespace Watchmaker {
 
-extern float  x3d, y3d, z3d;
+extern float  x3d, z3d;
 
 /* -----------------05/06/00 12.49-------------------
  *                  PointIn2DRectangle
@@ -156,7 +156,6 @@ int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, f
 		else if (r > 1.0f)   r = 1.0f;
 
 		x3d = xa + r * (xb - xa);
-		y3d = 0.0;
 		z3d = ya + r * (yb - ya);
 	}
 


Commit: 2b0a2b2f7a80701bc4dd53a5b4c713bb60214fe4
    https://github.com/scummvm/scummvm/commit/2b0a2b2f7a80701bc4dd53a5b4c713bb60214fe4
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:32+02:00

Commit Message:
WATCHMAKER: Change t3dWALK::Look{X,Z} and t3dWalk::Cur{X,Z} into PointXZ

Changed paths:
    engines/watchmaker/saveload.cpp
    engines/watchmaker/t3d.h
    engines/watchmaker/walk/act.cpp
    engines/watchmaker/walk/walk.cpp
    engines/watchmaker/walk/walkutil.cpp
    engines/watchmaker/walk/walkutil.h


diff --git a/engines/watchmaker/saveload.cpp b/engines/watchmaker/saveload.cpp
index 8c631011237..f2bbf4936cd 100644
--- a/engines/watchmaker/saveload.cpp
+++ b/engines/watchmaker/saveload.cpp
@@ -506,10 +506,8 @@ bool DataLoad(WGame &game, const Common::String &FileName, uint8 slot) {
 			Character[i]->Mesh->Trasl = t3dV3F(*stream);
 			Character[i]->Dir = t3dV3F(*stream);
 			Character[i]->Flags = stream->readByte();
-			Character[i]->Walk.LookX = stream->readFloatLE();
-			Character[i]->Walk.LookZ = stream->readFloatLE();
-			Character[i]->Walk.CurX = stream->readFloatLE();
-			Character[i]->Walk.CurZ = stream->readFloatLE();
+			Character[i]->Walk.Look = PointXZ::readFromStream(*stream);
+			Character[i]->Walk.Cur = PointXZ::readFromStream(*stream);
 			Character[i]->Walk.CurPanel = stream->readSint16LE();
 			Character[i]->Walk.OldPanel = stream->readSint16LE();
 		} else {
diff --git a/engines/watchmaker/t3d.h b/engines/watchmaker/t3d.h
index 2f961b0730e..de663fa94fd 100644
--- a/engines/watchmaker/t3d.h
+++ b/engines/watchmaker/t3d.h
@@ -327,6 +327,12 @@ public:
 
 struct PointXZ {
 	float x = 0.0f, z = 0.0f;
+	static PointXZ readFromStream(Common::SeekableReadStream &stream) {
+		PointXZ result;
+		result.x = stream.readFloatLE();
+		result.z = stream.readFloatLE();
+		return result;
+	}
 };
 
 struct t3dPAN {
@@ -359,8 +365,8 @@ struct t3dSTEPS {
 };
 
 struct t3dWALK {
-	t3dF32  LookX = 0.0f, LookZ = 0.0f;            // Point on the bounds
-	t3dF32  CurX = 0.0f, CurZ = 0.0f;              // Point perpendicular
+	PointXZ Look;                                  // Point on the bounds
+	PointXZ Cur;                                   // Point perpendicular
 	t3dPAN  *Panel = nullptr;                      // pointer to cur panel struct
 	t3dPATHNODE PathNode[T3D_MAX_PATHNODES] = {};  // path nodes list
 	t3dSTEPS    WalkSteps[T3D_MAX_WALKSTEPS] = {}; // walk steps list
diff --git a/engines/watchmaker/walk/act.cpp b/engines/watchmaker/walk/act.cpp
index 64796646f8d..90a3a44348b 100644
--- a/engines/watchmaker/walk/act.cpp
+++ b/engines/watchmaker/walk/act.cpp
@@ -56,9 +56,9 @@ void SlideChar(int32 oc) {
 		return ;
 	}
 
-	v.x = w->LookX;
+	v.x = w->Look.x;
 	v.y = 0.0f;
-	v.z = w->LookZ;
+	v.z = w->Look.z;
 
 	x1 = w->Panel[w->CurPanel].a.x;
 	z1 = w->Panel[w->CurPanel].a.z;
@@ -293,8 +293,8 @@ void CheckCharacterWithoutBounds(WGame &game, int32 oc, const uint8 *dpl, uint8
 		w->PathNode[w->NumPathNodes].dist = t3dVectDistance(&tmp, &Char->Pos);
 		w->NumPathNodes ++;
 
-		Char->Walk.CurX = tmp.x;
-		Char->Walk.CurZ = tmp.z;
+		Char->Walk.Cur.x = tmp.x;
+		Char->Walk.Cur.z = tmp.z;
 	}
 	bNotSkippableWalk = TRUE;
 	BuildStepList(oc, dp, back);
@@ -483,14 +483,14 @@ void BuildStepList(int32 oc, uint8 dp, uint8 back) {
 	}
 
 	if ((dp) && (GetLightDirection(&st, dp)) && (st.x != 0.0f) && (st.z != 0.0f)) {
-		lastangle = SinCosAngle((st.x - w->CurX), (st.z - w->CurZ));
+		lastangle = SinCosAngle((st.x - w->Cur.x), (st.z - w->Cur.z));
 //		DebugLogFile("LastPos %d | AN %d | %f %f", dp, lastangle, st.x, st.z );
 	}
 
 	w->WalkSteps[w->NumSteps].Angle = lastangle;
-	w->WalkSteps[w->NumSteps].Pos.x = w->CurX;
+	w->WalkSteps[w->NumSteps].Pos.x = w->Cur.x;
 	w->WalkSteps[w->NumSteps].Pos.y = CurFloorY;
-	w->WalkSteps[w->NumSteps].Pos.z = w->CurZ;
+	w->WalkSteps[w->NumSteps].Pos.z = w->Cur.z;
 	w->WalkSteps[w->NumSteps++].curp = w->CurPanel;
 
 	// arrotonda la fine
@@ -592,8 +592,8 @@ bool CheckCharacterWithBounds(WGame &game, int32 oc, t3dV3F *Pos, uint8 dp, uint
 	if (!Char) return FALSE;
 	StopObjAnim(game, oc);
 
-	Char->Walk.CurX = Pos->x;
-	Char->Walk.CurZ = Pos->z;
+	Char->Walk.Cur.x = Pos->x;
+	Char->Walk.Cur.z = Pos->z;
 
 	// Reset some vars
 	if (!(Char->Mesh->Flags & T3D_MESH_DEFAULTANIM))
diff --git a/engines/watchmaker/walk/walk.cpp b/engines/watchmaker/walk/walk.cpp
index a89b3b73527..63dcf13eed3 100644
--- a/engines/watchmaker/walk/walk.cpp
+++ b/engines/watchmaker/walk/walk.cpp
@@ -137,7 +137,7 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 //			( Panel[b].flags & (Panel[CurPanel].flags & 0x7FFFFFFF) ) )
 		{
 			// controlla pto 1
-			temp = DistF(w->CurX, w->CurZ, w->Panel[b].a.x, w->Panel[b].a.z);
+			temp = DistF(w->Cur, w->Panel[b].a);
 
 			if (temp < inters) {
 				inters = temp;
@@ -146,7 +146,7 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 			}
 
 			// controlla pto 2
-			temp = DistF(w->CurX, w->CurZ, w->Panel[b].b.x, w->Panel[b].b.z);
+			temp = DistF(w->Cur, w->Panel[b].b);
 
 			if (temp < inters) {
 				inters = temp;
@@ -157,8 +157,8 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 			// controlla intersezione con camera
 			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
 			                   Camera->Source.x, Camera->Source.z,
-			                   w->CurX, w->CurZ)) {
-				temp = DistF(w->CurX, w->CurZ, x3d, z3d);
+			                   w->Cur.x, w->Cur.z)) {
+				temp = DistF(w->Cur.x, w->Cur.z, x3d, z3d);
 
 				if (temp < inters) {
 					inters = temp;
@@ -171,8 +171,8 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 			// controlla intersezione con omino
 			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
 			                   Act->Pos.x, Act->Pos.z,
-			                   w->CurX, w->CurZ)) {
-				temp = DistF(w->CurX, w->CurZ, x3d, z3d);
+			                   w->Cur.x, w->Cur.z)) {
+				temp = DistF(w->Cur.x, w->Cur.z, x3d, z3d);
 
 				if (temp < inters) {
 					inters = temp;
@@ -202,8 +202,7 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 		}
 	}
 
-	w->CurX = p.x;
-	w->CurZ = p.z;
+	w->Cur = p;
 
 #undef LARGEVAL
 }
@@ -387,8 +386,7 @@ void FindShortPath(int32 oc) {
 	}
 
 	// aggiunge arrivo
-	TempPath[count].pos.x = w->CurX;
-	TempPath[count].pos.z = w->CurZ;
+	TempPath[count].pos = w->Cur;
 	TempPath[count].dist = 0.0;
 	TempPath[count].oldp = w->CurPanel;
 	TempPath[count].curp = w->CurPanel;
@@ -505,37 +503,36 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 	        w->CurPanel = 1;
 	*/
 	PointOut(oc, Camera);
-	w->LookX = w->CurX;
-	w->LookZ = w->CurZ;
+	w->Look = w->Cur;
 
 	// se hai cliccato dietro il pannello di partenza o dell'angolo non puo' camminare
 	if ((w->CurPanel < 0) && (w->OldPanel >= 0) &&
 	        // dietro il pannello di partenza
-	        ((PointInside(oc, b = w->OldPanel, (double)w->CurX, (double)w->CurZ)) ||
+	        ((PointInside(oc, b = w->OldPanel, w->Cur)) ||
 	         // dietro il pannello angolo1
 	         ((DistF(w->Panel[w->OldPanel].a.x, w->Panel[w->OldPanel].a.z, Act->Pos.x, Act->Pos.z) < EPSILON) &&
-	          (PointInside(oc, b = w->Panel[w->OldPanel].near1, (double)w->CurX, (double)w->CurZ))) ||
+	          (PointInside(oc, b = w->Panel[w->OldPanel].near1, w->Cur))) ||
 	         // dietro il pannello angolo2
 	         ((DistF(w->Panel[w->OldPanel].b.x, w->Panel[w->OldPanel].b.z, Act->Pos.x, Act->Pos.z) < EPSILON) &&
-	          (PointInside(oc, b = w->Panel[w->OldPanel].near2, (double)w->CurX, (double)w->CurZ))))) {
-		w->CurX = Act->Pos.x;
-		w->CurZ = Act->Pos.z;
+	          (PointInside(oc, b = w->Panel[w->OldPanel].near2, w->Cur))))) {
+		w->Cur.x = Act->Pos.x;
+		w->Cur.z = Act->Pos.z;
 		w->CurPanel = b;
 		w->NumPathNodes = 0;
 		check |= CLICKINTO;
 		w->Check = check;
 		return ;
 	}
-	DebugLogFile("W: CP %d OP %d | %f %f | %f %f", w->CurPanel, w->OldPanel, Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
+	DebugLogFile("W: CP %d OP %d | %f %f | %f %f", w->CurPanel, w->OldPanel, Act->Pos.x, Act->Pos.z, w->Cur.x, w->Cur.z);
 
-	dist = DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
+	dist = DistF(Act->Pos.x, Act->Pos.z, w->Cur.x, w->Cur.z);
 //	if( dist < EPSILON )
 //		return ;
 
 	for (b = 0; b < w->PanelNum; b++) {
 		if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
 		                   Act->Pos.x, Act->Pos.z,
-		                   w->CurX, w->CurZ)) {
+		                   w->Cur.x, w->Cur.z)) {
 			inters ++;
 			DebugLogFile("Inters %d: %f %f %f %f", b, w->Panel[b].a.x, w->Panel[b].a.z, w->Panel[b].b.x, w->Panel[b].b.z);
 
@@ -557,9 +554,9 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 					check |= OLDANGLESKIP;
 
 					// se ho cliccato dentro il pannello vicino
-					if ((w->CurPanel < 0) && (PointInside(oc, b, (double)w->CurX, (double)w->CurZ))) {
-						w->CurX = Act->Pos.x;
-						w->CurZ = Act->Pos.z;
+					if ((w->CurPanel < 0) && (PointInside(oc, b, w->Cur))) {
+						w->Cur.x = Act->Pos.x;
+						w->Cur.z = Act->Pos.z;
 						w->CurPanel = b;
 						w->NumPathNodes = 0;
 						check |= CLICKINTO;
@@ -594,8 +591,7 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		} else if (b == w->CurPanel) {
 			inters ++;
 
-			w->PathNode[w->NumPathNodes].pos.x = w->CurX;
-			w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
+			w->PathNode[w->NumPathNodes].pos = w->Cur;
 			w->PathNode[w->NumPathNodes].dist = dist;
 			w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 			w->PathNode[w->NumPathNodes].curp = w->CurPanel;
@@ -620,21 +616,20 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		if (w->NumPathNodes > 1)
 			DebugLogFile("I %d | CP %d | OP %d | FA %d (%d %d) | PI %d (%d)", inters, w->CurPanel, w->OldPanel,
 			             FindAttachedPanel(oc, w->PathNode[w->NumPathNodes - 2].curp, w->PathNode[w->NumPathNodes - 1].curp), w->PathNode[w->NumPathNodes - 2].curp, w->PathNode[w->NumPathNodes - 1].curp,
-			             PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, (double)w->CurX, (double)w->CurZ), w->PathNode[w->NumPathNodes - 1].curp);
+			             PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, w->Cur), w->PathNode[w->NumPathNodes - 1].curp);
 
 		if (((inters   & 1) && (w->CurPanel < 0) && (w->OldPanel < 0)) ||
-		        ((w->CurPanel < 0) && (w->NumPathNodes >= 1) && (PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, (double)w->CurX, (double)w->CurZ))) ||
+		        ((w->CurPanel < 0) && (w->NumPathNodes >= 1) && (PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, w->Cur))) ||
 		        (((inters - 1) & 1) && (w->CurPanel < 0) && (w->NumPathNodes >= 2) &&
 		         (!(FindAttachedPanel(oc, w->PathNode[w->NumPathNodes - 2].curp, w->PathNode[w->NumPathNodes - 1].curp)) ||
-		          (PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, (double)w->CurX, (double)w->CurZ))))) {
+		          (PointInside(oc, w->PathNode[w->NumPathNodes - 1].curp, w->Cur))))) {
 			w->CurPanel = w->PathNode[w->NumPathNodes - 1].curp;
 
 			PointOut(oc, Camera);        // tira fuori il pto trovato
 
-			w->PathNode[w->NumPathNodes].pos.x = w->CurX;
-			w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
-			w->PathNode[w->NumPathNodes].oldp  = w->CurPanel;
-			w->PathNode[w->NumPathNodes].curp  = w->CurPanel;
+			w->PathNode[w->NumPathNodes].pos = w->Cur;
+			w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
+			w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 
 			UpdateLook(oc);
 
@@ -642,7 +637,7 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 
 			check |= POINTOUT1;
 
-			DebugLogFile("PO %d %d %f", w->NumPathNodes, w->CurPanel, DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ));
+			DebugLogFile("PO %d %d %f", w->NumPathNodes, w->CurPanel, DistF(Act->Pos.x, Act->Pos.z, w->Cur.x, w->Cur.z));
 //			if ( DistF( Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ ) < EPSILON )
 //				check |= CLICKINTO;
 		}
@@ -655,24 +650,21 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			// e con unione pannelli larghi con pannelli stretti
 			for (b = 0; b < w->PanelNum; b++) {
 				if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
-				                   w->CurX, w->CurZ))
+				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
+					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
 						inters ++;
 
 				if (IntersLineLine(w->Panel[b].a, w->Panel[b].backA,
-				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
-				                   w->CurX, w->CurZ))
+				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
+					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
 						inters ++;
 
 				if (IntersLineLine(w->Panel[b].b, w->Panel[b].backB,
-				                   w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z,
-				                   w->CurX, w->CurZ))
+				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
 					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->CurX, w->CurZ) > EPSILON))
+					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
 						inters ++;
 
 				if (inters)
@@ -684,8 +676,7 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 				w->CurPanel = w->PathNode[w->NumPathNodes - 1].curp;
 
 				PointOut(oc, Camera);        // tira fuori il pto trovato
-				w->PathNode[w->NumPathNodes].pos.x = w->CurX;
-				w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
+				w->PathNode[w->NumPathNodes].pos = w->Cur;
 				w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 				w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 
@@ -697,12 +688,11 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			}
 		}
 
-		DebugLogFile("CP: %d || OP: %d || %f %f || I: %d || C: %d || NPN: %d", w->CurPanel, w->OldPanel, w->CurX, w->CurZ, inters, check, w->NumPathNodes);
+		DebugLogFile("CP: %d || OP: %d || %f %f || I: %d || C: %d || NPN: %d", w->CurPanel, w->OldPanel, w->Cur.x, w->Cur.z, inters, check, w->NumPathNodes);
 //DebugText("CP: %d || OP: %d || I: %d || C: %d || PI: %d || NPN: %d", CurPanel, OldPanel, inters, check, PointInside( OldPanel, CurX, CurZ ), NumPathNodes );
 
-		w->PathNode[w->NumPathNodes].pos.x = w->CurX;
-		w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
-		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
+		w->PathNode[w->NumPathNodes].pos = w->Cur;
+		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->Cur.x, w->Cur.z);
 		w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 		w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 		w->NumPathNodes ++;
@@ -723,16 +713,15 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 		w->PathNode[w->NumPathNodes].curp = w->OldPanel;
 		w->NumPathNodes ++;
 
-		w->PathNode[w->NumPathNodes].pos.x = w->CurX;
-		w->PathNode[w->NumPathNodes].pos.z = w->CurZ;
-		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->CurX, w->CurZ);
+		w->PathNode[w->NumPathNodes].pos = w->Cur;
+		w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, w->Cur.x, w->Cur.z);
 		w->PathNode[w->NumPathNodes].oldp = w->CurPanel;
 		w->PathNode[w->NumPathNodes].curp = w->CurPanel;
 		w->NumPathNodes ++;
 
 	}
 	w->Check = check;
-	DebugLogFile("End Walk %f %f  %d | %f %f %d", Act->Pos.x, Act->Pos.z, w->OldPanel, w->CurX, w->CurZ, w->CurPanel);
+	DebugLogFile("End Walk %f %f  %d | %f %f %d", Act->Pos.x, Act->Pos.z, w->OldPanel, w->Cur.x, w->Cur.z, w->CurPanel);
 }
 
 /* -----------------12/02/99 11.07-------------------
diff --git a/engines/watchmaker/walk/walkutil.cpp b/engines/watchmaker/walk/walkutil.cpp
index c796fafc609..6ecb7336b3a 100644
--- a/engines/watchmaker/walk/walkutil.cpp
+++ b/engines/watchmaker/walk/walkutil.cpp
@@ -69,6 +69,9 @@ bool PointInside2DRectangle(double pgon[4][2], double x, double z) {
 /* 04/02/98 16.01 ----------------------------------
     Guarda se un pto e' all'interno di un pannello
 --------------------------------------------------*/
+int PointInside(int32 oc, int32 pan, const PointXZ &point) {
+	return PointInside(oc, pan, (double)point.x, (double)point.z);
+}
 int PointInside(int32 oc, int32 pan, double x, double z) {
 	t3dWALK *w = &Character[oc]->Walk;
 	double pgon[4][2], ox, oz, s;
diff --git a/engines/watchmaker/walk/walkutil.h b/engines/watchmaker/walk/walkutil.h
index 8d6c36b3b5f..b1a5b125050 100644
--- a/engines/watchmaker/walk/walkutil.h
+++ b/engines/watchmaker/walk/walkutil.h
@@ -29,6 +29,7 @@ namespace Watchmaker {
 
 t3dF32 SinCosAngle(t3dF32 sinus, t3dF32 cosinus);
 t3dF32 t3dVectAngle(t3dV3F *n, t3dV3F *o);
+int PointInside(int32 oc, int32 pan, const PointXZ &point);
 int PointInside(int32 oc, int32 pan, double x, double z);
 bool PointInside2DRectangle(double pgon[4][2], double x, double z);
 float DistF(PointXZ a, PointXZ b);


Commit: 6ffa76bb7f4023272a1a0a37627bc1df21bfd88c
    https://github.com/scummvm/scummvm/commit/6ffa76bb7f4023272a1a0a37627bc1df21bfd88c
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2024-09-20T23:28:32+02:00

Commit Message:
WATCHMAKER: Remove global variables for returning from IntersLineLine

Changed paths:
    engines/watchmaker/t3d.h
    engines/watchmaker/walk/act.cpp
    engines/watchmaker/walk/walk.cpp
    engines/watchmaker/walk/walkutil.cpp
    engines/watchmaker/walk/walkutil.h


diff --git a/engines/watchmaker/t3d.h b/engines/watchmaker/t3d.h
index de663fa94fd..8871582d23a 100644
--- a/engines/watchmaker/t3d.h
+++ b/engines/watchmaker/t3d.h
@@ -335,6 +335,12 @@ struct PointXZ {
 	}
 };
 
+// Struct for returning from "partial" functions mathematically
+struct PointResult {
+	PointXZ result;
+	bool isValid = false;
+};
+
 struct t3dPAN {
 	PointXZ a, b;                           // point A / B position
 	PointXZ backA, backB;                   // back to point A / B
diff --git a/engines/watchmaker/walk/act.cpp b/engines/watchmaker/walk/act.cpp
index 90a3a44348b..632904166db 100644
--- a/engines/watchmaker/walk/act.cpp
+++ b/engines/watchmaker/walk/act.cpp
@@ -565,8 +565,9 @@ int32 CheckPathNodes(int32 oc) {
 //	se interseca almeno un baffo si ferma!!
 	for (i = 1; i < w->NumPathNodes; i++) {
 		for (b = 0; b < w->PanelNum; b++) {
-			if (IntersLineLine(w->Panel[b].backA, w->Panel[b].backB,
-			                   w->PathNode[i - 1].pos, w->PathNode[i].pos)) {
+			PointResult res = IntersLineLine(w->Panel[b].backA, w->Panel[b].backB,
+			                   w->PathNode[i - 1].pos, w->PathNode[i].pos);
+			if (res.isValid) {
 				w->NumPathNodes = i - 1;
 				w->CurPanel = w->PathNode[i - 1].curp;
 				w->NumSteps = 0;
diff --git a/engines/watchmaker/walk/walk.cpp b/engines/watchmaker/walk/walk.cpp
index 63dcf13eed3..d8f22ad0471 100644
--- a/engines/watchmaker/walk/walk.cpp
+++ b/engines/watchmaker/walk/walk.cpp
@@ -32,7 +32,6 @@
 namespace Watchmaker {
 
 // locals
-float  x3d, z3d;
 /*
 WALK60      0   225 0
 WALKBACK    4   162 226
@@ -155,47 +154,48 @@ void PointOut(int32 oc, t3dCAMERA *Camera) {
 			}
 
 			// controlla intersezione con camera
-			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-			                   Camera->Source.x, Camera->Source.z,
-			                   w->Cur.x, w->Cur.z)) {
-				temp = DistF(w->Cur.x, w->Cur.z, x3d, z3d);
+			PointResult res = IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                                 Camera->Source.x, Camera->Source.z,
+			                                 w->Cur.x, w->Cur.z);
+			if (res.isValid) {
+				temp = DistF(w->Cur, res.result);
 
 				if (temp < inters) {
 					inters = temp;
 					w->CurPanel = b;
-					p.x = x3d;
-					p.z = z3d;
+					p = res.result;
 				}
 			}
 
 			// controlla intersezione con omino
-			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-			                   Act->Pos.x, Act->Pos.z,
-			                   w->Cur.x, w->Cur.z)) {
-				temp = DistF(w->Cur.x, w->Cur.z, x3d, z3d);
+			res = IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                     Act->Pos.x, Act->Pos.z,
+			                     w->Cur.x, w->Cur.z);
+			if (res.isValid) {
+				temp = DistF(w->Cur, res.result);
 
 				if (temp < inters) {
 					inters = temp;
 					w->CurPanel = b;
-					p.x = x3d;
-					p.z = z3d;
+					p = res.result;
 				}
 			}
 
 			// controlla intersezione con normale pannello
-			/*          if( IntersLineLine( w->Panel[b].x1, w->Panel[b].z1,
-			                                w->Panel[b].x2, w->Panel[b].z2,
-			                                w->CurX+nx*LARGEVAL, w->CurZ+nz*LARGEVAL,
-			                                w->CurX-nx*LARGEVAL, w->CurZ-nz*LARGEVAL ) )
+			/*          PointResult res = IntersLineLine( w->Panel[b].x1, w->Panel[b].z1,
+			                                              w->Panel[b].x2, w->Panel[b].z2,
+			                                              w->CurX+nx*LARGEVAL, w->CurZ+nz*LARGEVAL,
+			                                              w->CurX-nx*LARGEVAL, w->CurZ-nz*LARGEVAL );
+			            if (res.isValid)
 			            {
-			                temp = DistF( w->CurX, w->CurZ, x3d, z3d );
+			                temp = DistF( w->Cur, res.result );
 
 			                if( temp < inters )
 			                {
 			                    inters = temp;
 			                    w->CurPanel = b;
-			                    x = x3d;
-			                    z = z3d;
+			                    x = res.result.x;
+			                    z = res.result.z;
 			                }
 			            }
 			*/
@@ -422,24 +422,27 @@ void FindShortPath(int32 oc) {
 				// non deve intersecare pannello stretto mai
 //				if( !( w->Panel[c].flags & 0x80000000 ) )
 				{
-					if (IntersLineLine(w->Panel[c].backA, w->Panel[c].backB,
-					                   TempPath[a].pos, TempPath[b].pos))
+					PointResult res = IntersLineLine(w->Panel[c].backA, w->Panel[c].backB,
+					                                TempPath[a].pos, TempPath[b].pos);
+					if (res.isValid)
 						inters ++;
 
-					if (IntersLineLine(w->Panel[c].a, w->Panel[c].backA,
-					                   TempPath[a].pos, TempPath[b].pos)) {
-						len2 = DistF(x3d, z3d, TempPath[a].pos.x, TempPath[a].pos.z);
-						len1 = DistF(x3d, z3d, TempPath[b].pos.x, TempPath[b].pos.z);
+					res = IntersLineLine(w->Panel[c].a, w->Panel[c].backA,
+					                     TempPath[a].pos, TempPath[b].pos);
+					if (res.isValid) {
+						len2 = DistF(res.result, TempPath[a].pos);
+						len1 = DistF(res.result, TempPath[b].pos);
 
 						// interseca in un pto distante da partenza e arrivo
 						if ((len1 > EPSILON) && (len2 > EPSILON))
 							inters ++;
 					}
 
-					if (IntersLineLine(w->Panel[c].b, w->Panel[c].backB,
-					                   TempPath[a].pos, TempPath[b].pos)) {
-						len2 = DistF(x3d, z3d, TempPath[a].pos.x, TempPath[a].pos.z);
-						len1 = DistF(x3d, z3d, TempPath[b].pos.x, TempPath[b].pos.z);
+					res = IntersLineLine(w->Panel[c].b, w->Panel[c].backB,
+					                     TempPath[a].pos, TempPath[b].pos);
+					if (res.isValid) {
+						len2 = DistF(res.result, TempPath[a].pos);
+						len1 = DistF(res.result, TempPath[b].pos);
 
 						// interseca in un pto distante da partenza e arrivo
 						if ((len1 > EPSILON) && (len2 > EPSILON))
@@ -530,15 +533,15 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 //		return ;
 
 	for (b = 0; b < w->PanelNum; b++) {
-		if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-		                   Act->Pos.x, Act->Pos.z,
-		                   w->Cur.x, w->Cur.z)) {
+		PointResult res = IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+		                                 Act->Pos.x, Act->Pos.z,
+		                                 w->Cur.x, w->Cur.z);
+		if (res.isValid) {
 			inters ++;
 			DebugLogFile("Inters %d: %f %f %f %f", b, w->Panel[b].a.x, w->Panel[b].a.z, w->Panel[b].b.x, w->Panel[b].b.z);
 
-			w->PathNode[w->NumPathNodes].pos.x = x3d;
-			w->PathNode[w->NumPathNodes].pos.z = z3d;
-			w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, x3d, z3d);
+			w->PathNode[w->NumPathNodes].pos = res.result;
+			w->PathNode[w->NumPathNodes].dist = DistF(Act->Pos.x, Act->Pos.z, res.result.x, res.result.z);
 			w->PathNode[w->NumPathNodes].oldp = b;
 			w->PathNode[w->NumPathNodes].curp = b;
 			w->NumPathNodes ++;
@@ -649,22 +652,26 @@ void FindPath(int32 oc, t3dCAMERA *Camera) {
 			// conto intersezioni con pannelli stretti
 			// e con unione pannelli larghi con pannelli stretti
 			for (b = 0; b < w->PanelNum; b++) {
-				if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
+				PointResult res;
+				res = IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+				                     w->PathNode[w->NumPathNodes - 1].pos, w->Cur);
+				if (res.isValid)
+					if ((DistF(res.result, w->PathNode[w->NumPathNodes - 1].pos) > EPSILON) &&
+					        (DistF(res.result, w->Cur) > EPSILON))
 						inters ++;
 
-				if (IntersLineLine(w->Panel[b].a, w->Panel[b].backA,
-				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
+				res = IntersLineLine(w->Panel[b].a, w->Panel[b].backA,
+				                     w->PathNode[w->NumPathNodes - 1].pos, w->Cur);
+				if (res.isValid)
+					if ((DistF(res.result, w->PathNode[w->NumPathNodes - 1].pos) > EPSILON) &&
+					        (DistF(res.result, w->Cur) > EPSILON))
 						inters ++;
 
-				if (IntersLineLine(w->Panel[b].b, w->Panel[b].backB,
-				                   w->PathNode[w->NumPathNodes - 1].pos, w->Cur))
-					if ((DistF(x3d, z3d, w->PathNode[w->NumPathNodes - 1].pos.x, w->PathNode[w->NumPathNodes - 1].pos.z) > EPSILON) &&
-					        (DistF(x3d, z3d, w->Cur.x, w->Cur.z) > EPSILON))
+				res = IntersLineLine(w->Panel[b].b, w->Panel[b].backB,
+				                     w->PathNode[w->NumPathNodes - 1].pos, w->Cur);
+				if (res.isValid)
+					if ((DistF(res.result, w->PathNode[w->NumPathNodes - 1].pos) > EPSILON) &&
+					        (DistF(res.result, w->Cur) > EPSILON))
 						inters ++;
 
 				if (inters)
@@ -754,13 +761,14 @@ void ForceAnimInBounds(int32 oc) {
 				DebugLogFile("Aggiorno CurPanel %d", b);
 			}
 //			Se un punto interseca pannello slida
-			if (IntersLineLine(w->Panel[b].a, w->Panel[b].b,
-			                   Trasl[0].x, Trasl[0].z,
-			                   Trasl[a].x, Trasl[a].z)) {
+			PointResult res = IntersLineLine(w->Panel[b].a, w->Panel[b].b,
+			                                 Trasl[0].x, Trasl[0].z,
+			                                 Trasl[a].x, Trasl[a].z);
+			if (res.isValid) {
 				inters ++;
 
-				Trasl[a].x = x3d;
-				Trasl[a].z = z3d;
+				Trasl[a].x = res.result.x;
+				Trasl[a].z = res.result.z;
 				DebugLogFile("%d: entrerebbe in %d", a, b);
 			}
 		}
diff --git a/engines/watchmaker/walk/walkutil.cpp b/engines/watchmaker/walk/walkutil.cpp
index 6ecb7336b3a..30d98cf02d0 100644
--- a/engines/watchmaker/walk/walkutil.cpp
+++ b/engines/watchmaker/walk/walkutil.cpp
@@ -28,8 +28,6 @@
 
 namespace Watchmaker {
 
-extern float  x3d, z3d;
-
 /* -----------------05/06/00 12.49-------------------
  *                  PointIn2DRectangle
  * --------------------------------------------------*/
@@ -138,31 +136,30 @@ float DistF(float x1, float y1, float x2, float y2) {
 /*-----------------07/10/96 11.21-------------------
         Interseca linea 2D con linea 2D
 --------------------------------------------------*/
-int IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d) {
+PointResult IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d) {
 	return IntersLineLine(a.x, a.z, b.x, b.z, c.x, c.z, d.x, d.z);
 }
-int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd) {
+PointResult IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd) {
 	return IntersLineLine(a.x, a.z, b.x, b.z, xc, yc, xd, yd);
 }
-int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) {
-	float r, s, divisor;
-
-	divisor = (float)((xb - xa) * (yd - yc) - (yb - ya) * (xd - xc));
+PointResult IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) {
+	float divisor = (float)((xb - xa) * (yd - yc) - (yb - ya) * (xd - xc));
 	if (!divisor) divisor = 0.000001f;
-	r = (float)((ya - yc) * (xd - xc) - (xa - xc) * (yd - yc)) / divisor;
-	s = (float)((ya - yc) * (xb - xa) - (xa - xc) * (yb - ya)) / divisor;
+	float r = (float)((ya - yc) * (xd - xc) - (xa - xc) * (yd - yc)) / divisor;
+	float s = (float)((ya - yc) * (xb - xa) - (xa - xc) * (yb - ya)) / divisor;
 
-	if ((r < -EPSILON) || (r > (1.0f + EPSILON)) || (s < -EPSILON) || (s > (1.0f + EPSILON)))
-		return FALSE;
-	else {
+	PointResult result;
+	if ((r < -EPSILON) || (r > (1.0f + EPSILON)) || (s < -EPSILON) || (s > (1.0f + EPSILON))) {
+		result.isValid = false;
+	} else {
 		if (r < 0.0f)    r = 0.0f;
 		else if (r > 1.0f)   r = 1.0f;
 
-		x3d = xa + r * (xb - xa);
-		z3d = ya + r * (yb - ya);
+		result.result.x = xa + r * (xb - xa);
+		result.result.z = ya + r * (yb - ya);
 	}
 
-	return TRUE;
+	return result;
 }
 
 /*-----------------15/10/96 10.33-------------------
diff --git a/engines/watchmaker/walk/walkutil.h b/engines/watchmaker/walk/walkutil.h
index b1a5b125050..44789279480 100644
--- a/engines/watchmaker/walk/walkutil.h
+++ b/engines/watchmaker/walk/walkutil.h
@@ -34,9 +34,9 @@ int PointInside(int32 oc, int32 pan, double x, double z);
 bool PointInside2DRectangle(double pgon[4][2], double x, double z);
 float DistF(PointXZ a, PointXZ b);
 float DistF(float x1, float y1, float x2, float y2);
-int IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd);
-int IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d);
-int IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
+PointResult IntersLineLine(const PointXZ &a, const PointXZ &b, float xc, float yc, float xd, float yd);
+PointResult IntersLineLine(const PointXZ &a, const PointXZ &b, const PointXZ &c, const PointXZ &d);
+PointResult IntersLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
 int PathCompare(const void *arg1, const void *arg2);
 void SortPath(int32 oc);
 




More information about the Scummvm-git-logs mailing list