So I've been searching and studying up on game loops and decided to go with deWitter's(the final version with interpolation). Yesterday I implemented the loop into a simple test game to see how it works, and it worked fine. My little circle would move across the screen very smoothly with no problems at all, so I saved everything and took a break.
Okay.. now here's the problem: I came back later to check it out again, but this time there was a slight stutter when the circle moved! I had no other winndows open, only CodeBlocks and the program, but when i first successfully tried it, I had Chrome open. so I tried it again with chrome open, and it didn't stutter! but when I try it with nothing open, there's that small stutter again. I looked at the code over and over, and it was exactly like the code from the (site), so I am positive it is not a problem with my code.
It's very confusing because it Really does work fine,the small stutter is very subtle, but it is there. I am using SFML 2, so maybe there is a problem with the clock function? What do you guys think? Is this even a programming problem or just my pc?
Weird DeWitter's Game Loop Problem
#1 Members - Reputation: 173
Posted 07 February 2013 - 09:32 PM
#2 Members - Reputation: 451
Posted 08 February 2013 - 01:23 AM
Have you tried building your program in release mode, and executing without having other things open?
I've never used SFML, but if it doesn't work properly based on the programs you have open, then i don't see how that might be a programming issue.
#3 Crossbones+ - Reputation: 5144
Posted 08 February 2013 - 03:32 AM
Yes, there is a problem with clock() and it should never be used.
On Windows®, always use QueryPerformanceCounter() and QueryPerformanceFrequency(). The resolution of clock() is low and its problems with games/high-performance timing can be found via Google.
This is most likely your main problem, but I have listed many other potential problems here: Fixed-Time-Step Implementation
You will want to give it the once-over and be sure you are not making some of the common mistakes people often make when first implementing fixed time-steps.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#4 Members - Reputation: 1540
Posted 08 February 2013 - 11:10 AM
Chrome is so powerful that it speeds up other programs while it's running.
Well played, Google... Well played...![]()
There are ten kinds of people in this world: those who understand binary and those who don't.
#5 Members - Reputation: 173
Posted 08 February 2013 - 02:08 PM
I know right? it should go slower with other stuff open not the other way around. I've been looking up on better time keeping methods instead of sf::clock, I avoided the QueryPerformanceCounter, since it only works on windows. but I guess cross platform isnt really necessary for me, so I'll look into it.
Edited by handoman, 08 February 2013 - 02:08 PM.
#6 Marketplace Seller - Reputation: 8909
Posted 08 February 2013 - 02:46 PM
If you are using C++11, you can use the new standard and cross-platform high resolution timers in that.
See std::chrono::high_resolution_clock::now()
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#8 Marketplace Seller - Reputation: 8909
Posted 09 February 2013 - 01:42 AM
yea! I was just looking at that. But i guess my compiler doesnt support 11 yet? hmmm...I thought it was up to date.
What compiler? GCC/MinGW supports (most of) C++11 if you pass -std=c++11 to the compiler (earlier versions use -std=c++0x).
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#10 Members - Reputation: 173
Posted 10 February 2013 - 05:29 PM
cool so I got the chrono classes to work and convert my game loop to use the high resolution clock insted of sf clock, and it works but it still looks smoother while Chrome is open!! haha it seems so odd to me.
Edited by handoman, 10 February 2013 - 05:30 PM.
#11 Members - Reputation: 173
Posted 12 February 2013 - 04:39 PM
I decided to created a log and output the time since each update into a file... if the game loop was working right, the time time between each frame should be the same right? well there were slightly different:(here is just some of the times)
#12 Crossbones+ - Reputation: 5144
Posted 12 February 2013 - 04:49 PM
The actual time between frames?
They will generally be close as long as nothing is moving around on your screen, and as long as you are not writing times to a file every frame.
Print to the debug console—it is still laggy but less so than writing to a file.
Also, waiting for v-sync can cause different delays between frames.
L. Spiro
Edited by L. Spiro, 12 February 2013 - 04:51 PM.
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#13 Members - Reputation: 173
Posted 12 February 2013 - 06:56 PM
ah okay, I'm not gunna bother with the code anymore, the game loop and timing are pretty precise ..gunna go try it on other computers to be sure its not just mine... or I'll just have to play with Chrome open all the time! thanks for the help guys, Ill probly be back when it doesnt work
Edited by handoman, 12 February 2013 - 06:58 PM.
#14 Members - Reputation: 173
Posted 12 February 2013 - 09:20 PM






