rutile-game/src/wrappers/sdl/init.cppm

63 lines
1.8 KiB
Text
Raw Normal View History

module;
#include <type_traits>
#include <SDL3/SDL_init.h>
export module wrappers.sdl.init;
import wrappers.sdl.error;
export namespace sdl
{
using InitFlags_t = SDL_InitFlags;
/**
* Wrapper for the SDL_InitFlags enum/constants.
*
* We're using a namespace here to emulate an enum-like interface. If we used an actual enum, we would have to
* explicitly define bit-wise operations for it (as well as for every other kind of bit flag enum.
* (Maybe in the future this can be replaced with a more elegant template-based solution or something.)
*/
namespace InitFlags
{
constexpr InitFlags_t Audio = SDL_INIT_AUDIO;
constexpr InitFlags_t Video = SDL_INIT_VIDEO;
constexpr InitFlags_t Joystick = SDL_INIT_JOYSTICK;
constexpr InitFlags_t Haptic = SDL_INIT_HAPTIC;
constexpr InitFlags_t Gamepad = SDL_INIT_GAMEPAD;
constexpr InitFlags_t Events = SDL_INIT_EVENTS;
constexpr InitFlags_t Sensor = SDL_INIT_SENSOR;
constexpr InitFlags_t Camera = SDL_INIT_CAMERA;
}
/**
* Wrapper for the SDL_AppResult enum.
*/
enum class AppResult : std::underlying_type_t<SDL_AppResult>
{
Continue = SDL_APP_CONTINUE,
Success = SDL_APP_SUCCESS,
Failure = SDL_APP_FAILURE,
};
/**
* Wrapper for SDL_Init().
*/
constexpr void initialize_sdl(const InitFlags_t flags)
{
if (!SDL_Init(flags)) {
throw SDLException("SDL_Init");
}
}
/**
* Wrapper for SDL_SetAppMetadataProperty().
*/
constexpr void set_app_metadata_property(const char* property_name, const char* value)
{
if (!SDL_SetAppMetadataProperty(property_name, value)) {
throw SDLException("SDL_SetAppMetadataProperty");
}
}
}