View Single Post
Old 19 April 2021, 16:33   #3
Registered User
Join Date: Aug 2018
Location: Untergrund/Germany
Posts: 358
Originally Posted by Jobbo View Post
Very interesting to see co-routines in use on Amiga. I haven't used them myself in other projects but I've seen the concept used in games at least as far back as 1998.

What is the overhead like for yielding and continuing on the Amiga? Is the optimizer able to inline everything to such an extent that it only needs to save a partial context?
Code generation within a coroutine follows the same rules as for any other function call. However, the coroutine itself can't be inlined. A coroutine yield will just restore registers and do a rts.
The code for iterating over and jumping into the coroutines adds also a little bit of extra work, but compared to just calling an array of function pointers and context its not much slower (at least when each of this functions also actually do some work).

Coroutines allow shorter, easier and much better readable code, for very little extra performance impact. Especially for typical 'throw away' game code that only happens once in your game without much structure.
pink^abyss is offline  
Page generated in 0.04952 seconds with 11 queries