diff --git a/src/SDLmzx.h b/src/SDLmzx.h index 5b63d6277..5b12d96e9 100644 --- a/src/SDLmzx.h +++ b/src/SDLmzx.h @@ -349,16 +349,14 @@ typedef struct { float x; float y; float w; float h; } SDL_FRect; #if SDL_VERSION_ATLEAST(3,0,0) typedef SDL_FRect SDL_Rect_mzx; -static inline SDL_Rect_mzx sdl_render_rect(int x, int y, - int w, int h, int full_w, int full_h) +static inline SDL_Rect_mzx sdl_render_rect(int x, int y, int w, int h) { SDL_FRect tmp = { (float)x, (float)y, (float)w, (float)h }; return tmp; } #elif SDL_VERSION_ATLEAST(2,0,0) typedef SDL_Rect SDL_Rect_mzx; -static inline SDL_Rect_mzx sdl_render_rect(int x, int y, - int w, int h, int full_w, int full_h) +static inline SDL_Rect_mzx sdl_render_rect(int x, int y, int w, int h) { SDL_Rect tmp = { x, y, w, h }; return tmp; @@ -374,29 +372,24 @@ typedef int SDL_RendererLogicalPresentation; #define SDL_SCALEMODE_BEST SDL_ScaleModeBest #define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear #define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest -#define SDL_SetRenderClipRect(r, rect) SDL_RenderSetClipRect(r, rect) -#define SDL_SetRenderLogicalSize(r, w, h) SDL_RenderSetLogicalSize(r, w, h) +#define SDL_SetRenderClipRect(r, rect) (SDL_RenderSetClipRect((r), (rect)) == 0) #if !SDL_VERSION_ATLEAST(2,0,12) typedef int SDL_ScaleMode; #endif -static inline int SDL_SetRenderLogicalPresentation(SDL_Renderer *render, +static inline SDL_bool SDL_SetRenderLogicalPresentation(SDL_Renderer *render, int w, int h, SDL_RendererLogicalPresentation p, SDL_ScaleMode s) { - return SDL_SetRenderLogicalSize(render, w, h); + // Return value 0/-1 -> true/false + return (SDL_bool)(SDL_RenderSetLogicalSize(render, w, h) == 0); } -#endif -#if SDL_VERSION_ATLEAST(2,0,0) -static inline int SDL_RenderTexture_mzx(SDL_Renderer *renderer, SDL_Texture *texture, - const SDL_Rect_mzx *src_rect, const SDL_Rect_mzx *dest_rect) +static inline SDL_bool SDL_RenderTexture(SDL_Renderer *renderer, + SDL_Texture *texture, const SDL_Rect_mzx *src_rect, const SDL_Rect_mzx *dest_rect) { -#if SDL_VERSION_ATLEAST(3,0,0) - return SDL_RenderTexture(renderer, texture, src_rect, dest_rect); -#else - return SDL_RenderCopy(renderer, texture, src_rect, dest_rect); -#endif + // Return value 0/-1 -> true/false + return (SDL_bool)(SDL_RenderCopy(renderer, texture, src_rect, dest_rect) == 0); } #endif @@ -407,7 +400,12 @@ static inline int SDL_RenderTexture_mzx(SDL_Renderer *renderer, SDL_Texture *tex #define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest #define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear #define SDL_DestroySurface(s) SDL_FreeSurface(s) -#define SDL_FillSurfaceRect(s,r,c) SDL_FillRect(s,r,c) + +static inline SDL_bool SDL_FillSurfaceRect(SDL_Surface *surface, SDL_Rect *rect, + Uint32 color) +{ + return (SDL_bool)(SDL_FillRect(surface, rect, color) == 0); +} static inline SDL_bool SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect) { diff --git a/src/event_sdl.c b/src/event_sdl.c index a41e287c4..101e84048 100644 --- a/src/event_sdl.c +++ b/src/event_sdl.c @@ -1800,9 +1800,9 @@ void platform_init_event(void) #endif #if SDL_VERSION_ATLEAST(2,0,0) - SDL_SetGamepadEventsEnabled(true); + SDL_SetGamepadEventsEnabled(1); load_gamecontrollerdb(); #endif - SDL_SetJoystickEventsEnabled(true); + SDL_SetJoystickEventsEnabled(1); } diff --git a/src/graphics.c b/src/graphics.c index df4ef458e..bb4cea2cb 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1488,22 +1488,12 @@ static boolean icon_w_h_constraint(png_uint_32 w, png_uint_32 h) return (w == h) && ((w % 16) == 0) && ((h % 16) == 0); } -#if SDL_VERSION_ATLEAST(2,0,0) static void *sdl_alloc_rgba_surface(png_uint_32 w, png_uint_32 h, png_uint_32 *stride, void **pixels) { +#if SDL_VERSION_ATLEAST(2,0,0) SDL_Surface *s = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_RGBA32); - if(!s) - return NULL; - - *stride = s->pitch; - *pixels = s->pixels; - return s; -} #else -static void *sdl_alloc_rgba_surface(png_uint_32 w, png_uint_32 h, - png_uint_32 *stride, void **pixels) -{ Uint32 rmask, gmask, bmask, amask; SDL_Surface *s; @@ -1520,6 +1510,7 @@ static void *sdl_alloc_rgba_surface(png_uint_32 w, png_uint_32 h, #endif s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask); +#endif if(!s) return NULL; @@ -1527,7 +1518,6 @@ static void *sdl_alloc_rgba_surface(png_uint_32 w, png_uint_32 h, *pixels = s->pixels; return s; } -#endif static SDL_Surface *png_read_icon(const char *name) { diff --git a/src/render_sdl.c b/src/render_sdl.c index 13f442f67..326fe4783 100644 --- a/src/render_sdl.c +++ b/src/render_sdl.c @@ -913,7 +913,6 @@ static void find_texture_format(struct graphics_data *graphics, if(!strcmp(renderer_name, SDL_SOFTWARE_RENDERER)) is_software_renderer = true; - // thanks for the michael mouse API formats = (const uint32_t *)SDL_GetPointerProperty(props, SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL); num_formats = 0; @@ -1168,12 +1167,7 @@ void sdl_set_texture_scale_mode(struct graphics_data *graphics, else mode = SDL_SCALEMODE_LINEAR; -#if SDL_VERSION_ATLEAST(3,0,0) - if(!SDL_SetTextureScaleMode(render_data->texture[texture_id], mode)) -#else - if(SDL_SetTextureScaleMode(render_data->texture[texture_id], mode) < 0) -#endif - warn("Failed to set texture %d scale mode: %s\n", texture_id, SDL_GetError()); + SDL_SetTextureScaleMode(render_data->texture[texture_id], mode); } else warn("Texture %d is null!\n", texture_id); diff --git a/src/render_sdlaccel.c b/src/render_sdlaccel.c index 519e95763..c402a4310 100644 --- a/src/render_sdlaccel.c +++ b/src/render_sdlaccel.c @@ -568,9 +568,8 @@ static void sdlaccel_render_layer(struct graphics_data *graphics, SDL_Texture *chars_tex = render_data->sdl.texture[TEX_CHARS]; SDL_Texture *bg_tex = render_data->sdl.texture[TEX_BACKGROUND]; - SDL_Rect_mzx dest_bg = - sdl_render_rect(offx, offy, w * CHAR_W, h * CHAR_H, TEX_SCREEN_W, TEX_SCREEN_H); - SDL_Rect_mzx src_bg = sdl_render_rect(0, 0, w, h, TEX_BG_W, TEX_BG_H); + SDL_Rect_mzx dest_bg = sdl_render_rect(offx, offy, w * CHAR_W, h * CHAR_H); + SDL_Rect_mzx src_bg = sdl_render_rect(0, 0, w, h); void *_bg; int bg_pitch; @@ -656,7 +655,7 @@ static void sdlaccel_render_layer(struct graphics_data *graphics, } } SDL_UnlockTexture(bg_tex); - SDL_RenderTexture_mzx(renderer, bg_tex, &src_bg, &dest_bg); + SDL_RenderTexture(renderer, bg_tex, &src_bg, &dest_bg); #ifdef RENDER_GEOMETRY @@ -714,11 +713,8 @@ static void sdlaccel_render_cursor(struct graphics_data *graphics, unsigned x, uint8_t *palette = render_data->palette; // Input coordinates are on the character grid. -#if SDL_VERSION_ATLEAST(3,0,0) - SDL_FRect dest = { x * CHAR_W, y * CHAR_H + offset, CHAR_W, lines }; -#else - SDL_Rect dest = { x * CHAR_W, y * CHAR_H + offset, CHAR_W, lines }; -#endif + SDL_Rect_mzx dest = + sdl_render_rect(x * CHAR_W, y * CHAR_H + offset, CHAR_W, lines); SDL_SetRenderDrawBlendMode(render_data->sdl.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawColor(render_data->sdl.renderer, @@ -734,11 +730,7 @@ static void sdlaccel_render_mouse(struct graphics_data *graphics, unsigned x, struct sdlaccel_render_data *render_data = graphics->render_data; // Input coordinates are pixel values. -#if SDL_VERSION_ATLEAST(3,0,0) - SDL_FRect dest = { x, y, w, h }; -#else - SDL_Rect dest = { x, y, w, h }; -#endif + SDL_Rect_mzx dest = sdl_render_rect(x, y, w, h); /* There is no preset inversion blend mode, so make a custom blend mode. * Lower SDL versions should simply fall back to drawing a white rectangle. @@ -769,8 +761,7 @@ static void sdlaccel_sync_screen(struct graphics_data *graphics, SDL_Rect_mzx src; SDL_Rect_mzx dest; - src = sdl_render_rect(0, 0, SCREEN_PIX_W, SCREEN_PIX_H, - TEX_SCREEN_W, TEX_SCREEN_H); + src = sdl_render_rect(0, 0, SCREEN_PIX_W, SCREEN_PIX_H); dest.x = window->viewport_x; dest.y = window->viewport_y; @@ -778,7 +769,7 @@ static void sdlaccel_sync_screen(struct graphics_data *graphics, dest.h = window->viewport_height; SDL_SetRenderTarget(renderer, NULL); - SDL_RenderTexture_mzx(renderer, screen_tex, &src, &dest); + SDL_RenderTexture(renderer, screen_tex, &src, &dest); SDL_RenderPresent(renderer); diff --git a/src/render_softscale.c b/src/render_softscale.c index bb0ee9466..59bbada12 100644 --- a/src/render_softscale.c +++ b/src/render_softscale.c @@ -270,7 +270,7 @@ static void softscale_sync_screen(struct graphics_data *graphics, SDL_Rect_mzx dest_rect; src_rect = sdl_render_rect(texture_rect->x, texture_rect->y, - texture_rect->w, texture_rect->h, render_data->texture_width, SCREEN_PIX_H); + texture_rect->w, texture_rect->h); dest_rect.x = window->viewport_x; dest_rect.y = window->viewport_y; @@ -282,7 +282,7 @@ static void softscale_sync_screen(struct graphics_data *graphics, SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(renderer); - SDL_RenderTexture_mzx(renderer, texture, &src_rect, &dest_rect); + SDL_RenderTexture(renderer, texture, &src_rect, &dest_rect); SDL_RenderPresent(renderer); } diff --git a/unit/configure.cpp b/unit/configure.cpp index 74c5594c0..ba259eda7 100644 --- a/unit/configure.cpp +++ b/unit/configure.cpp @@ -32,7 +32,7 @@ #ifdef CONFIG_SDL #include "../src/SDLmzx.h" -#undef IGNORE /* wtf Windows? */ +#undef IGNORE /* Windows defines this for some reason... */ #endif #ifdef CONFIG_EDITOR