[Scummvm-cvs-logs] CVS: scummvm/queen credits.cpp,1.6,1.7 display.cpp,1.65,1.66 display.h,1.46,1.47 logic.cpp,1.199,1.200 music.cpp,1.21,1.22 queen.cpp,1.88,1.89 resource.cpp,1.48,1.49 resource.h,1.39,1.40 sound.cpp,1.42,1.43

Gregory Montoir cyx at users.sourceforge.net
Fri Aug 6 10:03:04 CEST 2004


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

Modified Files:
	credits.cpp display.cpp display.h logic.cpp music.cpp 
	queen.cpp resource.cpp resource.h sound.cpp 
Log Message:
cleanup and simplify Resource class a bit more

Index: credits.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/credits.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- credits.cpp	23 Jan 2004 16:57:22 -0000	1.6
+++ credits.cpp	6 Aug 2004 17:01:58 -0000	1.7
@@ -30,9 +30,9 @@
 
 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),
-		_vm->resource()->fileSize(filename));
+	uint32 size;
+	char *buf = (char *)_vm->resource()->loadFile(filename, 0, &size);
+	_credits = new LineReader(buf, size);
 }
 
 Credits::~Credits() {

Index: display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/display.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- display.cpp	4 Jun 2004 17:29:26 -0000	1.65
+++ display.cpp	6 Aug 2004 17:01:58 -0000	1.66
@@ -39,7 +39,6 @@
 Display::Display(QueenEngine *vm, OSystem *system)
 	: _fullscreen(true), _horizontalScroll(0), _bdWidth(0), _bdHeight(0), 
 	_system(system), _vm(vm) {
-	_dynalum.prevColMask = 0xFF;
 
 	if (vm->resource()->getLanguage() == HEBREW)
 		_font = _fontHebrew;
@@ -76,6 +75,8 @@
 	_pal.dirtyMin = 0;
 	_pal.dirtyMax = 255;
 	_pal.scrollable = true;
+	
+	memset(&_dynalum, 0, sizeof(_dynalum));
 }
 
 Display::~Display() {
@@ -96,23 +97,24 @@
 
 void Display::dynalumInit(const char *roomName, uint16 roomNum) {
 	debug(9, "Display::dynalumInit(%s, %d)", roomName, roomNum);
-	memset(_dynalum.msk, 0, sizeof(_dynalum.msk));
-	memset(_dynalum.lum, 0, sizeof(_dynalum.lum));
+
 	_dynalum.valid = false;
-	_dynalum.prevColMask = 0xFF;
+	delete[] _dynalum.mskBuf;
+	_dynalum.mskBuf = NULL;
+	delete[] _dynalum.lumBuf;
+	_dynalum.lumBuf = NULL;
 
 	if (!(Logic::isAltIntroRoom(roomNum) || Logic::isIntroRoom(roomNum))) {
 		char filename[20];
-
 		sprintf(filename, "%s.msk", roomName);
-		_dynalum.valid = _vm->resource()->fileExists(filename);
-		if (_dynalum.valid)
-			_vm->resource()->loadFile(filename, 0, (uint8*)_dynalum.msk);
-
-		sprintf(filename, "%s.lum", roomName);
-		_dynalum.valid = _vm->resource()->fileExists(filename);
-		if (_dynalum.valid)
-			_vm->resource()->loadFile(filename, 0, (uint8*)_dynalum.lum);
+		if (_vm->resource()->fileExists(filename)) {
+			_dynalum.mskBuf = (uint8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.mskSize);
+			sprintf(filename, "%s.lum", roomName);
+			if (_vm->resource()->fileExists(filename)) {
+				_dynalum.lumBuf = (int8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.lumSize);
+				_dynalum.valid = true;
+			}
+		}
 	}
 }
 
@@ -131,17 +133,17 @@
 		y = ROOM_ZONE_HEIGHT - 1;
 	}
 
-	uint offset = (y / 4) * 160 + (x / 4);
-	assert(offset < sizeof(_dynalum.msk));
+	uint32 offset = (y / 4) * 160 + (x / 4);
+	assert(offset < _dynalum.mskSize);
 
-	uint8 colMask = _dynalum.msk[offset];
+	uint8 colMask = _dynalum.mskBuf[offset];
 	debug(9, "Display::dynalumUpdate(%d, %d) - colMask = %d", x, y, colMask);
 	if (colMask != _dynalum.prevColMask) {
 		uint8 i;
 		for (i = 144; i < 160; ++i) {
 			uint8 j;
 			for (j = 0; j < 3; ++j) {
-				int16 c = (int16)(_pal.room[i * 3 + j] + _dynalum.lum[colMask * 3 + j] * 4);
+				int16 c = (int16)(_pal.room[i * 3 + j] + _dynalum.lumBuf[colMask * 3 + j] * 4);
 				if (c < 0) {
 					c = 0;
 				} else if (c > 255) {
@@ -635,8 +637,8 @@
 }
 
 void Display::setupPanel() {
-	uint8 *pcxBuf = _vm->resource()->loadFile("panel.pcx");
-	uint32 size = _vm->resource()->fileSize("panel.pcx");
+	uint32 size;
+	uint8 *pcxBuf = _vm->resource()->loadFile("panel.pcx", 0, &size);
 	uint8 *dst = _panelBuf + PANEL_W * 10;
 	readPCX(dst, PANEL_W, pcxBuf + 128, PANEL_W, PANEL_H - 10);
 	const uint8 *pal = pcxBuf + size - 768 + 144 * 3;
@@ -648,11 +650,10 @@
 
 void Display::setupNewRoom(const char *name, uint16 room) {
 	dynalumInit(name, room);
-
+	uint32 size;
 	char filename[20];
 	sprintf(filename, "%s.PCX", name);
-	uint8 *pcxBuf = _vm->resource()->loadFile(filename);
-	uint32 size = _vm->resource()->fileSize(filename);
+	uint8 *pcxBuf = _vm->resource()->loadFile(filename, 0, &size);
 	_bdWidth  = READ_LE_UINT16(pcxBuf + 12);
 	_bdHeight = READ_LE_UINT16(pcxBuf + 14);
 	readPCX(_backdropBuf, BACKDROP_W, pcxBuf + 128, _bdWidth, _bdHeight);

Index: display.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/display.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- display.h	5 May 2004 18:03:41 -0000	1.46
+++ display.h	6 Aug 2004 17:01:58 -0000	1.47
@@ -136,8 +136,10 @@
 
 	struct Dynalum {
 		bool valid;
-		uint8 msk[50 * 160];
-		int8 lum[8 * 3];
+		uint8 *mskBuf;
+		uint32 mskSize;
+		int8 *lumBuf;
+		uint32 lumSize;
 		uint8 prevColMask;
 	};
 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- logic.cpp	6 Aug 2004 11:28:33 -0000	1.199
+++ logic.cpp	6 Aug 2004 17:01:58 -0000	1.200
@@ -181,10 +181,9 @@
 
 	delete[] jas;
 
-
-	_queen2jas = new LineReader(
-		(char *)_vm->resource()->loadFile("QUEEN2.JAS"),
-		_vm->resource()->fileSize("QUEEN2.JAS"));
+	uint32 size;
+	char *buf = (char *)_vm->resource()->loadFile("QUEEN2.JAS", 0, &size);
+	_queen2jas = new LineReader(buf, size);
 	
 	_objDescription = new char*[_numDescriptions + 1];
 	_objDescription[0] = 0;

Index: music.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/music.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- music.cpp	28 Mar 2004 21:44:41 -0000	1.21
+++ music.cpp	6 Aug 2004 17:01:58 -0000	1.22
@@ -324,11 +324,9 @@
 
 	Music::Music(MidiDriver *driver, QueenEngine *vm) : _vToggle(false) {
 		if (vm->resource()->isDemo()) {
-			_musicData = vm->resource()->loadFile("AQ8.RL", 0, NULL);
-			_musicDataSize = vm->resource()->fileSize("AQ8.RL");
+			_musicData = vm->resource()->loadFile("AQ8.RL", 0, &_musicDataSize);
 		} else {
-			_musicData = vm->resource()->loadFile("AQ.RL", 0, NULL);
-			_musicDataSize = vm->resource()->fileSize("AQ.RL");
+			_musicData = vm->resource()->loadFile("AQ.RL", 0, &_musicDataSize);
 		}
 		
 		_player = new MusicPlayer(driver, _musicData, _musicDataSize);

Index: queen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- queen.cpp	6 Aug 2004 11:28:33 -0000	1.88
+++ queen.cpp	6 Aug 2004 17:01:58 -0000	1.89
@@ -329,7 +329,7 @@
 
 void QueenEngine::initialise(void) {
 	_bam = new BamScene(this);
-	_resource = new Resource(_gameDataPath);
+	_resource = new Resource();
 	_bankMan = new BankManager(_resource);
 	_command = new Command(this);
 	_debugger = new Debugger(this);

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- resource.cpp	6 Aug 2004 11:28:33 -0000	1.48
+++ resource.cpp	6 Aug 2004 17:01:58 -0000	1.49
@@ -52,11 +52,11 @@
 	return strcmp(filename, entry->filename);
 }
 
-Resource::Resource(const Common::String &datafilePath)
-	: _datafilePath(datafilePath), _resourceEntries(0), _resourceTable(NULL) {
+Resource::Resource()
+	: _resourceEntries(0), _resourceTable(NULL) {
 	_resourceFile = new File();
 	if (!findCompressedVersion() && !findNormalVersion())
-		error("Could not open resource file '%s%s'", _datafilePath.c_str(), "queen.1");
+		error("Could not open resource file '%s'", "queen.1");
 	checkJASVersion();
 	debug(5, "Detected game version: %s, which has %d resource entries", _versionString, _resourceEntries);
 }
@@ -98,26 +98,28 @@
 	return re;
 }
 
-uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
+uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, uint32 *size, bool useMalloc) {
 	ResourceEntry *re = resourceEntry(filename);
 	assert(re != NULL);
-	uint32 size = re->size - skipBytes;
+	uint32 sz = re->size - skipBytes;
+	if (size != NULL) {
+		*size = sz;
+	}
+	byte *dstBuf;
 #ifndef __PALM_OS__
-	if (dstBuf == NULL)
-		dstBuf = new byte[size];
+	if (useMalloc) {
+		dstBuf = (byte *)malloc(sz);
+	} else {
+		dstBuf = new byte[sz];
+	}
 #else
-	if (dstBuf == NULL)
-		dstBuf = (byte *)calloc(size, sizeof(byte));
+	dstBuf = (byte *)calloc(sz, sizeof(byte));
 #endif
 	_resourceFile->seek(re->offset + skipBytes);
-	_resourceFile->read(dstBuf, size);
+	_resourceFile->read(dstBuf, sz);
 	return dstBuf;
 }
 
-uint8 *Resource::loadFileMalloc(const char *filename, uint32 skipBytes, byte *dstBuf) {
-	return loadFile(filename, skipBytes, (byte *)malloc(fileSize(filename) - skipBytes));
-}
-
 bool Resource::findNormalVersion() {
 	_resourceFile->open("queen.1");
 	if (!_resourceFile->isOpen()) {
@@ -139,7 +141,7 @@
 			_resourceEntries = 1076;
 			_resourceTable = _resourceTablePEM10;
 		} else {
-			error("Could not find tablefile '%s%s'",  _datafilePath.c_str(), _tableFilename);
+			error("Could not find tablefile '%s'", _tableFilename);
 		}
 	}
 	return true;
@@ -239,10 +241,13 @@
 	return NULL;
 }
 
-File *Resource::giveCompressedSound(const char *filename) {
+File *Resource::giveCompressedSound(const char *filename, uint32 *size) {
 	assert(strstr(filename, ".SB"));
 	ResourceEntry *re = resourceEntry(filename);
 	assert(re != NULL);
+	if (size != NULL) {
+		*size = re->size;
+	}
 	_resourceFile->seek(re->offset);
 	return _resourceFile;
 }

Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- resource.h	6 Aug 2004 11:28:33 -0000	1.39
+++ resource.h	6 Aug 2004 17:01:58 -0000	1.40
@@ -77,15 +77,13 @@
 class Resource {
 
 public:
-	Resource(const Common::String &datafilePath);
-	~Resource(void);
+	Resource();
+	~Resource();
 
-	uint8 *loadFile(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
-	uint8 *loadFileMalloc(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
+	uint8 *loadFile(const char *filename, uint32 skipBytes = 0, uint32 *size = NULL, bool useMalloc = false);
 	bool fileExists(const char *filename) const { return resourceEntry(filename) != NULL; }
-	uint32 fileSize(const char *filename) const { return resourceEntry(filename)->size; }
 
-	File *giveCompressedSound(const char *filename);
+	File *giveCompressedSound(const char *filename, uint32 *size);
 
 	bool isDemo() const { return !strcmp(_versionString, "PE100"); }
 	bool isInterview() const { return !strcmp(_versionString, "PEint"); }
@@ -104,9 +102,7 @@
 protected:
 	File *_resourceFile;
 	uint8 _compression;
-	const Common::String _datafilePath;
 	char _versionString[6];
-	const char *_savePath;
 	uint32 _resourceEntries;
 	ResourceEntry *_resourceTable;
 

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/sound.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- sound.cpp	23 Mar 2004 20:34:19 -0000	1.42
+++ sound.cpp	6 Aug 2004 17:01:58 -0000	1.43
@@ -176,28 +176,40 @@
 }
 
 void SBSound::sfxPlay(const char *name, bool isSpeech) {
-	if (_vm->resource()->fileExists(name)) 
-		playSound(_vm->resource()->loadFileMalloc(name, SB_HEADER_SIZE), _vm->resource()->fileSize(name) - SB_HEADER_SIZE, isSpeech);
+	if (_vm->resource()->fileExists(name)) {
+		uint32 size;
+		uint8 *buf = _vm->resource()->loadFile(name, SB_HEADER_SIZE, &size, true);
+		playSound(buf, size, isSpeech);
+	}
 }
 
 #ifdef USE_MAD
 void MP3Sound::sfxPlay(const char *name, bool isSpeech) {
-	if (_vm->resource()->fileExists(name)) 
-		_mixer->playMP3(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
+	if (_vm->resource()->fileExists(name)) {
+		uint32 size;
+		File *f = _vm->resource()->giveCompressedSound(name, &size);
+		_mixer->playMP3(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
+	}
 }
 #endif
 
 #ifdef USE_VORBIS
 void OGGSound::sfxPlay(const char *name, bool isSpeech) {
-	if (_vm->resource()->fileExists(name))
-		_mixer->playVorbis(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
+	if (_vm->resource()->fileExists(name)) {
+		uint32 size;
+		File *f = _vm->resource()->giveCompressedSound(name, &size);		
+		_mixer->playVorbis(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
+	}
 }
 #endif
 
 #ifdef USE_FLAC
 void FLACSound::sfxPlay(const char *name, bool isSpeech) {
-	if (_vm->resource()->fileExists(name))
-		_mixer->playFlac(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
+	if (_vm->resource()->fileExists(name)) {
+		uint32 size;
+		File *f = _vm->resource()->giveCompressedSound(name, &size);		
+		_mixer->playFlac(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
+	}
 }
 #endif
 





More information about the Scummvm-git-logs mailing list