Archived

This topic is now archived and is closed to further replies.

cody

timing and input

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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:-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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!

Share this post


Link to post
Share on other sites