5#include <SDL3/SDL_init.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
9#include "SDL3pp_strings.h"
316inline void Quit() { SDL_Quit(); }
396 CheckError(SDL_RunOnMainThread(callback, userdata, wait_complete));
427 void* wrapped = Wrapper::Wrap(std::move(callback));
468 CheckError(SDL_SetAppMetadata(appname, appversion, appidentifier));
532 CheckError(SDL_SetAppMetadataProperty(name, value));
535namespace prop::appMetaData {
537constexpr auto NAME_STRING = SDL_PROP_APP_METADATA_NAME_STRING;
539constexpr auto VERSION_STRING = SDL_PROP_APP_METADATA_VERSION_STRING;
541constexpr auto IDENTIFIER_STRING = SDL_PROP_APP_METADATA_IDENTIFIER_STRING;
543constexpr auto CREATOR_STRING = SDL_PROP_APP_METADATA_CREATOR_STRING;
545constexpr auto COPYRIGHT_STRING = SDL_PROP_APP_METADATA_COPYRIGHT_STRING;
547constexpr auto URL_STRING = SDL_PROP_APP_METADATA_URL_STRING;
549constexpr auto TYPE_STRING = SDL_PROP_APP_METADATA_TYPE_STRING;
576 return SDL_GetAppMetadataProperty(name);
579#ifndef SDL3PP_APPCLASS_LOG_PRIORITY
583#define SDL3PP_APPCLASS_LOG_PRIORITY LOG_PRIORITY_CRITICAL
606 static_assert(std::is_default_constructible_v<T>);
612 requires std::convertible_to<AppArgs, T>
615 *state =
new T{args};
622concept HasInitFunction =
requires(T** state) {
623 { T::Init(state,
AppArgs{}) } -> std::convertible_to<AppResult>;
644 }
catch (std::exception& e) {
652template<HasInitFunction T>
660 }
catch (std::exception& e) {
671concept HasIterateFunction =
requires(T* state) { state->Iterate(); };
680template<HasIterateFunction T>
684 return state->Iterate();
685 }
catch (std::exception& e) {
695concept HasEventFunction =
696 requires(T* state,
const SDL_Event& event) { state->Event(event); };
709 if (event.type == SDL_EVENT_QUIT)
return APP_SUCCESS;
727 }
catch (std::exception& e) {
735template<HasEventFunction T>
739 return state->Event(event);
740 }
catch (std::exception& e) {
764concept HasQuitFunction =
765 requires(T* state,
AppResult result) { T::Quit(state, result); };
785template<HasQuitFunction T>
788 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:197
void Init(InitFlags flags)
Initialize the SDL library.
Definition: SDL3pp_init.h:250
void SetAppMetadata(StringParam appname, StringParam appversion, StringParam appidentifier)
Specify basic metadata about your app.
Definition: SDL3pp_init.h:464
void QuitClass(T *state, AppResult result)
Destroy state with given result.
Definition: SDL3pp_init.h:780
AppResult IterateClass(T *state)
Iterate the state.
Definition: SDL3pp_init.h:681
InitFlags WasInit(InitFlags flags)
Get a mask of the specified subsystems which are currently initialized.
Definition: SDL3pp_init.h:298
std::function< void()> MainThreadCB
Callback run on the main thread.
Definition: SDL3pp_init.h:365
void InitSubSystem(InitFlags flags)
Compatibility function to initialize the SDL library.
Definition: SDL3pp_init.h:266
AppResult DefaultCreateClass(T **state, AppArgs args)
Allocate and initialize state with new.
Definition: SDL3pp_init.h:604
constexpr AppResult APP_FAILURE
Value that requests termination with error from the main callbacks.
Definition: SDL3pp_init.h:123
std::span< char const *const > AppArgs
Represents application parameters.
Definition: SDL3pp_init.h:589
constexpr AppResult APP_CONTINUE
Value that requests that the app continue from the main callbacks.
Definition: SDL3pp_init.h:117
SDL_AppIterate_func AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition: SDL3pp_init.h:164
const char * GetAppMetadataProperty(StringParam name)
Get metadata about your app.
Definition: SDL3pp_init.h:574
SDL_MainThreadCallback MainThreadCallback
Callback run on the main thread.
Definition: SDL3pp_init.h:351
SDL_AppResult AppResult
Return values for optional main callbacks.
Definition: SDL3pp_init.h:114
SDL_AppInit_func AppInit_func
Function pointer typedef for SDL_AppInit.
Definition: SDL3pp_init.h:149
void RunOnMainThread(MainThreadCallback callback, void *userdata, bool wait_complete)
Call a function on the main thread during event processing.
Definition: SDL3pp_init.h:392
AppResult DefaultEventClass(T *state, const SDL_Event &event)
Default handle by finishing if QUIT is requested.
Definition: SDL3pp_init.h:707
void DefaultClassDestroy(T *state)
Destroy state with delete;.
Definition: SDL3pp_init.h:757
void SetAppMetadataProperty(StringParam name, StringParam value)
Specify metadata about your app through a set of properties.
Definition: SDL3pp_init.h:530
#define SDL3PP_APPCLASS_LOG_PRIORITY
The default log priority for app class.
Definition: SDL3pp_init.h:583
AppResult EventClass(T *state, const SDL_Event &event)
Iterate the state.
Definition: SDL3pp_init.h:723
void Quit()
Clean up all initialized subsystems.
Definition: SDL3pp_init.h:316
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition: SDL3pp_init.h:284
SDL_AppEvent_func AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition: SDL3pp_init.h:180
AppResult InitClass(T **state, AppArgs args)
Init state with arguments.
Definition: SDL3pp_init.h:640
bool IsMainThread()
Return whether this is the main thread.
Definition: SDL3pp_init.h:335
SDL_AppQuit_func AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition: SDL3pp_init.h:194
constexpr AppResult APP_SUCCESS
Value that requests termination with success from the main callbacks.
Definition: SDL3pp_init.h:120
void LogUnformatted(LogPriority priority, StringParam message) const
Log an unformatted message with the specified priority.
Definition: SDL3pp_log.h:207
constexpr LogCategory LOG_CATEGORY_APPLICATION
APPLICATION.
Definition: SDL3pp_log.h:432
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
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