Display.sync();

Started by Yarin1312, July 13, 2012, 14:35:35

Previous topic - Next topic

Yarin1312

can you explain what the method Display.sync(60) doing?
its set a 60 frame per second or stop/rest for 60 frame per second?

kappa

Display.sync(60) will try to run your game at a constant frame rate of 60 fps. Its a method that you need to call once every frame (i.e. it should be in your game loop). Firstly the method calculates the amount of time it needs to sleep every frame (i.e. 1 second / 60 which is about 16 milliseconds) it then calculates the amount of time that has passed since the last time it was called, if the time passed is less than 16ms it then sleeps for the remainder of that time otherwise it does nothing.

moci

Is it actually a constant 60? If I'm moving/resizing/... my window it will drop somewhat. Maybe my FPS calculation function is a bit off, but I find that it is close to whatever value you use (60 in this case) but not exactly. I really use it to limit the workload of my GPU as there is no need to run at 5000 fps (and heat up the GPU).

Yarin1312

Its mean that if i wirte this code, so if the progrem did 60 frame in a half of a second(for example right, real its take 16 ms)so the rest of the second that mean another half of a second he will "sleep"? thats mean he have to do 60 frame and after he did that he can "Sleep" all the rest of the second that left him? am i right? :D

kappa

Quote from: Yarin1312 on July 13, 2012, 17:03:45
Its mean that if i wirte this code, so if the progrem did 60 frame in a half of a second(for example right, real its take 16 ms)so the rest of the second that mean another half of a second he will "sleep"? thats mean he have to do 60 frame and after he did that he can "Sleep" all the rest of the second that left him? am i right? :D
No that understanding of how Display.sync() works is incorrect, the 60 frames will not display as quickly as possible, instead it will take about 16ms to draw each frame (i.e. time it actually took to draw the the frame + sleeping to make it a total of about 16ms) therefore it will take a full second to draw 60 frames.

Yarin1312

thats mean he actually divides a second in 60 and its the time he will draw one frame? in this time he sleep too or when you draw or making things slowly not onerous the resources thats mean he dont have to sleep?
and what about vsync what hes doing? :O

by the way thank you and sorry about my question i'm just wanna know the subject a best as i can :D