[Scummvm-cvs-logs] CVS: scummvm/queen credits.cpp,NONE,1.1 credits.h,NONE,1.1 cutaway.cpp,1.96,1.97 logic.cpp,1.153,1.154 logic.h,1.98,1.99 module.mk,1.18,1.19 resource.cpp,1.37,1.38 resource.h,1.28,1.29

David Eriksson twogood at users.sourceforge.net
Mon Jan 5 03:59:01 CET 2004


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv1499

Modified Files:
	cutaway.cpp logic.cpp logic.h module.mk resource.cpp 
	resource.h 
Added Files:
	credits.cpp credits.h 
Log Message:
At last - credits!


--- NEW FILE: credits.cpp ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/queen/credits.cpp,v 1.1 2004/01/05 11:58:19 twogood Exp $
 *
 */

#include "stdafx.h"
#include "queen/credits.h"

#include "queen/graphics.h"
#include "queen/queen.h"
#include "queen/resource.h"

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) {
	_credits = new LineReader(
			(char*)_vm->resource()->loadFile(filename));
}

Credits::~Credits() {
	_vm->graphics()->textClear(0, 199);
	delete _credits;
}

void Credits::nextRoom() {
	if (-1 == _pause) {
		_pause = 0;
		_vm->graphics()->textClear(0, 199);
	}
}

void Credits::update() {
	if (!_running)
		return;

	if (_pause > 0) {
		_pause--;
		if (!_pause)
			_vm->graphics()->textClear(0, 199);
		return;
	}

	/* wait until next room */
	if (-1 == _pause)
		return;

	for (;;) {
		char *line = _credits->nextLine();

		if (0 == memcmp(line, "EN", 2)) {
			_running = false;
			return;
		}

		if ('.' == line[0]) {
			int i;

			switch (tolower(line[1])) {
				
				case 'l' :
					_justify = 0;
					break;
				case 'c' :
					_justify = 1;
					break;
				case 'r' :
					_justify = 2;
					break;

				case 's' :
					_fontSize = 0;
					break;
				case 'b' :
					_fontSize = 1;
					break;

				case 'p' :
					sscanf(&line[3], "%d\n", &_pause);
					_pause *= 10;

					/* wait until next room */
					if (0 == _pause)
						_pause = -1;


					for(i = 0; i < _count; i++)
					{
						_vm->graphics()->textCurrentColor(_list[i].color);
						_vm->graphics()->textSet(_list[i].x, _list[i].y, _list[i].text);
					}

					_count = 0;
					return;
					
				case 'i' :
					sscanf(&line[3], "%d\n", &_color);
					break;

				case '1' :
				case '2' :
				case '3' :
				case '4' :
				case '5' :
				case '6' :
				case '7' :
				case '8' :
				case '9' :
					_zone = line[1] - '1';
					break;
			}

		}
		else {
			_list[_count].text = line;
			_list[_count].color = _color;
			_list[_count].fontSize = _fontSize;

			switch (_justify) {
				case 0:
					_list[_count].x = (_zone % 3) * (320 / 3) + 8;
					break;
				case 1:
					_list[_count].x = (_zone % 3) * (320 / 3) + 54 - _vm->graphics()->textWidth(line) / 2;
					if (_list[_count].x < 8)
						_list[_count].x = 8;
					break;
				case 2:
					_list[_count].x = (_zone % 3) * (320 / 3) + 100 - _vm->graphics()->textWidth(line);
					break;
			}

			_list[_count].y = (_zone / 3) * (200 / 3) + (_count * 10);
			_count++;
		}
	}
}


} // End of namespace Queen


--- NEW FILE: credits.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/queen/credits.h,v 1.1 2004/01/05 11:58:19 twogood Exp $
 *
 */

#ifndef CREDITS_H
#define CREDITS_H

#include "common/util.h"
#include "queen/defs.h"

namespace Queen {

class QueenEngine;
class LineReader;

class Credits {

public:

	Credits(QueenEngine *vm, const char* filename);
	~Credits();

	void update();
	void nextRoom();

	bool running() const { return _running; }

private:

	QueenEngine *_vm;
	LineReader *_credits;

	struct Line
	{
		short x,y,color,fontSize;
		char *text;
	};

	Line _list[15];

	bool _running;
	int _count;
	int _pause;
	int _justify;
	int _fontSize;
	int _color;
	int _zone;

};

} // End of namespace Queen

#endif

Index: cutaway.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/cutaway.cpp,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- cutaway.cpp	30 Dec 2003 21:06:22 -0000	1.96
+++ cutaway.cpp	5 Jan 2004 11:58:19 -0000	1.97
@@ -22,6 +22,7 @@
 #include "stdafx.h"
 #include "queen/cutaway.h"
 
+#include "queen/credits.h"
 #include "queen/display.h"
 #include "queen/graphics.h"
 #include "queen/input.h"
@@ -820,8 +821,8 @@
 
 	if (0 != strcmp(sentence, "*")) {
 		if (sentence[0] == '#') {
-			warning("Credit scripting system not yet implemented");
-			// XXX Cinit(sentence + 1);
+			debug(0, "Starting credits");
+			_vm->logic()->startCredits(sentence + 1);
 		}
 		else {
 			if (object.objectNumber > 0) {
@@ -1095,7 +1096,7 @@
 		int i;
 		
 		// Stop the credits from running
-		// XXX CFlag = 0;
+		_vm->logic()->stopCredits();
 		
 		_vm->graphics()->bobStopAll();
 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- logic.cpp	4 Jan 2004 20:25:21 -0000	1.153
+++ logic.cpp	5 Jan 2004 11:58:19 -0000	1.154
@@ -24,6 +24,7 @@
 
 #include "common/config-manager.h"
 #include "queen/command.h"
+#include "queen/credits.h"
 #include "queen/cutaway.h"
 #include "queen/debug.h"
 #include "queen/defs.h"
@@ -42,7 +43,7 @@
 namespace Queen {
 
 Logic::Logic(QueenEngine *vm)
-	: _vm(vm) {
+	:  _queen2jas(NULL), _vm(vm), _credits(NULL) {
 	_joe.x = _joe.y = 0;
 	_joe.scale = 100;
 	memset(_gameState, 0, sizeof(_gameState));
@@ -61,6 +62,10 @@
 	}
 }
 
+Logic::~Logic() {
+	delete _credits;
+	delete _queen2jas;
+}
 
 void Logic::initialise() {
 	
@@ -72,6 +77,8 @@
 	uint8 *jas = _vm->resource()->loadFile("QUEEN.JAS", 20);
 	uint8 *ptr = jas;
 
+	_queen2jas = new LineReader((char*)_vm->resource()->loadFile("QUEEN2.JAS"));
+
 	_numRooms = READ_BE_UINT16(ptr); ptr += 2;
 	_numNames = READ_BE_UINT16(ptr); ptr += 2;
 	_numObjects = READ_BE_UINT16(ptr); ptr += 2;
@@ -215,7 +222,7 @@
 	_objDescription = new char*[_numDescriptions + 1];
 	_objDescription[0] = 0;
 	for (i = 1; i <= _numDescriptions; i++)
-		_objDescription[i] = _vm->resource()->getJAS2Line();
+		_objDescription[i] = _queen2jas->nextLine();
 
 	//Patch for German text bug
 	if (_vm->resource()->getLanguage() == GERMAN) {
@@ -227,35 +234,35 @@
 	_objName = new char*[_numNames + 1];
 	_objName[0] = 0;
 	for (i = 1; i <= _numNames; i++)
-		_objName[i] = _vm->resource()->getJAS2Line();
+		_objName[i] = _queen2jas->nextLine();
 
 	_roomName = new char*[_numRooms + 1];
 	_roomName[0] = 0;
 	for (i = 1; i <= _numRooms; i++)
-		_roomName[i] = _vm->resource()->getJAS2Line();
+		_roomName[i] = _queen2jas->nextLine();
 
 	_verbName[0] = 0;
 	for (i = 1; i <= 12; i++)
-		_verbName[i] = _vm->resource()->getJAS2Line();
+		_verbName[i] = _queen2jas->nextLine();
 
 	_joeResponse[0] = 0;
 	for (i = 1; i <= JOE_RESPONSE_MAX; i++)
-		_joeResponse[i] = _vm->resource()->getJAS2Line();
+		_joeResponse[i] = _queen2jas->nextLine();
 
 	_aAnim = new char*[_numAAnim + 1];
 	_aAnim[0] = 0;
 	for (i = 1; i <= _numAAnim; i++)
-		_aAnim[i] = _vm->resource()->getJAS2Line();
+		_aAnim[i] = _queen2jas->nextLine();
 
 	_aName = new char*[_numAName + 1];
 	_aName[0] = 0;
 	for (i = 1; i <= _numAName; i++)
-		_aName[i] = _vm->resource()->getJAS2Line();
+		_aName[i] = _queen2jas->nextLine();
 	
 	_aFile = new char*[_numAFile + 1];
 	_aFile[0] = 0;
 	for (i = 1; i <= _numAFile; i++)
-		_aFile[i] = _vm->resource()->getJAS2Line();
+		_aFile[i] = _queen2jas->nextLine();
 
 
 	// Step 3 : initialise game state / variables
@@ -978,6 +985,9 @@
 
 	roomErase();
 
+	if (_credits)
+		_credits->nextRoom();
+
 	roomSetup(roomName(room), comPanel, inCutaway);
 	ObjectData *pod = NULL;
 	if (mode != RDM_FADE_NOJOE) {
@@ -2078,6 +2088,8 @@
 	}
 
 	_vm->graphics()->update(_currentRoom);
+	if (_credits)
+		_credits->update();
 
 	_vm->input()->delay();
 
@@ -3178,6 +3190,19 @@
 void Logic::asmEndInterview() {
 	debug(0, "Interactive Interview copyright (c) 1995, IBI.");
 	OSystem::instance()->quit();
+}
+
+void Logic::startCredits(const char *filename) {
+
+	stopCredits();
+	_credits = new Credits(_vm, filename);
+}
+
+void Logic::stopCredits() {
+	if (_credits) {
+		delete _credits;
+		_credits = NULL;
+	}
 }
 
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.h,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- logic.h	2 Jan 2004 14:17:42 -0000	1.98
+++ logic.h	5 Jan 2004 11:58:19 -0000	1.99
@@ -25,6 +25,7 @@
 #include "common/util.h"
 #include "queen/defs.h"
 #include "queen/structs.h"
+#include "queen/resource.h"
 
 namespace Queen {
 
@@ -53,11 +54,13 @@
 };
 
 class QueenEngine;
+class Credits;
 
 class Logic {
 
 public:
 	Logic(QueenEngine *vm);
+	~Logic();
 
 	uint16 currentRoom() const { return _currentRoom; }
 	void currentRoom(uint16 room) { 
@@ -296,6 +299,9 @@
 	void asmInterviewIntro();
 	void asmEndInterview();
 
+	void startCredits(const char *filename);
+	void stopCredits();
+
 	typedef bool (Logic::*ExecuteSpecialMoveProc)(uint16);
 	typedef bool (Logic::*PreChangeRoomProc)();
 
@@ -312,6 +318,8 @@
 
 	void initialise();
 
+	LineReader *_queen2jas;
+
 	uint16 _currentRoom;
 	uint16 _oldRoom;
 	uint16 _newRoom;
@@ -440,6 +448,7 @@
 	PreChangeRoomProc _preChangeRoom;
 
 	QueenEngine *_vm;
+	Credits *_credits;
 };
 
 

Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/module.mk,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- module.mk	14 Dec 2003 00:33:21 -0000	1.18
+++ module.mk	5 Jan 2004 11:58:20 -0000	1.19
@@ -2,6 +2,7 @@
 
 MODULE_OBJS = \
 	queen/command.o \
+	queen/credits.o \
 	queen/cutaway.o \
 	queen/debug.o \
 	queen/display.o \

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- resource.cpp	31 Dec 2003 16:15:46 -0000	1.37
+++ resource.cpp	5 Jan 2004 11:58:20 -0000	1.38
@@ -44,14 +44,13 @@
 
 
 Resource::Resource(const Common::String &datafilePath, SaveFileManager *mgr, const char *savePath)
-	: _JAS2Pos(0), _datafilePath(datafilePath), _savePath(savePath), _resourceEntries(0), _resourceTable(NULL), _saveFileManager(mgr) {
+	: _datafilePath(datafilePath), _savePath(savePath), _resourceEntries(0), _resourceTable(NULL), _saveFileManager(mgr) {
 
 	_resourceFile = new File();
 	if (!findCompressedVersion() && !findNormalVersion())
 		error("Could not open resource file '%s%s'", _datafilePath.c_str(), "queen.1");
 	checkJASVersion();
 	debug(5, "Detected game version: %s, which has %d resource entries", _versionString, _resourceEntries);
-	_JAS2Ptr = (char *)loadFile("QUEEN2.JAS", 0);
 }
 
 Resource::~Resource() {
@@ -59,7 +58,6 @@
 	delete _resourceFile;
 	if(_resourceTable != _resourceTablePEM10) 
 		delete[] _resourceTable;
-	delete[] _JAS2Ptr;
 	delete _saveFileManager;
 }
 
@@ -112,17 +110,6 @@
 		return NULL;
 }
 
-char *Resource::getJAS2Line() {
-	assert(_JAS2Pos < resourceEntry("QUEEN2.JAS")->size);
-	char *startOfLine = _JAS2Ptr + _JAS2Pos;
-	char *curPos = startOfLine;
-	while (*curPos++ != 0xd) ;
-	*(curPos - 1) = '\0';     // '\r'
-	*curPos = '\0';           // '\n'
-	_JAS2Pos = (curPos - _JAS2Ptr) + 1;
-	return startOfLine;
-}
-
 uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
 	ResourceEntry *re = resourceEntry(filename);
 	assert(re != NULL);
@@ -293,6 +280,23 @@
 	}
 
 	return true;
+}
+
+LineReader::LineReader(char *buffer) : _buffer(buffer), _current(0) {
+}
+
+LineReader::~LineReader() {
+	delete[] _buffer;
+}
+
+char* LineReader::nextLine() {
+	char *startOfLine = _buffer + _current;
+	char *curPos = startOfLine;
+	while (*curPos++ != 0xd) ;
+	*(curPos - 1) = '\0';     // '\r'
+	*curPos = '\0';           // '\n'
+	_current = (curPos - _buffer) + 1;
+	return startOfLine;
 }
 
 } // End of namespace Queen

Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- resource.h	31 Dec 2003 16:15:46 -0000	1.28
+++ resource.h	5 Jan 2004 11:58:20 -0000	1.29
@@ -61,6 +61,17 @@
 	uint32 dataFileSize;
 };
 
+class LineReader {
+
+public:
+	LineReader(char *buffer);
+	~LineReader();
+	char* nextLine();
+
+private:
+	char *_buffer;
+	int _current;
+};
 
 class Resource {
 
@@ -81,7 +92,6 @@
 	uint8 compression() const { return _compression; }
 	const char *JASVersion() const { return _versionString; }
 	Language getLanguage() const;
-	char *getJAS2Line();
 
 	bool writeSave(uint16 slot, const byte *saveData, uint32 size);
 	bool readSave(uint16 slot, byte *&ptr);
@@ -94,8 +104,6 @@
 
 protected:
 	File *_resourceFile;
-	char *_JAS2Ptr;
-	uint32 _JAS2Pos;
 	uint8 _compression;
 	const Common::String _datafilePath;
 	char _versionString[6];





More information about the Scummvm-git-logs mailing list