Skip to content

Commit

Permalink
SCUMM: Move _heV7RoomIntOffsets from ScummEngine to ScummEngine_v70he
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Apr 5, 2011
1 parent 8275619 commit 7ce3719
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 44 deletions.
4 changes: 4 additions & 0 deletions engines/scumm/he/intern_he.h
Expand Up @@ -115,6 +115,7 @@ class ScummEngine_v70he : public ScummEngine_v60he {

byte *_heV7DiskOffsets;
byte *_heV7RoomOffsets;
uint32 *_heV7RoomIntOffsets;

int32 _heSndSoundId, _heSndOffset, _heSndChannel, _heSndFlags, _heSndSoundFreq;

Expand All @@ -130,6 +131,9 @@ class ScummEngine_v70he : public ScummEngine_v60he {
void restoreBackgroundHE(Common::Rect rect, int dirtybit = 0);

protected:
virtual void allocateArrays();
virtual int readResTypeList(int id);
virtual uint32 getResourceRoomOffset(int type, int idx);
virtual void setupOpcodes();

virtual void setupScummVars();
Expand Down
2 changes: 1 addition & 1 deletion engines/scumm/he/sprite_he.cpp
Expand Up @@ -46,7 +46,7 @@ Sprite::~Sprite() {
}

void ScummEngine_v90he::allocateArrays() {
ScummEngine::allocateArrays();
ScummEngine_v70he::allocateArrays();
_sprite->allocTables(_numSprites, MAX(64, _numSprites / 4), 64);
}

Expand Down
82 changes: 48 additions & 34 deletions engines/scumm/resource.cpp
Expand Up @@ -167,8 +167,6 @@ void ScummEngine::deleteRoomOffsets() {

/** Read room offsets */
void ScummEngine::readRoomsOffsets() {
int num, room;

debug(9, "readRoomOffsets()");

if (_game.features & GF_SMALL_HEADER) {
Expand All @@ -177,13 +175,12 @@ void ScummEngine::readRoomsOffsets() {
_fileHandle->seek(16, SEEK_SET);
}

num = _fileHandle->readByte();
int num = _fileHandle->readByte();
while (num--) {
room = _fileHandle->readByte();
int room = _fileHandle->readByte();
int offset = _fileHandle->readUint32LE();
if (_res->roomoffs[rtRoom][room] != RES_INVALID_OFFSET) {
_res->roomoffs[rtRoom][room] = _fileHandle->readUint32LE();
} else {
_fileHandle->readUint32LE();
_res->roomoffs[rtRoom][room] = offset;
}
}
}
Expand Down Expand Up @@ -491,7 +488,7 @@ void ScummEngine::readArrayFromIndexFile() {
error("readArrayFromIndexFile() not supported in pre-V6 games");
}

void ScummEngine::readResTypeList(int id) {
int ScummEngine::readResTypeList(int id) {
int num;
int i;

Expand All @@ -511,16 +508,27 @@ void ScummEngine::readResTypeList(int id) {
}
for (i = 0; i < num; i++) {
_res->roomoffs[id][i] = _fileHandle->readUint32LE();

if (id == rtRoom && _game.heversion >= 70)
_heV7RoomIntOffsets[i] = _res->roomoffs[id][i];
}

if (_game.heversion >= 70) {
return num;
}

int ScummEngine_v70he::readResTypeList(int id) {
int num;
int i;

num = ScummEngine::readResTypeList(id);

if (id == rtRoom)
for (i = 0; i < num; i++) {
_res->globsize[id][i] = _fileHandle->readUint32LE();
_heV7RoomIntOffsets[i] = _res->roomoffs[rtRoom][i];
}

for (i = 0; i < num; i++) {
_res->globsize[id][i] = _fileHandle->readUint32LE();
}

return num;
}

void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) {
Expand Down Expand Up @@ -635,18 +643,9 @@ int ScummEngine::loadResource(int type, int idx) {
if (roomNr == 0)
roomNr = _roomResource;

if (type == rtRoom) {
if (_game.version == 8)
fileOffs = 8;
else if (_game.heversion >= 70)
fileOffs = _heV7RoomIntOffsets[idx];
else
fileOffs = 0;
} else {
fileOffs = _res->roomoffs[type][idx];
if (fileOffs == RES_INVALID_OFFSET)
return 0;
}
fileOffs = getResourceRoomOffset(type, idx);
if (fileOffs == RES_INVALID_OFFSET)
return 0;

openRoom(roomNr);

Expand Down Expand Up @@ -691,13 +690,11 @@ int ScummEngine::loadResource(int type, int idx) {
dumpResource("script-", idx, getResourceAddress(rtScript, idx));
}

if (!_fileHandle->err() && !_fileHandle->eos()) {
return 1;
if (_fileHandle->err() || _fileHandle->eos()) {
error("Cannot read resource");
}

_res->nukeResource(type, idx);

error("Cannot read resource");
return 1;
}

int ScummEngine::getResourceRoomNr(int type, int idx) {
Expand All @@ -706,6 +703,20 @@ int ScummEngine::getResourceRoomNr(int type, int idx) {
return _res->roomno[type][idx];
}

uint32 ScummEngine::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0;
}
return _res->roomoffs[type][idx];
}

uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) {
return _heV7RoomIntOffsets[idx];
}
return _res->roomoffs[type][idx];
}

int ScummEngine::getResourceSize(int type, int idx) {
byte *ptr = getResourceAddress(type, idx);
assert(ptr);
Expand Down Expand Up @@ -1295,13 +1306,16 @@ void ScummEngine::allocateArrays() {
_res->allocResTypeData(rtMatrix, 0, 10, "boxes", 0);
_res->allocResTypeData(rtImage, MKID_BE('AWIZ'), _numImages, "images", 1);
_res->allocResTypeData(rtTalkie, MKID_BE('TLKE'), _numTalkies, "talkie", 1);
}

if (_game.heversion >= 70) {
_res->allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", 1);
_heV7RoomIntOffsets = (uint32 *)calloc(_numRooms, sizeof(uint32));
}
void ScummEngine_v70he::allocateArrays() {
ScummEngine::allocateArrays();

_res->allocResTypeData(rtSpoolBuffer, 0, 9, "spool buffer", 1);
_heV7RoomIntOffsets = (uint32 *)calloc(_numRooms, sizeof(uint32));
}


void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
char buf[256];
Common::DumpFile out;
Expand Down
4 changes: 3 additions & 1 deletion engines/scumm/resource_v3.cpp
Expand Up @@ -32,7 +32,7 @@ namespace Scumm {

extern const char *resTypeFromId(int id);

void ScummEngine_v3old::readResTypeList(int id) {
int ScummEngine_v3old::readResTypeList(int id) {
int num;
int i;

Expand All @@ -57,6 +57,8 @@ void ScummEngine_v3old::readResTypeList(int id) {
if (_res->roomoffs[id][i] == 0xFFFF)
_res->roomoffs[id][i] = (uint32)RES_INVALID_OFFSET;
}

return num;
}

void ScummEngine_v3old::readIndexFile() {
Expand Down
4 changes: 3 additions & 1 deletion engines/scumm/resource_v4.cpp
Expand Up @@ -33,7 +33,7 @@ namespace Scumm {

extern const char *resTypeFromId(int id);

void ScummEngine_v4::readResTypeList(int id) {
int ScummEngine_v4::readResTypeList(int id) {
int num;
int i;

Expand All @@ -49,6 +49,8 @@ void ScummEngine_v4::readResTypeList(int id) {
_res->roomno[id][i] = _fileHandle->readByte();
_res->roomoffs[id][i] = _fileHandle->readUint32LE();
}

return num;
}

void ScummEngine_v4::readIndexFile() {
Expand Down
4 changes: 2 additions & 2 deletions engines/scumm/scumm.cpp
Expand Up @@ -201,7 +201,6 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
_bootParam = 0;
_dumpScripts = false;
_debugMode = 0;
_heV7RoomIntOffsets = NULL;
_objectOwnerTable = NULL;
_objectRoomTable = NULL;
_objectStateTable = NULL;
Expand Down Expand Up @@ -789,6 +788,7 @@ ScummEngine_v70he::ScummEngine_v70he(OSystem *syst, const DetectorResult &dr)

_heV7DiskOffsets = NULL;
_heV7RoomOffsets = NULL;
_heV7RoomIntOffsets = NULL;

_heSndSoundId = 0;
_heSndOffset = 0;
Expand All @@ -805,8 +805,8 @@ ScummEngine_v70he::ScummEngine_v70he(OSystem *syst, const DetectorResult &dr)
ScummEngine_v70he::~ScummEngine_v70he() {
delete _resExtractor;
free(_heV7DiskOffsets);
free(_heV7RoomIntOffsets);
free(_heV7RoomOffsets);
free(_heV7RoomIntOffsets);
free(_storedFlObjects);
}

Expand Down
6 changes: 3 additions & 3 deletions engines/scumm/scumm.h
Expand Up @@ -773,7 +773,6 @@ class ScummEngine : public Engine {
protected:
int _resourceHeaderSize;
byte _resourceMapper[128];
uint32 *_heV7RoomIntOffsets;
const byte *_resourceLastSearchBuf; // FIXME: need to put it to savefile?
uint32 _resourceLastSearchSize; // FIXME: need to put it to savefile?

Expand All @@ -786,19 +785,20 @@ class ScummEngine : public Engine {
bool openResourceFile(const Common::String &filename, byte encByte); // TODO: Use Common::String

void loadPtrToResource(int type, int i, const byte *ptr);
virtual void readResTypeList(int id);
virtual int readResTypeList(int id);
// void allocResTypeData(int id, uint32 tag, int num, const char *name, 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);

public:
byte *getResourceAddress(int type, int i);
virtual byte *getStringAddress(int i);
byte *getStringAddressVar(int i);
void ensureResourceLoaded(int type, int i);
int getResourceRoomNr(int type, int index);

protected:
int readSoundResource(int index);
Expand Down
2 changes: 1 addition & 1 deletion engines/scumm/scumm_v3.h
Expand Up @@ -62,7 +62,7 @@ class ScummEngine_v3old : public ScummEngine_v3 {
ScummEngine_v3old(OSystem *syst, const DetectorResult &dr);

protected:
virtual void readResTypeList(int id);
virtual int readResTypeList(int id);
virtual void readIndexFile();
virtual void setupRoomSubBlocks();
virtual void resetRoomSubBlocks();
Expand Down
2 changes: 1 addition & 1 deletion engines/scumm/scumm_v4.h
Expand Up @@ -59,7 +59,7 @@ class ScummEngine_v4 : public ScummEngine_v5 {

virtual void scummLoop_handleSaveLoad();

virtual void readResTypeList(int id);
virtual int readResTypeList(int id);
virtual void readIndexFile();
virtual void loadCharset(int no);
virtual void resetRoomObjects();
Expand Down

0 comments on commit 7ce3719

Please sign in to comment.