From 5348a15b75333f37f7f7c83f3dca31eece092824 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 11 Feb 2016 14:07:01 +0200 Subject: [PATCH] Added option to control dynamic loading of OpenAL Dynamic loading is enabled by default, set DYN_OPENAL to OFF to link with static or dynamic library # Conflicts: # src/sound/oalsound.cpp # src/sound/oalsound.h --- src/CMakeLists.txt | 21 ++++++++++++++++----- src/sound/oalload.h | 2 +- src/sound/oalsound.cpp | 32 +++++++++++++++++--------------- src/sound/oalsound.h | 2 ++ 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 84d6f06b9..93a165fb1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,7 @@ if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) endif() option( DYN_FLUIDSYNTH "Dynamically load fluidsynth" ON ) +option( DYN_OPENAL "Dynamically load OpenAL" ON ) if( APPLE ) option( OSX_COCOA_BACKEND "Use native Cocoa backend instead of SDL" ON ) @@ -226,13 +227,23 @@ endif() if( NOT NO_OPENAL ) - find_package( OpenAL ) + find_package( OpenAL ) mark_as_advanced(CLEAR OPENAL_INCLUDE_DIR) - if( OPENAL_INCLUDE_DIR ) - include_directories( ${OPENAL_INCLUDE_DIR} ) - else() + if( OPENAL_INCLUDE_DIR ) + include_directories( ${OPENAL_INCLUDE_DIR} ) + if( DYN_OPENAL ) + add_definitions( -DDYN_OPENAL ) + else() + mark_as_advanced(CLEAR OPENAL_LIBRARY) + if( OPENAL_LIBRARY ) + set( ZDOOM_LIBS ${OPENAL_LIBRARY} ${ZDOOM_LIBS} ) + else() + set( NO_OPENAL ON ) + endif() + endif() + else() set( NO_OPENAL ON ) - endif() + endif() endif() if( NOT NO_FMOD ) diff --git a/src/sound/oalload.h b/src/sound/oalload.h index 3cee30d58..ca02d25d9 100644 --- a/src/sound/oalload.h +++ b/src/sound/oalload.h @@ -1,7 +1,7 @@ #ifndef OALDEF_H #define OALDEF_H -#ifndef NO_OPENAL +#if !defined NO_OPENAL && defined DYN_OPENAL #ifndef _WIN32 typedef void* FARPROC; diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 8ac41a04b..6dd204c86 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -83,6 +83,8 @@ bool IsOpenALPresent() { #ifdef NO_OPENAL return false; +#elif !defined DYN_OPENAL + return true; #else static bool cached_result = false; static bool done = false; @@ -425,10 +427,10 @@ public: virtual bool IsEnded() { return !Playing.load(); - } + } virtual FString GetStats() - { + { FString stats; size_t pos, len; ALfloat volume; @@ -1538,24 +1540,24 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener else { alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); - alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); - } + alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); + } } else { FVector3 dir = pos; if(AL.EXT_SOURCE_RADIUS) alSourcef(source, AL_SOURCE_RADIUS, (chanflags&SNDF_AREA) ? AREA_SOUND_RADIUS : 0.f); - else if((chanflags&SNDF_AREA) && dist_sqr < AREA_SOUND_RADIUS*AREA_SOUND_RADIUS) - { + else if((chanflags&SNDF_AREA) && dist_sqr < AREA_SOUND_RADIUS*AREA_SOUND_RADIUS) + { dir -= listener->position; - float mindist = rolloff->MinDistance/distscale; - FVector3 amb(0.f, !(dir.Y>=0.f) ? -mindist : mindist, 0.f); - float a = sqrtf(dist_sqr) / AREA_SOUND_RADIUS; - dir = amb + (dir-amb)*a; + float mindist = rolloff->MinDistance/distscale; + FVector3 amb(0.f, !(dir.Y>=0.f) ? -mindist : mindist, 0.f); + float a = sqrtf(dist_sqr) / AREA_SOUND_RADIUS; + dir = amb + (dir-amb)*a; - dir += listener->position; + dir += listener->position; } if(dist_sqr < (0.0004f*0.0004f)) { @@ -1566,8 +1568,8 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener else { alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); - alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); - } + alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); + } } alSource3f(source, AL_VELOCITY, vel[0], vel[1], -vel[2]); alSource3f(source, AL_DIRECTION, 0.f, 0.f, 0.f); @@ -1799,7 +1801,7 @@ void OpenALSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FISoundCh { float gain = GetRolloff(&chan->Rolloff, sqrtf(chan->DistanceSqr)*chan->DistanceScale); dir.MakeResize((gain > 0.00001f) ? 1.f/gain : 100000.f); - } + } } else if(!AL.EXT_SOURCE_RADIUS && areasound && chan->DistanceSqr < AREA_SOUND_RADIUS*AREA_SOUND_RADIUS) @@ -1822,7 +1824,7 @@ void OpenALSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FISoundCh else { alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); - alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); + alSource3f(source, AL_POSITION, dir[0], dir[1], -dir[2]); } alSource3f(source, AL_VELOCITY, vel[0], vel[1], -vel[2]); getALError(); diff --git a/src/sound/oalsound.h b/src/sound/oalsound.h index 09fe64d92..d69e2e367 100644 --- a/src/sound/oalsound.h +++ b/src/sound/oalsound.h @@ -12,7 +12,9 @@ #ifndef NO_OPENAL +#ifdef DYN_OPENAL #define AL_NO_PROTOTYPES +#endif // DYN_OPENAL #include "al.h" #include "alc.h"