Skip to content

Commit

Permalink
NEVERHOOD: Don't load a DataResource if the same data is already load…
Browse files Browse the repository at this point in the history
…ed; this fixes a nasty bug in several scenes which use message lists from a DataResource
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent eea9dbe commit e51bea9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions engines/neverhood/gamemodule.cpp
Expand Up @@ -400,9 +400,9 @@ void GameModule::startup() {
// <<<DEBUG

#if 1
_vm->gameState().which = 0;
_vm->gameState().sceneNum = 0;
createModule(2500, -1);
_vm->gameState().which = 1;
_vm->gameState().sceneNum = 1;
createModule(1000, -1);
#endif
#if 0
_vm->gameState().sceneNum = 5;
Expand Down
6 changes: 4 additions & 2 deletions engines/neverhood/resource.cpp
Expand Up @@ -353,7 +353,9 @@ DataResource::~DataResource() {
}

void DataResource::load(uint32 fileHash) {
debug(2, "DataResource::load(%08X)", fileHash);
if (_resourceHandle.fileHash() == fileHash)
return;
debug("DataResource::load(%08X)", fileHash);
const byte *data = NULL;
uint32 dataSize = 0;
unload();
Expand Down Expand Up @@ -497,7 +499,6 @@ void DataResource::load(uint32 fileHash) {
}

void DataResource::unload() {
_vm->_res->unloadResource(_resourceHandle);
_directory.clear();
_points.clear();
for (Common::Array<NPointArray*>::iterator it = _pointArrays.begin(); it != _pointArrays.end(); ++it)
Expand All @@ -516,6 +517,7 @@ void DataResource::unload() {
for (Common::Array<DRSubRectList*>::iterator it = _drSubRectLists.begin(); it != _drSubRectLists.end(); ++it)
delete (*it);
_drSubRectLists.clear();
_vm->_res->unloadResource(_resourceHandle);
}

NPoint DataResource::getPoint(uint32 nameHash) {
Expand Down
11 changes: 10 additions & 1 deletion engines/neverhood/scene.cpp
Expand Up @@ -397,7 +397,16 @@ void Scene::processMessageList() {
_messageListStatus = 0;
}

if (_messageList && _klayman) {
if (_messageList && _klayman) {

#if 0
debug("MessageList: %p, %d", (void*)_messageList, _messageList->size());
for (uint i = 0; i < _messageList->size(); ++i) {
if (i == _messageListIndex) debugN("**"); else debugN(" ");
debug("(%08X, %08X)", (*_messageList)[i].messageNum, (*_messageList)[i].messageValue);
}
debug("--------------------------------");
#endif

while (_messageList && _messageListIndex < _messageListCount && !_isKlaymanBusy) {
uint32 messageNum = (*_messageList)[_messageListIndex].messageNum;
Expand Down
12 changes: 6 additions & 6 deletions engines/neverhood/staticdata.cpp
Expand Up @@ -42,7 +42,7 @@ void StaticData::load(const char *filename) {

// Load message lists
uint32 messageListsCount = fd.readUint32LE();
debug("messageListsCount: %d", messageListsCount);
debug(3, "messageListsCount: %d", messageListsCount);
for (uint32 i = 0; i < messageListsCount; i++) {
MessageList *messageList = new MessageList();
uint32 id = fd.readUint32LE();
Expand All @@ -58,7 +58,7 @@ void StaticData::load(const char *filename) {

// Load rect lists
uint32 rectListsCount = fd.readUint32LE();
debug("rectListsCount: %d", rectListsCount);
debug(3, "rectListsCount: %d", rectListsCount);
for (uint32 i = 0; i < rectListsCount; i++) {
RectList *rectList = new RectList();
uint32 id = fd.readUint32LE();
Expand Down Expand Up @@ -87,7 +87,7 @@ void StaticData::load(const char *filename) {

// Load hit rects
uint32 hitRectListsCount = fd.readUint32LE();
debug("hitRectListsCount: %d", hitRectListsCount);
debug(3, "hitRectListsCount: %d", hitRectListsCount);
for (uint32 i = 0; i < hitRectListsCount; i++) {
HitRectList *hitRectList = new HitRectList();
uint32 id = fd.readUint32LE();
Expand All @@ -106,7 +106,7 @@ void StaticData::load(const char *filename) {

// Load navigation lists
uint32 navigationListsCount = fd.readUint32LE();
debug("navigationListsCount: %d", navigationListsCount);
debug(3, "navigationListsCount: %d", navigationListsCount);
for (uint32 i = 0; i < navigationListsCount; i++) {
NavigationList *navigationList = new NavigationList();
uint32 id = fd.readUint32LE();
Expand All @@ -127,7 +127,7 @@ void StaticData::load(const char *filename) {

// Load HallOfRecordsInfo items
uint32 hallOfRecordsInfoItemsCount = fd.readUint32LE();
debug("hallOfRecordsInfoItemsCount: %d", hallOfRecordsInfoItemsCount);
debug(3, "hallOfRecordsInfoItemsCount: %d", hallOfRecordsInfoItemsCount);
for (uint32 i = 0; i < hallOfRecordsInfoItemsCount; i++) {
HallOfRecordsInfo *hallOfRecordsInfo = new HallOfRecordsInfo();
uint32 id = fd.readUint32LE();
Expand All @@ -142,7 +142,7 @@ void StaticData::load(const char *filename) {

// Load TrackInfo items
uint32 trackInfoItemsCount = fd.readUint32LE();
debug("trackInfoItemsCount: %d", trackInfoItemsCount);
debug(3, "trackInfoItemsCount: %d", trackInfoItemsCount);
for (uint32 i = 0; i < trackInfoItemsCount; i++) {
TrackInfo *trackInfo = new TrackInfo();
uint32 id = fd.readUint32LE();
Expand Down

0 comments on commit e51bea9

Please sign in to comment.