2005-01-17 10:57:15 +00:00
|
|
|
/* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
* Copyright (C) 2003-2005 The ScummVM project
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/file.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/console.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/defs.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/memory.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/router.h"
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
#include "sword2/sound.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/driver/d_draw.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-19 18:40:53 +00:00
|
|
|
#define Debug_Printf _vm->_debugger->DebugPrintf
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-23 13:40:24 +00:00
|
|
|
// Welcome to the easy resource manager - written in simple code for easy
|
2003-09-02 09:55:11 +00:00
|
|
|
// maintenance
|
|
|
|
//
|
2003-11-23 13:40:24 +00:00
|
|
|
// The resource compiler will create two files
|
2003-09-02 09:55:11 +00:00
|
|
|
//
|
2003-07-28 01:44:38 +00:00
|
|
|
// resource.inf which is a list of ascii cluster file names
|
2003-09-02 09:55:11 +00:00
|
|
|
// resource.tab which is a table which tells us which cluster a resource
|
|
|
|
// is located in and the number within the cluster
|
2004-04-23 07:02:11 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
enum {
|
|
|
|
BOTH = 0x0, // Cluster is on both CDs
|
|
|
|
CD1 = 0x1, // Cluster is on CD1 only
|
|
|
|
CD2 = 0x2, // Cluster is on CD2 only
|
|
|
|
LOCAL_CACHE = 0x4, // Cluster is cached on HDD
|
|
|
|
LOCAL_PERM = 0x8 // Cluster is on HDD.
|
|
|
|
};
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-17 20:34:20 +00:00
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma START_PACK_STRUCTS
|
|
|
|
#endif
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
struct CdInf {
|
2003-09-02 09:55:11 +00:00
|
|
|
uint8 clusterName[20]; // Null terminated cluster name.
|
|
|
|
uint8 cd; // Cd cluster is on and whether it is on the local drive or not.
|
2003-10-03 13:53:46 +00:00
|
|
|
} GCC_PACK;
|
2003-09-17 20:34:20 +00:00
|
|
|
|
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma END_PACK_STRUCTS
|
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
ResourceManager::ResourceManager(Sword2Engine *vm) {
|
|
|
|
_vm = vm;
|
|
|
|
|
2004-03-04 08:03:32 +00:00
|
|
|
// Until proven differently, assume we're on CD 1. This is so the start
|
|
|
|
// dialog will be able to play any music at all.
|
|
|
|
_curCd = 1;
|
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// We read in the resource info which tells us the names of the
|
|
|
|
// resource cluster files ultimately, although there might be groups
|
|
|
|
// within the clusters at this point it makes no difference. We only
|
|
|
|
// wish to know what resource files there are and what is in each
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
File file;
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 size;
|
|
|
|
byte *temp;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-30 09:27:27 +00:00
|
|
|
_totalClusters = 0;
|
2004-01-07 07:42:00 +00:00
|
|
|
_resConvTable = NULL;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (!file.open("resource.inf"))
|
|
|
|
error("Cannot open resource.inf");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
size = file.size();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Get some space for the incoming resource file - soon to be trashed
|
|
|
|
temp = (byte *) malloc(size);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (file.read(temp, size) != size) {
|
2003-07-28 01:44:38 +00:00
|
|
|
file.close();
|
2003-09-30 09:27:27 +00:00
|
|
|
error("init cannot *READ* resource.inf");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Ok, we've loaded in the resource.inf file which contains a list of
|
|
|
|
// all the files now extract the filenames.
|
|
|
|
|
|
|
|
// Using this method the Gode generated resource.inf must have #0d0a on
|
|
|
|
// the last entry
|
|
|
|
|
|
|
|
uint32 i = 0;
|
|
|
|
uint32 j = 0;
|
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
do {
|
|
|
|
// item must have an #0d0a
|
2004-04-23 07:02:11 +00:00
|
|
|
while (temp[i] != 13) {
|
|
|
|
_resourceFiles[_totalClusters][j] = temp[i];
|
|
|
|
i++;
|
2003-07-28 01:44:38 +00:00
|
|
|
j++;
|
2003-09-02 09:55:11 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// NULL terminate our extracted string
|
2004-04-23 07:02:11 +00:00
|
|
|
_resourceFiles[_totalClusters][j] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// Reset position in current slot between entries, skip the
|
|
|
|
// 0x0a in the source and increase the number of clusters.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
j = 0;
|
|
|
|
i += 2;
|
2003-09-30 09:27:27 +00:00
|
|
|
_totalClusters++;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// TODO: put overload check here
|
2004-04-23 07:02:11 +00:00
|
|
|
} while (i != size);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
free(temp);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Now load in the binary id to res conversion table
|
|
|
|
if (!file.open("resource.tab"))
|
|
|
|
error("Cannot open resource.tab");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Find how many resources
|
|
|
|
size = file.size();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_totalResFiles = size / 4;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Table seems ok so malloc some space
|
|
|
|
_resConvTable = (uint16 *) malloc(size);
|
|
|
|
|
|
|
|
for (i = 0; i < size / 2; i++)
|
|
|
|
_resConvTable[i] = file.readUint16LE();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
if (file.ioFailed()) {
|
2003-07-28 01:44:38 +00:00
|
|
|
file.close();
|
2004-04-23 07:02:11 +00:00
|
|
|
error("Cannot read resource.tab");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
file.close();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (!file.open("cd.inf"))
|
|
|
|
error("Cannot open cd.inf");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
CdInf *cdInf = new CdInf[_totalClusters];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (i = 0; i < _totalClusters; i++) {
|
|
|
|
file.read(cdInf[i].clusterName, sizeof(cdInf[i].clusterName));
|
|
|
|
cdInf[i].cd = file.readByte();
|
2003-09-02 09:55:11 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (file.ioFailed())
|
|
|
|
error("Cannot read cd.inf");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (i = 0; i < _totalClusters; i++) {
|
|
|
|
for (j = 0; j < _totalClusters; j++) {
|
|
|
|
if (scumm_stricmp((char *) cdInf[j].clusterName, _resourceFiles[i]) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (j == _totalClusters)
|
|
|
|
error("%s is not in cd.inf", _resourceFiles[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_cdTab[i] = cdInf[j].cd;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-12-08 07:30:22 +00:00
|
|
|
delete [] cdInf;
|
2003-11-16 14:18:29 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
debug(1, "%d resources in %d cluster files", _totalResFiles, _totalClusters);
|
|
|
|
for (i = 0; i < _totalClusters; i++)
|
|
|
|
debug(2, "filename of cluster %d: -%s", i, _resourceFiles[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_resList = (Resource *) malloc(_totalResFiles * sizeof(Resource));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (i = 0; i < _totalResFiles; i++) {
|
|
|
|
_resList[i].ptr = NULL;
|
|
|
|
_resList[i].size = 0;
|
|
|
|
_resList[i].refCount = 0;
|
|
|
|
_resList[i].refTime = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_resTime = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
ResourceManager::~ResourceManager(void) {
|
2003-09-30 09:27:27 +00:00
|
|
|
free(_resList);
|
2004-01-07 07:42:00 +00:00
|
|
|
free(_resConvTable);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-13 13:02:44 +00:00
|
|
|
// Quick macro to make swapping in-place easier to write
|
2003-09-30 09:27:27 +00:00
|
|
|
|
2003-09-13 13:02:44 +00:00
|
|
|
#define SWAP16(x) x = SWAP_BYTES_16(x)
|
|
|
|
#define SWAP32(x) x = SWAP_BYTES_32(x)
|
2003-09-30 09:27:27 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void convertEndian(byte *file, uint32 len) {
|
2003-09-12 21:40:44 +00:00
|
|
|
int i;
|
2003-12-28 15:08:12 +00:00
|
|
|
StandardHeader *hdr = (StandardHeader *) file;
|
2003-09-12 21:40:44 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
file += sizeof(StandardHeader);
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-13 13:02:44 +00:00
|
|
|
SWAP32(hdr->compSize);
|
|
|
|
SWAP32(hdr->decompSize);
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
switch (hdr->fileType) {
|
2003-09-21 18:10:12 +00:00
|
|
|
case ANIMATION_FILE: {
|
2003-12-28 15:08:12 +00:00
|
|
|
AnimHeader *animHead = (AnimHeader *) file;
|
2003-09-21 16:11:26 +00:00
|
|
|
|
|
|
|
SWAP16(animHead->noAnimFrames);
|
|
|
|
SWAP16(animHead->feetStartX);
|
|
|
|
SWAP16(animHead->feetStartY);
|
|
|
|
SWAP16(animHead->feetEndX);
|
|
|
|
SWAP16(animHead->feetEndY);
|
|
|
|
SWAP16(animHead->blend);
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
CdtEntry *cdtEntry = (CdtEntry *) (file + sizeof(AnimHeader));
|
2003-09-21 16:11:26 +00:00
|
|
|
for (i = 0; i < animHead->noAnimFrames; i++, cdtEntry++) {
|
|
|
|
SWAP16(cdtEntry->x);
|
|
|
|
SWAP16(cdtEntry->y);
|
|
|
|
SWAP32(cdtEntry->frameOffset);
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
FrameHeader *frameHeader = (FrameHeader *) (file + cdtEntry->frameOffset);
|
2003-09-21 16:11:26 +00:00
|
|
|
// Quick trick to prevent us from incorrectly applying the endian
|
|
|
|
// fixes multiple times. This assumes that frames are less than 1 MB
|
|
|
|
// and have height/width less than 4096.
|
|
|
|
if ((frameHeader->compSize & 0xFFF00000) ||
|
|
|
|
(frameHeader->width & 0xF000) ||
|
|
|
|
(frameHeader->height & 0xF000)) {
|
|
|
|
SWAP32(frameHeader->compSize);
|
|
|
|
SWAP16(frameHeader->width);
|
|
|
|
SWAP16(frameHeader->height);
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
case SCREEN_FILE: {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) file;
|
2003-09-21 16:11:26 +00:00
|
|
|
|
|
|
|
SWAP32(mscreenHeader->palette);
|
|
|
|
SWAP32(mscreenHeader->bg_parallax[0]);
|
|
|
|
SWAP32(mscreenHeader->bg_parallax[1]);
|
|
|
|
SWAP32(mscreenHeader->screen);
|
|
|
|
SWAP32(mscreenHeader->fg_parallax[0]);
|
|
|
|
SWAP32(mscreenHeader->fg_parallax[1]);
|
|
|
|
SWAP32(mscreenHeader->layers);
|
|
|
|
SWAP32(mscreenHeader->paletteTable);
|
|
|
|
SWAP32(mscreenHeader->maskOffset);
|
|
|
|
|
|
|
|
// screenHeader
|
2003-12-28 15:08:12 +00:00
|
|
|
ScreenHeader *screenHeader = (ScreenHeader *) (file + mscreenHeader->screen);
|
2003-09-21 16:11:26 +00:00
|
|
|
|
|
|
|
SWAP16(screenHeader->width);
|
|
|
|
SWAP16(screenHeader->height);
|
|
|
|
SWAP16(screenHeader->noLayers);
|
|
|
|
|
|
|
|
// layerHeader
|
2003-12-28 15:08:12 +00:00
|
|
|
LayerHeader *layerHeader = (LayerHeader *) (file + mscreenHeader->layers);
|
2003-09-21 16:11:26 +00:00
|
|
|
for (i = 0; i < screenHeader->noLayers; i++, layerHeader++) {
|
|
|
|
SWAP16(layerHeader->x);
|
|
|
|
SWAP16(layerHeader->y);
|
|
|
|
SWAP16(layerHeader->width);
|
|
|
|
SWAP16(layerHeader->height);
|
|
|
|
SWAP32(layerHeader->maskSize);
|
|
|
|
SWAP32(layerHeader->offset);
|
|
|
|
}
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
// backgroundParallaxLayer
|
2003-12-28 15:08:12 +00:00
|
|
|
Parallax *parallax;
|
2003-09-21 16:11:26 +00:00
|
|
|
int offset;
|
|
|
|
offset = mscreenHeader->bg_parallax[0];
|
|
|
|
if (offset > 0) {
|
2003-12-28 15:08:12 +00:00
|
|
|
parallax = (Parallax *) (file + offset);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(parallax->w);
|
|
|
|
SWAP16(parallax->h);
|
|
|
|
}
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
offset = mscreenHeader->bg_parallax[1];
|
|
|
|
if (offset > 0) {
|
2003-12-28 15:08:12 +00:00
|
|
|
parallax = (Parallax *) (file + offset);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(parallax->w);
|
|
|
|
SWAP16(parallax->h);
|
|
|
|
}
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
// backgroundLayer
|
2003-12-28 15:08:12 +00:00
|
|
|
offset = mscreenHeader->screen + sizeof(ScreenHeader);
|
2003-09-21 16:11:26 +00:00
|
|
|
if (offset > 0) {
|
2003-12-28 15:08:12 +00:00
|
|
|
parallax = (Parallax *) (file + offset);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(parallax->w);
|
|
|
|
SWAP16(parallax->h);
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
// foregroundParallaxLayer
|
|
|
|
offset = mscreenHeader->fg_parallax[0];
|
|
|
|
if (offset > 0) {
|
2003-12-28 15:08:12 +00:00
|
|
|
parallax = (Parallax *) (file + offset);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(parallax->w);
|
|
|
|
SWAP16(parallax->h);
|
|
|
|
}
|
2003-09-12 18:52:53 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
offset = mscreenHeader->fg_parallax[1];
|
|
|
|
if (offset > 0) {
|
2003-12-28 15:08:12 +00:00
|
|
|
parallax = (Parallax *) (file + offset);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(parallax->w);
|
|
|
|
SWAP16(parallax->h);
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
|
|
|
case GAME_OBJECT: {
|
2003-12-28 15:08:12 +00:00
|
|
|
ObjectHub *objectHub = (ObjectHub *) file;
|
2003-09-13 20:42:08 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
objectHub->type = (int) SWAP_BYTES_32(objectHub->type);
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP32(objectHub->logic_level);
|
2003-09-13 20:42:08 +00:00
|
|
|
|
2003-09-21 16:11:26 +00:00
|
|
|
for (i = 0; i < TREE_SIZE; i++) {
|
|
|
|
SWAP32(objectHub->logic[i]);
|
|
|
|
SWAP32(objectHub->script_id[i]);
|
|
|
|
SWAP32(objectHub->script_pc[i]);
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
|
|
|
case WALK_GRID_FILE: {
|
2003-12-28 15:08:12 +00:00
|
|
|
WalkGridHeader *walkGridHeader = (WalkGridHeader *) file;
|
2003-09-21 16:11:26 +00:00
|
|
|
|
|
|
|
SWAP32(walkGridHeader->numBars);
|
|
|
|
SWAP32(walkGridHeader->numNodes);
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
BarData *barData = (BarData *) (file + sizeof(WalkGridHeader));
|
2003-09-21 16:11:26 +00:00
|
|
|
for (i = 0; i < walkGridHeader->numBars; i++) {
|
|
|
|
SWAP16(barData->x1);
|
|
|
|
SWAP16(barData->y1);
|
|
|
|
SWAP16(barData->x2);
|
|
|
|
SWAP16(barData->y2);
|
|
|
|
SWAP16(barData->xmin);
|
|
|
|
SWAP16(barData->ymin);
|
|
|
|
SWAP16(barData->xmax);
|
|
|
|
SWAP16(barData->ymax);
|
|
|
|
SWAP16(barData->dx);
|
|
|
|
SWAP16(barData->dy);
|
|
|
|
SWAP32(barData->co);
|
|
|
|
barData++;
|
2003-09-13 17:36:31 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
|
2004-01-12 20:04:22 +00:00
|
|
|
uint16 *node = (uint16 *) (file + sizeof(WalkGridHeader) + walkGridHeader->numBars * sizeof(BarData));
|
2003-11-23 13:40:24 +00:00
|
|
|
for (i = 0; i < walkGridHeader->numNodes * 2; i++) {
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP16(*node);
|
|
|
|
node++;
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
|
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
case GLOBAL_VAR_FILE:
|
|
|
|
break;
|
|
|
|
case PARALLAX_FILE_null:
|
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
case RUN_LIST: {
|
2003-11-23 13:40:24 +00:00
|
|
|
uint32 *list = (uint32 *) file;
|
2003-09-21 16:11:26 +00:00
|
|
|
while (*list) {
|
|
|
|
SWAP32(*list);
|
|
|
|
list++;
|
|
|
|
}
|
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
|
|
|
case TEXT_FILE: {
|
2003-12-28 15:08:12 +00:00
|
|
|
TextHeader *textHeader = (TextHeader *) file;
|
2003-09-21 16:11:26 +00:00
|
|
|
SWAP32(textHeader->noOfLines);
|
|
|
|
break;
|
2003-09-21 18:10:12 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
case SCREEN_MANAGER:
|
|
|
|
break;
|
|
|
|
case MOUSE_FILE:
|
|
|
|
break;
|
|
|
|
case ICON_FILE:
|
|
|
|
break;
|
2003-09-12 18:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Returns the address of a resource. Loads if not in memory. Retains a count.
|
|
|
|
*/
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *ResourceManager::openResource(uint32 res, bool dump) {
|
2003-11-23 13:40:24 +00:00
|
|
|
assert(res < _totalResFiles);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Is the resource in memory already? If not, load it.
|
|
|
|
|
|
|
|
if (!_resList[res].ptr) {
|
|
|
|
// Fetch the correct file and read in the correct portion.
|
2003-09-12 20:48:28 +00:00
|
|
|
|
|
|
|
// points to the number of the ascii filename
|
2004-04-23 07:02:11 +00:00
|
|
|
uint16 parent_res_file = _resConvTable[res * 2];
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2003-11-23 13:40:24 +00:00
|
|
|
assert(parent_res_file != 0xffff);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Relative resource within the file
|
|
|
|
uint16 actual_res = _resConvTable[(res * 2) + 1];
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// First we have to find the file via the _resConvTable
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
debug(5, "openResource %s res %d", _resourceFiles[parent_res_file], res);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
|
|
|
// If we're loading a cluster that's only available from one
|
|
|
|
// of the CDs, remember which one so that we can play the
|
|
|
|
// correct music.
|
|
|
|
|
2003-11-23 13:40:24 +00:00
|
|
|
if (!(_cdTab[parent_res_file] & LOCAL_PERM))
|
2003-09-30 09:27:27 +00:00
|
|
|
_curCd = _cdTab[parent_res_file] & 3;
|
2003-09-12 20:48:28 +00:00
|
|
|
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
// Actually, as long as the file can be found we don't really
|
|
|
|
// care which CD it's on. But if we can't find it, keep asking
|
|
|
|
// for the CD until we do.
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
File file;
|
|
|
|
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
while (!file.open(_resourceFiles[parent_res_file])) {
|
2003-11-15 09:38:00 +00:00
|
|
|
// If the file is supposed to be on hard disk, or we're
|
|
|
|
// playing a demo, then we're in trouble if the file
|
|
|
|
// can't be found!
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
|
2004-01-03 14:49:52 +00:00
|
|
|
if ((_vm->_features & GF_DEMO) || (_cdTab[parent_res_file] & LOCAL_PERM))
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
error("Could not find '%s'", _resourceFiles[parent_res_file]);
|
|
|
|
|
|
|
|
getCd(_cdTab[parent_res_file] & 3);
|
|
|
|
}
|
2003-09-12 20:48:28 +00:00
|
|
|
|
|
|
|
// 1st DWORD of a cluster is an offset to the look-up table
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 table_offset = file.readUint32LE();
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
debug(6, "table offset = %d", table_offset);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2003-09-27 11:02:58 +00:00
|
|
|
file.seek(table_offset + actual_res * 8, SEEK_SET);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 pos = file.readUint32LE();
|
|
|
|
uint32 len = file.readUint32LE();
|
|
|
|
|
2003-09-12 20:48:28 +00:00
|
|
|
file.seek(pos, SEEK_SET);
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
debug(6, "res len %d", len);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Ok, we know the length so try and allocate the memory.
|
|
|
|
_resList[res].ptr = _vm->_memory->memAlloc(len, res);
|
|
|
|
_resList[res].size = len;
|
2004-04-23 11:36:06 +00:00
|
|
|
_resList[res].refCount = 0;
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
file.read(_resList[res].ptr, len);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2003-11-23 13:40:24 +00:00
|
|
|
if (dump) {
|
2004-04-23 07:02:11 +00:00
|
|
|
StandardHeader *header = (StandardHeader *) _resList[res].ptr;
|
2003-11-23 13:40:24 +00:00
|
|
|
char buf[256];
|
2004-09-12 17:10:59 +00:00
|
|
|
const char *tag;
|
2003-11-23 13:40:24 +00:00
|
|
|
File out;
|
|
|
|
|
|
|
|
switch (header->fileType) {
|
|
|
|
case ANIMATION_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "anim";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case SCREEN_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "layer";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case GAME_OBJECT:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "object";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case WALK_GRID_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "walkgrid";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case GLOBAL_VAR_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "globals";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case PARALLAX_FILE_null:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "parallax"; // Not used!
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case RUN_LIST:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "runlist";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case TEXT_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "text";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case SCREEN_MANAGER:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "screen";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
case MOUSE_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "mouse";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
2003-11-27 07:34:19 +00:00
|
|
|
case WAV_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "wav";
|
2003-11-27 07:34:19 +00:00
|
|
|
break;
|
2003-11-23 13:40:24 +00:00
|
|
|
case ICON_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "icon";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
2003-11-27 07:34:19 +00:00
|
|
|
case PALETTE_FILE:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "palette";
|
2003-11-27 07:34:19 +00:00
|
|
|
break;
|
2003-11-23 13:40:24 +00:00
|
|
|
default:
|
2004-09-12 17:10:59 +00:00
|
|
|
tag = "unknown";
|
2003-11-23 13:40:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(MACOS_CARBON)
|
2003-11-27 07:34:19 +00:00
|
|
|
sprintf(buf, ":dumps:%s-%d.dmp", tag, res);
|
2003-11-23 13:40:24 +00:00
|
|
|
#else
|
2003-11-27 07:34:19 +00:00
|
|
|
sprintf(buf, "dumps/%s-%d.dmp", tag, res);
|
2003-11-23 13:40:24 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-27 15:09:53 +00:00
|
|
|
if (!out.exists(buf, "")) {
|
2004-06-27 22:14:35 +00:00
|
|
|
if (out.open(buf, File::kFileWriteMode, ""))
|
2004-04-23 07:02:11 +00:00
|
|
|
out.write(_resList[res].ptr, len);
|
2003-11-23 13:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// close the cluster
|
2003-09-12 20:48:28 +00:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
#ifdef SCUMM_BIG_ENDIAN
|
2004-04-23 07:02:11 +00:00
|
|
|
convertEndian(_resList[res].ptr, len);
|
2003-09-12 20:48:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_resList[res].refCount++;
|
|
|
|
_resList[res].refTime = _resTime;
|
|
|
|
|
|
|
|
return _resList[res].ptr;
|
|
|
|
}
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void ResourceManager::closeResource(uint32 res) {
|
|
|
|
assert(res < _totalResFiles);
|
|
|
|
assert(_resList[res].refCount > 0);
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
_resList[res].refCount--;
|
|
|
|
_resList[res].refTime = _resTime;
|
2003-09-12 20:48:28 +00:00
|
|
|
|
2004-09-12 17:10:59 +00:00
|
|
|
// It's tempting to free the resource immediately when refCount
|
|
|
|
// reaches zero, but that'd be a mistake. Closing a resource does not
|
|
|
|
// mean "I'm not going to use this resource any more". It means that
|
|
|
|
// "the next time I use this resource I'm going to ask for a new
|
|
|
|
// pointer to it".
|
|
|
|
//
|
|
|
|
// Since the original memory manager had to deal with memory
|
|
|
|
// fragmentation, keeping a resource open - and thus locked down to a
|
|
|
|
// specific memory address - was considered a bad thing.
|
2004-04-23 07:02:11 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Returns true if resource is valid, otherwise false.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
bool ResourceManager::checkValid(uint32 res) {
|
|
|
|
// Resource number out of range
|
2003-09-30 09:27:27 +00:00
|
|
|
if (res >= _totalResFiles)
|
2004-04-23 07:02:11 +00:00
|
|
|
return false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Points to the number of the ascii filename
|
|
|
|
uint16 parent_res_file = _resConvTable[res * 2];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Null & void resource
|
2003-09-02 09:55:11 +00:00
|
|
|
if (parent_res_file == 0xffff)
|
2004-04-23 07:02:11 +00:00
|
|
|
return false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void ResourceManager::passTime() {
|
|
|
|
// In the original game this was called every game cycle. This allowed
|
|
|
|
// for a more exact measure of when a loaded resouce was most recently
|
|
|
|
// used. When the memory pool got too fragmented, the oldest and
|
|
|
|
// largest of the closed resources would be expelled from the cache.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// With the new memory manager, there is no single memory block that
|
|
|
|
// can become fragmented. Therefore, it makes more sense to me to
|
|
|
|
// measure an object's age in how many rooms ago it was last used.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Therefore, this function is now called when a new room is loaded.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-30 09:27:27 +00:00
|
|
|
_resTime++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Returns the total file length of a resource - i.e. all headers are included
|
|
|
|
* too.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
uint32 ResourceManager::fetchLen(uint32 res) {
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_resList[res].ptr)
|
|
|
|
return _resList[res].size;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Does this ever happen?
|
|
|
|
warning("fetchLen: Resource %u is not loaded; reading length from file", res);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
// Points to the number of the ascii filename
|
|
|
|
uint16 parent_res_file = _resConvTable[res * 2];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// relative resource within the file
|
2004-04-23 07:02:11 +00:00
|
|
|
uint16 actual_res = _resConvTable[(res * 2) + 1];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-30 09:27:27 +00:00
|
|
|
// first we have to find the file via the _resConvTable
|
2003-08-23 14:33:57 +00:00
|
|
|
// open the cluster file
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
File file;
|
|
|
|
|
|
|
|
if (!file.open(_resourceFiles[parent_res_file]))
|
|
|
|
error("Cannot open %s", _resourceFiles[parent_res_file]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// 1st DWORD of a cluster is an offset to the look-up table
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 table_offset = file.readUint32LE();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-02 09:55:11 +00:00
|
|
|
// 2 dwords per resource + skip the position dword
|
2004-04-23 07:02:11 +00:00
|
|
|
file.seek(table_offset + (actual_res * 8) + 4, SEEK_SET);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return file.readUint32LE();
|
2003-09-02 09:55:11 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-09-12 17:10:59 +00:00
|
|
|
// When a resource is opened, regardless of whether it was read from disk or
|
|
|
|
// from the cache, its age is zeroed. They then age every time a new room is
|
|
|
|
// entered. This function is responsible for cleaning out the resources that
|
|
|
|
// have grown too old to live.
|
|
|
|
//
|
|
|
|
// It could use a bit more tuning, I guess. I picked a max age of three for
|
|
|
|
// most resources, because so much of the game seems to consist of areas of
|
|
|
|
// about three rooms. I made an exception for SCREEN_FILE resources because
|
|
|
|
// they are so large, but maybe the exception ought to be the rule...?
|
|
|
|
|
2004-09-08 07:10:54 +00:00
|
|
|
void ResourceManager::expireOldResources() {
|
2004-04-23 07:02:11 +00:00
|
|
|
int nuked = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (uint i = 0; i < _totalResFiles; i++) {
|
2004-09-12 17:10:59 +00:00
|
|
|
if (!_resList[i].ptr || _resList[i].refCount > 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
StandardHeader *head = (StandardHeader *) _resList[i].ptr;
|
|
|
|
uint maxCacheAge;
|
|
|
|
|
|
|
|
switch (head->fileType) {
|
|
|
|
case SCREEN_FILE:
|
|
|
|
// The resource will be read from disk once as soon as
|
|
|
|
// the player enters the room, and thrown away when
|
|
|
|
// the player enters a new room.
|
|
|
|
maxCacheAge = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
maxCacheAge = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_resTime - _resList[i].refTime >= maxCacheAge) {
|
2004-04-23 07:02:11 +00:00
|
|
|
remove(i);
|
|
|
|
nuked++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:55:11 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
debug(1, "%d resources died of old age", nuked);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
void ResourceManager::printConsoleClusters(void) {
|
2003-09-30 09:27:27 +00:00
|
|
|
if (_totalClusters) {
|
2003-11-11 15:07:35 +00:00
|
|
|
for (uint i = 0; i < _totalClusters; i++) {
|
|
|
|
Debug_Printf("%-20s ", _resourceFiles[i]);
|
|
|
|
if (!(_cdTab[i] & LOCAL_PERM)) {
|
|
|
|
switch (_cdTab[i] & 3) {
|
|
|
|
case BOTH:
|
|
|
|
Debug_Printf("CD 1 & 2\n");
|
|
|
|
break;
|
|
|
|
case CD1:
|
|
|
|
Debug_Printf("CD 1\n");
|
|
|
|
break;
|
|
|
|
case CD2:
|
|
|
|
Debug_Printf("CD 2\n");
|
|
|
|
break;
|
2003-11-11 15:16:41 +00:00
|
|
|
default:
|
|
|
|
Debug_Printf("CD 3? Huh?!\n");
|
|
|
|
break;
|
2003-11-11 15:07:35 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
Debug_Printf("HD\n");
|
|
|
|
}
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("%d resources\n", _totalResFiles);
|
2003-09-02 09:55:11 +00:00
|
|
|
} else
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("Argh! No resources!\n");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-09-08 07:10:54 +00:00
|
|
|
void ResourceManager::listResources(uint minCount) {
|
|
|
|
for (uint i = 0; i < _totalResFiles; i++) {
|
|
|
|
if (_resList[i].ptr && _resList[i].refCount >= minCount) {
|
|
|
|
StandardHeader *head = (StandardHeader *) _resList[i].ptr;
|
|
|
|
Debug_Printf("%-4d: %-35s refCount: %-3d age: %-2d\n", i, head->name, _resList[i].refCount, _resTime - _resList[i].refTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
void ResourceManager::examine(int res) {
|
|
|
|
if (res < 0 || res >= (int) _totalResFiles)
|
|
|
|
Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
|
|
|
|
else if (_resConvTable[res * 2] == 0xffff)
|
|
|
|
Debug_Printf("%d is a null & void resource number\n", res);
|
|
|
|
else {
|
2003-11-03 07:47:42 +00:00
|
|
|
// open up the resource and take a look inside!
|
2004-04-23 07:02:11 +00:00
|
|
|
StandardHeader *file_header = (StandardHeader *) openResource(res);
|
2003-10-26 15:42:49 +00:00
|
|
|
|
|
|
|
switch (file_header->fileType) {
|
|
|
|
case ANIMATION_FILE:
|
|
|
|
Debug_Printf("<anim> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case SCREEN_FILE:
|
|
|
|
Debug_Printf("<layer> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case GAME_OBJECT:
|
|
|
|
Debug_Printf("<game object> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case WALK_GRID_FILE:
|
|
|
|
Debug_Printf("<walk grid> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case GLOBAL_VAR_FILE:
|
|
|
|
Debug_Printf("<global variables> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case PARALLAX_FILE_null:
|
|
|
|
Debug_Printf("<parallax file NOT USED!> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case RUN_LIST:
|
|
|
|
Debug_Printf("<run list> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case TEXT_FILE:
|
|
|
|
Debug_Printf("<text file> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case SCREEN_MANAGER:
|
|
|
|
Debug_Printf("<screen manager> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case MOUSE_FILE:
|
|
|
|
Debug_Printf("<mouse pointer> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
case ICON_FILE:
|
|
|
|
Debug_Printf("<menu icon> %s\n", file_header->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
|
2003-07-28 01:44:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-11-03 07:47:42 +00:00
|
|
|
closeResource(res);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
void ResourceManager::kill(int res) {
|
|
|
|
if (res < 0 || res >= (int) _totalResFiles) {
|
|
|
|
Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (!_resList[res].ptr) {
|
|
|
|
Debug_Printf("Resource %d is not in memory\n", res);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-02 09:55:11 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_resList[res].refCount) {
|
|
|
|
Debug_Printf("Resource %d is open - cannot remove\n", res);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
remove(res);
|
|
|
|
Debug_Printf("Trashed %d\n", res);
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void ResourceManager::remove(int res) {
|
|
|
|
if (_resList[res].ptr) {
|
|
|
|
_vm->_memory->memFree(_resList[res].ptr);
|
|
|
|
_resList[res].ptr = NULL;
|
2004-04-23 11:36:06 +00:00
|
|
|
_resList[res].refCount = 0;
|
2004-04-23 07:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Remove all res files from memory - ready for a total restart. This includes
|
|
|
|
* the player object and global variables resource.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void ResourceManager::removeAll(void) {
|
2004-05-09 13:20:12 +00:00
|
|
|
// We need to clear the FX queue, because otherwise the sound system
|
|
|
|
// will still believe that the sound resources are in memory, and that
|
|
|
|
// it's ok to close them.
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_vm->_sound->clearFxQueue();
|
2004-05-09 13:20:12 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (uint i = 0; i < _totalResFiles; i++)
|
|
|
|
remove(i);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:55:11 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Remove all resources from memory.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
void ResourceManager::killAll(bool wantInfo) {
|
|
|
|
int nuked = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-05-01 10:42:23 +00:00
|
|
|
// We need to clear the FX queue, because otherwise the sound system
|
|
|
|
// will still believe that the sound resources are in memory, and that
|
|
|
|
// it's ok to close them.
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_vm->_sound->clearFxQueue();
|
2004-05-01 10:42:23 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (uint i = 0; i < _totalResFiles; i++) {
|
|
|
|
// Don't nuke the global variables or the player object!
|
|
|
|
if (i == 1 || i == CUR_PLAYER_ID)
|
|
|
|
continue;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_resList[i].ptr) {
|
|
|
|
StandardHeader *header = (StandardHeader *) _resList[i].ptr;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (wantInfo)
|
|
|
|
Debug_Printf("Nuked %5d: %s\n", i, header->name);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
remove(i);
|
|
|
|
nuked++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-23 07:02:11 +00:00
|
|
|
|
|
|
|
if (wantInfo)
|
|
|
|
Debug_Printf("Expelled %d resources\n", nuked);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-02 09:55:11 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
/**
|
|
|
|
* Like killAll but only kills objects (except George & the variable table of
|
|
|
|
* course) - ie. forcing them to reload & restart their scripts, which
|
|
|
|
* simulates the effect of a save & restore, thus checking that each object's
|
|
|
|
* re-entrant logic works correctly, and doesn't cause a statuette to
|
|
|
|
* disappear forever, or some plaster-filled holes in sand to crash the game &
|
|
|
|
* get James in trouble again.
|
|
|
|
*/
|
2003-09-02 09:55:11 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
void ResourceManager::killAllObjects(bool wantInfo) {
|
2004-04-23 07:02:11 +00:00
|
|
|
int nuked = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
for (uint i = 0; i < _totalResFiles; i++) {
|
|
|
|
// Don't nuke the global variables or the player object!
|
|
|
|
if (i == 1 || i == CUR_PLAYER_ID)
|
|
|
|
continue;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (_resList[i].ptr) {
|
|
|
|
StandardHeader *header = (StandardHeader *) _resList[i].ptr;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
if (header->fileType == GAME_OBJECT) {
|
|
|
|
if (wantInfo)
|
|
|
|
Debug_Printf("Nuked %5d: %s\n", i, header->name);
|
|
|
|
|
|
|
|
remove(i);
|
|
|
|
nuked++;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-23 07:02:11 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
if (wantInfo)
|
2004-04-23 07:02:11 +00:00
|
|
|
Debug_Printf("Expelled %d resources\n", nuked);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
void ResourceManager::getCd(int cd) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *textRes;
|
2003-09-02 09:55:11 +00:00
|
|
|
|
|
|
|
// stop any music from playing - so the system no longer needs the
|
|
|
|
// current CD - otherwise when we take out the CD, Windows will
|
|
|
|
// complain!
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-15 09:38:00 +00:00
|
|
|
_vm->_logic->fnStopMusic(NULL);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
textRes = openResource(2283);
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->displayMsg(_vm->fetchTextLine(textRes, 5 + cd) + 2, 0);
|
2003-11-03 07:47:42 +00:00
|
|
|
closeResource(2283);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
// The original code probably determined automagically when the correct
|
|
|
|
// CD had been inserted, but our backend doesn't support that, and
|
|
|
|
// anyway I don't know if all systems allow that sort of thing. So we
|
|
|
|
// wait for the user to press any key instead, or click the mouse.
|
2003-11-14 07:41:22 +00:00
|
|
|
//
|
|
|
|
// But just in case we ever try to identify the CDs by their labels,
|
|
|
|
// they should be:
|
|
|
|
//
|
|
|
|
// CD1: "RBSII1" (or "PCF76" for the PCF76 version, whatever that is)
|
|
|
|
// CD2: "RBSII2"
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|