Add wrappers for SDL functions and structs
This commit is contained in:
parent
4277f4c818
commit
d180b8a5b4
18 changed files with 410 additions and 206 deletions
62
src/wrappers/sdl/init.cppm
Normal file
62
src/wrappers/sdl/init.cppm
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
module;
|
||||
|
||||
#include <type_traits>
|
||||
#include <SDL3/SDL.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 around 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 around SDL_Init().
|
||||
*/
|
||||
constexpr void Init(const InitFlags_t flags)
|
||||
{
|
||||
if (!SDL_Init(flags)) {
|
||||
throw SDLException("SDL_Init");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around SDL_SetAppMetadataProperty().
|
||||
*/
|
||||
constexpr void SetAppMetadataProperty(const char* property_name, const char* value)
|
||||
{
|
||||
if (!SDL_SetAppMetadataProperty(property_name, value)) {
|
||||
throw SDLException("SDL_SetAppMetadataProperty");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue