diff options
| -rw-r--r-- | src/audio.c | 26 | ||||
| -rw-r--r-- | src/input.c | 21 | ||||
| -rw-r--r-- | src/scale.c | 10 |
3 files changed, 47 insertions, 10 deletions
diff --git a/src/audio.c b/src/audio.c index b2ba701..56e20dd 100644 --- a/src/audio.c +++ b/src/audio.c @@ -1,4 +1,5 @@ #include <SDL3/SDL_log.h> +#include <SDL3/SDL_version.h> #include "audio.h" @@ -177,16 +178,12 @@ cleanup: static void data_complete(void *userdata, const void *buf, int buflen) { (void)buflen; - struct pw_audio *audio = userdata; - for (size_t i = 0; i < SDL_arraysize(audio->buffers); ++i) { - struct pw_audio_buffer *b = audio->buffers + i; - if (b->data == buf && b->inuse) { - b->inuse = false; - return; - } + struct pw_audio_buffer *buffer = userdata; + if (buffer->data != buf || !buffer->inuse) { + SDL_LogWarn(0, "unexpected audio buffer completion"); + return; } - - SDL_LogWarn(0, "could not find completed in-use buffer"); + buffer->inuse = false; } bool pw_audio_unlock(struct pw_audio *audio) { @@ -209,8 +206,17 @@ bool pw_audio_unlock(struct pw_audio *audio) { } size_t sz = len * sizeof(*buffer->data); + +#if SDL_VERSION_ATLEAST(3, 4, 0) ok = SDL_PutAudioStreamDataNoCopy(audio->stream, buffer->data, sz, - data_complete, audio); + data_complete, buffer); +#else + ok = SDL_PutAudioStreamData(audio->stream, buffer->data, sz); + if (ok) { + data_complete(buffer, buffer->data, sz); + } +#endif + if (!ok) { buffer->inuse = false; } diff --git a/src/input.c b/src/input.c index 0cc2f78..f85c63c 100644 --- a/src/input.c +++ b/src/input.c @@ -1,6 +1,7 @@ #include <SDL3/SDL_clipboard.h> #include <SDL3/SDL_log.h> #include <SDL3/SDL_mouse.h> +#include <SDL3/SDL_version.h> #include "input.h" @@ -297,10 +298,30 @@ static int32_t saturating_add(int32_t a, int32_t b) { } static bool handle_wheel(struct pw_input *input, SDL_MouseWheelEvent *wheel) { +#if SDL_VERSION_ATLEAST(3, 2, 12) input->mouse.wheel.dx = saturating_add(input->mouse.wheel.dx, wheel->integer_x); input->mouse.wheel.dy = saturating_add(input->mouse.wheel.dy, wheel->integer_y); +#else + // We approximate wheel movement for older SDL versions that do not support + // the integer event values. This is slightly wrong (as we lose fractional + // movement across frames), but good enough: this will likely only affect + // homebrew versions with older SDL 3 ports that don't have mouse wheels + // anyway. If this becomes a problem, we can change mouse wheel deltas to + // be floats and report full ticks (similar to how we handle relative mouse + // positions). + if (!SDL_isnanf(wheel->x)) { + input->mouse.wheel.dx = saturating_add( + input->mouse.wheel.dx, + (int32_t)SDL_clamp(wheel->x, -PW_MAX_SAFE_INT, PW_MAX_SAFE_INT)); + } + if (!SDL_isnanf(wheel->y)) { + input->mouse.wheel.dy = saturating_add( + input->mouse.wheel.dy, + (int32_t)SDL_clamp(wheel->y, -PW_MAX_SAFE_INT, PW_MAX_SAFE_INT)); + } +#endif return true; } diff --git a/src/scale.c b/src/scale.c index 637db86..bf6addb 100644 --- a/src/scale.c +++ b/src/scale.c @@ -1,3 +1,5 @@ +#include <SDL3/SDL_version.h> + #include "scale.h" static bool is_safei(int i) { @@ -43,7 +45,11 @@ static SDL_ScaleMode scale_fill(float twf, float thf, int rw, int rh, target->x = x; target->y = y; +#if SDL_VERSION_ATLEAST(3, 4, 0) return SDL_SCALEMODE_PIXELART; +#else + return SDL_SCALEMODE_NEAREST; +#endif } static SDL_ScaleMode scale_stretch(float twf, float thf, int rw, int rh, @@ -56,7 +62,11 @@ static SDL_ScaleMode scale_stretch(float twf, float thf, int rw, int rh, target->x = 0.; target->y = 0.; +#if SDL_VERSION_ATLEAST(3, 4, 0) return SDL_SCALEMODE_PIXELART; +#else + return SDL_SCALEMODE_NEAREST; +#endif } bool pw_scale(enum pw_scale_mode mode, SDL_Texture *texture, |
