[Scummvm-cvs-logs] scummvm master -> 9ec64a66fe2f20eb1be0811b5f733332efff1b93
fingolfin
max at quendi.de
Fri May 13 15:05:45 CEST 2011
This automated email contains information about 26 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
068b4a5351 SCUMM: Move tmsk code into its own Gdi subclass
f05de5228f SCUMM: Print SCUMM & HE version when starting a game in deug mode
7773a17b0a SCUMM: Unify & extend index block related debug messages
b37463fe59 SCUMM: Move class ResourceManager to its own header
45e65d7ea0 SCUMM: Refactor how resource (types) are srepresented
26efa39d2c SCUMM: Document and cleanup resource type mode
7be0305da9 SCUMM: Rename saveLoadResource to loadResourceOLD, remove unused save code in it
0af2f71c71 SCUMM: Clean up ResourceManager initialization
75b9deb185 SCUMM: Get rid of the MemBlkHeader hack
0342ab3f1b SCUMM: Rename ResTypeData::num to _num
82a6f2ee3c SCUMM: Rename ResTypeData::tag to _tag, get rid of ResTypeData::name
ff3087e56c SCUMM: Remove obsolete TODO
107e25ff5b SCUMM: Document resource usage count / expiry a little bit
abaaf0cad9 SCUMM: Tweak sound res syncing
c02420df43 SCUMM: Add a Resource class, refactor res code around it
aaf2c0e6eb TSAGE: Fix warning when compiling in release mode
649f8e0a84 SCUMM: Rename ResTypes->ResType, introduce ResId typedef, change code to use both
dfd6112403 SCUMM: Rename resTypeFromId -> nameOfResType
45207a52d4 SCUMM: Remove ResTypeData::_num
1faf89c524 SCUMM: Improve ResTypeData doxygen comments
d63c2d17c2 SCUMM: Improve and document res tag sanity check
65a82610d1 DEVTOOLS: Remove obsolete TeX mode from credits.pl, mention Credits.rtf
4108f09543 SCUMM: Make it clearer that SCUMM's 'restart' feature leaks like hell
749a1beb35 SCUMM: Remove useless allocateArrays call, and make sure all resources are properly killed upon restart
cf513e3ed6 SCUMM: Get rid of the unused Resource::_globSize field
9ec64a66fe SCUMM: Turned ResTypeData into a Common::Array<Resource>, subsuming its _resource member
Commit: 068b4a5351a5574dbfac6acff5776a0071f3f2dd
https://github.com/scummvm/scummvm/commit/068b4a5351a5574dbfac6acff5776a0071f3f2dd
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:07-07:00
Commit Message:
SCUMM: Move tmsk code into its own Gdi subclass
Changed paths:
engines/scumm/gfx.cpp
engines/scumm/gfx.h
engines/scumm/scumm.cpp
diff --git a/engines/scumm/gfx.cpp b/engines/scumm/gfx.cpp
index 287fd1e..08ae9fd 100644
--- a/engines/scumm/gfx.cpp
+++ b/engines/scumm/gfx.cpp
@@ -218,6 +218,10 @@ Gdi::Gdi(ScummEngine *vm) : _vm(vm) {
Gdi::~Gdi() {
}
+GdiHE::GdiHE(ScummEngine *vm) : Gdi(vm), _tmskPtr(0) {
+}
+
+
GdiNES::GdiNES(ScummEngine *vm) : Gdi(vm) {
memset(&_NES, 0, sizeof(_NES));
}
@@ -1500,6 +1504,15 @@ void Gdi::prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
// Do nothing by default
}
+void GdiHE::prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
+ const int x, const int y, const int width, const int height,
+ int stripnr, int numstrip) {
+ if (_vm->_game.heversion >= 72) {
+ _tmskPtr = _vm->findResource(MKTAG('T','M','S','K'), ptr);
+ } else
+ _tmskPtr = 0;
+}
+
void GdiV1::prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
int stripnr, int numstrip) {
@@ -1745,11 +1758,6 @@ void Gdi::drawBitmap(const byte *ptr, VirtScreen *vs, int x, const int y, const
numzbuf = getZPlanes(ptr, zplane_list, false);
- const byte *tmsk_ptr = NULL;
- if (_vm->_game.heversion >= 72) {
- tmsk_ptr = _vm->findResource(MKTAG('T','M','S','K'), ptr);
- }
-
if (y + height > vs->h) {
warning("Gdi::drawBitmap, strip drawn to %d below window bottom %d", y + height, vs->h);
}
@@ -1812,7 +1820,7 @@ void Gdi::drawBitmap(const byte *ptr, VirtScreen *vs, int x, const int y, const
clear8Col(frontBuf, vs->pitch, height, vs->format.bytesPerPixel);
}
- decodeMask(x, y, width, height, stripnr, numzbuf, zplane_list, transpStrip, flag, tmsk_ptr);
+ decodeMask(x, y, width, height, stripnr, numzbuf, zplane_list, transpStrip, flag);
#if 0
// HACK: blit mask(s) onto normal screen. Useful to debug masking
@@ -1901,7 +1909,7 @@ bool GdiV2::drawStrip(byte *dstPtr, VirtScreen *vs, int x, int y, const int widt
void Gdi::decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr) {
+ bool transpStrip, byte flag) {
int i;
byte *mask_ptr;
const byte *z_plane_ptr;
@@ -1957,10 +1965,7 @@ void Gdi::decodeMask(int x, int y, const int width, const int height,
if (offs) {
z_plane_ptr = zplane_list[i] + offs;
- if (tmsk_ptr) {
- const byte *tmsk = tmsk_ptr + READ_LE_UINT16(tmsk_ptr + stripnr * 2 + 8);
- decompressTMSK(mask_ptr, tmsk, z_plane_ptr, height);
- } else if (transpStrip && (flag & dbAllowMaskOr)) {
+ if (transpStrip && (flag & dbAllowMaskOr)) {
decompressMaskImgOr(mask_ptr, z_plane_ptr, height);
} else {
decompressMaskImg(mask_ptr, z_plane_ptr, height);
@@ -1975,9 +1980,46 @@ void Gdi::decodeMask(int x, int y, const int width, const int height,
}
}
+void GdiHE::decodeMask(int x, int y, const int width, const int height,
+ int stripnr, int numzbuf, const byte *zplane_list[9],
+ bool transpStrip, byte flag) {
+ int i;
+ byte *mask_ptr;
+ const byte *z_plane_ptr;
+
+ for (i = 1; i < numzbuf; i++) {
+ uint32 offs;
+
+ if (!zplane_list[i])
+ continue;
+
+ offs = READ_LE_UINT16(zplane_list[i] + stripnr * 2 + 8);
+
+ mask_ptr = getMaskBuffer(x, y, i);
+
+ if (offs) {
+ z_plane_ptr = zplane_list[i] + offs;
+
+ if (_tmskPtr) {
+ const byte *tmsk = _tmskPtr + READ_LE_UINT16(_tmskPtr + stripnr * 2 + 8);
+ decompressTMSK(mask_ptr, tmsk, z_plane_ptr, height);
+ } else if (transpStrip && (flag & dbAllowMaskOr)) {
+ decompressMaskImgOr(mask_ptr, z_plane_ptr, height);
+ } else {
+ decompressMaskImg(mask_ptr, z_plane_ptr, height);
+ }
+
+ } else {
+ if (!(transpStrip && (flag & dbAllowMaskOr)))
+ for (int h = 0; h < height; h++)
+ mask_ptr[h * _numStrips] = 0;
+ }
+ }
+}
+
void GdiNES::decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr) {
+ bool transpStrip, byte flag) {
byte *mask_ptr = getMaskBuffer(x, y, 1);
drawStripNESMask(mask_ptr, stripnr, y, height);
}
@@ -1985,7 +2027,7 @@ void GdiNES::decodeMask(int x, int y, const int width, const int height,
#ifdef USE_RGB_COLOR
void GdiPCEngine::decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr) {
+ bool transpStrip, byte flag) {
byte *mask_ptr = getMaskBuffer(x, y, 1);
drawStripPCEngineMask(mask_ptr, stripnr, y, height);
}
@@ -1993,14 +2035,14 @@ void GdiPCEngine::decodeMask(int x, int y, const int width, const int height,
void GdiV1::decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr) {
+ bool transpStrip, byte flag) {
byte *mask_ptr = getMaskBuffer(x, y, 1);
drawStripC64Mask(mask_ptr, stripnr, width, height);
}
void GdiV2::decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr) {
+ bool transpStrip, byte flag) {
// Do nothing here for V2 games - zplane was already handled.
}
@@ -2368,7 +2410,7 @@ void Gdi::decompressMaskImg(byte *dst, const byte *src, int height) const {
}
}
-void Gdi::decompressTMSK(byte *dst, const byte *tmsk, const byte *src, int height) const {
+void GdiHE::decompressTMSK(byte *dst, const byte *tmsk, const byte *src, int height) const {
byte srcbits = 0;
byte srcFlag = 0;
byte maskFlag = 0;
diff --git a/engines/scumm/gfx.h b/engines/scumm/gfx.h
index 45ff8ce..6da07ef 100644
--- a/engines/scumm/gfx.h
+++ b/engines/scumm/gfx.h
@@ -221,7 +221,6 @@ protected:
virtual void writeRoomColor(byte *dst, byte color) const;
/* Mask decompressors */
- void decompressTMSK(byte *dst, const byte *tmsk, const byte *src, int height) const;
void decompressMaskImgOr(byte *dst, const byte *src, int height) const;
void decompressMaskImg(byte *dst, const byte *src, int height) const;
@@ -234,7 +233,7 @@ protected:
virtual void decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr);
+ bool transpStrip, byte flag);
virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
@@ -270,6 +269,24 @@ public:
};
};
+class GdiHE : public Gdi {
+protected:
+ const byte *_tmskPtr;
+
+protected:
+ void decompressTMSK(byte *dst, const byte *tmsk, const byte *src, int height) const;
+
+ virtual void decodeMask(int x, int y, const int width, const int height,
+ int stripnr, int numzbuf, const byte *zplane_list[9],
+ bool transpStrip, byte flag);
+
+ virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
+ const int x, const int y, const int width, const int height,
+ int stripnr, int numstrip);
+public:
+ GdiHE(ScummEngine *vm);
+};
+
class GdiNES : public Gdi {
protected:
struct {
@@ -293,7 +310,7 @@ protected:
virtual void decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr);
+ bool transpStrip, byte flag);
virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
@@ -336,7 +353,7 @@ protected:
virtual void decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr);
+ bool transpStrip, byte flag);
virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
@@ -373,7 +390,7 @@ protected:
virtual void decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr);
+ bool transpStrip, byte flag);
virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
@@ -399,7 +416,7 @@ protected:
virtual void decodeMask(int x, int y, const int width, const int height,
int stripnr, int numzbuf, const byte *zplane_list[9],
- bool transpStrip, byte flag, const byte *tmsk_ptr);
+ bool transpStrip, byte flag);
virtual void prepareDrawBitmap(const byte *ptr, VirtScreen *vs,
const int x, const int y, const int width, const int height,
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index b119824..f518754 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -112,7 +112,9 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
_currentScript(0xFF), // Let debug() work on init stage
_messageDialog(0), _pauseDialog(0), _versionDialog(0) {
- if (_game.platform == Common::kPlatformNES) {
+ if (_game.heversion > 0) {
+ _gdi = new GdiHE(this);
+ } else if (_game.platform == Common::kPlatformNES) {
_gdi = new GdiNES(this);
#ifdef USE_RGB_COLOR
} else if (_game.features & GF_16BIT_COLOR) {
Commit: f05de5228f9484a04da75e8b7c10bb0189e1be6e
https://github.com/scummvm/scummvm/commit/f05de5228f9484a04da75e8b7c10bb0189e1be6e
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:07-07:00
Commit Message:
SCUMM: Print SCUMM & HE version when starting a game in deug mode
Changed paths:
engines/scumm/detection.cpp
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index 6d2f395..95f76db 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -1036,6 +1036,7 @@ Common::Error ScummMetaEngine::createInstance(OSystem *syst, Engine **engine) co
// Simply use the first match
DetectorResult res(*(results.begin()));
debug(1, "Using gameid %s, variant %s, extra %s", res.game.gameid, res.game.variant, res.extra);
+ debug(1, " SCUMM version %d, HE version %d", res.game.version, res.game.heversion);
// Print the MD5 of the game; either verbose using printf, in case of an
// unknown MD5, or with a medium debug level in case of a known MD5 (for
Commit: 7773a17b0a1b1e7488490e96cba361ac060c0dd7
https://github.com/scummvm/scummvm/commit/7773a17b0a1b1e7488490e96cba361ac060c0dd7
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:08-07:00
Commit Message:
SCUMM: Unify & extend index block related debug messages
Changed paths:
engines/scumm/he/resource_he.cpp
engines/scumm/resource.cpp
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index f69bf09..dd50271 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -253,8 +253,6 @@ void ScummEngine_v70he::readGlobalObjects() {
#ifdef ENABLE_HE
void ScummEngine_v99he::readMAXS(int blockSize) {
if (blockSize == 52) {
- debug(0, "ScummEngine_v99he readMAXS: MAXS has blocksize %d", blockSize);
-
_numVariables = _fileHandle->readUint16LE();
_fileHandle->readUint16LE();
_numRoomVariables = _fileHandle->readUint16LE();
@@ -287,8 +285,6 @@ void ScummEngine_v99he::readMAXS(int blockSize) {
void ScummEngine_v90he::readMAXS(int blockSize) {
if (blockSize == 46) {
- debug(0, "ScummEngine_v90he readMAXS: MAXS has blocksize %d", blockSize);
-
_numVariables = _fileHandle->readUint16LE();
_fileHandle->readUint16LE();
_numRoomVariables = _fileHandle->readUint16LE();
@@ -321,8 +317,6 @@ void ScummEngine_v90he::readMAXS(int blockSize) {
void ScummEngine_v72he::readMAXS(int blockSize) {
if (blockSize == 40) {
- debug(0, "ScummEngine_v72he readMAXS: MAXS has blocksize %d", blockSize);
-
_numVariables = _fileHandle->readUint16LE();
_fileHandle->readUint16LE();
_numBitVariables = _numRoomVariables = _fileHandle->readUint16LE();
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 164b671..ac238ab 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -164,8 +164,6 @@ void ScummEngine::deleteRoomOffsets() {
/** Read room offsets */
void ScummEngine::readRoomsOffsets() {
- debug(9, "readRoomOffsets()");
-
if (_game.features & GF_SMALL_HEADER) {
_fileHandle->seek(12, SEEK_SET); // Directly searching for the room offset block would be more generic...
} else {
@@ -300,6 +298,7 @@ void ScummEngine::readIndexFile() {
break;
numblock++;
+ debug(2, "Reading index block of type '%s', size %d", tag2str(blocktype), itemsize);
readIndexBlock(blocktype, itemsize);
}
@@ -349,7 +348,6 @@ void ScummEngine_v7::readIndexBlock(uint32 blocktype, uint32 itemsize) {
char *ptr;
switch (blocktype) {
case MKTAG('A','N','A','M'): // Used by: The Dig, FT
- debug(9, "found ANAM block, reading audio names");
num = _fileHandle->readUint16LE();
ptr = (char*)malloc(num * 9);
_fileHandle->read(ptr, num * 9);
@@ -418,7 +416,6 @@ void ScummEngine::readIndexBlock(uint32 blocktype, uint32 itemsize) {
break;
case MKTAG('D','O','B','J'):
- debug(9, "found DOBJ block, reading object table");
readGlobalObjects();
break;
@@ -489,8 +486,6 @@ int ScummEngine::readResTypeList(int id) {
int num;
int i;
- debug(9, "readResTypeList(%s)", resTypeFromId(id));
-
if (_game.version == 8)
num = _fileHandle->readUint32LE();
else
@@ -500,6 +495,9 @@ int ScummEngine::readResTypeList(int id) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
}
+ debug(2, " readResTypeList(%s): %d entries", resTypeFromId(id), num);
+
+
for (i = 0; i < num; i++) {
_res->roomno[id][i] = _fileHandle->readByte();
}
@@ -1066,8 +1064,6 @@ void ResourceManager::resourceStats() {
}
void ScummEngine_v5::readMAXS(int blockSize) {
- debug(9, "ScummEngine_v5 readMAXS: MAXS has blocksize %d", blockSize);
-
_numVariables = _fileHandle->readUint16LE(); // 800
_fileHandle->readUint16LE(); // 16
_numBitVariables = _fileHandle->readUint16LE(); // 2048
@@ -1096,8 +1092,6 @@ void ScummEngine_v5::readMAXS(int blockSize) {
#ifdef ENABLE_SCUMM_7_8
void ScummEngine_v8::readMAXS(int blockSize) {
- debug(9, "ScummEngine_v8 readMAXS: MAXS has blocksize %d", blockSize);
-
_fileHandle->seek(50, SEEK_CUR); // Skip over SCUMM engine version
_fileHandle->seek(50, SEEK_CUR); // Skip over data file version
_numVariables = _fileHandle->readUint32LE(); // 1500
@@ -1126,8 +1120,6 @@ void ScummEngine_v8::readMAXS(int blockSize) {
}
void ScummEngine_v7::readMAXS(int blockSize) {
- debug(9, "ScummEngine_v7 readMAXS: MAXS has blocksize %d", blockSize);
-
_fileHandle->seek(50, SEEK_CUR); // Skip over SCUMM engine version
_fileHandle->seek(50, SEEK_CUR); // Skip over data file version
_numVariables = _fileHandle->readUint16LE();
@@ -1161,8 +1153,6 @@ void ScummEngine_v7::readMAXS(int blockSize) {
void ScummEngine_v6::readMAXS(int blockSize) {
if (blockSize == 38) {
- debug(0, "ScummEngine_v6 readMAXS: MAXS has blocksize %d", blockSize);
-
_numVariables = _fileHandle->readUint16LE();
_fileHandle->readUint16LE();
_numBitVariables = _fileHandle->readUint16LE();
Commit: b37463fe5921420a9081aa6c5cf7588d52b41e78
https://github.com/scummvm/scummvm/commit/b37463fe5921420a9081aa6c5cf7588d52b41e78
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:08-07:00
Commit Message:
SCUMM: Move class ResourceManager to its own header
Changed paths:
engines/scumm/akos.cpp
engines/scumm/boxes.cpp
engines/scumm/debugger.cpp
engines/scumm/detection.cpp
engines/scumm/he/sound_he.cpp
engines/scumm/imuse_digi/dimuse_sndmgr.cpp
engines/scumm/input.cpp
engines/scumm/insane/insane.cpp
engines/scumm/resource.h
engines/scumm/resource_v3.cpp
engines/scumm/script_v0.cpp
engines/scumm/script_v2.cpp
engines/scumm/script_v5.cpp
engines/scumm/scumm.cpp
engines/scumm/scumm.h
engines/scumm/sound.cpp
engines/scumm/string.cpp
diff --git a/engines/scumm/akos.cpp b/engines/scumm/akos.cpp
index 4fe70d3..b6acf01 100644
--- a/engines/scumm/akos.cpp
+++ b/engines/scumm/akos.cpp
@@ -27,6 +27,7 @@
#include "scumm/imuse/imuse.h"
#include "scumm/imuse_digi/dimuse.h"
#include "scumm/he/intern_he.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v7.h"
#include "scumm/sound.h"
#include "scumm/util.h"
diff --git a/engines/scumm/boxes.cpp b/engines/scumm/boxes.cpp
index 5afdce9..ba4dedf 100644
--- a/engines/scumm/boxes.cpp
+++ b/engines/scumm/boxes.cpp
@@ -23,6 +23,7 @@
#include "scumm/scumm.h"
#include "scumm/actor.h"
#include "scumm/boxes.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v6.h"
#include "scumm/util.h"
diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp
index 4d4a6ca..7de8a28 100644
--- a/engines/scumm/debugger.cpp
+++ b/engines/scumm/debugger.cpp
@@ -31,6 +31,7 @@
#include "scumm/debugger.h"
#include "scumm/imuse/imuse.h"
#include "scumm/object.h"
+#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/sound.h"
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index 95f76db..ad1cb3d 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -40,6 +40,7 @@
#include "scumm/scumm_v8.h"
#include "scumm/file.h"
#include "scumm/file_nes.h"
+#include "scumm/resource.h"
#include "engines/metaengine.h"
diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp
index 1f6a144..85a8c02 100644
--- a/engines/scumm/he/sound_he.cpp
+++ b/engines/scumm/he/sound_he.cpp
@@ -23,6 +23,7 @@
#include "scumm/actor.h"
#include "scumm/file.h"
#include "scumm/imuse/imuse.h"
+#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/he/sound_he.h"
#include "scumm/he/intern_he.h"
diff --git a/engines/scumm/imuse_digi/dimuse_sndmgr.cpp b/engines/scumm/imuse_digi/dimuse_sndmgr.cpp
index 9505f3a..abd0d68 100644
--- a/engines/scumm/imuse_digi/dimuse_sndmgr.cpp
+++ b/engines/scumm/imuse_digi/dimuse_sndmgr.cpp
@@ -28,6 +28,7 @@
#include "audio/decoders/vorbis.h"
#include "audio/decoders/mp3.h"
+#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/util.h"
#include "scumm/imuse_digi/dimuse.h"
diff --git a/engines/scumm/input.cpp b/engines/scumm/input.cpp
index e9272a8..1a4ed91 100644
--- a/engines/scumm/input.cpp
+++ b/engines/scumm/input.cpp
@@ -35,6 +35,7 @@
#include "scumm/he/intern_he.h"
#include "scumm/he/logic_he.h"
#endif
+#include "scumm/resource.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v6.h"
#include "scumm/scumm_v8.h"
diff --git a/engines/scumm/insane/insane.cpp b/engines/scumm/insane/insane.cpp
index 309877c..b8089ff 100644
--- a/engines/scumm/insane/insane.cpp
+++ b/engines/scumm/insane/insane.cpp
@@ -28,6 +28,7 @@
#include "scumm/actor.h"
#include "scumm/file.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v7.h"
#include "scumm/sound.h"
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 5cad7fc..32873a1 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -22,6 +22,8 @@
#ifndef SCUMM_RESOURCE_H
#define SCUMM_RESOURCE_H
+#include "scumm/scumm.h" // for rtNumTypes
+
namespace Scumm {
enum {
@@ -41,6 +43,74 @@ public:
const byte *findNext(uint32 tag);
};
+enum {
+ RES_INVALID_OFFSET = 0xFFFFFFFF
+};
+
+class ScummEngine;
+
+/**
+ * The 'resource manager' class. Currently doesn't really deserve to be called
+ * a 'class', at least until somebody gets around to OOfying this more.
+ */
+class ResourceManager {
+ //friend class ScummDebugger;
+ //friend class ScummEngine;
+protected:
+ ScummEngine *_vm;
+
+public:
+ byte mode[rtNumTypes];
+ uint16 num[rtNumTypes];
+ uint32 tags[rtNumTypes];
+ const char *name[rtNumTypes];
+ byte **address[rtNumTypes];
+protected:
+ byte *flags[rtNumTypes];
+ byte *status[rtNumTypes];
+public:
+ byte *roomno[rtNumTypes];
+ uint32 *roomoffs[rtNumTypes];
+ uint32 *globsize[rtNumTypes];
+
+protected:
+ uint32 _allocatedSize;
+ uint32 _maxHeapThreshold, _minHeapThreshold;
+ byte _expireCounter;
+
+public:
+ ResourceManager(ScummEngine *vm);
+ ~ResourceManager();
+
+ void setHeapThreshold(int min, int max);
+
+ void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
+ void freeResources();
+
+ byte *createResource(int type, int index, uint32 size);
+ void nukeResource(int type, int i);
+
+ bool isResourceLoaded(int type, int index) const;
+
+ void lock(int type, int i);
+ void unlock(int type, int i);
+ bool isLocked(int type, int i) const;
+
+ void setModified(int type, int i);
+ bool isModified(int type, int i) const;
+
+ void increaseExpireCounter();
+ void setResourceCounter(int type, int index, byte flag);
+ void increaseResourceCounter();
+
+ void resourceStats();
+
+//protected:
+ bool validateResource(const char *str, int type, int index) const;
+protected:
+ void expireResources(uint32 size);
+};
+
} // End of namespace Scumm
#endif
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index 9ce51be..323e5b6 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -23,6 +23,7 @@
#include "scumm/scumm_v3.h"
#include "scumm/file.h"
+#include "scumm/resource.h"
#include "scumm/util.h"
namespace Scumm {
diff --git a/engines/scumm/script_v0.cpp b/engines/scumm/script_v0.cpp
index aedbc63..1ef16d7 100644
--- a/engines/scumm/script_v0.cpp
+++ b/engines/scumm/script_v0.cpp
@@ -24,6 +24,7 @@
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/object.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v0.h"
#include "scumm/verbs.h"
diff --git a/engines/scumm/script_v2.cpp b/engines/scumm/script_v2.cpp
index ba27151..f7d4e74 100644
--- a/engines/scumm/script_v2.cpp
+++ b/engines/scumm/script_v2.cpp
@@ -23,6 +23,7 @@
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/object.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v2.h"
#include "scumm/sound.h"
#include "scumm/util.h"
diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp
index 9186371..81f28fb 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -23,6 +23,7 @@
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/object.h"
+#include "scumm/resource.h"
#include "scumm/scumm_v3.h"
#include "scumm/scumm_v5.h"
#include "scumm/sound.h"
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index f518754..70d8f0d 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -62,6 +62,7 @@
#include "scumm/player_v2a.h"
#include "scumm/player_v3a.h"
#include "scumm/player_v4a.h"
+#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v8.h"
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index 32f8e75..642db82 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -346,71 +346,7 @@ enum ResTypes {
rtNumTypes = 22
};
-enum {
- RES_INVALID_OFFSET = 0xFFFFFFFF
-};
-
-/**
- * The 'resource manager' class. Currently doesn't really deserve to be called
- * a 'class', at least until somebody gets around to OOfying this more.
- */
-class ResourceManager {
- //friend class ScummDebugger;
- //friend class ScummEngine;
-protected:
- ScummEngine *_vm;
-
-public:
- byte mode[rtNumTypes];
- uint16 num[rtNumTypes];
- uint32 tags[rtNumTypes];
- const char *name[rtNumTypes];
- byte **address[rtNumTypes];
-protected:
- byte *flags[rtNumTypes];
- byte *status[rtNumTypes];
-public:
- byte *roomno[rtNumTypes];
- uint32 *roomoffs[rtNumTypes];
- uint32 *globsize[rtNumTypes];
-
-protected:
- uint32 _allocatedSize;
- uint32 _maxHeapThreshold, _minHeapThreshold;
- byte _expireCounter;
-
-public:
- ResourceManager(ScummEngine *vm);
- ~ResourceManager();
-
- void setHeapThreshold(int min, int max);
-
- void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
- void freeResources();
-
- byte *createResource(int type, int index, uint32 size);
- void nukeResource(int type, int i);
-
- bool isResourceLoaded(int type, int index) const;
-
- void lock(int type, int i);
- void unlock(int type, int i);
- bool isLocked(int type, int i) const;
-
- void setModified(int type, int i);
- bool isModified(int type, int i) const;
-
- void increaseExpireCounter();
- void setResourceCounter(int type, int index, byte flag);
- void increaseResourceCounter();
-
- void resourceStats();
-
-//protected:
- bool validateResource(const char *str, int type, int index) const;
-protected:
- void expireResources(uint32 size);
-};
+class ResourceManager;
/**
* Base class for all SCUMM engines.
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 10eaf54..567cf74 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -29,6 +29,7 @@
#include "scumm/imuse/imuse.h"
#include "scumm/imuse_digi/dimuse.h"
#include "scumm/player_towns.h"
+#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/sound.h"
#include "scumm/util.h"
diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp
index 15ee22c..54826c3 100644
--- a/engines/scumm/string.cpp
+++ b/engines/scumm/string.cpp
@@ -32,6 +32,7 @@
#ifdef ENABLE_HE
#include "scumm/he/intern_he.h"
#endif
+#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/scumm_v6.h"
#include "scumm/scumm_v8.h"
Commit: 45e65d7ea04b10cf7bb5282bd66b8df609700a63
https://github.com/scummvm/scummvm/commit/45e65d7ea04b10cf7bb5282bd66b8df609700a63
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:08-07:00
Commit Message:
SCUMM: Refactor how resource (types) are srepresented
Previously, we had a couple of arrays of size N (where N = number of
resource types), one for each attribute of a resource type (such as as
the number of resources of that type.
Now, we have one array of size N, whose elements are a record
aggregating all the attributes of each resource type.
Changed paths:
engines/scumm/debugger.cpp
engines/scumm/detection.cpp
engines/scumm/he/resource_he.cpp
engines/scumm/he/script_v72he.cpp
engines/scumm/object.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v2.cpp
engines/scumm/resource_v3.cpp
engines/scumm/resource_v4.cpp
engines/scumm/room.cpp
engines/scumm/saveload.cpp
engines/scumm/script.cpp
engines/scumm/script_v6.cpp
engines/scumm/scumm.cpp
engines/scumm/sound.cpp
diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp
index 7de8a28..d404802 100644
--- a/engines/scumm/debugger.cpp
+++ b/engines/scumm/debugger.cpp
@@ -374,8 +374,8 @@ bool ScummDebugger::Cmd_Actor(int argc, const char **argv) {
DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) {
- if (value >= _vm->_res->num[rtCostume])
- DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->num[rtCostume]);
+ if (value >= _vm->_res->_types[rtCostume].num)
+ DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume].num);
else {
a->setActorCostume(value);
_vm->_fullRedraw = true;
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index ad1cb3d..6440228 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -68,7 +68,7 @@ static const MD5Table *findInMD5Table(const char *md5) {
}
Common::String ScummEngine::generateFilename(const int room) const {
- const int diskNumber = (room > 0) ? _res->roomno[rtRoom][room] : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
char buf[128];
if (_game.version == 4) {
@@ -110,7 +110,7 @@ Common::String ScummEngine_v60he::generateFilename(const int room) const {
if (room < 0) {
id = '0' - room;
} else {
- const int diskNumber = (room > 0) ? _res->roomno[rtRoom][room] : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
id = diskNumber + '0';
}
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index dd50271..435e0e5 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -226,7 +226,7 @@ void ScummEngine_v70he::readRoomsOffsets() {
num = READ_LE_UINT16(_heV7RoomOffsets);
ptr = _heV7RoomOffsets + 2;
for (i = 0; i < num; i++) {
- _res->roomoffs[rtRoom][i] = READ_LE_UINT32(ptr);
+ _res->_types[rtRoom].roomoffs[i] = READ_LE_UINT32(ptr);
ptr += 4;
}
}
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 63c97a9..b63feeb 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -621,7 +621,7 @@ void ScummEngine_v72he::o72_getArrayDimSize() {
}
void ScummEngine_v72he::o72_getNumFreeArrays() {
- byte **addr = _res->address[rtString];
+ byte **addr = _res->_types[rtString].address;
int i, num = 0;
for (i = 1; i < _numArray; i++) {
diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp
index 8b4d39a..457e2c7 100644
--- a/engines/scumm/object.cpp
+++ b/engines/scumm/object.cpp
@@ -192,8 +192,8 @@ void ScummEngine::clearOwnerOf(int obj) {
if (!_inventory[i] && _inventory[i+1]) {
_inventory[i] = _inventory[i+1];
_inventory[i+1] = 0;
- _res->address[rtInventory][i] = _res->address[rtInventory][i + 1];
- _res->address[rtInventory][i + 1] = NULL;
+ _res->_types[rtInventory].address[i] = _res->_types[rtInventory].address[i + 1];
+ _res->_types[rtInventory].address[i + 1] = NULL;
}
}
break;
@@ -1796,7 +1796,7 @@ int ScummEngine::findLocalObjectSlot() {
int ScummEngine::findFlObjectSlot() {
int i;
for (i = 1; i < _numFlObject; i++) {
- if (_res->address[rtFlObject][i] == NULL)
+ if (_res->_types[rtFlObject].address[i] == NULL)
return i;
}
error("findFlObjectSlot: Out of FLObject slots");
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index ac238ab..76b6830 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -83,8 +83,8 @@ void ScummEngine::openRoom(const int room) {
// Load the disk numer / room offs (special case for room 0 exists because
// room 0 contains the data which is used to create the roomno / roomoffs
// tables -- hence obviously we mustn't use those when loading room 0.
- const uint32 diskNumber = room ? _res->roomno[rtRoom][room] : 0;
- const uint32 room_offs = room ? _res->roomoffs[rtRoom][room] : 0;
+ const uint32 diskNumber = room ? _res->_types[rtRoom].roomno[room] : 0;
+ const uint32 room_offs = room ? _res->_types[rtRoom].roomoffs[room] : 0;
// FIXME: Since room_offs is const, clearly the following loop either
// is never entered, or loops forever (if it wasn't for the return/error
@@ -94,7 +94,7 @@ void ScummEngine::openRoom(const int room) {
while (room_offs != RES_INVALID_OFFSET) {
if (room_offs != 0 && room != 0 && _game.heversion < 98) {
- _fileOffset = _res->roomoffs[rtRoom][room];
+ _fileOffset = _res->_types[rtRoom].roomoffs[room];
return;
}
@@ -122,7 +122,7 @@ void ScummEngine::openRoom(const int room) {
return;
deleteRoomOffsets();
readRoomsOffsets();
- _fileOffset = _res->roomoffs[rtRoom][room];
+ _fileOffset = _res->_types[rtRoom].roomoffs[room];
if (_fileOffset != 8)
return;
@@ -157,8 +157,8 @@ void ScummEngine::closeRoom() {
/** Delete the currently loaded room offsets. */
void ScummEngine::deleteRoomOffsets() {
for (int i = 0; i < _numRooms; i++) {
- if (_res->roomoffs[rtRoom][i] != RES_INVALID_OFFSET)
- _res->roomoffs[rtRoom][i] = 0;
+ if (_res->_types[rtRoom].roomoffs[i] != RES_INVALID_OFFSET)
+ _res->_types[rtRoom].roomoffs[i] = 0;
}
}
@@ -174,8 +174,8 @@ void ScummEngine::readRoomsOffsets() {
while (num--) {
int room = _fileHandle->readByte();
int offset = _fileHandle->readUint32LE();
- if (_res->roomoffs[rtRoom][room] != RES_INVALID_OFFSET) {
- _res->roomoffs[rtRoom][room] = offset;
+ if (_res->_types[rtRoom].roomoffs[room] != RES_INVALID_OFFSET) {
+ _res->_types[rtRoom].roomoffs[room] = offset;
}
}
}
@@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(int id) {
else
num = _fileHandle->readUint16LE();
- if (num != _res->num[id]) {
+ if (num != _res->_types[id].num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
}
@@ -499,10 +499,10 @@ int ScummEngine::readResTypeList(int id) {
for (i = 0; i < num; i++) {
- _res->roomno[id][i] = _fileHandle->readByte();
+ _res->_types[id].roomno[i] = _fileHandle->readByte();
}
for (i = 0; i < num; i++) {
- _res->roomoffs[id][i] = _fileHandle->readUint32LE();
+ _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
}
return num;
@@ -516,11 +516,11 @@ int ScummEngine_v70he::readResTypeList(int id) {
if (id == rtRoom)
for (i = 0; i < num; i++) {
- _heV7RoomIntOffsets[i] = _res->roomoffs[rtRoom][i];
+ _heV7RoomIntOffsets[i] = _res->_types[rtRoom].roomoffs[i];
}
for (i = 0; i < num; i++) {
- _res->globsize[id][i] = _fileHandle->readUint32LE();
+ _res->_types[id].globsize[i] = _fileHandle->readUint32LE();
}
return num;
@@ -528,26 +528,26 @@ int ScummEngine_v70he::readResTypeList(int id) {
void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) {
debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name_, tag2str(TO_BE_32(tag)), num_, mode_);
- assert(id >= 0 && id < (int)(ARRAYSIZE(this->mode)));
+ assert(id >= 0 && id < (int)(ARRAYSIZE(_types)));
if (num_ >= 8000)
error("Too many %ss (%d) in directory", name_, num_);
- mode[id] = mode_;
- num[id] = num_;
- tags[id] = tag;
- name[id] = name_;
- address[id] = (byte **)calloc(num_, sizeof(void *));
- flags[id] = (byte *)calloc(num_, sizeof(byte));
- status[id] = (byte *)calloc(num_, sizeof(byte));
+ _types[id].mode = mode_;
+ _types[id].num = num_;
+ _types[id].tags = tag;
+ _types[id].name = name_;
+ _types[id].address = (byte **)calloc(num_, sizeof(void *));
+ _types[id].flags = (byte *)calloc(num_, sizeof(byte));
+ _types[id].status = (byte *)calloc(num_, sizeof(byte));
if (mode_) {
- roomno[id] = (byte *)calloc(num_, sizeof(byte));
- roomoffs[id] = (uint32 *)calloc(num_, sizeof(uint32));
+ _types[id].roomno = (byte *)calloc(num_, sizeof(byte));
+ _types[id].roomoffs = (uint32 *)calloc(num_, sizeof(uint32));
}
if (_vm->_game.heversion >= 70) {
- globsize[id] = (uint32 *)calloc(num_, sizeof(uint32));
+ _types[id].globsize = (uint32 *)calloc(num_, sizeof(uint32));
}
}
@@ -606,8 +606,8 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
if (type != rtCharset && i == 0)
return;
- if (i <= _res->num[type])
- addr = _res->address[type][i];
+ if (i <= _res->_types[type].num)
+ addr = _res->_types[type].address[i];
if (addr)
return;
@@ -632,8 +632,8 @@ int ScummEngine::loadResource(int type, int idx) {
roomNr = getResourceRoomNr(type, idx);
- if (idx >= _res->num[type])
- error("%s %d undefined %d %d", _res->name[type], idx, _res->num[type], roomNr);
+ if (idx >= _res->_types[type].num)
+ error("%s %d undefined %d %d", _res->_types[type].name, idx, _res->_types[type].num, roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -669,9 +669,9 @@ int ScummEngine::loadResource(int type, int idx) {
tag = _fileHandle->readUint32BE();
- if (tag != _res->tags[type] && _game.heversion < 70) {
+ if (tag != _res->_types[type].tags && _game.heversion < 70) {
error("%s %d not in room %d at %d+%d in file %s",
- _res->name[type], idx, roomNr,
+ _res->_types[type].name, idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName());
}
@@ -695,21 +695,21 @@ int ScummEngine::loadResource(int type, int idx) {
int ScummEngine::getResourceRoomNr(int type, int idx) {
if (type == rtRoom && _game.heversion < 70)
return idx;
- return _res->roomno[type][idx];
+ return _res->_types[type].roomno[idx];
}
uint32 ScummEngine::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0;
}
- return _res->roomoffs[type][idx];
+ return _res->_types[type].roomoffs[idx];
}
uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return _heV7RoomIntOffsets[idx];
}
- return _res->roomoffs[type][idx];
+ return _res->_types[type].roomoffs[idx];
}
int ScummEngine::getResourceSize(int type, int idx) {
@@ -729,16 +729,16 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
if (!_res->validateResource("getResourceAddress", type, idx))
return NULL;
- if (!_res->address[type]) {
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->address[type] == NULL", resTypeFromId(type), idx);
+ if (!_res->_types[type].address) {
+ debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->_types[type].address == NULL", resTypeFromId(type), idx);
return NULL;
}
- if (_res->mode[type] && !_res->address[type][idx]) {
+ if (_res->_types[type].mode && !_res->_types[type].address[idx]) {
ensureResourceLoaded(type, idx);
}
- if (!(ptr = (byte *)_res->address[type][idx])) {
+ if (!(ptr = (byte *)_res->_types[type].address[idx])) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
}
@@ -777,8 +777,8 @@ void ResourceManager::increaseResourceCounter() {
byte counter;
for (i = rtFirst; i <= rtLast; i++) {
- for (j = num[i]; --j >= 0;) {
- counter = flags[i][j] & RF_USAGE;
+ for (j = _types[i].num; --j >= 0;) {
+ counter = _types[i].flags[j] & RF_USAGE;
if (counter && counter < RF_USAGE_MAX) {
setResourceCounter(i, j, counter + 1);
}
@@ -787,8 +787,8 @@ void ResourceManager::increaseResourceCounter() {
}
void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
- flags[type][idx] &= ~RF_USAGE;
- flags[type][idx] |= flag;
+ _types[type].flags[idx] &= ~RF_USAGE;
+ _types[type].flags[idx] |= flag;
}
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
@@ -805,8 +805,8 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
// cases. For instance, Zak tries to reload the intro music
// while it's playing. See bug #1253171.
- if (address[type][idx] && (type == rtSound || type == rtScript || type == rtCostume))
- return address[type][idx] + sizeof(MemBlkHeader);
+ if (_types[type].address[idx] && (type == rtSound || type == rtScript || type == rtCostume))
+ return _types[type].address[idx] + sizeof(MemBlkHeader);
}
nukeResource(type, idx);
@@ -820,7 +820,7 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
_allocatedSize += size;
- address[type][idx] = (byte *)ptr;
+ _types[type].address[idx] = (byte *)ptr;
((MemBlkHeader *)ptr)->size = size;
setResourceCounter(type, idx, 1);
return (byte *)ptr + sizeof(MemBlkHeader); /* skip header */
@@ -844,7 +844,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
}
bool ResourceManager::validateResource(const char *str, int type, int idx) const {
- if (type < rtFirst || type > rtLast || (uint) idx >= (uint)num[type]) {
+ if (type < rtFirst || type > rtLast || (uint) idx >= (uint)_types[type].num) {
error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
return false;
}
@@ -854,17 +854,17 @@ bool ResourceManager::validateResource(const char *str, int type, int idx) const
void ResourceManager::nukeResource(int type, int idx) {
byte *ptr;
- if (!address[type])
+ if (!_types[type].address)
return;
- assert(idx >= 0 && idx < num[type]);
+ assert(idx >= 0 && idx < _types[type].num);
- ptr = address[type][idx];
+ ptr = _types[type].address[idx];
if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
- address[type][idx] = 0;
- flags[type][idx] = 0;
- status[type][idx] &= ~RS_MODIFIED;
+ _types[type].address[idx] = 0;
+ _types[type].flags[idx] = 0;
+ _types[type].status[idx] &= ~RS_MODIFIED;
_allocatedSize -= ((MemBlkHeader *)ptr)->size;
free(ptr);
}
@@ -898,19 +898,19 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
void ResourceManager::lock(int type, int i) {
if (!validateResource("Locking", type, i))
return;
- flags[type][i] |= RF_LOCK;
+ _types[type].flags[i] |= RF_LOCK;
}
void ResourceManager::unlock(int type, int i) {
if (!validateResource("Unlocking", type, i))
return;
- flags[type][i] &= ~RF_LOCK;
+ _types[type].flags[i] &= ~RF_LOCK;
}
bool ResourceManager::isLocked(int type, int i) const {
if (!validateResource("isLocked", type, i))
return false;
- return (flags[type][i] & RF_LOCK) != 0;
+ return (_types[type].flags[i] & RF_LOCK) != 0;
}
bool ScummEngine::isResourceInUse(int type, int i) const {
@@ -947,13 +947,13 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
void ResourceManager::setModified(int type, int i) {
if (!validateResource("Modified", type, i))
return;
- status[type][i] |= RS_MODIFIED;
+ _types[type].status[i] |= RS_MODIFIED;
}
bool ResourceManager::isModified(int type, int i) const {
if (!validateResource("isModified", type, i))
return false;
- return (status[type][i] & RS_MODIFIED) != 0;
+ return (_types[type].status[i] & RS_MODIFIED) != 0;
}
void ResourceManager::expireResources(uint32 size) {
@@ -978,10 +978,10 @@ void ResourceManager::expireResources(uint32 size) {
best_counter = 2;
for (i = rtFirst; i <= rtLast; i++)
- if (mode[i]) {
- for (j = num[i]; --j >= 0;) {
- flag = flags[i][j];
- if (!(flag & RF_LOCK) && flag >= best_counter && address[i][j] && !_vm->isResourceInUse(i, j)) {
+ if (_types[i].mode) {
+ for (j = _types[i].num; --j >= 0;) {
+ flag = _types[i].flags[j];
+ if (!(flag & RF_LOCK) && flag >= best_counter && _types[i].address[j] && !_vm->isResourceInUse(i, j)) {
best_counter = flag;
best_type = i;
best_res = j;
@@ -1002,17 +1002,17 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() {
int i, j;
for (i = rtFirst; i <= rtLast; i++) {
- for (j = num[i]; --j >= 0;) {
+ for (j = _types[i].num; --j >= 0;) {
if (isResourceLoaded(i, j))
nukeResource(i, j);
}
- free(address[i]);
- free(flags[i]);
- free(status[i]);
- free(roomno[i]);
- free(roomoffs[i]);
+ free(_types[i].address);
+ free(_types[i].flags);
+ free(_types[i].status);
+ free(_types[i].roomno);
+ free(_types[i].roomoffs);
- free(globsize[i]);
+ free(_types[i].globsize);
}
}
@@ -1043,7 +1043,7 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
bool ResourceManager::isResourceLoaded(int type, int idx) const {
if (!validateResource("isResourceLoaded", type, idx))
return false;
- return address[type][idx] != NULL;
+ return _types[type].address[idx] != NULL;
}
void ResourceManager::resourceStats() {
@@ -1052,10 +1052,10 @@ void ResourceManager::resourceStats() {
byte flag;
for (i = rtFirst; i <= rtLast; i++)
- for (j = num[i]; --j >= 0;) {
- flag = flags[i][j];
- if (flag & RF_LOCK && address[i][j]) {
- lockedSize += ((MemBlkHeader *)address[i][j])->size;
+ for (j = _types[i].num; --j >= 0;) {
+ flag = _types[i].flags[j];
+ if (flag & RF_LOCK && _types[i].address[j]) {
+ lockedSize += ((MemBlkHeader *)_types[i].roomoffs[j])->size;
lockedNum++;
}
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 32873a1..b3cb424 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -60,18 +60,23 @@ protected:
ScummEngine *_vm;
public:
- byte mode[rtNumTypes];
- uint16 num[rtNumTypes];
- uint32 tags[rtNumTypes];
- const char *name[rtNumTypes];
- byte **address[rtNumTypes];
-protected:
- byte *flags[rtNumTypes];
- byte *status[rtNumTypes];
-public:
- byte *roomno[rtNumTypes];
- uint32 *roomoffs[rtNumTypes];
- uint32 *globsize[rtNumTypes];
+ class ResTypeData {
+ friend class ResourceManager;
+ public:
+ byte mode;
+ uint16 num;
+ uint32 tags;
+ const char *name;
+ byte **address;
+ protected:
+ byte *flags;
+ byte *status;
+ public:
+ byte *roomno;
+ uint32 *roomoffs;
+ uint32 *globsize;
+ };
+ ResTypeData _types[rtNumTypes];
protected:
uint32 _allocatedSize;
diff --git a/engines/scumm/resource_v2.cpp b/engines/scumm/resource_v2.cpp
index c183a0e..f869248 100644
--- a/engines/scumm/resource_v2.cpp
+++ b/engines/scumm/resource_v2.cpp
@@ -84,40 +84,40 @@ void ScummEngine_v2::readClassicIndexFile() {
}
for (i = 0; i < _numRooms; i++) {
- _res->roomno[rtRoom][i] = i;
+ _res->_types[rtRoom].roomno[i] = i;
}
_fileHandle->seek(_numRooms, SEEK_CUR);
for (i = 0; i < _numRooms; i++) {
- _res->roomoffs[rtRoom][i] = _fileHandle->readUint16LE();
- if (_res->roomoffs[rtRoom][i] == 0xFFFF)
- _res->roomoffs[rtRoom][i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtRoom].roomoffs[i] = _fileHandle->readUint16LE();
+ if (_res->_types[rtRoom].roomoffs[i] == 0xFFFF)
+ _res->_types[rtRoom].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numCostumes; i++) {
- _res->roomno[rtCostume][i] = _fileHandle->readByte();
+ _res->_types[rtCostume].roomno[i] = _fileHandle->readByte();
}
for (i = 0; i < _numCostumes; i++) {
- _res->roomoffs[rtCostume][i] = _fileHandle->readUint16LE();
- if (_res->roomoffs[rtCostume][i] == 0xFFFF)
- _res->roomoffs[rtCostume][i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtCostume].roomoffs[i] = _fileHandle->readUint16LE();
+ if (_res->_types[rtCostume].roomoffs[i] == 0xFFFF)
+ _res->_types[rtCostume].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numScripts; i++) {
- _res->roomno[rtScript][i] = _fileHandle->readByte();
+ _res->_types[rtScript].roomno[i] = _fileHandle->readByte();
}
for (i = 0; i < _numScripts; i++) {
- _res->roomoffs[rtScript][i] = _fileHandle->readUint16LE();
- if (_res->roomoffs[rtScript][i] == 0xFFFF)
- _res->roomoffs[rtScript][i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtScript].roomoffs[i] = _fileHandle->readUint16LE();
+ if (_res->_types[rtScript].roomoffs[i] == 0xFFFF)
+ _res->_types[rtScript].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numSounds; i++) {
- _res->roomno[rtSound][i] = _fileHandle->readByte();
+ _res->_types[rtSound].roomno[i] = _fileHandle->readByte();
}
for (i = 0; i < _numSounds; i++) {
- _res->roomoffs[rtSound][i] = _fileHandle->readUint16LE();
- if (_res->roomoffs[rtSound][i] == 0xFFFF)
- _res->roomoffs[rtSound][i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtSound].roomoffs[i] = _fileHandle->readUint16LE();
+ if (_res->_types[rtSound].roomoffs[i] == 0xFFFF)
+ _res->_types[rtSound].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
}
}
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index 323e5b6..3a8b1dd 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -44,16 +44,16 @@ int ScummEngine_v3old::readResTypeList(int id) {
if (id == rtRoom) {
for (i = 0; i < num; i++)
- _res->roomno[id][i] = i;
+ _res->_types[id].roomno[i] = i;
_fileHandle->seek(num, SEEK_CUR);
} else {
for (i = 0; i < num; i++)
- _res->roomno[id][i] = _fileHandle->readByte();
+ _res->_types[id].roomno[i] = _fileHandle->readByte();
}
for (i = 0; i < num; i++) {
- _res->roomoffs[id][i] = _fileHandle->readUint16LE();
- if (_res->roomoffs[id][i] == 0xFFFF)
- _res->roomoffs[id][i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[id].roomoffs[i] = _fileHandle->readUint16LE();
+ if (_res->_types[id].roomoffs[i] == 0xFFFF)
+ _res->_types[id].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
}
return num;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index a3a2786..8fc2762 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -38,13 +38,13 @@ int ScummEngine_v4::readResTypeList(int id) {
num = _fileHandle->readUint16LE();
- if (num != _res->num[id]) {
+ if (num != _res->_types[id].num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
}
for (i = 0; i < num; i++) {
- _res->roomno[id][i] = _fileHandle->readByte();
- _res->roomoffs[id][i] = _fileHandle->readUint32LE();
+ _res->_types[id].roomno[i] = _fileHandle->readByte();
+ _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
}
return num;
diff --git a/engines/scumm/room.cpp b/engines/scumm/room.cpp
index f672798..7e0f70e 100644
--- a/engines/scumm/room.cpp
+++ b/engines/scumm/room.cpp
@@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
//
// Load scale data
//
- for (i = 1; i < _res->num[rtScaleTable]; i++)
+ for (i = 1; i < _res->_types[rtScaleTable].num; i++)
_res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) {
int s1, s2, y1, y2;
if (_game.version == 8) {
- for (i = 1; i < _res->num[rtScaleTable]; i++, ptr += 16) {
+ for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8);
@@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2);
}
} else {
- for (i = 1; i < _res->num[rtScaleTable]; i++, ptr += 8) {
+ for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4);
@@ -794,7 +794,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
//
// No scale data in old bundle games
//
- for (i = 1; i < _res->num[rtScaleTable]; i++)
+ for (i = 1; i < _res->_types[rtScaleTable].num; i++)
_res->nukeResource(rtScaleTable, i);
}
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index be90ba2..424e000 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -428,7 +428,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// Nuke all resources
for (i = rtFirst; i <= rtLast; i++)
if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat))
- for (j = 0; j < _res->num[i]; j++) {
+ for (j = 0; j < _res->_types[i].num; j++) {
_res->nukeResource(i, j);
}
@@ -517,7 +517,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items
- for (i = 1; i < _res->num[rtScaleTable]; i++) {
+ for (i = 1; i < _res->_types[rtScaleTable].num; i++) {
convertScaleTableToScaleSlot(i);
}
}
@@ -1243,11 +1243,11 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// number of script resources, savegames won't break.
if (s->isSaving()) {
for (type = rtFirst; type <= rtLast; type++) {
- if (_res->mode[type] != 1 && type != rtTemp && type != rtBuffer) {
+ if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
- for (idx = 0; idx < _res->num[type]; idx++) {
+ for (idx = 0; idx < _res->_types[type].num; idx++) {
// Only save resources which actually exist...
- if (_res->address[type][idx]) {
+ if (_res->_types[type].address[idx]) {
s->saveUint16(idx); // Save the index of the resource
saveResource(s, type, idx);
}
@@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
} else {
while ((type = s->loadUint16()) != 0xFFFF) {
while ((idx = s->loadUint16()) != 0xFFFF) {
- assert(0 <= idx && idx < _res->num[type]);
+ assert(0 <= idx && idx < _res->_types[type].num);
loadResource(s, type, idx);
}
}
@@ -1269,13 +1269,13 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// with index 0, and breaks whenever we change the limit on a given
// resource type.
for (type = rtFirst; type <= rtLast; type++)
- if (_res->mode[type] != 1 && type != rtTemp && type != rtBuffer) {
+ if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) {
// For V1-V5 games, there used to be no object name resources.
// At some point this changed. But since old savegames rely on
// unchanged resource counts, we have to hard code the following check
if (_game.version < 6 && type == rtObjectName)
continue;
- for (idx = 1; idx < _res->num[type]; idx++)
+ for (idx = 1; idx < _res->_types[type].num; idx++)
saveLoadResource(s, type, idx);
}
}
@@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
//
if (s->isSaving()) {
for (i = rtFirst; i <= rtLast; i++)
- for (j = 1; j < _res->num[i]; j++) {
+ for (j = 1; j < _res->_types[i].num; j++) {
if (_res->isLocked(i, j)) {
s->saveByte(i);
s->saveUint16(j);
@@ -1637,9 +1637,9 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
byte *ptr;
uint32 size;
- if (!_res->mode[type]) {
+ if (!_res->_types[type].mode) {
if (ser->isSaving()) {
- ptr = _res->address[type][idx];
+ ptr = _res->_types[type].address[idx];
if (ptr == NULL) {
ser->saveUint32(0);
return;
@@ -1676,10 +1676,10 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
}
}
}
- } else if (_res->mode[type] == 2 && ser->getVersion() >= VER(23)) {
+ } else if (_res->_types[type].mode == 2 && ser->getVersion() >= VER(23)) {
// Save/load only a list of resource numbers that need to be reloaded.
if (ser->isSaving()) {
- ser->saveUint16(_res->address[type][idx] ? 1 : 0);
+ ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0);
} else {
if (ser->loadUint16())
ensureResourceLoaded(type, idx);
@@ -1688,10 +1688,10 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
}
void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
- assert(_res->address[type][idx]);
+ assert(_res->_types[type].address[idx]);
- if (_res->mode[type] == 0) {
- byte *ptr = _res->address[type][idx];
+ if (_res->_types[type].mode == 0) {
+ byte *ptr = _res->_types[type].address[idx];
uint32 size = ((MemBlkHeader *)ptr)->size;
ser->saveUint32(size);
@@ -1713,7 +1713,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
assert(size);
_res->createResource(type, idx, size);
ser->loadBytes(getResourceAddress(type, idx), size);
- } else if (_res->mode[type] == 0) {
+ } else if (_res->_types[type].mode == 0) {
uint32 size = ser->loadUint32();
assert(size);
_res->createResource(type, idx, size);
@@ -1725,7 +1725,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
if (type == rtObjectName) {
_newNames[idx] = ser->loadUint16();
}
- } else if (_res->mode[type] == 2) {
+ } else if (_res->_types[type].mode == 2) {
// HE Games use sound resource 1 for speech
if (_game.heversion >= 60 && idx == 1)
return;
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index ae48139..4630ec1 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -390,26 +390,26 @@ void ScummEngine::getScriptBaseAddress() {
break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory);
- _lastCodePtr = &_res->address[rtInventory][idx];
+ _lastCodePtr = &_res->_types[rtInventory].address[idx];
break;
case WIO_LOCAL:
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
- assert(_roomResource < _res->num[rtRoomScripts]);
- _lastCodePtr = &_res->address[rtRoomScripts][_roomResource];
+ assert(_roomResource < _res->_types[rtRoomScripts].num);
+ _lastCodePtr = &_res->_types[rtRoomScripts].address[_roomResource];
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms);
- _lastCodePtr = &_res->address[rtRoom][_roomResource];
+ _lastCodePtr = &_res->_types[rtRoom].address[_roomResource];
}
break;
case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts);
- _lastCodePtr = &_res->address[rtScript][ss->number];
+ _lastCodePtr = &_res->_types[rtScript].address[ss->number];
break;
case WIO_FLOBJECT: /* flobject script */
@@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject);
- _lastCodePtr = &_res->address[rtFlObject][idx];
+ _lastCodePtr = &_res->_types[rtFlObject].address[idx];
break;
default:
error("Bad type while getting base address");
@@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
- if (_res->num[rtScript] > 460) {
+ if (_res->_types[rtScript].num > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index c5fa245..afc1eb6 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -357,7 +357,7 @@ void ScummEngine_v6::nukeArray(int a) {
}
int ScummEngine_v6::findFreeArrayId() {
- byte **addr = _res->address[rtString];
+ byte **addr = _res->_types[rtString].address;
int i;
for (i = 1; i < _numArray; i++) {
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 70d8f0d..d5c2b2e 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1185,7 +1185,7 @@ Common::Error ScummEngine::init() {
resetScummVars();
if (_imuse) {
- _imuse->setBase(_res->address[rtSound]);
+ _imuse->setBase(_res->_types[rtSound].address);
}
if (_game.version >= 5 && _game.version <= 7)
@@ -2462,7 +2462,7 @@ void ScummEngine::restart() {
resetScummVars();
if (_imuse) {
- _imuse->setBase(_res->address[rtSound]);
+ _imuse->setBase(_res->_types[rtSound].address);
}
// Reinit sound engine
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 567cf74..f5068e7 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -1224,7 +1224,7 @@ int ScummEngine::readSoundResource(int idx) {
if (!dmuFile.open(buffer)) {
error("Can't open music file %s", buffer);
- _res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0;
}
dmuFile.seek(4, SEEK_SET);
@@ -1248,7 +1248,7 @@ int ScummEngine::readSoundResource(int idx) {
}
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
}
- _res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0;
}
@@ -2123,7 +2123,7 @@ int ScummEngine::readSoundResourceSmallHeader(int idx) {
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
return 1;
}
- _res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0;
}
Commit: 26efa39d2caa0b6bb7da8414382eb5643c108261
https://github.com/scummvm/scummvm/commit/26efa39d2caa0b6bb7da8414382eb5643c108261
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:09-07:00
Commit Message:
SCUMM: Document and cleanup resource type mode
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/saveload.cpp
engines/scumm/scumm.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 76b6830..7f88def 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -526,28 +526,28 @@ int ScummEngine_v70he::readResTypeList(int id) {
return num;
}
-void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) {
- debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name_, tag2str(TO_BE_32(tag)), num_, mode_);
+void ResourceManager::allocResTypeData(int id, uint32 tag, int num, const char *name, ResTypeMode mode) {
+ debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name, tag2str(TO_BE_32(tag)), num, mode);
assert(id >= 0 && id < (int)(ARRAYSIZE(_types)));
- if (num_ >= 8000)
- error("Too many %ss (%d) in directory", name_, num_);
+ if (num >= 8000)
+ error("Too many %ss (%d) in directory", name, num);
- _types[id].mode = mode_;
- _types[id].num = num_;
- _types[id].tags = tag;
- _types[id].name = name_;
- _types[id].address = (byte **)calloc(num_, sizeof(void *));
- _types[id].flags = (byte *)calloc(num_, sizeof(byte));
- _types[id].status = (byte *)calloc(num_, sizeof(byte));
+ _types[id]._mode = mode;
+ _types[id].num = num;
+ _types[id].tag = tag;
+ _types[id].name = name;
+ _types[id].address = (byte **)calloc(num, sizeof(void *));
+ _types[id].flags = (byte *)calloc(num, sizeof(byte));
+ _types[id].status = (byte *)calloc(num, sizeof(byte));
- if (mode_) {
- _types[id].roomno = (byte *)calloc(num_, sizeof(byte));
- _types[id].roomoffs = (uint32 *)calloc(num_, sizeof(uint32));
+ if (mode) {
+ _types[id].roomno = (byte *)calloc(num, sizeof(byte));
+ _types[id].roomoffs = (uint32 *)calloc(num, sizeof(uint32));
}
if (_vm->_game.heversion >= 70) {
- _types[id].globsize = (uint32 *)calloc(num_, sizeof(uint32));
+ _types[id].globsize = (uint32 *)calloc(num, sizeof(uint32));
}
}
@@ -669,7 +669,7 @@ int ScummEngine::loadResource(int type, int idx) {
tag = _fileHandle->readUint32BE();
- if (tag != _res->_types[type].tags && _game.heversion < 70) {
+ if (tag != _res->_types[type].tag && _game.heversion < 70) {
error("%s %d not in room %d at %d+%d in file %s",
_res->_types[type].name, idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName());
@@ -734,11 +734,13 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
return NULL;
}
- if (_res->_types[type].mode && !_res->_types[type].address[idx]) {
+ // If the resource is missing, but loadable from the game data files, try to do so.
+ if (!_res->_types[type].address[idx] && _res->_types[type]._mode != kDynamicResTypeMode) {
ensureResourceLoaded(type, idx);
}
- if (!(ptr = (byte *)_res->_types[type].address[idx])) {
+ ptr = (byte *)_res->_types[type].address[idx];
+ if (!ptr) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
}
@@ -978,7 +980,9 @@ void ResourceManager::expireResources(uint32 size) {
best_counter = 2;
for (i = rtFirst; i <= rtLast; i++)
- if (_types[i].mode) {
+ if (_types[i]._mode != kDynamicResTypeMode) {
+ // Resources of this type can be reloaded from the data files,
+ // so we can potentially unload them to free memory.
for (j = _types[i].num; --j >= 0;) {
flag = _types[i].flags[j];
if (!(flag & RF_LOCK) && flag >= best_counter && _types[i].address[j] && !_vm->isResourceInUse(i, j)) {
@@ -1275,30 +1279,30 @@ void ScummEngine::allocateArrays() {
}
_res->allocResTypeData(rtCostume, (_game.features & GF_NEW_COSTUMES) ? MKTAG('A','K','O','S') : MKTAG('C','O','S','T'),
- _numCostumes, "costume", 1);
- _res->allocResTypeData(rtRoom, MKTAG('R','O','O','M'), _numRooms, "room", 1);
- _res->allocResTypeData(rtRoomImage, MKTAG('R','M','I','M'), _numRooms, "room image", 1);
- _res->allocResTypeData(rtRoomScripts, MKTAG('R','M','S','C'), _numRooms, "room script", 1);
- _res->allocResTypeData(rtSound, MKTAG('S','O','U','N'), _numSounds, "sound", 2);
- _res->allocResTypeData(rtScript, MKTAG('S','C','R','P'), _numScripts, "script", 1);
- _res->allocResTypeData(rtCharset, MKTAG('C','H','A','R'), _numCharsets, "charset", 1);
- _res->allocResTypeData(rtObjectName, 0, _numNewNames, "new name", 0);
- _res->allocResTypeData(rtInventory, 0, _numInventory, "inventory", 0);
- _res->allocResTypeData(rtTemp, 0, 10, "temp", 0);
- _res->allocResTypeData(rtScaleTable, 0, 5, "scale table", 0);
- _res->allocResTypeData(rtActorName, 0, _numActors, "actor name", 0);
- _res->allocResTypeData(rtVerb, 0, _numVerbs, "verb", 0);
- _res->allocResTypeData(rtString, 0, _numArray, "array", 0);
- _res->allocResTypeData(rtFlObject, 0, _numFlObject, "flobject", 0);
- _res->allocResTypeData(rtMatrix, 0, 10, "boxes", 0);
- _res->allocResTypeData(rtImage, MKTAG('A','W','I','Z'), _numImages, "images", 1);
- _res->allocResTypeData(rtTalkie, MKTAG('T','L','K','E'), _numTalkies, "talkie", 1);
+ _numCostumes, "costume", kStaticResTypeMode);
+ _res->allocResTypeData(rtRoom, MKTAG('R','O','O','M'), _numRooms, "room", kStaticResTypeMode);
+ _res->allocResTypeData(rtRoomImage, MKTAG('R','M','I','M'), _numRooms, "room image", kStaticResTypeMode);
+ _res->allocResTypeData(rtRoomScripts, MKTAG('R','M','S','C'), _numRooms, "room script", kStaticResTypeMode);
+ _res->allocResTypeData(rtSound, MKTAG('S','O','U','N'), _numSounds, "sound", kSoundResTypeMode);
+ _res->allocResTypeData(rtScript, MKTAG('S','C','R','P'), _numScripts, "script", kStaticResTypeMode);
+ _res->allocResTypeData(rtCharset, MKTAG('C','H','A','R'), _numCharsets, "charset", kStaticResTypeMode);
+ _res->allocResTypeData(rtObjectName, 0, _numNewNames, "new name", kDynamicResTypeMode);
+ _res->allocResTypeData(rtInventory, 0, _numInventory, "inventory", kDynamicResTypeMode);
+ _res->allocResTypeData(rtTemp, 0, 10, "temp", kDynamicResTypeMode);
+ _res->allocResTypeData(rtScaleTable, 0, 5, "scale table", kDynamicResTypeMode);
+ _res->allocResTypeData(rtActorName, 0, _numActors, "actor name", kDynamicResTypeMode);
+ _res->allocResTypeData(rtVerb, 0, _numVerbs, "verb", kDynamicResTypeMode);
+ _res->allocResTypeData(rtString, 0, _numArray, "array", kDynamicResTypeMode);
+ _res->allocResTypeData(rtFlObject, 0, _numFlObject, "flobject", kDynamicResTypeMode);
+ _res->allocResTypeData(rtMatrix, 0, 10, "boxes", kDynamicResTypeMode);
+ _res->allocResTypeData(rtImage, MKTAG('A','W','I','Z'), _numImages, "images", kStaticResTypeMode);
+ _res->allocResTypeData(rtTalkie, MKTAG('T','L','K','E'), _numTalkies, "talkie", kStaticResTypeMode);
}
void ScummEngine_v70he::allocateArrays() {
ScummEngine::allocateArrays();
- _res->allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", 1);
+ _res->allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", kStaticResTypeMode);
_heV7RoomIntOffsets = (uint32 *)calloc(_numRooms, sizeof(uint32));
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index b3cb424..8540ef3 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -50,6 +50,24 @@ enum {
class ScummEngine;
/**
+ * The mode of a resource type indicates whether the resource can be restored
+ * from the game data files or not.
+ * This affects for example whether the resource is stored in savestates.
+ *
+ * Note that we treat sound resources somewhat differently: On the one hand,
+ * these behave mostly like a kStaticResTypeMode res type. However, when we
+ * create a savestate, we do save *some* information about them: Namely, which
+ * sound resources are loaded in memory at the time the save is made. And when
+ * loading, we invoke ensureResourceLoaded() for each sound resource that was
+ * marked in this way.
+ */
+enum ResTypeMode {
+ kDynamicResTypeMode = 0, ///!< Resource is generated during runtime and may change
+ kStaticResTypeMode = 1, ///!< Resource comes from data files, does not change
+ kSoundResTypeMode = 2 ///!< Resource comes from data files, but may change
+};
+
+/**
* The 'resource manager' class. Currently doesn't really deserve to be called
* a 'class', at least until somebody gets around to OOfying this more.
*/
@@ -60,12 +78,15 @@ protected:
ScummEngine *_vm;
public:
+ /**
+ * This struct represents a resource type and all resource of that type.
+ */
class ResTypeData {
friend class ResourceManager;
public:
- byte mode;
+ ResTypeMode _mode;
uint16 num;
- uint32 tags;
+ uint32 tag;
const char *name;
byte **address;
protected:
@@ -89,7 +110,7 @@ public:
void setHeapThreshold(int min, int max);
- void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
+ void allocResTypeData(int id, uint32 tag, int num, const char *name, ResTypeMode mode);
void freeResources();
byte *createResource(int type, int index, uint32 size);
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 424e000..40dc70a 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -1243,7 +1243,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// number of script resources, savegames won't break.
if (s->isSaving()) {
for (type = rtFirst; type <= rtLast; type++) {
- if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) {
+ if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
for (idx = 0; idx < _res->_types[type].num; idx++) {
// Only save resources which actually exist...
@@ -1269,7 +1269,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// with index 0, and breaks whenever we change the limit on a given
// resource type.
for (type = rtFirst; type <= rtLast; type++)
- if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) {
+ if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
// For V1-V5 games, there used to be no object name resources.
// At some point this changed. But since old savegames rely on
// unchanged resource counts, we have to hard code the following check
@@ -1637,7 +1637,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
byte *ptr;
uint32 size;
- if (!_res->_types[type].mode) {
+ if (_res->_types[type]._mode == kDynamicResTypeMode) {
if (ser->isSaving()) {
ptr = _res->_types[type].address[idx];
if (ptr == NULL) {
@@ -1676,7 +1676,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
}
}
}
- } else if (_res->_types[type].mode == 2 && ser->getVersion() >= VER(23)) {
+ } else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) {
// Save/load only a list of resource numbers that need to be reloaded.
if (ser->isSaving()) {
ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0);
@@ -1690,7 +1690,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
assert(_res->_types[type].address[idx]);
- if (_res->_types[type].mode == 0) {
+ if (_res->_types[type]._mode == kDynamicResTypeMode) {
byte *ptr = _res->_types[type].address[idx];
uint32 size = ((MemBlkHeader *)ptr)->size;
@@ -1713,7 +1713,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
assert(size);
_res->createResource(type, idx, size);
ser->loadBytes(getResourceAddress(type, idx), size);
- } else if (_res->_types[type].mode == 0) {
+ } else if (_res->_types[type]._mode == kDynamicResTypeMode) {
uint32 size = ser->loadUint32();
assert(size);
_res->createResource(type, idx, size);
@@ -1725,7 +1725,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
if (type == rtObjectName) {
_newNames[idx] = ser->loadUint16();
}
- } else if (_res->_types[type].mode == 2) {
+ } else if (_res->_types[type]._mode == kSoundResTypeMode) {
// HE Games use sound resource 1 for speech
if (_game.heversion >= 60 && idx == 1)
return;
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index d5c2b2e..e891006 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1233,7 +1233,7 @@ void ScummEngine::setupScumm() {
requestLoad(ConfMan.getInt("save_slot"));
}
- _res->allocResTypeData(rtBuffer, 0, 10, "buffer", 0);
+ _res->allocResTypeData(rtBuffer, 0, 10, "buffer", kDynamicResTypeMode);
setupScummVars();
Commit: 7be0305da9998568c9ac2538ab8c0ab4ca507bf1
https://github.com/scummvm/scummvm/commit/7be0305da9998568c9ac2538ab8c0ab4ca507bf1
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:09-07:00
Commit Message:
SCUMM: Rename saveLoadResource to loadResourceOLD, remove unused save code in it
Changed paths:
engines/scumm/saveload.cpp
engines/scumm/scumm.h
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 40dc70a..cd48fee 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -1276,7 +1276,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
if (_game.version < 6 && type == rtObjectName)
continue;
for (idx = 1; idx < _res->_types[type].num; idx++)
- saveLoadResource(s, type, idx);
+ loadResourceOLD(s, type, idx);
}
}
@@ -1633,57 +1633,32 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) {
}
#endif
-void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
- byte *ptr;
+void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
uint32 size;
if (_res->_types[type]._mode == kDynamicResTypeMode) {
- if (ser->isSaving()) {
- ptr = _res->_types[type].address[idx];
- if (ptr == NULL) {
- ser->saveUint32(0);
- return;
- }
-
- size = ((MemBlkHeader *)ptr)->size;
-
- ser->saveUint32(size);
- ser->saveBytes(ptr + sizeof(MemBlkHeader), size);
-
+ size = ser->loadUint32();
+ if (size) {
+ _res->createResource(type, idx, size);
+ ser->loadBytes(getResourceAddress(type, idx), size);
if (type == rtInventory) {
- ser->saveUint16(_inventory[idx]);
+ _inventory[idx] = ser->loadUint16();
}
if (type == rtObjectName && ser->getVersion() >= VER(25)) {
- ser->saveUint16(_newNames[idx]);
- }
- } else {
- size = ser->loadUint32();
- if (size) {
- _res->createResource(type, idx, size);
- ser->loadBytes(getResourceAddress(type, idx), size);
- if (type == rtInventory) {
- _inventory[idx] = ser->loadUint16();
- }
- if (type == rtObjectName && ser->getVersion() >= VER(25)) {
- // Paranoia: We increased the possible number of new names
- // to fix bugs #933610 and #936323. The savegame format
- // didn't change, but at least during the transition
- // period there is a slight chance that we try to load
- // more names than we have allocated space for. If so,
- // discard them.
- if (idx < _numNewNames)
- _newNames[idx] = ser->loadUint16();
- }
+ // Paranoia: We increased the possible number of new names
+ // to fix bugs #933610 and #936323. The savegame format
+ // didn't change, but at least during the transition
+ // period there is a slight chance that we try to load
+ // more names than we have allocated space for. If so,
+ // discard them.
+ if (idx < _numNewNames)
+ _newNames[idx] = ser->loadUint16();
}
}
} else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) {
// Save/load only a list of resource numbers that need to be reloaded.
- if (ser->isSaving()) {
- ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0);
- } else {
- if (ser->loadUint16())
- ensureResourceLoaded(type, idx);
- }
+ if (ser->loadUint16())
+ ensureResourceLoaded(type, idx);
}
}
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index 642db82..768c976 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -587,9 +587,9 @@ protected:
bool saveState(int slot, bool compat);
bool loadState(int slot, bool compat);
virtual void saveOrLoad(Serializer *s);
- void saveLoadResource(Serializer *ser, int type, int index); // "Obsolete"
void saveResource(Serializer *ser, int type, int index);
void loadResource(Serializer *ser, int type, int index);
+ void loadResourceOLD(Serializer *ser, int type, int index); // "Obsolete"
Common::String makeSavegameName(int slot, bool temporary) const {
return makeSavegameName(_targetName, slot, temporary);
Commit: 0af2f71c71e39df2d61dd7cc9faed7c5e6a50fab
https://github.com/scummvm/scummvm/commit/0af2f71c71e39df2d61dd7cc9faed7c5e6a50fab
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:10-07:00
Commit Message:
SCUMM: Clean up ResourceManager initialization
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource.h
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 7f88def..a00630f 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -828,10 +828,18 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
return (byte *)ptr + sizeof(MemBlkHeader); /* skip header */
}
-ResourceManager::ResourceManager(ScummEngine *vm) {
- memset(this, 0, sizeof(ResourceManager));
- _vm = vm;
-// _allocatedSize = 0;
+ResourceManager::ResTypeData::ResTypeData() {
+ memset(this, 0, sizeof(this));
+}
+
+ResourceManager::ResTypeData::~ResTypeData() {
+}
+
+ResourceManager::ResourceManager(ScummEngine *vm) : _vm(vm) {
+ _allocatedSize = 0;
+ _maxHeapThreshold = 0;
+ _minHeapThreshold = 0;
+ _expireCounter = 0;
}
ResourceManager::~ResourceManager() {
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 8540ef3..f1bcc14 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -95,7 +95,11 @@ public:
public:
byte *roomno;
uint32 *roomoffs;
- uint32 *globsize;
+ uint32 *globsize; ///!< Occurs in HE 70+, but we don't use it for anything.
+
+ public:
+ ResTypeData();
+ ~ResTypeData();
};
ResTypeData _types[rtNumTypes];
Commit: 75b9deb1856bae8355403faa5f55857f3929adb6
https://github.com/scummvm/scummvm/commit/75b9deb1856bae8355403faa5f55857f3929adb6
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:10-07:00
Commit Message:
SCUMM: Get rid of the MemBlkHeader hack
This uncovered at least one potentially serious bug in the inventory
code, which still needs to be investigated and fixed.
Changed paths:
engines/scumm/he/script_v72he.cpp
engines/scumm/imuse/imuse.cpp
engines/scumm/object.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/saveload.cpp
engines/scumm/script.cpp
engines/scumm/script_v6.cpp
engines/scumm/scumm.cpp
engines/scumm/scumm.h
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index b63feeb..96ffa2a 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -621,7 +621,7 @@ void ScummEngine_v72he::o72_getArrayDimSize() {
}
void ScummEngine_v72he::o72_getNumFreeArrays() {
- byte **addr = _res->_types[rtString].address;
+ byte **addr = _res->_types[rtString]._address;
int i, num = 0;
for (i = 1; i < _numArray; i++) {
@@ -629,7 +629,7 @@ void ScummEngine_v72he::o72_getNumFreeArrays() {
num++;
}
- push (num);
+ push(num);
}
void ScummEngine_v72he::o72_roomOps() {
diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index e6b134a..4a7ddd0 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -112,12 +112,12 @@ byte *IMuseInternal::findStartOfSound(int sound) {
}
// Check for old-style headers first, like 'RO'
- if (ptr[4] == 'R' && ptr[5] == 'O'&& ptr[6] != 'L')
+ if (ptr[0] == 'R' && ptr[1] == 'O'&& ptr[2] != 'L')
+ return ptr;
+ if (ptr[4] == 'S' && ptr[5] == 'O')
return ptr + 4;
- if (ptr[8] == 'S' && ptr[9] == 'O')
- return ptr + 8;
- ptr += 8;
+ ptr += 4;
size = READ_BE_UINT32(ptr);
ptr += 4;
@@ -145,7 +145,7 @@ bool IMuseInternal::isMT32(int sound) {
if (ptr == NULL)
return false;
- tag = READ_BE_UINT32(ptr + 4);
+ tag = READ_BE_UINT32(ptr);
switch (tag) {
case MKTAG('A','D','L',' '):
case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
@@ -164,17 +164,17 @@ bool IMuseInternal::isMT32(int sound) {
case MKTAG('M','I','D','I'): // Occurs in Sam & Max
// HE games use Roland music
- if (ptr[12] == 'H' && ptr[13] == 'S')
+ if (ptr[8] == 'H' && ptr[9] == 'S')
return true;
else
return false;
}
// Old style 'RO' has equivalent properties to 'ROL'
- if (ptr[4] == 'R' && ptr[5] == 'O')
+ if (ptr[0] == 'R' && ptr[1] == 'O')
return true;
// Euphony tracks show as 'SO' and have equivalent properties to 'ADL'
- if (ptr[8] == 'S' && ptr[9] == 'O')
+ if (ptr[4] == 'S' && ptr[5] == 'O')
return false;
error("Unknown music type: '%c%c%c%c'", (char)tag >> 24, (char)tag >> 16, (char)tag >> 8, (char)tag);
@@ -192,7 +192,7 @@ bool IMuseInternal::isMIDI(int sound) {
if (ptr == NULL)
return false;
- tag = READ_BE_UINT32(ptr + 4);
+ tag = READ_BE_UINT32(ptr);
switch (tag) {
case MKTAG('A','D','L',' '):
case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
@@ -212,11 +212,11 @@ bool IMuseInternal::isMIDI(int sound) {
}
// Old style 'RO' has equivalent properties to 'ROL'
- if (ptr[4] == 'R' && ptr[5] == 'O')
+ if (ptr[0] == 'R' && ptr[1] == 'O')
return true;
// Euphony tracks show as 'SO' and have equivalent properties to 'ADL'
// FIXME: Right now we're pretending it's GM.
- if (ptr[8] == 'S' && ptr[9] == 'O')
+ if (ptr[4] == 'S' && ptr[5] == 'O')
return true;
error("Unknown music type: '%c%c%c%c'", (char)tag >> 24, (char)tag >> 16, (char)tag >> 8, (char)tag);
diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp
index 457e2c7..8b0e22d 100644
--- a/engines/scumm/object.cpp
+++ b/engines/scumm/object.cpp
@@ -192,8 +192,11 @@ void ScummEngine::clearOwnerOf(int obj) {
if (!_inventory[i] && _inventory[i+1]) {
_inventory[i] = _inventory[i+1];
_inventory[i+1] = 0;
- _res->_types[rtInventory].address[i] = _res->_types[rtInventory].address[i + 1];
- _res->_types[rtInventory].address[i + 1] = NULL;
+ // FIXME FIXME FIXME: This is incomplete, as we do not touch flags, status... BUG
+ _res->_types[rtInventory]._address[i] = _res->_types[rtInventory]._address[i + 1];
+ _res->_types[rtInventory]._size[i] = _res->_types[rtInventory]._size[i + 1];
+ _res->_types[rtInventory]._address[i + 1] = NULL;
+ _res->_types[rtInventory]._size[i + 1] = 0;
}
}
break;
@@ -1796,7 +1799,7 @@ int ScummEngine::findLocalObjectSlot() {
int ScummEngine::findFlObjectSlot() {
int i;
for (i = 1; i < _numFlObject; i++) {
- if (_res->_types[rtFlObject].address[i] == NULL)
+ if (_res->_types[rtFlObject]._address[i] == NULL)
return i;
}
error("findFlObjectSlot: Out of FLObject slots");
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index a00630f..009fd5c 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -537,9 +537,10 @@ void ResourceManager::allocResTypeData(int id, uint32 tag, int num, const char *
_types[id].num = num;
_types[id].tag = tag;
_types[id].name = name;
- _types[id].address = (byte **)calloc(num, sizeof(void *));
+ _types[id]._address = (byte **)calloc(num, sizeof(byte *));
+ _types[id]._size = (uint32 *)calloc(num, sizeof(uint32));
_types[id].flags = (byte *)calloc(num, sizeof(byte));
- _types[id].status = (byte *)calloc(num, sizeof(byte));
+ _types[id]._status = (byte *)calloc(num, sizeof(byte));
if (mode) {
_types[id].roomno = (byte *)calloc(num, sizeof(byte));
@@ -584,8 +585,6 @@ void ScummEngine::nukeCharset(int i) {
}
void ScummEngine::ensureResourceLoaded(int type, int i) {
- void *addr = NULL;
-
debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
if ((type == rtRoom) && i > 0x7F && _game.version < 7 && _game.heversion <= 71) {
@@ -606,10 +605,7 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
if (type != rtCharset && i == 0)
return;
- if (i <= _res->_types[type].num)
- addr = _res->_types[type].address[i];
-
- if (addr)
+ if (i <= _res->_types[type].num && _res->_types[type]._address[i])
return;
loadResource(type, i);
@@ -715,9 +711,7 @@ uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
int ScummEngine::getResourceSize(int type, int idx) {
byte *ptr = getResourceAddress(type, idx);
assert(ptr);
- MemBlkHeader *hdr = (MemBlkHeader *)(ptr - sizeof(MemBlkHeader));
-
- return hdr->size;
+ return _res->_types[type]._size[idx];
}
byte *ScummEngine::getResourceAddress(int type, int idx) {
@@ -729,17 +723,17 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
if (!_res->validateResource("getResourceAddress", type, idx))
return NULL;
- if (!_res->_types[type].address) {
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->_types[type].address == NULL", resTypeFromId(type), idx);
+ if (!_res->_types[type]._address) {
+ debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->_types[type]._address == NULL", resTypeFromId(type), idx);
return NULL;
}
// If the resource is missing, but loadable from the game data files, try to do so.
- if (!_res->_types[type].address[idx] && _res->_types[type]._mode != kDynamicResTypeMode) {
+ if (!_res->_types[type]._address[idx] && _res->_types[type]._mode != kDynamicResTypeMode) {
ensureResourceLoaded(type, idx);
}
- ptr = (byte *)_res->_types[type].address[idx];
+ ptr = (byte *)_res->_types[type]._address[idx];
if (!ptr) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
@@ -747,8 +741,8 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
_res->setResourceCounter(type, idx, 1);
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
- return ptr + sizeof(MemBlkHeader);
+ debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr);
+ return ptr;
}
byte *ScummEngine::getStringAddress(int i) {
@@ -807,29 +801,29 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
// cases. For instance, Zak tries to reload the intro music
// while it's playing. See bug #1253171.
- if (_types[type].address[idx] && (type == rtSound || type == rtScript || type == rtCostume))
- return _types[type].address[idx] + sizeof(MemBlkHeader);
+ if (_types[type]._address[idx] && (type == rtSound || type == rtScript || type == rtCostume))
+ return _types[type]._address[idx];
}
nukeResource(type, idx);
expireResources(size);
- void *ptr = calloc(size + sizeof(MemBlkHeader) + SAFETY_AREA, 1);
+ byte *ptr = (byte *)calloc(size + SAFETY_AREA, 1);
if (ptr == NULL) {
error("createResource(%s,%d): Out of memory while allocating %d", resTypeFromId(type), idx, size);
}
_allocatedSize += size;
- _types[type].address[idx] = (byte *)ptr;
- ((MemBlkHeader *)ptr)->size = size;
+ _types[type]._address[idx] = ptr;
+ _types[type]._size[idx] = size;
setResourceCounter(type, idx, 1);
- return (byte *)ptr + sizeof(MemBlkHeader); /* skip header */
+ return ptr;
}
ResourceManager::ResTypeData::ResTypeData() {
- memset(this, 0, sizeof(this));
+ memset(this, 0, sizeof(*this));
}
ResourceManager::ResTypeData::~ResTypeData() {
@@ -864,18 +858,19 @@ bool ResourceManager::validateResource(const char *str, int type, int idx) const
void ResourceManager::nukeResource(int type, int idx) {
byte *ptr;
- if (!_types[type].address)
+ if (!_types[type]._address)
return;
assert(idx >= 0 && idx < _types[type].num);
- ptr = _types[type].address[idx];
+ ptr = _types[type]._address[idx];
if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
- _types[type].address[idx] = 0;
+ _types[type]._address[idx] = 0;
+ _types[type]._size[idx] = 0;
_types[type].flags[idx] = 0;
- _types[type].status[idx] &= ~RS_MODIFIED;
- _allocatedSize -= ((MemBlkHeader *)ptr)->size;
+ _types[type]._status[idx] &= ~RS_MODIFIED;
+ _allocatedSize -= _types[type]._size[idx];
free(ptr);
}
}
@@ -957,13 +952,13 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
void ResourceManager::setModified(int type, int i) {
if (!validateResource("Modified", type, i))
return;
- _types[type].status[i] |= RS_MODIFIED;
+ _types[type]._status[i] |= RS_MODIFIED;
}
bool ResourceManager::isModified(int type, int i) const {
if (!validateResource("isModified", type, i))
return false;
- return (_types[type].status[i] & RS_MODIFIED) != 0;
+ return (_types[type]._status[i] & RS_MODIFIED) != 0;
}
void ResourceManager::expireResources(uint32 size) {
@@ -993,7 +988,7 @@ void ResourceManager::expireResources(uint32 size) {
// so we can potentially unload them to free memory.
for (j = _types[i].num; --j >= 0;) {
flag = _types[i].flags[j];
- if (!(flag & RF_LOCK) && flag >= best_counter && _types[i].address[j] && !_vm->isResourceInUse(i, j)) {
+ if (!(flag & RF_LOCK) && flag >= best_counter && _types[i]._address[j] && !_vm->isResourceInUse(i, j)) {
best_counter = flag;
best_type = i;
best_res = j;
@@ -1018,9 +1013,10 @@ void ResourceManager::freeResources() {
if (isResourceLoaded(i, j))
nukeResource(i, j);
}
- free(_types[i].address);
+ free(_types[i]._address);
+ free(_types[i]._size);
free(_types[i].flags);
- free(_types[i].status);
+ free(_types[i]._status);
free(_types[i].roomno);
free(_types[i].roomoffs);
@@ -1055,7 +1051,7 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
bool ResourceManager::isResourceLoaded(int type, int idx) const {
if (!validateResource("isResourceLoaded", type, idx))
return false;
- return _types[type].address[idx] != NULL;
+ return _types[type]._address[idx] != NULL;
}
void ResourceManager::resourceStats() {
@@ -1066,8 +1062,8 @@ void ResourceManager::resourceStats() {
for (i = rtFirst; i <= rtLast; i++)
for (j = _types[i].num; --j >= 0;) {
flag = _types[i].flags[j];
- if (flag & RF_LOCK && _types[i].address[j]) {
- lockedSize += ((MemBlkHeader *)_types[i].roomoffs[j])->size;
+ if (flag & RF_LOCK && _types[i]._address[j]) {
+ lockedSize += _types[i]._size[j];
lockedNum++;
}
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index f1bcc14..dd314cb 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -88,14 +88,50 @@ public:
uint16 num;
uint32 tag;
const char *name;
- byte **address;
+
+ /**
+ * Array of size num containing pointers to each resource of this type.
+ */
+ byte **_address;
+
+ /**
+ * Array of size num containing the sizes of each resource of this type.
+ */
+ uint32 *_size;
protected:
+ /**
+ * Array of size num containing TODO of each resource of this type.
+ */
byte *flags;
- byte *status;
+
+ /**
+ * Array of size num containing the status of each resource of this type.
+ * This is a bitfield of which currently only one bit is used, which indicates
+ * whether the resource is modified.
+ */
+ byte *_status;
public:
+ /**
+ * Array of size num containing for each resource of this type the
+ * id of the room (resp. the disk) the resource is contained in.
+ */
byte *roomno;
+
+ /**
+ * Array of size num containing room offsets of each resource of this type.
+ * That is the offset (in bytes) where the data for this resources
+ * can be found in the game data file(s), relative to the start
+ * of the room the resource is contained in.
+ *
+ * A value of RES_INVALID_OFFSET indicates a resources that is not contained
+ * in the game data files.
+ */
uint32 *roomoffs;
- uint32 *globsize; ///!< Occurs in HE 70+, but we don't use it for anything.
+
+ /**
+ * Array of size num. Occurs in HE 70+, but we don't use it for anything.
+ */
+ uint32 *globsize;
public:
ResTypeData();
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index cd48fee..0ca1648 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -1247,7 +1247,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
s->saveUint16(type); // Save the res type...
for (idx = 0; idx < _res->_types[type].num; idx++) {
// Only save resources which actually exist...
- if (_res->_types[type].address[idx]) {
+ if (_res->_types[type]._address[idx]) {
s->saveUint16(idx); // Save the index of the resource
saveResource(s, type, idx);
}
@@ -1663,14 +1663,14 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
}
void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
- assert(_res->_types[type].address[idx]);
+ assert(_res->_types[type]._address[idx]);
if (_res->_types[type]._mode == kDynamicResTypeMode) {
- byte *ptr = _res->_types[type].address[idx];
- uint32 size = ((MemBlkHeader *)ptr)->size;
+ byte *ptr = _res->_types[type]._address[idx];
+ uint32 size = _res->_types[type]._size[idx];
ser->saveUint32(size);
- ser->saveBytes(ptr + sizeof(MemBlkHeader), size);
+ ser->saveBytes(ptr, size);
if (type == rtInventory) {
ser->saveUint16(_inventory[idx]);
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index 4630ec1..7f279a3 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -390,7 +390,7 @@ void ScummEngine::getScriptBaseAddress() {
break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory);
- _lastCodePtr = &_res->_types[rtInventory].address[idx];
+ _lastCodePtr = &_res->_types[rtInventory]._address[idx];
break;
case WIO_LOCAL:
@@ -398,18 +398,18 @@ void ScummEngine::getScriptBaseAddress() {
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
assert(_roomResource < _res->_types[rtRoomScripts].num);
- _lastCodePtr = &_res->_types[rtRoomScripts].address[_roomResource];
+ _lastCodePtr = &_res->_types[rtRoomScripts]._address[_roomResource];
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms);
- _lastCodePtr = &_res->_types[rtRoom].address[_roomResource];
+ _lastCodePtr = &_res->_types[rtRoom]._address[_roomResource];
}
break;
case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts);
- _lastCodePtr = &_res->_types[rtScript].address[ss->number];
+ _lastCodePtr = &_res->_types[rtScript]._address[ss->number];
break;
case WIO_FLOBJECT: /* flobject script */
@@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject);
- _lastCodePtr = &_res->_types[rtFlObject].address[idx];
+ _lastCodePtr = &_res->_types[rtFlObject]._address[idx];
break;
default:
error("Bad type while getting base address");
@@ -445,7 +445,7 @@ void ScummEngine::resetScriptPointer() {
* collected by ResourceManager::expireResources.
*/
void ScummEngine::refreshScriptPointer() {
- if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
+ if (*_lastCodePtr != _scriptOrgPointer) {
long oldoffs = _scriptPointer - _scriptOrgPointer;
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index afc1eb6..138da3f 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -357,7 +357,7 @@ void ScummEngine_v6::nukeArray(int a) {
}
int ScummEngine_v6::findFreeArrayId() {
- byte **addr = _res->_types[rtString].address;
+ byte **addr = _res->_types[rtString]._address;
int i;
for (i = 1; i < _numArray; i++) {
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index e891006..2273697 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1185,7 +1185,7 @@ Common::Error ScummEngine::init() {
resetScummVars();
if (_imuse) {
- _imuse->setBase(_res->_types[rtSound].address);
+ _imuse->setBase(_res->_types[rtSound]._address);
}
if (_game.version >= 5 && _game.version <= 7)
@@ -2462,7 +2462,7 @@ void ScummEngine::restart() {
resetScummVars();
if (_imuse) {
- _imuse->setBase(_res->_types[rtSound].address);
+ _imuse->setBase(_res->_types[rtSound]._address);
}
// Reinit sound engine
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index 768c976..9d64202 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -168,17 +168,6 @@ enum {
DEBUG_SMUSH = 1 << 10 // Track SMUSH
};
-/**
- * Internal header for any memory block allocated by the resource manager.
- *
- * @todo Hide MemBlkHeader; no code outside the resource manager should
- * have to use it, ever. Currently script code needs it to detect whether
- * some scripts have moved (in fetchScriptByte()).
- */
-struct MemBlkHeader {
- uint32 size;
-};
-
struct VerbSlot;
struct ObjectData;
@@ -622,9 +611,11 @@ protected:
protected:
/* Script VM - should be in Script class */
uint32 _localScriptOffsets[1024];
- const byte *_scriptPointer, *_scriptOrgPointer;
- byte _opcode, _currentScript;
+ const byte *_scriptPointer;
+ const byte *_scriptOrgPointer;
const byte * const *_lastCodePtr;
+ byte _opcode;
+ byte _currentScript;
int _scummStackPos;
int _vmStack[150];
Commit: 0342ab3f1b2d67de6fa0112311b973b55d509f1c
https://github.com/scummvm/scummvm/commit/0342ab3f1b2d67de6fa0112311b973b55d509f1c
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:11-07:00
Commit Message:
SCUMM: Rename ResTypeData::num to _num
Changed paths:
engines/scumm/debugger.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v4.cpp
engines/scumm/room.cpp
engines/scumm/saveload.cpp
engines/scumm/script.cpp
diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp
index d404802..f7293b5 100644
--- a/engines/scumm/debugger.cpp
+++ b/engines/scumm/debugger.cpp
@@ -374,8 +374,8 @@ bool ScummDebugger::Cmd_Actor(int argc, const char **argv) {
DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) {
- if (value >= _vm->_res->_types[rtCostume].num)
- DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume].num);
+ if (value >= _vm->_res->_types[rtCostume]._num)
+ DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._num);
else {
a->setActorCostume(value);
_vm->_fullRedraw = true;
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 009fd5c..d0dd077 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(int id) {
else
num = _fileHandle->readUint16LE();
- if (num != _res->_types[id].num) {
+ if (num != _res->_types[id]._num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
}
@@ -534,7 +534,7 @@ void ResourceManager::allocResTypeData(int id, uint32 tag, int num, const char *
error("Too many %ss (%d) in directory", name, num);
_types[id]._mode = mode;
- _types[id].num = num;
+ _types[id]._num = num;
_types[id].tag = tag;
_types[id].name = name;
_types[id]._address = (byte **)calloc(num, sizeof(byte *));
@@ -605,7 +605,7 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
if (type != rtCharset && i == 0)
return;
- if (i <= _res->_types[type].num && _res->_types[type]._address[i])
+ if (i <= _res->_types[type]._num && _res->_types[type]._address[i])
return;
loadResource(type, i);
@@ -628,8 +628,8 @@ int ScummEngine::loadResource(int type, int idx) {
roomNr = getResourceRoomNr(type, idx);
- if (idx >= _res->_types[type].num)
- error("%s %d undefined %d %d", _res->_types[type].name, idx, _res->_types[type].num, roomNr);
+ if (idx >= _res->_types[type]._num)
+ error("%s %d undefined %d %d", _res->_types[type].name, idx, _res->_types[type]._num, roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -773,7 +773,7 @@ void ResourceManager::increaseResourceCounter() {
byte counter;
for (i = rtFirst; i <= rtLast; i++) {
- for (j = _types[i].num; --j >= 0;) {
+ for (j = _types[i]._num; --j >= 0;) {
counter = _types[i].flags[j] & RF_USAGE;
if (counter && counter < RF_USAGE_MAX) {
setResourceCounter(i, j, counter + 1);
@@ -848,7 +848,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
}
bool ResourceManager::validateResource(const char *str, int type, int idx) const {
- if (type < rtFirst || type > rtLast || (uint) idx >= (uint)_types[type].num) {
+ if (type < rtFirst || type > rtLast || (uint) idx >= (uint)_types[type]._num) {
error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
return false;
}
@@ -861,7 +861,7 @@ void ResourceManager::nukeResource(int type, int idx) {
if (!_types[type]._address)
return;
- assert(idx >= 0 && idx < _types[type].num);
+ assert(idx >= 0 && idx < _types[type]._num);
ptr = _types[type]._address[idx];
if (ptr != NULL) {
@@ -986,7 +986,7 @@ void ResourceManager::expireResources(uint32 size) {
if (_types[i]._mode != kDynamicResTypeMode) {
// Resources of this type can be reloaded from the data files,
// so we can potentially unload them to free memory.
- for (j = _types[i].num; --j >= 0;) {
+ for (j = _types[i]._num; --j >= 0;) {
flag = _types[i].flags[j];
if (!(flag & RF_LOCK) && flag >= best_counter && _types[i]._address[j] && !_vm->isResourceInUse(i, j)) {
best_counter = flag;
@@ -1009,7 +1009,7 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() {
int i, j;
for (i = rtFirst; i <= rtLast; i++) {
- for (j = _types[i].num; --j >= 0;) {
+ for (j = _types[i]._num; --j >= 0;) {
if (isResourceLoaded(i, j))
nukeResource(i, j);
}
@@ -1060,7 +1060,7 @@ void ResourceManager::resourceStats() {
byte flag;
for (i = rtFirst; i <= rtLast; i++)
- for (j = _types[i].num; --j >= 0;) {
+ for (j = _types[i]._num; --j >= 0;) {
flag = _types[i].flags[j];
if (flag & RF_LOCK && _types[i]._address[j]) {
lockedSize += _types[i]._size[j];
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index dd314cb..1182dfb 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -85,40 +85,44 @@ public:
friend class ResourceManager;
public:
ResTypeMode _mode;
- uint16 num;
+ /**
+ * The maximal number of resource of this type. Determines the size
+ * of various arrays.
+ */
+ uint16 _num;
uint32 tag;
const char *name;
/**
- * Array of size num containing pointers to each resource of this type.
+ * Array of size _num containing pointers to each resource of this type.
*/
byte **_address;
/**
- * Array of size num containing the sizes of each resource of this type.
+ * Array of size _num containing the sizes of each resource of this type.
*/
uint32 *_size;
protected:
/**
- * Array of size num containing TODO of each resource of this type.
+ * Array of size _num containing TODO of each resource of this type.
*/
byte *flags;
/**
- * Array of size num containing the status of each resource of this type.
+ * Array of size _num containing the status of each resource of this type.
* This is a bitfield of which currently only one bit is used, which indicates
* whether the resource is modified.
*/
byte *_status;
public:
/**
- * Array of size num containing for each resource of this type the
+ * Array of size _num containing for each resource of this type the
* id of the room (resp. the disk) the resource is contained in.
*/
byte *roomno;
/**
- * Array of size num containing room offsets of each resource of this type.
+ * Array of size _num containing room offsets of each resource of this type.
* That is the offset (in bytes) where the data for this resources
* can be found in the game data file(s), relative to the start
* of the room the resource is contained in.
@@ -129,7 +133,7 @@ public:
uint32 *roomoffs;
/**
- * Array of size num. Occurs in HE 70+, but we don't use it for anything.
+ * Array of size _num. Occurs in HE 70+, but we don't use it for anything.
*/
uint32 *globsize;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index 8fc2762..95eb8d4 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -38,7 +38,7 @@ int ScummEngine_v4::readResTypeList(int id) {
num = _fileHandle->readUint16LE();
- if (num != _res->_types[id].num) {
+ if (num != _res->_types[id]._num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
}
diff --git a/engines/scumm/room.cpp b/engines/scumm/room.cpp
index 7e0f70e..6ff55e2 100644
--- a/engines/scumm/room.cpp
+++ b/engines/scumm/room.cpp
@@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
//
// Load scale data
//
- for (i = 1; i < _res->_types[rtScaleTable].num; i++)
+ for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
_res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) {
int s1, s2, y1, y2;
if (_game.version == 8) {
- for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 16) {
+ for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8);
@@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2);
}
} else {
- for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 8) {
+ for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4);
@@ -794,7 +794,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
//
// No scale data in old bundle games
//
- for (i = 1; i < _res->_types[rtScaleTable].num; i++)
+ for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
_res->nukeResource(rtScaleTable, i);
}
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 0ca1648..376351c 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -428,7 +428,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// Nuke all resources
for (i = rtFirst; i <= rtLast; i++)
if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat))
- for (j = 0; j < _res->_types[i].num; j++) {
+ for (j = 0; j < _res->_types[i]._num; j++) {
_res->nukeResource(i, j);
}
@@ -517,7 +517,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items
- for (i = 1; i < _res->_types[rtScaleTable].num; i++) {
+ for (i = 1; i < _res->_types[rtScaleTable]._num; i++) {
convertScaleTableToScaleSlot(i);
}
}
@@ -1245,7 +1245,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
for (type = rtFirst; type <= rtLast; type++) {
if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
- for (idx = 0; idx < _res->_types[type].num; idx++) {
+ for (idx = 0; idx < _res->_types[type]._num; idx++) {
// Only save resources which actually exist...
if (_res->_types[type]._address[idx]) {
s->saveUint16(idx); // Save the index of the resource
@@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
} else {
while ((type = s->loadUint16()) != 0xFFFF) {
while ((idx = s->loadUint16()) != 0xFFFF) {
- assert(0 <= idx && idx < _res->_types[type].num);
+ assert(0 <= idx && idx < _res->_types[type]._num);
loadResource(s, type, idx);
}
}
@@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// unchanged resource counts, we have to hard code the following check
if (_game.version < 6 && type == rtObjectName)
continue;
- for (idx = 1; idx < _res->_types[type].num; idx++)
+ for (idx = 1; idx < _res->_types[type]._num; idx++)
loadResourceOLD(s, type, idx);
}
}
@@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
//
if (s->isSaving()) {
for (i = rtFirst; i <= rtLast; i++)
- for (j = 1; j < _res->_types[i].num; j++) {
+ for (j = 1; j < _res->_types[i]._num; j++) {
if (_res->isLocked(i, j)) {
s->saveByte(i);
s->saveUint16(j);
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index 7f279a3..e418fcd 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -397,7 +397,7 @@ void ScummEngine::getScriptBaseAddress() {
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
- assert(_roomResource < _res->_types[rtRoomScripts].num);
+ assert(_roomResource < _res->_types[rtRoomScripts]._num);
_lastCodePtr = &_res->_types[rtRoomScripts]._address[_roomResource];
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
@@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
- if (_res->_types[rtScript].num > 460) {
+ if (_res->_types[rtScript]._num > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {
Commit: 82a6f2ee3ce1cd11c7b186b0ec728e48589445ae
https://github.com/scummvm/scummvm/commit/82a6f2ee3ce1cd11c7b186b0ec728e48589445ae
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:11-07:00
Commit Message:
SCUMM: Rename ResTypeData::tag to _tag, get rid of ResTypeData::name
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/scumm.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index d0dd077..b9f88b2 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -526,17 +526,16 @@ int ScummEngine_v70he::readResTypeList(int id) {
return num;
}
-void ResourceManager::allocResTypeData(int id, uint32 tag, int num, const char *name, ResTypeMode mode) {
- debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name, tag2str(TO_BE_32(tag)), num, mode);
+void ResourceManager::allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode) {
+ debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(id), tag2str(TO_BE_32(tag)), num, mode);
assert(id >= 0 && id < (int)(ARRAYSIZE(_types)));
if (num >= 8000)
- error("Too many %ss (%d) in directory", name, num);
+ error("Too many %s resources (%d) in directory", resTypeFromId(id), num);
_types[id]._mode = mode;
_types[id]._num = num;
- _types[id].tag = tag;
- _types[id].name = name;
+ _types[id]._tag = tag;
_types[id]._address = (byte **)calloc(num, sizeof(byte *));
_types[id]._size = (uint32 *)calloc(num, sizeof(uint32));
_types[id].flags = (byte *)calloc(num, sizeof(byte));
@@ -629,7 +628,7 @@ int ScummEngine::loadResource(int type, int idx) {
roomNr = getResourceRoomNr(type, idx);
if (idx >= _res->_types[type]._num)
- error("%s %d undefined %d %d", _res->_types[type].name, idx, _res->_types[type]._num, roomNr);
+ error("%s %d undefined %d %d", resTypeFromId(type), idx, _res->_types[type]._num, roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -663,11 +662,11 @@ int ScummEngine::loadResource(int type, int idx) {
return readSoundResource(idx);
}
+ // Sanity check: Is this the right tag for this resource type?
tag = _fileHandle->readUint32BE();
-
- if (tag != _res->_types[type].tag && _game.heversion < 70) {
+ if (tag != _res->_types[type]._tag && _game.heversion < 70) {
error("%s %d not in room %d at %d+%d in file %s",
- _res->_types[type].name, idx, roomNr,
+ resTypeFromId(type), idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName());
}
@@ -1283,30 +1282,30 @@ void ScummEngine::allocateArrays() {
}
_res->allocResTypeData(rtCostume, (_game.features & GF_NEW_COSTUMES) ? MKTAG('A','K','O','S') : MKTAG('C','O','S','T'),
- _numCostumes, "costume", kStaticResTypeMode);
- _res->allocResTypeData(rtRoom, MKTAG('R','O','O','M'), _numRooms, "room", kStaticResTypeMode);
- _res->allocResTypeData(rtRoomImage, MKTAG('R','M','I','M'), _numRooms, "room image", kStaticResTypeMode);
- _res->allocResTypeData(rtRoomScripts, MKTAG('R','M','S','C'), _numRooms, "room script", kStaticResTypeMode);
- _res->allocResTypeData(rtSound, MKTAG('S','O','U','N'), _numSounds, "sound", kSoundResTypeMode);
- _res->allocResTypeData(rtScript, MKTAG('S','C','R','P'), _numScripts, "script", kStaticResTypeMode);
- _res->allocResTypeData(rtCharset, MKTAG('C','H','A','R'), _numCharsets, "charset", kStaticResTypeMode);
- _res->allocResTypeData(rtObjectName, 0, _numNewNames, "new name", kDynamicResTypeMode);
- _res->allocResTypeData(rtInventory, 0, _numInventory, "inventory", kDynamicResTypeMode);
- _res->allocResTypeData(rtTemp, 0, 10, "temp", kDynamicResTypeMode);
- _res->allocResTypeData(rtScaleTable, 0, 5, "scale table", kDynamicResTypeMode);
- _res->allocResTypeData(rtActorName, 0, _numActors, "actor name", kDynamicResTypeMode);
- _res->allocResTypeData(rtVerb, 0, _numVerbs, "verb", kDynamicResTypeMode);
- _res->allocResTypeData(rtString, 0, _numArray, "array", kDynamicResTypeMode);
- _res->allocResTypeData(rtFlObject, 0, _numFlObject, "flobject", kDynamicResTypeMode);
- _res->allocResTypeData(rtMatrix, 0, 10, "boxes", kDynamicResTypeMode);
- _res->allocResTypeData(rtImage, MKTAG('A','W','I','Z'), _numImages, "images", kStaticResTypeMode);
- _res->allocResTypeData(rtTalkie, MKTAG('T','L','K','E'), _numTalkies, "talkie", kStaticResTypeMode);
+ _numCostumes, kStaticResTypeMode);
+ _res->allocResTypeData(rtRoom, MKTAG('R','O','O','M'), _numRooms, kStaticResTypeMode);
+ _res->allocResTypeData(rtRoomImage, MKTAG('R','M','I','M'), _numRooms, kStaticResTypeMode);
+ _res->allocResTypeData(rtRoomScripts, MKTAG('R','M','S','C'), _numRooms, kStaticResTypeMode);
+ _res->allocResTypeData(rtSound, MKTAG('S','O','U','N'), _numSounds, kSoundResTypeMode);
+ _res->allocResTypeData(rtScript, MKTAG('S','C','R','P'), _numScripts, kStaticResTypeMode);
+ _res->allocResTypeData(rtCharset, MKTAG('C','H','A','R'), _numCharsets, kStaticResTypeMode);
+ _res->allocResTypeData(rtObjectName, 0, _numNewNames, kDynamicResTypeMode);
+ _res->allocResTypeData(rtInventory, 0, _numInventory, kDynamicResTypeMode);
+ _res->allocResTypeData(rtTemp, 0, 10, kDynamicResTypeMode);
+ _res->allocResTypeData(rtScaleTable, 0, 5, kDynamicResTypeMode);
+ _res->allocResTypeData(rtActorName, 0, _numActors, kDynamicResTypeMode);
+ _res->allocResTypeData(rtVerb, 0, _numVerbs, kDynamicResTypeMode);
+ _res->allocResTypeData(rtString, 0, _numArray, kDynamicResTypeMode);
+ _res->allocResTypeData(rtFlObject, 0, _numFlObject, kDynamicResTypeMode);
+ _res->allocResTypeData(rtMatrix, 0, 10, kDynamicResTypeMode);
+ _res->allocResTypeData(rtImage, MKTAG('A','W','I','Z'), _numImages, kStaticResTypeMode);
+ _res->allocResTypeData(rtTalkie, MKTAG('T','L','K','E'), _numTalkies, kStaticResTypeMode);
}
void ScummEngine_v70he::allocateArrays() {
ScummEngine::allocateArrays();
- _res->allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", kStaticResTypeMode);
+ _res->allocResTypeData(rtSpoolBuffer, 0, 9, kStaticResTypeMode);
_heV7RoomIntOffsets = (uint32 *)calloc(_numRooms, sizeof(uint32));
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 1182dfb..7a7d49d 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -90,8 +90,12 @@ public:
* of various arrays.
*/
uint16 _num;
- uint32 tag;
- const char *name;
+
+ /**
+ * The 4-byte tag or chunk type associated to this resource type, if any.
+ * Only applies to resources that are loaded from the game data files.
+ */
+ uint32 _tag;
/**
* Array of size _num containing pointers to each resource of this type.
@@ -154,7 +158,7 @@ public:
void setHeapThreshold(int min, int max);
- void allocResTypeData(int id, uint32 tag, int num, const char *name, ResTypeMode mode);
+ void allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode);
void freeResources();
byte *createResource(int type, int index, uint32 size);
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 2273697..21521d0 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1233,7 +1233,7 @@ void ScummEngine::setupScumm() {
requestLoad(ConfMan.getInt("save_slot"));
}
- _res->allocResTypeData(rtBuffer, 0, 10, "buffer", kDynamicResTypeMode);
+ _res->allocResTypeData(rtBuffer, 0, 10, kDynamicResTypeMode);
setupScummVars();
Commit: ff3087e56cfe45ba94e26dece0ac4a75a8774956
https://github.com/scummvm/scummvm/commit/ff3087e56cfe45ba94e26dece0ac4a75a8774956
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:11-07:00
Commit Message:
SCUMM: Remove obsolete TODO
Changed paths:
engines/scumm/palette.cpp
diff --git a/engines/scumm/palette.cpp b/engines/scumm/palette.cpp
index 5910b74..b85771e 100644
--- a/engines/scumm/palette.cpp
+++ b/engines/scumm/palette.cpp
@@ -1006,9 +1006,6 @@ void ScummEngine::setPalColor(int idx, int r, int g, int b) {
}
void ScummEngine::setCurrentPalette(int palindex) {
- // TODO: This method could almost be moved to ScummEngin_v6, the only
- // problem is that it is called by ScummEngine::resetRoomSubBlocks().
- // But it should be possible to get rid of that, too (with some care).
const byte *pals;
_curPalIndex = palindex;
Commit: 107e25ff5bc65ccca62c8fe0a51cf978ee86dae4
https://github.com/scummvm/scummvm/commit/107e25ff5bc65ccca62c8fe0a51cf978ee86dae4
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:12-07:00
Commit Message:
SCUMM: Document resource usage count / expiry a little bit
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/room.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index b9f88b2..3b278a6 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -762,12 +762,13 @@ byte *ScummEngine::getStringAddressVar(int i) {
}
void ResourceManager::increaseExpireCounter() {
- if (!(++_expireCounter)) {
- increaseResourceCounter();
+ ++_expireCounter;
+ if (_expireCounter == 0) { // overflow?
+ increaseResourceCounters();
}
}
-void ResourceManager::increaseResourceCounter() {
+void ResourceManager::increaseResourceCounters() {
int i, j;
byte counter;
@@ -781,9 +782,9 @@ void ResourceManager::increaseResourceCounter() {
}
}
-void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
- _types[type].flags[idx] &= ~RF_USAGE;
- _types[type].flags[idx] |= flag;
+void ResourceManager::setResourceCounter(int type, int idx, byte counter) {
+ _types[type].flags[idx] &= RF_LOCK; // Clear lower 7 bits, preserve the lock bit.
+ _types[type].flags[idx] |= counter; // Update the usage counter
}
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
@@ -969,7 +970,7 @@ void ResourceManager::expireResources(uint32 size) {
if (_expireCounter != 0xFF) {
_expireCounter = 0xFF;
- increaseResourceCounter();
+ increaseResourceCounters();
}
if (size + _allocatedSize < _maxHeapThreshold)
@@ -1000,7 +1001,7 @@ void ResourceManager::expireResources(uint32 size) {
nukeResource(best_type, best_res);
} while (size + _allocatedSize > _minHeapThreshold);
- increaseResourceCounter();
+ increaseResourceCounters();
debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 7a7d49d..9685830 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -106,9 +106,19 @@ public:
* Array of size _num containing the sizes of each resource of this type.
*/
uint32 *_size;
+
protected:
/**
- * Array of size _num containing TODO of each resource of this type.
+ * Array of size _num containing some information on each resource of
+ * this type.
+ * First off, the uppermost bit indicates whether the resources is
+ * locked into memory.
+ * Secondly, the lower 7 bits contain a counter. This counter measures
+ * roughly how old it is; a resource starts out with a count of 1 and
+ * can go as high as 127. When memory falls low resp. when the engine
+ * decides that it should throw out some unused stuff, then it begins
+ * by removing the resources with the highest counter (excluding locked
+ * resources and resources that are known to be in use).
*/
byte *flags;
@@ -118,6 +128,7 @@ public:
* whether the resource is modified.
*/
byte *_status;
+
public:
/**
* Array of size _num containing for each resource of this type the
@@ -161,26 +172,42 @@ public:
void allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode);
void freeResources();
- byte *createResource(int type, int index, uint32 size);
- void nukeResource(int type, int i);
+ byte *createResource(int type, int idx, uint32 size);
+ void nukeResource(int type, int idx);
- bool isResourceLoaded(int type, int index) const;
+ bool isResourceLoaded(int type, int idx) const;
- void lock(int type, int i);
- void unlock(int type, int i);
- bool isLocked(int type, int i) const;
+ void lock(int type, int idx);
+ void unlock(int type, int idx);
+ bool isLocked(int type, int idx) const;
- void setModified(int type, int i);
- bool isModified(int type, int i) const;
+ void setModified(int type, int idx);
+ bool isModified(int type, int idx) const;
+ /**
+ * This method increments the _expireCounter, and if it overflows (which happens
+ * after at most 256 calls), it calls increaseResourceCounter.
+ * It is invoked in the engine's main loop ScummEngine::scummLoop().
+ */
void increaseExpireCounter();
- void setResourceCounter(int type, int index, byte flag);
- void increaseResourceCounter();
+
+ /**
+ * Update the specified resource's counter.
+ */
+ void setResourceCounter(int type, int idx, byte counter);
+
+ /**
+ * Increment the counter of all unlocked loaded resources.
+ * The maximal count is 255.
+ * This is called by increaseExpireCounter and expireResources,
+ * but also by ScummEngine::startScene.
+ */
+ void increaseResourceCounters();
void resourceStats();
//protected:
- bool validateResource(const char *str, int type, int index) const;
+ bool validateResource(const char *str, int type, int idx) const;
protected:
void expireResources(uint32 size);
};
diff --git a/engines/scumm/room.cpp b/engines/scumm/room.cpp
index 6ff55e2..a0bb527 100644
--- a/engines/scumm/room.cpp
+++ b/engines/scumm/room.cpp
@@ -115,7 +115,7 @@ void ScummEngine::startScene(int room, Actor *a, int objectNr) {
VAR(VAR_ROOM) = room;
_fullRedraw = true;
- _res->increaseResourceCounter();
+ _res->increaseResourceCounters();
_currentRoom = room;
VAR(VAR_ROOM) = room;
Commit: abaaf0cad9a63c1a6f1946a8a90facd1535e762d
https://github.com/scummvm/scummvm/commit/abaaf0cad9a63c1a6f1946a8a90facd1535e762d
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:12-07:00
Commit Message:
SCUMM: Tweak sound res syncing
Changed paths:
engines/scumm/saveload.cpp
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 376351c..d81095a 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -1636,7 +1636,11 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) {
void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
uint32 size;
- if (_res->_types[type]._mode == kDynamicResTypeMode) {
+ if (type == rtSound && ser->getVersion() >= VER(23)) {
+ // Save/load only a list of resource numbers that need to be reloaded.
+ if (ser->loadUint16())
+ ensureResourceLoaded(rtSound, idx);
+ } else if (_res->_types[type]._mode == kDynamicResTypeMode) {
size = ser->loadUint32();
if (size) {
_res->createResource(type, idx, size);
@@ -1655,10 +1659,6 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
_newNames[idx] = ser->loadUint16();
}
}
- } else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) {
- // Save/load only a list of resource numbers that need to be reloaded.
- if (ser->loadUint16())
- ensureResourceLoaded(type, idx);
}
}
@@ -1688,11 +1688,17 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
assert(size);
_res->createResource(type, idx, size);
ser->loadBytes(getResourceAddress(type, idx), size);
+ } else if (type == rtSound) {
+ // HE Games use sound resource 1 for speech
+ if (_game.heversion >= 60 && idx == 1)
+ return;
+
+ ensureResourceLoaded(rtSound, idx);
} else if (_res->_types[type]._mode == kDynamicResTypeMode) {
uint32 size = ser->loadUint32();
assert(size);
- _res->createResource(type, idx, size);
- ser->loadBytes(getResourceAddress(type, idx), size);
+ byte *ptr = _res->createResource(type, idx, size);
+ ser->loadBytes(ptr, size);
if (type == rtInventory) {
_inventory[idx] = ser->loadUint16();
@@ -1700,12 +1706,6 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
if (type == rtObjectName) {
_newNames[idx] = ser->loadUint16();
}
- } else if (_res->_types[type]._mode == kSoundResTypeMode) {
- // HE Games use sound resource 1 for speech
- if (_game.heversion >= 60 && idx == 1)
- return;
-
- ensureResourceLoaded(type, idx);
}
}
Commit: c02420df43bec4ec523c18d8e6fdb381af29c1b5
https://github.com/scummvm/scummvm/commit/c02420df43bec4ec523c18d8e6fdb381af29c1b5
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:13-07:00
Commit Message:
SCUMM: Add a Resource class, refactor res code around it
Changed paths:
engines/scumm/detection.cpp
engines/scumm/he/resource_he.cpp
engines/scumm/he/script_v72he.cpp
engines/scumm/imuse/imuse.cpp
engines/scumm/imuse/imuse.h
engines/scumm/imuse/imuse_internal.h
engines/scumm/object.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v2.cpp
engines/scumm/resource_v3.cpp
engines/scumm/resource_v4.cpp
engines/scumm/saveload.cpp
engines/scumm/script.cpp
engines/scumm/script_v6.cpp
engines/scumm/scumm.cpp
engines/scumm/sound.cpp
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index 6440228..38c65b3 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -68,7 +68,7 @@ static const MD5Table *findInMD5Table(const char *md5) {
}
Common::String ScummEngine::generateFilename(const int room) const {
- const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
char buf[128];
if (_game.version == 4) {
@@ -110,7 +110,7 @@ Common::String ScummEngine_v60he::generateFilename(const int room) const {
if (room < 0) {
id = '0' - room;
} else {
- const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
id = diskNumber + '0';
}
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index 435e0e5..70b5543 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -226,7 +226,7 @@ void ScummEngine_v70he::readRoomsOffsets() {
num = READ_LE_UINT16(_heV7RoomOffsets);
ptr = _heV7RoomOffsets + 2;
for (i = 0; i < num; i++) {
- _res->_types[rtRoom].roomoffs[i] = READ_LE_UINT32(ptr);
+ _res->_types[rtRoom]._resources[i]._roomoffs = READ_LE_UINT32(ptr);
ptr += 4;
}
}
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 96ffa2a..dfcfa32 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -621,11 +621,11 @@ void ScummEngine_v72he::o72_getArrayDimSize() {
}
void ScummEngine_v72he::o72_getNumFreeArrays() {
- byte **addr = _res->_types[rtString]._address;
+ const ResourceManager::ResTypeData &rtd = _res->_types[rtString];
int i, num = 0;
for (i = 1; i < _numArray; i++) {
- if (!addr[i])
+ if (!rtd._resources[i]._address)
num++;
}
diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index 4a7ddd0..75cdb20 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -30,6 +30,7 @@
#include "scumm/imuse/imuse.h"
#include "scumm/imuse/imuse_internal.h"
#include "scumm/imuse/instrument.h"
+#include "scumm/resource.h"
#include "scumm/saveload.h"
#include "scumm/scumm.h"
@@ -47,7 +48,6 @@ _enable_gs(false),
_sc55(false),
_midi_adlib(NULL),
_midi_native(NULL),
-_base_sounds(NULL),
_sysex(NULL),
_paused(false),
_initialized(false),
@@ -100,11 +100,9 @@ IMuseInternal::~IMuseInternal() {
}
byte *IMuseInternal::findStartOfSound(int sound) {
- byte *ptr = NULL;
int32 size, pos;
- if (_base_sounds)
- ptr = _base_sounds[sound];
+ byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
if (ptr == NULL) {
debug(1, "IMuseInternal::findStartOfSound(): Sound %d doesn't exist", sound);
@@ -136,16 +134,11 @@ byte *IMuseInternal::findStartOfSound(int sound) {
}
bool IMuseInternal::isMT32(int sound) {
- byte *ptr = NULL;
- uint32 tag;
-
- if (_base_sounds)
- ptr = _base_sounds[sound];
-
+ byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
if (ptr == NULL)
return false;
- tag = READ_BE_UINT32(ptr);
+ uint32 tag = READ_BE_UINT32(ptr);
switch (tag) {
case MKTAG('A','D','L',' '):
case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
@@ -183,16 +176,11 @@ bool IMuseInternal::isMT32(int sound) {
}
bool IMuseInternal::isMIDI(int sound) {
- byte *ptr = NULL;
- uint32 tag;
-
- if (_base_sounds)
- ptr = _base_sounds[sound];
-
+ byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
if (ptr == NULL)
return false;
- tag = READ_BE_UINT32(ptr);
+ uint32 tag = READ_BE_UINT32(ptr);
switch (tag) {
case MKTAG('A','D','L',' '):
case MKTAG('A','S','F','X'): // Special AD class for old AdLib sound effects
@@ -423,11 +411,6 @@ int32 IMuseInternal::doCommand(int numargs, int a[]) {
return doCommand_internal(numargs, a);
}
-void IMuseInternal::setBase(byte **base) {
- Common::StackLock lock(_mutex, "IMuseInternal::setBase()");
- _base_sounds = base;
-}
-
uint32 IMuseInternal::property(int prop, uint32 value) {
Common::StackLock lock(_mutex, "IMuseInternal::property()");
switch (prop) {
diff --git a/engines/scumm/imuse/imuse.h b/engines/scumm/imuse/imuse.h
index c5e7f0a..8014b13 100644
--- a/engines/scumm/imuse/imuse.h
+++ b/engines/scumm/imuse/imuse.h
@@ -65,7 +65,6 @@ public:
virtual bool get_sound_active(int sound) const = 0;
virtual int32 doCommand(int numargs, int args[]) = 0;
virtual int clear_queue() = 0;
- virtual void setBase(byte **base) = 0;
virtual uint32 property(int prop, uint32 value) = 0;
virtual void addSysexHandler (byte mfgID, sysexfunc handler) = 0;
diff --git a/engines/scumm/imuse/imuse_internal.h b/engines/scumm/imuse/imuse_internal.h
index 56617ff..ec60b22 100644
--- a/engines/scumm/imuse/imuse_internal.h
+++ b/engines/scumm/imuse/imuse_internal.h
@@ -394,7 +394,6 @@ protected:
TimerCallbackInfo _timer_info_native;
uint32 _game_id;
- byte **_base_sounds;
// Plug-in SysEx handling. Right now this only supports one
// custom SysEx handler for the hardcoded IMUSE_SYSEX_ID
@@ -510,7 +509,6 @@ public:
int save_or_load(Serializer *ser, ScummEngine *scumm);
bool get_sound_active(int sound) const;
int32 doCommand(int numargs, int args[]);
- void setBase(byte **base);
uint32 property(int prop, uint32 value);
virtual void addSysexHandler(byte mfgID, sysexfunc handler);
diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp
index 8b0e22d..edcf54d 100644
--- a/engines/scumm/object.cpp
+++ b/engines/scumm/object.cpp
@@ -193,10 +193,10 @@ void ScummEngine::clearOwnerOf(int obj) {
_inventory[i] = _inventory[i+1];
_inventory[i+1] = 0;
// FIXME FIXME FIXME: This is incomplete, as we do not touch flags, status... BUG
- _res->_types[rtInventory]._address[i] = _res->_types[rtInventory]._address[i + 1];
- _res->_types[rtInventory]._size[i] = _res->_types[rtInventory]._size[i + 1];
- _res->_types[rtInventory]._address[i + 1] = NULL;
- _res->_types[rtInventory]._size[i + 1] = 0;
+ _res->_types[rtInventory]._resources[i]._address = _res->_types[rtInventory]._resources[i + 1]._address;
+ _res->_types[rtInventory]._resources[i]._size = _res->_types[rtInventory]._resources[i + 1]._size;
+ _res->_types[rtInventory]._resources[i + 1]._address = NULL;
+ _res->_types[rtInventory]._resources[i + 1]._size = 0;
}
}
break;
@@ -1799,7 +1799,7 @@ int ScummEngine::findLocalObjectSlot() {
int ScummEngine::findFlObjectSlot() {
int i;
for (i = 1; i < _numFlObject; i++) {
- if (_res->_types[rtFlObject]._address[i] == NULL)
+ if (_res->_types[rtFlObject]._resources[i]._address == NULL)
return i;
}
error("findFlObjectSlot: Out of FLObject slots");
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 3b278a6..8767e1b 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -83,8 +83,8 @@ void ScummEngine::openRoom(const int room) {
// Load the disk numer / room offs (special case for room 0 exists because
// room 0 contains the data which is used to create the roomno / roomoffs
// tables -- hence obviously we mustn't use those when loading room 0.
- const uint32 diskNumber = room ? _res->_types[rtRoom].roomno[room] : 0;
- const uint32 room_offs = room ? _res->_types[rtRoom].roomoffs[room] : 0;
+ const uint32 diskNumber = room ? _res->_types[rtRoom]._resources[room]._roomno : 0;
+ const uint32 room_offs = room ? _res->_types[rtRoom]._resources[room]._roomoffs : 0;
// FIXME: Since room_offs is const, clearly the following loop either
// is never entered, or loops forever (if it wasn't for the return/error
@@ -94,7 +94,7 @@ void ScummEngine::openRoom(const int room) {
while (room_offs != RES_INVALID_OFFSET) {
if (room_offs != 0 && room != 0 && _game.heversion < 98) {
- _fileOffset = _res->_types[rtRoom].roomoffs[room];
+ _fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
return;
}
@@ -122,7 +122,7 @@ void ScummEngine::openRoom(const int room) {
return;
deleteRoomOffsets();
readRoomsOffsets();
- _fileOffset = _res->_types[rtRoom].roomoffs[room];
+ _fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
if (_fileOffset != 8)
return;
@@ -157,8 +157,8 @@ void ScummEngine::closeRoom() {
/** Delete the currently loaded room offsets. */
void ScummEngine::deleteRoomOffsets() {
for (int i = 0; i < _numRooms; i++) {
- if (_res->_types[rtRoom].roomoffs[i] != RES_INVALID_OFFSET)
- _res->_types[rtRoom].roomoffs[i] = 0;
+ if (_res->_types[rtRoom]._resources[i]._roomoffs != RES_INVALID_OFFSET)
+ _res->_types[rtRoom]._resources[i]._roomoffs = 0;
}
}
@@ -174,8 +174,8 @@ void ScummEngine::readRoomsOffsets() {
while (num--) {
int room = _fileHandle->readByte();
int offset = _fileHandle->readUint32LE();
- if (_res->_types[rtRoom].roomoffs[room] != RES_INVALID_OFFSET) {
- _res->_types[rtRoom].roomoffs[room] = offset;
+ if (_res->_types[rtRoom]._resources[room]._roomoffs != RES_INVALID_OFFSET) {
+ _res->_types[rtRoom]._resources[room]._roomoffs = offset;
}
}
}
@@ -499,10 +499,10 @@ int ScummEngine::readResTypeList(int id) {
for (i = 0; i < num; i++) {
- _res->_types[id].roomno[i] = _fileHandle->readByte();
+ _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < num; i++) {
- _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
+ _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE();
}
return num;
@@ -516,11 +516,11 @@ int ScummEngine_v70he::readResTypeList(int id) {
if (id == rtRoom)
for (i = 0; i < num; i++) {
- _heV7RoomIntOffsets[i] = _res->_types[rtRoom].roomoffs[i];
+ _heV7RoomIntOffsets[i] = _res->_types[rtRoom]._resources[i]._roomoffs;
}
for (i = 0; i < num; i++) {
- _res->_types[id].globsize[i] = _fileHandle->readUint32LE();
+ _res->_types[id]._resources[i]._globsize = _fileHandle->readUint32LE();
}
return num;
@@ -536,11 +536,11 @@ void ResourceManager::allocResTypeData(int id, uint32 tag, int num, ResTypeMode
_types[id]._mode = mode;
_types[id]._num = num;
_types[id]._tag = tag;
- _types[id]._address = (byte **)calloc(num, sizeof(byte *));
- _types[id]._size = (uint32 *)calloc(num, sizeof(uint32));
- _types[id].flags = (byte *)calloc(num, sizeof(byte));
- _types[id]._status = (byte *)calloc(num, sizeof(byte));
+ _types[id]._resources.resize(num);
+/*
+ TODO: Use multiple Resource subclasses, one for each res mode; then,
+ given them serializability.
if (mode) {
_types[id].roomno = (byte *)calloc(num, sizeof(byte));
_types[id].roomoffs = (uint32 *)calloc(num, sizeof(uint32));
@@ -549,7 +549,7 @@ void ResourceManager::allocResTypeData(int id, uint32 tag, int num, ResTypeMode
if (_vm->_game.heversion >= 70) {
_types[id].globsize = (uint32 *)calloc(num, sizeof(uint32));
}
-
+*/
}
void ScummEngine::loadCharset(int no) {
@@ -604,7 +604,7 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
if (type != rtCharset && i == 0)
return;
- if (i <= _res->_types[type]._num && _res->_types[type]._address[i])
+ if (i <= _res->_types[type]._num && _res->_types[type]._resources[i]._address)
return;
loadResource(type, i);
@@ -690,27 +690,27 @@ int ScummEngine::loadResource(int type, int idx) {
int ScummEngine::getResourceRoomNr(int type, int idx) {
if (type == rtRoom && _game.heversion < 70)
return idx;
- return _res->_types[type].roomno[idx];
+ return _res->_types[type]._resources[idx]._roomno;
}
uint32 ScummEngine::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0;
}
- return _res->_types[type].roomoffs[idx];
+ return _res->_types[type]._resources[idx]._roomoffs;
}
uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return _heV7RoomIntOffsets[idx];
}
- return _res->_types[type].roomoffs[idx];
+ return _res->_types[type]._resources[idx]._roomoffs;
}
int ScummEngine::getResourceSize(int type, int idx) {
byte *ptr = getResourceAddress(type, idx);
assert(ptr);
- return _res->_types[type]._size[idx];
+ return _res->_types[type]._resources[idx]._size;
}
byte *ScummEngine::getResourceAddress(int type, int idx) {
@@ -722,17 +722,12 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
if (!_res->validateResource("getResourceAddress", type, idx))
return NULL;
- if (!_res->_types[type]._address) {
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->_types[type]._address == NULL", resTypeFromId(type), idx);
- return NULL;
- }
-
// If the resource is missing, but loadable from the game data files, try to do so.
- if (!_res->_types[type]._address[idx] && _res->_types[type]._mode != kDynamicResTypeMode) {
+ if (!_res->_types[type]._resources[idx]._address && _res->_types[type]._mode != kDynamicResTypeMode) {
ensureResourceLoaded(type, idx);
}
- ptr = (byte *)_res->_types[type]._address[idx];
+ ptr = (byte *)_res->_types[type]._resources[idx]._address;
if (!ptr) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
@@ -774,7 +769,7 @@ void ResourceManager::increaseResourceCounters() {
for (i = rtFirst; i <= rtLast; i++) {
for (j = _types[i]._num; --j >= 0;) {
- counter = _types[i].flags[j] & RF_USAGE;
+ counter = _types[i]._resources[j].getResourceCounter();
if (counter && counter < RF_USAGE_MAX) {
setResourceCounter(i, j, counter + 1);
}
@@ -783,8 +778,16 @@ void ResourceManager::increaseResourceCounters() {
}
void ResourceManager::setResourceCounter(int type, int idx, byte counter) {
- _types[type].flags[idx] &= RF_LOCK; // Clear lower 7 bits, preserve the lock bit.
- _types[type].flags[idx] |= counter; // Update the usage counter
+ _types[type]._resources[idx].setResourceCounter(counter);
+}
+
+void ResourceManager::Resource::setResourceCounter(byte counter) {
+ _flags &= RF_LOCK; // Clear lower 7 bits, preserve the lock bit.
+ _flags |= counter; // Update the usage counter
+}
+
+byte ResourceManager::Resource::getResourceCounter() const {
+ return _flags & RF_USAGE;
}
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
@@ -801,8 +804,8 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
// cases. For instance, Zak tries to reload the intro music
// while it's playing. See bug #1253171.
- if (_types[type]._address[idx] && (type == rtSound || type == rtScript || type == rtCostume))
- return _types[type]._address[idx];
+ if (_types[type]._resources[idx]._address && (type == rtSound || type == rtScript || type == rtCostume))
+ return _types[type]._resources[idx]._address;
}
nukeResource(type, idx);
@@ -816,14 +819,39 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
_allocatedSize += size;
- _types[type]._address[idx] = ptr;
- _types[type]._size[idx] = size;
+ _types[type]._resources[idx]._address = ptr;
+ _types[type]._resources[idx]._size = size;
setResourceCounter(type, idx, 1);
return ptr;
}
+ResourceManager::Resource::Resource() {
+ _address = 0;
+ _size = 0;
+ _flags = 0;
+ _status = 0;
+ _roomno = 0;
+ _roomoffs = 0;
+ _globsize = 0;
+}
+
+ResourceManager::Resource::~Resource() {
+ delete _address;
+ _address = 0;
+}
+
+void ResourceManager::Resource::nuke() {
+ delete _address;
+ _address = 0;
+ _size = 0;
+ _flags = 0;
+ _status &= ~RS_MODIFIED;
+}
+
ResourceManager::ResTypeData::ResTypeData() {
- memset(this, 0, sizeof(*this));
+ _mode = kDynamicResTypeMode;
+ _num = 0;
+ _tag = 0;
}
ResourceManager::ResTypeData::~ResTypeData() {
@@ -856,22 +884,11 @@ bool ResourceManager::validateResource(const char *str, int type, int idx) const
}
void ResourceManager::nukeResource(int type, int idx) {
- byte *ptr;
-
- if (!_types[type]._address)
- return;
-
- assert(idx >= 0 && idx < _types[type]._num);
-
- ptr = _types[type]._address[idx];
+ byte *ptr = _types[type]._resources[idx]._address;
if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
- _types[type]._address[idx] = 0;
- _types[type]._size[idx] = 0;
- _types[type].flags[idx] = 0;
- _types[type]._status[idx] &= ~RS_MODIFIED;
- _allocatedSize -= _types[type]._size[idx];
- free(ptr);
+ _allocatedSize -= _types[type]._resources[idx]._size;
+ _types[type]._resources[idx].nuke();
}
}
@@ -903,19 +920,31 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
void ResourceManager::lock(int type, int i) {
if (!validateResource("Locking", type, i))
return;
- _types[type].flags[i] |= RF_LOCK;
+ _types[type]._resources[i].lock();
}
void ResourceManager::unlock(int type, int i) {
if (!validateResource("Unlocking", type, i))
return;
- _types[type].flags[i] &= ~RF_LOCK;
+ _types[type]._resources[i].unlock();
}
bool ResourceManager::isLocked(int type, int i) const {
if (!validateResource("isLocked", type, i))
return false;
- return (_types[type].flags[i] & RF_LOCK) != 0;
+ return _types[type]._resources[i].isLocked();
+}
+
+void ResourceManager::Resource::lock() {
+ _flags |= RF_LOCK;
+}
+
+void ResourceManager::Resource::unlock() {
+ _flags &= ~RF_LOCK;
+}
+
+bool ResourceManager::Resource::isLocked() const {
+ return (_flags & RF_LOCK) != 0;
}
bool ScummEngine::isResourceInUse(int type, int i) const {
@@ -952,18 +981,25 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
void ResourceManager::setModified(int type, int i) {
if (!validateResource("Modified", type, i))
return;
- _types[type]._status[i] |= RS_MODIFIED;
+ _types[type]._resources[i].setModified();
}
bool ResourceManager::isModified(int type, int i) const {
if (!validateResource("isModified", type, i))
return false;
- return (_types[type]._status[i] & RS_MODIFIED) != 0;
+ return _types[type]._resources[i].isModified();
+}
+
+void ResourceManager::Resource::setModified() {
+ _status |= RS_MODIFIED;
+}
+
+bool ResourceManager::Resource::isModified() const {
+ return (_status & RS_MODIFIED) != 0;
}
void ResourceManager::expireResources(uint32 size) {
int i, j;
- byte flag;
byte best_counter;
int best_type, best_res = 0;
uint32 oldAllocatedSize;
@@ -987,9 +1023,10 @@ void ResourceManager::expireResources(uint32 size) {
// Resources of this type can be reloaded from the data files,
// so we can potentially unload them to free memory.
for (j = _types[i]._num; --j >= 0;) {
- flag = _types[i].flags[j];
- if (!(flag & RF_LOCK) && flag >= best_counter && _types[i]._address[j] && !_vm->isResourceInUse(i, j)) {
- best_counter = flag;
+ Resource &tmp = _types[i]._resources[j];
+ byte counter = tmp.getResourceCounter();
+ if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(i, j)) {
+ best_counter = counter;
best_type = i;
best_res = j;
}
@@ -1013,14 +1050,7 @@ void ResourceManager::freeResources() {
if (isResourceLoaded(i, j))
nukeResource(i, j);
}
- free(_types[i]._address);
- free(_types[i]._size);
- free(_types[i].flags);
- free(_types[i]._status);
- free(_types[i].roomno);
- free(_types[i].roomoffs);
-
- free(_types[i].globsize);
+ _types[i]._resources.clear();
}
}
@@ -1051,19 +1081,18 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
bool ResourceManager::isResourceLoaded(int type, int idx) const {
if (!validateResource("isResourceLoaded", type, idx))
return false;
- return _types[type]._address[idx] != NULL;
+ return _types[type]._resources[idx]._address != NULL;
}
void ResourceManager::resourceStats() {
int i, j;
uint32 lockedSize = 0, lockedNum = 0;
- byte flag;
for (i = rtFirst; i <= rtLast; i++)
for (j = _types[i]._num; --j >= 0;) {
- flag = _types[i].flags[j];
- if (flag & RF_LOCK && _types[i]._address[j]) {
- lockedSize += _types[i]._size[j];
+ Resource &tmp = _types[i]._resources[j];
+ if (tmp.isLocked() && tmp._address) {
+ lockedSize += tmp._size;
lockedNum++;
}
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 9685830..5aae49b 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -22,6 +22,7 @@
#ifndef SCUMM_RESOURCE_H
#define SCUMM_RESOURCE_H
+#include "common/array.h"
#include "scumm/scumm.h" // for rtNumTypes
namespace Scumm {
@@ -78,79 +79,97 @@ protected:
ScummEngine *_vm;
public:
- /**
- * This struct represents a resource type and all resource of that type.
- */
- class ResTypeData {
- friend class ResourceManager;
+ class Resource {
public:
- ResTypeMode _mode;
/**
- * The maximal number of resource of this type. Determines the size
- * of various arrays.
+ * Pointer to the data contained in this resource
*/
- uint16 _num;
+ byte *_address;
/**
- * The 4-byte tag or chunk type associated to this resource type, if any.
- * Only applies to resources that are loaded from the game data files.
+ * Size of this resource, i.e. of the data contained in it.
*/
- uint32 _tag;
+ uint32 _size;
+ protected:
/**
- * Array of size _num containing pointers to each resource of this type.
+ * The uppermost bit indicates whether the resources is locked.
+ * The lower 7 bits contain a counter. This counter measures roughly
+ * how old the resource is; it starts out with a count of 1 and can go
+ * as high as 127. When memory falls low resp. when the engine decides
+ * that it should throw out some unused stuff, then it begins by
+ * removing the resources with the highest counter (excluding locked
+ * resources and resources that are known to be in use).
*/
- byte **_address;
+ byte _flags;
/**
- * Array of size _num containing the sizes of each resource of this type.
+ * The status of the resource. Currently only one bit is used, which
+ * indicates whether the resource is modified.
*/
- uint32 *_size;
+ byte _status;
- protected:
+ public:
/**
- * Array of size _num containing some information on each resource of
- * this type.
- * First off, the uppermost bit indicates whether the resources is
- * locked into memory.
- * Secondly, the lower 7 bits contain a counter. This counter measures
- * roughly how old it is; a resource starts out with a count of 1 and
- * can go as high as 127. When memory falls low resp. when the engine
- * decides that it should throw out some unused stuff, then it begins
- * by removing the resources with the highest counter (excluding locked
- * resources and resources that are known to be in use).
+ * The id of the room (resp. the disk) the resource is contained in.
+ */
+ byte _roomno;
+
+ /**
+ * The offset (in bytes) where the data for this resources can be found
+ * in the game data file(s), relative to the start of the room the
+ * resource is contained in.
+ *
+ * A value of RES_INVALID_OFFSET indicates a resources that is not contained
+ * in the game data files.
*/
- byte *flags;
+ uint32 _roomoffs;
/**
- * Array of size _num containing the status of each resource of this type.
- * This is a bitfield of which currently only one bit is used, which indicates
- * whether the resource is modified.
+ * Occurs in HE 70+, but we don't use it for anything.
*/
- byte *_status;
+ uint32 _globsize;
public:
+ Resource();
+ ~Resource();
+
+ void nuke();
+
+ inline void setResourceCounter(byte counter);
+ inline byte getResourceCounter() const;
+
+ void lock();
+ void unlock();
+ bool isLocked() const;
+
+ void setModified();
+ bool isModified() const;
+ };
+
+ /**
+ * This struct represents a resource type and all resource of that type.
+ */
+ class ResTypeData {
+ friend class ResourceManager;
+ public:
+ ResTypeMode _mode;
/**
- * Array of size _num containing for each resource of this type the
- * id of the room (resp. the disk) the resource is contained in.
+ * The maximal number of resource of this type. Determines the size
+ * of various arrays.
*/
- byte *roomno;
+ uint16 _num;
/**
- * Array of size _num containing room offsets of each resource of this type.
- * That is the offset (in bytes) where the data for this resources
- * can be found in the game data file(s), relative to the start
- * of the room the resource is contained in.
- *
- * A value of RES_INVALID_OFFSET indicates a resources that is not contained
- * in the game data files.
+ * The 4-byte tag or chunk type associated to this resource type, if any.
+ * Only applies to resources that are loaded from the game data files.
*/
- uint32 *roomoffs;
+ uint32 _tag;
/**
- * Array of size _num. Occurs in HE 70+, but we don't use it for anything.
+ * Array of size _num containing pointers to each resource of this type.
*/
- uint32 *globsize;
+ Common::Array<Resource> _resources;
public:
ResTypeData();
@@ -175,6 +194,9 @@ public:
byte *createResource(int type, int idx, uint32 size);
void nukeResource(int type, int idx);
+ inline Resource &getRes(int type, int idx) { return _types[type]._resources[idx]; }
+ inline const Resource &getRes(int type, int idx) const { return _types[type]._resources[idx]; }
+
bool isResourceLoaded(int type, int idx) const;
void lock(int type, int idx);
diff --git a/engines/scumm/resource_v2.cpp b/engines/scumm/resource_v2.cpp
index f869248..38dfa7c 100644
--- a/engines/scumm/resource_v2.cpp
+++ b/engines/scumm/resource_v2.cpp
@@ -84,40 +84,40 @@ void ScummEngine_v2::readClassicIndexFile() {
}
for (i = 0; i < _numRooms; i++) {
- _res->_types[rtRoom].roomno[i] = i;
+ _res->_types[rtRoom]._resources[i]._roomno = i;
}
_fileHandle->seek(_numRooms, SEEK_CUR);
for (i = 0; i < _numRooms; i++) {
- _res->_types[rtRoom].roomoffs[i] = _fileHandle->readUint16LE();
- if (_res->_types[rtRoom].roomoffs[i] == 0xFFFF)
- _res->_types[rtRoom].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtRoom]._resources[i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtRoom]._resources[i]._roomoffs == 0xFFFF)
+ _res->_types[rtRoom]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numCostumes; i++) {
- _res->_types[rtCostume].roomno[i] = _fileHandle->readByte();
+ _res->_types[rtCostume]._resources[i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numCostumes; i++) {
- _res->_types[rtCostume].roomoffs[i] = _fileHandle->readUint16LE();
- if (_res->_types[rtCostume].roomoffs[i] == 0xFFFF)
- _res->_types[rtCostume].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtCostume]._resources[i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtCostume]._resources[i]._roomoffs == 0xFFFF)
+ _res->_types[rtCostume]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numScripts; i++) {
- _res->_types[rtScript].roomno[i] = _fileHandle->readByte();
+ _res->_types[rtScript]._resources[i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numScripts; i++) {
- _res->_types[rtScript].roomoffs[i] = _fileHandle->readUint16LE();
- if (_res->_types[rtScript].roomoffs[i] == 0xFFFF)
- _res->_types[rtScript].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtScript]._resources[i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtScript]._resources[i]._roomoffs == 0xFFFF)
+ _res->_types[rtScript]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numSounds; i++) {
- _res->_types[rtSound].roomno[i] = _fileHandle->readByte();
+ _res->_types[rtSound]._resources[i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numSounds; i++) {
- _res->_types[rtSound].roomoffs[i] = _fileHandle->readUint16LE();
- if (_res->_types[rtSound].roomoffs[i] == 0xFFFF)
- _res->_types[rtSound].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtSound]._resources[i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtSound]._resources[i]._roomoffs == 0xFFFF)
+ _res->_types[rtSound]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
}
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index 3a8b1dd..0f9f97a 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -44,16 +44,16 @@ int ScummEngine_v3old::readResTypeList(int id) {
if (id == rtRoom) {
for (i = 0; i < num; i++)
- _res->_types[id].roomno[i] = i;
+ _res->_types[id]._resources[i]._roomno = i;
_fileHandle->seek(num, SEEK_CUR);
} else {
for (i = 0; i < num; i++)
- _res->_types[id].roomno[i] = _fileHandle->readByte();
+ _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < num; i++) {
- _res->_types[id].roomoffs[i] = _fileHandle->readUint16LE();
- if (_res->_types[id].roomoffs[i] == 0xFFFF)
- _res->_types[id].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
+ _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[id]._resources[i]._roomoffs == 0xFFFF)
+ _res->_types[id]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
return num;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index 95eb8d4..e7e6d30 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -43,8 +43,8 @@ int ScummEngine_v4::readResTypeList(int id) {
}
for (i = 0; i < num; i++) {
- _res->_types[id].roomno[i] = _fileHandle->readByte();
- _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
+ _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
+ _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE();
}
return num;
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index d81095a..996e868 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -1247,7 +1247,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
s->saveUint16(type); // Save the res type...
for (idx = 0; idx < _res->_types[type]._num; idx++) {
// Only save resources which actually exist...
- if (_res->_types[type]._address[idx]) {
+ if (_res->_types[type]._resources[idx]._address) {
s->saveUint16(idx); // Save the index of the resource
saveResource(s, type, idx);
}
@@ -1663,11 +1663,11 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
}
void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
- assert(_res->_types[type]._address[idx]);
+ assert(_res->_types[type]._resources[idx]._address);
if (_res->_types[type]._mode == kDynamicResTypeMode) {
- byte *ptr = _res->_types[type]._address[idx];
- uint32 size = _res->_types[type]._size[idx];
+ byte *ptr = _res->_types[type]._resources[idx]._address;
+ uint32 size = _res->_types[type]._resources[idx]._size;
ser->saveUint32(size);
ser->saveBytes(ptr, size);
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index e418fcd..47cf8e0 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -390,7 +390,7 @@ void ScummEngine::getScriptBaseAddress() {
break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory);
- _lastCodePtr = &_res->_types[rtInventory]._address[idx];
+ _lastCodePtr = &_res->_types[rtInventory]._resources[idx]._address;
break;
case WIO_LOCAL:
@@ -398,18 +398,18 @@ void ScummEngine::getScriptBaseAddress() {
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
assert(_roomResource < _res->_types[rtRoomScripts]._num);
- _lastCodePtr = &_res->_types[rtRoomScripts]._address[_roomResource];
+ _lastCodePtr = &_res->_types[rtRoomScripts]._resources[_roomResource]._address;
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms);
- _lastCodePtr = &_res->_types[rtRoom]._address[_roomResource];
+ _lastCodePtr = &_res->_types[rtRoom]._resources[_roomResource]._address;
}
break;
case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts);
- _lastCodePtr = &_res->_types[rtScript]._address[ss->number];
+ _lastCodePtr = &_res->_types[rtScript]._resources[ss->number]._address;
break;
case WIO_FLOBJECT: /* flobject script */
@@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject);
- _lastCodePtr = &_res->_types[rtFlObject]._address[idx];
+ _lastCodePtr = &_res->_types[rtFlObject]._resources[idx]._address;
break;
default:
error("Bad type while getting base address");
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index 138da3f..341f6ec 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -357,11 +357,11 @@ void ScummEngine_v6::nukeArray(int a) {
}
int ScummEngine_v6::findFreeArrayId() {
- byte **addr = _res->_types[rtString]._address;
+ const ResourceManager::ResTypeData &rtd = _res->_types[rtString];
int i;
for (i = 1; i < _numArray; i++) {
- if (!addr[i])
+ if (!rtd._resources[i]._address)
return i;
}
error("Out of array pointers, %d max", _numArray);
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 21521d0..f0b6461 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1184,10 +1184,6 @@ Common::Error ScummEngine::init() {
resetScumm();
resetScummVars();
- if (_imuse) {
- _imuse->setBase(_res->_types[rtSound]._address);
- }
-
if (_game.version >= 5 && _game.version <= 7)
_sound->setupSound();
@@ -2461,10 +2457,6 @@ void ScummEngine::restart() {
resetScumm();
resetScummVars();
- if (_imuse) {
- _imuse->setBase(_res->_types[rtSound]._address);
- }
-
// Reinit sound engine
if (_game.version >= 5 && _game.version <= 7)
_sound->setupSound();
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index f5068e7..4a136f6 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -1224,7 +1224,7 @@ int ScummEngine::readSoundResource(int idx) {
if (!dmuFile.open(buffer)) {
error("Can't open music file %s", buffer);
- _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
dmuFile.seek(4, SEEK_SET);
@@ -1248,7 +1248,7 @@ int ScummEngine::readSoundResource(int idx) {
}
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
}
- _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
@@ -2123,7 +2123,7 @@ int ScummEngine::readSoundResourceSmallHeader(int idx) {
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
return 1;
}
- _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
+ _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
Commit: aaf2c0e6ebe373afd06cbf8ebca334710a4ed15d
https://github.com/scummvm/scummvm/commit/aaf2c0e6ebe373afd06cbf8ebca334710a4ed15d
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T02:47:13-07:00
Commit Message:
TSAGE: Fix warning when compiling in release mode
Changed paths:
engines/tsage/saveload.h
diff --git a/engines/tsage/saveload.h b/engines/tsage/saveload.h
index 611e5b3..a04bba2 100644
--- a/engines/tsage/saveload.h
+++ b/engines/tsage/saveload.h
@@ -115,7 +115,7 @@ template<typename T>
class SynchronizedList : public Common::List<T> {
public:
void synchronize(Serializer &s) {
- int entryCount;
+ int entryCount = 0;
if (s.isLoading()) {
this->clear();
Commit: 649f8e0a84804a9d1272ba16b146ea2b9da501fe
https://github.com/scummvm/scummvm/commit/649f8e0a84804a9d1272ba16b146ea2b9da501fe
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:02:53-07:00
Commit Message:
SCUMM: Rename ResTypes->ResType, introduce ResId typedef, change code to use both
Changed paths:
engines/scumm/he/intern_he.h
engines/scumm/he/resource_he.cpp
engines/scumm/he/script_v100he.cpp
engines/scumm/he/script_v72he.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v3.cpp
engines/scumm/resource_v4.cpp
engines/scumm/saveload.cpp
engines/scumm/script_v2.cpp
engines/scumm/script_v5.cpp
engines/scumm/scumm.h
engines/scumm/scumm_v3.h
engines/scumm/scumm_v4.h
engines/scumm/scumm_v6.h
engines/scumm/sound.cpp
diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h
index e1d7bee..c49217b 100644
--- a/engines/scumm/he/intern_he.h
+++ b/engines/scumm/he/intern_he.h
@@ -129,8 +129,8 @@ public:
protected:
virtual void allocateArrays();
- virtual int readResTypeList(int id);
- virtual uint32 getResourceRoomOffset(int type, int idx);
+ virtual int readResTypeList(ResType type);
+ virtual uint32 getResourceRoomOffset(ResType type, ResId idx);
virtual void setupOpcodes();
virtual void setupScummVars();
@@ -265,7 +265,7 @@ protected:
virtual void resetScummVars();
virtual void readArrayFromIndexFile();
- virtual byte *getStringAddress(int i);
+ virtual byte *getStringAddress(ResId idx);
virtual void readMAXS(int blockSize);
virtual void redrawBGAreas();
@@ -289,7 +289,7 @@ protected:
void copyScriptString(byte *dst, int dstSize);
int findObject(int x, int y, int num, int *args);
- int getSoundResourceSize(int id);
+ int getSoundResourceSize(ResId idx);
virtual bool handleNextCharsetCode(Actor *a, int *c);
virtual int convertMessageToString(const byte *msg, byte *dst, int dstSize);
@@ -554,7 +554,8 @@ protected:
class ScummEngine_v100he : public ScummEngine_v99he {
protected:
- int32 _heResId, _heResType;
+ ResType _heResType;
+ int32 _heResId;
byte _debugInputBuffer[256];
public:
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index 70b5543..1dce01a 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -341,14 +341,14 @@ void ScummEngine_v72he::readMAXS(int blockSize) {
ScummEngine_v6::readMAXS(blockSize);
}
-byte *ScummEngine_v72he::getStringAddress(int i) {
- byte *addr = getResourceAddress(rtString, i);
+byte *ScummEngine_v72he::getStringAddress(ResId idx) {
+ byte *addr = getResourceAddress(rtString, idx);
if (addr == NULL)
return NULL;
return ((ScummEngine_v72he::ArrayHeader *)addr)->data;
}
-int ScummEngine_v72he::getSoundResourceSize(int id) {
+int ScummEngine_v72he::getSoundResourceSize(ResId id) {
const byte *ptr;
int offs, size;
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index 8ff28a1..b6f9294 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -2380,7 +2380,8 @@ void ScummEngine_v100he::o100_isResourceLoaded() {
void ScummEngine_v100he::o100_getResourceSize() {
const byte *ptr;
- int size, type;
+ int size;
+ ResType type;
int resid = pop();
byte subOp = fetchScriptByte();
@@ -2399,7 +2400,7 @@ void ScummEngine_v100he::o100_getResourceSize() {
type = rtScript;
break;
case 72:
- push (getSoundResourceSize(resid));
+ push(getSoundResourceSize(resid));
return;
default:
error("o100_getResourceSize: default type %d", subOp);
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index dfcfa32..0e25fe4 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -1911,7 +1911,8 @@ void ScummEngine_v72he::o72_writeINI() {
void ScummEngine_v72he::o72_getResourceSize() {
const byte *ptr;
- int size, type;
+ int size;
+ ResType type;
int resid = pop();
if (_game.heversion == 72) {
@@ -1923,7 +1924,7 @@ void ScummEngine_v72he::o72_getResourceSize() {
switch (subOp) {
case 13:
- push (getSoundResourceSize(resid));
+ push(getSoundResourceSize(resid));
return;
case 14:
type = rtRoomImage;
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 8767e1b..2eedf5e 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -52,7 +52,7 @@ enum {
-extern const char *resTypeFromId(int id);
+extern const char *resTypeFromId(int type);
static uint16 newTag2Old(uint32 newTag);
static const byte *findResourceSmall(uint32 tag, const byte *searchin);
@@ -482,72 +482,72 @@ void ScummEngine::readArrayFromIndexFile() {
error("readArrayFromIndexFile() not supported in pre-V6 games");
}
-int ScummEngine::readResTypeList(int id) {
- int num;
- int i;
+int ScummEngine::readResTypeList(ResType type) {
+ uint num;
+ ResId idx;
if (_game.version == 8)
num = _fileHandle->readUint32LE();
else
num = _fileHandle->readUint16LE();
- if (num != _res->_types[id]._num) {
- error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
+ if (num != _res->_types[type]._num) {
+ error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num);
}
- debug(2, " readResTypeList(%s): %d entries", resTypeFromId(id), num);
+ debug(2, " readResTypeList(%s): %d entries", resTypeFromId(type), num);
- for (i = 0; i < num; i++) {
- _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
+ for (idx = 0; idx < num; idx++) {
+ _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
}
- for (i = 0; i < num; i++) {
- _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE();
+ for (idx = 0; idx < num; idx++) {
+ _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
}
return num;
}
-int ScummEngine_v70he::readResTypeList(int id) {
- int num;
- int i;
+int ScummEngine_v70he::readResTypeList(ResType type) {
+ uint num;
+ ResId idx;
- num = ScummEngine::readResTypeList(id);
+ num = ScummEngine::readResTypeList(type);
- if (id == rtRoom)
- for (i = 0; i < num; i++) {
- _heV7RoomIntOffsets[i] = _res->_types[rtRoom]._resources[i]._roomoffs;
+ if (type == rtRoom)
+ for (idx = 0; idx < num; idx++) {
+ _heV7RoomIntOffsets[idx] = _res->_types[rtRoom]._resources[idx]._roomoffs;
}
- for (i = 0; i < num; i++) {
- _res->_types[id]._resources[i]._globsize = _fileHandle->readUint32LE();
+ for (idx = 0; idx < num; idx++) {
+ _res->_types[type]._resources[idx]._globsize = _fileHandle->readUint32LE();
}
return num;
}
-void ResourceManager::allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode) {
- debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(id), tag2str(TO_BE_32(tag)), num, mode);
- assert(id >= 0 && id < (int)(ARRAYSIZE(_types)));
+void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode) {
+ debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(type), tag2str(TO_BE_32(tag)), num, mode);
+ assert(type >= 0 && type < (int)(ARRAYSIZE(_types)));
if (num >= 8000)
- error("Too many %s resources (%d) in directory", resTypeFromId(id), num);
+ error("Too many %s resources (%d) in directory", resTypeFromId(type), num);
- _types[id]._mode = mode;
- _types[id]._num = num;
- _types[id]._tag = tag;
- _types[id]._resources.resize(num);
+ _types[type]._mode = mode;
+ _types[type]._num = num;
+ _types[type]._tag = tag;
+ _types[type]._resources.resize(num);
/*
TODO: Use multiple Resource subclasses, one for each res mode; then,
given them serializability.
if (mode) {
- _types[id].roomno = (byte *)calloc(num, sizeof(byte));
- _types[id].roomoffs = (uint32 *)calloc(num, sizeof(uint32));
+ _types[type].roomno = (byte *)calloc(num, sizeof(byte));
+ _types[type].roomoffs = (uint32 *)calloc(num, sizeof(uint32));
}
if (_vm->_game.heversion >= 70) {
- _types[id].globsize = (uint32 *)calloc(num, sizeof(uint32));
+ _types[type].globsize = (uint32 *)calloc(num, sizeof(uint32));
}
*/
}
@@ -583,14 +583,14 @@ void ScummEngine::nukeCharset(int i) {
_res->nukeResource(rtCharset, i);
}
-void ScummEngine::ensureResourceLoaded(int type, int i) {
- debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
+void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
+ debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), idx);
- if ((type == rtRoom) && i > 0x7F && _game.version < 7 && _game.heversion <= 71) {
- i = _resourceMapper[i & 0x7F];
+ if ((type == rtRoom) && idx > 0x7F && _game.version < 7 && _game.heversion <= 71) {
+ idx = _resourceMapper[idx & 0x7F];
}
- // FIXME: This check used to be "i==0". However, that causes
+ // FIXME: This check used to be "idx==0". However, that causes
// problems when using this function to ensure charset 0 is loaded.
// This is done for many games, e.g. Zak256 or Indy3 (EGA and VGA).
// For now we restrict the check to anything which is not a charset.
@@ -601,19 +601,19 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
// our code base? After all we also have to add special cases for many
// of our script opcodes that check for the (invalid) actor 0... so
// maybe both issues are related...
- if (type != rtCharset && i == 0)
+ if (type != rtCharset && idx == 0)
return;
- if (i <= _res->_types[type]._num && _res->_types[type]._resources[i]._address)
+ if (idx <= _res->_types[type]._num && _res->_types[type]._resources[idx]._address)
return;
- loadResource(type, i);
+ loadResource(type, idx);
- if (_game.version == 5 && type == rtRoom && i == _roomResource)
+ if (_game.version == 5 && type == rtRoom && (int)idx == _roomResource)
VAR(VAR_ROOM_FLAG) = 1;
}
-int ScummEngine::loadResource(int type, int idx) {
+int ScummEngine::loadResource(ResType type, ResId idx) {
int roomNr;
uint32 fileOffs;
uint32 size, tag;
@@ -687,33 +687,33 @@ int ScummEngine::loadResource(int type, int idx) {
return 1;
}
-int ScummEngine::getResourceRoomNr(int type, int idx) {
+int ScummEngine::getResourceRoomNr(ResType type, ResId idx) {
if (type == rtRoom && _game.heversion < 70)
return idx;
return _res->_types[type]._resources[idx]._roomno;
}
-uint32 ScummEngine::getResourceRoomOffset(int type, int idx) {
+uint32 ScummEngine::getResourceRoomOffset(ResType type, ResId idx) {
if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0;
}
return _res->_types[type]._resources[idx]._roomoffs;
}
-uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
+uint32 ScummEngine_v70he::getResourceRoomOffset(ResType type, ResId idx) {
if (type == rtRoom) {
return _heV7RoomIntOffsets[idx];
}
return _res->_types[type]._resources[idx]._roomoffs;
}
-int ScummEngine::getResourceSize(int type, int idx) {
+int ScummEngine::getResourceSize(ResType type, ResId idx) {
byte *ptr = getResourceAddress(type, idx);
assert(ptr);
return _res->_types[type]._resources[idx]._size;
}
-byte *ScummEngine::getResourceAddress(int type, int idx) {
+byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
byte *ptr;
if (_game.heversion >= 80 && type == rtString)
@@ -739,13 +739,13 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
return ptr;
}
-byte *ScummEngine::getStringAddress(int i) {
- byte *addr = getResourceAddress(rtString, i);
+byte *ScummEngine::getStringAddress(ResId idx) {
+ byte *addr = getResourceAddress(rtString, idx);
return addr;
}
-byte *ScummEngine_v6::getStringAddress(int i) {
- byte *addr = getResourceAddress(rtString, i);
+byte *ScummEngine_v6::getStringAddress(ResId idx) {
+ byte *addr = getResourceAddress(rtString, idx);
if (addr == NULL)
return NULL;
// Skip over the ArrayHeader
@@ -764,20 +764,18 @@ void ResourceManager::increaseExpireCounter() {
}
void ResourceManager::increaseResourceCounters() {
- int i, j;
- byte counter;
-
- for (i = rtFirst; i <= rtLast; i++) {
- for (j = _types[i]._num; --j >= 0;) {
- counter = _types[i]._resources[j].getResourceCounter();
+ for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
+ ResId idx = _types[type]._num;
+ while (idx-- > 0) {
+ byte counter = _types[type]._resources[idx].getResourceCounter();
if (counter && counter < RF_USAGE_MAX) {
- setResourceCounter(i, j, counter + 1);
+ setResourceCounter(type, idx, counter + 1);
}
}
}
}
-void ResourceManager::setResourceCounter(int type, int idx, byte counter) {
+void ResourceManager::setResourceCounter(ResType type, ResId idx, byte counter) {
_types[type]._resources[idx].setResourceCounter(counter);
}
@@ -793,7 +791,7 @@ byte ResourceManager::Resource::getResourceCounter() const {
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
#define SAFETY_AREA 2
-byte *ResourceManager::createResource(int type, int idx, uint32 size) {
+byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
debugC(DEBUG_RESOURCE, "_res->createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
if (!validateResource("allocating", type, idx))
@@ -875,15 +873,15 @@ void ResourceManager::setHeapThreshold(int min, int max) {
_minHeapThreshold = min;
}
-bool ResourceManager::validateResource(const char *str, int type, int idx) const {
- if (type < rtFirst || type > rtLast || (uint) idx >= (uint)_types[type]._num) {
+bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const {
+ if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._num) {
error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
return false;
}
return true;
}
-void ResourceManager::nukeResource(int type, int idx) {
+void ResourceManager::nukeResource(ResType type, ResId idx) {
byte *ptr = _types[type]._resources[idx]._address;
if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
@@ -917,22 +915,22 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
return READ_BE_UINT32(ptr - 4) - _resourceHeaderSize;
}
-void ResourceManager::lock(int type, int i) {
- if (!validateResource("Locking", type, i))
+void ResourceManager::lock(ResType type, ResId idx) {
+ if (!validateResource("Locking", type, idx))
return;
- _types[type]._resources[i].lock();
+ _types[type]._resources[idx].lock();
}
-void ResourceManager::unlock(int type, int i) {
- if (!validateResource("Unlocking", type, i))
+void ResourceManager::unlock(ResType type, ResId idx) {
+ if (!validateResource("Unlocking", type, idx))
return;
- _types[type]._resources[i].unlock();
+ _types[type]._resources[idx].unlock();
}
-bool ResourceManager::isLocked(int type, int i) const {
- if (!validateResource("isLocked", type, i))
+bool ResourceManager::isLocked(ResType type, ResId idx) const {
+ if (!validateResource("isLocked", type, idx))
return false;
- return _types[type]._resources[i].isLocked();
+ return _types[type]._resources[idx].isLocked();
}
void ResourceManager::Resource::lock() {
@@ -947,47 +945,47 @@ bool ResourceManager::Resource::isLocked() const {
return (_flags & RF_LOCK) != 0;
}
-bool ScummEngine::isResourceInUse(int type, int i) const {
- if (!_res->validateResource("isResourceInUse", type, i))
+bool ScummEngine::isResourceInUse(ResType type, ResId idx) const {
+ if (!_res->validateResource("isResourceInUse", type, idx))
return false;
switch (type) {
case rtRoom:
- return _roomResource == (byte)i;
+ return _roomResource == (byte)idx;
case rtRoomImage:
- return _roomResource == (byte)i;
+ return _roomResource == (byte)idx;
case rtRoomScripts:
- return _roomResource == (byte)i;
+ return _roomResource == (byte)idx;
case rtScript:
- return isScriptInUse(i);
+ return isScriptInUse(idx);
case rtCostume:
- return isCostumeInUse(i);
+ return isCostumeInUse(idx);
case rtSound:
// Sound resource 1 is used for queued speech
- if (_game.heversion >= 60 && i == 1)
+ if (_game.heversion >= 60 && idx == 1)
return true;
else
- return _sound->isSoundInUse(i);
+ return _sound->isSoundInUse(idx);
case rtCharset:
- return _charset->getCurID() == i;
+ return _charset->getCurID() == (int)idx;
case rtImage:
- return _res->isModified(type, i) != 0;
+ return _res->isModified(type, idx) != 0;
case rtSpoolBuffer:
- return _sound->isSoundRunning(10000 + i) != 0;
+ return _sound->isSoundRunning(10000 + idx) != 0;
default:
return false;
}
}
-void ResourceManager::setModified(int type, int i) {
- if (!validateResource("Modified", type, i))
+void ResourceManager::setModified(ResType type, ResId idx) {
+ if (!validateResource("Modified", type, idx))
return;
- _types[type]._resources[i].setModified();
+ _types[type]._resources[idx].setModified();
}
-bool ResourceManager::isModified(int type, int i) const {
- if (!validateResource("isModified", type, i))
+bool ResourceManager::isModified(ResType type, ResId idx) const {
+ if (!validateResource("isModified", type, idx))
return false;
- return _types[type]._resources[i].isModified();
+ return _types[type]._resources[idx].isModified();
}
void ResourceManager::Resource::setModified() {
@@ -999,9 +997,9 @@ bool ResourceManager::Resource::isModified() const {
}
void ResourceManager::expireResources(uint32 size) {
- int i, j;
byte best_counter;
- int best_type, best_res = 0;
+ ResType best_type;
+ int best_res = 0;
uint32 oldAllocatedSize;
if (_expireCounter != 0xFF) {
@@ -1015,23 +1013,25 @@ void ResourceManager::expireResources(uint32 size) {
oldAllocatedSize = _allocatedSize;
do {
- best_type = 0;
+ best_type = rtInvalid;
best_counter = 2;
- for (i = rtFirst; i <= rtLast; i++)
- if (_types[i]._mode != kDynamicResTypeMode) {
+ for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
+ if (_types[type]._mode != kDynamicResTypeMode) {
// Resources of this type can be reloaded from the data files,
// so we can potentially unload them to free memory.
- for (j = _types[i]._num; --j >= 0;) {
- Resource &tmp = _types[i]._resources[j];
+ ResId idx = _types[type]._num;
+ while (idx-- > 0) {
+ Resource &tmp = _types[type]._resources[idx];
byte counter = tmp.getResourceCounter();
- if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(i, j)) {
+ if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(type, idx)) {
best_counter = counter;
- best_type = i;
- best_res = j;
+ best_type = type;
+ best_res = idx;
}
}
}
+ }
if (!best_type)
break;
@@ -1044,28 +1044,27 @@ void ResourceManager::expireResources(uint32 size) {
}
void ResourceManager::freeResources() {
- int i, j;
- for (i = rtFirst; i <= rtLast; i++) {
- for (j = _types[i]._num; --j >= 0;) {
- if (isResourceLoaded(i, j))
- nukeResource(i, j);
+ for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
+ ResId idx = _types[type]._num;
+ while (idx-- > 0) {
+ if (isResourceLoaded(type, idx))
+ nukeResource(type, idx);
}
- _types[i]._resources.clear();
+ _types[type]._resources.clear();
}
}
-void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source) {
+void ScummEngine::loadPtrToResource(ResType type, ResId idx, const byte *source) {
byte *alloced;
int len;
- _res->nukeResource(type, resindex);
+ _res->nukeResource(type, idx);
len = resStrLen(source) + 1;
-
if (len <= 0)
return;
- alloced = _res->createResource(type, resindex, len);
+ alloced = _res->createResource(type, idx, len);
if (!source) {
// Need to refresh the script pointer, since createResource may
@@ -1078,24 +1077,25 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
}
}
-bool ResourceManager::isResourceLoaded(int type, int idx) const {
+bool ResourceManager::isResourceLoaded(ResType type, ResId idx) const {
if (!validateResource("isResourceLoaded", type, idx))
return false;
return _types[type]._resources[idx]._address != NULL;
}
void ResourceManager::resourceStats() {
- int i, j;
uint32 lockedSize = 0, lockedNum = 0;
- for (i = rtFirst; i <= rtLast; i++)
- for (j = _types[i]._num; --j >= 0;) {
- Resource &tmp = _types[i]._resources[j];
+ for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
+ ResId idx = _types[type]._num;
+ while (idx-- > 0) {
+ Resource &tmp = _types[type]._resources[idx];
if (tmp.isLocked() && tmp._address) {
lockedSize += tmp._size;
lockedNum++;
}
}
+ }
debug(1, "Total allocated size=%d, locked=%d(%d)", _allocatedSize, lockedSize, lockedNum);
}
@@ -1340,7 +1340,7 @@ void ScummEngine_v70he::allocateArrays() {
}
-void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
+void ScummEngine::dumpResource(const char *tag, int id, const byte *ptr, int length) {
char buf[256];
Common::DumpFile out;
@@ -1354,7 +1354,7 @@ void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int le
else
size = READ_BE_UINT32(ptr + 4);
- sprintf(buf, "dumps/%s%d.dmp", tag, idx);
+ sprintf(buf, "dumps/%s%d.dmp", tag, id);
out.open(buf);
if (out.isOpen() == false)
@@ -1523,10 +1523,10 @@ uint16 newTag2Old(uint32 newTag) {
}
}
-const char *resTypeFromId(int id) {
+const char *resTypeFromId(int type) {
static char buf[100];
- switch (id) {
+ switch (type) {
case rtRoom:
return "Room";
case rtScript:
@@ -1569,10 +1569,8 @@ const char *resTypeFromId(int id) {
return "Talkie";
case rtSpoolBuffer:
return "SpoolBuffer";
- case rtNumTypes:
- return "NumTypes";
default:
- sprintf(buf, "%d", id);
+ sprintf(buf, "rt%d", type);
return buf;
}
}
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 5aae49b..15aed24 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -23,7 +23,7 @@
#define SCUMM_RESOURCE_H
#include "common/array.h"
-#include "scumm/scumm.h" // for rtNumTypes
+#include "scumm/scumm.h" // for ResType
namespace Scumm {
@@ -175,7 +175,7 @@ public:
ResTypeData();
~ResTypeData();
};
- ResTypeData _types[rtNumTypes];
+ ResTypeData _types[rtLast + 1];
protected:
uint32 _allocatedSize;
@@ -188,23 +188,23 @@ public:
void setHeapThreshold(int min, int max);
- void allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode);
+ void allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode);
void freeResources();
- byte *createResource(int type, int idx, uint32 size);
- void nukeResource(int type, int idx);
+ byte *createResource(ResType type, ResId idx, uint32 size);
+ void nukeResource(ResType type, ResId idx);
- inline Resource &getRes(int type, int idx) { return _types[type]._resources[idx]; }
- inline const Resource &getRes(int type, int idx) const { return _types[type]._resources[idx]; }
+// inline Resource &getRes(ResType type, ResId idx) { return _types[type]._resources[idx]; }
+// inline const Resource &getRes(ResType type, ResId idx) const { return _types[type]._resources[idx]; }
- bool isResourceLoaded(int type, int idx) const;
+ bool isResourceLoaded(ResType type, ResId idx) const;
- void lock(int type, int idx);
- void unlock(int type, int idx);
- bool isLocked(int type, int idx) const;
+ void lock(ResType type, ResId idx);
+ void unlock(ResType type, ResId idx);
+ bool isLocked(ResType type, ResId idx) const;
- void setModified(int type, int idx);
- bool isModified(int type, int idx) const;
+ void setModified(ResType type, ResId idx);
+ bool isModified(ResType type, ResId idx) const;
/**
* This method increments the _expireCounter, and if it overflows (which happens
@@ -216,7 +216,7 @@ public:
/**
* Update the specified resource's counter.
*/
- void setResourceCounter(int type, int idx, byte counter);
+ void setResourceCounter(ResType type, ResId idx, byte counter);
/**
* Increment the counter of all unlocked loaded resources.
@@ -229,7 +229,7 @@ public:
void resourceStats();
//protected:
- bool validateResource(const char *str, int type, int idx) const;
+ bool validateResource(const char *str, ResType type, ResId idx) const;
protected:
void expireResources(uint32 size);
};
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index 0f9f97a..f422f82 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -30,30 +30,30 @@ namespace Scumm {
extern const char *resTypeFromId(int id);
-int ScummEngine_v3old::readResTypeList(int id) {
- int num;
- int i;
+int ScummEngine_v3old::readResTypeList(ResType type) {
+ uint num;
+ ResId idx;
- debug(9, "readResTypeList(%s)", resTypeFromId(id));
+ debug(9, "readResTypeList(%s)", resTypeFromId(type));
num = _fileHandle->readByte();
if (num >= 0xFF) {
- error("Too many %ss (%d) in directory", resTypeFromId(id), num);
+ error("Too many %ss (%d) in directory", resTypeFromId(type), num);
}
- if (id == rtRoom) {
- for (i = 0; i < num; i++)
- _res->_types[id]._resources[i]._roomno = i;
+ if (type == rtRoom) {
+ for (idx = 0; idx < num; idx++)
+ _res->_types[type]._resources[idx]._roomno = idx;
_fileHandle->seek(num, SEEK_CUR);
} else {
- for (i = 0; i < num; i++)
- _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
+ for (idx = 0; idx < num; idx++)
+ _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
}
- for (i = 0; i < num; i++) {
- _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[id]._resources[i]._roomoffs == 0xFFFF)
- _res->_types[id]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ for (idx = 0; idx < num; idx++) {
+ _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[type]._resources[idx]._roomoffs == 0xFFFF)
+ _res->_types[type]._resources[idx]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
return num;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index e7e6d30..d062fe1 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -30,21 +30,20 @@ namespace Scumm {
extern const char *resTypeFromId(int id);
-int ScummEngine_v4::readResTypeList(int id) {
- int num;
- int i;
+int ScummEngine_v4::readResTypeList(ResType type) {
+ uint num;
- debug(9, "readResTypeList(%s)", resTypeFromId(id));
+ debug(9, "readResTypeList(%s)", resTypeFromId(type));
num = _fileHandle->readUint16LE();
- if (num != _res->_types[id]._num) {
- error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
+ if (num != _res->_types[type]._num) {
+ error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num);
}
- for (i = 0; i < num; i++) {
- _res->_types[id]._resources[i]._roomno = _fileHandle->readByte();
- _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE();
+ for (ResId idx = 0; idx < num; idx++) {
+ _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
+ _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
}
return num;
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 996e868..f37ca36 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -311,7 +311,6 @@ static bool loadSaveGameHeader(Common::SeekableReadStream *in, SaveGameHeader &h
bool ScummEngine::loadState(int slot, bool compat) {
Common::String filename;
Common::SeekableReadStream *in;
- int i, j;
SaveGameHeader hdr;
int sb, sh;
@@ -426,10 +425,10 @@ bool ScummEngine::loadState(int slot, bool compat) {
memset(gfxUsageBits, 0, sizeof(gfxUsageBits));
// Nuke all resources
- for (i = rtFirst; i <= rtLast; i++)
- if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat))
- for (j = 0; j < _res->_types[i]._num; j++) {
- _res->nukeResource(i, j);
+ for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1))
+ if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat))
+ for (ResId idx = 0; idx < _res->_types[type]._num; idx++) {
+ _res->nukeResource(type, idx);
}
resetScummVars();
@@ -517,8 +516,8 @@ bool ScummEngine::loadState(int slot, bool compat) {
// loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items
- for (i = 1; i < _res->_types[rtScaleTable]._num; i++) {
- convertScaleTableToScaleSlot(i);
+ for (ResId idx = 1; idx < _res->_types[rtScaleTable]._num; idx++) {
+ convertScaleTableToScaleSlot(idx);
}
}
@@ -1116,7 +1115,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
MKEND()
};
- int i, j;
+ int i;
int var120Backup;
int var98Backup;
uint8 md5Backup[16];
@@ -1134,9 +1133,9 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// MD5 Operations: Backup on load, compare, and reset.
if (s->isLoading()) {
char md5str1[32+1], md5str2[32+1];
- for (j = 0; j < 16; j++) {
- sprintf(md5str1 + j*2, "%02x", (int)_gameMD5[j]);
- sprintf(md5str2 + j*2, "%02x", (int)md5Backup[j]);
+ for (i = 0; i < 16; i++) {
+ sprintf(md5str1 + i*2, "%02x", (int)_gameMD5[i]);
+ sprintf(md5str2 + i*2, "%02x", (int)md5Backup[i]);
}
debug(2, "Save version: %d", s->getVersion());
@@ -1236,13 +1235,14 @@ void ScummEngine::saveOrLoad(Serializer *s) {
//
// Save/load resources
//
- int type, idx;
+ ResType type;
+ ResId idx;
if (s->getVersion() >= VER(26)) {
// New, more robust resource save/load system. This stores the type
// and index of each resource. Thus if we increase e.g. the maximum
// number of script resources, savegames won't break.
if (s->isSaving()) {
- for (type = rtFirst; type <= rtLast; type++) {
+ for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
for (idx = 0; idx < _res->_types[type]._num; idx++) {
@@ -1257,9 +1257,9 @@ void ScummEngine::saveOrLoad(Serializer *s) {
}
s->saveUint16(0xFFFF); // End marker
} else {
- while ((type = s->loadUint16()) != 0xFFFF) {
+ while ((type = (ResType)s->loadUint16()) != 0xFFFF) {
while ((idx = s->loadUint16()) != 0xFFFF) {
- assert(0 <= idx && idx < _res->_types[type]._num);
+ assert(idx < _res->_types[type]._num);
loadResource(s, type, idx);
}
}
@@ -1268,7 +1268,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// Old, fragile resource save/load system. Doesn't save resources
// with index 0, and breaks whenever we change the limit on a given
// resource type.
- for (type = rtFirst; type <= rtLast; type++)
+ for (type = rtFirst; type <= rtLast; type = ResType(type + 1))
if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
// For V1-V5 games, there used to be no object name resources.
// At some point this changed. But since old savegames rely on
@@ -1387,18 +1387,18 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// Save/load a list of the locked objects
//
if (s->isSaving()) {
- for (i = rtFirst; i <= rtLast; i++)
- for (j = 1; j < _res->_types[i]._num; j++) {
- if (_res->isLocked(i, j)) {
- s->saveByte(i);
- s->saveUint16(j);
+ for (type = rtFirst; type <= rtLast; type = ResType(type + 1))
+ for (idx = 1; idx < _res->_types[type]._num; idx++) {
+ if (_res->isLocked(type, idx)) {
+ s->saveByte(type);
+ s->saveUint16(idx);
}
}
s->saveByte(0xFF);
} else {
- while ((i = s->loadByte()) != 0xFF) {
- j = s->loadUint16();
- _res->lock(i, j);
+ while ((type = (ResType)s->loadByte()) != 0xFF) {
+ idx = s->loadUint16();
+ _res->lock(type, idx);
}
}
@@ -1633,7 +1633,7 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) {
}
#endif
-void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
+void ScummEngine::loadResourceOLD(Serializer *ser, ResType type, ResId idx) {
uint32 size;
if (type == rtSound && ser->getVersion() >= VER(23)) {
@@ -1662,7 +1662,7 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) {
}
}
-void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
+void ScummEngine::saveResource(Serializer *ser, ResType type, ResId idx) {
assert(_res->_types[type]._resources[idx]._address);
if (_res->_types[type]._mode == kDynamicResTypeMode) {
@@ -1681,7 +1681,7 @@ void ScummEngine::saveResource(Serializer *ser, int type, int idx) {
}
}
-void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
+void ScummEngine::loadResource(Serializer *ser, ResType type, ResId idx) {
if (_game.heversion >= 60 && ser->getVersion() <= VER(65) &&
((type == rtSound && idx == 1) || (type == rtSpoolBuffer))) {
uint32 size = ser->loadUint32();
diff --git a/engines/scumm/script_v2.cpp b/engines/scumm/script_v2.cpp
index f7d4e74..7f02e89 100644
--- a/engines/scumm/script_v2.cpp
+++ b/engines/scumm/script_v2.cpp
@@ -738,23 +738,23 @@ void ScummEngine_v2::o2_drawObject() {
}
void ScummEngine_v2::o2_resourceRoutines() {
- const ResTypes resTypes[] = {
- rtNumTypes, // Invalid
- rtNumTypes, // Invalid
+ const ResType resTypes[] = {
+ rtInvalid,
+ rtInvalid,
rtCostume,
rtRoom,
- rtNumTypes, // Invalid
+ rtInvalid,
rtScript,
rtSound
};
int resid = getVarOrDirectByte(PARAM_1);
int opcode = fetchScriptByte();
- ResTypes type = rtNumTypes;
+ ResType type = rtInvalid;
if (0 <= (opcode >> 4) && (opcode >> 4) < (int)ARRAYSIZE(resTypes))
type = resTypes[opcode >> 4];
- if ((opcode & 0x0f) == 0 || type == rtNumTypes)
+ if ((opcode & 0x0f) == 0 || type == rtInvalid)
return;
// HACK V2 Maniac Mansion tries to load an invalid sound resource in demo script.
diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp
index 81f28fb..b8f3b4b 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -1490,7 +1490,7 @@ void ScummEngine_v5::o5_systemOps() {
}
void ScummEngine_v5::o5_resourceRoutines() {
- const ResTypes resType[4] = { rtScript, rtSound, rtCostume, rtRoom };
+ const ResType resType[4] = { rtScript, rtSound, rtCostume, rtRoom };
int resid = 0;
int foo, bar;
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index 9d64202..636c909 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -308,7 +308,8 @@ struct SaveStateMetaInfos {
* WARNING: Do not change the order of these, as the savegame format relies
* on it; any change made here will break savegame compatibility!
*/
-enum ResTypes {
+enum ResType {
+ rtInvalid = 0,
rtFirst = 1,
rtRoom = 1,
rtScript = 2,
@@ -331,10 +332,11 @@ enum ResTypes {
rtImage = 19,
rtTalkie = 20,
rtSpoolBuffer = 21,
- rtLast = 21,
- rtNumTypes = 22
+ rtLast = 21
};
+typedef uint16 ResId;
+
class ResourceManager;
/**
@@ -576,9 +578,9 @@ protected:
bool saveState(int slot, bool compat);
bool loadState(int slot, bool compat);
virtual void saveOrLoad(Serializer *s);
- void saveResource(Serializer *ser, int type, int index);
- void loadResource(Serializer *ser, int type, int index);
- void loadResourceOLD(Serializer *ser, int type, int index); // "Obsolete"
+ void saveResource(Serializer *ser, ResType type, ResId idx);
+ void loadResource(Serializer *ser, ResType type, ResId idx);
+ void loadResourceOLD(Serializer *ser, ResType type, ResId idx); // "Obsolete"
Common::String makeSavegameName(int slot, bool temporary) const {
return makeSavegameName(_targetName, slot, temporary);
@@ -711,26 +713,26 @@ protected:
void askForDisk(const char *filename, int disknum); // TODO: Use Common::String
bool openResourceFile(const Common::String &filename, byte encByte); // TODO: Use Common::String
- void loadPtrToResource(int type, int i, const byte *ptr);
- virtual int readResTypeList(int id);
-// void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
+ void loadPtrToResource(ResType type, ResId idx, const byte *ptr);
+ virtual int readResTypeList(ResType type);
+// void allocResTypeData(ResType type, uint32 tag, int num, int mode);
// byte *createResource(int type, int index, uint32 size);
- int loadResource(int type, int i);
-// void nukeResource(int type, int i);
- int getResourceRoomNr(int type, int idx);
- virtual uint32 getResourceRoomOffset(int type, int idx);
- int getResourceSize(int type, int idx);
+ int loadResource(ResType type, ResId idx);
+// void nukeResource(ResType type, ResId idx);
+ int getResourceRoomNr(ResType type, ResId idx);
+ virtual uint32 getResourceRoomOffset(ResType type, ResId idx);
+ int getResourceSize(ResType type, ResId idx);
public:
- byte *getResourceAddress(int type, int i);
- virtual byte *getStringAddress(int i);
+ byte *getResourceAddress(ResType type, ResId idx);
+ virtual byte *getStringAddress(ResId idx);
byte *getStringAddressVar(int i);
- void ensureResourceLoaded(int type, int i);
+ void ensureResourceLoaded(ResType type, ResId idx);
protected:
- int readSoundResource(int index);
- int readSoundResourceSmallHeader(int index);
- bool isResourceInUse(int type, int i) const;
+ int readSoundResource(ResId idx);
+ int readSoundResourceSmallHeader(ResId idx);
+ bool isResourceInUse(ResType type, ResId idx) const;
virtual void setupRoomSubBlocks();
virtual void resetRoomSubBlocks();
diff --git a/engines/scumm/scumm_v3.h b/engines/scumm/scumm_v3.h
index 6367f4a..f11ca16 100644
--- a/engines/scumm/scumm_v3.h
+++ b/engines/scumm/scumm_v3.h
@@ -59,7 +59,7 @@ public:
ScummEngine_v3old(OSystem *syst, const DetectorResult &dr);
protected:
- virtual int readResTypeList(int id);
+ virtual int readResTypeList(ResType type);
virtual void readIndexFile();
virtual void setupRoomSubBlocks();
virtual void resetRoomSubBlocks();
diff --git a/engines/scumm/scumm_v4.h b/engines/scumm/scumm_v4.h
index 96fa7f7..e21e4b2 100644
--- a/engines/scumm/scumm_v4.h
+++ b/engines/scumm/scumm_v4.h
@@ -56,7 +56,7 @@ protected:
virtual void scummLoop_handleSaveLoad();
- virtual int readResTypeList(int id);
+ virtual int readResTypeList(ResType type);
virtual void readIndexFile();
virtual void loadCharset(int no);
virtual void resetRoomObjects();
diff --git a/engines/scumm/scumm_v6.h b/engines/scumm/scumm_v6.h
index 5b6ad88..c42a49a 100644
--- a/engines/scumm/scumm_v6.h
+++ b/engines/scumm/scumm_v6.h
@@ -107,7 +107,7 @@ protected:
virtual void decodeParseString(int a, int b);
virtual void readArrayFromIndexFile();
- virtual byte *getStringAddress(int i);
+ virtual byte *getStringAddress(ResId idx);
virtual void readMAXS(int blockSize);
virtual void palManipulateInit(int resID, int start, int end, int time);
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 4a136f6..40b151b 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -1064,7 +1064,7 @@ void Sound::saveLoadWithSerializer(Serializer *ser) {
#pragma mark --- Sound resource handling ---
#pragma mark -
-static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, int size);
+static void convertMac0Resource(ResourceManager *res, ResId idx, byte *src_ptr, int size);
/*
@@ -1074,7 +1074,7 @@ static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, in
* could stand a thorough cleanup!
*/
-int ScummEngine::readSoundResource(int idx) {
+int ScummEngine::readSoundResource(ResId idx) {
uint32 pos, total_size, size, tag, basetag, max_total_size;
int pri, best_pri;
uint32 best_size = 0, best_offs = 0;
@@ -1427,7 +1427,7 @@ static byte Mac0ToGMInstrument(uint32 type, int &transpose) {
}
}
-static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, int size) {
+static void convertMac0Resource(ResourceManager *res, ResId idx, byte *src_ptr, int size) {
/*
From Markus Magnuson (superqult) we got this information:
Mac0
@@ -1618,7 +1618,7 @@ static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, in
#endif
}
-static void convertADResource(ResourceManager *res, const GameSettings& game, int idx, byte *src_ptr, int size) {
+static void convertADResource(ResourceManager *res, const GameSettings& game, ResId idx, byte *src_ptr, int size) {
// We will ignore the PPQN in the original resource, because
// it's invalid anyway. We use a constant PPQN of 480.
const int ppqn = 480;
@@ -2001,7 +2001,7 @@ static void convertADResource(ResourceManager *res, const GameSettings& game, in
}
-int ScummEngine::readSoundResourceSmallHeader(int idx) {
+int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
uint32 pos, total_size, size, tag;
uint32 ad_size = 0, ad_offs = 0;
uint32 ro_size = 0, ro_offs = 0;
Commit: dfd61124039dc04540207a09f7f26e2693599ded
https://github.com/scummvm/scummvm/commit/dfd61124039dc04540207a09f7f26e2693599ded
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:04:59-07:00
Commit Message:
SCUMM: Rename resTypeFromId -> nameOfResType
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource_v3.cpp
engines/scumm/resource_v4.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 2eedf5e..b24c172 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -52,7 +52,7 @@ enum {
-extern const char *resTypeFromId(int type);
+extern const char *nameOfResType(ResType type);
static uint16 newTag2Old(uint32 newTag);
static const byte *findResourceSmall(uint32 tag, const byte *searchin);
@@ -492,10 +492,10 @@ int ScummEngine::readResTypeList(ResType type) {
num = _fileHandle->readUint16LE();
if (num != _res->_types[type]._num) {
- error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num);
+ error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
- debug(2, " readResTypeList(%s): %d entries", resTypeFromId(type), num);
+ debug(2, " readResTypeList(%s): %d entries", nameOfResType(type), num);
for (idx = 0; idx < num; idx++) {
@@ -527,11 +527,11 @@ int ScummEngine_v70he::readResTypeList(ResType type) {
}
void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode) {
- debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(type), tag2str(TO_BE_32(tag)), num, mode);
+ debug(2, "allocResTypeData(%s,%s,%d,%d)", nameOfResType(type), tag2str(TO_BE_32(tag)), num, mode);
assert(type >= 0 && type < (int)(ARRAYSIZE(_types)));
if (num >= 8000)
- error("Too many %s resources (%d) in directory", resTypeFromId(type), num);
+ error("Too many %s resources (%d) in directory", nameOfResType(type), num);
_types[type]._mode = mode;
_types[type]._num = num;
@@ -584,7 +584,7 @@ void ScummEngine::nukeCharset(int i) {
}
void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
- debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), idx);
+ debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", nameOfResType(type), idx);
if ((type == rtRoom) && idx > 0x7F && _game.version < 7 && _game.heversion <= 71) {
idx = _resourceMapper[idx & 0x7F];
@@ -618,7 +618,7 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
uint32 fileOffs;
uint32 size, tag;
- debugC(DEBUG_RESOURCE, "loadResource(%s,%d)", resTypeFromId(type), idx);
+ debugC(DEBUG_RESOURCE, "loadResource(%s,%d)", nameOfResType(type), idx);
if (type == rtCharset && (_game.features & GF_SMALL_HEADER)) {
loadCharset(idx);
@@ -628,7 +628,7 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
roomNr = getResourceRoomNr(type, idx);
if (idx >= _res->_types[type]._num)
- error("%s %d undefined %d %d", resTypeFromId(type), idx, _res->_types[type]._num, roomNr);
+ error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._num, roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -666,7 +666,7 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
tag = _fileHandle->readUint32BE();
if (tag != _res->_types[type]._tag && _game.heversion < 70) {
error("%s %d not in room %d at %d+%d in file %s",
- resTypeFromId(type), idx, roomNr,
+ nameOfResType(type), idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName());
}
@@ -729,13 +729,13 @@ byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
ptr = (byte *)_res->_types[type]._resources[idx]._address;
if (!ptr) {
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
+ debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", nameOfResType(type), idx);
return NULL;
}
_res->setResourceCounter(type, idx, 1);
- debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr);
+ debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", nameOfResType(type), idx, ptr);
return ptr;
}
@@ -792,7 +792,7 @@ byte ResourceManager::Resource::getResourceCounter() const {
#define SAFETY_AREA 2
byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
- debugC(DEBUG_RESOURCE, "_res->createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
+ debugC(DEBUG_RESOURCE, "_res->createResource(%s,%d,%d)", nameOfResType(type), idx, size);
if (!validateResource("allocating", type, idx))
return NULL;
@@ -812,7 +812,7 @@ byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
byte *ptr = (byte *)calloc(size + SAFETY_AREA, 1);
if (ptr == NULL) {
- error("createResource(%s,%d): Out of memory while allocating %d", resTypeFromId(type), idx, size);
+ error("createResource(%s,%d): Out of memory while allocating %d", nameOfResType(type), idx, size);
}
_allocatedSize += size;
@@ -875,7 +875,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const {
if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._num) {
- error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
+ error("%s Illegal Glob type %s (%d) num %d", str, nameOfResType(type), type, idx);
return false;
}
return true;
@@ -884,7 +884,7 @@ bool ResourceManager::validateResource(const char *str, ResType type, ResId idx)
void ResourceManager::nukeResource(ResType type, ResId idx) {
byte *ptr = _types[type]._resources[idx]._address;
if (ptr != NULL) {
- debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
+ debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", nameOfResType(type), idx);
_allocatedSize -= _types[type]._resources[idx]._size;
_types[type]._resources[idx].nuke();
}
@@ -1523,7 +1523,7 @@ uint16 newTag2Old(uint32 newTag) {
}
}
-const char *resTypeFromId(int type) {
+const char *nameOfResType(ResType type) {
static char buf[100];
switch (type) {
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index f422f82..46f7994 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -28,18 +28,18 @@
namespace Scumm {
-extern const char *resTypeFromId(int id);
+extern const char *nameOfResType(ResType type);
int ScummEngine_v3old::readResTypeList(ResType type) {
uint num;
ResId idx;
- debug(9, "readResTypeList(%s)", resTypeFromId(type));
+ debug(9, "readResTypeList(%s)", nameOfResType(type));
num = _fileHandle->readByte();
if (num >= 0xFF) {
- error("Too many %ss (%d) in directory", resTypeFromId(type), num);
+ error("Too many %ss (%d) in directory", nameOfResType(type), num);
}
if (type == rtRoom) {
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index d062fe1..258122b 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -28,17 +28,17 @@
namespace Scumm {
-extern const char *resTypeFromId(int id);
+extern const char *nameOfResType(ResType type);
int ScummEngine_v4::readResTypeList(ResType type) {
uint num;
- debug(9, "readResTypeList(%s)", resTypeFromId(type));
+ debug(9, "readResTypeList(%s)", nameOfResType(type));
num = _fileHandle->readUint16LE();
if (num != _res->_types[type]._num) {
- error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num);
+ error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
for (ResId idx = 0; idx < num; idx++) {
Commit: 45207a52d480cdd70f6bf08bbad76ec3d23a5688
https://github.com/scummvm/scummvm/commit/45207a52d480cdd70f6bf08bbad76ec3d23a5688
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:12:00-07:00
Commit Message:
SCUMM: Remove ResTypeData::_num
Changed paths:
engines/scumm/debugger.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v4.cpp
engines/scumm/room.cpp
engines/scumm/saveload.cpp
engines/scumm/script.cpp
diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp
index f7293b5..5502715 100644
--- a/engines/scumm/debugger.cpp
+++ b/engines/scumm/debugger.cpp
@@ -374,8 +374,8 @@ bool ScummDebugger::Cmd_Actor(int argc, const char **argv) {
DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) {
- if (value >= _vm->_res->_types[rtCostume]._num)
- DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._num);
+ if (value >= (int)_vm->_res->_types[rtCostume]._resources.size())
+ DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._resources.size());
else {
a->setActorCostume(value);
_vm->_fullRedraw = true;
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index b24c172..b5cfa40 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(ResType type) {
else
num = _fileHandle->readUint16LE();
- if (num != _res->_types[type]._num) {
+ if (num != _res->_types[type]._resources.size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
@@ -534,7 +534,6 @@ void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTyp
error("Too many %s resources (%d) in directory", nameOfResType(type), num);
_types[type]._mode = mode;
- _types[type]._num = num;
_types[type]._tag = tag;
_types[type]._resources.resize(num);
@@ -604,7 +603,7 @@ void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
if (type != rtCharset && idx == 0)
return;
- if (idx <= _res->_types[type]._num && _res->_types[type]._resources[idx]._address)
+ if (idx <= _res->_types[type]._resources.size() && _res->_types[type]._resources[idx]._address)
return;
loadResource(type, idx);
@@ -627,8 +626,8 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
roomNr = getResourceRoomNr(type, idx);
- if (idx >= _res->_types[type]._num)
- error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._num, roomNr);
+ if (idx >= _res->_types[type]._resources.size())
+ error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._resources.size(), roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -765,7 +764,7 @@ void ResourceManager::increaseExpireCounter() {
void ResourceManager::increaseResourceCounters() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._num;
+ ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
byte counter = _types[type]._resources[idx].getResourceCounter();
if (counter && counter < RF_USAGE_MAX) {
@@ -848,7 +847,6 @@ void ResourceManager::Resource::nuke() {
ResourceManager::ResTypeData::ResTypeData() {
_mode = kDynamicResTypeMode;
- _num = 0;
_tag = 0;
}
@@ -874,7 +872,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
}
bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const {
- if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._num) {
+ if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._resources.size()) {
error("%s Illegal Glob type %s (%d) num %d", str, nameOfResType(type), type, idx);
return false;
}
@@ -1020,7 +1018,7 @@ void ResourceManager::expireResources(uint32 size) {
if (_types[type]._mode != kDynamicResTypeMode) {
// Resources of this type can be reloaded from the data files,
// so we can potentially unload them to free memory.
- ResId idx = _types[type]._num;
+ ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
Resource &tmp = _types[type]._resources[idx];
byte counter = tmp.getResourceCounter();
@@ -1045,7 +1043,7 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._num;
+ ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
if (isResourceLoaded(type, idx))
nukeResource(type, idx);
@@ -1087,7 +1085,7 @@ void ResourceManager::resourceStats() {
uint32 lockedSize = 0, lockedNum = 0;
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._num;
+ ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
Resource &tmp = _types[type]._resources[idx];
if (tmp.isLocked() && tmp._address) {
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 15aed24..e8c2255 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -154,11 +154,6 @@ public:
friend class ResourceManager;
public:
ResTypeMode _mode;
- /**
- * The maximal number of resource of this type. Determines the size
- * of various arrays.
- */
- uint16 _num;
/**
* The 4-byte tag or chunk type associated to this resource type, if any.
@@ -167,7 +162,7 @@ public:
uint32 _tag;
/**
- * Array of size _num containing pointers to each resource of this type.
+ * Array containing the resources of this type.
*/
Common::Array<Resource> _resources;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index 258122b..e0d86e7 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -37,7 +37,7 @@ int ScummEngine_v4::readResTypeList(ResType type) {
num = _fileHandle->readUint16LE();
- if (num != _res->_types[type]._num) {
+ if (num != _res->_types[type]._resources.size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
diff --git a/engines/scumm/room.cpp b/engines/scumm/room.cpp
index a0bb527..4ee771e 100644
--- a/engines/scumm/room.cpp
+++ b/engines/scumm/room.cpp
@@ -465,7 +465,7 @@ void ScummEngine::setupRoomSubBlocks() {
* So it is not appropriate to call it after loading a savegame.
*/
void ScummEngine::resetRoomSubBlocks() {
- int i;
+ ResId i;
const byte *ptr;
byte *roomptr;
@@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
//
// Load scale data
//
- for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
+ for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++)
_res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) {
int s1, s2, y1, y2;
if (_game.version == 8) {
- for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 16) {
+ for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8);
@@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2);
}
} else {
- for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 8) {
+ for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4);
@@ -712,7 +712,6 @@ void ScummEngine_v3old::setupRoomSubBlocks() {
}
void ScummEngine_v3old::resetRoomSubBlocks() {
- int i;
const byte *ptr;
byte *roomptr;
@@ -769,7 +768,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
size = 0;
// Compute matrix size
- for (i = 0; i < numOfBoxes; i++) {
+ for (int i = 0; i < numOfBoxes; i++) {
while (*tmp != 0xFF) {
size++;
tmp++;
@@ -794,8 +793,8 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
//
// No scale data in old bundle games
//
- for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
- _res->nukeResource(rtScaleTable, i);
+ for (ResId id = 1; id < _res->_types[rtScaleTable]._resources.size(); id++)
+ _res->nukeResource(rtScaleTable, id);
}
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index f37ca36..b823e3c 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -427,7 +427,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// Nuke all resources
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1))
if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat))
- for (ResId idx = 0; idx < _res->_types[type]._num; idx++) {
+ for (ResId idx = 0; idx < _res->_types[type]._resources.size(); idx++) {
_res->nukeResource(type, idx);
}
@@ -516,7 +516,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items
- for (ResId idx = 1; idx < _res->_types[rtScaleTable]._num; idx++) {
+ for (ResId idx = 1; idx < _res->_types[rtScaleTable]._resources.size(); idx++) {
convertScaleTableToScaleSlot(idx);
}
}
@@ -1245,7 +1245,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
- for (idx = 0; idx < _res->_types[type]._num; idx++) {
+ for (idx = 0; idx < _res->_types[type]._resources.size(); idx++) {
// Only save resources which actually exist...
if (_res->_types[type]._resources[idx]._address) {
s->saveUint16(idx); // Save the index of the resource
@@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
} else {
while ((type = (ResType)s->loadUint16()) != 0xFFFF) {
while ((idx = s->loadUint16()) != 0xFFFF) {
- assert(idx < _res->_types[type]._num);
+ assert(idx < _res->_types[type]._resources.size());
loadResource(s, type, idx);
}
}
@@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// unchanged resource counts, we have to hard code the following check
if (_game.version < 6 && type == rtObjectName)
continue;
- for (idx = 1; idx < _res->_types[type]._num; idx++)
+ for (idx = 1; idx < _res->_types[type]._resources.size(); idx++)
loadResourceOLD(s, type, idx);
}
}
@@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
//
if (s->isSaving()) {
for (type = rtFirst; type <= rtLast; type = ResType(type + 1))
- for (idx = 1; idx < _res->_types[type]._num; idx++) {
+ for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) {
if (_res->isLocked(type, idx)) {
s->saveByte(type);
s->saveUint16(idx);
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index 47cf8e0..6fe80de 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -397,7 +397,7 @@ void ScummEngine::getScriptBaseAddress() {
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
- assert(_roomResource < _res->_types[rtRoomScripts]._num);
+ assert(_roomResource < (int)_res->_types[rtRoomScripts]._resources.size());
_lastCodePtr = &_res->_types[rtRoomScripts]._resources[_roomResource]._address;
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
@@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
- if (_res->_types[rtScript]._num > 460) {
+ if (_res->_types[rtScript]._resources.size() > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {
Commit: 1faf89c524ff734ad40a13ab85a84f465e54e1ce
https://github.com/scummvm/scummvm/commit/1faf89c524ff734ad40a13ab85a84f465e54e1ce
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:26:09-07:00
Commit Message:
SCUMM: Improve ResTypeData doxygen comments
Changed paths:
engines/scumm/resource.h
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index e8c2255..49f5f07 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -153,11 +153,15 @@ public:
class ResTypeData {
friend class ResourceManager;
public:
+ /**
+ * The mode of this res type.
+ */
ResTypeMode _mode;
/**
* The 4-byte tag or chunk type associated to this resource type, if any.
* Only applies to resources that are loaded from the game data files.
+ * This value is only used for debugging purposes.
*/
uint32 _tag;
Commit: d63c2d17c210f2cc0b5bf5ddc914f827b42b8511
https://github.com/scummvm/scummvm/commit/d63c2d17c210f2cc0b5bf5ddc914f827b42b8511
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:26:35-07:00
Commit Message:
SCUMM: Improve and document res tag sanity check
Changed paths:
engines/scumm/resource.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index b5cfa40..8eb41ec 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -662,9 +662,17 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
}
// Sanity check: Is this the right tag for this resource type?
+ //
+ // Currently disabled for newer HE games because they use different
+ // tags. For example, for rtRoom, 'ROOM' changed to 'RMDA'; and for
+ // rtImage, 'AWIZ' and 'MULT' can both occur simultaneously.
+ // On the long run, it would be preferable to not turn this check off,
+ // but instead to explicitly support the variations in the HE games.
tag = _fileHandle->readUint32BE();
if (tag != _res->_types[type]._tag && _game.heversion < 70) {
- error("%s %d not in room %d at %d+%d in file %s",
+ error("Unknown res tag '%s' encountered (expected '%s') "
+ "while trying to load res (%s,%d) in room %d at %d+%d in file %s",
+ tag2str(tag), tag2str(_res->_types[type]._tag),
nameOfResType(type), idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName());
}
Commit: 65a82610d15214eee56d0719c0f80c1e86b3039a
https://github.com/scummvm/scummvm/commit/65a82610d15214eee56d0719c0f80c1e86b3039a
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:30:56-07:00
Commit Message:
DEVTOOLS: Remove obsolete TeX mode from credits.pl, mention Credits.rtf
Changed paths:
devtools/credits.pl
diff --git a/devtools/credits.pl b/devtools/credits.pl
index c45f16e..46c7540 100755
--- a/devtools/credits.pl
+++ b/devtools/credits.pl
@@ -5,10 +5,9 @@
# of the credits in other places from this source. In particular:
# - The AUTHORS file
# - The gui/credits.h header file
+# - The Credits.rtf file used by the Mac OS X port
# - The credits.xml file, part of the DocBook manual
# - Finally, credits.xml, for use on the website (different format than the DocBook one)
-# And maybe in the future, also "doc/10.tex", the LaTeX version of the README.
-# Although that might soon be obsolete, if the manual evolves enough.
#
# Initial version written by Fingolfin in December 2004.
#
@@ -37,7 +36,6 @@ if ($#ARGV >= 0) {
$mode = "CPP" if ($ARGV[0] eq "--cpp"); # credits.h (for use by about.cpp)
$mode = "XML-DOC" if ($ARGV[0] eq "--xml-docbook"); # credits.xml (DocBook)
$mode = "RTF" if ($ARGV[0] eq "--rtf"); # Credits.rtf (Mac OS X About box)
- $mode = "TEX" if ($ARGV[0] eq "--tex"); # 10.tex (LaTeX)
}
if ($mode eq "") {
@@ -184,10 +182,6 @@ sub begin_credits {
if ($mode eq "TEXT") {
#print html_entities_to_ascii($title)."\n";
- } elsif ($mode eq "TEX") {
- print "% This file was generated by credits.pl. Do not edit by hand!\n";
- print '\section{Credits}' . "\n";
- print '\begin{trivlist}' . "\n";
} elsif ($mode eq "RTF") {
print '{\rtf1\mac\ansicpg10000' . "\n";
print '{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;}' . "\n";
@@ -219,9 +213,6 @@ sub begin_credits {
sub end_credits {
if ($mode eq "TEXT") {
- } elsif ($mode eq "TEX") {
- print '\end{trivlist}' . "\n";
- print "\n";
} elsif ($mode eq "RTF") {
print "}\n";
} elsif ($mode eq "CPP") {
@@ -252,15 +243,6 @@ sub begin_section {
} elsif ($section_level eq 1) {
print " " x $section_level . "-" x (length $title)."\n";
}
- } elsif ($mode eq "TEX") {
- print '\item \textbf{';
- if ($section_level eq 0) {
- print '\LARGE';
- } elsif ($section_level eq 1) {
- print '\large';
- }
- print " " . html_entities_to_tex($title) . "}\n";
- print '\begin{list}{}{\setlength{\leftmargin}{0.2cm}}' . "\n";
} elsif ($mode eq "RTF") {
$title = html_entities_to_rtf($title);
@@ -327,8 +309,6 @@ sub end_section {
if ($mode eq "TEXT") {
# nothing
- } elsif ($mode eq "TEX") {
- print '\end{list}' . "\n";
} elsif ($mode eq "RTF") {
# nothing
} elsif ($mode eq "CPP") {
@@ -352,16 +332,12 @@ sub begin_persons {
print "\t\t\t<group>\n";
print "\t\t\t\t<name>" . $title . "</name>\n";
#print "\t\t\t\t<persons>\n";
- } elsif ($mode eq "TEX") {
- print '\item \begin{tabular}[h]{p{0.3\linewidth}p{0.6\linewidth}}' . "\n";
}
}
sub end_persons {
if ($mode eq "TEXT") {
print "\n";
- } elsif ($mode eq "TEX") {
- print ' \end{tabular}' . "\n";
} elsif ($mode eq "RTF") {
# nothing
} elsif ($mode eq "XML-WEB") {
@@ -392,12 +368,6 @@ sub add_person {
print " - " . substr(wrap($multitab, $multitab, $desc), $inner_indent);
}
print "\n";
- } elsif ($mode eq "TEX") {
- $name = $nick if $name eq "";
- $name = html_entities_to_tex($name);
- $desc = html_entities_to_tex($desc);
-
- print " $name & \\textit{$desc}\\\\\n";
} elsif ($mode eq "RTF") {
$name = $nick if $name eq "";
$name = html_entities_to_rtf($name);
@@ -447,11 +417,6 @@ sub add_paragraph {
$tab = " " x ($section_level * 2 + 1);
print wrap($tab, $tab, html_entities_to_ascii($text))."\n";
print "\n";
- } elsif ($mode eq "TEX") {
- $text = html_entities_to_tex($text);
- print '\item' . "\n";
- print $text;
- print "\n";
} elsif ($mode eq "RTF") {
$text = html_entities_to_rtf($text);
# Center text
Commit: 4108f09543afd543fbfab86cc5f3e7f4850150a2
https://github.com/scummvm/scummvm/commit/4108f09543afd543fbfab86cc5f3e7f4850150a2
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:33:22-07:00
Commit Message:
SCUMM: Make it clearer that SCUMM's 'restart' feature leaks like hell
Changed paths:
engines/scumm/scumm.cpp
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index f0b6461..3ebacee 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -2418,13 +2418,16 @@ void ScummEngine::pauseGame() {
}
void ScummEngine::restart() {
-// TODO: Check this function - we should probably be reinitting a lot more stuff, and I suspect
-// this leaks memory like a sieve
+ // FIXME: This function *leaks memory*, and quite a lot so. For example,
+ // we re-init the resource manager, which causes readMAXS() to be called
+ // again, which allocates some memory. There are many other leaks, though.
-// Fingolfin seez: An alternate way to implement restarting would be to create
-// a save state right after startup ... to this end we could introduce a SaveFile
-// subclass which is implemented using a memory buffer (i.e. no actual file is
-// created). Then to restart we just have to load that pseudo save state.
+ // TODO: We should also probably be reinitting a lot more stuff.
+
+ // Fingolfin seez: An alternate way to implement restarting would be to create
+ // a save state right after startup ... to this end we could introduce a SaveFile
+ // subclass which is implemented using a memory buffer (i.e. no actual file is
+ // created). Then to restart we just have to load that pseudo save state.
int i;
Commit: 749a1beb350d33fb1e48494134bdca70bc8c2ad8
https://github.com/scummvm/scummvm/commit/749a1beb350d33fb1e48494134bdca70bc8c2ad8
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:39:34-07:00
Commit Message:
SCUMM: Remove useless allocateArrays call, and make sure all resources are properly killed upon restart
Changed paths:
engines/scumm/resource.cpp
engines/scumm/scumm.cpp
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 8eb41ec..10f2851 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -535,6 +535,10 @@ void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTyp
_types[type]._mode = mode;
_types[type]._tag = tag;
+
+ // If there was data in there, let's clear it out completely. This is important
+ // in case we are restarting the game.
+ _types[type]._resources.clear();
_types[type]._resources.resize(num);
/*
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 3ebacee..6e95846 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -2447,13 +2447,6 @@ void ScummEngine::restart() {
for (i = 1; i < _numGlobalObjects; i++)
clearOwnerOf(i);
- // Reallocate arrays
- // FIXME: This should already be called by readIndexFile.
- // FIXME: regardless of that, allocateArrays and allocResTypeData leaks
- // heavily, which should be fixed.
- allocateArrays();
-
- // Reread index (reset objectstate etc)
readIndexFile();
// Reinit scumm variables
Commit: cf513e3ed64556d05383209664a0cd3909f45399
https://github.com/scummvm/scummvm/commit/cf513e3ed64556d05383209664a0cd3909f45399
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:40:45-07:00
Commit Message:
SCUMM: Get rid of the unused Resource::_globSize field
Changed paths:
engines/scumm/resource.cpp
engines/scumm/resource.h
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 10f2851..85addeb9 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -520,7 +520,8 @@ int ScummEngine_v70he::readResTypeList(ResType type) {
}
for (idx = 0; idx < num; idx++) {
- _res->_types[type]._resources[idx]._globsize = _fileHandle->readUint32LE();
+ // The globsize is currently not being used
+ /*_res->_types[type]._resources[idx]._globsize =*/ _fileHandle->readUint32LE();
}
return num;
@@ -841,7 +842,6 @@ ResourceManager::Resource::Resource() {
_status = 0;
_roomno = 0;
_roomoffs = 0;
- _globsize = 0;
}
ResourceManager::Resource::~Resource() {
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 49f5f07..6e73732 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -125,11 +125,6 @@ public:
*/
uint32 _roomoffs;
- /**
- * Occurs in HE 70+, but we don't use it for anything.
- */
- uint32 _globsize;
-
public:
Resource();
~Resource();
Commit: 9ec64a66fe2f20eb1be0811b5f733332efff1b93
https://github.com/scummvm/scummvm/commit/9ec64a66fe2f20eb1be0811b5f733332efff1b93
Author: Max Horn (max at quendi.de)
Date: 2011-05-13T05:48:01-07:00
Commit Message:
SCUMM: Turned ResTypeData into a Common::Array<Resource>, subsuming its _resource member
Changed paths:
engines/scumm/debugger.cpp
engines/scumm/detection.cpp
engines/scumm/he/resource_he.cpp
engines/scumm/he/script_v72he.cpp
engines/scumm/imuse/imuse.cpp
engines/scumm/object.cpp
engines/scumm/resource.cpp
engines/scumm/resource.h
engines/scumm/resource_v2.cpp
engines/scumm/resource_v3.cpp
engines/scumm/resource_v4.cpp
engines/scumm/room.cpp
engines/scumm/saveload.cpp
engines/scumm/script.cpp
engines/scumm/script_v6.cpp
engines/scumm/sound.cpp
diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp
index 5502715..205b7a4 100644
--- a/engines/scumm/debugger.cpp
+++ b/engines/scumm/debugger.cpp
@@ -374,8 +374,8 @@ bool ScummDebugger::Cmd_Actor(int argc, const char **argv) {
DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) {
- if (value >= (int)_vm->_res->_types[rtCostume]._resources.size())
- DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._resources.size());
+ if (value >= (int)_vm->_res->_types[rtCostume].size())
+ DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume].size());
else {
a->setActorCostume(value);
_vm->_fullRedraw = true;
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index 38c65b3..ec85f52 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -68,7 +68,7 @@ static const MD5Table *findInMD5Table(const char *md5) {
}
Common::String ScummEngine::generateFilename(const int room) const {
- const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom][room]._roomno : 0;
char buf[128];
if (_game.version == 4) {
@@ -110,7 +110,7 @@ Common::String ScummEngine_v60he::generateFilename(const int room) const {
if (room < 0) {
id = '0' - room;
} else {
- const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
+ const int diskNumber = (room > 0) ? _res->_types[rtRoom][room]._roomno : 0;
id = diskNumber + '0';
}
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index 1dce01a..6b195be 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -226,7 +226,7 @@ void ScummEngine_v70he::readRoomsOffsets() {
num = READ_LE_UINT16(_heV7RoomOffsets);
ptr = _heV7RoomOffsets + 2;
for (i = 0; i < num; i++) {
- _res->_types[rtRoom]._resources[i]._roomoffs = READ_LE_UINT32(ptr);
+ _res->_types[rtRoom][i]._roomoffs = READ_LE_UINT32(ptr);
ptr += 4;
}
}
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 0e25fe4..8f16bf0 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -625,7 +625,7 @@ void ScummEngine_v72he::o72_getNumFreeArrays() {
int i, num = 0;
for (i = 1; i < _numArray; i++) {
- if (!rtd._resources[i]._address)
+ if (!rtd[i]._address)
num++;
}
diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index 75cdb20..fa154ea 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -102,7 +102,7 @@ IMuseInternal::~IMuseInternal() {
byte *IMuseInternal::findStartOfSound(int sound) {
int32 size, pos;
- byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
+ byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
if (ptr == NULL) {
debug(1, "IMuseInternal::findStartOfSound(): Sound %d doesn't exist", sound);
@@ -134,7 +134,7 @@ byte *IMuseInternal::findStartOfSound(int sound) {
}
bool IMuseInternal::isMT32(int sound) {
- byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
+ byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
if (ptr == NULL)
return false;
@@ -176,7 +176,7 @@ bool IMuseInternal::isMT32(int sound) {
}
bool IMuseInternal::isMIDI(int sound) {
- byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
+ byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
if (ptr == NULL)
return false;
diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp
index edcf54d..fb99d6c 100644
--- a/engines/scumm/object.cpp
+++ b/engines/scumm/object.cpp
@@ -193,10 +193,10 @@ void ScummEngine::clearOwnerOf(int obj) {
_inventory[i] = _inventory[i+1];
_inventory[i+1] = 0;
// FIXME FIXME FIXME: This is incomplete, as we do not touch flags, status... BUG
- _res->_types[rtInventory]._resources[i]._address = _res->_types[rtInventory]._resources[i + 1]._address;
- _res->_types[rtInventory]._resources[i]._size = _res->_types[rtInventory]._resources[i + 1]._size;
- _res->_types[rtInventory]._resources[i + 1]._address = NULL;
- _res->_types[rtInventory]._resources[i + 1]._size = 0;
+ _res->_types[rtInventory][i]._address = _res->_types[rtInventory][i + 1]._address;
+ _res->_types[rtInventory][i]._size = _res->_types[rtInventory][i + 1]._size;
+ _res->_types[rtInventory][i + 1]._address = NULL;
+ _res->_types[rtInventory][i + 1]._size = 0;
}
}
break;
@@ -1799,7 +1799,7 @@ int ScummEngine::findLocalObjectSlot() {
int ScummEngine::findFlObjectSlot() {
int i;
for (i = 1; i < _numFlObject; i++) {
- if (_res->_types[rtFlObject]._resources[i]._address == NULL)
+ if (_res->_types[rtFlObject][i]._address == NULL)
return i;
}
error("findFlObjectSlot: Out of FLObject slots");
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 85addeb9..0448f60 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -83,8 +83,8 @@ void ScummEngine::openRoom(const int room) {
// Load the disk numer / room offs (special case for room 0 exists because
// room 0 contains the data which is used to create the roomno / roomoffs
// tables -- hence obviously we mustn't use those when loading room 0.
- const uint32 diskNumber = room ? _res->_types[rtRoom]._resources[room]._roomno : 0;
- const uint32 room_offs = room ? _res->_types[rtRoom]._resources[room]._roomoffs : 0;
+ const uint32 diskNumber = room ? _res->_types[rtRoom][room]._roomno : 0;
+ const uint32 room_offs = room ? _res->_types[rtRoom][room]._roomoffs : 0;
// FIXME: Since room_offs is const, clearly the following loop either
// is never entered, or loops forever (if it wasn't for the return/error
@@ -94,7 +94,7 @@ void ScummEngine::openRoom(const int room) {
while (room_offs != RES_INVALID_OFFSET) {
if (room_offs != 0 && room != 0 && _game.heversion < 98) {
- _fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
+ _fileOffset = _res->_types[rtRoom][room]._roomoffs;
return;
}
@@ -122,7 +122,7 @@ void ScummEngine::openRoom(const int room) {
return;
deleteRoomOffsets();
readRoomsOffsets();
- _fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
+ _fileOffset = _res->_types[rtRoom][room]._roomoffs;
if (_fileOffset != 8)
return;
@@ -157,8 +157,8 @@ void ScummEngine::closeRoom() {
/** Delete the currently loaded room offsets. */
void ScummEngine::deleteRoomOffsets() {
for (int i = 0; i < _numRooms; i++) {
- if (_res->_types[rtRoom]._resources[i]._roomoffs != RES_INVALID_OFFSET)
- _res->_types[rtRoom]._resources[i]._roomoffs = 0;
+ if (_res->_types[rtRoom][i]._roomoffs != RES_INVALID_OFFSET)
+ _res->_types[rtRoom][i]._roomoffs = 0;
}
}
@@ -174,8 +174,8 @@ void ScummEngine::readRoomsOffsets() {
while (num--) {
int room = _fileHandle->readByte();
int offset = _fileHandle->readUint32LE();
- if (_res->_types[rtRoom]._resources[room]._roomoffs != RES_INVALID_OFFSET) {
- _res->_types[rtRoom]._resources[room]._roomoffs = offset;
+ if (_res->_types[rtRoom][room]._roomoffs != RES_INVALID_OFFSET) {
+ _res->_types[rtRoom][room]._roomoffs = offset;
}
}
}
@@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(ResType type) {
else
num = _fileHandle->readUint16LE();
- if (num != _res->_types[type]._resources.size()) {
+ if (num != _res->_types[type].size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
@@ -499,10 +499,10 @@ int ScummEngine::readResTypeList(ResType type) {
for (idx = 0; idx < num; idx++) {
- _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
+ _res->_types[type][idx]._roomno = _fileHandle->readByte();
}
for (idx = 0; idx < num; idx++) {
- _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
+ _res->_types[type][idx]._roomoffs = _fileHandle->readUint32LE();
}
return num;
@@ -516,12 +516,12 @@ int ScummEngine_v70he::readResTypeList(ResType type) {
if (type == rtRoom)
for (idx = 0; idx < num; idx++) {
- _heV7RoomIntOffsets[idx] = _res->_types[rtRoom]._resources[idx]._roomoffs;
+ _heV7RoomIntOffsets[idx] = _res->_types[rtRoom][idx]._roomoffs;
}
for (idx = 0; idx < num; idx++) {
// The globsize is currently not being used
- /*_res->_types[type]._resources[idx]._globsize =*/ _fileHandle->readUint32LE();
+ /*_res->_types[type][idx]._globsize =*/ _fileHandle->readUint32LE();
}
return num;
@@ -539,8 +539,8 @@ void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTyp
// If there was data in there, let's clear it out completely. This is important
// in case we are restarting the game.
- _types[type]._resources.clear();
- _types[type]._resources.resize(num);
+ _types[type].clear();
+ _types[type].resize(num);
/*
TODO: Use multiple Resource subclasses, one for each res mode; then,
@@ -608,7 +608,7 @@ void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
if (type != rtCharset && idx == 0)
return;
- if (idx <= _res->_types[type]._resources.size() && _res->_types[type]._resources[idx]._address)
+ if (idx <= _res->_types[type].size() && _res->_types[type][idx]._address)
return;
loadResource(type, idx);
@@ -631,8 +631,8 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
roomNr = getResourceRoomNr(type, idx);
- if (idx >= _res->_types[type]._resources.size())
- error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._resources.size(), roomNr);
+ if (idx >= _res->_types[type].size())
+ error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type].size(), roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@@ -702,27 +702,27 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
int ScummEngine::getResourceRoomNr(ResType type, ResId idx) {
if (type == rtRoom && _game.heversion < 70)
return idx;
- return _res->_types[type]._resources[idx]._roomno;
+ return _res->_types[type][idx]._roomno;
}
uint32 ScummEngine::getResourceRoomOffset(ResType type, ResId idx) {
if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0;
}
- return _res->_types[type]._resources[idx]._roomoffs;
+ return _res->_types[type][idx]._roomoffs;
}
uint32 ScummEngine_v70he::getResourceRoomOffset(ResType type, ResId idx) {
if (type == rtRoom) {
return _heV7RoomIntOffsets[idx];
}
- return _res->_types[type]._resources[idx]._roomoffs;
+ return _res->_types[type][idx]._roomoffs;
}
int ScummEngine::getResourceSize(ResType type, ResId idx) {
byte *ptr = getResourceAddress(type, idx);
assert(ptr);
- return _res->_types[type]._resources[idx]._size;
+ return _res->_types[type][idx]._size;
}
byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
@@ -735,11 +735,11 @@ byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
return NULL;
// If the resource is missing, but loadable from the game data files, try to do so.
- if (!_res->_types[type]._resources[idx]._address && _res->_types[type]._mode != kDynamicResTypeMode) {
+ if (!_res->_types[type][idx]._address && _res->_types[type]._mode != kDynamicResTypeMode) {
ensureResourceLoaded(type, idx);
}
- ptr = (byte *)_res->_types[type]._resources[idx]._address;
+ ptr = (byte *)_res->_types[type][idx]._address;
if (!ptr) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", nameOfResType(type), idx);
return NULL;
@@ -777,9 +777,9 @@ void ResourceManager::increaseExpireCounter() {
void ResourceManager::increaseResourceCounters() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._resources.size();
+ ResId idx = _types[type].size();
while (idx-- > 0) {
- byte counter = _types[type]._resources[idx].getResourceCounter();
+ byte counter = _types[type][idx].getResourceCounter();
if (counter && counter < RF_USAGE_MAX) {
setResourceCounter(type, idx, counter + 1);
}
@@ -788,7 +788,7 @@ void ResourceManager::increaseResourceCounters() {
}
void ResourceManager::setResourceCounter(ResType type, ResId idx, byte counter) {
- _types[type]._resources[idx].setResourceCounter(counter);
+ _types[type][idx].setResourceCounter(counter);
}
void ResourceManager::Resource::setResourceCounter(byte counter) {
@@ -814,8 +814,8 @@ byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
// cases. For instance, Zak tries to reload the intro music
// while it's playing. See bug #1253171.
- if (_types[type]._resources[idx]._address && (type == rtSound || type == rtScript || type == rtCostume))
- return _types[type]._resources[idx]._address;
+ if (_types[type][idx]._address && (type == rtSound || type == rtScript || type == rtCostume))
+ return _types[type][idx]._address;
}
nukeResource(type, idx);
@@ -829,8 +829,8 @@ byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
_allocatedSize += size;
- _types[type]._resources[idx]._address = ptr;
- _types[type]._resources[idx]._size = size;
+ _types[type][idx]._address = ptr;
+ _types[type][idx]._size = size;
setResourceCounter(type, idx, 1);
return ptr;
}
@@ -884,7 +884,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
}
bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const {
- if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._resources.size()) {
+ if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type].size()) {
error("%s Illegal Glob type %s (%d) num %d", str, nameOfResType(type), type, idx);
return false;
}
@@ -892,11 +892,11 @@ bool ResourceManager::validateResource(const char *str, ResType type, ResId idx)
}
void ResourceManager::nukeResource(ResType type, ResId idx) {
- byte *ptr = _types[type]._resources[idx]._address;
+ byte *ptr = _types[type][idx]._address;
if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", nameOfResType(type), idx);
- _allocatedSize -= _types[type]._resources[idx]._size;
- _types[type]._resources[idx].nuke();
+ _allocatedSize -= _types[type][idx]._size;
+ _types[type][idx].nuke();
}
}
@@ -928,19 +928,19 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
void ResourceManager::lock(ResType type, ResId idx) {
if (!validateResource("Locking", type, idx))
return;
- _types[type]._resources[idx].lock();
+ _types[type][idx].lock();
}
void ResourceManager::unlock(ResType type, ResId idx) {
if (!validateResource("Unlocking", type, idx))
return;
- _types[type]._resources[idx].unlock();
+ _types[type][idx].unlock();
}
bool ResourceManager::isLocked(ResType type, ResId idx) const {
if (!validateResource("isLocked", type, idx))
return false;
- return _types[type]._resources[idx].isLocked();
+ return _types[type][idx].isLocked();
}
void ResourceManager::Resource::lock() {
@@ -989,13 +989,13 @@ bool ScummEngine::isResourceInUse(ResType type, ResId idx) const {
void ResourceManager::setModified(ResType type, ResId idx) {
if (!validateResource("Modified", type, idx))
return;
- _types[type]._resources[idx].setModified();
+ _types[type][idx].setModified();
}
bool ResourceManager::isModified(ResType type, ResId idx) const {
if (!validateResource("isModified", type, idx))
return false;
- return _types[type]._resources[idx].isModified();
+ return _types[type][idx].isModified();
}
void ResourceManager::Resource::setModified() {
@@ -1030,9 +1030,9 @@ void ResourceManager::expireResources(uint32 size) {
if (_types[type]._mode != kDynamicResTypeMode) {
// Resources of this type can be reloaded from the data files,
// so we can potentially unload them to free memory.
- ResId idx = _types[type]._resources.size();
+ ResId idx = _types[type].size();
while (idx-- > 0) {
- Resource &tmp = _types[type]._resources[idx];
+ Resource &tmp = _types[type][idx];
byte counter = tmp.getResourceCounter();
if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(type, idx)) {
best_counter = counter;
@@ -1055,12 +1055,12 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._resources.size();
+ ResId idx = _types[type].size();
while (idx-- > 0) {
if (isResourceLoaded(type, idx))
nukeResource(type, idx);
}
- _types[type]._resources.clear();
+ _types[type].clear();
}
}
@@ -1090,16 +1090,16 @@ void ScummEngine::loadPtrToResource(ResType type, ResId idx, const byte *source)
bool ResourceManager::isResourceLoaded(ResType type, ResId idx) const {
if (!validateResource("isResourceLoaded", type, idx))
return false;
- return _types[type]._resources[idx]._address != NULL;
+ return _types[type][idx]._address != NULL;
}
void ResourceManager::resourceStats() {
uint32 lockedSize = 0, lockedNum = 0;
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
- ResId idx = _types[type]._resources.size();
+ ResId idx = _types[type].size();
while (idx-- > 0) {
- Resource &tmp = _types[type]._resources[idx];
+ Resource &tmp = _types[type][idx];
if (tmp.isLocked() && tmp._address) {
lockedSize += tmp._size;
lockedNum++;
diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h
index 6e73732..e8b0c1e 100644
--- a/engines/scumm/resource.h
+++ b/engines/scumm/resource.h
@@ -145,7 +145,7 @@ public:
/**
* This struct represents a resource type and all resource of that type.
*/
- class ResTypeData {
+ class ResTypeData : public Common::Array<Resource> {
friend class ResourceManager;
public:
/**
@@ -160,11 +160,6 @@ public:
*/
uint32 _tag;
- /**
- * Array containing the resources of this type.
- */
- Common::Array<Resource> _resources;
-
public:
ResTypeData();
~ResTypeData();
@@ -188,8 +183,8 @@ public:
byte *createResource(ResType type, ResId idx, uint32 size);
void nukeResource(ResType type, ResId idx);
-// inline Resource &getRes(ResType type, ResId idx) { return _types[type]._resources[idx]; }
-// inline const Resource &getRes(ResType type, ResId idx) const { return _types[type]._resources[idx]; }
+// inline Resource &getRes(ResType type, ResId idx) { return _types[type][idx]; }
+// inline const Resource &getRes(ResType type, ResId idx) const { return _types[type][idx]; }
bool isResourceLoaded(ResType type, ResId idx) const;
diff --git a/engines/scumm/resource_v2.cpp b/engines/scumm/resource_v2.cpp
index 38dfa7c..927ee67 100644
--- a/engines/scumm/resource_v2.cpp
+++ b/engines/scumm/resource_v2.cpp
@@ -84,40 +84,40 @@ void ScummEngine_v2::readClassicIndexFile() {
}
for (i = 0; i < _numRooms; i++) {
- _res->_types[rtRoom]._resources[i]._roomno = i;
+ _res->_types[rtRoom][i]._roomno = i;
}
_fileHandle->seek(_numRooms, SEEK_CUR);
for (i = 0; i < _numRooms; i++) {
- _res->_types[rtRoom]._resources[i]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[rtRoom]._resources[i]._roomoffs == 0xFFFF)
- _res->_types[rtRoom]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtRoom][i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtRoom][i]._roomoffs == 0xFFFF)
+ _res->_types[rtRoom][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numCostumes; i++) {
- _res->_types[rtCostume]._resources[i]._roomno = _fileHandle->readByte();
+ _res->_types[rtCostume][i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numCostumes; i++) {
- _res->_types[rtCostume]._resources[i]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[rtCostume]._resources[i]._roomoffs == 0xFFFF)
- _res->_types[rtCostume]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtCostume][i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtCostume][i]._roomoffs == 0xFFFF)
+ _res->_types[rtCostume][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numScripts; i++) {
- _res->_types[rtScript]._resources[i]._roomno = _fileHandle->readByte();
+ _res->_types[rtScript][i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numScripts; i++) {
- _res->_types[rtScript]._resources[i]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[rtScript]._resources[i]._roomoffs == 0xFFFF)
- _res->_types[rtScript]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtScript][i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtScript][i]._roomoffs == 0xFFFF)
+ _res->_types[rtScript][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
for (i = 0; i < _numSounds; i++) {
- _res->_types[rtSound]._resources[i]._roomno = _fileHandle->readByte();
+ _res->_types[rtSound][i]._roomno = _fileHandle->readByte();
}
for (i = 0; i < _numSounds; i++) {
- _res->_types[rtSound]._resources[i]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[rtSound]._resources[i]._roomoffs == 0xFFFF)
- _res->_types[rtSound]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ _res->_types[rtSound][i]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[rtSound][i]._roomoffs == 0xFFFF)
+ _res->_types[rtSound][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
}
diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp
index 46f7994..55e42e3 100644
--- a/engines/scumm/resource_v3.cpp
+++ b/engines/scumm/resource_v3.cpp
@@ -44,16 +44,16 @@ int ScummEngine_v3old::readResTypeList(ResType type) {
if (type == rtRoom) {
for (idx = 0; idx < num; idx++)
- _res->_types[type]._resources[idx]._roomno = idx;
+ _res->_types[type][idx]._roomno = idx;
_fileHandle->seek(num, SEEK_CUR);
} else {
for (idx = 0; idx < num; idx++)
- _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
+ _res->_types[type][idx]._roomno = _fileHandle->readByte();
}
for (idx = 0; idx < num; idx++) {
- _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint16LE();
- if (_res->_types[type]._resources[idx]._roomoffs == 0xFFFF)
- _res->_types[type]._resources[idx]._roomoffs = (uint32)RES_INVALID_OFFSET;
+ _res->_types[type][idx]._roomoffs = _fileHandle->readUint16LE();
+ if (_res->_types[type][idx]._roomoffs == 0xFFFF)
+ _res->_types[type][idx]._roomoffs = (uint32)RES_INVALID_OFFSET;
}
return num;
diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp
index e0d86e7..6215e86 100644
--- a/engines/scumm/resource_v4.cpp
+++ b/engines/scumm/resource_v4.cpp
@@ -37,13 +37,13 @@ int ScummEngine_v4::readResTypeList(ResType type) {
num = _fileHandle->readUint16LE();
- if (num != _res->_types[type]._resources.size()) {
+ if (num != _res->_types[type].size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
for (ResId idx = 0; idx < num; idx++) {
- _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
- _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
+ _res->_types[type][idx]._roomno = _fileHandle->readByte();
+ _res->_types[type][idx]._roomoffs = _fileHandle->readUint32LE();
}
return num;
diff --git a/engines/scumm/room.cpp b/engines/scumm/room.cpp
index 4ee771e..8962a0e 100644
--- a/engines/scumm/room.cpp
+++ b/engines/scumm/room.cpp
@@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
//
// Load scale data
//
- for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++)
+ for (i = 1; i < _res->_types[rtScaleTable].size(); i++)
_res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) {
int s1, s2, y1, y2;
if (_game.version == 8) {
- for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 16) {
+ for (i = 1; i < _res->_types[rtScaleTable].size(); i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8);
@@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2);
}
} else {
- for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 8) {
+ for (i = 1; i < _res->_types[rtScaleTable].size(); i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4);
@@ -793,7 +793,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
//
// No scale data in old bundle games
//
- for (ResId id = 1; id < _res->_types[rtScaleTable]._resources.size(); id++)
+ for (ResId id = 1; id < _res->_types[rtScaleTable].size(); id++)
_res->nukeResource(rtScaleTable, id);
}
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index b823e3c..f5d219c 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -427,7 +427,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// Nuke all resources
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1))
if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat))
- for (ResId idx = 0; idx < _res->_types[type]._resources.size(); idx++) {
+ for (ResId idx = 0; idx < _res->_types[type].size(); idx++) {
_res->nukeResource(type, idx);
}
@@ -516,7 +516,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items
- for (ResId idx = 1; idx < _res->_types[rtScaleTable]._resources.size(); idx++) {
+ for (ResId idx = 1; idx < _res->_types[rtScaleTable].size(); idx++) {
convertScaleTableToScaleSlot(idx);
}
}
@@ -1245,9 +1245,9 @@ void ScummEngine::saveOrLoad(Serializer *s) {
for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) {
s->saveUint16(type); // Save the res type...
- for (idx = 0; idx < _res->_types[type]._resources.size(); idx++) {
+ for (idx = 0; idx < _res->_types[type].size(); idx++) {
// Only save resources which actually exist...
- if (_res->_types[type]._resources[idx]._address) {
+ if (_res->_types[type][idx]._address) {
s->saveUint16(idx); // Save the index of the resource
saveResource(s, type, idx);
}
@@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
} else {
while ((type = (ResType)s->loadUint16()) != 0xFFFF) {
while ((idx = s->loadUint16()) != 0xFFFF) {
- assert(idx < _res->_types[type]._resources.size());
+ assert(idx < _res->_types[type].size());
loadResource(s, type, idx);
}
}
@@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// unchanged resource counts, we have to hard code the following check
if (_game.version < 6 && type == rtObjectName)
continue;
- for (idx = 1; idx < _res->_types[type]._resources.size(); idx++)
+ for (idx = 1; idx < _res->_types[type].size(); idx++)
loadResourceOLD(s, type, idx);
}
}
@@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
//
if (s->isSaving()) {
for (type = rtFirst; type <= rtLast; type = ResType(type + 1))
- for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) {
+ for (idx = 1; idx < _res->_types[type].size(); idx++) {
if (_res->isLocked(type, idx)) {
s->saveByte(type);
s->saveUint16(idx);
@@ -1663,11 +1663,11 @@ void ScummEngine::loadResourceOLD(Serializer *ser, ResType type, ResId idx) {
}
void ScummEngine::saveResource(Serializer *ser, ResType type, ResId idx) {
- assert(_res->_types[type]._resources[idx]._address);
+ assert(_res->_types[type][idx]._address);
if (_res->_types[type]._mode == kDynamicResTypeMode) {
- byte *ptr = _res->_types[type]._resources[idx]._address;
- uint32 size = _res->_types[type]._resources[idx]._size;
+ byte *ptr = _res->_types[type][idx]._address;
+ uint32 size = _res->_types[type][idx]._size;
ser->saveUint32(size);
ser->saveBytes(ptr, size);
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index 6fe80de..4402445 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -390,26 +390,26 @@ void ScummEngine::getScriptBaseAddress() {
break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory);
- _lastCodePtr = &_res->_types[rtInventory]._resources[idx]._address;
+ _lastCodePtr = &_res->_types[rtInventory][idx]._address;
break;
case WIO_LOCAL:
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
- assert(_roomResource < (int)_res->_types[rtRoomScripts]._resources.size());
- _lastCodePtr = &_res->_types[rtRoomScripts]._resources[_roomResource]._address;
+ assert(_roomResource < (int)_res->_types[rtRoomScripts].size());
+ _lastCodePtr = &_res->_types[rtRoomScripts][_roomResource]._address;
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms);
- _lastCodePtr = &_res->_types[rtRoom]._resources[_roomResource]._address;
+ _lastCodePtr = &_res->_types[rtRoom][_roomResource]._address;
}
break;
case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts);
- _lastCodePtr = &_res->_types[rtScript]._resources[ss->number]._address;
+ _lastCodePtr = &_res->_types[rtScript][ss->number]._address;
break;
case WIO_FLOBJECT: /* flobject script */
@@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject);
- _lastCodePtr = &_res->_types[rtFlObject]._resources[idx]._address;
+ _lastCodePtr = &_res->_types[rtFlObject][idx]._address;
break;
default:
error("Bad type while getting base address");
@@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
- if (_res->_types[rtScript]._resources.size() > 460) {
+ if (_res->_types[rtScript].size() > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index 341f6ec..decd342 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -361,7 +361,7 @@ int ScummEngine_v6::findFreeArrayId() {
int i;
for (i = 1; i < _numArray; i++) {
- if (!rtd._resources[i]._address)
+ if (!rtd[i]._address)
return i;
}
error("Out of array pointers, %d max", _numArray);
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 40b151b..9d14c16 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -1224,7 +1224,7 @@ int ScummEngine::readSoundResource(ResId idx) {
if (!dmuFile.open(buffer)) {
error("Can't open music file %s", buffer);
- _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
+ _res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
dmuFile.seek(4, SEEK_SET);
@@ -1248,7 +1248,7 @@ int ScummEngine::readSoundResource(ResId idx) {
}
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
}
- _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
+ _res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
@@ -2123,7 +2123,7 @@ int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
return 1;
}
- _res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
+ _res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
return 0;
}
More information about the Scummvm-git-logs
mailing list