Skip to content

Commit

Permalink
Scripting|libcore: Rewinding Scheduler to a specific point in time
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 17, 2015
1 parent 976d5ff commit ce71734
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion doomsday/sdk/libcore/include/de/scriptsys/scheduler.h
Expand Up @@ -77,8 +77,10 @@ class DENG2_PUBLIC Scheduler

/**
* Rewinds the clock back to zero.
*
* @param toTime Rewind destination time.
*/
void rewind();
void rewind(TimeDelta const &toTime = 0.0);

/**
* Advances the current time of the clock and executes any scripts whose
Expand Down
22 changes: 15 additions & 7 deletions doomsday/sdk/libcore/src/scriptsys/scheduler.cpp
Expand Up @@ -138,12 +138,20 @@ DENG2_PIMPL_NOREF(Scheduler::Clock)
TimeDelta at = 0.0;
Events events;

void rewind()
void rewind(TimeDelta const &toTime)
{
at = 0.0;
at = toTime;

// Restore all events in the queue.
events = scheduler->d->events; // copied
// Restore events into the queue.
events = scheduler->d->events;
while(!events.empty())
{
if(events.top()->at < at)
{
events.pop();
}
else break;
}
}

void advanceTime(TimeDelta const &elapsed)
Expand All @@ -170,17 +178,17 @@ Scheduler::Clock::Clock(Scheduler const &schedule, Record *context)
{
d->scheduler = &schedule;
d->context = context;
d->rewind();
d->rewind(0.0);
}

TimeDelta Scheduler::Clock::at() const
{
return d->at;
}

void Scheduler::Clock::rewind()
void Scheduler::Clock::rewind(TimeDelta const &toTime)
{
d->rewind();
d->rewind(toTime);
}

void Scheduler::Clock::advanceTime(TimeDelta const &elapsed)
Expand Down

0 comments on commit ce71734

Please sign in to comment.