5#include <SDL3/SDL_init.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
9#include "SDL3pp_strings.h"
322inline void Quit() { SDL_Quit(); }
402 CheckError(SDL_RunOnMainThread(callback, userdata, wait_complete));
433 void* wrapped = Wrapper::Wrap(std::move(callback));
476 CheckError(SDL_SetAppMetadata(appname, appversion, appidentifier));
541 CheckError(SDL_SetAppMetadataProperty(name, value));
544namespace prop::appMetaData {
546constexpr auto NAME_STRING = SDL_PROP_APP_METADATA_NAME_STRING;
548constexpr auto VERSION_STRING = SDL_PROP_APP_METADATA_VERSION_STRING;
550constexpr auto IDENTIFIER_STRING = SDL_PROP_APP_METADATA_IDENTIFIER_STRING;
552constexpr auto CREATOR_STRING = SDL_PROP_APP_METADATA_CREATOR_STRING;
554constexpr auto COPYRIGHT_STRING = SDL_PROP_APP_METADATA_COPYRIGHT_STRING;
556constexpr auto URL_STRING = SDL_PROP_APP_METADATA_URL_STRING;
558constexpr auto TYPE_STRING = SDL_PROP_APP_METADATA_TYPE_STRING;
585 return SDL_GetAppMetadataProperty(name);
588#ifndef SDL3PP_APPCLASS_LOG_PRIORITY
592#define SDL3PP_APPCLASS_LOG_PRIORITY LOG_PRIORITY_CRITICAL
615 static_assert(std::is_default_constructible_v<T>);
621 requires std::convertible_to<AppArgs, T>
624 *state =
new T{args};
631concept HasInitFunction =
requires(T** state) {
632 { T::Init(state,
AppArgs{}) } -> std::convertible_to<AppResult>;
653 }
catch (std::exception& e) {
661template<HasInitFunction T>
669 }
catch (std::exception& e) {
680concept HasIterateFunction =
requires(T* state) { state->Iterate(); };
689template<HasIterateFunction T>
693 return state->Iterate();
694 }
catch (std::exception& e) {
704concept HasEventFunction =
705 requires(T* state,
const SDL_Event& event) { state->Event(event); };
718 if (event.type == SDL_EVENT_QUIT)
return APP_SUCCESS;
736 }
catch (std::exception& e) {
744template<HasEventFunction T>
748 return state->Event(event);
749 }
catch (std::exception& e) {
773concept HasQuitFunction =
774 requires(T* state,
AppResult result) { T::Quit(state, result); };
794template<HasQuitFunction T>
797 T::Quit(state, result);
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
void Init(InitFlags flags)
Initialize the SDL library.
Definition: SDL3pp_init.h:256
void SetAppMetadata(StringParam appname, StringParam appversion, StringParam appidentifier)
Specify basic metadata about your app.
Definition: SDL3pp_init.h:472
void QuitClass(T *state, AppResult result)
Destroy state with given result.
Definition: SDL3pp_init.h:789
AppResult IterateClass(T *state)
Iterate the state.
Definition: SDL3pp_init.h:690
InitFlags WasInit(InitFlags flags)
Get a mask of the specified subsystems which are currently initialized.
Definition: SDL3pp_init.h:304
std::function< void()> MainThreadCB
Callback run on the main thread.
Definition: SDL3pp_init.h:371
void InitSubSystem(InitFlags flags)
Compatibility function to initialize the SDL library.
Definition: SDL3pp_init.h:272
AppResult DefaultCreateClass(T **state, AppArgs args)
Allocate and initialize state with new.
Definition: SDL3pp_init.h:613
constexpr AppResult APP_FAILURE
Value that requests termination with error from the main callbacks.
Definition: SDL3pp_init.h:126
std::span< char const *const > AppArgs
Represents application parameters.
Definition: SDL3pp_init.h:598
constexpr AppResult APP_CONTINUE
Value that requests that the app continue from the main callbacks.
Definition: SDL3pp_init.h:120
SDL_AppIterate_func AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition: SDL3pp_init.h:168
const char * GetAppMetadataProperty(StringParam name)
Get metadata about your app.
Definition: SDL3pp_init.h:583
SDL_MainThreadCallback MainThreadCallback
Callback run on the main thread.
Definition: SDL3pp_init.h:358
SDL_AppResult AppResult
Return values for optional main callbacks.
Definition: SDL3pp_init.h:117
SDL_AppInit_func AppInit_func
Function pointer typedef for SDL_AppInit.
Definition: SDL3pp_init.h:153
void RunOnMainThread(MainThreadCallback callback, void *userdata, bool wait_complete)
Call a function on the main thread during event processing.
Definition: SDL3pp_init.h:398
AppResult DefaultEventClass(T *state, const SDL_Event &event)
Default handle by finishing if QUIT is requested.
Definition: SDL3pp_init.h:716
void DefaultClassDestroy(T *state)
Destroy state with delete;.
Definition: SDL3pp_init.h:766
void SetAppMetadataProperty(StringParam name, StringParam value)
Specify metadata about your app through a set of properties.
Definition: SDL3pp_init.h:539
#define SDL3PP_APPCLASS_LOG_PRIORITY
The default log priority for app class.
Definition: SDL3pp_init.h:592
AppResult EventClass(T *state, const SDL_Event &event)
Iterate the state.
Definition: SDL3pp_init.h:732
void Quit()
Clean up all initialized subsystems.
Definition: SDL3pp_init.h:322
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition: SDL3pp_init.h:290
SDL_AppEvent_func AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition: SDL3pp_init.h:184
AppResult InitClass(T **state, AppArgs args)
Init state with arguments.
Definition: SDL3pp_init.h:649
bool IsMainThread()
Return whether this is the main thread.
Definition: SDL3pp_init.h:342
SDL_AppQuit_func AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition: SDL3pp_init.h:198
constexpr AppResult APP_SUCCESS
Value that requests termination with success from the main callbacks.
Definition: SDL3pp_init.h:123
void LogUnformatted(LogPriority priority, StringParam message) const
Log an unformatted message with the specified priority.
Definition: SDL3pp_log.h:216
constexpr LogCategory LOG_CATEGORY_APPLICATION
APPLICATION.
Definition: SDL3pp_log.h:441
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:325
constexpr InitFlags INIT_SENSOR
INIT_SENSOR implies INIT_EVENTS
Definition: SDL3pp_init.h:82
Uint32 InitFlags
Initialization flags for Init and/or InitSubSystem.
Definition: SDL3pp_init.h:62
constexpr InitFlags INIT_JOYSTICK
INIT_JOYSTICK implies INIT_EVENTS
Definition: SDL3pp_init.h:72
constexpr InitFlags INIT_VIDEO
INIT_VIDEO implies INIT_EVENTS, should be initialized on the main thread
Definition: SDL3pp_init.h:70
constexpr InitFlags INIT_AUDIO
INIT_AUDIO implies INIT_EVENTS
Definition: SDL3pp_init.h:64
constexpr InitFlags INIT_EVENTS
EVENTS.
Definition: SDL3pp_init.h:80
constexpr InitFlags INIT_GAMEPAD
INIT_GAMEPAD implies INIT_JOYSTICK
Definition: SDL3pp_init.h:77
constexpr InitFlags INIT_HAPTIC
HAPTIC.
Definition: SDL3pp_init.h:75
constexpr InitFlags INIT_CAMERA
INIT_CAMERA implies INIT_EVENTS
Definition: SDL3pp_init.h:85
Main include header for the SDL3pp library.
Definition: SDL3pp_callbackWrapper.h:66