[Scummvm-cvs-logs] SF.net SVN: scummvm:[40954] scummvm/trunk/engines/cruise

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Thu May 28 10:49:57 CEST 2009


Revision: 40954
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40954&view=rev
Author:   dreammaster
Date:     2009-05-28 08:49:56 +0000 (Thu, 28 May 2009)

Log Message:
-----------
Replaced the original implementation of walk box handling with a cleaner, structure array based one

Modified Paths:
--------------
    scummvm/trunk/engines/cruise/actor.cpp
    scummvm/trunk/engines/cruise/cruise.cpp
    scummvm/trunk/engines/cruise/cruise.h
    scummvm/trunk/engines/cruise/ctp.cpp
    scummvm/trunk/engines/cruise/ctp.h
    scummvm/trunk/engines/cruise/perso.cpp
    scummvm/trunk/engines/cruise/saveload.cpp

Modified: scummvm/trunk/engines/cruise/actor.cpp
===================================================================
--- scummvm/trunk/engines/cruise/actor.cpp	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/actor.cpp	2009-05-28 08:49:56 UTC (rev 40954)
@@ -73,37 +73,22 @@
 int flag_aff_chemin;
 
 void getPixel(int x, int y) {
-	int x_min, x_max, y_min, y_max;
 
-	int16* polygone = (int16*)polyStruct0;
-	int16* next;
+	for (uint i = 0; i < polyStructs->size(); ++i) {
+		CtStruct &ct = (*polyStructs)[i];
+		numPoly = ct.num;
 
-	while ((next = *(int16**)polygone) != (int16 *) - 1) {
-		polygone += sizeof(uint16*);
-
-		int16* tableau = polygone + 2;
-
-		x_min = *tableau++;
-		x_max = *tableau++;
-		y_min = *tableau++;
-		y_max = *tableau++;
-
-		numPoly = *polygone++;
-
-		if (walkboxState[numPoly] == 0 && ((x >= x_min && x <= x_max) && (y >= y_min && y <= y_max))) {
+		if (walkboxState[numPoly] == 0 && ct.bounds.contains(x, y)) {
 			// click was in given box
-			int u = y - y_min;
-			tableau += u * 2;
-			x_min = *tableau++;
-			x_max = *tableau++;
+			int u = y - ct.bounds.top;
+			CtEntry &cte = ct.slices[u];
 
-			if ((x >= x_min && x <= x_max)) {
+			if ((x >= cte.minX && x <= cte.maxX)) {
 				flag_obstacle = walkboxColor[numPoly];
 
 				return;
 			}
 		}
-		polygone = next;
 	}
 
 	flag_obstacle = 0;
@@ -188,7 +173,7 @@
 		return;
 	}
 
-	while (--cx) {
+	while (--cx >= 0) {
 		if (dx > 0) {
 			ax += mD0;
 			bx += mD1;
@@ -279,7 +264,7 @@
 		return;
 	}
 
-	while (--cx) {
+	while (--cx >= 0) {
 		if (dx > 0) {
 			ax += mD0;
 			bx += mD1;
@@ -308,7 +293,7 @@
 	int x1, y1, i, x, y, p;
 	int d1 = 1000;
 
-	polyStruct0 = polyStructNorm;
+	polyStructs = &polyStructNorm;
 
 	if (nclick_noeud == 1) {
 		x = x_mouse;
@@ -316,19 +301,19 @@
 		x1 = table_ptselect[0][0];
 		y1 = table_ptselect[0][1];
 
-		polyStruct0 = polyStructExp;
+		polyStructs = &polyStructExp;
 
 		getPixel(x, y);
 
 		if (!flag_obstacle) {
-			polyStruct0 = polyStructNorm;
+			polyStructs = &polyStructNorm;
 
 			getPixel(x, y);
 
 			if (flag_obstacle) {
 				polydroite(x1, y1, x, y);
 			}
-			polyStruct0 = polyStructExp;
+			polyStructs = &polyStructExp;
 		}
 		if (!flag_obstacle) {	/* dans flag_obstacle --> couleur du point */
 			x1 = table_ptselect[0][0];
@@ -340,7 +325,7 @@
 			y_mouse = Y;
 		}
 	}
-	polyStruct0 = polyStructNorm;
+	polyStructs = &polyStructNorm;
 
 	p = -1;
 	for (i = 0; i < ctp_routeCoordCount; i++) {
@@ -468,7 +453,7 @@
 	table_ptselect[*nclick][0] = x_mouse;
 	table_ptselect[*nclick][1] = y_mouse;
 	(*nclick)++;
-	polyStruct0 = polyStructNorm;
+	polyStructs = &polyStructNorm;
 
 	if (*nclick == 2) {	// second point
 		x1 = table_ptselect[0][0];
@@ -479,7 +464,7 @@
 			return;
 		}
 		flag_aff_chemin = 1;
-		polyStruct0 = polyStructExp;
+		polyStructs = &polyStructExp;
 
 		// can we go there directly ?
 		polydroite(x1, y1, x2, y2);
@@ -487,7 +472,7 @@
 		if (!flag_obstacle) {
 			solution0[0][0] = x1;
 			solution0[0][1] = y1;
-			polyStruct0 = polyStructExp;
+			polyStructs = &polyStructExp;
 
 			poly2(x2, y2, ctp_routeCoords[select_noeud[1]][0],
 			      ctp_routeCoords[select_noeud[1]][1]);
@@ -531,7 +516,7 @@
 					solution0[++i][1] =
 					    ctp_routeCoords[p1][1];
 				}
-				polyStruct0 = polyStructExp;
+				polyStructs = &polyStructExp;
 				poly2(x2, y2,
 				      ctp_routeCoords[select_noeud[1]][0],
 				      ctp_routeCoords[select_noeud[1]][1]);
@@ -556,7 +541,7 @@
 					while (flag_obstacle && i != d) {
 						x2 = solution0[i][0];
 						y2 = solution0[i][1];
-						polyStruct0 = polyStructExp;
+						polyStructs = &polyStructExp;
 						polydroite(x1, y1, x2, y2);
 						i--;
 					}
@@ -636,7 +621,7 @@
 	}
 
 	nclick_noeud = 0;
-	polyStruct0 = polyStructNorm;
+	polyStructs = &polyStructNorm;
 	flag_aff_chemin = 0;
 
 	if (x == destX && y == destY) {

Modified: scummvm/trunk/engines/cruise/cruise.cpp
===================================================================
--- scummvm/trunk/engines/cruise/cruise.cpp	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/cruise.cpp	2009-05-28 08:49:56 UTC (rev 40954)
@@ -102,12 +102,13 @@
 
 	mainLoop();
 
+	deinitialise();
+
 	return Common::kNoError;
 }
 
 void CruiseEngine::initialize() {
 	PCFadeFlag = 0;
-	workBuffer = (uint8 *) mallocAndZero(8192);
 
 	/*volVar1 = 0;
 	 * fileData1 = 0; */
@@ -136,6 +137,11 @@
 		_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
 }
 
+void CruiseEngine::deinitialise() {
+	polyStructNorm.clear();
+	polyStructExp.clear();
+}
+
 bool CruiseEngine::loadLanguageStrings() {
 	Common::File f;
 

Modified: scummvm/trunk/engines/cruise/cruise.h
===================================================================
--- scummvm/trunk/engines/cruise/cruise.h	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/cruise.h	2009-05-28 08:49:56 UTC (rev 40954)
@@ -65,6 +65,7 @@
 	uint32 lastTick, lastTickDebug;
 
 	void initialize(void);
+	void deinitialise(void);
 	bool loadLanguageStrings();
 	bool makeLoad(char *saveName);
 	void mainLoop();

Modified: scummvm/trunk/engines/cruise/ctp.cpp
===================================================================
--- scummvm/trunk/engines/cruise/ctp.cpp	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/ctp.cpp	2009-05-28 08:49:56 UTC (rev 40954)
@@ -28,15 +28,13 @@
 
 namespace Cruise {
 
-uint8 *workBuffer;
-uint8 *polyStruct;
-uint8 *adrStructPoly;
-uint8 *polyStructNorm;
-uint8 *polyStructExp;
-
 uint8 *ctpVar17;
-uint8 *polyStruct0;
 
+Common::Array<CtStruct> polyStructNorm;
+Common::Array<CtStruct> polyStructExp;
+Common::Array<CtStruct> *polyStructs = NULL;
+Common::Array<CtStruct> *polyStruct = NULL;
+
 int currentWalkBoxCenterX;
 int currentWalkBoxCenterY;
 int currentWalkBoxCenterXBis;
@@ -135,7 +133,7 @@
 }
 
 // this process the walkboxes
-void makeCtStruct(uint8* str, int16 table[][40], int num, int z) {
+void makeCtStruct(Common::Array<CtStruct> &lst, int16 table[][40], int num, int z) {
 	int minX = 1000;
 	int maxX = -1;
 
@@ -149,12 +147,9 @@
 
 	renderCTPWalkBox(&table[num][0], currentWalkBoxCenterX, currentWalkBoxCenterY,  currentWalkBoxCenterX, currentWalkBoxCenterY, z + 0x200);
 
-	int16* a1;
-	int16* a2;
+	lst.push_back(CtStruct());
+	CtStruct &ct = lst[lst.size() - 1];
 
-	a1 = a2 = (int16*)str;
-	a2 += sizeof(int16*) / sizeof(int16) + 6; // skip header
-
 	int16* XArray = XMIN_XMAX;
 	int minY = *XArray++;
 
@@ -170,23 +165,16 @@
 		if (x2 > maxX)
 			maxX = x2;
 
-		*a2++ = x1;
-		*a2++ = x2;
+		ct.slices.push_back(CtEntry(x1, x2));
 		i++;
 	}
-	*(int16**)a1 = a2;
 
-	adrStructPoly = (uint8*)a2;
-
-	*(uint16**)a2 = (uint16*) - 1; //chained list terminator
-
-	a1 += sizeof(int16*);
-	*a1++ = num;
-	*a1++ = walkboxColor[num];
-	*a1++ = minX;
-	*a1++ = maxX;
-	*a1++ = minY;
-	*a1++ = minY + i + 2;
+	ct.num = num;
+	ct.colour = walkboxColor[num];
+	ct.bounds.left = minX;
+	ct.bounds.right = maxX;
+	ct.bounds.top = minY;
+	ct.bounds.bottom = minY + i;
 }
 
 int getNode(int nodeResult[2], int nodeId) {
@@ -332,35 +320,20 @@
 
 	computeAllDistance(distanceTable, ctp_routeCoordCount);	// process path-finding stuff
 
-	polyStruct = polyStructNorm = adrStructPoly = workBuffer;
+	// Load the polyStructNorm list
 
-	ptr = (uint8 *) polyStruct;
-
 	for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
-		makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0);
+		makeCtStruct(polyStructNorm, ctp_walkboxTable, i, 0);
 	}
 
-	polyStructExp = adrStructPoly += sizeof(int16 *);
+	// Load the polyStructExp list
 
 	for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
-		makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20);
+		makeCtStruct(polyStructExp, ctp_walkboxTable, i, walkboxZoom[i] * 20);
 	}
 
-	int ctSize = (adrStructPoly - ptr) + sizeof(int16 *); // for now, the +sizeof(int16 *) is a safe zone
-	adrStructPoly = polyStructNorm = polyStruct = (uint8 *) malloc(ctSize);
+	polyStruct = polyStructs = &polyStructNorm;
 
-	for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
-		makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0);
-	}
-
-	polyStructExp = adrStructPoly += sizeof(int16 *);
-
-	for (int i = numberOfWalkboxes - 1; i >= 0; i--) {
-		makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20);
-	}
-
-	polyStruct0 = polyStructNorm;
-
 	return (1);
 }
 

Modified: scummvm/trunk/engines/cruise/ctp.h
===================================================================
--- scummvm/trunk/engines/cruise/ctp.h	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/ctp.h	2009-05-28 08:49:56 UTC (rev 40954)
@@ -26,6 +26,8 @@
 #ifndef CRUISE_CTP_H
 #define CRUISE_CTP_H
 
+#include "common/rect.h"
+
 namespace Cruise {
 
 struct ctpVar19SubStruct {
@@ -42,15 +44,31 @@
 	ctpVar19SubStruct subStruct;
 };
 
-extern uint8 *workBuffer;
-extern uint8 *polyStruct;
-extern uint8 *adrStructPoly;
-extern uint8 *polyStructNorm;
-extern uint8 *polyStructExp;
+class CtEntry {
+public:
+	CtEntry(int16 xs, int16 xe) { minX = xs; maxX = xe; }
+	CtEntry() { minX = 0; maxX = 0; }
 
+	int16 minX;
+	int16 maxX;
+};
+
+class CtStruct {
+public:
+	CtStruct *next;
+	int16 num;
+	int16 colour;
+	Common::Rect bounds;
+	Common::Array<CtEntry> slices;
+};
+
 extern uint8 *ctpVar17;
-extern uint8 *polyStruct0;
 
+extern Common::Array<CtStruct> polyStructNorm;
+extern Common::Array<CtStruct> polyStructExp;
+extern Common::Array<CtStruct> *polyStructs;
+extern Common::Array<CtStruct> *polyStruct;
+
 int initCt(const char * ctpName);
 int computeDistance(int varX, int varY, int paramX, int paramY);
 

Modified: scummvm/trunk/engines/cruise/perso.cpp
===================================================================
--- scummvm/trunk/engines/cruise/perso.cpp	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/perso.cpp	2009-05-28 08:49:56 UTC (rev 40954)
@@ -46,7 +46,9 @@
 	}
 
 	if (polyStruct) {
-		free(polyStruct);
+		polyStructNorm.clear();
+		polyStructExp.clear();
+		polyStruct = NULL;
 	}
 
 	ctpVar17 = NULL;

Modified: scummvm/trunk/engines/cruise/saveload.cpp
===================================================================
--- scummvm/trunk/engines/cruise/saveload.cpp	2009-05-28 08:36:27 UTC (rev 40953)
+++ scummvm/trunk/engines/cruise/saveload.cpp	2009-05-28 08:49:56 UTC (rev 40954)
@@ -558,6 +558,8 @@
 static void syncCT(Common::Serializer &s) {
 	int v = (polyStruct) ? 1 : 0;
 	s.syncAsSint32LE(v);
+	if (s.isLoading())
+		polyStruct = (v != 0) ? &polyStructNorm : NULL;
 
 	if (v == 0)
 		// There is no further data to load or save


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list