Skip to content

Commit

Permalink
Update for latest 'main' version/renderer/keysym changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed May 22, 2024
1 parent 7ae338f commit e21e38c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
26 changes: 25 additions & 1 deletion src/SDLmzx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ __M_BEGIN_DECLS

#if CONFIG_SDL == 3
#include <SDL3/SDL.h>
#include <SDL3/SDL_version.h>
#else
#include <SDL.h>
#if defined(_WIN32) || defined(CONFIG_X11)
Expand Down Expand Up @@ -284,6 +285,8 @@ static inline void SDL_SetJoystickEventsEnabled(SDL_bool enabled)
* SDL_keyboard.h and SDL_keycode.h
*/
#if !SDL_VERSION_ATLEAST(3,0,0)
#define SDLK_APOSTROPHE SDLK_QUOTE
#define SDLK_GRAVE SDLK_BACKQUOTE
#define SDL_KMOD_CTRL KMOD_CTRL
#define SDL_KMOD_ALT KMOD_ALT
#define SDL_KMOD_NUM KMOD_NUM
Expand Down Expand Up @@ -418,7 +421,28 @@ typedef SDL_sem SDL_Semaphore;
* SDL_version.h
*/
#if !SDL_VERSION_ATLEAST(3,0,0)
typedef SDL_version SDL_Version;
#define SDL_MICRO_VERSION SDL_PATCHLEVEL

#undef SDL_VERSIONNUM
#define SDL_VERSIONNUM(x,y,z) ((x) * 1000000 + (y) * 1000 + (z))
#define SDL_VERSIONNUM_MAJOR(v) ((v) / 1000000)
#define SDL_VERSIONNUM_MINOR(v) (((v) / 1000) % 1000)
#define SDL_VERSIONNUM_MICRO(v) ((v) % 1000)

#undef SDL_VERSION
#define SDL_VERSION SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)

static inline int replace_SDL_GetVersion(void)
{
SDL_version ver;
#if SDL_VERSION_ATLEAST(2,0,0)
SDK_GetVersion(&ver);
#else
ver = *SDL_Linked_Version();
#endif
return SDL_VERSIONNUM(ver.major, ver.minor, ver.patch);
}
#define SDL_GetVersion replace_SDL_GetVersion
#endif

/**
Expand Down
23 changes: 12 additions & 11 deletions src/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,22 @@ static char **about_text(int *num_lines)

#ifdef CONFIG_SDL
{
SDL_Version compiled;
SDL_Version ver;
SDL_VERSION(&compiled);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_GetVersion(&ver);
#else
ver = *SDL_Linked_Version();
#endif
if(memcmp(&compiled, &ver, sizeof(SDL_Version)))
int ver_compiled = SDL_VERSION;
int ver_linked = SDL_GetVersion();

if(ver_compiled != ver_linked)
{
lines[i++] = about_line("SDL: %u.%u.%u (compiled: %u.%u.%u)",
ver.major, ver.minor, ver.patch, compiled.major, compiled.minor, compiled.patch);
SDL_VERSIONNUM_MAJOR(ver_linked),
SDL_VERSIONNUM_MINOR(ver_linked),
SDL_VERSIONNUM_MICRO(ver_linked),
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION);
}
else
lines[i++] = about_line("SDL: %u.%u.%u", ver.major, ver.minor, ver.patch);
{
lines[i++] = about_line("SDL: %u.%u.%u",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION);
}
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/event_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static enum keycode convert_SDL_internal(SDL_Keycode key)
case SDLK_RETURN: return IKEY_RETURN;
case SDLK_ESCAPE: return IKEY_ESCAPE;
case SDLK_SPACE: return IKEY_SPACE;
case SDLK_QUOTE: return IKEY_QUOTE;
case SDLK_APOSTROPHE: return IKEY_QUOTE;
case SDLK_PLUS: return IKEY_EQUALS;
case SDLK_COMMA: return IKEY_COMMA;
case SDLK_MINUS: return IKEY_MINUS;
Expand All @@ -71,7 +71,7 @@ static enum keycode convert_SDL_internal(SDL_Keycode key)
case SDLK_LEFTBRACKET: return IKEY_LEFTBRACKET;
case SDLK_BACKSLASH: return IKEY_BACKSLASH;
case SDLK_RIGHTBRACKET: return IKEY_RIGHTBRACKET;
case SDLK_BACKQUOTE: return IKEY_BACKQUOTE;
case SDLK_GRAVE: return IKEY_BACKQUOTE;
case SDLK_a: return IKEY_a;
case SDLK_b: return IKEY_b;
case SDLK_c: return IKEY_c;
Expand Down
4 changes: 4 additions & 0 deletions src/render_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,12 @@ boolean sdlrender_set_video_mode(struct graphics_data *graphics,

// Note: previously attempted SDL_RENDERER_ACCELERATED first, then
// SDL_RENDERER_SOFTWARE, but these flags were removed in SDL3.
#if SDL_VERSION_ATLEAST(3,0,0)
render_data->renderer = SDL_CreateRenderer(render_data->window, BEST_RENDERER);
#else
render_data->renderer =
SDL_CreateRenderer(render_data->window, BEST_RENDERER, sdl_rendererflags);
#endif
if(!render_data->renderer)
{
warn("Failed to create renderer: %s\n", SDL_GetError());
Expand Down

0 comments on commit e21e38c

Please sign in to comment.