From 4fc6cef968fbf3dc12a6f60611689938dc76da8e Mon Sep 17 00:00:00 2001 From: Simei Yin Date: Tue, 18 Jul 2017 19:03:45 +0200 Subject: SLUDGE: Objectify resource manager --- engines/sludge/backdrop.cpp | 25 +++++------ engines/sludge/fileset.cpp | 103 ++++++++++++++++++++----------------------- engines/sludge/fileset.h | 39 ++++++++++++---- engines/sludge/floor.cpp | 17 +++---- engines/sludge/language.cpp | 2 +- engines/sludge/main_loop.cpp | 2 - engines/sludge/objtypes.cpp | 40 ++++++++--------- engines/sludge/sludge.cpp | 4 +- engines/sludge/sludge.h | 2 + engines/sludge/sludger.cpp | 21 +++++---- engines/sludge/sound.cpp | 13 +++--- engines/sludge/sprites.cpp | 55 +++++++++++------------ engines/sludge/variable.cpp | 2 +- engines/sludge/zbuffer.cpp | 25 ++++++----- 14 files changed, 183 insertions(+), 167 deletions(-) (limited to 'engines/sludge') diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index 9e211f4cb9..0f94f56fee 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -165,17 +165,17 @@ bool killResizeBackdrop(int x, int y) { void loadBackDrop(int fileNum, int x, int y) { debug(kSludgeDebugGraphics, "Load back drop"); setResourceForFatal(fileNum); - if (!openFileFromNum(fileNum)) { + if (!g_sludge->_resMan->openFileFromNum(fileNum)) { fatal("Can't load overlay image"); return; } - if (!loadHSI(bigDataFile, x, y, false)) { + if (!loadHSI(g_sludge->_resMan->getData(), x, y, false)) { Common::String mess = Common::String::format("Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight); fatal(mess); } - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); // set zBuffer if it's not set @@ -187,16 +187,16 @@ void loadBackDrop(int fileNum, int x, int y) { void mixBackDrop(int fileNum, int x, int y) { setResourceForFatal(fileNum); - if (!openFileFromNum(fileNum)) { + if (!g_sludge->_resMan->openFileFromNum(fileNum)) { fatal("Can't load overlay image"); return; } - if (!mixHSI(bigDataFile, x, y)) { + if (!mixHSI(g_sludge->_resMan->getData(), x, y)) { fatal("Can't paste overlay image outside screen dimensions"); } - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); } @@ -310,13 +310,13 @@ void drawBackDrop() { bool loadLightMap(int v) { setResourceForFatal(v); - if (!openFileFromNum(v)) + if (!g_sludge->_resMan->openFileFromNum(v)) return fatal("Can't open light map."); killLightMap(); lightMapNumber = v; - if (!ImgLoader::loadImage(bigDataFile, &lightMap)) + if (!ImgLoader::loadImage(g_sludge->_resMan->getData(), &lightMap)) return false; if (lightMapMode == LIGHTMAPMODE_HOTSPOT) { @@ -325,8 +325,7 @@ bool loadLightMap(int v) { } } - finishAccess(); - + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); return true; @@ -334,7 +333,7 @@ bool loadLightMap(int v) { bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) { setResourceForFatal(v); - if (!openFileFromNum(v)) + if (!g_sludge->_resMan->openFileFromNum(v)) return fatal("Can't open parallax image"); parallaxLayer *nP = new parallaxLayer; @@ -348,7 +347,7 @@ bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) { } nP->prev = NULL; - if (!ImgLoader::loadImage(bigDataFile, &nP->surface, 0)) + if (!ImgLoader::loadImage(g_sludge->_resMan->getData(), &nP->surface, 0)) return false; nP->fileNum = v; @@ -388,7 +387,7 @@ bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #endif - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); return true; } diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp index 4920662a17..4f88fe93f5 100644 --- a/engines/sludge/fileset.cpp +++ b/engines/sludge/fileset.cpp @@ -31,50 +31,44 @@ namespace Sludge { -bool sliceBusy = true; - -Common::File *bigDataFile = NULL; - -uint32 startOfDataIndex, startOfTextIndex, startOfSubIndex, startOfObjectIndex; - -bool openSubSlice(int num) { - if (sliceBusy) { +bool ResourceManager::openSubSlice(int num) { + if (_sliceBusy) { fatal("Can't read from data file", "I'm already reading something"); return false; } - bigDataFile->seek(startOfSubIndex + (num << 2), 0); - bigDataFile->seek(bigDataFile->readUint32LE(), 0); + _bigDataFile->seek(_startOfSubIndex + (num << 2), 0); + _bigDataFile->seek(_bigDataFile->readUint32LE(), 0); - return sliceBusy = true; + return _sliceBusy = true; } -bool openObjectSlice(int num) { - if (sliceBusy) { +bool ResourceManager::openObjectSlice(int num) { + if (_sliceBusy) { fatal("Can't read from data file", "I'm already reading something"); return false; } - bigDataFile->seek(startOfObjectIndex + (num << 2), 0); - bigDataFile->seek(bigDataFile->readUint32LE(), 0); - return sliceBusy = true; + _bigDataFile->seek(_startOfObjectIndex + (num << 2), 0); + _bigDataFile->seek(_bigDataFile->readUint32LE(), 0); + return _sliceBusy = true; } -uint openFileFromNum(int num) { - if (sliceBusy) { +uint ResourceManager::openFileFromNum(int num) { + if (_sliceBusy) { fatal("Can't read from data file", "I'm already reading something"); return 0; } - bigDataFile->seek(startOfDataIndex + (num << 2), 0); - bigDataFile->seek(bigDataFile->readUint32LE(), 1); - sliceBusy = true; + _bigDataFile->seek(_startOfDataIndex + (num << 2), 0); + _bigDataFile->seek(_bigDataFile->readUint32LE(), 1); + _sliceBusy = true; - return bigDataFile->readUint32LE(); + return _bigDataFile->readUint32LE(); } // Converts a string from Windows CP-1252 to UTF-8. // This is needed for old games. -Common::String convertString(const Common::String &s) { +Common::String ResourceManager::convertString(const Common::String &s) { #if 0 static char *buf = NULL; @@ -137,18 +131,17 @@ Common::String convertString(const Common::String &s) { return s; //TODO: false value } -Common::String getNumberedString(int value) { - - if (sliceBusy) { +Common::String ResourceManager::getNumberedString(int value) { + if (_sliceBusy) { fatal("Can't read from data file", "I'm already reading something"); return NULL; } - bigDataFile->seek((value << 2) + startOfTextIndex, 0); - value = bigDataFile->readUint32LE(); - bigDataFile->seek(value, 0); + _bigDataFile->seek((value << 2) + _startOfTextIndex, 0); + value = _bigDataFile->readUint32LE(); + _bigDataFile->seek(value, 0); - Common::String s = readString(bigDataFile); + Common::String s = readString(_bigDataFile); if (gameVersion < VERSION(2, 2)) { // This is an older game - We need to convert the string to UTF-8 @@ -158,25 +151,23 @@ Common::String getNumberedString(int value) { return s; } -bool startAccess() { - int wasBusy = sliceBusy; - sliceBusy = true; +bool ResourceManager::startAccess() { + int wasBusy = _sliceBusy; + _sliceBusy = true; return wasBusy; } -void finishAccess() { - sliceBusy = false; +void ResourceManager::finishAccess() { + _sliceBusy = false; } -int32 startIndex; - -void setBigDataFile(Common::File *fp) { - bigDataFile = fp; - startIndex = fp->pos(); +void ResourceManager::setData(Common::File *fp) { + _bigDataFile = fp; + _startIndex = fp->pos(); } -void setFileIndices(uint numLanguages, uint skipBefore) { - bigDataFile->seek(startIndex, SEEK_SET); - sliceBusy = false; +void ResourceManager::setFileIndices(uint numLanguages, uint skipBefore) { + _bigDataFile->seek(_startIndex, SEEK_SET); + _sliceBusy = false; if (skipBefore > numLanguages) { warning("Not a valid language ID! Using default instead."); @@ -186,30 +177,30 @@ void setFileIndices(uint numLanguages, uint skipBefore) { // STRINGS int skipAfter = numLanguages - skipBefore; while (skipBefore) { - bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET); + _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET); skipBefore--; } - startOfTextIndex = bigDataFile->pos() + 4; - debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", startOfTextIndex); + _startOfTextIndex = _bigDataFile->pos() + 4; + debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", _startOfTextIndex); - bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET); + _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET); while (skipAfter) { - bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET); + _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET); skipAfter--; } - startOfSubIndex = bigDataFile->pos() + 4; - bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR); - debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", startOfSubIndex); + _startOfSubIndex = _bigDataFile->pos() + 4; + _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_CUR); + debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", _startOfSubIndex); - startOfObjectIndex = bigDataFile->pos() + 4; - bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR); - debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", startOfObjectIndex); + _startOfObjectIndex = _bigDataFile->pos() + 4; + _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_CUR); + debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", _startOfObjectIndex); // Remember that the data section starts here - startOfDataIndex = bigDataFile->pos(); - debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", startOfDataIndex); + _startOfDataIndex = _bigDataFile->pos(); + debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", _startOfDataIndex); } } // End of namespace Sludge diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h index fe2293dca7..9cde705a55 100644 --- a/engines/sludge/fileset.h +++ b/engines/sludge/fileset.h @@ -26,18 +26,39 @@ namespace Sludge { -extern Common::File *bigDataFile; +class ResourceManager { -void setBigDataFile(Common::File *readStream); -void setFileIndices(uint, uint); +public: + ResourceManager(): + _sliceBusy(true), + _bigDataFile(0), + _startOfDataIndex(0), + _startOfTextIndex(0), + _startOfSubIndex(0), + _startOfObjectIndex(0), + _startIndex(0) {} -uint openFileFromNum(int num); -bool openSubSlice(int num); -bool openObjectSlice(int num); -Common::String getNumberedString(int value); + void setData(Common::File *readStream); + void setFileIndices(uint, uint); + Common::SeekableReadStream *getData() { return _bigDataFile; } -bool startAccess(); -void finishAccess(); + uint openFileFromNum(int num); + bool openSubSlice(int num); + bool openObjectSlice(int num); + Common::String getNumberedString(int value); + + bool startAccess(); + void finishAccess(); + +private: + bool _sliceBusy; + Common::File *_bigDataFile; + uint32 _startOfDataIndex, _startOfTextIndex, _startOfSubIndex, _startOfObjectIndex; + int32 _startIndex; + +private: + Common::String convertString(const Common::String &s); +}; } // End of namespace Sludge diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp index 7e9677a36f..6b8f7815af 100644 --- a/engines/sludge/floor.cpp +++ b/engines/sludge/floor.cpp @@ -26,6 +26,7 @@ #include "sludge/newfatal.h" #include "sludge/fileset.h" #include "sludge/moreio.h" +#include "sludge/sludge.h" #include "sludge/floor.h" namespace Sludge { @@ -130,13 +131,13 @@ bool setFloor(int fileNum) { setResourceForFatal(fileNum); - if (!openFileFromNum(fileNum)) + if (!g_sludge->_resMan->openFileFromNum(fileNum)) return false; // Find out how many polygons there are and reserve memory currentFloor->originalNum = fileNum; - currentFloor->numPolygons = bigDataFile->readByte(); + currentFloor->numPolygons = g_sludge->_resMan->getData()->readByte(); currentFloor->polygon = new floorPolygon[currentFloor->numPolygons]; if (!checkNew(currentFloor->polygon)) return false; @@ -147,7 +148,7 @@ bool setFloor(int fileNum) { // Find out how many vertex IDs there are and reserve memory - currentFloor->polygon[i].numVertices = bigDataFile->readByte(); + currentFloor->polygon[i].numVertices = g_sludge->_resMan->getData()->readByte(); currentFloor->polygon[i].vertexID = new int[currentFloor->polygon[i].numVertices]; if (!checkNew(currentFloor->polygon[i].vertexID)) return false; @@ -155,24 +156,24 @@ bool setFloor(int fileNum) { // Read in each vertex ID for (j = 0; j < currentFloor->polygon[i].numVertices; j++) { - currentFloor->polygon[i].vertexID[j] = bigDataFile->readUint16BE(); + currentFloor->polygon[i].vertexID[j] = g_sludge->_resMan->getData()->readUint16BE(); } } // Find out how many vertices there are and reserve memory - i = bigDataFile->readUint16BE(); + i = g_sludge->_resMan->getData()->readUint16BE(); currentFloor->vertex = new Common::Point[i]; if (!checkNew(currentFloor->vertex)) return false; for (j = 0; j < i; j++) { - currentFloor->vertex[j].x = bigDataFile->readUint16BE(); - currentFloor->vertex[j].y = bigDataFile->readUint16BE(); + currentFloor->vertex[j].x = g_sludge->_resMan->getData()->readUint16BE(); + currentFloor->vertex[j].y = g_sludge->_resMan->getData()->readUint16BE(); } - finishAccess(); + g_sludge->_resMan->finishAccess(); // Now build the movement martix diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp index 52c1dc881d..a4469411bb 100644 --- a/engines/sludge/language.cpp +++ b/engines/sludge/language.cpp @@ -104,7 +104,7 @@ void LanguageManager::setLanguageIndex(int idx) { // Load the saved language! _languageIdx = idx; // Now set file indices properly to the chosen language. - setFileIndices(_numLanguages, _languageIdx); + g_sludge->_resMan->setFileIndices(_numLanguages, _languageIdx); } } diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp index 78ce63b6c3..8f31167df3 100644 --- a/engines/sludge/main_loop.cpp +++ b/engines/sludge/main_loop.cpp @@ -179,8 +179,6 @@ int main_loop(const char *filename) initStatusBar(); resetRandW(); - g_sludge->gameName = getNumberedString(1); - if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) { initSoundStuff(hMainWindow); } diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp index 8b7f258c63..57365e22ae 100644 --- a/engines/sludge/objtypes.cpp +++ b/engines/sludge/objtypes.cpp @@ -25,6 +25,7 @@ #include "sludge/variable.h" #include "sludge/newfatal.h" #include "sludge/moreio.h" +#include "sludge/sludge.h" #include "sludge/fileset.h" #include "sludge/version.h" @@ -32,8 +33,6 @@ namespace Sludge { objectType *allObjectTypes = NULL; -#define DEBUG_COMBINATIONS 0 - bool initObjectTypes() { return true; } @@ -55,40 +54,41 @@ objectType *loadObjectType(int i) { objectType *newType = new objectType; if (checkNew(newType)) { - if (openObjectSlice(i)) { - nameNum = bigDataFile->readUint16BE(); - newType->r = (byte)bigDataFile->readByte(); - newType->g = (byte)bigDataFile->readByte(); - newType->b = (byte)bigDataFile->readByte(); - newType->speechGap = bigDataFile->readByte(); - newType->walkSpeed = bigDataFile->readByte(); - newType->wrapSpeech = bigDataFile->readUint32LE(); - newType->spinSpeed = bigDataFile->readUint16BE(); + if (g_sludge->_resMan->openObjectSlice(i)) { + Common::SeekableReadStream *readStream = g_sludge->_resMan->getData(); + nameNum = readStream->readUint16BE(); + newType->r = (byte)readStream->readByte(); + newType->g = (byte)readStream->readByte(); + newType->b = (byte)readStream->readByte(); + newType->speechGap = readStream->readByte(); + newType->walkSpeed = readStream->readByte(); + newType->wrapSpeech = readStream->readUint32LE(); + newType->spinSpeed = readStream->readUint16BE(); if (gameVersion >= VERSION(1, 6)) { // aaLoad - bigDataFile->readByte(); - bigDataFile->readFloatLE(); - bigDataFile->readFloatLE(); + readStream->readByte(); + readStream->readFloatLE(); + readStream->readFloatLE(); } if (gameVersion >= VERSION(1, 4)) { - newType->flags = bigDataFile->readUint16BE(); + newType->flags = readStream->readUint16BE(); } else { newType->flags = 0; } - newType->numCom = bigDataFile->readUint16BE(); + newType->numCom = readStream->readUint16BE(); newType->allCombis = (newType->numCom) ? new combination[newType->numCom] : NULL; for (a = 0; a < newType->numCom; a++) { - newType->allCombis[a].withObj = bigDataFile->readUint16BE(); - newType->allCombis[a].funcNum = bigDataFile->readUint16BE(); + newType->allCombis[a].withObj = readStream->readUint16BE(); + newType->allCombis[a].funcNum = readStream->readUint16BE(); } - finishAccess(); - newType->screenName = getNumberedString(nameNum); + g_sludge->_resMan->finishAccess(); + newType->screenName = g_sludge->_resMan->getNumberedString(nameNum); newType->objectNum = i; newType->next = allObjectTypes; allObjectTypes = newType; diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index fe8a96ff0f..ff62459451 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -55,7 +55,6 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) // Init Strings launchMe = ""; loadNow = ""; - gameName = ""; gamePath = ""; bundleFolder = ""; @@ -63,6 +62,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) fatalInfo = "Initialisation error! Something went wrong before we even got started!"; // Init managers + _resMan = new ResourceManager(); _languageMan = new LanguageManager(); } @@ -88,6 +88,8 @@ SludgeEngine::~SludgeEngine() { // Dispose managers delete _languageMan; _languageMan = nullptr; + delete _resMan; + _resMan = nullptr; } Common::Error SludgeEngine::run() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 0816d2229e..8d41b5c317 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -29,6 +29,7 @@ #include "gui/debugger.h" #include "sludge/console.h" +#include "sludge/fileset.h" #include "sludge/language.h" #include "sludge/timing.h" @@ -67,6 +68,7 @@ public: Timer _timer; // managers + ResourceManager *_resMan; LanguageManager *_languageMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index e0f20bbd5d..e1fd3c8c1f 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -279,7 +279,7 @@ bool initSludge(const Common::String &filename) { initVarNew(globalVars[a]); // Get language selected by user - setBigDataFile(fp); + g_sludge->_resMan->setData(fp); g_sludge->_languageMan->setLanguageID(g_sludge->getLanguageID()); if (!dataFol.empty()) { @@ -942,33 +942,32 @@ bool runSludge() { } bool loadFunctionCode(loadedFunction *newFunc) { - - debug(kSludgeDebugDataLoad, "Current address: %i", bigDataFile->pos()); uint numLines, numLinesRead; - if (!openSubSlice(newFunc->originalNumber)) + if (!g_sludge->_resMan->openSubSlice(newFunc->originalNumber)) return false; debug(kSludgeDebugDataLoad, "Load function code"); - newFunc->unfreezable = bigDataFile->readByte(); - numLines = bigDataFile->readUint16BE(); + Common::SeekableReadStream *readStream = g_sludge->_resMan->getData(); + newFunc->unfreezable = readStream->readByte(); + numLines = readStream->readUint16BE(); debug(kSludgeDebugDataLoad, "numLines: %i", numLines); - newFunc->numArgs = bigDataFile->readUint16BE(); + newFunc->numArgs = readStream->readUint16BE(); debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs); - newFunc->numLocals = bigDataFile->readUint16BE(); + newFunc->numLocals = readStream->readUint16BE(); debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals); newFunc->compiledLines = new lineOfCode[numLines]; if (!checkNew(newFunc->compiledLines)) return false; for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) { - newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) bigDataFile->readByte(); - newFunc->compiledLines[numLinesRead].param = bigDataFile->readUint16BE(); + newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand)readStream->readByte(); + newFunc->compiledLines[numLinesRead].param = readStream->readUint16BE(); debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead, newFunc->compiledLines[numLinesRead].theCommand); } - finishAccess(); + g_sludge->_resMan->finishAccess(); // Now we need to reserve memory for the local variables newFunc->localVars = new variable[newFunc->numLocals]; diff --git a/engines/sludge/sound.cpp b/engines/sludge/sound.cpp index d77f3d4e63..702a8c9c5b 100644 --- a/engines/sludge/sound.cpp +++ b/engines/sludge/sound.cpp @@ -381,20 +381,21 @@ int makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy) { } setResourceForFatal(f); - uint32 length = openFileFromNum(f); + uint32 length = g_sludge->_resMan->openFileFromNum(f); if (!length) return -1; - uint curr_ptr = bigDataFile->pos(); - Audio::RewindableAudioStream *stream = Audio::makeWAVStream(bigDataFile->readStream(length), DisposeAfterUse::NO); + Common::SeekableReadStream *readStream = g_sludge->_resMan->getData(); + uint curr_ptr = readStream->pos(); + Audio::RewindableAudioStream *stream = Audio::makeWAVStream(readStream->readStream(length), DisposeAfterUse::NO); #ifdef USE_VORBIS if (!stream) { - bigDataFile->seek(curr_ptr); - stream = Audio::makeVorbisStream(bigDataFile->readStream(length), DisposeAfterUse::NO); + readStream->seek(curr_ptr); + stream = Audio::makeVorbisStream(readStream->readStream(length), DisposeAfterUse::NO); } #endif - finishAccess(); + g_sludge->_resMan->finishAccess(); if (stream) { audiostream = Audio::makeLoopingAudioStream(stream, loopy ? 0 : 1); diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp index 39bb65211d..ce8d61e7a3 100644 --- a/engines/sludge/sprites.cpp +++ b/engines/sludge/sprites.cpp @@ -123,18 +123,19 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { byte *data; setResourceForFatal(fileNum); - if (!openFileFromNum(fileNum)) + if (!g_sludge->_resMan->openFileFromNum(fileNum)) return fatal("Can't open sprite bank / font"); loadhere.isFont = isFont; - total = bigDataFile->readUint16BE(); + Common::SeekableReadStream *readStream = g_sludge->_resMan->getData(); + total = readStream->readUint16BE(); if (!total) { - spriteBankVersion = bigDataFile->readByte(); + spriteBankVersion = readStream->readByte(); if (spriteBankVersion == 1) { total = 0; } else { - total = bigDataFile->readUint16BE(); + total = readStream->readUint16BE(); } } @@ -153,7 +154,7 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { // version 1, 2, read how many now if (spriteBankVersion && spriteBankVersion < 3) { - howmany = bigDataFile->readByte(); + howmany = readStream->readByte(); startIndex = 1; } @@ -161,13 +162,13 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { if (spriteBankVersion == 3) { debug(kSludgeDebugGraphics, "png sprite"); for (int i = 0; i < total; i++) { - loadhere.sprites[i].xhot = bigDataFile->readSint16LE(); - loadhere.sprites[i].yhot = bigDataFile->readSint16LE(); - if (!ImgLoader::loadPNGImage(bigDataFile, &loadhere.sprites[i].surface, false)) { + loadhere.sprites[i].xhot = readStream->readSint16LE(); + loadhere.sprites[i].yhot = readStream->readSint16LE(); + if (!ImgLoader::loadPNGImage(readStream, &loadhere.sprites[i].surface, false)) { return fatal("fail to read png sprite"); } } - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); return true; } @@ -177,15 +178,15 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { uint picwidth, picheight; // load sprite width, height, relative position if (spriteBankVersion == 2) { - picwidth = bigDataFile->readUint16BE(); - picheight = bigDataFile->readUint16BE(); - loadhere.sprites[i].xhot = bigDataFile->readSint16LE(); - loadhere.sprites[i].yhot = bigDataFile->readSint16LE(); + picwidth = readStream->readUint16BE(); + picheight = readStream->readUint16BE(); + loadhere.sprites[i].xhot = readStream->readSint16LE(); + loadhere.sprites[i].yhot = readStream->readSint16LE(); } else { - picwidth = (byte)bigDataFile->readByte(); - picheight = (byte)bigDataFile->readByte(); - loadhere.sprites[i].xhot = bigDataFile->readByte(); - loadhere.sprites[i].yhot = bigDataFile->readByte(); + picwidth = (byte)readStream->readByte(); + picheight = (byte)readStream->readByte(); + loadhere.sprites[i].xhot = readStream->readByte(); + loadhere.sprites[i].yhot = readStream->readByte(); } // init data @@ -205,11 +206,11 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { uint pip = 0; while (pip < size) { - byte col = bigDataFile->readByte(); + byte col = readStream->readByte(); int looper; if (col > howmany) { col -= howmany + 1; - looper = bigDataFile->readByte() + 1; + looper = readStream->readByte() + 1; } else looper = 1; @@ -218,8 +219,8 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { } } } else { // RAW DATA - uint bytes_read = bigDataFile->read(data, picwidth * picheight); - if (bytes_read != picwidth * picheight && bigDataFile->err()) { + uint bytes_read = readStream->read(data, picwidth * picheight); + if (bytes_read != picwidth * picheight && readStream->err()) { warning("Reading error in loadSpriteBank."); } } @@ -227,17 +228,17 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { // read howmany for version 0 if (!spriteBankVersion) { - howmany = bigDataFile->readByte(); - startIndex = bigDataFile->readByte(); + howmany = readStream->readByte(); + startIndex = readStream->readByte(); } // Make palette for version 0, 1, 2 if (!reserveSpritePal(loadhere.myPalette, howmany + startIndex)) return false; for (int i = 0; i < howmany; i++) { - loadhere.myPalette.r[i + startIndex] = (byte)bigDataFile->readByte(); - loadhere.myPalette.g[i + startIndex] = (byte)bigDataFile->readByte(); - loadhere.myPalette.b[i + startIndex] = (byte)bigDataFile->readByte(); + loadhere.myPalette.r[i + startIndex] = (byte)readStream->readByte(); + loadhere.myPalette.g[i + startIndex] = (byte)readStream->readByte(); + loadhere.myPalette.b[i + startIndex] = (byte)readStream->readByte(); loadhere.myPalette.pal[i + startIndex] = (uint16)g_sludge->getOrigPixelFormat()->RGBToColor( loadhere.myPalette.r[i + startIndex], @@ -290,7 +291,7 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) { delete[] spriteData; spriteData = NULL; - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index b13e123c09..b445095630 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -260,7 +260,7 @@ void makeTextVar(variable &thisVar, const Common::String &txt) { } bool loadStringToVar(variable &thisVar, int value) { - makeTextVar(thisVar, getNumberedString(value)); + makeTextVar(thisVar, g_sludge->_resMan->getNumberedString(value)); return (bool)(thisVar.varData.theString != NULL); } diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp index e3b305632b..b01bc9f5d0 100644 --- a/engines/sludge/zbuffer.cpp +++ b/engines/sludge/zbuffer.cpp @@ -88,25 +88,26 @@ bool setZBuffer(int num) { setResourceForFatal(num); zBuffer.originalNum = num; - if (!openFileFromNum(num)) + if (!g_sludge->_resMan->openFileFromNum(num)) return false; - if (bigDataFile->readByte() != 'S') + Common::ReadStream *readStream = g_sludge->_resMan->getData(); + if (readStream->readByte() != 'S') return fatal("Not a Z-buffer file"); - if (bigDataFile->readByte() != 'z') + if (readStream->readByte() != 'z') return fatal("Not a Z-buffer file"); - if (bigDataFile->readByte() != 'b') + if (readStream->readByte() != 'b') return fatal("Not a Z-buffer file"); uint width, height; - switch (bigDataFile->readByte()) { + switch (readStream->readByte()) { case 0: width = 640; height = 480; break; case 1: - width = bigDataFile->readUint16BE(); - height = bigDataFile->readUint16BE(); + width = readStream->readUint16BE(); + height = readStream->readUint16BE(); break; default: @@ -117,9 +118,9 @@ bool setZBuffer(int num) { return fatal("Z-buffer width and height don't match scene width and height", tmp); } - zBuffer.numPanels = bigDataFile->readByte(); + zBuffer.numPanels = readStream->readByte(); for (int y = 0; y < zBuffer.numPanels; y++) { - yPalette[y] = bigDataFile->readUint16BE(); + yPalette[y] = readStream->readUint16BE(); } sortZPal(yPalette, sorted, zBuffer.numPanels); for (int y = 0; y < zBuffer.numPanels; y++) { @@ -141,10 +142,10 @@ bool setZBuffer(int num) { for (uint x = 0; x < sceneWidth; x++) { int n; if (stillToGo == 0) { - n = bigDataFile->readByte(); + n = readStream->readByte(); stillToGo = n >> 4; if (stillToGo == 15) - stillToGo = bigDataFile->readUint16BE() + 16l; + stillToGo = readStream->readUint16BE() + 16l; else stillToGo++; n &= 15; @@ -167,7 +168,7 @@ bool setZBuffer(int num) { stillToGo--; } } - finishAccess(); + g_sludge->_resMan->finishAccess(); setResourceForFatal(-1); return true; } -- cgit v1.2.3