mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-19 16:21:44 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.
In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.
The script I ran for the src directory is added as build-scripts/clang-format-src.sh
This fixes:
#6592
#6593
#6594
(cherry picked from commit 5750bcb174
)
This commit is contained in:
@@ -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);
|
||||
@@ -387,17 +384,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 +403,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;
|
||||
@@ -488,7 +483,7 @@ SDL_RemoveTimer(SDL_TimerID id)
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
return (Uint32) (SDL_GetTicks64() & 0xFFFFFFFF);
|
||||
return (Uint32)(SDL_GetTicks64() & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
@@ -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);
|
||||
|
@@ -26,8 +26,7 @@
|
||||
|
||||
static SDL_bool ticks_started = SDL_FALSE;
|
||||
|
||||
void
|
||||
SDL_TicksInit(void)
|
||||
void SDL_TicksInit(void)
|
||||
{
|
||||
if (ticks_started) {
|
||||
return;
|
||||
@@ -35,8 +34,7 @@ SDL_TicksInit(void)
|
||||
ticks_started = SDL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -64,8 +62,7 @@ SDL_GetPerformanceFrequency(void)
|
||||
return 1000;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
void SDL_Delay(Uint32 ms)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
}
|
||||
|
@@ -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,8 +40,7 @@ SDL_TicksInit(void)
|
||||
start = system_time();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -54,7 +52,7 @@ SDL_GetTicks64(void)
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
return (Uint64) ((system_time() - start) / 1000);
|
||||
return (Uint64)((system_time() - start) / 1000);
|
||||
}
|
||||
|
||||
Uint64
|
||||
@@ -69,8 +67,7 @@ SDL_GetPerformanceFrequency(void)
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
void SDL_Delay(Uint32 ms)
|
||||
{
|
||||
snooze(ms * 1000);
|
||||
}
|
||||
|
@@ -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,8 +39,7 @@ SDL_TicksInit(void)
|
||||
start_tick = svcGetSystemTick();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -70,8 +68,7 @@ SDL_GetPerformanceFrequency(void)
|
||||
return SYSCLOCK_ARM11;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
void SDL_Delay(Uint32 ms)
|
||||
{
|
||||
svcSleepThread(ms * NSEC_PER_MSEC);
|
||||
}
|
||||
|
@@ -28,32 +28,30 @@
|
||||
#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) {
|
||||
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;
|
||||
}
|
||||
@@ -61,7 +59,7 @@ SDL_TicksQuit(void)
|
||||
Uint64
|
||||
SDL_GetTicks64(void)
|
||||
{
|
||||
if (! ticks_started) {
|
||||
if (!ticks_started) {
|
||||
SDL_TicksInit();
|
||||
}
|
||||
|
||||
@@ -83,8 +81,7 @@ SDL_GetPerformanceFrequency(void)
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
void SDL_Delay(Uint32 ms)
|
||||
{
|
||||
User::After(TTimeIntervalMicroSeconds32(ms * 1000));
|
||||
}
|
||||
|
@@ -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,8 +44,7 @@ SDL_TicksInit(void)
|
||||
start = GetTimerSystemTime();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -78,9 +76,9 @@ SDL_GetPerformanceFrequency(void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -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,8 +44,7 @@ SDL_TicksInit(void)
|
||||
gettimeofday(&start, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -97,8 +96,7 @@ SDL_TicksInit(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -178,13 +176,12 @@ 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;
|
||||
|
||||
|
@@ -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,8 +44,7 @@ SDL_TicksInit(void)
|
||||
start = sceKernelGetProcessTimeWide();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TicksQuit(void)
|
||||
void SDL_TicksQuit(void)
|
||||
{
|
||||
ticks_started = SDL_FALSE;
|
||||
}
|
||||
@@ -61,7 +59,7 @@ SDL_GetTicks64(void)
|
||||
}
|
||||
|
||||
now = sceKernelGetProcessTimeWide();
|
||||
return (Uint64) ((now - start) / 1000);
|
||||
return (Uint64)((now - start) / 1000);
|
||||
}
|
||||
|
||||
Uint64
|
||||
|
@@ -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,17 +91,16 @@ 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;
|
||||
@@ -121,8 +117,8 @@ 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
|
||||
@@ -130,8 +126,8 @@ 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
|
||||
@@ -139,12 +135,11 @@ 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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user