mirror of
https://github.com/love2d/love.git
synced 2026-08-21 05:00:08 +02:00
New attempt at love.timer.getMicroTime
This commit is contained in:
@@ -93,19 +93,12 @@ namespace sdl
|
|||||||
float Timer::getMicroTime() const
|
float Timer::getMicroTime() const
|
||||||
{
|
{
|
||||||
#ifdef LOVE_WINDOWS
|
#ifdef LOVE_WINDOWS
|
||||||
FILETIME tstruct;
|
long ticks, freq;
|
||||||
unsigned __int64 t = 0;
|
QueryPeformanceCounter(&ticks);
|
||||||
GetSystemTimeAsFileTime(&tstruct); //ah, yes, a struct with a high and a low part
|
QueryPeformanceFrequency(&freq);
|
||||||
t = tstruct.dwHighDateTime; //let's make it one variable;
|
long secs = ticks/freq;
|
||||||
t <<= 32;
|
long usecs = (ticks%freq)/(freq/1000000.0f);
|
||||||
t |= tstruct.dwLowDateTime;
|
return secs%86400 + usecs/1000000.0f;
|
||||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
|
||||||
float floatt = (t/10-11644473600000000Ui64)/1000000.0f;
|
|
||||||
#else
|
|
||||||
float floatt = (t/11644473600000000ULL)/1000000.0f;
|
|
||||||
#endif //even windows has it's differences, yay...
|
|
||||||
floatt %= 86400; //from start of day, else it's too big for a lua_Number
|
|
||||||
return floatt;
|
|
||||||
#else
|
#else
|
||||||
timeval t;
|
timeval t;
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ namespace sdl
|
|||||||
float getTime() const;
|
float getTime() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the amount of time since the Epoch. Useful for timing too because
|
* Gets the amount of time passed since an unspecified time. The time is accurate
|
||||||
* it is accurate to the microsecond.
|
* to the microsecond, and is limited to 24 hours.
|
||||||
* @return The time (in seconds) since the Epoch.
|
* @return The time (in seconds)
|
||||||
**/
|
**/
|
||||||
float getMicroTime() const;
|
float getMicroTime() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user