Delay command - what is it good for

Blitz3D Forums/Blitz3D Programming/Delay command - what is it good for

Matty(Posted 2005) [#1]
What is the difference between:

delay 1000


and

mydelay=millisecs()
repeat 
until millisecs()-mydelay>1000



Oddball(Posted 2005) [#2]
Whilst a program is delayed it is not hogging 100% of the CPU. Some people have been sticking a Delay 1 in the main loop of their windowed apps so that other apps get a slice of the CPU time. Not sure how useful it is as I've not used it in this way myself.


jfk EO-11110(Posted 2005) [#3]
Like delay, flip and vwait let the system breath while they are waiting. I had problems with Apps that didn't wait in any way, they completely throw windows down on its knees and after a couple of minutes the OS crashed fulminantly. I then added a "Delay 1" somewhere in the mainloop and it didn't crash anymore.

Additionally, as Oddball said, you can use delay to control ho much CPU usage your app may utilize. When you have a watch that has to animate every second, it makes no sense to hook all the CPU time with an empty loop:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1121


Matty(Posted 2005) [#4]
Thanks for your replies, quite helpful.

This leads to my next question:

If I used a 'delay' statement as part of a frame limiting algorithm in a full screen game is it then possible that when the 'delay' command is executed the actual delay could be longer (by a significant amount) because some other windows app decides to use the CPU heavily and take control of the CPU for longer than the amount specified when the 'delay' command was executed.

And - if that were true I'm guessing it would be better to use the simple "repeat..until millisecs()-timebeforethisloop>somesmallamount"?


big10p(Posted 2005) [#5]
Not sure but I would guess that Delay can take longer than specified for the reason you suggest. I guess you could test this by wrapping a delay command with the millisecs counter code. Make sure you have lots of hoggy background tasks running to test this properly and report back here. :)