Timers are a required platform feature

Many SDL subsystems depend on being able to see time passing. If you are porting to a new platform, you'll need to fill in a timer implementation as part of the initial port.

Fixes https://github.com/libsdl-org/SDL/issues/8850
This commit is contained in:
Sam Lantinga 2024-01-16 20:09:37 -08:00
parent 518b070aa9
commit 0d7df16812
7 changed files with 2 additions and 75 deletions

View File

@ -2179,7 +2179,7 @@ elseif(APPLE)
set(SDL_TIMER_UNIX 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c")
set(HAVE_SDL_TIMERS TRUE)
endif(SDL_TIMERS)
endif()
if(SDL_FILESYSTEM)
set(SDL_FILESYSTEM_COCOA 1)
@ -2831,8 +2831,7 @@ if(NOT HAVE_SDL_THREADS)
endif()
endif()
if(NOT HAVE_SDL_TIMERS)
set(SDL_TIMER_DUMMY 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/dummy/*.c")
message(FATAL_ERROR "Timers are needed by many SDL subsystems and may not be disabled")
endif()
# Most platforms use this.

View File

@ -96,7 +96,6 @@
A7D8AB2523E2514100DCD162 /* SDL_log.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A5DD23E2513D00DCD162 /* SDL_log.c */; };
A7D8AB2B23E2514100DCD162 /* SDL_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A5DF23E2513D00DCD162 /* SDL_timer.c */; };
A7D8AB3123E2514100DCD162 /* SDL_timer_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A5E023E2513D00DCD162 /* SDL_timer_c.h */; };
A7D8AB3723E2514100DCD162 /* SDL_systimer.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A5E223E2513D00DCD162 /* SDL_systimer.c */; };
A7D8AB4923E2514100DCD162 /* SDL_systimer.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A5E823E2513D00DCD162 /* SDL_systimer.c */; };
A7D8AB5B23E2514100DCD162 /* SDL_offscreenevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A5EE23E2513D00DCD162 /* SDL_offscreenevents_c.h */; };
A7D8AB6123E2514100DCD162 /* SDL_offscreenwindow.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A5EF23E2513D00DCD162 /* SDL_offscreenwindow.c */; };
@ -592,7 +591,6 @@
A7D8A5DD23E2513D00DCD162 /* SDL_log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_log.c; sourceTree = "<group>"; };
A7D8A5DF23E2513D00DCD162 /* SDL_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_timer.c; sourceTree = "<group>"; };
A7D8A5E023E2513D00DCD162 /* SDL_timer_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_timer_c.h; sourceTree = "<group>"; };
A7D8A5E223E2513D00DCD162 /* SDL_systimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systimer.c; sourceTree = "<group>"; };
A7D8A5E823E2513D00DCD162 /* SDL_systimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systimer.c; sourceTree = "<group>"; };
A7D8A5EE23E2513D00DCD162 /* SDL_offscreenevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_offscreenevents_c.h; sourceTree = "<group>"; };
A7D8A5EF23E2513D00DCD162 /* SDL_offscreenwindow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_offscreenwindow.c; sourceTree = "<group>"; };
@ -1388,7 +1386,6 @@
A7D8A5DE23E2513D00DCD162 /* timer */ = {
isa = PBXGroup;
children = (
A7D8A5E123E2513D00DCD162 /* dummy */,
A7D8A5E723E2513D00DCD162 /* unix */,
A7D8A5E023E2513D00DCD162 /* SDL_timer_c.h */,
A7D8A5DF23E2513D00DCD162 /* SDL_timer.c */,
@ -1396,14 +1393,6 @@
path = timer;
sourceTree = "<group>";
};
A7D8A5E123E2513D00DCD162 /* dummy */ = {
isa = PBXGroup;
children = (
A7D8A5E223E2513D00DCD162 /* SDL_systimer.c */,
);
path = dummy;
sourceTree = "<group>";
};
A7D8A5E723E2513D00DCD162 /* unix */ = {
isa = PBXGroup;
children = (
@ -2544,7 +2533,6 @@
A7D8B9DD23E2514400DCD162 /* SDL_blendpoint.c in Sources */,
A7D8B4EE23E2514300DCD162 /* SDL_gamepad.c in Sources */,
E4A568B62AF763940062EEC4 /* SDL_sysmain_callbacks.c in Sources */,
A7D8AB3723E2514100DCD162 /* SDL_systimer.c in Sources */,
A7D8BA1323E2514400DCD162 /* SDL_render_sw.c in Sources */,
A7D8B42223E2514300DCD162 /* SDL_syssem.c in Sources */,
A7D8B53923E2514300DCD162 /* SDL_hidapi_xbox360.c in Sources */,

View File

@ -268,7 +268,6 @@
#cmakedefine SDL_LOADSO_DISABLED @SDL_LOADSO_DISABLED@
#cmakedefine SDL_RENDER_DISABLED @SDL_RENDER_DISABLED@
#cmakedefine SDL_THREADS_DISABLED @SDL_THREADS_DISABLED@
#cmakedefine SDL_TIMERS_DISABLED @SDL_TIMERS_DISABLED@
#cmakedefine SDL_VIDEO_DISABLED @SDL_VIDEO_DISABLED@
#cmakedefine SDL_POWER_DISABLED @SDL_POWER_DISABLED@
#cmakedefine SDL_FILESYSTEM_DISABLED @SDL_FILESYSTEM_DISABLED@

View File

@ -83,9 +83,6 @@ typedef unsigned int uintptr_t;
/* Enable the stub thread support (src/thread/generic/\*.c) */
#define SDL_THREADS_DISABLED 1
/* Enable the stub timer support (src/timer/dummy/\*.c) */
#define SDL_TIMERS_DISABLED 1
/* Enable the dummy video driver (src/video/dummy/\*.c) */
#define SDL_VIDEO_DRIVER_DUMMY 1

View File

@ -48,9 +48,7 @@
#include "sensor/SDL_sensor_c.h"
/* Initialization/Cleanup routines */
#ifndef SDL_TIMERS_DISABLED
#include "timer/SDL_timer_c.h"
#endif
#ifdef SDL_VIDEO_DRIVER_WINDOWS
extern int SDL_HelperWindowCreate(void);
extern int SDL_HelperWindowDestroy(void);
@ -202,9 +200,7 @@ int SDL_InitSubSystem(Uint32 flags)
}
#endif
#ifndef SDL_TIMERS_DISABLED
SDL_InitTicks();
#endif
/* Initialize the event subsystem */
if (flags & SDL_INIT_EVENTS) {
@ -227,7 +223,6 @@ int SDL_InitSubSystem(Uint32 flags)
/* Initialize the timer subsystem */
if (flags & SDL_INIT_TIMER) {
#if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
if (SDL_ShouldInitSubsystem(SDL_INIT_TIMER)) {
SDL_IncrementSubsystemRefCount(SDL_INIT_TIMER);
if (SDL_InitTimers() < 0) {
@ -238,10 +233,6 @@ int SDL_InitSubSystem(Uint32 flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_TIMER);
}
flags_initialized |= SDL_INIT_TIMER;
#else
SDL_SetError("SDL not built with timer support");
goto quit_and_error;
#endif
}
/* Initialize the video subsystem */
@ -454,14 +445,12 @@ void SDL_QuitSubSystem(Uint32 flags)
}
#endif
#if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
if (flags & SDL_INIT_TIMER) {
if (SDL_ShouldQuitSubsystem(SDL_INIT_TIMER)) {
SDL_QuitTimers();
}
SDL_DecrementSubsystemRefCount(SDL_INIT_TIMER);
}
#endif
#ifndef SDL_EVENTS_DISABLED
if (flags & SDL_INIT_EVENTS) {
@ -513,9 +502,7 @@ void SDL_Quit(void)
#endif
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
#ifndef SDL_TIMERS_DISABLED
SDL_QuitTicks();
#endif
#ifdef SDL_USE_LIBDBUS
SDL_DBus_Quit();

View File

@ -1,41 +0,0 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
Uint64 SDL_GetPerformanceCounter(void)
{
SDL_Unsupported();
return 0;
}
Uint64 SDL_GetPerformanceFrequency(void)
{
return 1;
}
void SDL_DelayNS(Uint64 ns)
{
SDL_Unsupported();
}
#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */

View File

@ -465,9 +465,7 @@ int SDL_VideoInit(const char *driver_name)
SDL_VideoQuit();
}
#ifndef SDL_TIMERS_DISABLED
SDL_InitTicks();
#endif
/* Start the event loop */
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {