Skip to main content
GameDev.net gamedev.net
🔒 Locked

Timer for Multiple Platforms

Started by The Lion King Dec 27, 2004 at 10:25 PM 8 replies 1.2k views
Original Post
The Lion King
The Lion King
What is the timer function that can be used in different operating systems simultaneously i.e. Windows, Linux and MAC OS. Functions like timeGetTime() that tells time in milliseconds from when the computer starts or something like that. Only problem is ... I can find plenty for Windows. I need something that can be used in all Win, Linux and MAC OS. Regards,
DukeAtreides076
DukeAtreides076
Theres a bunch of standard library functions provided in that you should be able to use.
The Lion King
The Lion King
Quote:
Original post by DukeAtreides076
Theres a bunch of standard library functions provided in that you should be able to use.


I need to know the time in seconds. Either seconds passes sincs computer has started or time in seconds ... for instance ... if 1 minute and 30 seconds have passed ... it should return 90 seconds. Which function should I use?

Between ... does it support the three OS i.e. Win, Linux and MAC OS?
Extrarius
Extrarius
Did you even try to google this? There is a C function called time located in time.h that returns a time in seconds... ... ...
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
mike25025
mike25025
#include <time.h>float getSeconds(){	return (float)clock()/(float)CLOCKS_PER_SEC;}
The Lion King
The Lion King
Quote:
Original post by Extrarius
Did you even try to google this? There is a C function called time located in time.h that returns a time in seconds... ... ...

Yes! I searched for that and find a couple of remakes ... but I am not sure wether they will work on other platforms besides Windows ... I have to make sure that my code works on Linux and MAC OS the same way without any changes for some one ... and I don't have Linux nor MAC OS. So, I have to only choose those functions that are perfectly sured to be working in the three Operating Systems.
MaulingMonkey
MaulingMonkey
Quote:
Original post by The Lion King
Quote:
Original post by Extrarius
Did you even try to google this? There is a C function called time located in time.h that returns a time in seconds... ... ...

Yes! I searched for that and find a couple of remakes ... but I am not sure wether they will work on other platforms besides Windows ... I have to make sure that my code works on Linux and MAC OS the same way without any changes for some one ... and I don't have Linux nor MAC OS. So, I have to only choose those functions that are perfectly sured to be working in the three Operating Systems.


The functions found in time.h / ctime (they're the same thing, except ctime is for use with C++, and has it's functions located within the std namespace) are standard. They should be available on all development environments. If they arn't, it's horribly broken*, since well, it's standard :-).

*(ctime won't exist on older compilers however)
markr
markr
Remember that clock() (if it exists at all), returns the CPU time used, not the elapsed time. So it's effectively useless for determining wall-clock time.

yes, the time() function works on all platforms and returns the time in seconds. For less than that, use the more accurate functions which are platform specific (hint: win32 = QueryPerformanceCounter or something, Unix-like=gettimeofday )

Mark
The Lion King
The Lion King
Thanks ... I don't need the function for counting FPS ... its for something else ... anyway ... clock() works perfectly as per my requirement.

Thank you guys (Y)

Cheers!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.