timing and input

Started by
5 comments, last by cody 22 years, 5 months ago
ok guys, i have graphics with opengl und sound with fmod... nice! but how do i get a time value in milliseconds, something like the timeGetTime() function in windows? and is there something like direct input? i need to get mouse/joystick position and key states.
Advertisement
quote:Original post by cody
but how do i get a time value in milliseconds, something like the timeGetTime() function in windows?

See SDL.

quote:and is there something like direct input? i need to get mouse/joystick position and key states.

See SDL.

Of course, there are other options, but SDL is fast becoming the most popular, most robust and most user-friendly.
Here''s how to get time using Windows or UNIX:

time_t GetCurMilliTime(void)
{
#ifdef __MSW__
SYSTEMTIME t; /* Current time of day structure. */

GetSystemTime(&t);
return(
(time_t)(
(((((t.wHour * 60.0) + t.wMinute) * 60) + t.wSecond) * 1000) +
t.wMilliseconds
)
);
#else
struct timeval tv[1];

if(gettimeofday(tv, NULL) < 0)
return(-1);

return(((tv->tv_sec % 86400) * 1000) + (tv->tv_usec / 1000));
#endif
}
Tara Milana - WP Entertainmenthttp://wolfpack.twu.net/Comp graphics artist and programmer.
For better joystick IO you should take a look at
http://wolfpack.twu.net/libjsw/

Note that the new 1.5.0 version is comming out soon
which will support more advanced error corrections.
Tara Milana - WP Entertainmenthttp://wolfpack.twu.net/Comp graphics artist and programmer.
For a decent timer, try using times(0) and sysconf(_SC_CLK_TCK) ... read the man pages

long int liOldClock = (long int)times(0);float GetDeltaTime( bool bReset ){  float fDeltaTime = float( (long int)times(0) - liOldClock ) / float( sysconf( _SC_CLK_TCK ) );  if( bReset )    liOldClock = (long int)times(0);  return fDeltaTime;} 


... you get the idea
-------------------------------------------------------------LGPL 3D engine - http://www.sourceforge.net/projects/realityengine
i looked at the source code of sdl and used their method.

but lord chaos´ version looks more acurate because it uses float.

thanks for the quick help:-)
quote:Original post by cody
i looked at the source code of sdl and used their method.

but lord chaos´ version looks more acurate because it uses float.

thanks for the quick help:-)


What? Using floats usualy introduces inaccuracy!

This topic is closed to new replies.

Advertisement