diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-28 15:28:33 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-28 15:28:33 +0100 |
| commit | 756750924357cae5ea9df48af3f55e17a2fd90e2 (patch) | |
| tree | 7283448ffbe14bfcb924b2fb513dd4ee2a957e69 /src/audio.c | |
| parent | 85db6937aa2da1605d299e9b3327f10d2dfc889e (diff) | |
Fix Relative Mouse Motion
We do some fixes, namely fixing relative mouse motion which worked
very differently compared to mouse motion outside of pointer lock.
This appears to be something built in to PICO-8 itself (as evident by
keeping track of `STAT(32-33,38-39)` under pointer lock: PICO-8 scales
relative mouse motion by a factor of `.25` before adding to the
absolute mouse position.
Additionally, we support running PICO-w on systems with no audio
playback.
Diffstat (limited to 'src/audio.c')
| -rw-r--r-- | src/audio.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/audio.c b/src/audio.c index cbe5be3..b2ba701 100644 --- a/src/audio.c +++ b/src/audio.c @@ -3,6 +3,11 @@ #include "audio.h" struct pw_audio *pw_audio_init(void) { + struct pw_audio *audio = SDL_calloc(1, sizeof(*audio)); + if (!audio) { + return NULL; + } + // PICO-8 exposes a `_mix(len0, len1)` function for copying audio data // from an internal buffer to the host's audio context. From the // Emscripten bundle, we see a few things: @@ -20,19 +25,12 @@ struct pw_audio *pw_audio_init(void) { .channels = 1, .freq = 22050, }; - SDL_AudioStream *stream = SDL_OpenAudioDeviceStream( - SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL); - if (!stream) { - return NULL; - } - - struct pw_audio *audio = SDL_calloc(1, sizeof(*audio)); - if (!audio) { - SDL_DestroyAudioStream(stream); - return NULL; + audio->stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, + &spec, NULL, NULL); + if (!audio->stream) { + SDL_LogWarn(0, "starting without audio"); } - audio->stream = stream; return audio; } @@ -196,8 +194,8 @@ bool pw_audio_unlock(struct pw_audio *audio) { return SDL_InvalidParamError("audio"); } - size_t i = audio->lock / PW_AUDIO_BUFFER_MAX; - size_t len = audio->lock % PW_AUDIO_BUFFER_MAX; + size_t i = (audio->lock - 1) / PW_AUDIO_BUFFER_MAX; + size_t len = (audio->lock - 1) % PW_AUDIO_BUFFER_MAX + 1; if (!SDL_LockAudioStream(audio->stream)) { return false; |
