Here is an example emscripten/webassembly app made with this library. The corresponding source file can be found at this repo.
- don’t provide an OO framework
- follow Lisa Lippincott’s advice for wrapping C libraries
SDL_
=>sdl::
IMG_
=>sdl::img::
- Owning types
- owning types are provided for Surface, Texture, Window, and Renderer in the
sdl::unique
namespace. - these are unique pointers with the correct deleters supplied
- Functions that create an SDL object and return a pointer (SDL_CreateWindow) return unique:: types.
SDL_CreateWindow returns a
sdl::unique::Window
- owning types are provided for Surface, Texture, Window, and Renderer in the
- no out parameters
these are returned in a
tuple
orstruct
in the same order - when in parameters are pointers to allow a null value, provide an additional overload taking
std::optional
by value
- these are either constants or old style enums (for or-ing together)
- they are put in namespaces corresponding to the underscored prefixes in the SDL constant’s name
- if they were named all uppercase, we downcase everything and keep the underscores otherwise casing is the same
SDL_WINDOW_FULLSCREEN
=>sdl::window::fullscreen
SDL_WINDOW_
constants live in namespacewindow_opts
because there is already a Window type. Differing only by case is too tricky.SDL_PollEvent
is split into two functions:HasNextEvent()
which checks if the event queue has more eventsNextEvent()
which returns an optional containing the next event or nullopt if there are no more
SDL_WINDOWPOS_UNDEFINED
=>sdl::window::pos_undefined
- documented in the horrible macros file
- systematic changes are carried out through macros
- macros are prefixed with
SDLRAII_
- private/implementation macros are postfixed with a trailing underscore
- macros are undefined at the end of each file
- this tells the preprocessor what prefix to append to get SDL’s name for something
- examples
#define SDLRAII_THE_PREFIX SDL_
for things that start withSDL_
#define SDLRAII_THE_PREFIX IMG_
for things that start withIMG_
- appends the aformentioned prefix to
X
- subclasses
std::unique_ptr
(publicly) - names it
name
- sets the deleter to
destructor
- sets the type to
<prefix>_name
the rest provide a straightforward wrapping (either through using
or a variadic template that forwards its arguments)
- boost preprocessor
- SDL2