Synchronizing time step.

This is a discussion on Synchronizing time step. within the Game Programming forums, part of the General Programming Boards category; Hello guys. Is my first post here. I'm having problems with time step. I'm using a physics engine that I ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Synchronizing time step.

    Hello guys.

    Is my first post here. I'm having problems with time step.
    I'm using a physics engine that I have to tell how much times it will update each second, but my program is running at inconstant rate.

    Have some way to force the main loop to spend a specific amount of time each pass?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,352
    Quote Originally Posted by Auradrummer View Post
    Have some way to force the main loop to spend a specific amount of time each pass?
    Yes, I have a way of forcing any piece of code to execute in any arbitrary length of time. I used this to predict the final outcome of the universe in less than two microseconds.

    More seriously, you need to occassionally call a time-getting function to see if you're getting too far "ahead", sleeping if necessary. For instance, if each loop iteration takes dt seconds, then:

    Code:
    double t = CurrentTime();
    for(;;)
    {
        if( t > CurrentTime() + slop )
            WaitUntil( t );
        ...
        t += dt;
    }
    Where CurrentTime() gives the current time in seconds (double precision), slop is the maximum time you are allowed to overshoot (possibly 0.0), and WaitUntil() is a function which causes the program to sleep until the time is greater than or equal to t.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    147
    Good physics engines have ways to deal with this common problem.

    Typically, you either have an interpolation (if your a bit slow), or the engine 'cycles twice' (or more) for it's fixed timestep to catch up.

    Bullet, for example, offers a fairly standardized approach - but each engine can have different service for this, and you'll need to check documentation / example programs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 08:11 AM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21