Thank you both very much for your replies.
(For Windows Allegro 5.0.8, Vsync works for:)
Vsync called by: al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE); // Or ALEGRO_SUGGEST, Placed before the display is created.
Not Vsync called by: al_wait_for_vsync(); // Placed in the main loop (At least 1 other person has reported this does not work properly on windows. The motion goes very jerky)
I’ve found Vsync does indeed work at least on the 4 different computers I’ve been testing on:
HP HDX Laptop Windows Vista (Perfect)
Samsung Laptop Windows 7 (Perfect)
Acer Desktop Windows Vista (Perfect)
HP Pavilion Windows XP (Pauses a bit, not sure if it’s the computer though, or something else)
SiegeLord, Vsync used all on it’s own without any other form of time control causes the game loop to wait until the screen has finished refreshing. At that point the back buffer and frame buffer are switched in what must be some small time period available before the monitor starts to retrieve the next frame from the frame buffer.
As far as I can see this seems to be the absolute simplest method (Just 1 line) for producing perfect smooth motion on any computer that works compatibly with the Vsync request, which I’m guessing is most computers running Windows Vista or later and possibly XP as well.
I’m only a beginner to programming in general and have chosen C++ and Allegro because of their potential.
Kris it seems is confirming what I thought, which is to simply use Vsync to get perfect smooth motion, and then use delta time (just simply the time between each game loop) to calculate how far to move game objects. So SiegeLord, delta time and Vsync do indeed work logically together. Timing how long Vsync causes the game loop to wait based on the screen refreshing is not a problem, and using this measured amount of time to calculated how far to move objects so they appear the same speed on monitors of different refresh rates, also makes perfect sense.
Of course as I’ve read many times now during my research, there is the issue of collision detection and game physics becoming much more complicated using delta time in this way, as I know Kris has been involved in discussing in other posts.
SiegeLord thank you for providing your code example. I will attempt to understand the workings after work today. I have for now copy and pasted and run the program. It runs fine, but I am getting the significant jerking I get when just using fixed timing. I don’t doubt it runs as smooth as butter on your computer, but I strongly recommend you try it on several other computers to see if you get what I’m seeing. Sometimes around 60FPS game loop and 60Hz monitor refresh rate it’s just a fluke that the 2 are very close to being exact.
Just to point out one example of how it’s possible to be deceived relating to my last paragraph. My first language was Python which I started last August where I ended up using Pygame. Now I found from blitting the FPS to the screen, that in fact instead of getting exactly what you asked for by Clock.tick(), you got divisions of 1000 instead, being 1000, 500, 333, 250, 200, 166.6 and so on. For 60FPS you got 62.5 since 1000/16 = 62.5 and Pygame rounded up to the nearest division of 1000, and since 1000/17 was 58.8, 62.5 was what you ended up with. I also confirmed this by moving an object across the screen, and you could see the sudden increase in speed as you headed for Clock.tick(1000). Just imagine for anyone who hadn’t discovered this what the implications could be. It wasn’t mentioned anywhere on the web that I could find. I haven’t tested Allegro but does anyone know if you actually get the integer you ask for such as 58, 59, 60, 61, 62 and not just divisions of 1000 as in Pygame.
Finally Kris, I don’t yet understand how to implement Interpolation, but may be SiegeLord’s program will help me (Although clearly it’s jerking a lot on my HD HDX laptop). I’m going to take your advice Kris and stick with Vsync for now, and maybe use the simple delta timing method in addition, if I decide requesting a screen resolution accompanied with it’s available refresh rate is not as suitably compatible as I would like. Your right I’m just a hobbyist and a beginner and don’t want to over complicate things for myself at this stage.
Thank you both very much for your input, it’s all of great help for me.
Just one last question: Is it standard practice to use Vsync in combination with a Timer? If so please describe an example of how the two work together.