timing and input
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.
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
}
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
}
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.
http://wolfpack.twu.net/libjsw/
Note that the new 1.5.0 version is comming out soon
which will support more advanced error corrections.
For a decent timer, try using times(0) and sysconf(_SC_CLK_TCK) ... read the man pages
... you get the idea
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
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:-)
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
Popular Topics
Advertisement