Windows V-Sync question

T

trentallain

Guest
I have to turn on vsync in most of my games so that I don't get screen tearing. My laptop has a 60hz refresh rate and the room_speed/game_speed is also 60 so it works as expected. But if just say my friend had a 120hz or 30hz refresh rate monitor, would the game be running twice as fast or twice as slow? Because that would make it unfair.

Edit: also the current game is 3D and vsync being off on my laptop makes it very hard to see what's going on
 
E

elsi11

Guest
Monitor refresh rate is different than game speed, and it has no impact on it.
Game speed is the number of times your code loops in a second. I have to turn on V-sync on some of my games in order to artificially cap them at 60 fps because the genious developer didn't cap it, so it runs as fast as the CPU can run it.
Everyones CPU / GPU can only process so many instructions before it gets hot or starts lagging. What you are doing with Game Speed is telling the CPU that you want it only to loop your code 60 times in a second. And that's also how many frames of animation you will get

That being said, I'm no expert, and don't listen to me :p
 
T

trentallain

Guest
Monitor refresh rate is different than game speed, and it has no impact on it.
Game speed is the number of times your code loops in a second. I have to turn on V-sync on some of my games in order to artificially cap them at 60 fps because the genious developer didn't cap it, so it runs as fast as the CPU can run it.
Everyones CPU / GPU can only process so many instructions before it gets hot or starts lagging. What you are doing with Game Speed is telling the CPU that you want it only to loop your code 60 times in a second. And that's also how many frames of animation you will get

That being said, I'm no expert, and don't listen to me :p
Okay thanks, but would it make the game (normally 60fps) twice as fast or twice as slow if the monitor was at 120 or 30 fps and vsync was on?
 
Last edited:

RangerX

Member
Ok let me help you understand why your game will not go faster or slower.
V-sync makes so GameMaker shoots an image to the monitor at the same moment the monitor is refreshing. Do you get that part?
So if you game is room_speed 60 frame per second, GameMaker will try to send an image to the monitor 60 times during one second. And your monitor refreshes 60 times to, so its in perfect accordance:

GMS sends image ---- Monitor refreshed with that new image.
GMS sends image ---- Monitor refreshed with that new image.
GMS sends image ---- Monitor refreshed with that new image.
this is 60 times during one second. That's easy.



Now let's say your game is only 30 fps and your monitor refreshes 60 frames. Your game will look 30 fps but will NOT look faster because here's what's happening:

GMS sends image ---- Monitor refreshes with that new image.
--------------------------- Monitor refreshes but didn't receive anything new there fore it keeps the same image displayed
GMS sends image ---- Monitor refreshes with that new image.
--------------------------- Monitor refreshes but didn't receive anything new there fore it keeps the same image displayed


So basically, your monitor display the image that is in its buffer 60 times during a second but receives a new image from GameMaker 30 times a second. Therefore your monitor will display the game GM frames twice in a row since it doesn't receive a new one.
 
C

CedSharp

Guest
Also worth mentionning, vsync will not negatively affect your game even if your game starts to lag, because it only caps the fps, it doesn't boost it.
If your game starts to lag, then there is too much for the cpu to be able to render enough frames in one second, which has nothing to do with vsync.
 
T

trentallain

Guest
Ok let me help you understand why your game will not go faster or slower.
V-sync makes so GameMaker shoots an image to the monitor at the same moment the monitor is refreshing. Do you get that part?
So if you game is room_speed 60 frame per second, GameMaker will try to send an image to the monitor 60 times during one second. And your monitor refreshes 60 times to, so its in perfect accordance:

GMS sends image ---- Monitor refreshed with that new image.
GMS sends image ---- Monitor refreshed with that new image.
GMS sends image ---- Monitor refreshed with that new image.
this is 60 times during one second. That's easy.



Now let's say your game is only 30 fps and your monitor refreshes 60 frames. Your game will look 30 fps but will NOT look faster because here's what's happening:

GMS sends image ---- Monitor refreshes with that new image.
--------------------------- Monitor refreshes but didn't receive anything new there fore it keeps the same image displayed
GMS sends image ---- Monitor refreshes with that new image.
--------------------------- Monitor refreshes but didn't receive anything new there fore it keeps the same image displayed


So basically, your monitor display the image that is in its buffer 60 times during a second but receives a new image from GameMaker 30 times a second. Therefore your monitor will display the game GM frames twice in a row since it doesn't receive a new one.
I understand that part. What I'm asking is would game maker increase the room_speed to 120 (from 60) if vsync was on for a 120hz monitor?
 
T

trentallain

Guest
Okay, so its only the FPS that is adjusted to match the monitor refresh rate, not the room_speed. Which means the game still runs at the same pace for all users (unless lagging of course)

Thanks guys!
 

RangerX

Member
I understand that part. What I'm asking is would game maker increase the room_speed to 120 (from 60) if vsync was on for a 120hz monitor?
It's the same logic. If you get it, that question is already answered.
GMS shoots 120 images in that second and the monitor being 120hz also is able to display those 120 images. And if the monitor is 60 while your game is 120, then GMS will shoot half of its images in nothingness, your monitor will only show 60 of them 120 during one second.
 
S

skinnybrown

Guest
I have a 144Hz monitor so I can confirm that no, enabling VSync will not allow the game to update faster or slower than the game speed. Though, if you want your game to support higher refresh rates, you should look into making your game framerate independent with delta time and unlocking your game speed.

EDIT: In your example above, the game would run at 60 FPS as intended, even with VSync on and a 144Hz monitor.
I am trying to add fullscreen support to a game, and so far, my observations don't match yours.

I have a 60 Hz monitor, so I am setting my room's speed to 10, to make the problem easy to visualies. If I run the game with sync off, room_speed reads 10, and fps reads 10 (and all movement is unsurprisingly very jerky). However, if I enable sync, room_speed still reads 10, but fps is now 60 (and everything is buttery smooth).

For anything using delta_time, this doesn't really matter. However, my sprite animation speeds are all calculated based on room_speed. Lets say I have a sprite that I want to run at 10 FPS. I set sprite_speed = 10 / room_speed. With sync off, this works correctly regardless of what I set my room speed to. For example, with a room_speed of 10, my image_index goes up by 1 every step and the animation behaves as expected. With sync on though, image_index still goes up by 1 every step (because room_speed still reports 10), but the steps are happening 60 times per seconds, so the animation runs too fast. The same happens with alarms.

Short of animating my sprites manually (I don't really use the built in alarms any more, so that's not such an issue), I don't really know how to work around this. I could use the value of fps, but this can fluctuate depending on load, and I wouldn't want to calculate an animation speed based on a value that could be far from the nominal. You could work around that by re-calculating the speed every step, but at that point you might as well animate the sprite manually.

Is there a way to determine the target frame rate when sync is enabled?
 
I am trying to add fullscreen support to a game, and so far, my observations don't match yours.

I have a 60 Hz monitor, so I am setting my room's speed to 10, to make the problem easy to visualies. If I run the game with sync off, room_speed reads 10, and fps reads 10 (and all movement is unsurprisingly very jerky). However, if I enable sync, room_speed still reads 10, but fps is now 60 (and everything is buttery smooth).

For anything using delta_time, this doesn't really matter. However, my sprite animation speeds are all calculated based on room_speed. Lets say I have a sprite that I want to run at 10 FPS. I set sprite_speed = 10 / room_speed. With sync off, this works correctly regardless of what I set my room speed to. For example, with a room_speed of 10, my image_index goes up by 1 every step and the animation behaves as expected. With sync on though, image_index still goes up by 1 every step (because room_speed still reports 10), but the steps are happening 60 times per seconds, so the animation runs too fast. The same happens with alarms.

Short of animating my sprites manually (I don't really use the built in alarms any more, so that's not such an issue), I don't really know how to work around this. I could use the value of fps, but this can fluctuate depending on load, and I wouldn't want to calculate an animation speed based on a value that could be far from the nominal. You could work around that by re-calculating the speed every step, but at that point you might as well animate the sprite manually.

Is there a way to determine the target frame rate when sync is enabled?
Are you using the alternate sync method option? I have found that sometimes that does increase the speed of my games when enabled. I think it was on higher refresh rate monitors too.
 
S

skinnybrown

Guest
Are you using the alternate sync method option? I have found that sometimes that does increase the speed of my games when enabled. I think it was on higher refresh rate monitors too.
You're right, I was using the alternative method. When switching back to the standard method, my game speed doesn't change unless I set it to something that is higher than the monitor refresh rate.

So the question is now, are there monitors that run at less than 60 Hz? If so, I still need to find a solution. If not, I can let it go. I don't know much about modern refresh rates. However, I'm in the UK, and our mains electricity runs at 50 Hz, so back in the CRT days monitors and TVs used to run at that speed too. Maybe this is a complete non-issue with LCDs (my current, basic screen is 60 Hz).
 
T

trentallain

Guest
You're right, I was using the alternative method. When switching back to the standard method, my game speed doesn't change unless I set it to something that is higher than the monitor refresh rate.

So the question is now, are there monitors that run at less than 60 Hz? If so, I still need to find a solution. If not, I can let it go. I don't know much about modern refresh rates. However, I'm in the UK, and our mains electricity runs at 50 Hz, so back in the CRT days monitors and TVs used to run at that speed too. Maybe this is a complete non-issue with LCDs (my current, basic screen is 60 Hz).
Just have vsync as an option in you game's menu
 
S

skinnybrown

Guest
Just have vsync as an option in you game's menu
That would allow people with lower refresh rates to play the game, but they still wouldn’t be able to play it full screen.

They also wouldn’t necessarily know that they needed to turn the option off (if you don’t know how fast the sprites are supposed to animate, how do you know they’re running slow?).

I might have to look into writing a DLL to query the drivers to find out the actual refresh rate. Although this seems like such a fundamental issue that I’m surprised there isn’t a way to deal with it directly in Game Maker.
 
Last edited by a moderator:
Top