Simple update scheduler and ticker for your game.
$ dotnet add package RedHerring.AlibiSimple update scheduler and ticker for your game. Use this if you want to have better control when your updates get called and free up some performance.
The basic idea is that whatever callback you schedule, the only guarantee is that the callback will not be called before its due time.
There is, however, no guarantee that it will be called precisely when scheduled.
All time-related parameters are either a TimeSpan or a long in milliseconds.
Scheduler(TimeSpan startingTime, long frameBudget);
startingTime - starting time for ticks
frameBudget - the maximum amount of time per one invoke of the Tick method
void Tick(TimeSpan time);
time - game time according to which scheduled updates should be invoked.
Starts calling scheduled updates until it exceeds the frameBudget specified within constructor.
void Dispose();
Basic cleanup when getting rid of the scheduler.
void SetFrameBudget(long frameBudget);
Sets the new frame budget. Useful when changing target framerate of the application during runtime.
public delegate void DeferredUpdate(double elapsedTime);
IDisposable Schedule(DeferredUpdate update, long dueTime);
IDisposable ScheduleRepeating(DeferredUpdate update, long period);
The specified callback will be called after dueTime has elapsed, but not before.
Optionally, a recurring callback can be specified with a period.
The callback can be unscheduled by disposing of the IDisposable object.
Notice: Callback will never be called within the same tick as it was scheduled.
void Unschedule(DeferredUpdate update);
The specified callback will be unregistered from scheduled updates.
All scheduled updated will be unscheduled.
Calls registered updates each tick, regardless of time.
public delegate void TickUpdate();
IDisposable Add(TickUpdate update);
IDisposable Add(TickUpdate update, int priority);
priority - priority with which the update is to be called (higher means sooner).
Adds the specified callback to the list of updates to be called during a tick.
bool Remove(TickUpdate update)