Gamestudio Links
Zorro Links
Newest Posts
WFO Training with parallel cores Zorro64
by Martin_HH. 02/23/26 10:49
ZorroGPT
by TipmyPip. 02/21/26 19:15
Camera always moves upwards?
by clonman. 02/21/26 09:29
Zorro version 3.0 prerelease!
by TipmyPip. 02/20/26 13:22
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (TipmyPip, alx, Martin_HH), 6,129 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
proper usage of loop wait(1) #340393
09/03/10 18:58
09/03/10 18:58
Joined: Sep 2009
Posts: 1,034
Budapest
Aku_Aku Offline OP
Serious User
Aku_Aku  Offline OP
Serious User

Joined: Sep 2009
Posts: 1,034
Budapest
What would be the proper usage of loop wait(1)? Can i use that?
In this situation:
In the loop i call a function that writes some records into a file. Sometimes it could happen the write slows down.
So i put a wait_for after the function call, inside the loop.
Will the engine handle properly my file updater function?
I am afraid the calls will accumulate and maybe they have to wait the end of the function. And it will go infinitely...

Re: proper usage of loop wait(1) [Re: Aku_Aku] #340410
09/03/10 21:31
09/03/10 21:31
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
depending where you call it from there's no reason to doubt it will work

if you're trying something like
Code:
for(i=0;i<10000;i++){

then dependant on how many functions are being called, it's probably best to use wait(1) (e.g at every 100th iternation), though if you're only writing something like
Code:
for(i=0;i<3;i++){
...
wait(1);

then it's not really worthwhile the engine wait 3 frames for 'no reason'

as a rule i only use wait(1); if something is going to be hogging the cpu, and if it's not critical it's done by a certain time

otherwise i'll use wait(1) while i'm waiting for something to happen, obvious reason while(!player){wait(1);}

but if there's a function that's returning a result, then you'll undoubtedly require wait_for() but you need to ensure this is the only time this function is being called and returned

Re: proper usage of loop wait(1) [Re: MrGuest] #340436
09/04/10 11:43
09/04/10 11:43
Joined: Sep 2009
Posts: 1,034
Budapest
Aku_Aku Offline OP
Serious User
Aku_Aku  Offline OP
Serious User

Joined: Sep 2009
Posts: 1,034
Budapest
My program works like this:
Code:
main() {
  while(1) {
     myfunc();
     wait_for(myfunc);
     wait(1);
  }
}

void myfunc() {
  do some writes into the file
}



Because there are a lot of activity in my program i am afraid the queue with functions waiting processing will increased seconds by seconds.

Last edited by Aku_Aku; 09/04/10 11:44.
Re: proper usage of loop wait(1) [Re: Aku_Aku] #340453
09/04/10 14:10
09/04/10 14:10
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: Aku_Aku
My program works like this:
Code:
main() {
  while(1) {
     myfunc();
     wait_for(myfunc);
     wait(1);
  }
}

void myfunc() {
  do some writes into the file
}



Because there are a lot of activity in my program i am afraid the queue with functions waiting processing will increased seconds by seconds.
in this case i'd just call the function from itself

Code:
void myfunc(){
  //do stuff file writing
  wait(1);
  myfunc();
}

void main(){
  myfunc();
}

hope this helps

Re: proper usage of loop wait(1) [Re: MrGuest] #340455
09/04/10 14:23
09/04/10 14:23
Joined: Sep 2009
Posts: 1,034
Budapest
Aku_Aku Offline OP
Serious User
Aku_Aku  Offline OP
Serious User

Joined: Sep 2009
Posts: 1,034
Budapest
OK, i can see, i have to give a better picture.
For the sake of simplicity i made a real tiny example.
Here is what is closer to the real one:
Code:
main() {
     myent=ent_create(...);
     myent.event=whatever;
}

void whatever() {
  while(1) {
     myfunc();
     wait_for(myfunc);
     wait(1);
  }
}

void myfunc() {
  do some writes into the file
}



Re: proper usage of loop wait(1) [Re: Aku_Aku] #340460
09/04/10 14:49
09/04/10 14:49
Joined: Oct 2009
Posts: 149
Germany
M
muffel Offline
Member
muffel  Offline
Member
M

Joined: Oct 2009
Posts: 149
Germany
if there is no wait in your myfunc-function, there is no Usage for the Wait_for.
My English is to bad to explain it

Click to reveal..

A test Code showing the behaviour of wait
Code:
function fuu()
{
	printf("2 in fuu");
	wait(1);
	printf("3 in fuu after wait");
}
function main()
{
	level_load("");
	
	printf("1 before fuu");
	fuu();
	printf("4 after fuu");
}


The output with wait is
Code:
1 before fuu
2 in fuu
4 after fuu
3 in fuu after wait


The output if wait is commented out
Code:
1 before fuu
2 in fuu
3 in fuu after wait
4 after fuu




The solution of Mr.Guest to make it recursive is very bad.
Using an recursive solution for an endless loop fills the stack fast resulting that the program/system crashes

Code:
main() {
     myent=ent_create(...);
     myent.event=whatever;
}

void whatever() {
  while(1) {
     myfunc();
     wait(1);
  }
}

void myfunc() {
  do some writes into the file
  using no wait
}


this will be OK if you don't use a wait in myfunc

EDIT:
Why do you start an endless lopp inside an event??
Each call of the event results to one more endless loop

muffel

Last edited by muffel; 09/04/10 14:50.
Re: proper usage of loop wait(1) [Re: muffel] #340537
09/05/10 12:28
09/05/10 12:28
Joined: Sep 2009
Posts: 1,034
Budapest
Aku_Aku Offline OP
Serious User
Aku_Aku  Offline OP
Serious User

Joined: Sep 2009
Posts: 1,034
Budapest
Quote:
if there is no wait in your myfunc-function, there is no Usage for the Wait_for.

Are you sure?

Re: proper usage of loop wait(1) [Re: Aku_Aku] #340541
09/05/10 13:02
09/05/10 13:02
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Originally Posted By: Aku_Aku
[quote]if there is no wait in your myfunc-function, there is no Usage for the Wait_for.[quote]
Are you sure?
.

Most definately...

"wait_for" is not an actual function, it is a macro.
It gets replaced by "while( proc_status(function) ) wait(1);"
And proc_status only pays attention to functions that have executed at least one "wait".


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: proper usage of loop wait(1) [Re: EvilSOB] #340544
09/05/10 13:50
09/05/10 13:50
Joined: Sep 2009
Posts: 1,034
Budapest
Aku_Aku Offline OP
Serious User
Aku_Aku  Offline OP
Serious User

Joined: Sep 2009
Posts: 1,034
Budapest
Thanks for Muffel and you.
Based on this information i will review my code.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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