diff options
Diffstat (limited to 'engines/agi/loader_v2.cpp')
-rw-r--r-- | engines/agi/loader_v2.cpp | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp index 693c53c2bf..43ef46bd72 100644 --- a/engines/agi/loader_v2.cpp +++ b/engines/agi/loader_v2.cpp @@ -23,14 +23,15 @@ #include "common/textconsole.h" #include "agi/agi.h" +#include "agi/words.h" namespace Agi { int AgiLoader_v2::detectGame() { if (!Common::File::exists(LOGDIR) || - !Common::File::exists(PICDIR) || - !Common::File::exists(SNDDIR) || - !Common::File::exists(VIEWDIR)) + !Common::File::exists(PICDIR) || + !Common::File::exists(SNDDIR) || + !Common::File::exists(VIEWDIR)) return errInvalidAGIFile; return _vm->setupV2Game(_vm->getVersion()); @@ -60,7 +61,7 @@ int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) { fp.read(mem, flen); // set all directory resources to gone - for (i = 0; i < MAX_DIRS; i++) { + for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) { agid[i].volume = 0xff; agid[i].offset = _EMPTY; } @@ -107,21 +108,21 @@ int AgiLoader_v2::deinit() { return ec; } -int AgiLoader_v2::unloadResource(int t, int n) { +int AgiLoader_v2::unloadResource(int16 resourceType, int16 resourceNr) { debugC(3, kDebugLevelResources, "unload resource"); - switch (t) { - case rLOGIC: - _vm->unloadLogic(n); + switch (resourceType) { + case RESOURCETYPE_LOGIC: + _vm->unloadLogic(resourceNr); break; - case rPICTURE: - _vm->_picture->unloadPicture(n); + case RESOURCETYPE_PICTURE: + _vm->_picture->unloadPicture(resourceNr); break; - case rVIEW: - _vm->unloadView(n); + case RESOURCETYPE_VIEW: + _vm->unloadView(resourceNr); break; - case rSOUND: - _vm->_sound->unloadSound(n); + case RESOURCETYPE_SOUND: + _vm->_sound->unloadSound(resourceNr); break; } @@ -129,7 +130,7 @@ int AgiLoader_v2::unloadResource(int t, int n) { } /** - * This function does noting but load a raw resource into memory, + * This function loads a raw resource into memory, * if further decoding is required, it must be done by another * routine. NULL is returned if unsucsessfull. */ @@ -173,84 +174,84 @@ uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) { * Loads a resource into memory, a raw resource is loaded in * with above routine, then further decoded here. */ -int AgiLoader_v2::loadResource(int t, int n) { +int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) { int ec = errOK; uint8 *data = NULL; - debugC(3, kDebugLevelResources, "(t = %d, n = %d)", t, n); - if (n >= MAX_DIRS) + debugC(3, kDebugLevelResources, "(t = %d, n = %d)", resourceType, resourceNr); + if (resourceNr >= MAX_DIRECTORY_ENTRIES) return errBadResource; - switch (t) { - case rLOGIC: - if (~_vm->_game.dirLogic[n].flags & RES_LOADED) { - debugC(3, kDebugLevelResources, "loading logic resource %d", n); - unloadResource(rLOGIC, n); + switch (resourceType) { + case RESOURCETYPE_LOGIC: + if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) { + debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr); + unloadResource(RESOURCETYPE_LOGIC, resourceNr); // load raw resource into data - data = loadVolRes(&_vm->_game.dirLogic[n]); + data = loadVolRes(&_vm->_game.dirLogic[resourceNr]); - _vm->_game.logics[n].data = data; - ec = data ? _vm->decodeLogic(n) : errBadResource; + _vm->_game.logics[resourceNr].data = data; + ec = data ? _vm->decodeLogic(resourceNr) : errBadResource; - _vm->_game.logics[n].sIP = 2; + _vm->_game.logics[resourceNr].sIP = 2; } // if logic was cached, we get here // reset code pointers incase it was cached - _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP; + _vm->_game.logics[resourceNr].cIP = _vm->_game.logics[resourceNr].sIP; break; - case rPICTURE: + case RESOURCETYPE_PICTURE: // if picture is currently NOT loaded *OR* cacheing is off, // unload the resource (caching == off) and reload it - debugC(3, kDebugLevelResources, "loading picture resource %d", n); - if (_vm->_game.dirPic[n].flags & RES_LOADED) + debugC(3, kDebugLevelResources, "loading picture resource %d", resourceNr); + if (_vm->_game.dirPic[resourceNr].flags & RES_LOADED) break; // if loaded but not cached, unload it // if cached but not loaded, etc - unloadResource(rPICTURE, n); - data = loadVolRes(&_vm->_game.dirPic[n]); + unloadResource(RESOURCETYPE_PICTURE, resourceNr); + data = loadVolRes(&_vm->_game.dirPic[resourceNr]); if (data != NULL) { - _vm->_game.pictures[n].rdata = data; - _vm->_game.dirPic[n].flags |= RES_LOADED; + _vm->_game.pictures[resourceNr].rdata = data; + _vm->_game.dirPic[resourceNr].flags |= RES_LOADED; } else { ec = errBadResource; } break; - case rSOUND: - debugC(3, kDebugLevelResources, "loading sound resource %d", n); - if (_vm->_game.dirSound[n].flags & RES_LOADED) + case RESOURCETYPE_SOUND: + debugC(3, kDebugLevelResources, "loading sound resource %d", resourceNr); + if (_vm->_game.dirSound[resourceNr].flags & RES_LOADED) break; - data = loadVolRes(&_vm->_game.dirSound[n]); + data = loadVolRes(&_vm->_game.dirSound[resourceNr]); if (data != NULL) { // Freeing of the raw resource from memory is delegated to the createFromRawResource-function - _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, _vm->_soundemu); - _vm->_game.dirSound[n].flags |= RES_LOADED; + _vm->_game.sounds[resourceNr] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[resourceNr].len, resourceNr, _vm->_soundemu); + _vm->_game.dirSound[resourceNr].flags |= RES_LOADED; } else { ec = errBadResource; } break; - case rVIEW: + case RESOURCETYPE_VIEW: // Load a VIEW resource into memory... // Since VIEWS alter the view table ALL the time // can we cache the view? or must we reload it all // the time? - if (_vm->_game.dirView[n].flags & RES_LOADED) + if (_vm->_game.dirView[resourceNr].flags & RES_LOADED) break; - debugC(3, kDebugLevelResources, "loading view resource %d", n); - unloadResource(rVIEW, n); - data = loadVolRes(&_vm->_game.dirView[n]); + debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr); + unloadResource(RESOURCETYPE_VIEW, resourceNr); + data = loadVolRes(&_vm->_game.dirView[resourceNr]); if (data) { - _vm->_game.views[n].rdata = data; - _vm->_game.dirView[n].flags |= RES_LOADED; - ec = _vm->decodeView(n); + _vm->_game.dirView[resourceNr].flags |= RES_LOADED; + ec = _vm->decodeView(data, _vm->_game.dirView[resourceNr].len, resourceNr); + free(data); } else { ec = errBadResource; } @@ -268,7 +269,7 @@ int AgiLoader_v2::loadObjects(const char *fname) { } int AgiLoader_v2::loadWords(const char *fname) { - return _vm->loadWords(fname); + return _vm->_words->loadDictionary(fname); } } // End of namespace Agi |