🔒 Locked
Vsync question
Advertisement
Original Post
My question is this: With my current project, when I have vsync off, everything pretty much works as it should. The problem is, when I turn vsync back on, the calculations are done less frequently, and therefore are less accurate for animation. Does the game loop wait for the vsync time to end until it continues, even though it is already done drawing? Here is sort of a psuedo-code version of my main loop: while(1) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg);// Translate The Message DispatchMessage(&msg);// Dispatch The Message } else // If There Are No Messages { timer = Update_Timer(); Update(timer); // do calculations Render(); // render the scene } }
Depends on what library you use to render, but I know that with DirectX, the Present() call at the end of each frame will block until the vsync time comes, so yes, in your case, it would indeed slow down the rate of updating stuff. I'm guessing that it's like this with most libraries. (Besides, if it doesn't block, then after Render(), you'll get back to your loop, handle any messages, update your world, and then call Render() again, all before the previous Render() call has even gone through, since the vsync time still hasn't elapsed. In this case, you'll be good if Render() just skips everything and returns, but if it blocks, waiting for the previous Render() to finish, then you'll have the same problem as above.)
just out of intrest, why would you only update the game if there WASNT an event? Surely you should be updating the game regardless?
Alright, I set up a timer with SetTimer(), and every time the timer expires, I call the update function. The timer I set is to 10 milliseconds, or to update 100 times per second. When I was doing everything every frame, I was getting around 150 FPS. Now that I set the timer it only updates at around 60 FPS. Could the vsync still be slowing my program down? Does it still wait for rendering even though the update should be running on a different thread?
Thanks!
-Shane
Thanks!
-Shane
First, a 10 MS timer is a bad idea, a guaranteed granularity is around 20-30 MS I think (well, it depends on the OS, library, etc.)
Second, you need to make your timmer and drawing independent of eachother. Set a mutex on the drawing to prevent the timer from doing bad stuff while drawing.
Second, you need to make your timmer and drawing independent of eachother. Set a mutex on the drawing to prevent the timer from doing bad stuff while drawing.
Oh, sorry, I was wrong. The granularity is smaller, around 10 MS.
From the SDL docs:
From the SDL docs:
Quote:
The granularity of the timer is platform-dependent, but you should count on it being at least 10 ms as this is the most common number. This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system.
Quote:
Original post by Raduprv Quote:
Original post by _the_phantom_
just out of intrest, why would you only update the game if there WASNT an event? Surely you should be updating the game regardless?
AI? Sound? Sprites such as projectiles?
how are they related to the windows message pump?
Quote:
Original post by _the_phantom_ Quote:
Original post by Raduprv Quote:
Original post by _the_phantom_
just out of intrest, why would you only update the game if there WASNT an event? Surely you should be updating the game regardless?
AI? Sound? Sprites such as projectiles?
how are they related to the windows message pump?
You didn't say "update the window" but "update the game".
Regardless, the window update is independent to whether or not there is any event.
*points at the start of the thread*
Correct, I didnt say update the window coz that wasnt what i was talking about [wink]
The code at the start ONLY updates the game states when a windows message pump event doesnt happen, so even moving the mouse would stall the game for whatever reason.
Thus my wondering why this was how it was done [smile]
Correct, I didnt say update the window coz that wasnt what i was talking about [wink]
The code at the start ONLY updates the game states when a windows message pump event doesnt happen, so even moving the mouse would stall the game for whatever reason.
Thus my wondering why this was how it was done [smile]
heh, no worries, i'd had come back to it earier but i'd forgotten about this thread [smile]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement