Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AbrahamR, wdlmaster, 7th_zorro, dr_panther, 1 invisible), 764 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
calling order of while loops #146298
08/06/07 21:25
08/06/07 21:25
Joined: Sep 2003
Posts: 9,859
F
FBL Offline OP
Senior Expert
FBL  Offline OP
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Let's say I have two functions:

Code:

void bla()
{
while(1)
{
//do something
wait(1)
}
}


and
Code:

void blub()
{
bla();
while(1)
{
//do something
wait(1)
}
}


blub calls bla - the while loop of bla starts running.
Afterwards the while loop of blub is started.

Now my question: Is it GUARANTEED that the while loop of bla is ALWAYS processed before the while loop of blub or can there be random behaviour?


Why should someone use a setup like this?
Well, I've written a DLL for a input device. It is used with a script which simualtes key_... and joy_raw values for this device. This is supposed to be done in bla(). The user writes his function blub(), calls the main function for the device one single time (bla) and then can use the values in his own while loop - without having to use proc_late() or whatever. Does this work out, or can it cause a one frame delay (which DOES hurt)?

Last edited by Firoball; 08/06/07 21:30.
Re: calling order of while loops [Re: FBL] #146299
08/06/07 22:53
08/06/07 22:53
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Only JCL can answer this, because he wrote the coroutine support.

The question is: the calling function is stored on the stack before the called function is being called. So, the wait call of the called action would be placed in the queue before the wait instruction of the calling function in the very first frame. But it could be as well the case that the wait instructions are executed in the order of the calls of the functions - so the wait instruction of the called function would be executed after the wait call of the calling function.

Nevertheless if 1 frame delay would hurt you or not, this is definitely not good. Normally you use for such a behaviour frame functions (or callbacks for generic code):

Code:
function funcA (...) {...}
function funcB (...) {...}

function funcMain (...)
{
while (1) {
funcA();
funcB();
wait(1);
}
}



By this you assure the right order of your calculations and have no trouble with coroutines. If you are in the case that another programmer does sloppy coroutine programming, simply kick his ass or write it yourself

Re: calling order of while loops [Re: FBL] #146300
08/06/07 23:22
08/06/07 23:22
Joined: Jul 2003
Posts: 82
Southern California
lucidman Offline
Junior Member
lucidman  Offline
Junior Member

Joined: Jul 2003
Posts: 82
Southern California
Hi Firoball,

It's been my my experience that the scheduling of multiple functions with imbedded "while(1) {wait(1);}" is very deterministic, and there is no randomness at all. I strongly suspect that once you have setup an order of execution (i.e. bla first, then blub), it will stay the same for each frame. Don't take my word for it. You can test this easily with some debug logging.

Lucidman


Vision is mind
Mind is emptiness
Empty is clear light
Clear light is union
Union is great bliss
Re: calling order of while loops [Re: lucidman] #146301
08/07/07 06:35
08/07/07 06:35
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Functions run in the same order they were started. For changing the order of functions see proc_mode ( http://manual.conitec.net/proc_mode.htm ).

Re: calling order of while loops [Re: jcl] #146302
08/07/07 16:08
08/07/07 16:08
Joined: Sep 2003
Posts: 9,859
F
FBL Offline OP
Senior Expert
FBL  Offline OP
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Ok, so if I understood correct, my sample setup should work as intended.

Thanks to all contributors.


Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1