aboutsummaryrefslogtreecommitdiff
path: root/src/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl')
-rw-r--r--src/sdl/action.c2
-rw-r--r--src/sdl/draw.c2
-rw-r--r--src/sdl/sounds.c47
-rw-r--r--src/sdl/sounds.h10
4 files changed, 59 insertions, 2 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c
index 18badc1..bc0cf89 100644
--- a/src/sdl/action.c
+++ b/src/sdl/action.c
@@ -125,7 +125,7 @@ get_action(
};
break;
case SOLVE_EVENT_FAIL:
- warn("solve failed: %s", ev->user.data2 ? ev->user.data2 : "unknown error");
+ warn("solve failed: %s", ev->user.data2 ? (char*) ev->user.data2 : "unknown error");
return (action_t) { .type = ACTION_SOLVE_EVENT_FAIL };
break;
case SOLVE_EVENT_DONE:
diff --git a/src/sdl/draw.c b/src/sdl/draw.c
index 37d9ba2..d95e83f 100644
--- a/src/sdl/draw.c
+++ b/src/sdl/draw.c
@@ -291,7 +291,7 @@ draw_solve_moves_text(
char buf[1024];
// fill buffer
- snprintf(buf, sizeof(buf), " %lu attempts ", draw_ctx->solve_num_steps);
+ snprintf(buf, sizeof(buf), " %u attempts ", (unsigned int) draw_ctx->solve_num_steps);
// draw text
draw_text(draw_ctx->renderer, draw_ctx->font, style, buf);
diff --git a/src/sdl/sounds.c b/src/sdl/sounds.c
new file mode 100644
index 0000000..956229c
--- /dev/null
+++ b/src/sdl/sounds.c
@@ -0,0 +1,47 @@
+#include <SDL.h>
+#include "util.h"
+#include "assets.h"
+#include "sounds.h"
+
+#define SOUND_OFS(asset_id) ((asset_id) - ASSET_SOUND_FIRST - 1)
+
+void
+sounds_init(
+ Mix_Chunk ** const sounds
+) {
+ for (asset_id_t id = ASSET_SOUND_FIRST + 1; id < ASSET_SOUND_LAST; id++) {
+ // get asset
+ const asset_t * const asset = asset_get(id);
+
+ // create rwops
+ SDL_RWops *rw = SDL_RWFromConstMem(asset->buf, asset->len);
+ if (!rw) {
+ die("SDL_RWFromConstMem(): %s", SDL_GetError());
+ }
+
+ // load chunk
+ Mix_Chunk *chunk = Mix_LoadWAV_RW(rw, 1);
+ if (!chunk) {
+ die("Mix_LoadWAV_RW(): %s", Mix_GetError());
+ }
+
+ // add to list of sounds
+ sounds[SOUND_OFS(id)] = chunk;
+ }
+}
+
+void
+sound_play(
+ Mix_Chunk ** const sounds,
+ const asset_id_t id
+) {
+ // check ID
+ if (id <= ASSET_SOUND_FIRST || id >= ASSET_SOUND_LAST) {
+ die("invalid sound asset id: %u", id);
+ }
+
+ // play sound
+ if (Mix_PlayChannel(-1, sounds[SOUND_OFS(id)], 0)) {
+ die("Mix_PlayChannel(): %s", Mix_GetError());
+ }
+}
diff --git a/src/sdl/sounds.h b/src/sdl/sounds.h
new file mode 100644
index 0000000..3b74aff
--- /dev/null
+++ b/src/sdl/sounds.h
@@ -0,0 +1,10 @@
+#ifndef SOUNDS_H
+#define SOUNDS_H
+
+#include <SDL_mixer.h>
+#include "assets.h"
+
+void sounds_init(Mix_Chunk ** const);
+void sound_play(Mix_Chunk ** const sounds, const asset_id_t);
+
+#endif /* SOUNDS_H */