renBuWen / CoroutineScheduler

A single-threaded CoroutineScheduler that can be used for (but is not limited to) game programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coroutine scheduler

A fast, low-allocation coroutine system with a focus on, but not limited to, games.

The implementation re-uses objects as much a possible using object pooling. The only garbage is generated by creating the IEnumerator when starting the co-routine.

Features

  • Fast, single-threaded co-routine scheduler.
  • Easy to use and very similar to Unity3D co-routines.
  • Co-routines are composable.

Example

IEnumerator SomeRoutine() {
    yield return WaitCommand.WaitSeconds(1f);
    // Do something
    yield return WaitCommand.WaitFrames(5);
	// Do something else
	// Wait for another co-routine to finish
	yield return WaitCommand.WaitRoutine(OtherRoutine());
    yield return WaitCommand.WaitForNextFrame;
	// Finalize
}

// Create a scheduler and start the co-routine
var scheduler = new CoroutineScheduler();
var routine = scheduler.Run(SomeRoutine());

// Dispose routine to cancel it when it is still running
//routine.Dispose();

void Update() {
    // You control the update-rate of the scheduler
    scheduler.Update(Time.FrameCount, Time.CurrentTime);
}

About

A single-threaded CoroutineScheduler that can be used for (but is not limited to) game programming


Languages

Language:C# 100.0%