Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Baffled by dbSync() puzzle

Author
Message
Whimsy
19
Years of Service
User Offline
Joined: 16th Mar 2005
Location: UK
Posted: 17th Sep 2005 00:55
Okay, perhaps somebody could explain this to me, because I am well and truly confused now.

It's more of a puzzle than a problem. I noticed today that when I jumped out of the main game loop (the one that has dbSync() in it) and came back in, everything suddenly went extremely fast, and yet the frame rate was the same.

I did a bit more testing, and shrunk it down to this:



With a syncRate of 40, the sprite rotates fully once every eight or nine seconds or so, which you'd expect (9*40=360). After calling testFunction() and returning, it rotates - and I kid you not - about 275 times in eight seconds, but the frame rate is still around 40.

With a syncRate of 0, I get > 500 FPS, and it rotates 11 or 12 times in eight seconds, but the same effect doesn't occur: exiting the function makes no difference to the speed. Similarly, if I check for any other key - not escape - if doesn't speed up.

So, my questions are:

- What's going on?
- Why does it only seem to work with a sync rate greater than 0 and only with the escape key?
- How would I get it to go that fast normally, without needing to enter testFunction()?

Does this happen for anyone else, or is it just me? Does anyone have any ideas why it's happening?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Sep 2005 13:19
The escape key is used by default to abort the program, so when it is pressed, it sets a flag. To get you out of the program quickly, certain commands (dbSync for example) do what they need to do, and return control to you as soon as they can.

You can test for this flag yourself by checking the return code of LoopSDK(). You can also disable this special feature of the escape key by calling dbDisableEscapekey()

You can get the speed increase simply by setting your sync rate to 0.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Whimsy
19
Years of Service
User Offline
Joined: 16th Mar 2005
Location: UK
Posted: 17th Sep 2005 15:29
Thanks for the reply IanM. That explains why it only works with the escape key. But unfortunately, it raises more questions. I did some more playing about and checked the return code of LoopSDK(), and found the following:

- Pressing the escape key sets a flag but makes no difference to the return value
- Pressing Alt-F4 or the X button etc sets the flag and gets LoopSDK() to return false
- If you don't use the return value of LoopSDK() to exit, setting the flag makes it speed up
- The speed up still only works with sync rates greater than 0



So, from what I understand, there's a flag inside the SDK that checks for exit conditions, and you can obtain this flag by calling LoopSDK(). However, although the escape key sets this flag (if you've got it enabled), it doesn't change the return code of LoopSDK(). Other exit methods, like Alt-F4 and closing the window, set the flag too, but they return false from LoopSDK(). You can see this by pressing Alt-F4 or Escape with the code above.

Anyway, from what you say, once this flag is set dbSync() returns as quickly as possible; i.e. it doesn't wait any more. But if you've not exited the program, dbSync() continues to return quickly, and so you get this strange speed increase whilst the frame rate remains the same. And yet this speed increase only happens when the sync rate is greater than 0.

I don't understand why this high speed phenomenon occurs, nor can I see how to achieve it any other way. Setting the sync rate to 0 gives a high FPS, but it's still far slower than setting this exit flag without returning:

- dbSyncRate(0), flag not set: about 1.5 revolutions / sec (FPS is ~550)
- dbSyncRate(0), flag set: about 1.5 rev/sec
- dbSyncRate(40), flag not set: about 0.1 rev/sec
- dbSyncRate(40), flag set: about 30 rev/sec (but FPS is still ~40)

As far as I can see, dbSync() is still only maintaining a constant frame rate, but the loop is being executed many more times. This could be very useful if you had lots of processing to do but not much graphics. By using a constant frame rate, you're limited to executing the loop that many times a second; this flag means the loop is executed much more often than the screen is refreshed, so you could do all your collision detection and physics and heavy processing stuff separately from your graphics part and still maintain a high FPS.

Any thoughts? Am I even making any sense?
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 29th Sep 2005 14:29
I guess you are inside a loop, for some reason DB Pro (and this sdk apparently) thinks it has to finish executeing any loops before it can exit, so it ignores the normal framerate and goes flat out to finish off the loop asap before it exits, why it just doesn`t exit I have no idea, there must be some tech reason for it since DarkBasic does the same thing when you try to exit loops, it races through the code as fast as possible and only exits when the loop ends, weird but true, at the time DB started doing this Lee was muttering something about safety code inside the loops and windows control, but I havent a clue what he was on about.



why do they say Aliens are gonna be friendly?, surely the agressive ones wipe out the peaceloving ones, so all you have left out there are crazed flesh eating interstellar monsters.

Login to post a reply

Server time is: 2024-11-19 02:18:22
Your offset time is: 2024-11-19 02:18:22