From b5d572d66abb4455f9f955da4642b11d63a2a4b0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Oct 2023 12:24:58 +0300 Subject: [PATCH 52/52] Add SDL3_mixer support See osdn #48777 Signed-off-by: Marko Lindqvist --- client/audio_sdl.c | 22 +++++++++++++--- doc/INSTALL.meson | 2 +- gen_headers/meson_fc_config.h.in | 5 +++- meson.build | 45 +++++++++++++++++++++++++++++--- meson_options.txt | 2 +- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/client/audio_sdl.c b/client/audio_sdl.c index 51571d8f01..6c33875c71 100644 --- a/client/audio_sdl.c +++ b/client/audio_sdl.c @@ -17,6 +17,10 @@ #include +#ifdef AUDIO_SDL3 +#include +#include +#else #ifdef SDL2_PLAIN_INCLUDE #include #include @@ -24,6 +28,7 @@ #include #include #endif /* SDL2_PLAIN_INCLUDE */ +#endif /* AUDIO_SDL3 */ /* utility */ #include "log.h" @@ -204,6 +209,9 @@ static void quit_sdl_audio(void) **************************************************************************/ static int init_sdl_audio(void) { +#ifdef AUDIO_SDL3 + return SDL_Init(SDL_INIT_AUDIO); +#else /* AUDIO_SDL3 */ SDL_SetHint(SDL_HINT_AUDIO_RESAMPLING_MODE, "medium"); if (SDL_WasInit(SDL_INIT_VIDEO)) { @@ -211,6 +219,7 @@ static int init_sdl_audio(void) } else { return SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE); } +#endif /* AUDIO_SDL3 */ } /**********************************************************************//** @@ -243,17 +252,22 @@ static void sdl_audio_shutdown(struct audio_plugin *self) **************************************************************************/ static bool sdl_audio_init(struct audio_plugin *self) { - /* Initialize variables */ - const int audio_rate = MIX_DEFAULT_FREQUENCY; - const int audio_format = MIX_DEFAULT_FORMAT; - const int audio_channels = 2; int i; if (init_sdl_audio() < 0) { return FALSE; } +#ifdef AUDIO_SDL3 + if (Mix_OpenAudio(0, NULL) < 0) { +#else /* AUDIO_SDL3 */ + /* Initialize variables */ + const int audio_rate = MIX_DEFAULT_FREQUENCY; + const int audio_format = MIX_DEFAULT_FORMAT; + const int audio_channels = 2; + if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, buf_size) < 0) { +#endif /* AUDIO_SDL3 */ log_error("Error calling Mix_OpenAudio"); /* Try something else */ diff --git a/doc/INSTALL.meson b/doc/INSTALL.meson index 98636a6e01..f47502bd06 100644 --- a/doc/INSTALL.meson +++ b/doc/INSTALL.meson @@ -147,7 +147,7 @@ readline ('try'/'true'/'false') Whether to enable readline functionality on server. The default is 'try' to enable it if suitable readline found. -audio ('none'/'sdl2'): +audio ('none'/'sdl2'/'sdl3'): What kind of sound support should be built to the clients. Defaults to sdl2. tools (array): diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in index 1200aa4973..9d1f90054a 100644 --- a/gen_headers/meson_fc_config.h.in +++ b/gen_headers/meson_fc_config.h.in @@ -62,9 +62,12 @@ /* Produce debug version */ #mesondefine FREECIV_DEBUG -/* enable audio */ +/* Enable audio */ #mesondefine AUDIO_SDL +/* Use SDL3_mixer */ +#mesondefine AUDIO_SDL3 + /* Native language support enabled */ #mesondefine ENABLE_NLS diff --git a/meson.build b/meson.build index f780cd10de..0aff6222a7 100644 --- a/meson.build +++ b/meson.build @@ -802,6 +802,38 @@ if get_option('audio') == 'sdl2' or get_option('clients').contains('sdl2') endif endif +if get_option('audio') == 'sdl3' or get_option('clients').contains('sdl3') + if host_system == 'windows' + sdl3main_dep = [c_compiler.find_library('mingw32', dirs: cross_lib_path), + c_compiler.find_library('SDL3main', dirs: cross_lib_path), + c_compiler.find_library('SDL3', dirs: cross_lib_path)] + else + if emscripten + emscripten_sdl3_args = [ + '-s', 'USE_SDL=3' + ] + + if get_option('audio') == 'sdl3' + emscripten_sdl3_args += [ '-s', 'USE_SDL_MIXER=3' ] + endif + + if get_option('clients').contains('sdl3') + emscripten_sdl3_args += [ + '-s', 'USE_SDL_IMAGE=3', + '-s', 'USE_SDL_TTF=3', + '-s', 'USE_SDL_GFX=3' + ] + endif + + add_global_arguments(emscripten_sdl3_args, language: ['c', 'cpp']) + add_global_link_arguments(emscripten_sdl3_args, language: ['c', 'cpp']) + sdl3main_dep = [] + else + sdl3main_dep = [c_compiler.find_library('SDL3', dirs: cross_lib_path)] + endif + endif +endif + if get_option('clients').contains('sdl3') if host_system == 'windows' sdl3main_dep = [c_compiler.find_library('mingw32', dirs: cross_lib_path), @@ -810,13 +842,13 @@ if get_option('clients').contains('sdl3') else if emscripten emscripten_sdl3_args = [ - '-s', 'USE_SDL=2' + '-s', 'USE_SDL=3' ] emscripten_sdl3_args += [ - '-s', 'USE_SDL_IMAGE=2', - '-s', 'USE_SDL_TTF=2', - '-s', 'USE_SDL_GFX=2' + '-s', 'USE_SDL_IMAGE=3', + '-s', 'USE_SDL_TTF=3', + '-s', 'USE_SDL_GFX=3' ] add_global_arguments(emscripten_sdl3_args, language: ['c', 'cpp']) @@ -845,6 +877,11 @@ if get_option('audio') != 'none' if emscripten audio_dep = [] + elif get_option('audio') == 'sdl3' + audio_sdl3_dep = c_compiler.find_library('SDL3_mixer', + dirs: cross_lib_path) + audio_dep = [sdl3main_dep, audio_sdl3_dep] + priv_conf_data.set('AUDIO_SDL3', 1) else audio_sdl2_dep = c_compiler.find_library('SDL2_mixer', dirs: cross_lib_path) diff --git a/meson_options.txt b/meson_options.txt index ac65a3f727..3ec70cfee9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -47,7 +47,7 @@ option('readline', option('audio', type: 'combo', - choices: ['none', 'sdl2'], + choices: ['none', 'sdl2', 'sdl3'], value: 'sdl2', description: 'Sound support type to build') -- 2.40.1