lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 24/02/2014 13.33, John Hind wrote:
For example, I would like to be able to say "yield this coroutine
until some real-time criterion is met" ( yield(for 10 seconds), or
yield(until packet received OR 20 seconds has elapsed) ). This would
enable a style of single-threaded real-time programming similar to
that offered byhttp://www.nodejs.org/  (event driven), except that
scheduling coroutine resumes would be so much more powerful than just
scheduling function execution (as in node.js) because it would
maintain procedural context.

I think this has always been done in game engines (I too wrote one of those schedulers when working in the game industry). Even the Unity3D C# framework does this, although in a rather messy way.

I did some thinking about this idea, including a conceptual design
for  such a scheduler, but never progressed it as far as code.

I cannot publish the code, but if I remember correctly the basic idea of my scheduler was to store coroutines in a table when launching them, with an associated unique ID. The ID was passed to the C scheduler by the yield_until_some_event() functions (e.g. "wait until the end on this animation", or "wait n seconds"); the C scheduler kept a waiting list and awoke the correct coroutine (via its ID) when the desired event happened.

--
  Enrico