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 windows 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 teh 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?
Odd deWitter's Game Loop Problem
Page 1 of 111 Replies - 438 Views - Last Post: 12 February 2013 - 11:41 PM
Replies To: Odd deWitter's Game Loop Problem
#2
Re: Odd deWitter's Game Loop Problem
Posted 07 February 2013 - 09:03 PM
Without seeing your update or display code it's kind of hard to tell. Are you sure that your update or display code is always guaranteed to run within your frame rate?
#3
Re: Odd deWitter's Game Loop Problem
Posted 07 February 2013 - 11:27 PM
oh yea, here is the code i use to set the position of the circle sprite and implement the interpolation:
where alpha is the interpolation value calculated from the leftover time from the update function.
circle.setPosition((x * alpha) + (px *(1.0f-alpha)),(y * alpha) + (py *(1.0f-alpha)));
where alpha is the interpolation value calculated from the leftover time from the update function.
#4
Re: Odd deWitter's Game Loop Problem
Posted 07 February 2013 - 11:32 PM
okay sorry px and py are the previous x, and y values. I going to try out the other famous gameloop from this link. Those two gameloops are used a lot and have tons positive feedback. I starting to think it is just my computer.
#5
Re: Odd deWitter's Game Loop Problem
Posted 08 February 2013 - 06:28 AM
The true way to find out is to have a log file with timestamps for each entry. If you find a gap in the timestamps and the gap is for a function that you know shouldn't take that long then it's your hardware. But to make that conclusion, you have to know how your functions behave by profiling your game.
#6
Re: Odd deWitter's Game Loop Problem
Posted 10 February 2013 - 04:35 PM
I decided to use Chrono high resolution clock instead of the sf::clock, but the problem is the same! so, I guess the percision wasnt the problem. I'll try out creating the log file with timestaps to see what might be happening. I just don't understand why having another application open would help my game run smoother!
#7
Re: Odd deWitter's Game Loop Problem
Posted 10 February 2013 - 04:43 PM
If you are Windows 7, and have the CPU setting on the default balanced power management, then the speed of your CPU is variable. Try setting it to full power and see if you are still encountering the stuttering.
If you are Windows 7, and have the CPU setting on the default balanced power management, then the speed of your CPU is variable. Try setting it to full power and see if you are still encountering the stuttering.
If you are Windows 7, and have the CPU setting on the default balanced power management, then the speed of your CPU is variable. Try setting it to full power and see if you are still encountering the stuttering.
#8
Re: Odd deWitter's Game Loop Problem
Posted 10 February 2013 - 05:18 PM
Yea just tried that now and its still the same. I still think this has to do with my drawing/rendering rather than the updating...maybe my display rate is going too fast when there is no other windows open??
#9
Re: Odd deWitter's Game Loop Problem
Posted 12 February 2013 - 03:42 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??
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??
#10
Re: Odd deWitter's Game Loop Problem
Posted 12 February 2013 - 07:27 PM
The dewitters game loop is setup this way:
It's been a long day and I maybe misreading the code, but here's my interpretation of the code above right now: update_game() will be called at most MAX_FRAMESKIP times, and I would expect at most MAX_FRAMESKIP values in your log clustered together to have very similar times. I'm too tired to try to analyze what the minimum will be. It'll probably just be easier for you mere to add another call to write to your log file what the value of loops prior to calling display_game(). This seems to be the easier to determine if your update_game() is working within a consistent time.
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
DWORD next_game_tick = GetTickCount();
int loops;
float interpolation;
bool game_is_running = true;
while( game_is_running ) {
loops = 0;
while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
update_game();
next_game_tick += SKIP_TICKS;
loops++;
}
interpolation = float( GetTickCount() + SKIP_TICKS - next_game_tick )
/ float( SKIP_TICKS );
display_game( interpolation );
}
It's been a long day and I maybe misreading the code, but here's my interpretation of the code above right now: update_game() will be called at most MAX_FRAMESKIP times, and I would expect at most MAX_FRAMESKIP values in your log clustered together to have very similar times. I'm too tired to try to analyze what the minimum will be. It'll probably just be easier for you mere to add another call to write to your log file what the value of loops prior to calling display_game(). This seems to be the easier to determine if your update_game() is working within a consistent time.
#11
Re: Odd deWitter's Game Loop Problem
Posted 12 February 2013 - 08:19 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.
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.
#12
Re: Odd deWitter's Game Loop Problem
Posted 12 February 2013 - 11:41 PM
If on Windows maybe look at Windows Task Manager.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|