Delay 1?

Miscellaneous Forums/General Discussion/Delay 1?

I tend to put Delay 1 in my main loop to let Windows back in to do some multi-tasking and reduce load - laptops don't seem to like running at full tilt and turn on the fans to cool things down. Also, I think Windows tries to fight the application if it hogs all the CPU, so that could cause some judder in a game.

Does everybody do this or something similar? Ofcourse it tends to screw-up your FPS calculations so I turn it off then.

I do it, but I've never really needed accurate FPS calculations or such.

Yes, I do this. It's as near as Blitz gets to the sleep command, which I think most c programmers use to achieve the same result. As you say, Windows expects to get a little CPU time to do its housekeeping and if you don't let it, it will eventually become more forceful and just grab CPU time,causing a nasty judder in your game.

You game/application should eventually take more than 1 millisecs to operate so it won't get that high.

Does 'PollSystem()' do the same?

I use PollSystem().

For games I hog the CPU, I use delta timing to control movement and I put suspension on the delta timing to compensate for any jitter.

Short answer:

For applications in Windowed Mode i do (i use a delay 10). For games in Fullscreen not.

But like I said, laptop owners especially won't thank you for running at full tilt, because they get very warm and noisy.

Ofcourse this does cause problems when asking for FPS figures on a demo. I guess I could have it running with a delay to monitor smooth movement - then with a key press the delay is turned off and the FPS shown on-screen for performance feedback.

PC programming is never straightforward is it? :-)

btw Does PollSystem() work in fullscreen games or is it designed for an event based system when GUI programming?

Steve: my framework uses this code (I've turned off the standard PolledInput):
While PeekEvent()
			PollEvent()
		  	Select EventID()
			Case EVENT_MOUSEDOWN
                        'do something
		        End Select
Wend 	


Plus I only use Delay(1) when the user clicks out of the game and the game is in a suspended state. This gives some processing power back to Windows so everything isn't really slow.

..guys..sorry on this dumb question, but, can someone turn on light over PollSystem() for me..whats that?

Naughty: do you have BMax? Here's what the manual says:
PollSystem returns control back to the operating system, allowing such events as keystrokes and gadget actions to be processed. Control is then returned back to your program.

If PollSystem encounters a key, mouse or app suspend/resume/terminate event, and equivalent BlitzMax Event will be generated which may be examined using the SYSTEMEVENTHOOK hook.


However, it's no good if you want to have stuff automatically moving unless you put it on a timer.

Jake, that example is just for Windows (rather than full screen) access is it? In a game you're not going to want to catch any event like that - just give Windows some time to do whatever it wants.

But is PollSystem as per docs? Or is it aimed at a Windows Event based system.

oh..no wonder...I dont have Bmax...I'm B3D kid, but soon I'm planing to jump in to Bmax boat with hope that it will be soon 3D...

Steve: Yeah PollSystem is for a GUI in a window, so I wouldn't use it in a game, that's why I used PollEvent in my full-screen AND windowed mode cos it allowed me to run other code as well like scrolling, moving aliens etc.

Flip true and Vwait will do the trick too in Blitz3D. If the app is running at full speed, eg. using flip false, the I'd suggest too, add a delay 1. I even had BSODs without it, on Win98.

I have never used Delay 1... To hear after all these years of Blitz Basic being around that if you don't include "Delay 1" in your game, people's PCs might get noisy and give blue screens of death is interesting news and surely worth being put in some kind of manual or on the front page of this website? ;)

Thanks for the advice though! :)

WaitEvent() accomplishes the same thing if you develop your game using timers (which is good practice anyhow).

local timer:TTimer = CreateTimer(60)

while(not(keydown(KEY_ESCAPE)))
     waitevent()
     if EventSource() = timer then
           ' do stuff
     end if
wend


that's one way of doing it with timers. EventSource() isn't as reliable as I've found when you have multiple things ticking/polling. So an alternate way is...

local timer:TTimer = CreateTimer(60) ' your main loop now runs at 60 ticks per second.
local lastTicks:int = 0
while(not(keydown(KEY_ESCAPE)))
     waitevent()
     local ticks:int = timerTicks(timer)
     if ticks > lastTicks then
           ' do stuff
           lastTicks = ticks
     end if
wend


Both ways return control back to the OS, and your CPU isn't running at 100% anymore. IMO, using timers and waitEvent is a good setup for most games made in blitz and using Delay(x) just seems hacker-ish to me.

Thanks a lot for this thread. I could never understand why, when using games that worked fine on the desktop they were written on, when I run them on my laptop the fans start up almost immediately. I'd just assumed that it was probally something to do with the capabilities (or lack of them) of the gfx system.

I think ite s just polite to add the delay in there, so people can alt tab into other apps without their systen locking up. It's also really handy for multitasking during developement.

Does everybody do this or something similar?
I dont.

What I do (like Grey and Alex), is have auto call timers, (Normaly at screen frequency or a denominator of such for display), that call the game logic/display and such automaticaly. These then do their stuff and when finished pass control back to the normal message loop. I do this so that I dont have to worry to much about sync. Ok I have to make sure that any task that is auto called is short enough to do its stuff and return control back within a few milli, but it works OK, and "Looks" like multi thread/tasks because the logic (say), works independantly of the display.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1721

In the message loop the While WaitEvent() probably has the same effect as the delay


I think ite s just polite to add the delay in there, so people can alt tab into other apps without their systen locking up. It's also really handy for multitasking during developement


WaitEvent() has the same effect if I remember correctly.