diff options
author | Arnaud Boutonné | 2010-12-17 23:12:36 +0000 |
---|---|---|
committer | Arnaud Boutonné | 2010-12-17 23:12:36 +0000 |
commit | 222d2809e93fd774c44c78c23628a478ec68b7a1 (patch) | |
tree | 5ab818ac3768129b024d03bd60db4f1a2c410158 /engines/hugo/schedule.cpp | |
parent | 7daea87e617198796220f5915b43fd27d57772e6 (diff) | |
download | scummvm-rg350-222d2809e93fd774c44c78c23628a478ec68b7a1.tar.gz scummvm-rg350-222d2809e93fd774c44c78c23628a478ec68b7a1.tar.bz2 scummvm-rg350-222d2809e93fd774c44c78c23628a478ec68b7a1.zip |
HUGO: little code cleanup
svn-id: r54948
Diffstat (limited to 'engines/hugo/schedule.cpp')
-rw-r--r-- | engines/hugo/schedule.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp index 6ea7bfd273..6e4e4f5de3 100644 --- a/engines/hugo/schedule.cpp +++ b/engines/hugo/schedule.cpp @@ -537,7 +537,7 @@ void Scheduler::loadActListArr(Common::File &in) { break; case OLD_SONG: //49 _actListArr[i][j].a49.timer = in.readSint16BE(); - _actListArr[i][j].a49.soundIndex = in.readUint16BE(); + _actListArr[i][j].a49.songIndex = in.readUint16BE(); break; default: error("Engine - Unknown action type encountered: %d", _actListArr[i][j].a0.actType); @@ -948,4 +948,56 @@ void Scheduler::restoreEvents(Common::SeekableReadStream *f) { } } +/** +* Insert the action pointed to by p into the timer event queue +* The queue goes from head (earliest) to tail (latest) timewise +*/ +void Scheduler::insertAction(act *action) { + debugC(1, kDebugSchedule, "insertAction() - Action type A%d", action->a0.actType); + + // First, get and initialise the event structure + event_t *curEvent = getQueue(); + curEvent->action = action; + switch (action->a0.actType) { // Assign whether local or global + case AGSCHEDULE: + curEvent->localActionFl = false; // Lasts over a new screen + break; + default: + curEvent->localActionFl = true; // Rest are for current screen only + break; + } + + curEvent->time = action->a0.timer + getTicks(); // Convert rel to abs time + + // Now find the place to insert the event + if (!_tailEvent) { // Empty queue + _tailEvent = _headEvent = curEvent; + curEvent->nextEvent = curEvent->prevEvent = 0; + } else { + event_t *wrkEvent = _tailEvent; // Search from latest time back + bool found = false; + + while (wrkEvent && !found) { + if (wrkEvent->time <= curEvent->time) { // Found if new event later + found = true; + if (wrkEvent == _tailEvent) // New latest in list + _tailEvent = curEvent; + else + wrkEvent->nextEvent->prevEvent = curEvent; + curEvent->nextEvent = wrkEvent->nextEvent; + wrkEvent->nextEvent = curEvent; + curEvent->prevEvent = wrkEvent; + } + wrkEvent = wrkEvent->prevEvent; + } + + if (!found) { // Must be earliest in list + _headEvent->prevEvent = curEvent; // So insert as new head + curEvent->nextEvent = _headEvent; + curEvent->prevEvent = 0; + _headEvent = curEvent; + } + } +} + } // End of namespace Hugo |