5#include <SDL3/SDL_init.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
9#include "SDL3pp_stdinc.h"
345template<
class FLAG0,
class FLAG1,
class... FLAGS>
411template<
class FLAG,
class... FLAGS>
449template<
class FLAG0,
class FLAG1,
class... FLAGS>
471template<
class FLAG,
class... FLAGS>
502template<
class FLAG0,
class FLAG1,
class... FLAGS>
503inline bool WasInit(FLAG0 flag0, FLAG1 flag1, FLAGS... flags)
519template<
class FLAG,
class... FLAGS>
520inline bool WasInit(FLAG flag0, FLAG flag1, FLAGS... flags)
522 return WasInit(flag0 | flag1, flags...);
541inline void Quit() { SDL_Quit(); }
556 bool m_active =
false;
558 bool updateActive(
bool active);
571 template<
class... FLAGS>
574 if (updateActive(
true)) {
589 constexpr SDL() =
default;
592 SDL(
const SDL& other) =
delete;
596 : m_active(other.m_active)
598 other.m_active =
false;
607 std::swap(m_active, rhs.m_active);
620 bool wasActive = m_active;
621 if (wasActive) { updateActive(
false); }
632 if (release())
Quit();
637 operator bool()
const {
return m_active; }
714 CheckError(SDL_RunOnMainThread(callback, userdata, wait_complete));
745 void* wrapped = Wrapper::Wrap(std::move(callback));
749 Wrapper::release(wrapped);
793 CheckError(SDL_SetAppMetadata(appname, appversion, appidentifier));
858 CheckError(SDL_SetAppMetadataProperty(name, value));
861namespace prop::appMetaData {
863constexpr auto NAME_STRING = SDL_PROP_APP_METADATA_NAME_STRING;
865constexpr auto VERSION_STRING = SDL_PROP_APP_METADATA_VERSION_STRING;
867constexpr auto IDENTIFIER_STRING = SDL_PROP_APP_METADATA_IDENTIFIER_STRING;
869constexpr auto CREATOR_STRING = SDL_PROP_APP_METADATA_CREATOR_STRING;
871constexpr auto COPYRIGHT_STRING = SDL_PROP_APP_METADATA_COPYRIGHT_STRING;
873constexpr auto URL_STRING = SDL_PROP_APP_METADATA_URL_STRING;
875constexpr auto TYPE_STRING = SDL_PROP_APP_METADATA_TYPE_STRING;
902 return SDL_GetAppMetadataProperty(name);
907#ifndef SDL3PP_APPCLASS_LOG_PRIORITY
911#define SDL3PP_APPCLASS_LOG_PRIORITY LOG_PRIORITY_CRITICAL
934 static_assert(std::is_default_constructible_v<T>);
940 requires std::convertible_to<AppArgs, T>
943 *state =
new T{args};
951 { T::Init(state,
AppArgs{}) } -> std::convertible_to<AppResult>;
972 }
catch (std::exception& e) {
980template<HasInitFunction T>
988 }
catch (std::exception& e) {
1008template<HasIterateFunction T>
1012 return state->Iterate();
1013 }
catch (std::exception& e) {
1024 requires(T* state,
const SDL_Event& event) { state->Event(event); };
1037 if (event.type == SDL_EVENT_QUIT)
return APP_SUCCESS;
1055 }
catch (std::exception& e) {
1063template<HasEventFunction T>
1067 return state->Event(event);
1068 }
catch (std::exception& e) {
1093 requires(T* state,
AppResult result) { T::Quit(state, result); };
1113template<HasQuitFunction T>
1116 T::Quit(state, result);
1122inline bool SDL::updateActive(
bool active)
1124 static std::atomic_bool currentlyInitd{
false};
1125 bool result = !currentlyInitd.exchange(active);
1126 if (active && !result) {
1128 "Can not initialize, there is already an active instance");
void LogUnformatted(LogPriority priority, StringParam message) const
Log an unformatted message with the specified priority.
Definition SDL3pp_log.h:226
constexpr SDL(SDL &&other)
Move ctor.
Definition SDL3pp_init.h:595
SDL(FLAGS... flags)
Init given subsystems.
Definition SDL3pp_init.h:572
constexpr SDL()=default
Default ctor.
bool reset()
reset the value of this instance, acts like it was destroyed and then newly instantiated with empty c...
Definition SDL3pp_init.h:630
SDL & operator=(SDL rhs)
Assignment operator.
Definition SDL3pp_init.h:605
bool release()
release locking such as reset() does, but never calls SDL_Quit() or SDL_QuitSubSystem()
Definition SDL3pp_init.h:618
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Definition SDL3pp_init.h:1023
Definition SDL3pp_init.h:950
Definition SDL3pp_init.h:999
Definition SDL3pp_init.h:1092
bool SetErrorUnformatted(StringParam message)
Set the SDL error message for the current thread.
Definition SDL3pp_error.h:66
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
void SetAppMetadata(StringParam appname, StringParam appversion, StringParam appidentifier)
Specify basic metadata about your app.
Definition SDL3pp_init.h:789
void QuitClass(T *state, AppResult result)
Destroy state with given result.
Definition SDL3pp_init.h:1108
AppResult IterateClass(T *state)
Iterate the state.
Definition SDL3pp_init.h:1009
std::function< void()> MainThreadCB
Definition SDL3pp_init.h:683
void InitSubSystem(InitFlags flags)
Initialize the SDL library.
Definition SDL3pp_init.h:283
AppResult DefaultCreateClass(T **state, AppArgs args)
Allocate and initialize state with new.
Definition SDL3pp_init.h:932
constexpr AppResult APP_FAILURE
Value that requests termination with error from the main callbacks.
Definition SDL3pp_init.h:153
std::span< char const *const > AppArgs
Represents application parameters.
Definition SDL3pp_init.h:917
constexpr AppResult APP_CONTINUE
Value that requests that the app continue from the main callbacks.
Definition SDL3pp_init.h:143
SDL_AppIterate_func AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition SDL3pp_init.h:195
const char * GetAppMetadataProperty(StringParam name)
Get metadata about your app.
Definition SDL3pp_init.h:900
SDL_MainThreadCallback MainThreadCallback
Callback run on the main thread.
Definition SDL3pp_init.h:674
SDL_AppResult AppResult
Return values for optional main callbacks.
Definition SDL3pp_init.h:138
bool WasInit(InitFlags flags)
Check if all of the specified subsystems which are currently initialized.
Definition SDL3pp_init.h:489
SDL_AppInit_func AppInit_func
Function pointer typedef for SDL_AppInit.
Definition SDL3pp_init.h:180
void RunOnMainThread(MainThreadCallback callback, void *userdata, bool wait_complete)
Call a function on the main thread during event processing.
Definition SDL3pp_init.h:710
AppResult DefaultEventClass(T *state, const SDL_Event &event)
Default handle by finishing if QUIT is requested.
Definition SDL3pp_init.h:1035
void DefaultClassDestroy(T *state)
Destroy state with delete;.
Definition SDL3pp_init.h:1085
void SetAppMetadataProperty(StringParam name, StringParam value)
Specify metadata about your app through a set of properties.
Definition SDL3pp_init.h:856
#define SDL3PP_APPCLASS_LOG_PRIORITY
The default log priority for app class.
Definition SDL3pp_init.h:911
AppResult EventClass(T *state, const SDL_Event &event)
Iterate the state.
Definition SDL3pp_init.h:1051
void Quit()
Clean up all initialized subsystems.
Definition SDL3pp_init.h:541
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition SDL3pp_init.h:431
SDL_AppEvent_func AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition SDL3pp_init.h:211
AppResult InitClass(T **state, AppArgs args)
Init state with arguments.
Definition SDL3pp_init.h:968
bool IsMainThread()
Return whether this is the main thread.
Definition SDL3pp_init.h:658
SDL_AppQuit_func AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition SDL3pp_init.h:225
constexpr AppResult APP_SUCCESS
Value that requests termination with success from the main callbacks.
Definition SDL3pp_init.h:148
constexpr LogCategory LOG_CATEGORY_APPLICATION
APPLICATION.
Definition SDL3pp_log.h:489
constexpr InitFlags INIT_SENSOR
INIT_SENSOR implies INIT_EVENTS
Definition SDL3pp_init.h:103
Uint32 InitFlags
Initialization flags for SDL.
Definition SDL3pp_init.h:66
constexpr InitFlags INIT_JOYSTICK
INIT_JOYSTICK implies INIT_EVENTS, should be initialized on the same thread as INIT_VIDEO on Windows ...
Definition SDL3pp_init.h:94
constexpr InitFlags INIT_VIDEO
INIT_VIDEO implies INIT_EVENTS, should be initialized on the main thread
Definition SDL3pp_init.h:88
constexpr InitFlags INIT_AUDIO
INIT_AUDIO implies INIT_EVENTS
Definition SDL3pp_init.h:82
constexpr InitFlags INIT_EVENTS
EVENTS.
Definition SDL3pp_init.h:101
constexpr InitFlags INIT_GAMEPAD
INIT_GAMEPAD implies INIT_JOYSTICK
Definition SDL3pp_init.h:98
constexpr InitFlags INIT_HAPTIC
HAPTIC.
Definition SDL3pp_init.h:96
constexpr InitFlags INIT_CAMERA
INIT_CAMERA implies INIT_EVENTS
Definition SDL3pp_init.h:106
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Definition SDL3pp_callbackWrapper.h:66