[Scummvm-cvs-logs] CVS: scummvm/sky disk.cpp,1.74,1.75 disk.h,1.23,1.24 intro.cpp,1.61,1.62 logic.cpp,1.160,1.161

Robert Göffringmann lavosspawn at users.sourceforge.net
Tue Dec 6 08:51:18 CET 2005


Update of /cvsroot/scummvm/scummvm/sky
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4425/sky

Modified Files:
	disk.cpp disk.h intro.cpp logic.cpp 
Log Message:
minor cleanup

Index: disk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/disk.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- disk.cpp	5 Dec 2005 05:02:43 -0000	1.74
+++ disk.cpp	6 Dec 2005 16:50:39 -0000	1.75
@@ -34,13 +34,9 @@
 static const char *dinnerFilename = "sky.dnr";
 
 Disk::Disk(const Common::String &gameDataPath) {
-	_prefRoot = NULL;
-
 	_dataDiskHandle = new Common::File();
 	_dnrHandle = new Common::File();
 
-	uint32 entriesRead;
-
 	_dnrHandle->open(dinnerFilename);
 	if (!_dnrHandle->isOpen())
 		error("Could not open %s%s", gameDataPath.c_str(), dinnerFilename);
@@ -49,10 +45,10 @@
 		error("Error reading from sky.dnr"); //even though it was opened correctly?!
 
 	_dinnerTableArea = (uint8 *)malloc(_dinnerTableEntries * 8);
-	entriesRead = _dnrHandle->read(_dinnerTableArea, 8 * _dinnerTableEntries) / 8;
+	uint32 entriesRead = _dnrHandle->read(_dinnerTableArea, 8 * _dinnerTableEntries) / 8;
 
 	if (entriesRead != _dinnerTableEntries)
-		warning("entriesRead != dinnerTableEntries. [%d/%d]", entriesRead, _dinnerTableEntries);
+		error("entriesRead != dinnerTableEntries. [%d/%d]", entriesRead, _dinnerTableEntries);
 
 	_dataDiskHandle->open(dataFilename);
 	if (!_dataDiskHandle->isOpen())
@@ -65,14 +61,6 @@
 }
 
 Disk::~Disk(void) {
-
-	PrefFile *fEntry = _prefRoot;
-	while (fEntry) {
-		free(fEntry->data);
-		PrefFile *fTemp = fEntry;
-		fEntry = fEntry->next;
-		delete fTemp;
-	}
 	if (_dnrHandle->isOpen())
 		_dnrHandle->close();
 	if (_dataDiskHandle->isOpen())
@@ -83,20 +71,7 @@
 	delete _dataDiskHandle;
 }
 
-void Disk::flushPrefetched(void) {
-
-	PrefFile *fEntry = _prefRoot;
-	while (fEntry) {
-		free(fEntry->data);
-		PrefFile *fTemp = fEntry;
-		fEntry = fEntry->next;
-		delete fTemp;
-	}
-	_prefRoot = NULL;
-}
-
 bool Disk::fileExists(uint16 fileNr) {
-
 	return (getFileInfo(fileNr) != NULL);
 }
 
@@ -105,10 +80,6 @@
 
 	uint8 cflag;
 
-	uint8 *prefData = givePrefetched(fileNr, &_lastLoadedFileSize);
-	if (prefData)
-		return prefData;
-
 	debug(2, "load file %d,%d (%d)", (fileNr >> 11), (fileNr & 2047), fileNr);
 
 	uint8 *fileInfoPtr = getFileInfo(fileNr);
@@ -202,47 +173,13 @@
 	}
 }
 
-void Disk::prefetchFile(uint16 fileNr) {
-
-	PrefFile **fEntry = &_prefRoot;
-	bool found = false;
-	while (*fEntry) {
-		if ((*fEntry)->fileNr == fileNr)
-			found = true;
-		fEntry = &((*fEntry)->next);
-	}
-	if (found) {
-		debug(1, "Disk::prefetchFile: File %d was already prefetched", fileNr);
-		return;
-	}
-	uint8 *temp = loadFile(fileNr);
-	*fEntry = new PrefFile;
-	(*fEntry)->data = temp;
-	(*fEntry)->fileSize = _lastLoadedFileSize;
-	(*fEntry)->fileNr = fileNr;
-	(*fEntry)->next = NULL;
-}
-
-uint8 *Disk::givePrefetched(uint16 fileNr, uint32 *fSize) {
-
-	PrefFile **fEntry = &_prefRoot;
-	bool found = false;
-	while ((*fEntry) && (!found)) {
-		if ((*fEntry)->fileNr == fileNr)
-			found = true;
-		else
-			fEntry = &((*fEntry)->next);
-	}
-	if (!found) {
-		*fSize = 0;
-		return NULL;
-	}
-	uint8 *retPtr = (*fEntry)->data;
-	PrefFile *retStr = *fEntry;
-	*fEntry = (*fEntry)->next;
-	*fSize = retStr->fileSize;
-	delete retStr;
-	return retPtr;
+uint16 *Disk::loadScriptFile(uint16 fileNr) {
+	uint16 *buf = (uint16*)loadFile(fileNr);
+#ifdef SCUMM_BIG_ENDIAN
+	for (int i = 0; i < _lastLoadedFileSize / 2; i++)
+		buf[i] = FROM_LE_16(buf[i]);
+#endif
+	return buf;
 }
 
 uint8 *Disk::getFileInfo(uint16 fileNr) {

Index: disk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/disk.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- disk.h	18 Oct 2005 01:30:23 -0000	1.23
+++ disk.h	6 Dec 2005 16:50:39 -0000	1.24
@@ -27,32 +27,23 @@
 #include "common/str.h"
 #include "sky/rnc_deco.h"
 
+#define MAX_FILES_IN_LIST 60
+
 namespace Common {
 	class File;
 }
 
 namespace Sky {
 
-#define MAX_FILES_IN_LIST 60
-
-struct PrefFile {
-	uint8 *data;
-	uint16 fileNr;
-	uint32 fileSize;
-	PrefFile *next;
-};
-
 class Disk {
 public:
 	Disk(const Common::String &gameDataPath);
 	~Disk(void);
 
 	uint8 *loadFile(uint16 fileNr);
+	uint16 *loadScriptFile(uint16 fileNr);
 	bool fileExists(uint16 fileNr);
 
-	void prefetchFile(uint16 fileNr);
-	void flushPrefetched(void);
-
 	uint32 determineGameVersion();
 
 	uint32 _lastLoadedFileSize;
@@ -66,10 +57,6 @@
 	void refreshFilesList(uint32 *list);
 
 protected:
-
-	PrefFile *_prefRoot;
-	uint8 *givePrefetched(uint16 fileNr, uint32 *fSize);
-
 	uint8 *getFileInfo(uint16 fileNr);
 	void dumpFile(uint16 fileNr);
 

Index: intro.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/intro.cpp,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- intro.cpp	5 Dec 2005 05:02:43 -0000	1.61
+++ intro.cpp	6 Dec 2005 16:50:39 -0000	1.62
@@ -639,7 +639,6 @@
 Intro::~Intro(void) {
 
 	_mixer->stopAll();
-	_skyDisk->flushPrefetched();
 	_skyScreen->stopSequence();
 	if (_textBuf)
 		free(_textBuf);
@@ -654,8 +653,6 @@
 	if (!SkyEngine::isCDVersion())
 		floppyIntro = true;
 
-	_skyDisk->prefetchFile(60112);
-	_skyDisk->prefetchFile(60113);
 	_skyMusic->loadSection(0);
 	_skySound->loadSection(0);
 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/logic.cpp,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -d -r1.160 -r1.161
--- logic.cpp	6 Dec 2005 16:13:39 -0000	1.160
+++ logic.cpp	6 Dec 2005 16:50:39 -0000	1.161
@@ -1217,13 +1217,13 @@
 	/// process a script
 	/// low level interface to interpreter
 
-	uint16 moduleNo = (uint16)((scriptNo & 0xff00) >> 12);
+	uint16 moduleNo = scriptNo >> 12;
 	debug(3, "Doing Script %x", (offset << 16) | scriptNo);
 	uint16 *scriptData = _moduleList[moduleNo]; // get module address
 
-	if (!scriptData) { // The module has not been loaded
-		scriptData = (uint16 *)_skyDisk->loadFile(moduleNo + F_MODULE_0);
-		_moduleList[moduleNo] = scriptData; // module has been loaded
+	if (!scriptData) { // We need to load the script module
+		_moduleList[moduleNo] = _skyDisk->loadScriptFile(moduleNo + F_MODULE_0);
+		 scriptData = _moduleList[moduleNo]; // module has been loaded
 	}
 
 	uint16 *moduleStart = scriptData;
@@ -1232,18 +1232,18 @@
 	if (offset)
 		scriptData = moduleStart + offset;
 	else
-		scriptData += READ_LE_UINT16(scriptData + (scriptNo & 0x0fff));
+		scriptData += scriptData[scriptNo & 0x0fff];
 
 	uint32 a = 0, b = 0, c = 0;
 	uint16 command, s;
 
 	for (;;) {
-		command = READ_LE_UINT16(scriptData++); // get a command
+		command = *scriptData++; // get a command
 		Debug::script(command, scriptData);
 
 		switch (command) {
 		case 0: // push_variable
-			push( _scriptVariables[READ_LE_UINT16(scriptData++) / 4] );
+			push( _scriptVariables[*scriptData++ / 4] );
 			break;
 		case 1: // less_than
 			a = pop();
@@ -1254,7 +1254,7 @@
 				push(0);
 			break;
 		case 2: // push_number
-			push(READ_LE_UINT16(scriptData++));
+			push(*scriptData++);
 			break;
 		case 3: // not_equal
 			a = pop();
@@ -1273,14 +1273,14 @@
 				push(0);
 			break;
 		case 5: // skip_zero
-			s = READ_LE_UINT16(scriptData++);
+			s = *scriptData++;
 
 			a = pop();
 			if (!a)
 				scriptData += s / 2;
 			break;
 		case 6: // pop_var
-			b = _scriptVariables[READ_LE_UINT16(scriptData++) / 4] = pop();
+			b = _scriptVariables[*scriptData++ / 4] = pop();
 			break;
 		case 7: // minus
 			a = pop();
@@ -1293,7 +1293,7 @@
 			push(b+a);
 			break;
 		case 9: // skip_always
-			s = READ_LE_UINT16(scriptData++);
+			s = *scriptData++;
 			scriptData += s / 2;
 			break;
 		case 10: // if_or
@@ -1306,7 +1306,7 @@
 			break;
 		case 11: // call_mcode
 			{
-				a = READ_LE_UINT16(scriptData++);
+				a = *scriptData++;
 				assert(a <= 3);
 				// No, I did not forget the "break"s
 				switch (a) {
@@ -1318,7 +1318,7 @@
 					a = pop();
 				}
 
-				uint16 mcode = READ_LE_UINT16(scriptData++)/4; // get mcode number
+				uint16 mcode = *scriptData++ / 4; // get mcode number
 				Debug::mcode(mcode, a, b, c);
 
 				Compact *saveCpt = _compact;
@@ -1338,13 +1338,13 @@
 				push(0);
 			break;
 		case 14: // switch
-			c = s = READ_LE_UINT16(scriptData++); // get number of cases
+			c = s = *scriptData++; // get number of cases
 
 			a = pop(); // and value to switch on
 
 			do {
-				if (a == READ_LE_UINT16(scriptData)) {
-					scriptData += READ_LE_UINT16(scriptData + 1) / 2;
+				if (a == *scriptData) {
+					scriptData += scriptData[1] / 2;
 					scriptData++;
 					break;
 				}
@@ -1352,14 +1352,14 @@
 			} while (--s);
 
 			if (s == 0)
-				scriptData += READ_LE_UINT16(scriptData)/2; // use the default
+				scriptData += *scriptData / 2; // use the default
 			break;
 		case 15: // push_offset
-			push( *(uint16 *)_skyCompact->getCompactElem(_compact, READ_LE_UINT16(scriptData++)) );
+			push( *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) );
 			break;
 		case 16: // pop_offset
 			// pop a value into a compact
-			*(uint16 *)_skyCompact->getCompactElem(_compact, READ_LE_UINT16(scriptData++)) = (uint16)pop();
+			*(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) = (uint16)pop();
 			break;
 		case 17: // is_equal
 			a = pop();
@@ -1370,7 +1370,7 @@
 				push(0);
 			break;
 		case 18: { // skip_nz
-				int16 t = READ_LE_UINT16(scriptData++);
+				int16 t = *scriptData++;
 				a = pop();
 				if (a)
 					scriptData += t / 2;
@@ -1668,7 +1668,6 @@
 }
 
 bool Logic::fnPointerText(uint32 a, uint32 b, uint32 c) {
-
 	_skyText->fnPointerText(a, _skyMouse->giveMouseX(), _skyMouse->giveMouseY());
 	return true;
 }
@@ -2028,11 +2027,11 @@
 	uint16 *rst = (uint16 *)_skyCompact->fetchCpt(resetBlock);
 
 	if (!cpt) {
-		warning("fnResetId(): Compact %d (id) == NULL",id);
+		warning("fnResetId(): Compact %d (id) == NULL", id);
 		return true;
 	}
 	if (!rst) {
-		warning("fnResetId(): Compact %d (resetBlock) == NULL",resetBlock);
+		warning("fnResetId(): Compact %d (resetBlock) == NULL", resetBlock);
 		return true;
 	}
 
@@ -2318,13 +2317,11 @@
 }
 
 bool Logic::fnRestoreGame(uint32 a, uint32 b, uint32 c) {
-
 	_skyControl->doLoadSavePanel();
 	return false;
 }
 
 bool Logic::fnRestartGame(uint32 a, uint32 b, uint32 c) {
-
 	_skyControl->restartGame();
 	return false;
 }





More information about the Scummvm-git-logs mailing list