Results 1 to 6 of 6
What is the best way to measure milliseconds in c++ in linux? I'm using Allegro for the game that I'm making, any ideas?...
- 11-19-2007 #1Linux Newbie
- Join Date
- Jun 2006
- Posts
- 150
Best way to measure milliseconds?
What is the best way to measure milliseconds in c++ in linux? I'm using Allegro for the game that I'm making, any ideas?
- 11-19-2007 #2
I don't know anything about Allegro, but does this do the trick for you?
(Call it twice, subtract.)Code:man gettimeofday
--
Bill
Old age and treachery will overcome youth and skill.
- 11-19-2007 #3Linux Newbie
- Join Date
- Jun 2006
- Posts
- 150
hmm... now why was I thinking that that responded in seconds? Oh well, looks like it will work
. Thanks!
- 11-19-2007 #4
You might have been thinking of this:
which, being only 32 bits wide, has its uses.Code:man 2 time
--
Bill
Old age and treachery will overcome youth and skill.
- 11-19-2007 #5Linux Newbie
- Join Date
- Jun 2006
- Posts
- 150
...wait, this only returns the time in microseconds and seconds, which would be fine if the timer didn't overflow every quarter of a second or whatever... Is there a way to get timeval->tv_usec in something larger? I'm trying to write a simple game, and I need to make sure that the player can only fire his gun every half a second... Here's my function so far.
But right now, whenever the user fires right before the timer turns over, they can never fire again... Any other suggestions?Code:timeval now; gettimeofday(&now); if(now.tv_usec-this->LastShot<PLAYERSHOTTIME) { return NULL; } this->LastShot=now.tv_usec;
p.s. How do I get those man pages? They've all given me page not found errors.
- 11-20-2007 #6
Let's answer the more important (by far) question first:
Hmmmm. Man pages missing from your computer? Google this:How do I get those man pages? They've all given me page not found errors.
From the google search results, choose the man page layout that pleases you most.Code:Linux man gettimeofday
When you've read the man page, you'll see that you're interested in not just the tv_usec field, but also the tv_sec field. Both of them together specify the time of day; it's customary for the tv_usec field not to exceed 999999.
Questions after reading the man page? Come back. :)--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote
