aboutsummaryrefslogtreecommitdiff
path: root/src/sfx
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-02-20 19:04:21 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:21 +0200
commit4765653cb3af905a9b20f1e5f2277e50d801c43b (patch)
tree9c9f914e5ea9b19f2312cd43221df37d19dec2f3 /src/sfx
parentc9754ac4300abad20d942ad18bc5bf611a0b3a2e (diff)
downloadjancity-4765653cb3af905a9b20f1e5f2277e50d801c43b.tar.gz
Add metadata header to media files
The following properties are supported: - Sound: "loop". Must be either 0 or 1 - Images: "transparent". Must be either 0 or 1 These headers are only used for non-PS1 builds, since .TIM and .VAG files do already implement such information.
Diffstat (limited to 'src/sfx')
-rw-r--r--src/sfx/CMakeLists.txt2
-rw-r--r--src/sfx/sdl-1.2/inc/sfx/port.h11
-rw-r--r--src/sfx/sdl-1.2/src/sound.c21
3 files changed, 31 insertions, 3 deletions
diff --git a/src/sfx/CMakeLists.txt b/src/sfx/CMakeLists.txt
index 3453d2e..6b774fd 100644
--- a/src/sfx/CMakeLists.txt
+++ b/src/sfx/CMakeLists.txt
@@ -10,7 +10,7 @@ elseif(SDL1_2_BUILD)
"sdl-1.2/src/sound.c")
set(inc ${inc} "sdl-1.2/inc")
set(deps ${deps} SDL_mixer)
- set(privdeps ${privdeps} SDL)
+ set(privdeps ${privdeps} SDL header)
endif()
add_library(sfx ${src})
diff --git a/src/sfx/sdl-1.2/inc/sfx/port.h b/src/sfx/sdl-1.2/inc/sfx/port.h
index d8418f7..2279229 100644
--- a/src/sfx/sdl-1.2/inc/sfx/port.h
+++ b/src/sfx/sdl-1.2/inc/sfx/port.h
@@ -2,10 +2,21 @@
#define SFX_SDL1_2_H
#include <SDL/SDL_mixer.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
struct sound
{
Mix_Chunk *chunk;
+ bool loop;
};
+#ifdef __cplusplus
+}
+#endif
+
#endif /* SFX_SDL1_2_H */
diff --git a/src/sfx/sdl-1.2/src/sound.c b/src/sfx/sdl-1.2/src/sound.c
index e843923..e3e9a8b 100644
--- a/src/sfx/sdl-1.2/src/sound.c
+++ b/src/sfx/sdl-1.2/src/sound.c
@@ -1,5 +1,6 @@
#include <sfx.h>
#include <sfx/port.h>
+#include <header.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
@@ -12,13 +13,13 @@ void sfx_free(struct sound *const s)
int sfx_play(const struct sound *const s)
{
- if (Mix_PlayChannel(-1, s->chunk, 0) < 0)
+ if (Mix_PlayChannel(-1, s->chunk, s->loop ? -1 : 0) < 0)
return -1;
return 0;
}
-int sfx_sound_from_fp(struct sound *const s, FILE *const f)
+static int load_data(struct sound *const s, FILE *const f)
{
int ret = -1;
SDL_RWops *const ops = SDL_RWFromFP(f, 0);
@@ -41,6 +42,22 @@ end:
return ret;
}
+static int load_header(struct sound *const s, FILE *const f)
+{
+ if (header_load_bool(f, "loop", &s->loop))
+ return -1;
+
+ return 0;
+}
+
+int sfx_sound_from_fp(struct sound *const s, FILE *const f)
+{
+ if (load_header(s, f) || load_data(s, f))
+ return -1;
+
+ return 0;
+}
+
void sfx_deinit(void)
{
Mix_CloseAudio();