Similation Time-Keeper -- URGENTLY NEED HELP!!!

Hi All,
I am working with my project on simulation and now i am having tough time to solve this timer problem.

I am calling two func, FeedWater() & OutputWater() in my RenderScene() func. I am confused how to setup timer for 30fps inside FeedWater() and run my program smoothly, I am using GLUT not Win32.

DESPERATLY LOOKING FORWARD FROM U GUYS TO HELP ME.

Actually I am calling a func. FeedWater() to feed water in every frame and i restrict to 30fps. I have a loop in the render function from frame 1 to 30 and calling this FeedWater() func @ 33ms.

Now the problem is once the control goes to the FeedWater() func, I have to create a timer to be there inside that function for 33ms. Here I need to do some operation.

Listing…
RenderScene()
{
for(frame=1;frame<=30;frame++)
{

time = frame * (1/30);
FeedWater(time);

OutputWater(time);
}

}

FeedWater(time)
{
start_time = GetTickCount();
time_len = time * 1000;
final_time = time_length - final_time;
while((GetTickCount() - start_time) < final_time)
{
TimerFunc(final_time);


}
}

TimerFunc(int value)
{
r1 = rand()%50;
c1 = rand()%75;
glutPostRedisplay();
glutTimerFunc(value, TimerFunc, 1);
}

The above listing code is not working fine… pls suggest and help me dude.

thanx
regards

“Not working fine” == what problem exactly?

I donno how to implement my time-keeper, is there any good method to implement the time-keeper? if so pls lemme know.

using GetTickCount is good or is there any other method?

expecting your reply
regards

try this:

// timing
static LARGE_INTEGER Frequency,Timer;
static float GetSystemSeconds( void )
{
#ifdef _WIN32
QueryPerformanceFrequency(&Frequency);
QueryPerformanceCounter(&Timer);
return (float) Timer.QuadPart/ (float)Frequency.QuadPart;
#else
gettimeofday (&_Timer,NULL);
return _Timer.tv_sec+_Timer.tv_usec*.000001;

#endif

}

static float time,lasttime;
__inline void StartTimer(void)
{ lasttime = GetSystemSeconds();
}

__inline float StopTimer(void)
{ time = GetSystemSeconds()-lasttime;
}

…but change float to double. Floats have too poor precision (after two days you only have 10 ms resolution, if I calculated it correctly).

Also, delta-times based on absolute 64-bit timer values (such as QueryPerformanceCounter) should always be performed with 64-bit integer math, NOT floating point math.

For a more complete example, see lib/win32/time.c of the GLFW source code distribution. As you will see, it is also more fail safe (works on all Windows computers, regardless of CPU, chipset or OS version).

Note: GetTickCount() is a very poor timer, with less than 10 ms resolution.

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