News for hackers. Stuff that matters.
Re:Simple coroutines for games in C++ by derefr on Sunday March 20, 2016 @03:48PM (#11324334)
Re: coroutines in games more generally, you can look to older console games (NES/SNES-era) for some good examples. Earlier games on the C64 et al were—as is commonly explained—purely event-loop based; but by the mid-1980s, the paradigm had switched to using a hardcoded coroutine-scheduled actor model.

If you've never read it, the Super Mario Bros 1 disassembly[1] is extremely enlightening. It feels a lot like Erlang, with individual parallel "process" actors being responsible for updating the physics of each sprite on screen—but instead of a "process" being an abstraction handled by a scheduler, it's just an entry-point function that calls a finite-state-machine-state function, then either calls a hardwired next "process" function, or a trampoline function that calls whatever is left to run in that game state. Effectively, it's a "direct-threaded next-jmp-prefetched" implementation of scheduling.

[1] https://gist.github.com/1wErt3r/4048722

There are no comments on this comment yet.