[Scummvm-cvs-logs] SF.net SVN: scummvm:[55540] scummvm/trunk/engines/hugo
sylvaintv at users.sourceforge.net
sylvaintv at users.sourceforge.net
Wed Jan 26 01:21:55 CET 2011
Revision: 55540
http://scummvm.svn.sourceforge.net/scummvm/?rev=55540&view=rev
Author: sylvaintv
Date: 2011-01-26 00:21:54 +0000 (Wed, 26 Jan 2011)
Log Message:
-----------
HUGO: Fix some save/restore issues
Invalidates current savegames! (now version 3)
Modified Paths:
--------------
scummvm/trunk/engines/hugo/file.cpp
scummvm/trunk/engines/hugo/hugo.h
scummvm/trunk/engines/hugo/schedule.cpp
scummvm/trunk/engines/hugo/schedule.h
Modified: scummvm/trunk/engines/hugo/file.cpp
===================================================================
--- scummvm/trunk/engines/hugo/file.cpp 2011-01-25 20:21:57 UTC (rev 55539)
+++ scummvm/trunk/engines/hugo/file.cpp 2011-01-26 00:21:54 UTC (rev 55540)
@@ -390,6 +390,9 @@
// Now save current time and all current events in event queue
_vm->_scheduler->saveEvents(out);
+ // Now save current actions
+ _vm->_scheduler->saveActions(out);
+
// Save palette table
_vm->_screen->savePal(out);
@@ -495,6 +498,9 @@
// Now restore time of the save and the event queue
_vm->_scheduler->restoreEvents(in);
+ // Now restore actions
+ _vm->_scheduler->restoreActions(in);
+
// Restore palette and change it if necessary
_vm->_screen->restorePal(in);
Modified: scummvm/trunk/engines/hugo/hugo.h
===================================================================
--- scummvm/trunk/engines/hugo/hugo.h 2011-01-25 20:21:57 UTC (rev 55539)
+++ scummvm/trunk/engines/hugo/hugo.h 2011-01-26 00:21:54 UTC (rev 55540)
@@ -58,7 +58,7 @@
*/
namespace Hugo {
-static const int kSavegameVersion = 2;
+static const int kSavegameVersion = 3;
static const int kInvDx = 32; // Width of an inventory icon
static const int kInvDy = 32; // Height of inventory icon
static const int kMaxTunes = 16; // Max number of tunes
Modified: scummvm/trunk/engines/hugo/schedule.cpp
===================================================================
--- scummvm/trunk/engines/hugo/schedule.cpp 2011-01-25 20:21:57 UTC (rev 55539)
+++ scummvm/trunk/engines/hugo/schedule.cpp 2011-01-26 00:21:54 UTC (rev 55540)
@@ -47,6 +47,7 @@
namespace Hugo {
Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0) {
+ memset(_events, 0, sizeof(_events));
}
Scheduler::~Scheduler() {
@@ -896,6 +897,12 @@
for (int16 i = 0; i < kMaxEvents; i++) {
event_t *wrkEvent = &_events[i];
saveEventArr[i] = *wrkEvent;
+
+ // fix up action pointer (to do better)
+ int16 index, subElem;
+ findAction(saveEventArr[i].action, &index, &subElem);
+ saveEventArr[i].action = (act*)((index << 16)| subElem);
+
saveEventArr[i].prevEvent = (wrkEvent->prevEvent == 0) ? (event_t *) - 1 : (event_t *)(wrkEvent->prevEvent - _events);
saveEventArr[i].nextEvent = (wrkEvent->nextEvent == 0) ? (event_t *) - 1 : (event_t *)(wrkEvent->nextEvent - _events);
}
@@ -904,6 +911,79 @@
warning("TODO: serialize saveEventArr");
}
+/**
+* Restore the action data from file with handle f
+*/
+
+void Scheduler::restoreActions(Common::SeekableReadStream *f) {
+
+ for (int i = 0; i < _actListArrSize; i++) {
+
+ // read all the sub elems
+ int j = 0;
+ do {
+
+ // handle special case for a3, keep list pointer
+ int* responsePtr = 0;
+ if (_actListArr[i][j].a3.actType == PROMPT) {
+ responsePtr = _actListArr[i][j].a3.responsePtr;
+ }
+
+ f->read(&_actListArr[i][j], sizeof(act));
+
+ // handle special case for a3, reset list pointer
+ if (_actListArr[i][j].a3.actType == PROMPT) {
+ _actListArr[i][j].a3.responsePtr = responsePtr;
+ }
+ j++;
+ } while (_actListArr[i][j-1].a0.actType != ANULL);
+ }
+}
+
+/*
+* Save the action data in the file with handle f
+*/
+
+void Scheduler::saveActions(Common::WriteStream* f) {
+ for (int i = 0; i < _actListArrSize; i++) {
+ // write all the sub elems data
+
+ int j = 0;
+ do {
+ f->write(&_actListArr[i][j], sizeof(act));
+ j++;
+ } while (_actListArr[i][j-1].a0.actType != ANULL);
+ }
+}
+
+/*
+* Find the index in the action list to be able to serialize the action to save game
+*/
+
+void Scheduler::findAction(act* action, int16* index, int16* subElem) {
+
+ assert(index && subElem);
+ if (!action) {
+ *index = -1;
+ *subElem = -1;
+ return;
+ }
+
+ for (int i = 0; i < _actListArrSize; i++) {
+ int j = 0;
+ do {
+ if (action == &_actListArr[i][j]) {
+ *index = i;
+ *subElem = j;
+ return;
+ }
+ j++;
+ } while (_actListArr[i][j-1].a0.actType != ANULL);
+ }
+ // action not found ??
+ assert(0);
+}
+
/**
* Restore the event list from file with handle f
*/
@@ -923,6 +1003,13 @@
for (int i = 0; i < kMaxEvents; i++) {
wrkEvent = &savedEvents[i];
_events[i] = *wrkEvent;
+ // fix up action pointer (to do better)
+ int32 val = (size_t)_events[i].action;
+ if ((val & 0xffff) == 0xffff) {
+ _events[i].action = 0;
+ } else {
+ _events[i].action = (act*)&_actListArr[val >> 16][val & 0xffff];
+ }
_events[i].prevEvent = (wrkEvent->prevEvent == (event_t *) - 1) ? (event_t *)0 : &_events[(size_t)wrkEvent->prevEvent ];
_events[i].nextEvent = (wrkEvent->nextEvent == (event_t *) - 1) ? (event_t *)0 : &_events[(size_t)wrkEvent->nextEvent ];
}
Modified: scummvm/trunk/engines/hugo/schedule.h
===================================================================
--- scummvm/trunk/engines/hugo/schedule.h 2011-01-25 20:21:57 UTC (rev 55539)
+++ scummvm/trunk/engines/hugo/schedule.h 2011-01-26 00:21:54 UTC (rev 55540)
@@ -471,6 +471,10 @@
void saveEvents(Common::WriteStream *f);
void waitForRefresh(void);
+ void findAction(act* action, int16* index, int16* subElem);
+ void saveActions(Common::WriteStream* f);
+ void restoreActions(Common::SeekableReadStream *f);
+
protected:
HugoEngine *_vm;
static const int kFilenameLength = 12; // Max length of a DOS file name
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list