diff options
author | Johannes Schickel | 2008-04-19 14:31:10 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-04-19 14:31:10 +0000 |
commit | 7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130 (patch) | |
tree | afd1e5dbbcf63d0b78dcc92e9c3b943e8e7f3bdb /engines/kyra | |
parent | 49cf8237f0d6188fa5c061b38e69d18b75eccc7c (diff) | |
download | scummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.tar.gz scummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.tar.bz2 scummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.zip |
- some minor renaming in TIM code
- added exists function to Resource
- started to add checks via exists to assure that important files are present
svn-id: r31572
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/resource.cpp | 53 | ||||
-rw-r--r-- | engines/kyra/resource.h | 1 | ||||
-rw-r--r-- | engines/kyra/scene_v1.cpp | 3 | ||||
-rw-r--r-- | engines/kyra/scene_v2.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/scene_v3.cpp | 3 | ||||
-rw-r--r-- | engines/kyra/script_tim.cpp | 28 | ||||
-rw-r--r-- | engines/kyra/script_tim.h | 6 | ||||
-rw-r--r-- | engines/kyra/sprites.cpp | 1 |
8 files changed, 62 insertions, 35 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index e76d553372..c3cecf1a22 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -277,13 +277,29 @@ uint8 *Resource::fileData(const char *file, uint32 *size) { return buffer; } +bool Resource::exists(const char *file, bool errorOutOnFail) { + if (Common::File::exists(file)) + return true; + else if (isAccessable(file)) + return true; + else if (errorOutOnFail) + error("File '%s' can't be found", file); + return false; +} + uint32 Resource::getFileSize(const char *file) { - if (!isAccessable(file)) - return 0; + if (Common::File::exists(file)) { + Common::File f; + if (f.open(file)) + return f.size(); + } else { + if (!isAccessable(file)) + return 0; - ResFileMap::const_iterator iter = _map.find(file); - if (iter != _map.end()) - return iter->_value.size; + ResFileMap::const_iterator iter = _map.find(file); + if (iter != _map.end()) + return iter->_value.size; + } return 0; } @@ -299,18 +315,22 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) { } Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) { - if (!isAccessable(file)) - return 0; - - ResFileMap::const_iterator iter = _map.find(file); - if (iter == _map.end()) - return 0; - - Common::File *stream = new Common::File(); - if (stream->open(file)) { + if (Common::File::exists(file)) { + Common::File *stream = new Common::File(); + if (!stream->open(file)) { + delete stream; + stream = 0; + error("Couldn't open file '%s'", file.c_str()); + } return stream; } else { - delete stream; + if (!isAccessable(file)) + return 0; + + ResFileMap::const_iterator iter = _map.find(file); + if (iter == _map.end()) + return 0; + if (!iter->_value.parent.empty()) { Common::SeekableReadStream *parent = getFileStream(iter->_value.parent); assert(parent); @@ -321,8 +341,7 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) return loader->loadFileFromArchive(file, parent, iter->_value); } else { - warning("Couldn't open file '%s'", file.c_str()); - return 0; + error("Couldn't open file '%s'", file.c_str()); } } diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h index 7a04d1317d..b60e39a017 100644 --- a/engines/kyra/resource.h +++ b/engines/kyra/resource.h @@ -102,6 +102,7 @@ public: // This unloads *all* pakfiles, even kyra.dat and protected ones void unloadAllPakFiles(); + bool exists(const char *file, bool errorOutOnFail=false); uint32 getFileSize(const char *file); uint8* fileData(const char *file, uint32 *size); Common::SeekableReadStream *getFileStream(const Common::String &file); diff --git a/engines/kyra/scene_v1.cpp b/engines/kyra/scene_v1.cpp index 6a980916bb..d79f280622 100644 --- a/engines/kyra/scene_v1.cpp +++ b/engines/kyra/scene_v1.cpp @@ -400,6 +400,7 @@ void KyraEngine_v1::loadSceneMsc() { strcpy(fileNameBuffer, _roomFilenameTable[tableId]); strcat(fileNameBuffer, ".MSC"); _screen->fillRect(0, 0, 319, 199, 0, 5); + _res->exists(fileNameBuffer, true); _screen->loadBitmap(fileNameBuffer, 3, 5, 0); } @@ -412,6 +413,7 @@ void KyraEngine_v1::startSceneScript(int brandonAlive) { strcpy(fileNameBuffer, _roomFilenameTable[tableId]); strcat(fileNameBuffer, ".CPS"); _screen->clearPage(3); + _res->exists(fileNameBuffer, true); // FIXME: check this hack for amiga version _screen->loadBitmap(fileNameBuffer, 3, 3, (_flags.platform == Common::kPlatformAmiga ? _screen->getPalette(0) : 0)); _sprites->loadSceneShapes(); @@ -425,6 +427,7 @@ void KyraEngine_v1::startSceneScript(int brandonAlive) { _scriptInterpreter->initScript(_scriptClick, _scriptClickData); strcpy(fileNameBuffer, _roomFilenameTable[tableId]); strcat(fileNameBuffer, ".EMC"); + _res->exists(fileNameBuffer, true); _scriptInterpreter->unloadScript(_scriptClickData); _scriptInterpreter->loadScript(fileNameBuffer, _scriptClickData, &_opcodes); _scriptInterpreter->startScript(_scriptClick, 0); diff --git a/engines/kyra/scene_v2.cpp b/engines/kyra/scene_v2.cpp index 498ddc1c6b..80353eb468 100644 --- a/engines/kyra/scene_v2.cpp +++ b/engines/kyra/scene_v2.cpp @@ -452,7 +452,7 @@ void KyraEngine_v2::startSceneScript(int unk1) { strcat(filename, "."); strcat(filename, _scriptLangExt[(_flags.platform == Common::kPlatformPC && !_flags.isTalkie) ? 0 : _lang]); - assert(_res->getFileSize(filename)); + _res->exists(filename, true); _scriptInterpreter->loadScript(filename, &_sceneScriptData, &_opcodes); runSceneScript7(); diff --git a/engines/kyra/scene_v3.cpp b/engines/kyra/scene_v3.cpp index 426b689f03..124f4c8bcc 100644 --- a/engines/kyra/scene_v3.cpp +++ b/engines/kyra/scene_v3.cpp @@ -347,6 +347,7 @@ void KyraEngine_v3::loadSceneMsc() { strcpy(filename, _sceneList[_mainCharacter.sceneId].filename1); strcat(filename, ".MSC"); + _res->exists(filename, true); Common::SeekableReadStream *stream = _res->getFileStream(filename); assert(stream); int16 minY = 0, height = 0; @@ -381,6 +382,7 @@ void KyraEngine_v3::initSceneScript(int unk1) { strcpy(filename, scene.filename1); strcat(filename, ".DAT"); + _res->exists(filename, true); Common::SeekableReadStream *stream = _res->getFileStream(filename); assert(stream); stream->seek(2, SEEK_CUR); @@ -436,6 +438,7 @@ void KyraEngine_v3::initSceneScript(int unk1) { strcpy(filename, scene.filename2); strcat(filename, ".EMC"); musicUpdate(0); + _res->exists(filename, true); _scriptInterpreter->loadScript(filename, &_sceneScriptData, &_opcodes); strcpy(filename, scene.filename1); diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp index 89f239648c..67e076cbf8 100644 --- a/engines/kyra/script_tim.cpp +++ b/engines/kyra/script_tim.cpp @@ -25,6 +25,7 @@ #include "kyra/script_tim.h" #include "kyra/script.h" +#include "kyra/resource.h" #include "common/endian.h" @@ -35,7 +36,7 @@ TIMInterpreter::TIMInterpreter(KyraEngine *vm, OSystem *system) : _vm(vm), _syst #define COMMAND_UNIMPL() { 0, 0 } static CommandEntry commandProcs[] = { // 0x00 - COMMAND(cmd_initFunc0Now), + COMMAND(cmd_initFunc0), COMMAND(cmd_stopCurFunc), COMMAND_UNIMPL(), COMMAND_UNIMPL(), @@ -63,7 +64,7 @@ TIMInterpreter::TIMInterpreter(KyraEngine *vm, OSystem *system) : _vm(vm), _syst COMMAND_UNIMPL(), COMMAND_UNIMPL(), COMMAND_UNIMPL(), - COMMAND(cmd_resetAllNextTime), + COMMAND(cmd_resetAllRuntimes), // 0x18 COMMAND(cmd_return<1>), COMMAND(cmd_execOpcode), @@ -80,20 +81,19 @@ TIMInterpreter::TIMInterpreter(KyraEngine *vm, OSystem *system) : _vm(vm), _syst } TIM *TIMInterpreter::load(const char *filename, const Common::Array<const TIMOpcode*> *opcodes) { + if (!_vm->resource()->exists(filename)) + return 0; + ScriptFileParser file(filename, _vm->resource()); if (!file) error("Couldn't open TIM file '%s'", filename); uint32 formBlockSize = file.getFORMBlockSize(); - if (formBlockSize == 0xFFFFFFFF) { - warning("No FORM chunk found in TIM file '%s'", filename); - return 0; - } + if (formBlockSize == 0xFFFFFFFF) + error("No FORM chunk found in TIM file '%s'", filename); - if (formBlockSize < 20) { - warning("TIM file '%s' FORM chunk size smaller than 20", filename); - return 0; - } + if (formBlockSize < 20) + error("TIM file '%s' FORM chunk size smaller than 20", filename); TIM *tim = new TIM; assert(tim); @@ -149,7 +149,7 @@ void TIMInterpreter::exec(TIM *tim, bool loop) { TIM::Function &cur = _currentTim->func[_currentFunc]; if (_currentTim->procFunc != -1) - execCommand(28, &_currentTim->unkFlag); + execCommand(28, &_currentTim->procParam); bool running = true; while (cur.ip && cur.nextTime <= _system->getMillis() && running) { @@ -199,7 +199,7 @@ int TIMInterpreter::execCommand(int cmd, const uint16 *param) { return (this->*_commands[cmd].proc)(param); } -int TIMInterpreter::cmd_initFunc0Now(const uint16 *param) { +int TIMInterpreter::cmd_initFunc0(const uint16 *param) { _currentTim->func[0].ip = _currentTim->func[0].avtl; _currentTim->func[0].lastTime = _system->getMillis(); return 1; @@ -230,7 +230,7 @@ int TIMInterpreter::cmd_stopFunc(const uint16 *param) { return 1; } -int TIMInterpreter::cmd_resetAllNextTime(const uint16 *param) { +int TIMInterpreter::cmd_resetAllRuntimes(const uint16 *param) { for (int i = 0; i < 10; ++i) { if (_currentTim->func[i].ip) _currentTim->func[i].nextTime = _system->getMillis(); @@ -246,7 +246,7 @@ int TIMInterpreter::cmd_execOpcode(const uint16 *param) { uint16 opcode = *param++; if (opcode > _currentTim->opcodes->size()) { - warning("calling unimplemented opcode(0x%.02X/%d)", opcode, opcode); + warning("Calling unimplemented TIM opcode(0x%.02X/%d)", opcode, opcode); return 0; } diff --git a/engines/kyra/script_tim.h b/engines/kyra/script_tim.h index 1cf1476c63..a76dcccb38 100644 --- a/engines/kyra/script_tim.h +++ b/engines/kyra/script_tim.h @@ -35,7 +35,7 @@ namespace Kyra { struct TIM { int16 procFunc; - uint16 unkFlag; + uint16 procParam; struct Function { const uint16 *ip; @@ -86,11 +86,11 @@ private: const CommandEntry *_commands; int _commandsSize; - int cmd_initFunc0Now(const uint16 *param); + int cmd_initFunc0(const uint16 *param); int cmd_stopCurFunc(const uint16 *param); int cmd_initFunc(const uint16 *param); int cmd_stopFunc(const uint16 *param); - int cmd_resetAllNextTime(const uint16 *param); + int cmd_resetAllRuntimes(const uint16 *param); int cmd_execOpcode(const uint16 *param); int cmd_initFuncNow(const uint16 *param); int cmd_stopFuncNow(const uint16 *param); diff --git a/engines/kyra/sprites.cpp b/engines/kyra/sprites.cpp index ad513d80f4..531033f5c4 100644 --- a/engines/kyra/sprites.cpp +++ b/engines/kyra/sprites.cpp @@ -408,6 +408,7 @@ void Sprites::loadDat(const char *filename, SceneExits &exits) { delete[] _dat; _spriteDefStart = 0; + _res->exists(filename, true); _dat = _res->fileData(filename, &fileSize); memset(_anims, 0, sizeof(_anims)); |