deps: SDL update to 2.30.0 (#3384)

In the hopes that some things have been fixed in the last year
(GAME_CONTROLLER init time, etc)

Make sure this does not regress #2691
This commit is contained in:
Tyler Wilding
2024-03-05 22:12:13 -05:00
committed by GitHub
parent 60db0e5ef9
commit ecd6091d7f
1295 changed files with 87263 additions and 281799 deletions
+24 -34
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,7 @@
/* #define DEBUG_TIMERS */
#if !defined(__EMSCRIPTEN__) || !SDL_THREADS_DISABLED
#if !defined(__EMSCRIPTEN__) || !defined(SDL_THREADS_DISABLED)
typedef struct _SDL_Timer
{
@@ -49,7 +49,8 @@ typedef struct _SDL_TimerMap
} SDL_TimerMap;
/* The timers are kept in a sorted list */
typedef struct {
typedef struct
{
/* Data used by the main thread */
SDL_Thread *thread;
SDL_atomic_t nextID;
@@ -78,14 +79,13 @@ static SDL_TimerData SDL_timer_data;
* Timers are removed by simply setting a canceled flag
*/
static void
SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer)
static void SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer)
{
SDL_Timer *prev, *curr;
prev = NULL;
for (curr = data->timers; curr; prev = curr, curr = curr->next) {
if ((Sint32)(timer->scheduled-curr->scheduled) < 0) {
if ((Sint32)(timer->scheduled - curr->scheduled) < 0) {
break;
}
}
@@ -99,8 +99,7 @@ SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer)
timer->next = curr;
}
static int SDLCALL
SDL_TimerThread(void *_data)
static int SDLCALL SDL_TimerThread(void *_data)
{
SDL_TimerData *data = (SDL_TimerData *)_data;
SDL_Timer *pending;
@@ -114,7 +113,7 @@ SDL_TimerThread(void *_data)
* 2. Handle any timers that should dispatch this cycle
* 3. Wait until next dispatch time or new timer arrives
*/
for ( ; ; ) {
for (;;) {
/* Pending and freelist maintenance */
SDL_AtomicLock(&data->lock);
{
@@ -153,7 +152,7 @@ SDL_TimerThread(void *_data)
while (data->timers) {
current = data->timers;
if ((Sint32)(tick-current->scheduled) < 0) {
if ((Sint32)(tick - current->scheduled) < 0) {
/* Scheduled for the future, wait a bit */
delay = (current->scheduled - tick);
break;
@@ -205,8 +204,7 @@ SDL_TimerThread(void *_data)
return 0;
}
int
SDL_TimerInit(void)
int SDL_TimerInit(void)
{
SDL_TimerData *data = &SDL_timer_data;
@@ -237,14 +235,13 @@ SDL_TimerInit(void)
return 0;
}
void
SDL_TimerQuit(void)
void SDL_TimerQuit(void)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
SDL_TimerMap *entry;
if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
/* Shutdown the timer thread */
if (data->thread) {
SDL_SemPost(data->sem);
@@ -277,8 +274,7 @@ SDL_TimerQuit(void)
}
}
SDL_TimerID
SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
@@ -340,8 +336,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
return entry->timerID;
}
SDL_bool
SDL_RemoveTimer(SDL_TimerID id)
SDL_bool SDL_RemoveTimer(SDL_TimerID id)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *prev, *entry;
@@ -387,17 +382,17 @@ typedef struct _SDL_TimerMap
struct _SDL_TimerMap *next;
} SDL_TimerMap;
typedef struct {
typedef struct
{
int nextID;
SDL_TimerMap *timermap;
} SDL_TimerData;
static SDL_TimerData SDL_timer_data;
static void
SDL_Emscripten_TimerHelper(void *userdata)
static void SDL_Emscripten_TimerHelper(void *userdata)
{
SDL_TimerMap *entry = (SDL_TimerMap*)userdata;
SDL_TimerMap *entry = (SDL_TimerMap *)userdata;
entry->interval = entry->callback(entry->interval, entry->param);
if (entry->interval > 0) {
entry->timeoutID = emscripten_set_timeout(&SDL_Emscripten_TimerHelper,
@@ -406,14 +401,12 @@ SDL_Emscripten_TimerHelper(void *userdata)
}
}
int
SDL_TimerInit(void)
int SDL_TimerInit(void)
{
return 0;
}
void
SDL_TimerQuit(void)
void SDL_TimerQuit(void)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *entry;
@@ -425,8 +418,7 @@ SDL_TimerQuit(void)
}
}
SDL_TimerID
SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *entry;
@@ -451,8 +443,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
return entry->timerID;
}
SDL_bool
SDL_RemoveTimer(SDL_TimerID id)
SDL_bool SDL_RemoveTimer(SDL_TimerID id)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *prev, *entry;
@@ -485,10 +476,9 @@ SDL_RemoveTimer(SDL_TimerID id)
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)
Uint32 SDL_GetTicks(void)
{
return (Uint32) (SDL_GetTicks64() & 0xFFFFFFFF);
return (Uint32)(SDL_GetTicks64() & 0xFFFFFFFF);
}
/* vi: set ts=4 sw=4 expandtab: */
+2 -2
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,7 @@
#include "SDL_timer.h"
#define ROUND_RESOLUTION(X) \
(((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
(((X + TIMER_RESOLUTION - 1) / TIMER_RESOLUTION) * TIMER_RESOLUTION)
extern void SDL_TicksInit(void);
extern void SDL_TicksQuit(void);
+7 -13
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -26,8 +26,7 @@
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -35,14 +34,12 @@ SDL_TicksInit(void)
ticks_started = SDL_TRUE;
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
if (!ticks_started) {
SDL_TicksInit();
@@ -52,20 +49,17 @@ SDL_GetTicks64(void)
return 0;
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
SDL_Unsupported();
}
+8 -14
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,8 +29,7 @@
static bigtime_t start;
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -41,36 +40,31 @@ SDL_TicksInit(void)
start = system_time();
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
if (!ticks_started) {
SDL_TicksInit();
}
return (Uint64) ((system_time() - start) / 1000);
return (Uint64)((system_time() - start) / 1000);
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return system_time();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000000;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
snooze(ms * 1000);
}
+7 -13
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -29,8 +29,7 @@ static u64 start_tick;
#define NSEC_PER_MSEC 1000000ULL
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -40,14 +39,12 @@ SDL_TicksInit(void)
start_tick = svcGetSystemTick();
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
u64 elapsed;
if (!ticks_started) {
@@ -58,20 +55,17 @@ SDL_GetTicks64(void)
return elapsed / CPU_TICKS_PER_MSEC;
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return svcGetSystemTick();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return SYSCLOCK_ARM11;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
svcSleepThread(ms * NSEC_PER_MSEC);
}
+13 -21
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,42 +28,37 @@
#include "SDL_timer.h"
static SDL_bool ticks_started = SDL_FALSE;
static TUint start = 0;
static TInt tickPeriodMilliSeconds;
static TUint start = 0;
static TInt tickPeriodMilliSeconds;
#ifdef __cplusplus
extern "C" {
#endif
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started)
{
if (ticks_started) {
return;
}
ticks_started = SDL_TRUE;
start = User::TickCount();
start = User::TickCount();
TTimeIntervalMicroSeconds32 period;
TInt tmp = UserHal::TickPeriod(period);
TInt tmp = UserHal::TickPeriod(period);
(void)tmp; /* Suppress redundant warning. */
tickPeriodMilliSeconds = period.Int() / 1000;
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
if (! ticks_started)
{
if (!ticks_started) {
SDL_TicksInit();
}
@@ -73,20 +68,17 @@ SDL_GetTicks64(void)
return (Uint64)(deltaTics * tickPeriodMilliSeconds);
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return (Uint64)User::TickCount();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000000;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
User::After(TTimeIntervalMicroSeconds32(ms * 1000));
}
+10 -16
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_TIMER_OS2
#ifdef SDL_TIMER_OS2
#include "SDL_timer.h"
#include "../../core/os2/SDL_os2.h"
@@ -43,8 +43,7 @@ static SDL_bool ticks_started = SDL_FALSE;
static ULONG ulTmrFreq = 0;
static ULLONG ullTmrStart = 0;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
ULONG ulTmrStart; /* for 32-bit fallback. */
ULONG ulRC;
@@ -66,18 +65,16 @@ SDL_TicksInit(void)
}
ulTmrFreq = 0; /* Error - use DosQuerySysInfo() for timer. */
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulTmrStart, sizeof (ULONG));
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulTmrStart, sizeof(ULONG));
ullTmrStart = (ULLONG) ulTmrStart;
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
Uint64 ui64Result;
ULLONG ullTmrNow;
@@ -92,15 +89,14 @@ SDL_GetTicks64(void)
} else {
/* 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));
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulTmrNow, sizeof(ULONG));
ui64Result = (((Uint64) ulTmrNow) - ullTmrStart);
}
return ui64Result;
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
QWORD qwTmrNow;
@@ -110,14 +106,12 @@ SDL_GetPerformanceCounter(void)
return *((Uint64 *)&qwTmrNow);
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return (ulTmrFreq == 0)? 1000 : (Uint64)ulTmrFreq;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
HTIMER hTimer = NULLHANDLE;
ULONG ulRC;
+9 -14
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,7 @@
static uint64_t start;
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -45,14 +44,12 @@ SDL_TicksInit(void)
start = GetTimerSystemTime();
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
uint64_t now;
@@ -64,23 +61,21 @@ SDL_GetTicks64(void)
return (Uint64)((now - start) / (kBUSCLK / CLOCKS_PER_SEC));
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks64();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000;
}
void SDL_Delay(Uint32 ms)
{
struct timespec tv = {0};
tv.tv_sec = ms / 1000;
tv.tv_nsec = (ms % 1000) * 1000000;
struct timespec tv = { 0 };
tv.tv_sec = ms / 1000;
tv.tv_nsec = (ms % 1000) * 1000000;
nanosleep(&tv, NULL);
}
+8 -12
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,7 @@
static struct timeval start;
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -45,14 +44,12 @@ SDL_TicksInit(void)
gettimeofday(&start, NULL);
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
struct timeval now;
@@ -64,14 +61,12 @@ SDL_GetTicks64(void)
return (Uint64)(((Sint64)(now.tv_sec - start.tv_sec) * 1000) + ((now.tv_usec - start.tv_usec) / 1000));
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return SDL_GetTicks64();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000;
}
@@ -79,8 +74,9 @@ SDL_GetPerformanceFrequency(void)
void SDL_Delay(Uint32 ms)
{
const Uint32 max_delay = 0xffffffffUL / 1000;
if(ms > max_delay)
if (ms > max_delay) {
ms = max_delay;
}
sceKernelDelayThreadCB(ms * 1000);
}
+21 -27
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -46,7 +46,7 @@
Also added OS X Monotonic clock support
Based on work in https://github.com/ThomasHabets/monotonic_clock
*/
#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
#if defined(HAVE_NANOSLEEP) || defined(HAVE_CLOCK_GETTIME)
#include <time.h>
#endif
#ifdef __APPLE__
@@ -54,7 +54,7 @@
#endif
/* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
#ifdef CLOCK_MONOTONIC_RAW
#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
#else
@@ -63,7 +63,7 @@
#endif
/* The first ticks value of the application */
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
static struct timespec start_ts;
#elif defined(__APPLE__)
static uint64_t start_mach;
@@ -73,8 +73,7 @@ static SDL_bool has_monotonic_time = SDL_FALSE;
static struct timeval start_tv;
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -82,7 +81,7 @@ SDL_TicksInit(void)
ticks_started = SDL_TRUE;
/* Set first ticks value */
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
if (clock_gettime(SDL_MONOTONIC_CLOCK, &start_ts) == 0) {
has_monotonic_time = SDL_TRUE;
} else
@@ -97,27 +96,25 @@ SDL_TicksInit(void)
}
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
if (!ticks_started) {
SDL_TicksInit();
}
if (has_monotonic_time) {
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
struct timespec now;
clock_gettime(SDL_MONOTONIC_CLOCK, &now);
return (Uint64)(((Sint64)(now.tv_sec - start_ts.tv_sec) * 1000) + ((now.tv_nsec - start_ts.tv_nsec) / 1000000));
#elif defined(__APPLE__)
const uint64_t now = mach_absolute_time();
return ((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
return (((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000;
#else
SDL_assert(SDL_FALSE);
return 0;
@@ -129,8 +126,7 @@ SDL_GetTicks64(void)
}
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
Uint64 ticks;
if (!ticks_started) {
@@ -138,7 +134,7 @@ SDL_GetPerformanceCounter(void)
}
if (has_monotonic_time) {
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
struct timespec now;
clock_gettime(SDL_MONOTONIC_CLOCK, &now);
@@ -159,18 +155,17 @@ SDL_GetPerformanceCounter(void)
ticks *= 1000000;
ticks += now.tv_usec;
}
return (ticks);
return ticks;
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
if (!ticks_started) {
SDL_TicksInit();
}
if (has_monotonic_time) {
#if HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
return 1000000000;
#elif defined(__APPLE__)
Uint64 freq = mach_base_info.denom;
@@ -178,17 +173,16 @@ SDL_GetPerformanceFrequency(void)
freq /= mach_base_info.numer;
return freq;
#endif
}
}
return 1000000;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
int was_error;
#if HAVE_NANOSLEEP
#ifdef HAVE_NANOSLEEP
struct timespec elapsed, tv;
#else
struct timeval tv;
@@ -204,7 +198,7 @@ SDL_Delay(Uint32 ms)
#endif
/* Set the timeout interval */
#if HAVE_NANOSLEEP
#ifdef HAVE_NANOSLEEP
elapsed.tv_sec = ms / 1000;
elapsed.tv_nsec = (ms % 1000) * 1000000;
#else
@@ -213,7 +207,7 @@ SDL_Delay(Uint32 ms)
do {
errno = 0;
#if HAVE_NANOSLEEP
#ifdef HAVE_NANOSLEEP
tv.tv_sec = elapsed.tv_sec;
tv.tv_nsec = elapsed.tv_nsec;
was_error = nanosleep(&tv, &elapsed);
+9 -13
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,7 @@
static uint64_t start;
static SDL_bool ticks_started = SDL_FALSE;
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
if (ticks_started) {
return;
@@ -45,14 +44,12 @@ SDL_TicksInit(void)
start = sceKernelGetProcessTimeWide();
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
uint64_t now;
@@ -61,17 +58,15 @@ SDL_GetTicks64(void)
}
now = sceKernelGetProcessTimeWide();
return (Uint64) ((now - start) / 1000);
return (Uint64)((now - start) / 1000);
}
Uint64
SDL_GetPerformanceCounter(void)
Uint64 SDL_GetPerformanceCounter(void)
{
return sceKernelGetProcessTimeWide();
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1000000;
}
@@ -79,8 +74,9 @@ SDL_GetPerformanceFrequency(void)
void SDL_Delay(Uint32 ms)
{
const Uint32 max_delay = 0xffffffffUL / 1000;
if(ms > max_delay)
if (ms > max_delay) {
ms = max_delay;
}
sceKernelDelayThreadCB(ms * 1000);
}
+18 -26
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -31,15 +31,14 @@
/* The first (low-resolution) ticks value of the application */
static DWORD start = 0;
static BOOL ticks_started = FALSE;
static BOOL ticks_started = FALSE;
/* The first high-resolution ticks value of the application */
static LARGE_INTEGER start_ticks;
/* The number of ticks per second of the high-resolution performance counter */
static LARGE_INTEGER ticks_per_second;
static void
SDL_SetSystemTimerResolution(const UINT uPeriod)
static void SDL_SetSystemTimerResolution(const UINT uPeriod)
{
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static UINT timer_period = 0;
@@ -58,8 +57,7 @@ SDL_SetSystemTimerResolution(const UINT uPeriod)
#endif
}
static void SDLCALL
SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static void SDLCALL SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
UINT uPeriod;
@@ -74,8 +72,7 @@ SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValu
}
}
void
SDL_TicksInit(void)
void SDL_TicksInit(void)
{
BOOL rc;
@@ -94,24 +91,22 @@ SDL_TicksInit(void)
so we'll rely on it here.
*/
rc = QueryPerformanceFrequency(&ticks_per_second);
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
QueryPerformanceCounter(&start_ticks);
}
void
SDL_TicksQuit(void)
void SDL_TicksQuit(void)
{
SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
SDL_TimerResolutionChanged, NULL);
SDL_SetSystemTimerResolution(0); /* always release our timer resolution request. */
SDL_SetSystemTimerResolution(0); /* always release our timer resolution request. */
start = 0;
ticks_started = SDL_FALSE;
}
Uint64
SDL_GetTicks64(void)
Uint64 SDL_GetTicks64(void)
{
LARGE_INTEGER now;
BOOL rc;
@@ -121,30 +116,27 @@ SDL_GetTicks64(void)
}
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);
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)
Uint64 SDL_GetPerformanceCounter(void)
{
LARGE_INTEGER counter;
const BOOL rc = QueryPerformanceCounter(&counter);
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
return (Uint64) counter.QuadPart;
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
return (Uint64)counter.QuadPart;
}
Uint64
SDL_GetPerformanceFrequency(void)
Uint64 SDL_GetPerformanceFrequency(void)
{
LARGE_INTEGER frequency;
const BOOL rc = QueryPerformanceFrequency(&frequency);
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
return (Uint64) frequency.QuadPart;
SDL_assert(rc != 0); /* this should _never_ fail if you're on XP or later. */
return (Uint64)frequency.QuadPart;
}
void
SDL_Delay(Uint32 ms)
void SDL_Delay(Uint32 ms)
{
/* Sleep() is not publicly available to apps in early versions of WinRT.
*