Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Weird DeWitter's Game Loop Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 handoman   Members   -  Reputation: 219

Like
0Likes
Like

Posted 07 February 2013 - 09:32 PM

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?



Sponsor:

#2 __SKYe   Members   -  Reputation: 1103

Like
0Likes
Like

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 L. Spiro   Crossbones+   -  Reputation: 14395

Like
0Likes
Like

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
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
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 Khatharr   Crossbones+   -  Reputation: 3064

Like
0Likes
Like

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

biggrin.png


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#5 handoman   Members   -  Reputation: 219

Like
0Likes
Like

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 Servant of the Lord   Crossbones+   -  Reputation: 21166

Like
1Likes
Like

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


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
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

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 handoman   Members   -  Reputation: 219

Like
0Likes
Like

Posted 08 February 2013 - 06:05 PM

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, 08 February 2013 - 06:06 PM.


#8 Servant of the Lord   Crossbones+   -  Reputation: 21166

Like
0Likes
Like

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


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
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

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#9 handoman   Members   -  Reputation: 219

Like
0Likes
Like

Posted 09 February 2013 - 01:56 PM

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



#10 handoman   Members   -  Reputation: 219

Like
0Likes
Like

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 handoman   Members   -  Reputation: 219

Like
0Likes
Like

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)

 

 

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??


#12 L. Spiro   Crossbones+   -  Reputation: 14395

Like
0Likes
Like

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.

OutputDebugString().

 

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

 

 

L. Spiro


Edited by L. Spiro, 12 February 2013 - 04:51 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
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
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#13 handoman   Members   -  Reputation: 219

Like
0Likes
Like

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 handoman   Members   -  Reputation: 219

Like
0Likes
Like

Posted 12 February 2013 - 09:20 PM

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS