WeSearch

Stackless coroutines for gamedev in ~200 lines of C++

·21 min read · 0 reactions · 0 comments · 2 views
#gamedev#c++#coroutines#serialization#performance
Stackless coroutines for gamedev in ~200 lines of C++
⚡ TL;DR · AI summary

C++20 coroutines, while syntactically elegant, are poorly suited for game development due to issues like heap allocations, opaque state, and lack of serializability. The article presents sfex::Coroutine, a lightweight, stackless coroutine library in about 200 lines of C++ that avoids these pitfalls. It enables allocation-free, serializable, and deterministic coroutines ideal for use in boss scripts, dialogue systems, and AI behaviors.

Key facts
Original article
Vittorioromeo
Read full at Vittorioromeo →
Opening excerpt (first ~120 words) tap to expand

stackless coroutines for gamedev in ~200 lines of C++ 01 may 2026 c++ c++20 coroutines 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.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Vittorioromeo.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Vittorioromeo