early-access version 2281
This commit is contained in:
122
externals/SDL/src/timer/SDL_timer.c
vendored
122
externals/SDL/src/timer/SDL_timer.c
vendored
@@ -28,6 +28,8 @@
|
||||
|
||||
/* #define DEBUG_TIMERS */
|
||||
|
||||
#if !defined(__EMSCRIPTEN__) || !SDL_THREADS_DISABLED
|
||||
|
||||
typedef struct _SDL_Timer
|
||||
{
|
||||
int timerID;
|
||||
@@ -370,4 +372,124 @@ SDL_RemoveTimer(SDL_TimerID id)
|
||||
return canceled;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
typedef struct _SDL_TimerMap
|
||||
{
|
||||
int timerID;
|
||||
int timeoutID;
|
||||
struct _SDL_TimerMap *next;
|
||||
} SDL_TimerMap;
|
||||
|
||||
typedef struct {
|
||||
int nextID;
|
||||
SDL_TimerMap *timermap;
|
||||
} SDL_TimerData;
|
||||
|
||||
static SDL_TimerData SDL_timer_data;
|
||||
|
||||
static void
|
||||
SDL_Emscripten_TimerHelper(SDL_TimerMap *entry, Uint32 interval, SDL_TimerCallback callback, void *param)
|
||||
{
|
||||
Uint32 new_timeout;
|
||||
|
||||
new_timeout = callback(interval, param);
|
||||
|
||||
if (new_timeout != 0) {
|
||||
entry->timeoutID = EM_ASM_INT({
|
||||
return Browser.safeSetTimeout(function() {
|
||||
dynCall('viiii', $0, [$1, $2, $3, $4]);
|
||||
}, $2);
|
||||
}, &SDL_Emscripten_TimerHelper, entry, interval, callback, param);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_TimerInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TimerQuit(void)
|
||||
{
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
while (data->timermap) {
|
||||
entry = data->timermap;
|
||||
data->timermap = entry->next;
|
||||
SDL_free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_TimerID
|
||||
SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
|
||||
{
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
SDL_TimerMap *entry;
|
||||
|
||||
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
|
||||
if (!entry) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
entry->timerID = ++data->nextID;
|
||||
|
||||
entry->timeoutID = EM_ASM_INT({
|
||||
return Browser.safeSetTimeout(function() {
|
||||
dynCall('viiii', $0, [$1, $2, $3, $4]);
|
||||
}, $2);
|
||||
}, &SDL_Emscripten_TimerHelper, entry, interval, callback, param);
|
||||
|
||||
entry->next = data->timermap;
|
||||
data->timermap = entry;
|
||||
|
||||
return entry->timerID;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_RemoveTimer(SDL_TimerID id)
|
||||
{
|
||||
SDL_TimerData *data = &SDL_timer_data;
|
||||
SDL_TimerMap *prev, *entry;
|
||||
|
||||
/* Find the timer */
|
||||
prev = NULL;
|
||||
for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
|
||||
if (entry->timerID == id) {
|
||||
if (prev) {
|
||||
prev->next = entry->next;
|
||||
} else {
|
||||
data->timermap = entry->next;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
EM_ASM_({
|
||||
window.clearTimeout($0);
|
||||
}, entry->timeoutID);
|
||||
SDL_free(entry);
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* This is a legacy support function; SDL_GetTicks() returns a Uint32,
|
||||
which wraps back to zero every ~49 days. The newer SDL_GetTicks64()
|
||||
doesn't have this problem, so we just wrap that function and clamp to
|
||||
the low 32-bits for binary compatibility. */
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
return (Uint32) (SDL_GetTicks64() & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
4
externals/SDL/src/timer/dummy/SDL_systimer.c
vendored
4
externals/SDL/src/timer/dummy/SDL_systimer.c
vendored
@@ -41,8 +41,8 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
|
6
externals/SDL/src/timer/haiku/SDL_systimer.c
vendored
6
externals/SDL/src/timer/haiku/SDL_systimer.c
vendored
@@ -47,14 +47,14 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
return ((system_time() - start) / 1000);
|
||||
return (Uint64) ((system_time() - start) / 1000);
|
||||
}
|
||||
|
||||
Uint64
|
||||
|
40
externals/SDL/src/timer/os2/SDL_systimer.c
vendored
40
externals/SDL/src/timer/os2/SDL_systimer.c
vendored
@@ -40,25 +40,26 @@
|
||||
typedef unsigned long long ULLONG;
|
||||
|
||||
static ULONG ulTmrFreq = 0;
|
||||
static ULLONG ullTmrStart;
|
||||
static ULLONG ullTmrStart = 0;
|
||||
|
||||
void
|
||||
SDL_TicksInit(void)
|
||||
{
|
||||
ULONG ulRC;
|
||||
|
||||
ulRC = DosTmrQueryFreq(&ulTmrFreq);
|
||||
ULONG ulTmrStart; /* for 32-bit fallback. */
|
||||
ULONG ulRC = DosTmrQueryFreq(&ulTmrFreq);
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosTmrQueryFreq() failed, rc = %u", ulRC);
|
||||
} else {
|
||||
ulRC = DosTmrQueryTime((PQWORD)&ullTmrStart);
|
||||
if (ulRC == NO_ERROR)
|
||||
if (ulRC == NO_ERROR) {
|
||||
return;
|
||||
}
|
||||
debug_os2("DosTmrQueryTime() failed, rc = %u", ulRC);
|
||||
}
|
||||
|
||||
ulTmrFreq = 0; /* Error - use DosQuerySysInfo() for timer. */
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrStart, sizeof(ULONG));
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulTmrStart, sizeof (ULONG));
|
||||
ullTmrStart = (ULLONG) ulTmrStart;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -66,24 +67,27 @@ SDL_TicksQuit(void)
|
||||
{
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
ULONG ulResult;
|
||||
ULLONG ullTmrNow;
|
||||
Uint64 ui64Result;
|
||||
ULLONG ullTmrNow;
|
||||
|
||||
if (ulTmrFreq == 0) /* Was not initialized. */
|
||||
if (ulTmrFreq == 0) { /* Was not initialized. */
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
if (ulTmrFreq != 0) {
|
||||
DosTmrQueryTime((PQWORD)&ullTmrNow);
|
||||
ulResult = (ullTmrNow - ullTmrStart) * 1000 / ulTmrFreq;
|
||||
ui64Result = (ullTmrNow - ullTmrStart) * 1000 / ulTmrFreq;
|
||||
} else {
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrNow, sizeof(ULONG));
|
||||
ulResult = (ULONG)ullTmrNow - (ULONG)ullTmrStart;
|
||||
/* note that this counter rolls over to 0 every ~49 days. Fix your system so DosTmrQueryTime works if you need to avoid this. */
|
||||
ULONG ulTmrNow;
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulTmrNow, sizeof (ULONG));
|
||||
ui64Result = (((Uint64) ulTmrNow) - ullTmrStart);
|
||||
}
|
||||
|
||||
return ulResult;
|
||||
return ui64Result;
|
||||
}
|
||||
|
||||
Uint64
|
||||
@@ -91,9 +95,9 @@ SDL_GetPerformanceCounter(void)
|
||||
{
|
||||
QWORD qwTmrNow;
|
||||
|
||||
if (ulTmrFreq == 0 || (DosTmrQueryTime(&qwTmrNow) != NO_ERROR))
|
||||
return SDL_GetTicks();
|
||||
|
||||
if (ulTmrFreq == 0 || (DosTmrQueryTime(&qwTmrNow) != NO_ERROR)) {
|
||||
return SDL_GetTicks64();
|
||||
}
|
||||
return *((Uint64 *)&qwTmrNow);
|
||||
}
|
||||
|
||||
|
13
externals/SDL/src/timer/psp/SDL_systimer.c
vendored
13
externals/SDL/src/timer/psp/SDL_systimer.c
vendored
@@ -51,24 +51,23 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32 SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
struct timeval now;
|
||||
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
struct timeval now;
|
||||
Uint32 ticks;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
|
||||
return(ticks);
|
||||
return (Uint64)(((Sint64)(now.tv_sec - start.tv_sec) * 1000) + ((now.tv_usec - start.tv_usec) / 1000));
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_GetPerformanceCounter(void)
|
||||
{
|
||||
return SDL_GetTicks();
|
||||
return SDL_GetTicks64();
|
||||
}
|
||||
|
||||
Uint64
|
||||
|
27
externals/SDL/src/timer/unix/SDL_systimer.c
vendored
27
externals/SDL/src/timer/unix/SDL_systimer.c
vendored
@@ -104,10 +104,9 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
Uint32 ticks;
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
@@ -116,21 +115,19 @@ SDL_GetTicks(void)
|
||||
#if HAVE_CLOCK_GETTIME
|
||||
struct timespec now;
|
||||
clock_gettime(SDL_MONOTONIC_CLOCK, &now);
|
||||
ticks = (Uint32)((now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec - start_ts.tv_nsec) / 1000000);
|
||||
return (Uint64)(((Sint64)(now.tv_sec - start_ts.tv_sec) * 1000) + ((now.tv_nsec - start_ts.tv_nsec) / 1000000));
|
||||
#elif defined(__APPLE__)
|
||||
uint64_t now = mach_absolute_time();
|
||||
ticks = (Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
|
||||
const uint64_t now = mach_absolute_time();
|
||||
return ((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
|
||||
#else
|
||||
SDL_assert(SDL_FALSE);
|
||||
ticks = 0;
|
||||
return 0;
|
||||
#endif
|
||||
} else {
|
||||
struct timeval now;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
ticks = (Uint32)((now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec - start_tv.tv_usec) / 1000);
|
||||
return (Uint64)(((Sint64)(now.tv_sec - start_tv.tv_sec) * 1000) + ((now.tv_usec - start_tv.tv_usec) / 1000));
|
||||
}
|
||||
return (ticks);
|
||||
}
|
||||
|
||||
Uint64
|
||||
@@ -203,7 +200,7 @@ SDL_Delay(Uint32 ms)
|
||||
struct timespec elapsed, tv;
|
||||
#else
|
||||
struct timeval tv;
|
||||
Uint32 then, now, elapsed;
|
||||
Uint64 then, now, elapsed;
|
||||
#endif
|
||||
|
||||
/* Set the timeout interval */
|
||||
@@ -211,7 +208,7 @@ SDL_Delay(Uint32 ms)
|
||||
elapsed.tv_sec = ms / 1000;
|
||||
elapsed.tv_nsec = (ms % 1000) * 1000000;
|
||||
#else
|
||||
then = SDL_GetTicks();
|
||||
then = SDL_GetTicks64();
|
||||
#endif
|
||||
do {
|
||||
errno = 0;
|
||||
@@ -222,13 +219,13 @@ SDL_Delay(Uint32 ms)
|
||||
was_error = nanosleep(&tv, &elapsed);
|
||||
#else
|
||||
/* Calculate the time interval left (in case of interrupt) */
|
||||
now = SDL_GetTicks();
|
||||
now = SDL_GetTicks64();
|
||||
elapsed = (now - then);
|
||||
then = now;
|
||||
if (elapsed >= ms) {
|
||||
if (elapsed >= ((Uint64)ms)) {
|
||||
break;
|
||||
}
|
||||
ms -= elapsed;
|
||||
ms -= (Uint32)elapsed;
|
||||
tv.tv_sec = ms / 1000;
|
||||
tv.tv_usec = (ms % 1000) * 1000;
|
||||
|
||||
|
7
externals/SDL/src/timer/vita/SDL_systimer.c
vendored
7
externals/SDL/src/timer/vita/SDL_systimer.c
vendored
@@ -51,18 +51,17 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32 SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
uint64_t now;
|
||||
Uint32 ticks;
|
||||
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
now = sceKernelGetProcessTimeWide();
|
||||
ticks = (now - start)/1000;
|
||||
return (ticks);
|
||||
return (Uint64) ((now - start) / 1000);
|
||||
}
|
||||
|
||||
Uint64
|
||||
|
66
externals/SDL/src/timer/windows/SDL_systimer.c
vendored
66
externals/SDL/src/timer/windows/SDL_systimer.c
vendored
@@ -33,12 +33,10 @@
|
||||
static DWORD start = 0;
|
||||
static BOOL ticks_started = FALSE;
|
||||
|
||||
/* Store if a high-resolution performance counter exists on the system */
|
||||
static BOOL hires_timer_available;
|
||||
/* The first high-resolution ticks value of the application */
|
||||
static LARGE_INTEGER hires_start_ticks;
|
||||
static LARGE_INTEGER start_ticks;
|
||||
/* The number of ticks per second of the high-resolution performance counter */
|
||||
static LARGE_INTEGER hires_ticks_per_second;
|
||||
static LARGE_INTEGER ticks_per_second;
|
||||
|
||||
static void
|
||||
SDL_SetSystemTimerResolution(const UINT uPeriod)
|
||||
@@ -79,6 +77,8 @@ SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValu
|
||||
void
|
||||
SDL_TicksInit(void)
|
||||
{
|
||||
BOOL rc;
|
||||
|
||||
if (ticks_started) {
|
||||
return;
|
||||
}
|
||||
@@ -90,18 +90,12 @@ SDL_TicksInit(void)
|
||||
SDL_TimerResolutionChanged, NULL);
|
||||
|
||||
/* Set first ticks value */
|
||||
/* QueryPerformanceCounter has had problems in the past, but lots of games
|
||||
use it, so we'll rely on it here.
|
||||
/* QueryPerformanceCounter allegedly is always available and reliable as of WinXP,
|
||||
so we'll rely on it here.
|
||||
*/
|
||||
if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
|
||||
hires_timer_available = TRUE;
|
||||
QueryPerformanceCounter(&hires_start_ticks);
|
||||
} else {
|
||||
hires_timer_available = FALSE;
|
||||
#ifndef __WINRT__
|
||||
start = timeGetTime();
|
||||
#endif /* __WINRT__ */
|
||||
}
|
||||
rc = QueryPerformanceFrequency(&ticks_per_second);
|
||||
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
|
||||
QueryPerformanceCounter(&start_ticks);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -116,53 +110,37 @@ SDL_TicksQuit(void)
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
DWORD now = 0;
|
||||
LARGE_INTEGER hires_now;
|
||||
LARGE_INTEGER now;
|
||||
BOOL rc;
|
||||
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
if (hires_timer_available) {
|
||||
QueryPerformanceCounter(&hires_now);
|
||||
|
||||
hires_now.QuadPart -= hires_start_ticks.QuadPart;
|
||||
hires_now.QuadPart *= 1000;
|
||||
hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
|
||||
|
||||
return (DWORD) hires_now.QuadPart;
|
||||
} else {
|
||||
#ifndef __WINRT__
|
||||
now = timeGetTime();
|
||||
#endif /* __WINRT__ */
|
||||
}
|
||||
|
||||
return (now - start);
|
||||
rc = QueryPerformanceCounter(&now);
|
||||
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
|
||||
return (Uint64) (((now.QuadPart - start_ticks.QuadPart) * 1000) / ticks_per_second.QuadPart);
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_GetPerformanceCounter(void)
|
||||
{
|
||||
LARGE_INTEGER counter;
|
||||
|
||||
if (!QueryPerformanceCounter(&counter)) {
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
return counter.QuadPart;
|
||||
const BOOL rc = QueryPerformanceCounter(&counter);
|
||||
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
|
||||
return (Uint64) counter.QuadPart;
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_GetPerformanceFrequency(void)
|
||||
{
|
||||
LARGE_INTEGER frequency;
|
||||
|
||||
if (!QueryPerformanceFrequency(&frequency)) {
|
||||
return 1000;
|
||||
}
|
||||
return frequency.QuadPart;
|
||||
const BOOL rc = QueryPerformanceFrequency(&frequency);
|
||||
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
|
||||
return (Uint64) frequency.QuadPart;
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user