Well, a Lite-C function that is littered with wait(1) statements is nothing more than a state machine (the code segments that are divided by wait(1) are hereby states) that is called from outside - when the active state of the machine gets called, the code of it gets executed and following state changes can be invoked (like leaving a while or so). Another thing which you'll need to successfully emulate Lite-C functions in C++ is that you have to save A) the parameters and B) the local variables.

One possible solution is the use of function objects. Function objects (or more commonly: functors) are similar to function pointers in C, but with a state. Basically, you set up a special class construct in which you can have arbitrary data members (local variables, etc.) and one specific public method (most commonly denominated as "::Call()") is the execution entry point.

You could now implement a simple switch/case statemachine in such a function object and use the private data members to guarantee persistence to your local variables and parameters independent from each call. Then in a scheduler class you could use a std::vector to store all function objects and use the global engine event (EVENT_FRAME, isn't it?) to let the schedular call on each wait(1) all ::Call() methods of all available function objects.

A simple to understand introduction for functors can be found here:
http://www.newty.de/fpt/functor.html

[EDIT] by "simple to understand" I expect you to have knowledge about basic inheritance, abstract classes and function pointer usage.

Actually, it should be pretty easy to do this. I already thought much about it and this is a neat solution I think. The only drawback is that switch/case statemachine are NOT NEAT, they are evil!! No kidding!!! :-P But it should be sufficient at the beginning.

Regards,
-Christian

Last edited by HeelX; 07/25/10 00:34.