Sign in to follow this  
handoman

Weird DeWitter's Game Loop Problem

Recommended Posts

handoman    219

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?

Share this post


Link to post
Share on other sites
__SKYe    1784

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.

Share this post


Link to post
Share on other sites
L. Spiro    25622

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

Share this post


Link to post
Share on other sites
handoman    219

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

Share this post


Link to post
Share on other sites
handoman    219

yea! I was just looking at that. But i guess my compiler doesnt support 11 yet? hmmm...I thought it was up to date. 

Edited by handoman

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites
handoman    219

yea, I got c++11 to work. I guess code::blocks just doesnt recognize some of the classes( it doesnt highlight them or anything), but they still work

Share this post


Link to post
Share on other sites
handoman    219

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

Share this post


Link to post
Share on other sites
handoman    219

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)

 

 

0.0167939
0.0197271
0.0204671
0.0206342
0.0188694
0.0201671
0.0196725
0.0219421
0.0180132
0.020587
0.0197747
 
are these times close enough, or should the game loop really be calling the update equally every time??

Share this post


Link to post
Share on other sites
L. Spiro    25622

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.

OutputDebugString().

 

Also, waiting for v-sync can cause different delays between frames.

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites
handoman    219

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

Share this post


Link to post
Share on other sites
handoman    219
okay, I actually now concluded that its not the code...its my comp: 
 
I ran the exe(not with code::blocks) on my pc, and the situation is the same. but then I take it to my dad's laptop and it runs normal and smooth no matter what else is open! gunna start comparing all of our setting and stuff.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this