- 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
This commit is contained in:
Johannes Schickel 2008-04-19 14:31:10 +00:00
parent 49cf8237f0
commit 7e12a50bed
8 changed files with 63 additions and 36 deletions

View File

@ -277,13 +277,29 @@ uint8 *Resource::fileData(const char *file, uint32 *size) {
return buffer;
}
uint32 Resource::getFileSize(const char *file) {
if (!isAccessable(file))
return 0;
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;
}
ResFileMap::const_iterator iter = _map.find(file);
if (iter != _map.end())
return iter->_value.size;
uint32 Resource::getFileSize(const char *file) {
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;
}
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());
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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));