WaitTimer Comand
Blitz3D Forums/Blitz3D Beginners Area/WaitTimer Comand
| ||
Hi, I've been fiddling with blitz for a couple of months on and off and decided to take apart one of the samples to see what made it tick. I chose Celestial Rift and promptly broke it down into modules (e.g. attractMode, player, enemy, bullets, stars, etc.) and then chucked in some tweaks (which programmer can resist?). Aside from some niggly bugs (including breaking the hi-score counter) I've sat back and tried to list what I've learnt, and what I need to find out about. One thing that does puzzle me is the WaitTimer command. I understand it's purpose (wait n units of time and then return control back to the program), what I don't understand is the way it's used in Celestial Rift :- Local iFrames, i iFrames = WaitTimer(g_tmr) For i = 1 To iFrames ;do game stuff here, check keys, etc. Next g_tmr is a timer set with g_tmr = CreateTimer(50) What puzzles me is why you'd want to loop? Wouldn't this just execute the game loop multiple times, if so, why would you want to do that? It's not a problem I'm stuck on, I'd just like to know the reasoning behind it so I can determine if it'll bite me in the ass in the future! Thanks in advance |
| ||
Basically, when you create a timer like: mytimer = createtimer(50) you create a 'trigger' that will shoot 50 times in a second, that means, every 1000/50 = 20 millisecs. So, when you write k = WaitTimer(mytim) is like you check if are already passed 20 millisecs since the last update. If not, then K will be 0, and the for i = 1 to k loop is not executed. If yes, then the loop for i = 1 to K will be executed at least one time. This to 'force' fast pcs to run at a reasonable speed, and slow pc to run at that speed too. Hope this has sense for you, Sergio. |
| ||
Sergio, I did suspect that it was to act as some sort of throttle mechanism - many thanks. |