[Scummvm-cvs-logs] SF.net SVN: scummvm:[45827] scummvm/trunk/engines/m4

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Wed Nov 11 10:55:05 CET 2009


Revision: 45827
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45827&view=rev
Author:   dreammaster
Date:     2009-11-11 09:55:05 +0000 (Wed, 11 Nov 2009)

Log Message:
-----------
Removed all the '- 1' from calls to get vocabs, centralising it in the getVocab method. This is correct, as the first element in the game vocab list is '1', not '0'.

Modified Paths:
--------------
    scummvm/trunk/engines/m4/console.cpp
    scummvm/trunk/engines/m4/globals.h
    scummvm/trunk/engines/m4/hotspot.cpp
    scummvm/trunk/engines/m4/mads_anim.cpp
    scummvm/trunk/engines/m4/scene.h

Modified: scummvm/trunk/engines/m4/console.cpp
===================================================================
--- scummvm/trunk/engines/m4/console.cpp	2009-11-11 02:25:42 UTC (rev 45826)
+++ scummvm/trunk/engines/m4/console.cpp	2009-11-11 09:55:05 UTC (rev 45827)
@@ -310,7 +310,7 @@
 			DebugPrintf("%2d - ", objStart);
 			for (uint objId = objStart; objId < MIN<uint>(_vm->_globals->getObjectsSize(), objStart + 5); ++objId) {
 				if (objId != objStart) DebugPrintf(", ");
-				uint16 descId = _vm->_globals->getObject(objId)->descId - 1;
+				uint16 descId = _vm->_globals->getObject(objId)->descId;
 				DebugPrintf("%s", _vm->_globals->getVocab(descId));
 			}
 
@@ -327,13 +327,13 @@
 		else {
 			const MadsObject *obj = _vm->_globals->getObject(id);
 
-			DebugPrintf("Object #%d (%s) room=%d vocabs=%d", id, _vm->_globals->getVocab(obj->descId - 1),
+			DebugPrintf("Object #%d (%s) room=%d vocabs=%d", id, _vm->_globals->getVocab(obj->descId),
 				obj->roomNumber, obj->vocabCount);
 			if (obj->vocabCount > 0) {
 				DebugPrintf(" - ");
 				for (int i = 0; i < obj->vocabCount; ++i) {
 					if (i != 0) DebugPrintf(", ");
-					DebugPrintf("%s (%d)/%d", _vm->_globals->getVocab(obj->vocabList[i].vocabId - 1),
+					DebugPrintf("%s (%d)/%d", _vm->_globals->getVocab(obj->vocabList[i].vocabId),
 						obj->vocabList[i].vocabId, obj->vocabList[i].unk);
 				}
 			}

Modified: scummvm/trunk/engines/m4/globals.h
===================================================================
--- scummvm/trunk/engines/m4/globals.h	2009-11-11 02:25:42 UTC (rev 45826)
+++ scummvm/trunk/engines/m4/globals.h	2009-11-11 09:55:05 UTC (rev 45827)
@@ -194,7 +194,11 @@
 
 	void loadMadsVocab();
 	uint32 getVocabSize() { return _madsVocab.size(); }
-	const char *getVocab(uint32 index) { return _madsVocab[index]; }
+	const char *getVocab(uint32 index) { 
+		// Vocab list is 1-based, so always subtract one from index provided
+		assert((index > 0) && (index <= _madsVocab.size()));
+		return _madsVocab[index - 1]; 
+	}
 
 	void loadMadsQuotes();
 	uint32 getQuotesSize() { return _madsQuotes.size(); }

Modified: scummvm/trunk/engines/m4/hotspot.cpp
===================================================================
--- scummvm/trunk/engines/m4/hotspot.cpp	2009-11-11 02:25:42 UTC (rev 45826)
+++ scummvm/trunk/engines/m4/hotspot.cpp	2009-11-11 09:55:05 UTC (rev 45827)
@@ -51,6 +51,7 @@
 }
 
 HotSpot::~HotSpot() {
+	free(_vocab);
 }
 
 void HotSpot::setRect(int x1, int y1, int x2, int y2) {
@@ -273,10 +274,10 @@
 			currentHotSpot->setVerb("");
 
 			if (currentHotSpot->getVocabID() > 0)
-				currentHotSpot->setVocab(_vm->_globals->getVocab(currentHotSpot->getVocabID() - 1));
+				currentHotSpot->setVocab(_vm->_globals->getVocab(currentHotSpot->getVocabID()));
 
 			if (currentHotSpot->getVerbID() > 0)
-				currentHotSpot->setVerb(_vm->_globals->getVocab(currentHotSpot->getVerbID() - 1));
+				currentHotSpot->setVerb(_vm->_globals->getVocab(currentHotSpot->getVerbID()));
 		}
 	}
 }

Modified: scummvm/trunk/engines/m4/mads_anim.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_anim.cpp	2009-11-11 02:25:42 UTC (rev 45826)
+++ scummvm/trunk/engines/m4/mads_anim.cpp	2009-11-11 09:55:05 UTC (rev 45827)
@@ -25,6 +25,7 @@
 
 #include "m4/mads_anim.h"
 #include "m4/m4.h"
+#include "m4/compression.h"
 
 namespace M4 {
 
@@ -491,8 +492,6 @@
 		strcat(_resourceName, ".res");
 
 	_script = _vm->res()->get(_resourceName);
-
-	processLines();
 }
 
 bool AnimviewView::onEvent(M4EventType eventType, int param, int x, int y, bool &captureEvents) {
@@ -508,37 +507,97 @@
 }
 
 void AnimviewView::updateState() {
-	char bgFile[10];
-	int bgNumber = 0;
+	if (!_script)
+		return;
 
 	// Only update state if wait period has expired
 	if (_previousUpdate > 0) {
-		if (g_system->getMillis() - _previousUpdate < 3000) {
+		if (g_system->getMillis() - _previousUpdate < 100)
 			return;
-		} else {
-			// time for an update
-			_previousUpdate = g_system->getMillis();
-		}
-	} else {
+
 		_previousUpdate = g_system->getMillis();
-		return;
 	}
 
-	strncpy(bgFile, _currentFile, 5);
-	bgFile[0] = bgFile[2];
-	bgFile[1] = bgFile[3];
-	bgFile[2] = bgFile[4];
-	bgFile[3] = '\0';
-	bgNumber = atoi(bgFile);
-	sprintf(bgFile, "rm%i.art", bgNumber);
+	// Check if we're ready for the next command
+	bool animRunning = false;
+	if (!animRunning) {
+		if (_script->eos() ||  _script->err()) {
+			scriptDone();
+			return;
+		}
+		
+		readNextCommand();
 
+		// FIXME: Replace flag with proper animation end check
+		animRunning = true;
+	}
+}
+
+void AnimviewView::readNextCommand() {
+	while (!_script->eos() && !_script->err()) {
+		strncpy(_currentLine, _script->readLine().c_str(), 79);
+
+		// Process any switches on the line
+		char *cStart = strchr(_currentLine, '-');
+		while (cStart) {
+			// Loop for possible multiple commands on one line
+			char *cEnd = strchr(_currentLine, ' ');
+			if (!cEnd)
+				error("Unterminated command '%s' in response file", _currentLine);
+
+			*cEnd = '\0';
+			processCommand();
+
+			// Copy rest of line (if any) to start of buffer
+			// Don't use strcpy() here, because if the
+			// rest of the line is the longer of the two
+			// strings, the memory areas will overlap.
+			memmove(_currentLine, cEnd + 1, strlen(cEnd + 1) + 1);
+
+			cStart = strchr(_currentLine, '-');
+		}
+	
+		// If there's something left, presume it's a resource name to process
+		if (_currentLine[0])
+			break;
+	}
+
+	if (strchr(_currentLine, '.') == NULL)
+		strcat(_currentLine, ".aa");
+
+	AAFile aaFile(_currentLine, _vm);
+
+	// Initial validation
+	if (aaFile.flags & AA_HAS_FONT) {
+		assert(_vm->_resourceManager->resourceExists(aaFile.fontResource.c_str()));
+	}
+
+	for (int seriesCtr = 0; seriesCtr < aaFile.seriesCount; ++seriesCtr)
+		assert(_vm->_resourceManager->resourceExists(aaFile.filenames[seriesCtr].c_str()));
+
+	// Start sound
+	if (aaFile.flags & AA_HAS_SOUND)
+	{
+		char buffer[100];
+		strcpy(buffer, aaFile.soundName.c_str());
+		buffer[0] = 'A';	// A for Adlib resource
+
+		Common::SeekableReadStream *stream = _vm->_resourceManager->get(buffer);
+		
+		_vm->_resourceManager->toss(buffer);
+	}
+	
+
+	char artFile[80];
+	sprintf(artFile, "rm%d.art", aaFile.roomNumber);
+
 	// Not all scenes have a background. If there is one, refresh it
-	if (_vm->_resourceManager->resourceExists(bgFile)) {
+	if (_vm->_resourceManager->resourceExists(artFile)) {
 		if (_palData) {
 			_vm->_palette->deleteRange(_palData);
 			delete _palData;
 		}
-		_bgSurface.loadBackground(bgNumber, &_palData);
+		_bgSurface.loadBackground(aaFile.roomNumber, &_palData);
 		_vm->_palette->addRange(_palData);
 		_bgSurface.translate(_palData);
 	}
@@ -581,10 +640,10 @@
 	int yp = (height() - _bgSurface.height()) / 2;
 	_bgSurface.copyTo(this, 0, yp);
 
-	// Read next line
-	processLines();
+	_vm->_resourceManager->toss(_currentLine);
 }
 
+
 void AnimviewView::scriptDone() {
 	AnimviewCallback fn = _callback;
 	M4Engine *vm = _vm;
@@ -596,52 +655,6 @@
 		fn(vm);
 }
 
-void AnimviewView::processLines() {
-	strncpy(_currentLine, _script->readLine().c_str(), 79);
-	if (_script->eos() || _script->err()) {
-		// end of script, end animation
-		scriptDone();
-		return;
-	}
-
-	while (!_script->eos() && !_script->err()) {
-		// Process the line
-		char *cStart = strchr(_currentLine, '-');
-		if (cStart) {
-			while (cStart) {
-				// Loop for possible multiple commands on one line
-				char *cEnd = strchr(_currentLine, ' ');
-				if (!cEnd)
-					error("Unterminated command '%s' in response file", _currentLine);
-
-				*cEnd = '\0';
-				processCommand();
-
-				// Copy rest of line (if any) to start of buffer
-				// Don't use strcpy() here, because if the
-				// rest of the line is the longer of the two
-				// strings, the memory areas will overlap.
-				memmove(_currentLine, cEnd + 1, strlen(cEnd + 1) + 1);
-
-				cStart = strchr(_currentLine, '-');
-			}
-
-			if (_currentLine[0]) {
-				sprintf(_currentFile, "%s", _currentLine);
-				//printf("File: %s\n", _currentLine);
-				break;
-			}
-
-		} else {
-			sprintf(_currentFile, "%s", _currentLine);
-			//printf("File: %s\n", _currentLine);
-			break;
-		}
-
-		strncpy(_currentLine, _script->readLine().c_str(), 79);
-	}
-}
-
 /*
 Switches are: (taken from the help of the original executable)
   -b       Toggle background load status off/on.
@@ -705,4 +718,45 @@
 	}
 }
 
+AAFile::AAFile(const char *resourceName, M4Engine* vm): MadsPack(resourceName, vm) {
+	Common::MemoryReadStream stream1(*getItemStream(1));
+	Common::MemoryReadStream stream2(*getItemStream(2));
+
+	Common::MemoryReadStream stream(*getItemStream(0));
+printf("ss %d %d %d\n", stream.size(), stream1.size(), stream2.size());
+	seriesCount = stream.readUint16LE();
+	frameCount = stream.readUint16LE();
+	frameEntryCount = stream.readUint16LE();
+	stream.skip(3);
+	flags = stream.readByte();
+	stream.skip(4);
+	roomNumber = stream.readUint16LE();
+	stream.skip(10);
+	frameTicks = stream.readUint16LE();
+
+	stream.skip(21);
+	for (int i = 0; i < 10; ++i) {
+		char filename[13];
+		stream.read(filename, 13);
+		filenames.push_back(Common::String(filename, 13));
+	}
+
+	stream.skip(81);
+	char name[100];
+	stream.read(name, 13);
+	lbmFilename = Common::String(name, 13);
+
+	stream.skip(365);
+	stream.read(name, 13);
+	spritesFilename = Common::String(name, 13);
+
+	stream.skip(48);
+	stream.read(name, 13);
+	soundName = Common::String(name, 13);
+
+	stream.skip(26);
+	stream.read(name, 14);
+	fontResource = Common::String(name, 14);
 }
+
+}

Modified: scummvm/trunk/engines/m4/scene.h
===================================================================
--- scummvm/trunk/engines/m4/scene.h	2009-11-11 02:25:42 UTC (rev 45826)
+++ scummvm/trunk/engines/m4/scene.h	2009-11-11 09:55:05 UTC (rev 45827)
@@ -44,17 +44,17 @@
 #define MADS_SURFACE_HEIGHT 156
 
 enum MADSVerbs {
-	kVerbLook	= 2,
-	kVerbTake	= 3,
-	kVerbPush	= 4,
-	kVerbOpen	= 5,
-	kVerbPut	= 6,
-	kVerbTalkTo	= 7,
-	kVerbGive	= 8,
-	kVerbPull	= 9,
-	kVerbClose	= 10,
-	kVerbThrow	= 11,
-	kVerbWalkTo	= 12
+	kVerbLook	= 3,
+	kVerbTake	= 4,
+	kVerbPush	= 5,
+	kVerbOpen	= 6,
+	kVerbPut	= 7,
+	kVerbTalkTo	= 8,
+	kVerbGive	= 9,
+	kVerbPull	= 10,
+	kVerbClose	= 11,
+	kVerbThrow	= 12,
+	kVerbWalkTo	= 13
 };
 
 struct SceneResources {


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