5#include <SDL3/SDL_init.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
8#include "SDL3pp_events.h"
10#include "SDL3pp_strings.h"
329inline void Quit() { SDL_Quit(); }
409 CheckError(SDL_RunOnMainThread(callback, userdata, wait_complete));
440 void* wrapped = Wrapper::Wrap(std::move(callback));
481 CheckError(SDL_SetAppMetadata(appname, appversion, appidentifier));
544 CheckError(SDL_SetAppMetadataProperty(name, value));
555constexpr auto NAME_STRING = SDL_PROP_APP_METADATA_NAME_STRING;
557constexpr auto VERSION_STRING = SDL_PROP_APP_METADATA_VERSION_STRING;
559constexpr auto IDENTIFIER_STRING = SDL_PROP_APP_METADATA_IDENTIFIER_STRING;
561constexpr auto CREATOR_STRING = SDL_PROP_APP_METADATA_CREATOR_STRING;
563constexpr auto COPYRIGHT_STRING = SDL_PROP_APP_METADATA_COPYRIGHT_STRING;
565constexpr auto URL_STRING = SDL_PROP_APP_METADATA_URL_STRING;
567constexpr auto TYPE_STRING = SDL_PROP_APP_METADATA_TYPE_STRING;
594 return SDL_GetAppMetadataProperty(name);
597#ifndef SDL3PP_APPCLASS_LOG_PRIORITY
601#define SDL3PP_APPCLASS_LOG_PRIORITY LOG_PRIORITY_CRITICAL
622 requires std::convertible_to<AppArgs, T>
625 *state =
new T{args};
632 static_assert(std::is_default_constructible_v<T>);
642 { T::Init(state,
AppArgs{}) } -> std::convertible_to<AppResult>;
663 }
catch (std::exception& e) {
671template<HasInitFunction T>
679 }
catch (std::exception& e) {
699template<HasIterateFunction T>
703 return state->Iterate();
704 }
catch (std::exception& e) {
715 requires(T* state,
const SDL_Event& event) { state->Event(event); };
727 if (event.type == SDL_EVENT_QUIT)
return APP_SUCCESS;
745 }
catch (std::exception& e) {
753template<HasEventFunction T>
757 return state->Event(event);
758 }
catch (std::exception& e) {
783 requires(T* state,
AppResult result) { T::Quit(state, result); };
803template<HasQuitFunction T>
806 T::Quit(state, result);
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Definition SDL3pp_init.h:714
Definition SDL3pp_init.h:641
Definition SDL3pp_init.h:690
Definition SDL3pp_init.h:782
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
SDL_Event Event
The structure for all events in SDL.
Definition SDL3pp_events.h:844
AppResult(SDLCALL *)(void **appstate, int argc, char *argv[]) AppInit_func
Function pointer typedef for SDL_AppInit.
Definition SDL3pp_init.h:150
void Init(InitFlags flags)
Initialize the SDL library.
Definition SDL3pp_init.h:255
void SetAppMetadata(StringParam appname, StringParam appversion, StringParam appidentifier)
Specify basic metadata about your app.
Definition SDL3pp_init.h:477
AppResult DefaultEventClass(T *, const SDL_Event &event)
Default handle by finishing if QUIT is requested.
Definition SDL3pp_init.h:725
AppResult IterateClass(T *state)
Iterate the state.
Definition SDL3pp_init.h:700
InitFlags WasInit(InitFlags flags)
Get a mask of the specified subsystems which are currently initialized.
Definition SDL3pp_init.h:309
SDL_AppResult AppResult
Return values for optional main callbacks.
Definition SDL3pp_init.h:115
void(SDLCALL *)(void *appstate, AppResult result) AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition SDL3pp_init.h:197
void InitSubSystem(InitFlags flags)
Compatibility function to initialize the SDL library.
Definition SDL3pp_init.h:273
AppResult DefaultCreateClass(T **state, AppArgs args)
Allocate and initialize state with new.
Definition SDL3pp_init.h:623
std::span< char const *const > AppArgs
Represents application parameters.
Definition SDL3pp_init.h:607
constexpr AppResult APP_FAILURE
Value that requests termination with error from the main callbacks.
Definition SDL3pp_init.h:124
constexpr AppResult APP_CONTINUE
Value that requests that the app continue from the main callbacks.
Definition SDL3pp_init.h:118
std::function< void()> MainThreadCB
Callback run on the main thread.
Definition SDL3pp_init.h:378
const char * GetAppMetadataProperty(StringParam name)
Get metadata about your app.
Definition SDL3pp_init.h:592
AppResult(SDLCALL *)(void *appstate, Event *event) AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition SDL3pp_init.h:183
AppResult(SDLCALL *)(void *appstate) AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition SDL3pp_init.h:167
void RunOnMainThread(MainThreadCallback callback, void *userdata, bool wait_complete)
Call a function on the main thread during event processing.
Definition SDL3pp_init.h:405
void DefaultClassDestroy(T *state)
Destroy state with delete;.
Definition SDL3pp_init.h:775
void SetAppMetadataProperty(StringParam name, StringParam value)
Specify metadata about your app through a set of properties.
Definition SDL3pp_init.h:542
#define SDL3PP_APPCLASS_LOG_PRIORITY
The default log priority for app class.
Definition SDL3pp_init.h:601
AppResult EventClass(T *state, const SDL_Event &event)
Iterate the state.
Definition SDL3pp_init.h:741
void Quit()
Clean up all initialized subsystems.
Definition SDL3pp_init.h:329
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition SDL3pp_init.h:293
void(SDLCALL *)(void *userdata) MainThreadCallback
Callback run on the main thread.
Definition SDL3pp_init.h:364
AppResult InitClass(T **state, AppArgs args)
Init state with arguments.
Definition SDL3pp_init.h:659
bool IsMainThread()
Return whether this is the main thread.
Definition SDL3pp_init.h:348
void QuitClass(T *state, AppResult)
Destroy state with given result.
Definition SDL3pp_init.h:798
constexpr AppResult APP_SUCCESS
Value that requests termination with success from the main callbacks.
Definition SDL3pp_init.h:121
constexpr LogCategory LOG_CATEGORY_APPLICATION
APPLICATION.
Definition SDL3pp_log.h:432
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
constexpr InitFlags INIT_SENSOR
INIT_SENSOR implies INIT_EVENTS
Definition SDL3pp_init.h:83
constexpr InitFlags INIT_JOYSTICK
INIT_JOYSTICK implies INIT_EVENTS
Definition SDL3pp_init.h:73
constexpr InitFlags INIT_VIDEO
INIT_VIDEO implies INIT_EVENTS, should be initialized on the main thread
Definition SDL3pp_init.h:71
constexpr InitFlags INIT_AUDIO
INIT_AUDIO implies INIT_EVENTS
Definition SDL3pp_init.h:65
constexpr InitFlags INIT_EVENTS
EVENTS.
Definition SDL3pp_init.h:81
constexpr InitFlags INIT_GAMEPAD
INIT_GAMEPAD implies INIT_JOYSTICK
Definition SDL3pp_init.h:78
Uint32 InitFlags
Initialization flags for Init and/or InitSubSystem.
Definition SDL3pp_init.h:63
constexpr InitFlags INIT_HAPTIC
HAPTIC.
Definition SDL3pp_init.h:76
constexpr InitFlags INIT_CAMERA
INIT_CAMERA implies INIT_EVENTS
Definition SDL3pp_init.h:86
Main include header for the SDL3pp library.
Definition SDL3pp_callbackWrapper.h:20