Patch files are no longer left open the whole time, but are only opened when needed. This fixes the strange bug where BBM files didn't appear in the ITE demos that have substitute scenes when using MSVC compiled executables, as too many files were open at the same time

svn-id: r28381
This commit is contained in:
Filippos Karapetis 2007-08-01 09:02:28 +00:00
parent b58d259f7e
commit e68624e789
3 changed files with 5 additions and 24 deletions

View File

@ -330,6 +330,7 @@ bool Resource::loadContext(ResourceContext *context) {
if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
resourceData->offset = 0;
resourceData->size = resourceData->patchData->_patchFile->size();
resourceData->patchData->_patchFile->close();
} else {
delete resourceData->patchData;
resourceData->patchData = NULL;
@ -544,6 +545,8 @@ void Resource::loadResource(ResourceContext *context, uint32 resourceId, byte*&r
if (file->read(resourceBuffer, resourceSize) != resourceSize) {
error("Resource::loadResource() failed to read");
}
if (resourceData->patchData != NULL)
file->close();
}
static int metaResourceTable[] = { 0, 326, 517, 677, 805, 968, 1165, 0, 1271 };

View File

@ -83,6 +83,8 @@ struct ResourceContext {
Common::File *getFile(ResourceData *resourceData) const {
if (resourceData->patchData != NULL) {
if (!resourceData->patchData->_patchFile->isOpen())
resourceData->patchData->_patchFile->open(resourceData->patchData->_patchDescription->fileName);
return resourceData->patchData->_patchFile;
} else {
return file;

View File

@ -233,30 +233,6 @@ int SagaEngine::init() {
_voicesEnabled = true;
}
// WORKAROUND for a weird bug that I haven't been able to understand.
// In some ITE demos, scenes are substituted with pictures, which are
// loaded instead of the actual scene in Scene::changeScene(). The
// weird phenomenon is that NO files can be opened or found in that
// function. However, file existence works in other parts of the engine.
// The strange thing is that if we add a dummy file existence check here
// (or in any part of init() or go()) for a file that exists (it doesn't
// work if the file doesn't exist), files are opened correctly in the
// function. I don't know if this is a bug of the Common::File class or
// of the SAGA engine itself (or perhaps of a clashing definition?), but
// still, it's very strange that a file existence check fixes things. In
// both cases (with and without this dummy check here), the Common::File
// open function called from Scene::changeScene() finds the file through
// the _filesMap, but without this dummy check here, the handle returned
// is 0
// To reproduce: run any of the ITE demos that has scene substitutes like,
// for example, the ITE demo from Wyrmkeep's site. Enter the game, and
// exit the faire (to speed things up, open the debug console and type
// "scene_change 1", close the console and visit any place other than
// the faire)
// Since the files we need are BBM files, just check for the existence
// of one file of them here
if (Common::File::exists("tycho.bbm")) {}
// FIXME: This is the ugly way of reducing redraw overhead. It works
// well for 320x200 but it's unclear how well it will work for
// 640x480.