[Scummvm-cvs-logs] SF.net SVN: scummvm: [25871] scummvm/trunk/engines/queen

cyx at users.sourceforge.net cyx at users.sourceforge.net
Sun Feb 25 23:24:12 CET 2007


Revision: 25871
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25871&view=rev
Author:   cyx
Date:     2007-02-25 14:24:11 -0800 (Sun, 25 Feb 2007)

Log Message:
-----------
reduced code dup, Queen::LineReader -> SeekableReadStream::readLine

Modified Paths:
--------------
    scummvm/trunk/engines/queen/credits.cpp
    scummvm/trunk/engines/queen/credits.h
    scummvm/trunk/engines/queen/journal.cpp
    scummvm/trunk/engines/queen/logic.cpp
    scummvm/trunk/engines/queen/logic.h
    scummvm/trunk/engines/queen/resource.cpp
    scummvm/trunk/engines/queen/resource.h

Modified: scummvm/trunk/engines/queen/credits.cpp
===================================================================
--- scummvm/trunk/engines/queen/credits.cpp	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/credits.cpp	2007-02-25 22:24:11 UTC (rev 25871)
@@ -30,16 +30,10 @@
 namespace Queen {
 
 Credits::Credits(QueenEngine *vm, const char* filename) :
-	_vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0) {
-	uint32 size;
-	char *buf = (char *)_vm->resource()->loadFile(filename, 0, &size);
-	_credits = new LineReader(buf, size);
+	_vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0), _lineNum(0) {
+	_vm->resource()->loadTextFile(filename, _credits);
 }
 
-Credits::~Credits() {
-	delete _credits;
-}
-
 void Credits::nextRoom() {
 	if (-1 == _pause) {
 		_pause = 0;
@@ -62,8 +56,9 @@
 	if (-1 == _pause)
 		return;
 
-	for (;;) {
-		const char *line = _credits->nextLine();
+	while (_lineNum < _credits.size()) {
+		const char *line = _credits[_lineNum].c_str();
+		++_lineNum;
 
 		if (0 == memcmp(line, "EN", 2)) {
 			_running = false;

Modified: scummvm/trunk/engines/queen/credits.h
===================================================================
--- scummvm/trunk/engines/queen/credits.h	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/credits.h	2007-02-25 22:24:11 UTC (rev 25871)
@@ -35,7 +35,6 @@
 public:
 
 	Credits(QueenEngine *vm, const char* filename);
-	~Credits();
 
 	//! update/display credits for current room
 	void update();
@@ -77,8 +76,10 @@
 	//! current text position
 	int _zone;
 
+	uint _lineNum;
+
 	//! contains the credits description
-	LineReader *_credits;
+	Common::StringList _credits;
 
 	QueenEngine *_vm;
 };

Modified: scummvm/trunk/engines/queen/journal.cpp
===================================================================
--- scummvm/trunk/engines/queen/journal.cpp	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/journal.cpp	2007-02-25 22:24:11 UTC (rev 25871)
@@ -418,7 +418,11 @@
 	int y = 8;
 	while (n--) {
 		showBob(bobNum++, 32, y, *frames++);
-		drawPanelText(y + 12, _vm->logic()->joeResponse(*titles++));
+		// trim panel texts for spanish version
+		char buf[128];
+		strncpy(buf, _vm->logic()->joeResponse(*titles++), 128);
+		buf[127] = 0;
+		drawPanelText(y + 12, Common::trim(buf));
 		y += 48;
 	}
 }

Modified: scummvm/trunk/engines/queen/logic.cpp
===================================================================
--- scummvm/trunk/engines/queen/logic.cpp	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/logic.cpp	2007-02-25 22:24:11 UTC (rev 25871)
@@ -181,66 +181,22 @@
 	if (memcmp(ptr, _vm->resource()->getJASVersion(), 5) != 0) {
 		warning("Unexpected queen.jas file format");
 	}
-
 	delete[] jas;
 
-	uint32 size;
-	char *buf = (char *)_vm->resource()->loadFile("QUEEN2.JAS", 0, &size);
-	LineReader queen2jas(buf, size);
+	_vm->resource()->loadTextFile("QUEEN2.JAS", _jasStringList);
+	_jasStringOffset[0] = 0;
+	_jasStringOffset[1] = _jasStringOffset[0] + _numDescriptions;
+	_jasStringOffset[2] = _jasStringOffset[1] + _numNames;
+	_jasStringOffset[3] = _jasStringOffset[2] + _numRooms;
+	_jasStringOffset[4] = _jasStringOffset[3] + 12;
+	_jasStringOffset[5] = _jasStringOffset[4] + JOE_RESPONSE_MAX;
+	_jasStringOffset[6] = _jasStringOffset[5] + _numAAnim;
+	_jasStringOffset[7] = _jasStringOffset[6] + _numAName;
 
-	_objDescription.push_back("");
-	for (i = 1; i <= _numDescriptions; i++) {
-		_objDescription.push_back(queen2jas.nextLine());
-	}
-
 	// Patch for German text bug
 	if (_vm->resource()->getLanguage() == Common::DE_DEU) {
-		_objDescription[296] = "Es bringt nicht viel, das festzubinden.";
+		_jasStringList[_jasStringOffset[JSO_OBJECT_DESCRIPTION] + 296 - 1] = "Es bringt nicht viel, das festzubinden.";
 	}
-
-	_objName.push_back("");
-	for (i = 1; i <= _numNames; i++) {
-		_objName.push_back(queen2jas.nextLine());
-	}
-
-	_roomName.push_back("");
-	for (i = 1; i <= _numRooms; i++) {
-		_roomName.push_back(queen2jas.nextLine());
-	}
-
-	_verbName.push_back("");
-	for (i = 1; i <= 12; i++) {
-		_verbName.push_back(queen2jas.nextLine());
-	}
-
-	_joeResponse.push_back("");
-	for (i = 1; i <= JOE_RESPONSE_MAX; i++) {
-		char *defaultResponse = queen2jas.nextLine();
-
-		// In the spanish version, captions of journal buttons have leading & trailing
-		// whitespaces (they probably did it that way to center the texts). As we do
-		// differently (see code in journal.cpp), we remove these extra characters here.
-		if (_vm->resource()->getLanguage() == Common::ES_ESP && i >= 30 && i <= 35) {
-			defaultResponse = Common::trim(defaultResponse);
-		}
-
-		_joeResponse.push_back(defaultResponse);
-	}
-
-	_aAnim.push_back("");
-	for (i = 1; i <= _numAAnim; i++) {
-		_aAnim.push_back(queen2jas.nextLine());
-	}
-
-	_aName.push_back("");
-	for (i = 1; i <= _numAName; i++) {
-		_aName.push_back(queen2jas.nextLine());
-	}
-
-	_aFile.push_back("");
-	for (i = 1; i <= _numAFile; i++) {
-		_aFile.push_back(queen2jas.nextLine());
-	}
 }
 
 void Logic::start() {
@@ -256,11 +212,6 @@
 	_newRoom = _currentRoom;
 }
 
-ObjectData* Logic::objectData(int index) const {
-	assert(index >= 0 && index <= _numObjects);
-	return &_objectData[index];
-}
-
 uint16 Logic::findBob(uint16 obj) const {
 	assert(obj <= _numObjects);
 
@@ -441,29 +392,47 @@
 
 const char *Logic::roomName(uint16 roomNum) const {
 	assert(roomNum >= 1 && roomNum <= _numRooms);
-	return _roomName[roomNum].c_str();
+	return _jasStringList[_jasStringOffset[JSO_ROOM_NAME] + roomNum - 1].c_str();
 }
 
 const char *Logic::objectName(uint16 objNum) const {
 	assert(objNum >= 1 && objNum <= _numNames);
-	return _objName[objNum].c_str();
+	return _jasStringList[_jasStringOffset[JSO_OBJECT_NAME] + objNum - 1].c_str();
 }
 
 const char *Logic::objectTextualDescription(uint16 objNum) const {
 	assert(objNum >= 1 && objNum <= _numDescriptions);
-	return _objDescription[objNum].c_str();
+	return _jasStringList[_jasStringOffset[JSO_OBJECT_DESCRIPTION] + objNum - 1].c_str();
 }
 
 const char *Logic::joeResponse(int i) const {
 	assert(i >= 1 && i <= JOE_RESPONSE_MAX);
-	return _joeResponse[i].c_str();
+	return _jasStringList[_jasStringOffset[JSO_JOE_RESPONSE] + i - 1].c_str();
 }
 
 const char *Logic::verbName(Verb v) const {
 	assert(v >= 0 && v <= 12);
-	return _verbName[v].c_str();
+	if (v == 0) {
+		return "";
+	}
+	return _jasStringList[_jasStringOffset[JSO_VERB_NAME] + v - 1].c_str();
 }
 
+const char *Logic::actorAnim(int num) const {
+	assert(num >= 1 && num < _numAAnim);
+	return _jasStringList[_jasStringOffset[JSO_ACTOR_ANIM] + num - 1].c_str();
+}
+
+const char *Logic::actorName(int num) const {
+	assert(num >= 1 && num < _numAName);
+	return _jasStringList[_jasStringOffset[JSO_ACTOR_NAME] + num - 1].c_str();
+}
+
+const char *Logic::actorFile(int num) const {
+	assert(num >= 1 && num < _numAFile);
+	return _jasStringList[_jasStringOffset[JSO_ACTOR_FILE] + num - 1].c_str();
+}
+
 void Logic::eraseRoom() {
 	_vm->bankMan()->eraseFrames(false);
 	_vm->bankMan()->close(15);
@@ -559,7 +528,7 @@
 		for (uint16 i = 1; i <= _numActors; ++i) {
 			ActorData *pad = &_actorData[i];
 			if (pad->room == _currentRoom && gameState(pad->gsSlot) == pad->gsValue) {
-				if (bobNum == pad->bobNum || (name && _aName[pad->name] == name)) {
+				if (bobNum == pad->bobNum || (name && strcmp(actorName(pad->name), name) == 0)) {
 					return pad;
 				}
 			}
@@ -568,18 +537,18 @@
 	return NULL;
 }
 
-bool Logic::initPerson(uint16 noun, const char *actorName, bool loadBank, Person *pp) {
-	const ActorData *pad = findActor(noun, actorName);
+bool Logic::initPerson(uint16 noun, const char *name, bool loadBank, Person *pp) {
+	const ActorData *pad = findActor(noun, name);
 	if (pad != NULL) {
 		pp->actor = pad;
-		pp->name = _aName[pad->name].c_str();
+		pp->name = actorName(pad->name);
 		if (pad->anim != 0) {
-			pp->anim = _aAnim[pad->anim].c_str();
+			pp->anim = actorAnim(pad->anim);
 		} else {
 			pp->anim = NULL;
 		}
 		if (loadBank && pad->file != 0) {
-			_vm->bankMan()->load(_aFile[pad->file].c_str(), pad->bankNum);
+			_vm->bankMan()->load(actorFile(pad->file), pad->bankNum);
 			// if there is no valid actor file (ie pad->file is 0), the person
 			// data is already loaded as it is included in objects room bank (.bbk)
 		}
@@ -613,7 +582,7 @@
 }
 
 void Logic::setupJoe() {
-	loadJoeBanks("joe_a.BBK", "joe_b.BBK");
+	loadJoeBanks("JOE_A.BBK", "JOE_B.BBK");
 	joePrevFacing(DIR_FRONT);
 	joeFacing(DIR_FRONT);
 }
@@ -871,7 +840,7 @@
 }
 
 void Logic::makeJoeSpeak(uint16 descNum, bool objectType) {
-	const char *text = objectType ? _objDescription[descNum].c_str() : _joeResponse[descNum].c_str();
+	const char *text = objectType ? objectTextualDescription(descNum) : joeResponse(descNum);
 	if (objectType) {
 		descNum += JOE_RESPONSE_MAX;
 	}
@@ -1963,8 +1932,8 @@
 	bob->y = 300;
 	bob->scale = 100;
 	while (bob->y >= 120) {
-		bob->y -= 4;
 		_vm->update();
+		bob->y -= 4;
 	}
 }
 

Modified: scummvm/trunk/engines/queen/logic.h
===================================================================
--- scummvm/trunk/engines/queen/logic.h	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/logic.h	2007-02-25 22:24:11 UTC (rev 25871)
@@ -43,9 +43,20 @@
 	JWM_SPEAK   = 3
 };
 
+enum {
+	JSO_OBJECT_DESCRIPTION = 0,
+	JSO_OBJECT_NAME,
+	JSO_ROOM_NAME,
+	JSO_VERB_NAME,
+	JSO_JOE_RESPONSE,
+	JSO_ACTOR_ANIM,
+	JSO_ACTOR_NAME,
+	JSO_ACTOR_FILE,
+	JSO_COUNT
+};
+
 class Credits;
 class Journal;
-class LineReader;
 class QueenEngine;
 
 class Logic {
@@ -72,7 +83,7 @@
 		_newRoom = room;
 	}
 
-	ObjectData *objectData(int index) const;
+	ObjectData *objectData(int index) const { return &_objectData[index]; }
 	uint16 roomData(int room) const { return _roomData[room]; }
 	GraphicData *graphicData(int index) const { return &_graphicData[index]; }
 	ItemData *itemData(int index) const { return &_itemData[index]; }
@@ -117,6 +128,9 @@
 	const char *objectTextualDescription(uint16 objNum) const;
 	const char *joeResponse(int i) const;
 	const char *verbName(Verb v) const;
+	const char *actorAnim(int num) const;
+	const char *actorName(int num) const;
+	const char *actorFile(int num) const;
 
 	void eraseRoom();
 	void setupRoom(const char *room, int comPanel, bool inCutaway);
@@ -321,30 +335,13 @@
 	//! actor initial position in room is _walkOffData[_entryObj]
 	int16 _entryObj;
 
-	//! object description (Look At)
-	Common::StringList _objDescription;
-	uint16 _numDescriptions;
+	Common::StringList _jasStringList;
+	int _jasStringOffset[JSO_COUNT];
 
-	Common::StringList _objName;
+	uint16 _numDescriptions;
 	uint16 _numNames;
-
-	//! room name, prefix for data files (PCX, LUM...)
-	Common::StringList _roomName;
-
-	Common::StringList _verbName;
-
-	Common::StringList _joeResponse;
-
-	//! actor animation strings
-	Common::StringList _aAnim;
 	uint16 _numAAnim;
-
-	//! actor names
-	Common::StringList _aName;
 	uint16 _numAName;
-
-	//! actor filenames
-	Common::StringList _aFile;
 	uint16 _numAFile;
 
 	struct {
@@ -366,7 +363,7 @@
 
 	//! cutscene counter
 	int _scene;
-	
+
 	SpecialMoveProc _specialMoves[40];
 
 	Credits *_credits;

Modified: scummvm/trunk/engines/queen/resource.cpp
===================================================================
--- scummvm/trunk/engines/queen/resource.cpp	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/resource.cpp	2007-02-25 22:24:11 UTC (rev 25871)
@@ -90,10 +90,6 @@
 }
 
 ResourceEntry *Resource::resourceEntry(const char *filename) const {
-	if (filename[0] == 0 || strlen(filename) >= 14) {
-		uint8 *p = 0;
-		*p = 0x1234;
-	}
 	assert(filename[0] && strlen(filename) < 14);
 
 	Common::String entryName(filename);
@@ -129,6 +125,18 @@
 	return dstBuf;
 }
 
+void Resource::loadTextFile(const char *filename, Common::StringList &stringList) {
+	debug(7, "Resource::loadTextFile('%s')", filename);
+	ResourceEntry *re = resourceEntry(filename);
+	assert(re != NULL);
+	seekResourceFile(re->bundle, re->offset);
+	char buf[512];
+	Common::SeekableSubReadStream stream(&_resourceFile, re->offset, re->offset + re->size);
+	while (stream.readLine(buf, 512)) {
+		stringList.push_back(buf);
+	}
+}
+
 bool Resource::detectVersion(DetectedGameVersion *ver, Common::File *f) {
 	memset(ver, 0, sizeof(DetectedGameVersion));
 
@@ -306,25 +314,6 @@
 	return NULL;
 }
 
-LineReader::LineReader(char *buffer, uint32 bufsize) : _buffer(buffer), _bufSize(bufsize), _current(0) {
-}
-
-LineReader::~LineReader() {
-	delete[] _buffer;
-}
-
-char *LineReader::nextLine() {
-	char *startOfLine = _buffer + _current;
-	char *curPos = startOfLine;
-	while (curPos < _buffer + _bufSize && *curPos++ != 0xd) ;
-	*(curPos - 1) = '\0'; // '\r'
-	if (curPos < _buffer + _bufSize) {
-		*curPos = '\0'; // '\n'
-		_current = (curPos - _buffer) + 1;
-	}
-	return startOfLine;
-}
-
 } // End of namespace Queen
 
 #ifdef PALMOS_68K

Modified: scummvm/trunk/engines/queen/resource.h
===================================================================
--- scummvm/trunk/engines/queen/resource.h	2007-02-25 22:17:41 UTC (rev 25870)
+++ scummvm/trunk/engines/queen/resource.h	2007-02-25 22:24:11 UTC (rev 25871)
@@ -65,9 +65,12 @@
 	Resource();
 	~Resource();
 
-	//! loads the specified from the resource file
+	//! loads a binary file
 	uint8 *loadFile(const char *filename, uint32 skipBytes = 0, uint32 *size = NULL);
 
+	//! loads a text file
+	void loadTextFile(const char *filename, Common::StringList &stringList);
+
 	//! returns true if the file is present in the resource
 	bool fileExists(const char *filename) const { return resourceEntry(filename) != NULL; }
 
@@ -167,20 +170,6 @@
 #endif
 };
 
-class LineReader {
-public:
-
-	LineReader(char *buffer, uint32 bufsize);
-	~LineReader();
-	char *nextLine();
-
-private:
-
-	char *_buffer;
-	uint32 _bufSize;
-	int _current;
-};
-
 } // End of namespace Queen
 
 #endif


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