From 222d2809e93fd774c44c78c23628a478ec68b7a1 Mon Sep 17 00:00:00 2001 From: Arnaud Boutonné Date: Fri, 17 Dec 2010 23:12:36 +0000 Subject: HUGO: little code cleanup svn-id: r54948 --- engines/hugo/schedule.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'engines/hugo/schedule.cpp') 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 -- cgit v1.2.3