diff --git a/CMakeLists.txt b/CMakeLists.txt index 69ab279f9b6ce..ef9c2168502d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -366,14 +366,6 @@ if (CURSES) endif () if (SOUND) - # You need TILES to be able to use SOUND - if (NOT TILES) - message(FATAL_ERROR - "You must enable graphical support with -DTILES=1 \ - to be able to enable sound support. \ - See doc/COMPILING/COMPILING-CMAKE.md for details and more info.") - endif () - # Sound requires SDL_mixer library message(STATUS "Searching for SDL2_mixer library --") find_package(SDL2_mixer) diff --git a/Makefile b/Makefile index 428df64b265d0..62bacd6b9ceb1 100644 --- a/Makefile +++ b/Makefile @@ -835,9 +835,6 @@ else endif # TILES ifeq ($(SOUND), 1) - ifneq ($(TILES),1) - $(error "SOUND=1 only works with TILES=1") - endif ifeq ($(NATIVE),osx) ifndef FRAMEWORK # libsdl build ifeq ($(MACPORTS), 1) @@ -1271,7 +1268,6 @@ ifdef LANGUAGES mkdir -p $(APPRESOURCESDIR)/lang/mo/ cp -pR lang/mo/* $(APPRESOURCESDIR)/lang/mo/ endif -ifeq ($(TILES), 1) ifeq ($(SOUND), 1) cp -R data/sound $(APPDATADIR) endif # ifeq ($(SOUND), 1) @@ -1284,7 +1280,6 @@ ifeq ($(SOUND), 1) cp -R $(FRAMEWORKSDIR)/SDL2_mixer.framework $(APPRESOURCESDIR)/ endif # ifeq ($(SOUND), 1) endif # ifdef FRAMEWORK -endif # ifdef TILES dylibbundler -of -b -x $(APPRESOURCESDIR)/$(APPTARGET) -d $(APPRESOURCESDIR)/ -p @executable_path/ dmgdistclean: diff --git a/doc/COMPILING/COMPILING.md b/doc/COMPILING/COMPILING.md index ff9f5cfd303e3..b8cb2c50a1c42 100644 --- a/doc/COMPILING/COMPILING.md +++ b/doc/COMPILING/COMPILING.md @@ -79,7 +79,7 @@ Given you're building from source you have a number of choices to make: * `RELEASE=1` - without this you'll get a debug build (see note below) * `LTO=1` - enables link-time optimization with GCC/Clang * `TILES=1` - with this you'll get the tiles version, without it the curses version - * `SOUND=1` - if you want sound; this requires `TILES=1` + * `SOUND=1` - if you want sound * `LOCALIZE=0` - this disables localizations so `gettext` is not needed * `CLANG=1` - use Clang instead of GCC * `CCACHE=1` - use ccache diff --git a/src/main.cpp b/src/main.cpp index fb9dce428c37a..45ffcb8739414 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,7 @@ class ui_adaptor; -#if defined(TILES) +#if defined(TILES) || defined(SDL_SOUND) # if defined(_MSC_VER) && defined(USE_VCPKG) # include # else @@ -738,7 +738,7 @@ int main( int argc, const char *argv[] ) DebugLog( D_INFO, DC_ALL ) << "[main] C locale set to " << setlocale( LC_ALL, nullptr ); DebugLog( D_INFO, DC_ALL ) << "[main] C++ locale set to " << std::locale().name(); -#if defined(TILES) +#if defined(TILES) || defined(SDL_SOUND) SDL_version compiled; SDL_VERSION( &compiled ); DebugLog( D_INFO, DC_ALL ) << "SDL version used during compile is " diff --git a/src/ncurses_def.cpp b/src/ncurses_def.cpp index de0eac18e7a7c..f69d8339451dc 100644 --- a/src/ncurses_def.cpp +++ b/src/ncurses_def.cpp @@ -41,6 +41,10 @@ #include #endif +#if defined(SDL_SOUND) +#include "sdlsound.h" +#endif + std::unique_ptr imclient; static void curses_check_result( const int result, const int expected, const char *const /*name*/ ) @@ -361,6 +365,14 @@ void catacurses::init_interface() // The below line tries to force the mouse pointer events to be turned on anyway. ImTui misbehaves without them. printf( "\033[?1003h\n" ); #endif + +#if defined(SDL_SOUND) + initSDLAudioOnly(); + init_sound(); + if( sound_init_success ) { + load_soundset(); + } +#endif } bool catacurses::supports_256_colors() diff --git a/src/sdl_wrappers.cpp b/src/sdl_wrappers.cpp index 2bfd7bb5ef533..34e36edb3f6ee 100644 --- a/src/sdl_wrappers.cpp +++ b/src/sdl_wrappers.cpp @@ -1,4 +1,4 @@ -#if defined(TILES) +#if defined(TILES) || defined(SDL_SOUND) #include "sdl_wrappers.h" @@ -35,6 +35,8 @@ void throwErrorIf( const bool condition, const char *const message ) throw std::runtime_error( std::string( message ) + ": " + SDL_GetError() ); } +#if defined(TILES) + void RenderCopy( const SDL_Renderer_Ptr &renderer, const SDL_Texture_Ptr &texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect ) { @@ -191,5 +193,5 @@ SDL_Surface_Ptr CreateRGBSurface( const Uint32 flags, const int width, const int throwErrorIf( !surface, "Failed to create surface" ); return surface; } - -#endif +#endif // defined(TILES) +#endif // defined(TILES) || defined(SDL_SOUND) diff --git a/src/sdlsound.cpp b/src/sdlsound.cpp index 4c925d50a7438..73fb9739d6106 100644 --- a/src/sdlsound.cpp +++ b/src/sdlsound.cpp @@ -912,4 +912,14 @@ void load_soundset() } } +// capitalized to mirror cata_tiles::InitSDL() +void initSDLAudioOnly() +{ + const int ret = SDL_Init( SDL_INIT_AUDIO ); + throwErrorIf( ret != 0, "SDL_Init failed" ); + if( atexit( SDL_Quit ) ) { + debugmsg( "atexit failed to register SDL_Quit" ); + } +} + #endif diff --git a/src/sdlsound.h b/src/sdlsound.h index 8e6d74b642e38..4a42a70b0113b 100644 --- a/src/sdlsound.h +++ b/src/sdlsound.h @@ -9,6 +9,7 @@ * Attempt to initialize an audio device. Returns false if initialization fails. */ bool init_sound(); +void initSDLAudioOnly(); void shutdown_sound(); void play_music( const std::string &playlist ); void stop_music(); diff --git a/src/wincurse.cpp b/src/wincurse.cpp index 97d34fa537d5e..ef0fac7120df7 100644 --- a/src/wincurse.cpp +++ b/src/wincurse.cpp @@ -30,6 +30,11 @@ #include "ui_manager.h" #include "wcwidth.h" + +#if defined(SDL_SOUND) +#include "sdlsound.h" +#endif + //*********************************** //Globals * //*********************************** @@ -654,6 +659,14 @@ void catacurses::init_interface() //newwin calls `new WINDOW`, and that will throw, but not return nullptr. initialized = true; + +#if defined(SDL_SOUND) + initSDLAudioOnly(); + init_sound(); + if( sound_init_success ) { + load_soundset(); + } +#endif } bool catacurses::supports_256_colors()