Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, AndrewAMD), 593 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Wait Question #441291
05/18/14 03:50
05/18/14 03:50
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Quote:
wait(1) is often used at the end of a while loop which is to be executed once per frame cycle.


As the manual states, a wait is generally used at the end of a while loop. If all my loops have a wait(1) at the beginning of them, could that really effect my code in a negative way?

Could It make things behave in such a way that they "wait before they do", rather than "do then wait".. kinda resulting in bad performance? NOt sure if this example is clear enough :?

Last edited by DLively; 05/18/14 03:51.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Wait Question [Re: DLively] #441295
05/18/14 05:31
05/18/14 05:31
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline
Senior Member
xbox  Offline
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
I think, and I could be wrong, that putting a wait(1) at the end of a while loop is just good practice. Personally, after learning it at the end of a while loop, I can't put it any where else. I'm sure someone with more experience will correct me if I'm wrong but having the wait(1) at the beginning technically will be a "wait before they do" rather than "do then wait" but it will only be for a single frame so it won't be noticeable at all, unless the frame rate drops substantially. If worse comes to worse, at least moving a single line to the end of a loop isn't difficult to do tongue

Last edited by xbox; 05/18/14 05:33.
Re: Wait Question [Re: xbox] #441297
05/18/14 10:40
05/18/14 10:40
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
The only difference you will see is when your function yields back to others and when it performs its operation. You can also have a wait in the middle if that tickles your fancy, your local variables and my and you will be restored. However, note that wait() allows other functions to resume execution which may or may not have side effects on globals that you have to take into account. Of course only if it applies to your use case.

Something I really want to stress though: You don't need a wait() in your loops if they terminate by themselves! That is, unless you have a loop that you want to execute once per frame (or in similar intervals), putting a wait() will be decremental to your performance! I see that way too often that beginners assume that a wait() is a must within a loop or otherwise their program will halt.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Wait Question [Re: WretchedSid] #441299
05/18/14 16:00
05/18/14 16:00
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
My practice has been to put the waits just after the while's curly bracket {wait(1);..

My question now, is how to have a loop without a wait??? I always get an engine crash without one... laugh


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Wait Question [Re: DLively] #441300
05/18/14 16:04
05/18/14 16:04
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Code:
int i;
for(i = 0; i < 5; i++)
{
     //do some things here
}

//and continue without a crash



Code:
while(str_len(strMsg) > 0)
{
    str_trunc(strMsg, 1);
}



and so on...

Re: Wait Question [Re: DLively] #441302
05/18/14 16:25
05/18/14 16:25
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: DLively
My question now, is how to have a loop without a wait??? I always get an engine crash without one... laugh

Hanging != crashing!

Crashing means that all computation stops, hanging just means that you do computation without giving the window event handler any time to do its own processing, which the OS will then take as: Alright, it's not responding.

This, will hang your program, but not crash it:
Code:
while(1)
{}



Soo... How do you write loops that don't hang? Well, have them terminate at some point!

Take this strcpy function as an example:
Code:
char *strcpy(char *dst, const char *src)
{
	char *d = dst;

	while(1)
	{
		*dst = *src;

		if(*src == '\0')
			break;

		dst ++;
		src ++;
	}

	return d;
}



The loop will automatically terminate once the source string reached the end. So, why shouldn't you put a wait in there? Quite simply, first of all because it has a return value and that would never reach the caller with a wait (remember, wait doesn't allow the callee to return values), and secondly because it's superfluous in the first place!

You don't want your string copy operation to take multiple frames, you want to call it and have the result immediately. Your program won't hang, even for long strings, because copying the memory around is insanely fast especially once the CPUs branch predictor kicks in.


Of course, that doesn't mean wait in loops doesn't have its use case! Everything that you want to get periodically done every frame or so, well, use wait, that's what it's there for!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Wait Question [Re: WretchedSid] #441312
05/19/14 01:17
05/19/14 01:17
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Thanks Guys laugh

Awesome Read Sid, I really enjoyed how detailed you made it. You couldn't have made that any more clear for me laugh I am excited to put it to practice now ^_^
Your tip should be put in the manual laugh

Last edited by DLively; 05/19/14 01:17.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com

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

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