11 Replies - 1352 Views - Last Post: 12 February 2013 - 11:41 PM Rate Topic: -----

#1 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

Odd deWitter's Game Loop Problem

Posted 07 February 2013 - 08:25 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 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?

Is This A Good Question/Topic? 0
  • +

Replies To: Odd deWitter's Game Loop Problem

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

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?
Was This Post Helpful? 0
  • +
  • -

#3 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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:
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.
Was This Post Helpful? 0
  • +
  • -

#4 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

#6 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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!
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

#8 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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??
Was This Post Helpful? 0
  • +
  • -

#9 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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??
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,157
  • Joined: 05-May 12

Re: Odd deWitter's Game Loop Problem

Posted 12 February 2013 - 07:27 PM

The dewitters game loop is setup this way:
    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.
Was This Post Helpful? 0
  • +
  • -

#11 handoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-February 13

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.
Was This Post Helpful? 0
  • +
  • -

#12 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1352
  • View blog
  • Posts: 4,654
  • Joined: 19-February 09

Re: Odd deWitter's Game Loop Problem

Posted 12 February 2013 - 11:41 PM

If on Windows maybe look at Windows Task Manager.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1