mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-14 08:30:50 +00:00
Fixed incorrect value that I_FPSTime() may return when OS X thread-based timer implementation is used
This commit is contained in:
parent
67b68e6b48
commit
5336f1085c
1 changed files with 24 additions and 18 deletions
|
@ -32,6 +32,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <libkern/OSAtomic.h>
|
#include <libkern/OSAtomic.h>
|
||||||
|
@ -43,34 +44,23 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
|
|
||||||
|
|
||||||
static timeval s_startTicks;
|
namespace
|
||||||
|
|
||||||
|
|
||||||
unsigned int I_MSTime()
|
|
||||||
{
|
{
|
||||||
timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
const uint32_t ticks =
|
timeval s_gameStartTicks;
|
||||||
(now.tv_sec - s_startTicks.tv_sec ) * 1000
|
timeval s_systemBootTicks;
|
||||||
+ (now.tv_usec - s_startTicks.tv_usec) / 1000;
|
|
||||||
|
|
||||||
return ticks;
|
unsigned int GetMillisecondsSince(const timeval& time)
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int I_FPSTime()
|
|
||||||
{
|
{
|
||||||
timeval now;
|
timeval now;
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
return static_cast<unsigned int>(
|
return static_cast<unsigned int>(
|
||||||
(now.tv_sec) * 1000 + (now.tv_usec) / 1000);
|
(now.tv_sec - time.tv_sec ) * 1000
|
||||||
|
+ (now.tv_usec - time.tv_usec) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
bool s_isTicFrozen;
|
bool s_isTicFrozen;
|
||||||
|
|
||||||
timespec GetNextTickTime()
|
timespec GetNextTickTime()
|
||||||
|
@ -185,6 +175,17 @@ void FreezeTimeThreaded(bool frozen)
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int I_MSTime()
|
||||||
|
{
|
||||||
|
return GetMillisecondsSince(s_gameStartTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int I_FPSTime()
|
||||||
|
{
|
||||||
|
return GetMillisecondsSince(s_systemBootTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fixed_t I_GetTimeFrac(uint32* ms)
|
fixed_t I_GetTimeFrac(uint32* ms)
|
||||||
{
|
{
|
||||||
const uint32_t now = I_MSTime();
|
const uint32_t now = I_MSTime();
|
||||||
|
@ -205,7 +206,12 @@ void I_InitTimer()
|
||||||
assert(!s_timerInitialized);
|
assert(!s_timerInitialized);
|
||||||
s_timerInitialized = true;
|
s_timerInitialized = true;
|
||||||
|
|
||||||
gettimeofday(&s_startTicks, NULL);
|
gettimeofday(&s_gameStartTicks, NULL);
|
||||||
|
|
||||||
|
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
|
||||||
|
size_t len = sizeof s_systemBootTicks;
|
||||||
|
|
||||||
|
sysctl(mib, 2, &s_systemBootTicks, &len, NULL, 0);
|
||||||
|
|
||||||
pthread_cond_init (&s_timerEvent, NULL);
|
pthread_cond_init (&s_timerEvent, NULL);
|
||||||
pthread_mutex_init(&s_timerMutex, NULL);
|
pthread_mutex_init(&s_timerMutex, NULL);
|
||||||
|
|
Loading…
Reference in a new issue