[Scummvm-cvs-logs] CVS: scummvm/scumm resource.cpp,1.44,1.45 script.cpp,1.33,1.34 script_v5.cpp,1.10,1.11 script_v6.cpp,1.29,1.30 script_v8.cpp,2.72,2.73 scumm.h,1.117,1.118 string.cpp,1.70,1.71

Max Horn fingolfin at users.sourceforge.net
Fri Dec 27 17:58:03 CET 2002


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv15559/scumm

Modified Files:
	resource.cpp script.cpp script_v5.cpp script_v6.cpp 
	script_v8.cpp scumm.h string.cpp 
Log Message:
get rid of getStringLen and use the more powerful resStrLen instead; moved resStrLen from common/ to scumm/, where it belongs; enhanced resStrLen to suport V8; fixed translateText to support embeded vars (in strings I mean) - it may still not be fully correct but at least is better now; rewrote o6_arrayOps to parallel the V8 version - needs testing

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- resource.cpp	27 Dec 2002 19:48:30 -0000	1.44
+++ resource.cpp	28 Dec 2002 01:57:18 -0000	1.45
@@ -1477,7 +1477,7 @@
 
 	nukeResource(type, resindex);
 
-	len = getStringLen(source);
+	len = resStrLen(source) + 1;
 
 	if (len <= 0)
 		return;

Index: script.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- script.cpp	27 Dec 2002 15:11:43 -0000	1.33
+++ script.cpp	28 Dec 2002 01:57:18 -0000	1.34
@@ -1097,33 +1097,43 @@
 	return -1;
 }
 
-void Scumm::copyString(byte *dst, byte *src, int len)
+void Scumm::copyScriptString(byte *dst)
 {
-	if (!src) {
-		while (--len >= 0)
-			*dst++ = fetchScriptByte();
-	} else {
-		while (--len >= 0)
-			*dst++ = *src++;
-	}
+	int len = resStrLen(_scriptPointer) + 1;
+	while (len--)
+		*dst++ = fetchScriptByte();
 }
 
-int Scumm::getStringLen(byte *ptr)
+//
+// Given a pointer to a Scumm string, this function returns the total byte length
+// of the string data in that resource. To do so it has to understand certain
+// special characters embedded into the string. The reason for this function is that
+// sometimes this embedded data contains zero bytes, thus we can't just use strlen.
+//
+int Scumm::resStrLen(const byte *src) const
 {
-	int len;
-	byte c;
-	if (!ptr)
-		ptr = _scriptPointer;
-	len = 0;
-	do {
-		c = *ptr++;
-		if (!c)
-			break;
-		len++;
-		if (c == 0xFF)
-			ptr += 3, len += 3;
-	} while (1);
-	return len + 1;
+	int num = 0;
+	byte chr;
+	if (src == NULL)
+		src = _scriptPointer;
+	while ((chr = *src++) != 0) {
+		num++;
+		if (chr == 255) {
+			chr = *src++;
+			num++;
+
+			if (chr != 1 && chr != 2 && chr != 3 && chr != 8) {
+				if (_features & GF_AFTER_V8) {
+					src += 4;
+					num += 4;
+				} else {
+					src += 2;
+					num += 2;
+				}
+			}
+		}
+	}
+	return num;
 }
 
 void Scumm::exitCutscene()

Index: script_v5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v5.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- script_v5.cpp	27 Dec 2002 00:23:45 -0000	1.10
+++ script_v5.cpp	28 Dec 2002 01:57:18 -0000	1.11
@@ -1827,7 +1827,7 @@
 			if (out) {
 				byte *ptr;
 				ptr = getResourceAddress(rtString, a);
-				fwrite(ptr, getStringLen(ptr) + 1, 1, out);
+				fwrite(ptr, resStrLen(ptr) + 1, 1, out);
 				fclose(out);
 			}
 			break;

Index: script_v6.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v6.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- script_v6.cpp	27 Dec 2002 16:49:07 -0000	1.29
+++ script_v6.cpp	28 Dec 2002 01:57:18 -0000	1.30
@@ -1952,54 +1952,46 @@
 	push(getVerbEntrypoint(v, e));
 }
 
-void Scumm::arrayop_1(int a, byte *ptr)
-{
-	ArrayHeader *ah;
-	int r;
-	int len = getStringLen(ptr);
-
-	r = defineArray(a, 4, 0, len);
-	ah = (ArrayHeader *)getResourceAddress(rtString, r);
-	copyString(ah->data, ptr, len);
-}
-
 void Scumm_v6::o6_arrayOps()
 {
-	int a, b, c, d, num;
+	byte subOp = fetchScriptByte();
+	int array = fetchScriptWord();
+	int b, c, d, len;
+	ArrayHeader *ah;
 	int list[128];
 
-	switch (fetchScriptByte()) {
+	switch (subOp) {
 	case 205:
-		a = fetchScriptWord();
-		pop();
-		arrayop_1(a, NULL);
+		b = pop();
+		len = resStrLen(_scriptPointer);
+		c = defineArray(array, 4, 0, len + 1);
+		ah = (ArrayHeader *)getResourceAddress(rtString, c);
+		copyScriptString(ah->data + b);
 		break;
 	case 208:
-		a = fetchScriptWord();
 		b = pop();
 		c = pop();
-		d = readVar(a);
+		d = readVar(array);
 		if (d == 0) {
-			defineArray(a, 5, 0, b + c);
+			defineArray(array, 5, 0, b + c);
 		}
 		while (c--) {
-			writeArray(a, 0, b + c, pop());
+			writeArray(array, 0, b + c, pop());
 		}
 		break;
 	case 212:
-		a = fetchScriptWord();
 		b = pop();
-		num = getStackList(list, sizeof(list) / sizeof(list[0]));
-		d = readVar(a);
+		len = getStackList(list, sizeof(list) / sizeof(list[0]));
+		d = readVar(array);
 		if (d == 0)
 			error("Must DIM a two dimensional array before assigning");
 		c = pop();
-		while (--num >= 0) {
-			writeArray(a, c, b + num, list[num]);
+		while (--len >= 0) {
+			writeArray(array, c, b + len, list[len]);
 		}
 		break;
 	default:
-		error("o6_arrayOps: default case");
+		error("o6_arrayOps: default case %d (array %d)", subOp, array);
 	}
 }
 
@@ -2015,7 +2007,6 @@
 	byte subOp = fetchScriptByte();
 	if (_features & GF_AFTER_V8) {
 		subOp = (subOp - 141) + 0xB4;
-		printf("o8_saveRestoreVerbs:%d\n", (int)subOp);
 	}
 	
 	switch (subOp) {
@@ -2112,7 +2103,6 @@
 
 		return;
 	case 171:
-		printf("wait for sentence");
 		if (_sentenceNum) {
 			if (_sentence[_sentenceNum - 1].freezeCount && !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]))
 				return;
@@ -2290,8 +2280,9 @@
 		char pointer[20];
 		int i, j;
 
-		_scriptPointer += resStrLen((char*)_scriptPointer) + 1;
+		_scriptPointer += resStrLen(_scriptPointer) + 1;
 		translateText(_messagePtr, _transText);
+
 		for (i = 0, j = 0; (_messagePtr[i] != '/' || j == 0) && j < 19; i++) {
 			if (_messagePtr[i] != '/')
 				pointer[j++] = _messagePtr[i];
@@ -2934,7 +2925,7 @@
 				char pointer[20];
 				int i, j;
 
-				_scriptPointer += resStrLen((char*)_scriptPointer)+ 1;
+				_scriptPointer += resStrLen(_scriptPointer)+ 1;
 				translateText(_messagePtr, _transText);
 				for (i = 0, j = 0; (_messagePtr[i] != '/' || j == 0) && j < 19; i++) {
 					if (_messagePtr[i] != '/')

Index: script_v8.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v8.cpp,v
retrieving revision 2.72
retrieving revision 2.73
diff -u -d -r2.72 -r2.73
--- script_v8.cpp	28 Dec 2002 00:45:44 -0000	2.72
+++ script_v8.cpp	28 Dec 2002 01:57:18 -0000	2.73
@@ -512,16 +512,14 @@
 	case 0xD0:		// SO_PRINT_MUMBLE
 		error("decodeParseString: SO_PRINT_MUMBLE");
 		break;
-	case 0xD1: {
-
-#if 1
+	case 0xD1:
 		_messagePtr = _scriptPointer;
 
 		if (_messagePtr[0] == '/') {
 			char pointer[20];
 			int i, j;
 
-			_scriptPointer += resStrLen((char*)_scriptPointer)+ 1;
+			_scriptPointer += resStrLen(_scriptPointer) + 1;
 			translateText(_messagePtr, _transText);
 			for (i = 0, j = 0; (_messagePtr[i] != '/' || j == 0) && j < 19; i++) {
 				if (_messagePtr[i] != '/')
@@ -569,61 +567,7 @@
 			_scriptPointer = _messagePtr;
 			return;
 		}
-#else
-		char buffer[1024];
-		_messagePtr = _scriptPointer;
-
-		if (_messagePtr[0] == '/') {
-			char pointer[20];
-			int i, j;
-
-			// Skip over the string
-			_scriptPointer += resStrLen((char*)_scriptPointer) + 1;
-	
-			translateText(_messagePtr, _transText);
-			for (i = 0, j = 0; (_messagePtr[i] != '/' || j == 0) && j < 19; i++) {
-				if (_messagePtr[i] != '/')
-					pointer[j++] = _messagePtr[i];
-			}
-			pointer[j] = 0;
-
-			// Stop any talking that's still going on
-			if (_sound->_talkChannel > -1)
-				_mixer->stop(_sound->_talkChannel);
-
-			// FIXME: no 'digvoice.bun' in COMI
-			_sound->_talkChannel = _sound->playBundleSound(pointer);
-
-			_messagePtr = _transText;
-			_msgPtrToAdd = (byte *)buffer;
-			_messagePtr = addMessageToStack(_messagePtr);
-		} else {
-			_msgPtrToAdd = (byte *)buffer;
-			_scriptPointer = _messagePtr = addMessageToStack(_messagePtr);
-		}
-
-		if (_fr[_string[m].charset] == NULL)	// FIXME: Put this elsewhere?
-			loadCharset(_string[m].charset);
-
-		if (_fr[_string[m].charset] != NULL) {
-			int x = _string[m].xpos;
-			// HACK - center mode. I call this a hack because we really should
-			// not duplicate all the string code from string.cpp. Rather, maybe
-			// abstract away the code in string.cpp from using the 'charset'
-			// fonts, and allow it to work both with old and new fonts. To this
-			// end, we should seperate the parts of Charset/_charset which are
-			// for bookkeeping (like x_pos, center mode etc.) and those that are
-			// for rendering. Then let the old (think printCharOld), medium (printChar),
-			// new (NUT) style renderers be subclasses of a common base class (which
-			// defines the API). This will clean up the code, and allow us to reuse
-			// the string logic in string.cpp.
-			if (_string[m].center)
-				x -= _fr[_string[m].charset]->getStringWidth(buffer) / 2;
-			_fr[_string[m].charset]->drawString(buffer, x, _string[m].ypos, _string[m].color, 0);
-		}
-#endif
 		break;
-	}
 	case 0xD2:		// SO_PRINT_WRAP Set print wordwrap
 		error("decodeParseString: SO_PRINT_MUMBLE");
 		break;
@@ -746,23 +690,18 @@
 	byte subOp = fetchScriptByte();
 	int array = fetchScriptWord();
 	int b, c, d, len;
+	ArrayHeader *ah;
 	int list[128];
 	
 	switch (subOp) {
 	case 0x14:		// SO_ASSIGN_STRING
-		{
-		int idx = pop();
-		ArrayHeader *ah;
-		int r;
-		len = getStringLen(NULL);
-	
-		r = defineArray(array, 4, 0, len);
-		ah = (ArrayHeader *)getResourceAddress(rtString, r);
-		copyString(ah->data + idx, NULL, len);
-		}
+		b = pop();
+		len = resStrLen(_scriptPointer);
+		c = defineArray(array, 4, 0, len + 1);
+		ah = (ArrayHeader *)getResourceAddress(rtString, c);
+		copyScriptString(ah->data + b);
 		break;
 	case 0x15:		// SO_ASSIGN_SCUMMVAR_LIST
-		// TODO / FIXME: is this right?
 		b = pop();
 		c = pop();
 		d = readVar(array);
@@ -774,7 +713,6 @@
 		}
 		break;
 	case 0x16:		// SO_ASSIGN_2DIM_LIST
-		// TODO / FIXME: is this right?
 		b = pop();
 		len = getStackList(list, sizeof(list) / sizeof(list[0]));
 		d = readVar(array);
@@ -1333,7 +1271,7 @@
 
 void Scumm_v8::o8_startVideo()
 {
-	int len = resStrLen((char*)_scriptPointer);
+	int len = resStrLen(_scriptPointer);
 	
 	warning("o8_startVideo(%s/%s)", getGameDataPath(), (char*)_scriptPointer);
 	
@@ -1528,7 +1466,7 @@
 void Scumm_v8::o8_getStringWidth()
 {
 	int charset = pop();
-	int len = resStrLen((char*)_scriptPointer);
+	int len = resStrLen(_scriptPointer);
 	int oldID = _charset->getCurID(); 
 	int width;
 	

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- scumm.h	27 Dec 2002 14:36:28 -0000	1.117
+++ scumm.h	28 Dec 2002 01:57:18 -0000	1.118
@@ -457,7 +457,6 @@
 	virtual void writeVar(uint var, int value);
 	void runHook(int i);
 	bool isScriptInUse(int script);
-	int getStringLen(byte *ptr);
 	
 	void freezeScripts(int scr);
 	void unfreezeScripts();
@@ -476,8 +475,8 @@
 	void decreaseScriptDelay(int amount);
 	bool isScriptRunning(int script);
 	bool isRoomScriptRunning(int script);
-	void arrayop_1(int a, byte *ptr);
-	void copyString(byte *dst, byte *src, int len);
+	void copyScriptString(byte *dst);
+	int resStrLen(const byte *src) const;
 	void doSentence(int c, int b, int a);
 	void setStringVars(int i);
 

Index: string.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/string.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- string.cpp	27 Dec 2002 23:18:06 -0000	1.70
+++ string.cpp	28 Dec 2002 01:57:19 -0000	1.71
@@ -494,7 +494,7 @@
 	}
 
 	for (i = 0; (chr = buf[i++]) != 0;) {
-		if (chr == 254 || chr == 255) {
+		if (chr == 0xFE || chr == 0xFF) {
 			chr = buf[i++];
 			switch (chr) {
 			case 9:
@@ -650,6 +650,11 @@
 				*_msgPtrToAdd++ = chr;
 				*_msgPtrToAdd++ = ptr[num++];
 				*_msgPtrToAdd++ = ptr[num++];
+				if (_features & GF_AFTER_V8) {
+					// FIXME - is this right?!?
+					*_msgPtrToAdd++ = ptr[num++];
+					*_msgPtrToAdd++ = ptr[num++];
+				}
 				break;
 			default: 
 				debug(2, "addMessageToStack(): string escape sequence %d unknown", chr);
@@ -808,11 +813,11 @@
 		// skip translation if flag 'h' exist
 		if (*(buf + pos) == 'h') {
 			pos += 3;
-			char *pointer = strchr((char*)text + 1, '/');
+			byte *pointer = (byte *)strchr((char*)text + 1, '/');
 			if (pointer != NULL)
-				strcpy((char *)trans_buff, pointer + 1);
+				memcpy(trans_buff, pointer + 1, resStrLen(pointer + 1) + 1);
 			else
-				strcpy((char *)trans_buff, "");
+				trans_buff[0] = '\0';
 			return;
 		}
 
@@ -868,14 +873,14 @@
 	}
 
 	if (text[0] == '/') {
-		char *pointer = strchr((char*)text + 1, '/');
+		byte *pointer = (byte *)strchr((char*)text + 1, '/');
 		if (pointer != NULL)
-			strcpy((char *)trans_buff, pointer + 1);
+			memcpy(trans_buff, pointer + 1, resStrLen(pointer + 1) + 1);
 		else
-			strcpy((char *)trans_buff, "");
-
+			trans_buff[0] = '\0';
 		return;
 	}
-	strcpy((char *)trans_buff, (char *)text);
+
+	memcpy(trans_buff, text, resStrLen(text) + 1);
 }
 





More information about the Scummvm-git-logs mailing list