C++20 coroutines have lovely1 syntax. They are also a terrible fit for game development.2
If you’ve ever tried to use them for boss scripts, dialogue, or AI behaviors – anywhere you want straight-line code that pauses for a few frames – you’ve probably hit the same wall I did: opaque handles, heap allocations3, hidden compiler lowering, and – most damning for games – no way to serialize a paused coroutine to disk.
In this article, I will present
sfex::Coroutine: a ~200-line stackless
macro-based coroutine library built around a variant of the classic
switch + __LINE__ trick. Like my previously
discussed sfex::Profiler,
these coroutines are meant to be simple and lightweight.