Stackless coroutines for gamedev in ~200 lines of C++
10 hours ago
- #Coroutines
- #Game Development
- #C++
- C++20 coroutines are unsuitable for game development due to unpredictable heap allocations, opaque handles, and lack of serialization.
- The sfex::Coroutine library provides allocation-free, trivially serializable, deterministic, and composable coroutines for games.
- It uses a macro-based switch and __COUNTER__ trick for stable state values, avoiding issues with __LINE__ for serialization.
- Coroutines allow straightforward composition via SFEX_CO_AWAIT, enabling hierarchical control flow without complex state machines.
- Key limitations include the need for persistent data as struct members, RAII issues across yields, and debugging challenges.