Effective Time-Keeper

Hi dudes,
I am trying to create a simulation program, in that i need an effective time keeping using the glutTimerFunc for a 30fps.

can i call this timer function from my RenderScene function?

if possible try to explain me how it works? i mean for 30fps it take 33millisec to wait n return to the timerfunction to execute.

the objective of my program is to create a driving simulation with rain effect. here droplet is fed into the windowpane and it begin to flow down. i wrote the code for everything but the timer not function properly.

if any clever head like 2 gimme some idea?

thanx
regards

You should get time in miliseconds and compare (time==n*(1/33))?proceed:sleep; But I’m working with MSVC++ 6.0 and I havn’t found way how to get time in miliseconds & get sleep to work, it seems that computer simply hangs If you’ll find out about those functions, please let me know.

thanx dude… will let u know, if it works fine.

If guys ready to gimme suggestion regarding the timer function, pls do it so…

thanx.

I think that I’ve found solution -> www.gametutorials.com There was somthing about time based movement, unfortunately it uses additional lib.
Is there realy no way to record milisecond in MSVC. like time.ti_hund in Borland Builder (HATE THAT THNG)

GLFW - sub microsecond resolution. Check the source for how it’s done (lib/win32/time.c).

Almost all example programs that are included use time-based movement, and some (which use differential equations to propagate movement) also have special handling for low frame rates (which can lead to unstable simulations).

It’s quite simple, basically:

#define MAX_DELTA_T 1.0e-3   // Maximum propagation = 1 ms

  double t, t_old, dt_total, dt;

  t = glfwGetTime();
  dt_total = t - t_old;
  t_old = t;
  while( dt_total > 0.0 )
  {
    dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
    dt_total -= dt;
    UpdateState( dt );
  }

…where UpdateState is your physics propagation, collision detection etc. (NO rendering!)

In this example, we will propagate the simulation exactly the amount of time that has passed since we last updated the state (=realtime). If the elapsed time between two rendered frames is too large (limit here is 1 ms), then we iterate in 1 ms steps until we have completed dt_total seconds. That way we avoid an unstable simulation when the system can not maintain a high enough rendering speed, like some dude trying to run the simulation in 1600x1200 fullscreen with software OpenGL rendering (=zero point nought FPS).

Note that glfwGetTime() returns the time in seconds as a double precision floating point value. The timer resolution is usually better than 1 us. Bonus: it’s portable (!)

[This message has been edited by marcus256 (edited 12-12-2002).]

If you just want Win32 functions to get milliseconds, you can look at timeGetTime, or the more accurate functions QueryPerformanceCounter and QueryPerformanceFrequency.

For a more portable method, you can use ftime(), which uses a timeb struct that contains seconds and milliseconds. I don’t think that the accuracy of this method is that great, though.