From e6a113b32e36ba1111b15a5d258272d34bacf455 Mon Sep 17 00:00:00 2001 From: Alexander Pavlov Date: Fri, 30 May 2025 16:34:07 +0300 Subject: [PATCH] Add games/idtech4a-engine --- FINISHED | 1 + games/idtech4a-engine/Makefile | 78 + games/idtech4a-engine/distinfo | 2 + .../patches/patch-CMakeLists_txt | 56 + .../idtech4a-engine/patches/patch-SConstruct | 228 ++ .../patches/patch-externlibs_miniz_miniz_c | 12 + .../patches/patch-framework_BuildDefines_h | 28 + .../patches/patch-framework_Common_cpp | 49 + .../patches/patch-framework_Session_menu_cpp | 25 + .../patches/patch-idlib_Lib_cpp | 48 + .../patches/patch-idlib_precompiled_h | 12 + .../patches/patch-sound_efxlib_h | 66 + .../patches/patch-sound_snd_cache_cpp | 900 ++++++ .../patches/patch-sound_snd_decoder_cpp | 951 ++++++ .../patches/patch-sound_snd_efxfile_cpp | 568 ++++ .../patches/patch-sound_snd_emitter_cpp | 1460 +++++++++ .../patches/patch-sound_snd_local_h | 1290 ++++++++ .../patches/patch-sound_snd_shader_cpp | 607 ++++ .../patches/patch-sound_snd_system_cpp | 1979 ++++++++++++ .../patches/patch-sound_snd_wavefile_cpp | 426 +++ .../patches/patch-sound_snd_world_cpp | 2812 +++++++++++++++++ .../patches/patch-sound_sound_h | 387 +++ .../patches/patch-sys_cmake_FindOGG_cmake | 87 + .../patch-sys_cmake_FindVorbisFile_cmake | 95 + .../patches/patch-sys_cmake_FindVorbis_cmake | 87 + .../patches/patch-sys_linux_main_cpp | 529 ++++ .../patches/patch-sys_linux_sdlmain_cpp | 203 ++ .../patches/patch-sys_linux_sound_cpp | 12 + .../patches/patch-sys_linux_sound_h | 11 + .../patches/patch-sys_scons_SConscript_core | 186 ++ .../patches/patch-sys_scons_SConscript_idlib | 16 + .../patches/patch-sys_sdl_glimp_cpp | 11 + .../patches/patch-sys_sdl_threads_cpp | 20 + .../patches/patch-sys_stub_openal_stub_cpp | 139 + .../patches/patch-sys_stub_stub_gl_cpp | 399 +++ .../patches/patch-sys_sys_local_cpp | 12 + .../patches/patch-sys_sys_public_h | 30 + games/idtech4a-engine/pkg/DESCR | 9 + games/idtech4a-engine/pkg/PLIST | 22 + games/idtech4a-engine/pkg/README | 17 + 40 files changed, 13870 insertions(+) create mode 100644 games/idtech4a-engine/Makefile create mode 100644 games/idtech4a-engine/distinfo create mode 100644 games/idtech4a-engine/patches/patch-CMakeLists_txt create mode 100644 games/idtech4a-engine/patches/patch-SConstruct create mode 100644 games/idtech4a-engine/patches/patch-externlibs_miniz_miniz_c create mode 100644 games/idtech4a-engine/patches/patch-framework_BuildDefines_h create mode 100644 games/idtech4a-engine/patches/patch-framework_Common_cpp create mode 100644 games/idtech4a-engine/patches/patch-framework_Session_menu_cpp create mode 100644 games/idtech4a-engine/patches/patch-idlib_Lib_cpp create mode 100644 games/idtech4a-engine/patches/patch-idlib_precompiled_h create mode 100644 games/idtech4a-engine/patches/patch-sound_efxlib_h create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_cache_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_decoder_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_efxfile_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_emitter_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_local_h create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_shader_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_system_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_wavefile_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_snd_world_cpp create mode 100644 games/idtech4a-engine/patches/patch-sound_sound_h create mode 100644 games/idtech4a-engine/patches/patch-sys_cmake_FindOGG_cmake create mode 100644 games/idtech4a-engine/patches/patch-sys_cmake_FindVorbisFile_cmake create mode 100644 games/idtech4a-engine/patches/patch-sys_cmake_FindVorbis_cmake create mode 100644 games/idtech4a-engine/patches/patch-sys_linux_main_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_linux_sdlmain_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_linux_sound_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_linux_sound_h create mode 100644 games/idtech4a-engine/patches/patch-sys_scons_SConscript_core create mode 100644 games/idtech4a-engine/patches/patch-sys_scons_SConscript_idlib create mode 100644 games/idtech4a-engine/patches/patch-sys_sdl_glimp_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_sdl_threads_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_stub_openal_stub_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_stub_stub_gl_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_sys_local_cpp create mode 100644 games/idtech4a-engine/patches/patch-sys_sys_public_h create mode 100644 games/idtech4a-engine/pkg/DESCR create mode 100644 games/idtech4a-engine/pkg/PLIST create mode 100644 games/idtech4a-engine/pkg/README diff --git a/FINISHED b/FINISHED index 821ccd2be..6f16719cc 100644 --- a/FINISHED +++ b/FINISHED @@ -134,6 +134,7 @@ net/py-netifaces2 ready to import (lcheylus) devel/gh-gr ready to import (lcheylus) devel/tokei ready to import (lcheylus) devel/scc ready to import (lcheylus) +games/idtech4a-engine ready for import, sent to ports@ (tx00100xt) games/runelite sent to ports@ 2023-02-09 (limero) games/serioussam ready for import, sent to ports@ (tx00100xt) games/recoil-rts ready for import, sent to ports@ (thfr) diff --git a/games/idtech4a-engine/Makefile b/games/idtech4a-engine/Makefile new file mode 100644 index 000000000..2d3c81254 --- /dev/null +++ b/games/idtech4a-engine/Makefile @@ -0,0 +1,78 @@ +ONLY_FOR_ARCHS= amd64 i386 + +COMMENT= idTEch4a Engine provided Doom3/Quake4/Prey source port + +N= idtech4a-engine +V= 1.1.0harmattan65 +P= com.n0n3m4.diii4a + +DIST_TUPLE = github glKarin ${P} v${V} . +PKGNAME = ${N}-${V} + +CATEGORIES= games + +MAINTAINER= Alexander Pavlov + + +# GPL-3 - Main Code, OpenAL Code from dhewm3 +# GPL-3 - Doom3/Quake4/Prey SDK for Android idTech4A++ +# BSD - msinttypes, TinyEXR, OpenEXR, vorbis, ogg +# BSD-1 - Mesa +# BSD-2 - Base64, binpack2d, SSAO, SSGI +# CC0-1.0 - Replacement Textures +# MIT - ImGui, stb, curl +# RSA - MD4 +# ZLIB - Minizip, CRC32i irrxml, mikktspace +# public-domain - MD5, stb +# GPL-2 - timidity +# LGPL-2 - timidity +# Artistic - timidity +# FTL BSD-style - freetype +# Apache-2.0 - soil +PERMIT_PACKAGE= Yes + +WRKDIST= ${WRKDIR}/${P}-${V}/Q3E/src/main/jni/doom3/neo + +# Extra: ogg.6 vorbis.9 vorbisfile.6 (dlopen) +WANTLIB += ${COMPILER_LIBCXX} SDL2 c m pthread vorbis +WANTLIB += ${COMPILER_LIBCXX} openal z curl ogg vorbisfile + +MODULES = devel/cmake + +# c++17 +COMPILER = base-clang ports-gcc +CFLAGS += -I${X11BASE}/include +CXXFLAGS += -I${X11BASE}/include + +CONFIGURE_ARGS += -DUSE_SYSTEM_ZLIB=ON -DOPENAL=TRUE +CONFIGURE_ARGS += -DCMAKE_BUILD_TYPE=Release -DSDL2=ON +CONFIGURE_ARGS += -DUSE_SYSTEM_CURL=ON -DNO_ALSA=ON + + +BUILD_DEPENDS = devel/ninja \ + audio/libogg \ + audio/libvorbis \ + audio/openal \ + net/curl \ + devel/sdl2 + +LIB_DEPENDS = audio/openal \ + audio/libogg \ + audio/libvorbis \ + net/curl \ + devel/sdl2 + +NO_TEST = Yes + +post-install: + ${INSTALL_PROGRAM} ${WRKDIR}/build-${MACHINE_ARCH}/Doom3 \ + ${PREFIX}/bin/idtech4a-doom3 + ${INSTALL_PROGRAM} ${WRKDIR}/build-${MACHINE_ARCH}/Quake4 \ + ${PREFIX}/bin/idtech4a-quake4 + ${INSTALL_PROGRAM} ${WRKDIR}/build-${MACHINE_ARCH}/Prey \ + ${PREFIX}/bin/idtech4a-prey + ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/${N} + ${INSTALL_DATA} ${WRKDIR}/${P}-${V}/README.md \ + ${PREFIX}/share/doc/${N} + +.include diff --git a/games/idtech4a-engine/distinfo b/games/idtech4a-engine/distinfo new file mode 100644 index 000000000..f6d10b391 --- /dev/null +++ b/games/idtech4a-engine/distinfo @@ -0,0 +1,2 @@ +SHA256 (glKarin-com.n0n3m4.diii4a-v1.1.0harmattan65.tar.gz) = KNX8GRwAR6R0ioe25dETT6nF9Lx5rOpfan62+u/9LyQ= +SIZE (glKarin-com.n0n3m4.diii4a-v1.1.0harmattan65.tar.gz) = 388197988 diff --git a/games/idtech4a-engine/patches/patch-CMakeLists_txt b/games/idtech4a-engine/patches/patch-CMakeLists_txt new file mode 100644 index 000000000..0439f8230 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-CMakeLists_txt @@ -0,0 +1,56 @@ +Index: CMakeLists.txt +--- CMakeLists.txt.orig ++++ CMakeLists.txt +@@ -366,9 +366,12 @@ find_package(ZLIB REQUIRED) + include_directories(${ZLIB_INCLUDE_DIRS}) + endif() + ++find_package(OpenAL REQUIRED) ++include_directories(${OPENAL_INCLUDE_DIR}) ++ + # OpenAL using internal OpenAL-soft + #[[find_package(OpenAL REQUIRED) +-include_directories(${OPENAL_INCLUDE_DIR})]] ++#include_directories(${OPENAL_INCLUDE_DIR})]] + + + if(WIN32) +@@ -615,7 +618,9 @@ elseif(ANDROID) + set(sys_libs ${sys_libs} z) + endif() + else() #TODO linux +- set(sys_libs ${sys_libs} dl pthread) ++ set(sys_libs ${sys_libs} pthread) # TODO OpenBSD fix link ++ set(OPENAL_SOUND_LIBRARY "OpenAL::OpenAL") ++ set(sys_libs ${sys_libs} ${OPENAL_SOUND_LIBRARY}) + if(USE_X11) + set(LINUX_SDL FALSE) + message(STATUS "use X11 + EGL") +@@ -1615,8 +1620,8 @@ else() + ) + set(src_sys_base + ${src_sys_base} +- sys/linux/sound.cpp +- sys/linux/sound_alsa.cpp ++ #sys/linux/sound.cpp ++ #sys/linux/sound_alsa.cpp + sys/linux/sdlmain.cpp + ) + set(src_sys_core +@@ -1628,7 +1633,7 @@ else() + sys/linux/main.cpp + sys/linux/input.cpp + sys/linux/sound.cpp +- sys/linux/sound_alsa.cpp ++ ##sys/linux/sound_alsa.cpp + ) + set(src_sys_core + sys/linux/gles2.cpp +@@ -1813,6 +1818,7 @@ if(CORE) + idlib + ${sys_libs} + ${local_libs} ++ ${OPENAL_LIBRARY} + ) + + if(NOT APPLE AND NOT WIN32 AND NOT ANDROID) diff --git a/games/idtech4a-engine/patches/patch-SConstruct b/games/idtech4a-engine/patches/patch-SConstruct new file mode 100644 index 000000000..8d4989e60 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-SConstruct @@ -0,0 +1,228 @@ +Index: SConstruct +--- SConstruct.orig ++++ SConstruct +@@ -12,8 +12,8 @@ import scons_utils + conf_filename='site.conf' + # choose configuration variables which should be saved between runs + # ( we handle all those as strings ) +-serialized=['CC', 'CXX', 'JOBS', 'BUILD', 'IDNET_HOST', 'DEDICATED', +- 'DEBUG_MEMORY', 'LIBC_MALLOC', 'ID_NOLANADDRESS', 'ID_MCHECK', 'ALSA', ++serialized=['CC', 'CXX', 'X86', 'JOBS', 'BUILD', 'IDNET_HOST', 'DEDICATED', ++ 'DEBUG_MEMORY', 'LIBC_MALLOC', 'ID_NOLANADDRESS', 'ID_MCHECK', + 'TARGET_CORE', 'TARGET_GAME', 'TARGET_D3XP', 'TARGET_MONO', 'TARGET_DEMO', 'NOCURL', + 'TARGET_CDOOM', + 'TARGET_D3LE', +@@ -29,6 +29,13 @@ serialized=['CC', 'CXX', 'JOBS', 'BUILD', 'IDNET_HOST' + 'MULTITHREAD', 'OPENSLES' + ] + ++ ++# global build mode ------------------------------ ++ ++g_sdk = not os.path.exists( 'sys/scons/SConscript.core' ) ++ ++# ------------------------------------------------ ++ + # help ------------------------------------------- + + help_string = """ +@@ -102,12 +109,18 @@ BUILD_GAMEPAK (default 0) + BASEFLAGS (default '') + Add compile flags + +-NOCONF (default 0, not saved) +- ignore site configuration and use defaults + command line only ++X86 (default 0) ++ cross compile for x86 (only applicable on x86_64) + + SILENT ( default 0, saved ) + hide the compiler output, unless error + ++NOCONF (default 0, not saved) ++ ignore site configuration and use defaults + command line only ++""" ++ ++if ( not g_sdk ): ++ help_string += """ + DEDICATED (default 0) + Control regular / dedicated type of build: + 0 - client +@@ -155,9 +168,12 @@ ID_MCHECK (default 2) + note that Doom has it's own block allocator/checking + this should not be considered a replacement, but an additional tool + +-ALSA (default 1) +- enable ALSA sound backend support +- ++SETUP (default 0, not saved) ++ build a setup. implies release build ++ ++SDK (default 0, not saved) ++ build an SDK release ++ + NOCURL (default 0) + set to 1 to disable usage of libcurl and http/ftp downloads feature + """ +@@ -175,18 +191,27 @@ EnsureSConsVersion( 0, 96 ) + # system detection ------------------------------- + + # CPU type +-cpu = commands.getoutput('uname -m') +-exp = re.compile('i?86') +-if exp.match(cpu): +- cpu = 'x86' +-else: +- if (commands.getoutput('uname -p') == 'powerpc'): +- cpu = 'ppc' +-g_os = 'Linux' ++g_cpu = '' + +-if ARGUMENTS.has_key( 'ARCH' ): +- cpu = ARGUMENTS['ARCH'] ++uname = commands.getoutput('uname -m') ++if uname == 'x86_64': ++ g_cpu = 'x86_64' + ++if len(g_cpu) < 1: ++ exp = re.compile('.*i?86.*') ++ if exp.match(uname): ++ g_cpu = 'x86' ++ ++if len(g_cpu) < 1: ++ uname = commands.getoutput('uname -p') ++ if (uname == 'powerpc'): ++ g_cpu = 'ppc' ++ ++if len(g_cpu) < 1: ++ g_cpu = 'cpu' ++ ++g_os = commands.getoutput('uname -s') ++ + # end system detection --------------------------- + + # default settings ------------------------------- +@@ -195,6 +220,7 @@ CC = 'gcc' + CXX = 'g++' + JOBS = '16' + BUILD = 'debug' ++X86 = '0' + DEDICATED = '0' + TARGET_CORE = '1' + TARGET_GAME = '1' +@@ -218,7 +244,8 @@ LIBC_MALLOC = '1' + ID_NOLANADDRESS = '0' + ID_MCHECK = '2' + BUILD_ROOT = 'build' +-ALSA = '1' ++SETUP = '0' ++SDK = '0' + NOCONF = '0' + NOCURL = '0' + BUILD_GAMEPAK = '0' +@@ -271,6 +298,21 @@ if ( not ARGUMENTS.has_key( 'NOCONF' ) or ARGUMENTS['N + + # end save site configuration ------------------ + ++# configuration rules -------------------------- ++ ++if ( SETUP != '0' ): ++ DEDICATED = '2' ++ BUILD = 'release' ++ ++if ( g_sdk or SDK != '0' ): ++ TARGET_CORE = '0' ++ TARGET_GAME = '1' ++ TARGET_D3XP = '1' ++ TARGET_MONO = '0' ++ TARGET_DEMO = '0' ++ ++# end configuration rules ---------------------- ++ + # general configuration, target selection -------- + + g_build = BUILD_ROOT + '/' + BUILD +@@ -297,15 +339,31 @@ CORECPPPATH = [ ] + CORELIBPATH = [ ] + CORECPPFLAGS = [ ] + GAMECPPFLAGS = [ ] +-BASELINKFLAGS = [ '-Wl,--no-undefined' ] +-CORELINKFLAGS = [ '-Wl,--no-undefined' ] +-#//k BASELINKFLAGS = [ '-Wl,--no-undefined', '-static-libstdc++' ] +-#//k CORELINKFLAGS = [ '-Wl,--no-undefined', '-static-libstdc++' ] ++BASELINKFLAGS = [ ] ++CORELINKFLAGS = [ ] + + # for release build, further optimisations that may not work on all files + OPTCPPFLAGS = [ ] + +-BASECPPFLAGS.append( BASEFLAGS.split() ) ++if (g_cpu == 'x86_64' and X86 == '1'): ++ print('cross compiling for x86') ++ g_cpu = 'x86' ++ BASECPPFLAGS.append('-m32') ++ BASELINKFLAGS.append('-m32') ++ ++g_build = '%s/%s-%s' % (BUILD_ROOT, g_cpu, BUILD) ++ ++SConsignFile( g_build + '/scons.signatures' ) ++ ++if ( DEBUG_MEMORY != '0' ): ++ g_build += '-debugmem' ++ ++if ( LIBC_MALLOC != '1' ): ++ g_build += '-nolibcmalloc' ++ ++LINK = CXX ++ ++BASECPPFLAGS.extend( BASEFLAGS.split(' ') ) + BASECPPFLAGS.append( '-pipe' ) + # warn all + BASECPPFLAGS.append( '-Wall' ) # -w +@@ -328,6 +386,13 @@ if ( g_os == 'Linux' ): + #BASECPPFLAGS.append('-D__arm__') + # //k + ++if ( "BSD" in g_os ): ++ BASECPPFLAGS.append( '-I/usr/local/include' ) ++ BASELINKFLAGS.append('-L/usr/local/lib') ++ ++if ( g_sdk or SDK != '0' ): ++ BASECPPFLAGS.append( '-D_D3SDK' ) ++ + if ( TARGET_ANDROID == '1' ): + BASECPPFLAGS.append( '-D__ANDROID__') + g_os = 'Android' +@@ -353,6 +418,10 @@ elif ( BUILD == 'release' ): + OPTCPPFLAGS = [ '-O3', '-Wl,--no-undefined', '-ffast-math', '-fno-unsafe-math-optimizations', '-fomit-frame-pointer' ] + else: + OPTCPPFLAGS = [ '-O3', '-march=native', '-ffast-math', '-fno-unsafe-math-optimizations', '-fomit-frame-pointer' ] ++ ++ if (g_cpu == 'x86'): ++ OPTCPPFLAGS.append('-march=pentium3') ++ + if ( ID_MCHECK == '0' ): + ID_MCHECK = '2' + else: +@@ -373,7 +442,12 @@ if ( ID_NOLANADDRESS != '0' ): + + if ( ID_MCHECK == '1' ): + BASECPPFLAGS.append( '-DID_MCHECK' ) +- ++ ++# TODO fix these warnings ++BASECPPFLAGS.append('-Wno-sign-compare') ++BASECPPFLAGS.append('-Wno-switch') ++BASECPPFLAGS.append('-Wno-format-security') ++ + # create the build environements + g_base_env = Environment( ENV = os.environ, CC = CC, CXX = CXX, LINK = LINK, CPPFLAGS = BASECPPFLAGS, LINKFLAGS = BASELINKFLAGS, CPPPATH = CORECPPPATH, LIBPATH = CORELIBPATH, NDK = NDK, MULTITHREAD = MULTITHREAD, OPENSLES = OPENSLES ) + scons_utils.SetupUtils( g_base_env ) +@@ -430,7 +504,7 @@ local_humanhead = 0 + # OpenGL + local_opengl = 0 + +-GLOBALS = 'g_env g_env_noopt g_game_env g_os ID_MCHECK ALSA idlib_objects game_objects local_dedicated local_gamedll local_demo local_idlibpic local_curl local_d3xp local_cdoom local_d3le local_rivensin local_hardcorps local_quake4 local_raven local_prey local_humanhead local_opengl OPTCPPFLAGS NDK MULTITHREAD OPENSLES' ++GLOBALS = 'g_env g_env_noopt g_game_env g_os g_cpu g_build ID_MCHECK idlib_objects game_objects local_dedicated local_gamedll local_demo local_idlibpic local_curl local_d3xp local_cdoom local_d3le local_rivensin local_hardcorps local_quake4 local_raven local_prey local_humanhead local_opengl OPTCPPFLAGS NDK MULTITHREAD OPENSLES' + + # end general configuration ---------------------- + diff --git a/games/idtech4a-engine/patches/patch-externlibs_miniz_miniz_c b/games/idtech4a-engine/patches/patch-externlibs_miniz_miniz_c new file mode 100644 index 000000000..4a3083026 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-externlibs_miniz_miniz_c @@ -0,0 +1,12 @@ +Index: externlibs/miniz/miniz.c +--- externlibs/miniz/miniz.c.orig ++++ externlibs/miniz/miniz.c +@@ -3171,7 +3171,7 @@ static int mz_stat64(const char *path, struct __stat64 + #define MZ_FREOPEN(p, m, s) freopen64(p, m, s) + #define MZ_DELETE_FILE remove + +-#elif defined(__APPLE__) || defined(__FreeBSD__) ++#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) + #ifndef MINIZ_NO_TIME + #include + #endif diff --git a/games/idtech4a-engine/patches/patch-framework_BuildDefines_h b/games/idtech4a-engine/patches/patch-framework_BuildDefines_h new file mode 100644 index 000000000..d8a1fe652 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-framework_BuildDefines_h @@ -0,0 +1,28 @@ +Index: framework/BuildDefines.h +--- framework/BuildDefines.h.orig ++++ framework/BuildDefines.h +@@ -116,18 +116,17 @@ If you have questions concerning this license or the a + #endif + + #ifndef ID_OPENAL +-# if ( defined(_WIN32) || defined(MACOS_X) ) && !defined( ID_DEDICATED ) +-#ifdef _OPENAL ++# if !defined( ID_DEDICATED ) + # define ID_OPENAL 1 +-#else +-# define ID_OPENAL 0 +-#endif +-# elif defined( _OPENAL ) +-# define ID_OPENAL 1 + # else + # define ID_OPENAL 0 + # endif + #endif ++ ++#ifndef ID_OPENAL_EAX ++# define ID_OPENAL_EAX 0 ++#endif ++ + + #ifndef ID_ALLOW_D3XP + # if defined( MACOS_X ) diff --git a/games/idtech4a-engine/patches/patch-framework_Common_cpp b/games/idtech4a-engine/patches/patch-framework_Common_cpp new file mode 100644 index 000000000..f9367fec4 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-framework_Common_cpp @@ -0,0 +1,49 @@ +Index: framework/Common.cpp +--- framework/Common.cpp.orig ++++ framework/Common.cpp +@@ -2884,10 +2884,13 @@ void idCommonLocal::Async(void) + + #ifdef _RAVEN // quake4 game dll + #define _HARM_BASE_GAME_DLL "q4game" ++idStr fsgame_dllname = "libq4game.so"; + #elif defined(_HUMANHEAD) // prey game dll + #define _HARM_BASE_GAME_DLL "preygame" ++idStr fsgame_dllname = "libpreygame.so"; + #else + #define _HARM_BASE_GAME_DLL "game" ++idStr fsgame_dllname = "libgame.so"; + #endif + + #ifdef _WIN32 +@@ -2959,6 +2962,22 @@ void idCommonLocal::LoadGameDLL(void) + else + common->Printf("[Harmattan]: cvar `harm_fs_gameLibPath` is unset.\n"); + ++ if(!gameDLL) ++ { ++ fsgame = "/usr/local/lib/" + fsgame_dllname; ++ common->Printf("[Harmattan]: Load game `%s` from cvar `harm_fs_gameLibPath`......\n", fsgame.c_str()); ++ gameDLL = sys->DLL_Load(fsgame); ++ common->Printf("[Harmattan]: Load dynamic library `%s` %s!\n", fsgame.c_str(), LOAD_RESULT(gameDLL)); ++ } ++ ++ if(!gameDLL) ++ { ++ fsgame = "/usr/local/lib/idtech4a-engine/" + fsgame_dllname; ++ common->Printf("[Harmattan]: Load game `%s` from cvar `harm_fs_gameLibPath`......\n", fsgame.c_str()); ++ gameDLL = sys->DLL_Load(fsgame); ++ common->Printf("[Harmattan]: Load dynamic library `%s` %s!\n", fsgame.c_str(), LOAD_RESULT(gameDLL)); ++ } ++ + // Second check `fs_game` cvar. + if(!gameDLL) + { +@@ -3538,7 +3557,7 @@ void idCommonLocal::ShutdownGame(bool reloading) + sw->StopAllSounds(); + } + +- soundSystem->ClearBuffer(); ++ // soundSystem->ClearBuffer(); + + // shutdown the script debugger + // DebuggerServerShutdown(); diff --git a/games/idtech4a-engine/patches/patch-framework_Session_menu_cpp b/games/idtech4a-engine/patches/patch-framework_Session_menu_cpp new file mode 100644 index 000000000..65d4ad220 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-framework_Session_menu_cpp @@ -0,0 +1,25 @@ +Index: framework/Session_menu.cpp +--- framework/Session_menu.cpp.orig ++++ framework/Session_menu.cpp +@@ -1003,10 +1003,7 @@ void idSessionLocal::HandleMainMenuCommands(const char + int eax = soundSystem->IsEAXAvailable(); + + switch (eax) { +- case 2: +- // OpenAL subsystem load failed +- MessageBox(MSG_OK, common->GetLanguageDict()->GetString("#str_07238"), common->GetLanguageDict()->GetString("#str_07231"), true); +- break; ++ + case 1: + // when you restart + MessageBox(MSG_OK, common->GetLanguageDict()->GetString("#str_04137"), common->GetLanguageDict()->GetString("#str_07231"), true); +@@ -1023,8 +1020,7 @@ void idSessionLocal::HandleMainMenuCommands(const char + break; + } + } else { +- // also turn off OpenAL so we fully go back to legacy mixer +- cvarSystem->SetCVarBool("s_useOpenAL", false); ++ + // when you restart + MessageBox(MSG_OK, common->GetLanguageDict()->GetString("#str_04137"), common->GetLanguageDict()->GetString("#str_07231"), true); + } diff --git a/games/idtech4a-engine/patches/patch-idlib_Lib_cpp b/games/idtech4a-engine/patches/patch-idlib_Lib_cpp new file mode 100644 index 000000000..751df3053 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-idlib_Lib_cpp @@ -0,0 +1,48 @@ +Index: idlib/Lib.cpp +--- idlib/Lib.cpp.orig ++++ idlib/Lib.cpp +@@ -33,7 +33,7 @@ If you have questions concerning this license or the a + #include + #include + #include +-#elif defined(__unix__) ++#elif defined(__OpenBSD__) + #include + #include + #endif +@@ -159,7 +159,7 @@ dword PackColor(const idVec4 &color) + dz = ColorFloatToByte(color.z); + dw = ColorFloatToByte(color.w); + +-#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__)) ++#if defined(_WIN32) || defined(__OpenBSD__) || (defined(MACOS_X) && defined(__i386__)) + return (dx << 0) | (dy << 8) | (dz << 16) | (dw << 24); + #elif (defined(MACOS_X) && defined(__ppc__)) + return (dx << 24) | (dy << 16) | (dz << 8) | (dw << 0); +@@ -175,7 +175,7 @@ UnpackColor + */ + void UnpackColor(const dword color, idVec4 &unpackedColor) + { +-#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__)) ++#if defined(_WIN32) || defined(__OpenBSD__) || (defined(MACOS_X) && defined(__i386__)) + unpackedColor.Set(((color >> 0) & 255) *(1.0f / 255.0f), + ((color >> 8) & 255) *(1.0f / 255.0f), + ((color >> 16) & 255) *(1.0f / 255.0f), +@@ -203,7 +203,7 @@ dword PackColor(const idVec3 &color) + dy = ColorFloatToByte(color.y); + dz = ColorFloatToByte(color.z); + +-#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__)) ++#if defined(_WIN32) || defined(__OpenBSD__) || (defined(MACOS_X) && defined(__i386__)) + return (dx << 0) | (dy << 8) | (dz << 16); + #elif (defined(MACOS_X) && defined(__ppc__)) + return (dy << 16) | (dz << 8) | (dx << 0); +@@ -219,7 +219,7 @@ UnpackColor + */ + void UnpackColor(const dword color, idVec3 &unpackedColor) + { +-#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__)) ++#if defined(_WIN32) || defined(__OpenBSD__) || (defined(MACOS_X) && defined(__i386__)) + unpackedColor.Set(((color >> 0) & 255) *(1.0f / 255.0f), + ((color >> 8) & 255) *(1.0f / 255.0f), + ((color >> 16) & 255) *(1.0f / 255.0f)); diff --git a/games/idtech4a-engine/patches/patch-idlib_precompiled_h b/games/idtech4a-engine/patches/patch-idlib_precompiled_h new file mode 100644 index 000000000..b95d65353 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-idlib_precompiled_h @@ -0,0 +1,12 @@ +Index: idlib/precompiled.h +--- idlib/precompiled.h.orig ++++ idlib/precompiled.h +@@ -98,7 +98,7 @@ class BITT { (public) + #define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk + #define DIRECTSOUND_VERSION 0x0800 + +-#include ++//#include + #include + + #endif /* !GAME_DLL */ diff --git a/games/idtech4a-engine/patches/patch-sound_efxlib_h b/games/idtech4a-engine/patches/patch-sound_efxlib_h new file mode 100644 index 000000000..9a35e076c --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_efxlib_h @@ -0,0 +1,66 @@ +Index: sound/efxlib.h +--- sound/efxlib.h.orig ++++ sound/efxlib.h +@@ -0,0 +1,62 @@ ++/* ++*/ ++ ++#ifndef __EFXLIBH ++#define __EFXLIBH ++ ++#if ID_OPENAL_EAX ++#include ++#endif ++ ++ ++ ++ ++/////////////////////////////////////////////////////////// ++// Class definitions. ++class idSoundEffect ++{ ++public: ++ idSoundEffect() { ++ }; ++ ~idSoundEffect() { ++ if ( data && datasize ) { ++ Mem_Free( data ); ++ data = NULL; ++ } ++ } ++ ++ idStr name; ++ int datasize; ++ void *data; ++}; ++ ++class idEFXFile ++{ ++private: ++ ++protected: ++ // Protected data members. ++ ++public: ++ // Public data members. ++ ++private: ++ ++public: ++ idEFXFile(); ++ ~idEFXFile(); ++ ++ bool FindEffect( idStr &name, idSoundEffect **effect, int *index ); ++ bool ReadEffect( idLexer &lexer, idSoundEffect *effect ); ++ bool LoadFile( const char *filename, bool OSPath = false ); ++ void UnloadFile( void ); ++ void Clear( void ); ++ ++ idListeffects; ++}; ++/////////////////////////////////////////////////////////// ++ ++ ++ ++ ++#endif // __EFXLIBH diff --git a/games/idtech4a-engine/patches/patch-sound_snd_cache_cpp b/games/idtech4a-engine/patches/patch-sound_snd_cache_cpp new file mode 100644 index 000000000..ecd7358f5 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_cache_cpp @@ -0,0 +1,900 @@ +Index: sound/snd_cache.cpp +--- sound/snd_cache.cpp.orig ++++ sound/snd_cache.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -37,11 +37,6 @@ static idDynamicBlockAlloc soundCa + #else + static idDynamicAlloc soundCacheAllocator; + #endif +-#ifdef _OPENAL +-#ifdef _OPENAL_SOFT +-static idCVar harm_s_useAmplitudeDataOpenAL("harm_s_useAmplitudeDataOpenAL", "0", CVAR_SOUND | CVAR_BOOL | CVAR_INIT, "Use amplitude data on OpenAL(It cause large shake)"); +-#endif +-#endif + + + /* +@@ -49,12 +44,11 @@ static idCVar harm_s_useAmplitudeDataOpenAL("harm_s_us + idSoundCache::idSoundCache() + =================== + */ +-idSoundCache::idSoundCache() +-{ ++idSoundCache::idSoundCache() { + soundCacheAllocator.Init(); +- soundCacheAllocator.SetLockMemory(true); +- listCache.AssureSize(1024, NULL); +- listCache.SetGranularity(256); ++ soundCacheAllocator.SetLockMemory( true ); ++ listCache.AssureSize( 1024, NULL ); ++ listCache.SetGranularity( 256 ); + insideLevelLoad = false; + } + +@@ -63,9 +57,8 @@ idSoundCache::idSoundCache() + idSoundCache::~idSoundCache() + =================== + */ +-idSoundCache::~idSoundCache() +-{ +- listCache.DeleteContents(true); ++idSoundCache::~idSoundCache() { ++ listCache.DeleteContents( true ); + soundCacheAllocator.Shutdown(); + } + +@@ -76,12 +69,10 @@ idSoundCache::::GetObject + returns a single cached object pointer + =================== + */ +-const idSoundSample *idSoundCache::GetObject(const int index) const +-{ ++const idSoundSample* idSoundCache::GetObject( const int index ) const { + if (index<0 || index>listCache.Num()) { + return NULL; + } +- + return listCache[index]; + } + +@@ -92,27 +83,23 @@ idSoundCache::FindSound + Adds a sound object to the cache and returns a handle for it. + =================== + */ +-idSoundSample *idSoundCache::FindSound(const idStr &filename, bool loadOnDemandOnly) +-{ ++idSoundSample *idSoundCache::FindSound( const idStr& filename, bool loadOnDemandOnly ) { + idStr fname; + + fname = filename; + fname.BackSlashesToSlashes(); + fname.ToLower(); + +- declManager->MediaPrint("%s\n", fname.c_str()); ++ declManager->MediaPrint( "%s\n", fname.c_str() ); + + // check to see if object is already in cache +- for (int i = 0; i < listCache.Num(); i++) { ++ for( int i = 0; i < listCache.Num(); i++ ) { + idSoundSample *def = listCache[i]; +- +- if (def && def->name == fname) { ++ if ( def && def->name == fname ) { + def->levelLoadReferenced = true; +- +- if (def->purged && !loadOnDemandOnly) { ++ if ( def->purged && !loadOnDemandOnly ) { + def->Load(); + } +- + return def; + } + } +@@ -121,11 +108,10 @@ idSoundSample *idSoundCache::FindSound(const idStr &fi + idSoundSample *def = new idSoundSample; + + int shandle = listCache.FindNull(); +- +- if (shandle != -1) { ++ if ( shandle != -1 ) { + listCache[shandle] = def; + } else { +- shandle = listCache.Append(def); ++ shandle = listCache.Append( def ); + } + + def->name = fname; +@@ -133,7 +119,7 @@ idSoundSample *idSoundCache::FindSound(const idStr &fi + def->onDemand = loadOnDemandOnly; + def->purged = true; + +- if (!loadOnDemandOnly) { ++ if ( !loadOnDemandOnly ) { + // this may make it a default sound if it can't be loaded + def->Load(); + } +@@ -148,15 +134,13 @@ idSoundCache::ReloadSounds + Completely nukes the current cache + =================== + */ +-void idSoundCache::ReloadSounds(bool force) +-{ ++void idSoundCache::ReloadSounds( bool force ) { + int i; + +- for (i = 0; i < listCache.Num(); i++) { ++ for( i = 0; i < listCache.Num(); i++ ) { + idSoundSample *def = listCache[i]; +- +- if (def) { +- def->Reload(force); ++ if ( def ) { ++ def->Reload( force ); + } + } + } +@@ -171,18 +155,16 @@ either mark the image as used, or create a new image w + loading the actual data. + ==================== + */ +-void idSoundCache::BeginLevelLoad() +-{ ++void idSoundCache::BeginLevelLoad() { + insideLevelLoad = true; + +- for (int i = 0 ; i < listCache.Num() ; i++) { ++ for ( int i = 0 ; i < listCache.Num() ; i++ ) { + idSoundSample *sample = listCache[ i ]; +- +- if (!sample) { ++ if ( !sample ) { + continue; + } + +- if (com_purgeAll.GetBool()) { ++ if ( com_purgeAll.GetBool() ) { + sample->PurgeSoundSample(); + } + +@@ -199,29 +181,24 @@ EndLevelLoad + Free all samples marked as unused + ==================== + */ +-void idSoundCache::EndLevelLoad() +-{ ++void idSoundCache::EndLevelLoad() { + int useCount, purgeCount; +- common->Printf("----- idSoundCache::EndLevelLoad -----\n"); ++ common->Printf( "----- idSoundCache::EndLevelLoad -----\n" ); + + insideLevelLoad = false; + + // purge the ones we don't need + useCount = 0; + purgeCount = 0; +- +- for (int i = 0 ; i < listCache.Num() ; i++) { ++ for ( int i = 0 ; i < listCache.Num() ; i++ ) { + idSoundSample *sample = listCache[ i ]; +- +- if (!sample) { ++ if ( !sample ) { + continue; + } +- +- if (sample->purged) { ++ if ( sample->purged ) { + continue; + } +- +- if (!sample->levelLoadReferenced) { ++ if ( !sample->levelLoadReferenced ) { + // common->Printf( "Purging %s\n", sample->name.c_str() ); + purgeCount += sample->objectMemSize; + sample->PurgeSoundSample(); +@@ -232,9 +209,9 @@ void idSoundCache::EndLevelLoad() + + soundCacheAllocator.FreeEmptyBaseBlocks(); + +- common->Printf("%5ik referenced\n", useCount / 1024); +- common->Printf("%5ik purged\n", purgeCount / 1024); +- common->Printf("----------------------------------------\n"); ++ common->Printf( "%5ik referenced\n", useCount / 1024 ); ++ common->Printf( "%5ik purged\n", purgeCount / 1024 ); ++ common->Printf( "----------------------------------------\n" ); + } + + /* +@@ -242,21 +219,19 @@ void idSoundCache::EndLevelLoad() + idSoundCache::PrintMemInfo + =================== + */ +-void idSoundCache::PrintMemInfo(MemInfo_t *mi) +-{ ++void idSoundCache::PrintMemInfo( MemInfo_t *mi ) { + int i, j, num = 0, total = 0; + int *sortIndex; + idFile *f; + +- f = fileSystem->OpenFileWrite(mi->filebase + "_sounds.txt"); +- +- if (!f) { ++ f = fileSystem->OpenFileWrite( mi->filebase + "_sounds.txt" ); ++ if ( !f ) { + return; + } + + // count +- for (i = 0; i < listCache.Num(); i++, num++) { +- if (!listCache[i]) { ++ for ( i = 0; i < listCache.Num(); i++, num++ ) { ++ if ( !listCache[i] ) { + break; + } + } +@@ -264,13 +239,13 @@ void idSoundCache::PrintMemInfo(MemInfo_t *mi) + // sort first + sortIndex = new int[num]; + +- for (i = 0; i < num; i++) { ++ for ( i = 0; i < num; i++ ) { + sortIndex[i] = i; + } + +- for (i = 0; i < num - 1; i++) { +- for (j = i + 1; j < num; j++) { +- if (listCache[sortIndex[i]]->objectMemSize < listCache[sortIndex[j]]->objectMemSize) { ++ for ( i = 0; i < num - 1; i++ ) { ++ for ( j = i + 1; j < num; j++ ) { ++ if ( listCache[sortIndex[i]]->objectMemSize < listCache[sortIndex[j]]->objectMemSize ) { + int temp = sortIndex[i]; + sortIndex[i] = sortIndex[j]; + sortIndex[j] = temp; +@@ -279,24 +254,22 @@ void idSoundCache::PrintMemInfo(MemInfo_t *mi) + } + + // print next +- for (i = 0; i < num; i++) { ++ for ( i = 0; i < num; i++ ) { + idSoundSample *sample = listCache[sortIndex[i]]; + + // this is strange +- if (!sample) { ++ if ( !sample ) { + continue; + } + + total += sample->objectMemSize; +- f->Printf("%s %s\n", idStr::FormatNumber(sample->objectMemSize).c_str(), sample->name.c_str()); ++ f->Printf( "%s %s\n", idStr::FormatNumber( sample->objectMemSize ).c_str(), sample->name.c_str() ); + } + +- delete[] sortIndex; +- + mi->soundAssetsTotal = total; + +- f->Printf("\nTotal sound bytes allocated: %s\n", idStr::FormatNumber(total).c_str()); +- fileSystem->CloseFile(f); ++ f->Printf( "\nTotal sound bytes allocated: %s\n", idStr::FormatNumber( total ).c_str() ); ++ fileSystem->CloseFile( f ); + } + + +@@ -313,9 +286,8 @@ idSoundSample + idSoundSample::idSoundSample + =================== + */ +-idSoundSample::idSoundSample() +-{ +- memset(&objectInfo, 0, sizeof(waveformatex_t)); ++idSoundSample::idSoundSample() { ++ memset( &objectInfo, 0, sizeof(waveformatex_t) ); + objectSize = 0; + objectMemSize = 0; + nonCacheData = NULL; +@@ -333,8 +305,7 @@ idSoundSample::idSoundSample() + idSoundSample::~idSoundSample + =================== + */ +-idSoundSample::~idSoundSample() +-{ ++idSoundSample::~idSoundSample() { + PurgeSoundSample(); + } + +@@ -343,12 +314,11 @@ idSoundSample::~idSoundSample() + idSoundSample::LengthIn44kHzSamples + =================== + */ +-int idSoundSample::LengthIn44kHzSamples(void) const +-{ ++int idSoundSample::LengthIn44kHzSamples( void ) const { + // objectSize is samples +- if (objectInfo.nSamplesPerSec == 11025) { ++ if ( objectInfo.nSamplesPerSec == 11025 ) { + return objectSize << 2; +- } else if (objectInfo.nSamplesPerSec == 22050) { ++ } else if ( objectInfo.nSamplesPerSec == 22050 ) { + return objectSize << 1; + } else { + return objectSize << 0; +@@ -360,56 +330,44 @@ int idSoundSample::LengthIn44kHzSamples(void) const + idSoundSample::MakeDefault + =================== + */ +-void idSoundSample::MakeDefault(void) +-{ ++void idSoundSample::MakeDefault( void ) { + int i; + float v; + int sample; + +- memset(&objectInfo, 0, sizeof(objectInfo)); ++ memset( &objectInfo, 0, sizeof( objectInfo ) ); + + objectInfo.nChannels = 1; + objectInfo.wBitsPerSample = 16; + objectInfo.nSamplesPerSec = 44100; + + objectSize = MIXBUFFER_SAMPLES * 2; +- objectMemSize = objectSize * sizeof(short); ++ objectMemSize = objectSize * sizeof( short ); + +- nonCacheData = (byte *)soundCacheAllocator.Alloc(objectMemSize); ++ nonCacheData = (byte *)soundCacheAllocator.Alloc( objectMemSize ); + + short *ncd = (short *)nonCacheData; + +- for (i = 0; i < MIXBUFFER_SAMPLES; i ++) { +- v = sin(idMath::PI * 2 * i / 64); ++ for ( i = 0; i < MIXBUFFER_SAMPLES; i ++ ) { ++ v = sin( idMath::PI * 2 * i / 64 ); + sample = v * 0x4000; + ncd[i*2+0] = sample; + ncd[i*2+1] = sample; + } + +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL) { +- alGetError(); +- alGenBuffers(1, &openalBuffer); ++ alGetError(); ++ alGenBuffers( 1, &openalBuffer ); ++ if ( alGetError() != AL_NO_ERROR ) { ++ common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); ++ } + +- if (alGetError() != AL_NO_ERROR) { +- common->Error("idSoundCache: error generating OpenAL hardware buffer"); +- } +- +- alGetError(); +- alBufferData(openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec); +- +- if (alGetError() != AL_NO_ERROR) { +-#ifdef _OPENAL_SOFT +- common->Warning( "idSoundCache: error loading data into OpenAL hardware buffer" ); +- hardwareBuffer = false; +-#else +- common->Error("idSoundCache: error loading data into OpenAL hardware buffer"); +-#endif +- } else { +- hardwareBuffer = true; +- } ++ alGetError(); ++ alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); ++ if ( alGetError() != AL_NO_ERROR ) { ++ common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); ++ } else { ++ hardwareBuffer = true; + } +-#endif + + defaultSound = true; + } +@@ -419,31 +377,27 @@ void idSoundSample::MakeDefault(void) + idSoundSample::CheckForDownSample + =================== + */ +-void idSoundSample::CheckForDownSample(void) +-{ +- if (!idSoundSystemLocal::s_force22kHz.GetBool()) { ++void idSoundSample::CheckForDownSample( void ) { ++ if ( !idSoundSystemLocal::s_force22kHz.GetBool() ) { + return; + } +- +- if (objectInfo.wFormatTag != WAVE_FORMAT_TAG_PCM || objectInfo.nSamplesPerSec != 44100) { ++ if ( objectInfo.wFormatTag != WAVE_FORMAT_TAG_PCM || objectInfo.nSamplesPerSec != 44100 ) { + return; + } +- + int shortSamples = objectSize >> 1; +- short *converted = (short *)soundCacheAllocator.Alloc(shortSamples * sizeof(short)); ++ short *converted = (short *)soundCacheAllocator.Alloc( shortSamples * sizeof( short ) ); + +- if (objectInfo.nChannels == 1) { +- for (int i = 0; i < shortSamples; i++) { ++ if ( objectInfo.nChannels == 1 ) { ++ for ( int i = 0; i < shortSamples; i++ ) { + converted[i] = ((short *)nonCacheData)[i*2]; + } + } else { +- for (int i = 0; i < shortSamples; i += 2) { ++ for ( int i = 0; i < shortSamples; i += 2 ) { + converted[i+0] = ((short *)nonCacheData)[i*2+0]; + converted[i+1] = ((short *)nonCacheData)[i*2+1]; + } + } +- +- soundCacheAllocator.Free(nonCacheData); ++ soundCacheAllocator.Free( nonCacheData ); + nonCacheData = (byte *)converted; + objectSize >>= 1; + objectMemSize >>= 1; +@@ -456,18 +410,15 @@ void idSoundSample::CheckForDownSample(void) + idSoundSample::GetNewTimeStamp + =================== + */ +-ID_TIME_T idSoundSample::GetNewTimeStamp(void) const +-{ ++ID_TIME_T idSoundSample::GetNewTimeStamp( void ) const { + ID_TIME_T timestamp; + +- fileSystem->ReadFile(name, NULL, ×tamp); +- +- if (timestamp == FILE_NOT_FOUND_TIMESTAMP) { ++ fileSystem->ReadFile( name, NULL, ×tamp ); ++ if ( timestamp == FILE_NOT_FOUND_TIMESTAMP ) { + idStr oggName = name; +- oggName.SetFileExtension(".ogg"); +- fileSystem->ReadFile(oggName, NULL, ×tamp); ++ oggName.SetFileExtension( ".ogg" ); ++ fileSystem->ReadFile( oggName, NULL, ×tamp ); + } +- + return timestamp; + } + +@@ -478,16 +429,15 @@ idSoundSample::Load + Loads based on name, possibly doing a MakeDefault if necessary + =================== + */ +-void idSoundSample::Load(void) +-{ ++void idSoundSample::Load( void ) { + defaultSound = false; + purged = false; + hardwareBuffer = false; + + timestamp = GetNewTimeStamp(); + +- if (timestamp == FILE_NOT_FOUND_TIMESTAMP) { +- common->Warning("Couldn't load sound '%s' using default", name.c_str()); ++ if ( timestamp == FILE_NOT_FOUND_TIMESTAMP ) { ++ common->Warning( "Couldn't load sound '%s' using default", name.c_str() ); + MakeDefault(); + return; + } +@@ -496,28 +446,28 @@ void idSoundSample::Load(void) + idWaveFile fh; + waveformatex_t info; + +- if (fh.Open(name, &info) == -1) { +- common->Warning("Couldn't load sound '%s' using default", name.c_str()); ++ if ( fh.Open( name, &info ) == -1 ) { ++ common->Warning( "Couldn't load sound '%s' using default", name.c_str() ); + MakeDefault(); + return; + } + +- if (info.nChannels != 1 && info.nChannels != 2) { +- common->Warning("idSoundSample: %s has %i channels, using default", name.c_str(), info.nChannels); ++ if ( info.nChannels != 1 && info.nChannels != 2 ) { ++ common->Warning( "idSoundSample: %s has %i channels, using default", name.c_str(), info.nChannels ); + fh.Close(); + MakeDefault(); + return; + } + +- if (info.wBitsPerSample != 16) { +- common->Warning("idSoundSample: %s is %dbits, expected 16bits using default", name.c_str(), info.wBitsPerSample); ++ if ( info.wBitsPerSample != 16 ) { ++ common->Warning( "idSoundSample: %s is %dbits, expected 16bits using default", name.c_str(), info.wBitsPerSample ); + fh.Close(); + MakeDefault(); + return; + } + +- if (info.nSamplesPerSec != 44100 && info.nSamplesPerSec != 22050 && info.nSamplesPerSec != 11025) { +- common->Warning("idSoundCache: %s is %dHz, expected 11025, 22050 or 44100 Hz. Using default", name.c_str(), info.nSamplesPerSec); ++ if ( info.nSamplesPerSec != 44100 && info.nSamplesPerSec != 22050 && info.nSamplesPerSec != 11025 ) { ++ common->Warning( "idSoundCache: %s is %dHz, expected 11025, 22050 or 44100 Hz. Using default", name.c_str(), info.nSamplesPerSec ); + fh.Close(); + MakeDefault(); + return; +@@ -527,185 +477,142 @@ void idSoundSample::Load(void) + objectSize = fh.GetOutputSize(); + objectMemSize = fh.GetMemorySize(); + +- nonCacheData = (byte *)soundCacheAllocator.Alloc(objectMemSize); +- fh.Read(nonCacheData, objectMemSize, NULL); ++ nonCacheData = (byte *)soundCacheAllocator.Alloc( objectMemSize ); ++ fh.Read( nonCacheData, objectMemSize, NULL ); + + // optionally convert it to 22kHz to save memory + CheckForDownSample(); + + // create hardware audio buffers +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL) { +- // PCM loads directly +- if (objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM) { ++ // PCM loads directly ++ if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM ) { ++ alGetError(); ++ alGenBuffers( 1, &openalBuffer ); ++ if ( alGetError() != AL_NO_ERROR ) ++ common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); ++ if ( alIsBuffer( openalBuffer ) ) { + alGetError(); +- alGenBuffers(1, &openalBuffer); ++ alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec ); ++ if ( alGetError() != AL_NO_ERROR ) { ++ common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); ++ } else { ++ // Compute amplitude block size ++ int blockSize = 512 * objectInfo.nSamplesPerSec / 44100 ; + +- if (alGetError() != AL_NO_ERROR) +- common->Error("idSoundCache: error generating OpenAL hardware buffer"); ++ // Allocate amplitude data array ++ amplitudeData = (byte *)soundCacheAllocator.Alloc( ( objectSize / blockSize + 1 ) * 2 * sizeof( short) ); + +- if (alIsBuffer(openalBuffer)) { +- alGetError(); +- alBufferData(openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, nonCacheData, objectMemSize, objectInfo.nSamplesPerSec); ++ // Creating array of min/max amplitude pairs per blockSize samples ++ int i; ++ for ( i = 0; i < objectSize; i+=blockSize ) { ++ short min = 32767; ++ short max = -32768; + +- if (alGetError() != AL_NO_ERROR) { +-#ifdef _OPENAL_SOFT +- common->Warning( "idSoundCache: error loading data into OpenAL hardware buffer" ); +- hardwareBuffer = false; +-#else +- common->Error("idSoundCache: error loading data into OpenAL hardware buffer"); +-#endif +- } else { +-#ifdef _OPENAL_SOFT //k: for large shake in idSoundWorld::CurrentShakeAmplitudeForPosition, using non-OpenAL compute amplitude +- if(harm_s_useAmplitudeDataOpenAL.GetBool()) { +-#endif +- // Compute amplitude block size +- int blockSize = 512 * objectInfo.nSamplesPerSec / 44100 ; +- +- // Allocate amplitude data array +- amplitudeData = (byte *)soundCacheAllocator.Alloc((objectSize / blockSize + 1) * 2 * sizeof(short)); +- +- // Creating array of min/max amplitude pairs per blockSize samples +- int i; +- +- for (i = 0; i < objectSize; i+=blockSize) { +- short min = 32767; +- short max = -32768; +- +- int j; +- +- for (j = 0; j < Min(objectSize - i, blockSize); j++) { +- min = ((short *)nonCacheData)[ i + j ] < min ? ((short *)nonCacheData)[ i + j ] : min; +- max = ((short *)nonCacheData)[ i + j ] > max ? ((short *)nonCacheData)[ i + j ] : max; +- } +- +- ((short *)amplitudeData)[(i / blockSize) * 2 ] = min; +- ((short *)amplitudeData)[(i / blockSize) * 2 + 1 ] = max; ++ int j; ++ for ( j = 0; j < Min( objectSize - i, blockSize ); j++ ) { ++ min = ((short *)nonCacheData)[ i + j ] < min ? ((short *)nonCacheData)[ i + j ] : min; ++ max = ((short *)nonCacheData)[ i + j ] > max ? ((short *)nonCacheData)[ i + j ] : max; + } +-#ifdef _OPENAL_SOFT //k: for large shake in idSoundWorld::CurrentShakeAmplitudeForPosition, using non-OpenAL compute amplitude +- } +-#endif + +- hardwareBuffer = true; ++ ((short *)amplitudeData)[ ( i / blockSize ) * 2 ] = min; ++ ((short *)amplitudeData)[ ( i / blockSize ) * 2 + 1 ] = max; + } ++ ++ hardwareBuffer = true; + } + } + + // OGG decompressed at load time (when smaller than s_decompressionLimit seconds, 6 seconds by default) +- if (objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) { +-#if defined(_OPENAL_SOFT) +- +- if ((objectSize < ((int) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger()))) ++ if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) { ++#if !ID_OPENAL_EAX ++ if ( ( objectSize < ( ( int ) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger() ) ) ) { + #else +- +- if ((alIsExtensionPresent(ID_ALCHAR "EAX-RAM") == AL_TRUE) && (objectSize < ((int) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger()))) ++ if ( ( alIsExtensionPresent( ID_ALCHAR "EAX-RAM" ) == AL_TRUE ) && ( objectSize < ( ( int ) objectInfo.nSamplesPerSec * idSoundSystemLocal::s_decompressionLimit.GetInteger() ) ) ) { + #endif +- { + alGetError(); +- alGenBuffers(1, &openalBuffer); +- +- if (alGetError() != AL_NO_ERROR) +- common->Error("idSoundCache: error generating OpenAL hardware buffer"); +- +- if (alIsBuffer(openalBuffer)) { ++ alGenBuffers( 1, &openalBuffer ); ++ if ( alGetError() != AL_NO_ERROR ) ++ common->Error( "idSoundCache: error generating OpenAL hardware buffer" ); ++ if ( alIsBuffer( openalBuffer ) ) { + idSampleDecoder *decoder = idSampleDecoder::Alloc(); +- float *destData = (float *)soundCacheAllocator.Alloc((LengthIn44kHzSamples() + 1) * sizeof(float)); ++ float *destData = (float *)soundCacheAllocator.Alloc( ( LengthIn44kHzSamples() + 1 ) * sizeof( float ) ); + + // Decoder *always* outputs 44 kHz data +- decoder->Decode(this, 0, LengthIn44kHzSamples(), destData); ++ decoder->Decode( this, 0, LengthIn44kHzSamples(), destData ); + + // Downsample back to original frequency (save memory) +- if (objectInfo.nSamplesPerSec == 11025) { +- for (int i = 0; i < objectSize; i++) { +- if (destData[i*4] < -32768.0f) ++ if ( objectInfo.nSamplesPerSec == 11025 ) { ++ for ( int i = 0; i < objectSize; i++ ) { ++ if ( destData[i*4] < -32768.0f ) + ((short *)destData)[i] = -32768; +- else if (destData[i*4] > 32767.0f) ++ else if ( destData[i*4] > 32767.0f ) + ((short *)destData)[i] = 32767; + else +- ((short *)destData)[i] = idMath::FtoiFast(destData[i*4]); ++ ((short *)destData)[i] = idMath::FtoiFast( destData[i*4] ); + } +- } else if (objectInfo.nSamplesPerSec == 22050) { +- for (int i = 0; i < objectSize; i++) { +- if (destData[i*2] < -32768.0f) ++ } else if ( objectInfo.nSamplesPerSec == 22050 ) { ++ for ( int i = 0; i < objectSize; i++ ) { ++ if ( destData[i*2] < -32768.0f ) + ((short *)destData)[i] = -32768; +- else if (destData[i*2] > 32767.0f) ++ else if ( destData[i*2] > 32767.0f ) + ((short *)destData)[i] = 32767; + else +- ((short *)destData)[i] = idMath::FtoiFast(destData[i*2]); ++ ((short *)destData)[i] = idMath::FtoiFast( destData[i*2] ); + } + } else { +- for (int i = 0; i < objectSize; i++) { +- if (destData[i] < -32768.0f) ++ for ( int i = 0; i < objectSize; i++ ) { ++ if ( destData[i] < -32768.0f ) + ((short *)destData)[i] = -32768; +- else if (destData[i] > 32767.0f) ++ else if ( destData[i] > 32767.0f ) + ((short *)destData)[i] = 32767; + else +- ((short *)destData)[i] = idMath::FtoiFast(destData[i]); ++ ((short *)destData)[i] = idMath::FtoiFast( destData[i] ); + } + } + + alGetError(); +- alBufferData(openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, destData, objectSize * sizeof(short), objectInfo.nSamplesPerSec); +- +- if (alGetError() != AL_NO_ERROR) +-#ifdef _OPENAL_SOFT +- { +- common->Warning( "idSoundCache: error loading data into OpenAL hardware buffer" ); +- hardwareBuffer = false; +- } +-#else +- common->Error("idSoundCache: error loading data into OpenAL hardware buffer"); +-#endif ++ alBufferData( openalBuffer, objectInfo.nChannels==1?AL_FORMAT_MONO16:AL_FORMAT_STEREO16, destData, objectSize * sizeof( short ), objectInfo.nSamplesPerSec ); ++ if ( alGetError() != AL_NO_ERROR ) ++ common->Error( "idSoundCache: error loading data into OpenAL hardware buffer" ); + else { +-#ifdef _OPENAL_SOFT //k: for large shake in idSoundWorld::CurrentShakeAmplitudeForPosition, using non-OpenAL compute amplitude +- if(harm_s_useAmplitudeDataOpenAL.GetBool()) { +-#endif + // Compute amplitude block size + int blockSize = 512 * objectInfo.nSamplesPerSec / 44100 ; + + // Allocate amplitude data array +- amplitudeData = (byte *)soundCacheAllocator.Alloc((objectSize / blockSize + 1) * 2 * sizeof(short)); ++ amplitudeData = (byte *)soundCacheAllocator.Alloc( ( objectSize / blockSize + 1 ) * 2 * sizeof( short ) ); + + // Creating array of min/max amplitude pairs per blockSize samples + int i; +- +- for (i = 0; i < objectSize; i+=blockSize) { ++ for ( i = 0; i < objectSize; i+=blockSize ) { + short min = 32767; + short max = -32768; + + int j; +- +- for (j = 0; j < Min(objectSize - i, blockSize); j++) { ++ for ( j = 0; j < Min( objectSize - i, blockSize ); j++ ) { + min = ((short *)destData)[ i + j ] < min ? ((short *)destData)[ i + j ] : min; + max = ((short *)destData)[ i + j ] > max ? ((short *)destData)[ i + j ] : max; + } + +- ((short *)amplitudeData)[(i / blockSize) * 2 ] = min; +- ((short *)amplitudeData)[(i / blockSize) * 2 + 1 ] = max; ++ ((short *)amplitudeData)[ ( i / blockSize ) * 2 ] = min; ++ ((short *)amplitudeData)[ ( i / blockSize ) * 2 + 1 ] = max; + } +-#ifdef _OPENAL_SOFT //k: for large shake in idSoundWorld::CurrentShakeAmplitudeForPosition, using non-OpenAL compute amplitude +- } +-#endif + + hardwareBuffer = true; + } + +- soundCacheAllocator.Free((byte *)destData); +- idSampleDecoder::Free(decoder); ++ soundCacheAllocator.Free( (byte *)destData ); ++ idSampleDecoder::Free( decoder ); + } + } + } + + // Free memory if sample was loaded into hardware +-#ifdef _OPENAL_SOFT //k: for large shake in idSoundWorld::CurrentShakeAmplitudeForPosition, using non-OpenAL compute amplitude +- if(harm_s_useAmplitudeDataOpenAL.GetBool()) +-#endif +- if (hardwareBuffer) { +- soundCacheAllocator.Free(nonCacheData); ++ if ( hardwareBuffer ) { ++ soundCacheAllocator.Free( nonCacheData ); + nonCacheData = NULL; + } + } +-#endif ++ + fh.Close(); + } + +@@ -714,37 +621,25 @@ void idSoundSample::Load(void) + idSoundSample::PurgeSoundSample + =================== + */ +-void idSoundSample::PurgeSoundSample() +-{ ++void idSoundSample::PurgeSoundSample() { + purged = true; + +-#ifdef _OPENAL +- if (hardwareBuffer && idSoundSystemLocal::useOpenAL) { +- alGetError(); +- alDeleteBuffers(1, &openalBuffer); +- +- if (alGetError() != AL_NO_ERROR) { +-#ifdef _OPENAL_SOFT +- common->Warning( "idSoundCache: error unloading data from OpenAL hardware buffer" ); +- openalBuffer = 0; +- hardwareBuffer = false; +-#else +- common->Error("idSoundCache: error unloading data from OpenAL hardware buffer"); +-#endif +- } else { +- openalBuffer = 0; +- hardwareBuffer = false; +- } ++ alGetError(); ++ alDeleteBuffers( 1, &openalBuffer ); ++ if ( alGetError() != AL_NO_ERROR ) { ++ common->Error( "idSoundCache: error unloading data from OpenAL hardware buffer" ); ++ } else { ++ openalBuffer = 0; ++ hardwareBuffer = false; + } +-#endif + +- if (amplitudeData) { +- soundCacheAllocator.Free(amplitudeData); ++ if ( amplitudeData ) { ++ soundCacheAllocator.Free( amplitudeData ); + amplitudeData = NULL; + } + +- if (nonCacheData) { +- soundCacheAllocator.Free(nonCacheData); ++ if ( nonCacheData ) { ++ soundCacheAllocator.Free( nonCacheData ); + nonCacheData = NULL; + } + } +@@ -754,29 +649,26 @@ void idSoundSample::PurgeSoundSample() + idSoundSample::Reload + =================== + */ +-void idSoundSample::Reload(bool force) +-{ +- if (!force) { ++void idSoundSample::Reload( bool force ) { ++ if ( !force ) { + ID_TIME_T newTimestamp; + + // check the timestamp + newTimestamp = GetNewTimeStamp(); + +- if (newTimestamp == FILE_NOT_FOUND_TIMESTAMP) { +- if (!defaultSound) { +- common->Warning("Couldn't load sound '%s' using default", name.c_str()); ++ if ( newTimestamp == FILE_NOT_FOUND_TIMESTAMP ) { ++ if ( !defaultSound ) { ++ common->Warning( "Couldn't load sound '%s' using default", name.c_str() ); + MakeDefault(); + } +- + return; + } +- +- if (newTimestamp == timestamp) { ++ if ( newTimestamp == timestamp ) { + return; // don't need to reload it + } + } + +- common->Printf("reloading %s\n", name.c_str()); ++ common->Printf( "reloading %s\n", name.c_str() ); + PurgeSoundSample(); + Load(); + } +@@ -788,29 +680,24 @@ idSoundSample::FetchFromCache + Returns true on success. + =================== + */ +-bool idSoundSample::FetchFromCache(int offset, const byte **output, int *position, int *size, const bool allowIO) +-{ ++bool idSoundSample::FetchFromCache( int offset, const byte **output, int *position, int *size, const bool allowIO ) { + offset &= 0xfffffffe; + +- if (objectSize == 0 || offset < 0 || offset > objectSize * (int)sizeof(short) || !nonCacheData) { ++ if ( objectSize == 0 || offset < 0 || offset > objectSize * (int)sizeof( short ) || !nonCacheData ) { + return false; + } + +- if (output) { ++ if ( output ) { + *output = nonCacheData + offset; + } +- +- if (position) { ++ if ( position ) { + *position = 0; + } +- +- if (size) { +- *size = objectSize * sizeof(short) - offset; +- +- if (*size > SCACHE_SIZE) { ++ if ( size ) { ++ *size = objectSize * sizeof( short ) - offset; ++ if ( *size > SCACHE_SIZE ) { + *size = SCACHE_SIZE; + } + } +- + return true; + } diff --git a/games/idtech4a-engine/patches/patch-sound_snd_decoder_cpp b/games/idtech4a-engine/patches/patch-sound_snd_decoder_cpp new file mode 100644 index 000000000..8a7c94b10 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_decoder_cpp @@ -0,0 +1,951 @@ +Index: sound/snd_decoder.cpp +--- sound/snd_decoder.cpp.orig ++++ sound/snd_decoder.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -29,68 +29,12 @@ If you have questions concerning this license or the a + #include "../idlib/precompiled.h" + #pragma hdrstop + +-#include "snd_local.h" +-#if !defined(_USING_STB_OGG) ++#define OV_EXCLUDE_STATIC_CALLBACKS + #include + #include +-#else +-#if D3_IS_BIG_ENDIAN +- #define STB_VORBIS_BIG_ENDIAN +-#endif +-#define STB_VORBIS_NO_STDIO +-#define STB_VORBIS_NO_PUSHDATA_API // we're using the pulldata API +-#include "../externlibs/stb/stb_vorbis.h" +-#undef L // the implementation part of stb_vorbis has these defines, they confuse other code.. +-#undef C +-#undef R + +-static const char* my_stbv_strerror(int stbVorbisError) +-{ +- switch(stbVorbisError) +- { +- case VORBIS__no_error: return "No Error"; +-#define ERRCASE(X) \ +- case VORBIS_ ## X : return #X; ++#include "snd_local.h" + +- ERRCASE( need_more_data ) // not a real error +- +- ERRCASE( invalid_api_mixing ) // can't mix API modes +- ERRCASE( outofmem ) // not enough memory +- ERRCASE( feature_not_supported ) // uses floor 0 +- ERRCASE( too_many_channels ) // STB_VORBIS_MAX_CHANNELS is too small +- ERRCASE( file_open_failure ) // fopen() failed +- ERRCASE( seek_without_length ) // can't seek in unknown-length file +- +- ERRCASE( unexpected_eof ) // file is truncated? +- ERRCASE( seek_invalid ) // seek past EOF +- +- // decoding errors (corrupt/invalid stream) -- you probably +- // don't care about the exact details of these +- +- // vorbis errors: +- ERRCASE( invalid_setup ) +- ERRCASE( invalid_stream ) +- +- // ogg errors: +- ERRCASE( missing_capture_pattern ) +- ERRCASE( invalid_stream_structure_version ) +- ERRCASE( continued_packet_flag_invalid ) +- ERRCASE( incorrect_stream_serial_number ) +- ERRCASE( invalid_first_page ) +- ERRCASE( bad_packet_type ) +- ERRCASE( cant_find_last_page ) +- ERRCASE( seek_failed ) +- ERRCASE( ogg_skeleton_not_supported ) +- +-#undef ERRCASE +- } +- assert(0 && "unknown stb_vorbis errorcode!"); +- return "Unknown Error!"; +-} +- +-#endif +- +- + /* + =================================================================================== + +@@ -105,39 +49,34 @@ idDynamicBlockAlloc decoderMemoryAl + + const int MIN_OGGVORBIS_MEMORY = 768 * 1024; + +-#if !defined(_USING_STB_OGG) + extern "C" { +- void *_decoder_malloc(size_t size); +- void *_decoder_calloc(size_t num, size_t size); +- void *_decoder_realloc(void *memblock, size_t size); +- void _decoder_free(void *memblock); ++ void *_decoder_malloc( size_t size ); ++ void *_decoder_calloc( size_t num, size_t size ); ++ void *_decoder_realloc( void *memblock, size_t size ); ++ void _decoder_free( void *memblock ); + } + +-void *_decoder_malloc(size_t size) +-{ +- void *ptr = decoderMemoryAllocator.Alloc(size); +- assert(size == 0 || ptr != NULL); ++void *_decoder_malloc( size_t size ) { ++ void *ptr = decoderMemoryAllocator.Alloc( size ); ++ assert( size == 0 || ptr != NULL ); + return ptr; + } + +-void *_decoder_calloc(size_t num, size_t size) +-{ +- void *ptr = decoderMemoryAllocator.Alloc(num * size); +- assert((num * size) == 0 || ptr != NULL); +- memset(ptr, 0, num * size); ++void *_decoder_calloc( size_t num, size_t size ) { ++ void *ptr = decoderMemoryAllocator.Alloc( num * size ); ++ assert( ( num * size ) == 0 || ptr != NULL ); ++ memset( ptr, 0, num * size ); + return ptr; + } + +-void *_decoder_realloc(void *memblock, size_t size) +-{ +- void *ptr = decoderMemoryAllocator.Resize((byte *)memblock, size); +- assert(size == 0 || ptr != NULL); ++void *_decoder_realloc( void *memblock, size_t size ) { ++ void *ptr = decoderMemoryAllocator.Resize( (byte *)memblock, size ); ++ assert( size == 0 || ptr != NULL ); + return ptr; + } + +-void _decoder_free(void *memblock) +-{ +- decoderMemoryAllocator.Free((byte *)memblock); ++void _decoder_free( void *memblock ) { ++ decoderMemoryAllocator.Free( (byte *)memblock ); + } + + +@@ -154,10 +93,9 @@ void _decoder_free(void *memblock) + FS_ReadOGG + ==================== + */ +-size_t FS_ReadOGG(void *dest, size_t size1, size_t size2, void *fh) +-{ ++size_t FS_ReadOGG( void *dest, size_t size1, size_t size2, void *fh ) { + idFile *f = reinterpret_cast(fh); +- return f->Read(dest, size1 * size2); ++ return f->Read( dest, size1 * size2 ); + } + + /* +@@ -165,22 +103,20 @@ size_t FS_ReadOGG(void *dest, size_t size1, size_t siz + FS_SeekOGG + ==================== + */ +-int FS_SeekOGG(void *fh, ogg_int64_t to, int type) +-{ ++int FS_SeekOGG( void *fh, ogg_int64_t to, int type ) { + fsOrigin_t retype = FS_SEEK_SET; + +- if (type == SEEK_CUR) { ++ if ( type == SEEK_CUR ) { + retype = FS_SEEK_CUR; +- } else if (type == SEEK_END) { ++ } else if ( type == SEEK_END ) { + retype = FS_SEEK_END; +- } else if (type == SEEK_SET) { ++ } else if ( type == SEEK_SET ) { + retype = FS_SEEK_SET; + } else { +- common->FatalError("fs_seekOGG: seek without type\n"); ++ common->FatalError( "fs_seekOGG: seek without type\n" ); + } +- + idFile *f = reinterpret_cast(fh); +- return f->Seek(to, retype); ++ return f->Seek( to, retype ); + } + + /* +@@ -188,8 +124,7 @@ int FS_SeekOGG(void *fh, ogg_int64_t to, int type) + FS_CloseOGG + ==================== + */ +-int FS_CloseOGG(void *fh) +-{ ++int FS_CloseOGG( void *fh ) { + return 0; + } + +@@ -198,8 +133,7 @@ int FS_CloseOGG(void *fh) + FS_TellOGG + ==================== + */ +-long FS_TellOGG(void *fh) +-{ ++long FS_TellOGG( void *fh ) { + idFile *f = reinterpret_cast(fh); + return f->Tell(); + } +@@ -209,11 +143,10 @@ long FS_TellOGG(void *fh) + ov_openFile + ==================== + */ +-int ov_openFile(idFile *f, OggVorbis_File *vf) +-{ ++int ov_openFile( idFile *f, OggVorbis_File *vf ) { + ov_callbacks callbacks; + +- memset(vf, 0, sizeof(OggVorbis_File)); ++ memset( vf, 0, sizeof( OggVorbis_File ) ); + + callbacks.read_func = FS_ReadOGG; + callbacks.seek_func = FS_SeekOGG; +@@ -221,58 +154,53 @@ int ov_openFile(idFile *f, OggVorbis_File *vf) + callbacks.tell_func = FS_TellOGG; + return ov_open_callbacks((void *)f, vf, NULL, -1, callbacks); + } +-#endif + + /* + ==================== + idWaveFile::OpenOGG + ==================== + */ +-int idWaveFile::OpenOGG(const char *strFileName, waveformatex_t *pwfx) +-{ +-#if !defined(_USING_STB_OGG) ++int idWaveFile::OpenOGG( const char* strFileName, waveformatex_t *pwfx ) { + OggVorbis_File *ov; + +- memset(pwfx, 0, sizeof(waveformatex_t)); ++ memset( pwfx, 0, sizeof( waveformatex_t ) ); + +- mhmmio = fileSystem->OpenFileRead(strFileName); +- +- if (!mhmmio) { ++ mhmmio = fileSystem->OpenFileRead( strFileName ); ++ if ( !mhmmio ) { + return -1; + } + +- Sys_EnterCriticalSection(CRITICAL_SECTION_ONE); ++ Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); + + ov = new OggVorbis_File; + +- if (ov_openFile(mhmmio, ov) < 0) { ++ if( ov_openFile( mhmmio, ov ) < 0 ) { + delete ov; +- Sys_LeaveCriticalSection(CRITICAL_SECTION_ONE); +- fileSystem->CloseFile(mhmmio); ++ Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); ++ fileSystem->CloseFile( mhmmio ); + mhmmio = NULL; +- common->Warning( "Opening OGG file '%s' with libogg/libvorbis failed.", strFileName ); + return -1; + } + + mfileTime = mhmmio->Timestamp(); + +- vorbis_info *vi = ov_info(ov, -1); ++ vorbis_info *vi = ov_info( ov, -1 ); + + mpwfx.Format.nSamplesPerSec = vi->rate; + mpwfx.Format.nChannels = vi->channels; + mpwfx.Format.wBitsPerSample = sizeof(short) * 8; +- mdwSize = ov_pcm_total(ov, -1) * vi->channels; // pcm samples * num channels ++ mdwSize = ov_pcm_total( ov, -1 ) * vi->channels; // pcm samples * num channels + mbIsReadingFromMemory = false; + +- if (idSoundSystemLocal::s_realTimeDecoding.GetBool()) { ++ if ( idSoundSystemLocal::s_realTimeDecoding.GetBool() ) { + +- ov_clear(ov); +- fileSystem->CloseFile(mhmmio); ++ ov_clear( ov ); ++ fileSystem->CloseFile( mhmmio ); + mhmmio = NULL; + delete ov; + + mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG_OGG; +- mhmmio = fileSystem->OpenFileRead(strFileName); ++ mhmmio = fileSystem->OpenFileRead( strFileName ); + mMemSize = mhmmio->Length(); + + } else { +@@ -280,86 +208,16 @@ int idWaveFile::OpenOGG(const char *strFileName, wavef + ogg = ov; + + mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG_PCM; +- mMemSize = mdwSize * sizeof(short); ++ mMemSize = mdwSize * sizeof( short ); + } + +- memcpy(pwfx, &mpwfx, sizeof(waveformatex_t)); ++ memcpy( pwfx, &mpwfx, sizeof( waveformatex_t ) ); + +- Sys_LeaveCriticalSection(CRITICAL_SECTION_ONE); ++ Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); + + isOgg = true; + + return 0; +-#else +- memset( pwfx, 0, sizeof( waveformatex_t ) ); +- +- mhmmio = fileSystem->OpenFileRead( strFileName ); +- if ( !mhmmio ) { +- return -1; +- } +- +- Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); +- +- int fileSize = mhmmio->Length(); +- byte* oggFileData = (byte*)Mem_Alloc( fileSize ); +- +- mhmmio->Read( oggFileData, fileSize ); +- +- int stbverr = 0; +- stb_vorbis *ov = stb_vorbis_open_memory( oggFileData, fileSize, &stbverr, NULL ); +- if( ov == NULL ) { +- Mem_Free( oggFileData ); +- Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); +- common->Warning( "Opening OGG file '%s' with stb_vorbis failed: %s\n", strFileName, my_stbv_strerror(stbverr) ); +- fileSystem->CloseFile( mhmmio ); +- mhmmio = NULL; +- return -1; +- } +- +- mfileTime = mhmmio->Timestamp(); +- +- stb_vorbis_info stbvi = stb_vorbis_get_info( ov ); +- int numSamples = stb_vorbis_stream_length_in_samples( ov ); +- if(numSamples == 0) { +- stbverr = stb_vorbis_get_error( ov ); +- common->Warning( "Couldn't get sound length of '%s' with stb_vorbis: %s\n", strFileName, my_stbv_strerror(stbverr) ); +- // TODO: return -1 etc? +- } +- +- mpwfx.Format.nSamplesPerSec = stbvi.sample_rate; +- mpwfx.Format.nChannels = stbvi.channels; +- mpwfx.Format.wBitsPerSample = sizeof(short) * 8; +- mdwSize = numSamples * stbvi.channels; // pcm samples * num channels +- mbIsReadingFromMemory = false; +- +- if ( idSoundSystemLocal::s_realTimeDecoding.GetBool() ) { +- +- stb_vorbis_close( ov ); +- fileSystem->CloseFile( mhmmio ); +- mhmmio = NULL; +- Mem_Free( oggFileData ); +- +- mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG_OGG; +- mhmmio = fileSystem->OpenFileRead( strFileName ); +- mMemSize = mhmmio->Length(); +- +- } else { +- +- ogg = ov; +- oggData = oggFileData; +- +- mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG_PCM; +- mMemSize = mdwSize * sizeof( short ); +- } +- +- memcpy( pwfx, &mpwfx, sizeof( waveformatex_t ) ); +- +- Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); +- +- isOgg = true; +- +- return 0; +-#endif + } + + /* +@@ -367,69 +225,30 @@ int idWaveFile::OpenOGG(const char *strFileName, wavef + idWaveFile::ReadOGG + ==================== + */ +-int idWaveFile::ReadOGG(byte *pBuffer, int dwSizeToRead, int *pdwSizeRead) +-{ +-#if !defined(_USING_STB_OGG) ++int idWaveFile::ReadOGG( byte* pBuffer, int dwSizeToRead, int *pdwSizeRead ) { + int total = dwSizeToRead; + char *bufferPtr = (char *)pBuffer; + OggVorbis_File *ov = (OggVorbis_File *) ogg; + + do { +- int ret = ov_read(ov, bufferPtr, total >= 4096 ? 4096 : total, Swap_IsBigEndian(), 2, 1, NULL); +- +- if (ret == 0) { ++ int ret = ov_read( ov, bufferPtr, total >= 4096 ? 4096 : total, Swap_IsBigEndian(), 2, 1, NULL ); ++ if ( ret == 0 ) { + break; + } +- +- if (ret < 0) { ++ if ( ret < 0 ) { + return -1; + } +- + bufferPtr += ret; + total -= ret; +- } while (total > 0); ++ } while( total > 0 ); + + dwSizeToRead = (byte *)bufferPtr - pBuffer; + +- if (pdwSizeRead != NULL) { ++ if ( pdwSizeRead != NULL ) { + *pdwSizeRead = dwSizeToRead; + } + + return dwSizeToRead; +-#else +- // DG: Note that stb_vorbis_get_samples_short_interleaved() operates on shorts, +- // while VorbisFile's ov_read() operates on bytes, so some numbers are different +- int total = dwSizeToRead/sizeof(short); +- short *bufferPtr = (short *)pBuffer; +- stb_vorbis *ov = (stb_vorbis *) ogg; +- +- do { +- int numShorts = total; // total >= 2048 ? 2048 : total; - I think stb_vorbis doesn't mind decoding all of it +- int ret = stb_vorbis_get_samples_short_interleaved( ov, mpwfx.Format.nChannels, bufferPtr, numShorts ); +- if ( ret == 0 ) { +- break; +- } +- if ( ret < 0 ) { +- int stbverr = stb_vorbis_get_error( ov ); +- common->Warning( "idWaveFile::ReadOGG() stb_vorbis_get_samples_short_interleaved() %d shorts failed: %s\n", numShorts, my_stbv_strerror(stbverr) ); +- return -1; +- } +- // for some reason, stb_vorbis_get_samples_short_interleaved() takes the absolute +- // number of shorts to read as a function argument, but returns the number of samples +- // that were read PER CHANNEL +- ret *= mpwfx.Format.nChannels; +- bufferPtr += ret; +- total -= ret; +- } while( total > 0 ); +- +- dwSizeToRead = (byte *)bufferPtr - pBuffer; +- +- if ( pdwSizeRead != NULL ) { +- *pdwSizeRead = dwSizeToRead; +- } +- +- return dwSizeToRead; +-#endif + } + + /* +@@ -437,37 +256,19 @@ int idWaveFile::ReadOGG(byte *pBuffer, int dwSizeToRea + idWaveFile::CloseOGG + ==================== + */ +-int idWaveFile::CloseOGG(void) +-{ +-#if !defined(_USING_STB_OGG) ++int idWaveFile::CloseOGG( void ) { + OggVorbis_File *ov = (OggVorbis_File *) ogg; +- +- if (ov != NULL) { +- Sys_EnterCriticalSection(CRITICAL_SECTION_ONE); +- ov_clear(ov); ++ if ( ov != NULL ) { ++ Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); ++ ov_clear( ov ); + delete ov; +- Sys_LeaveCriticalSection(CRITICAL_SECTION_ONE); +- fileSystem->CloseFile(mhmmio); ++ Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); ++ fileSystem->CloseFile( mhmmio ); + mhmmio = NULL; + ogg = NULL; + return 0; + } + return -1; +-#else +- stb_vorbis* ov = (stb_vorbis *)ogg; +- if ( ov != NULL ) { +- Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); +- stb_vorbis_close( ov ); +- Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); +- fileSystem->CloseFile( mhmmio ); +- mhmmio = NULL; +- ogg = NULL; +- Mem_Free( oggData ); +- oggData = NULL; +- return 0; +- } +- return -1; +-#endif + } + + +@@ -479,31 +280,26 @@ int idWaveFile::CloseOGG(void) + =================================================================================== + */ + +-class idSampleDecoderLocal : public idSampleDecoder +-{ +- public: +- virtual void Decode(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest); +- virtual void ClearDecoder(void); +- virtual idSoundSample *GetSample(void) const; +- virtual int GetLastDecodeTime(void) const; ++class idSampleDecoderLocal : public idSampleDecoder { ++public: ++ virtual void Decode( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ); ++ virtual void ClearDecoder( void ); ++ virtual idSoundSample * GetSample( void ) const; ++ virtual int GetLastDecodeTime( void ) const; + +- void Clear(void); +- int DecodePCM(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest); +- int DecodeOGG(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest); ++ void Clear( void ); ++ int DecodePCM( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ); ++ int DecodeOGG( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ); + +- private: +- bool failed; // set if decoding failed +- int lastFormat; // last format being decoded +- idSoundSample *lastSample; // last sample being decoded +- int lastSampleOffset; // last offset into the decoded sample +- int lastDecodeTime; // last time decoding sound +-#if !defined(_USING_STB_OGG) +- idFile_Memory file; // encoded file in memory ++private: ++ bool failed; // set if decoding failed ++ int lastFormat; // last format being decoded ++ idSoundSample * lastSample; // last sample being decoded ++ int lastSampleOffset; // last offset into the decoded sample ++ int lastDecodeTime; // last time decoding sound ++ idFile_Memory file; // encoded file in memory + +- OggVorbis_File ogg; // OggVorbis file +-#else +- stb_vorbis* stbv; // stb_vorbis (Ogg) handle, using lastSample->nonCacheData +-#endif ++ OggVorbis_File ogg; // OggVorbis file + }; + + idBlockAlloc sampleDecoderAllocator; +@@ -513,11 +309,10 @@ idBlockAlloc sampleDecoderA + idSampleDecoder::Init + ==================== + */ +-void idSampleDecoder::Init(void) +-{ ++void idSampleDecoder::Init( void ) { + decoderMemoryAllocator.Init(); +- decoderMemoryAllocator.SetLockMemory(true); +- decoderMemoryAllocator.SetFixedBlocks(idSoundSystemLocal::s_realTimeDecoding.GetBool() ? 10 : 1); ++ decoderMemoryAllocator.SetLockMemory( true ); ++ decoderMemoryAllocator.SetFixedBlocks( idSoundSystemLocal::s_realTimeDecoding.GetBool() ? 10 : 1 ); + } + + /* +@@ -525,8 +320,7 @@ void idSampleDecoder::Init(void) + idSampleDecoder::Shutdown + ==================== + */ +-void idSampleDecoder::Shutdown(void) +-{ ++void idSampleDecoder::Shutdown( void ) { + decoderMemoryAllocator.Shutdown(); + sampleDecoderAllocator.Shutdown(); + } +@@ -536,8 +330,7 @@ void idSampleDecoder::Shutdown(void) + idSampleDecoder::Alloc + ==================== + */ +-idSampleDecoder *idSampleDecoder::Alloc(void) +-{ ++idSampleDecoder *idSampleDecoder::Alloc( void ) { + idSampleDecoderLocal *decoder = sampleDecoderAllocator.Alloc(); + decoder->Clear(); + return decoder; +@@ -548,11 +341,10 @@ idSampleDecoder *idSampleDecoder::Alloc(void) + idSampleDecoder::Free + ==================== + */ +-void idSampleDecoder::Free(idSampleDecoder *decoder) +-{ +- idSampleDecoderLocal *localDecoder = static_cast(decoder); ++void idSampleDecoder::Free( idSampleDecoder *decoder ) { ++ idSampleDecoderLocal *localDecoder = static_cast( decoder ); + localDecoder->ClearDecoder(); +- sampleDecoderAllocator.Free(localDecoder); ++ sampleDecoderAllocator.Free( localDecoder ); + } + + /* +@@ -560,8 +352,7 @@ void idSampleDecoder::Free(idSampleDecoder *decoder) + idSampleDecoder::GetNumUsedBlocks + ==================== + */ +-int idSampleDecoder::GetNumUsedBlocks(void) +-{ ++int idSampleDecoder::GetNumUsedBlocks( void ) { + return decoderMemoryAllocator.GetNumUsedBlocks(); + } + +@@ -570,8 +361,7 @@ int idSampleDecoder::GetNumUsedBlocks(void) + idSampleDecoder::GetUsedBlockMemory + ==================== + */ +-int idSampleDecoder::GetUsedBlockMemory(void) +-{ ++int idSampleDecoder::GetUsedBlockMemory( void ) { + return decoderMemoryAllocator.GetUsedBlockMemory(); + } + +@@ -580,16 +370,12 @@ int idSampleDecoder::GetUsedBlockMemory(void) + idSampleDecoderLocal::Clear + ==================== + */ +-void idSampleDecoderLocal::Clear(void) +-{ ++void idSampleDecoderLocal::Clear( void ) { + failed = false; + lastFormat = WAVE_FORMAT_TAG_PCM; + lastSample = NULL; + lastSampleOffset = 0; + lastDecodeTime = 0; +-#ifdef _USING_STB_OGG +- stbv = NULL; +-#endif + } + + /* +@@ -597,29 +383,23 @@ void idSampleDecoderLocal::Clear(void) + idSampleDecoderLocal::ClearDecoder + ==================== + */ +-void idSampleDecoderLocal::ClearDecoder(void) +-{ +- Sys_EnterCriticalSection(CRITICAL_SECTION_ONE); ++void idSampleDecoderLocal::ClearDecoder( void ) { ++ Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); + +- switch (lastFormat) { ++ switch( lastFormat ) { + case WAVE_FORMAT_TAG_PCM: { + break; + } + case WAVE_FORMAT_TAG_OGG: { +-#if !defined(_USING_STB_OGG) +- ov_clear(&ogg); +- memset(&ogg, 0, sizeof(ogg)); +-#else +- stb_vorbis_close( stbv ); +- stbv = NULL; +-#endif ++ ov_clear( &ogg ); ++ memset( &ogg, 0, sizeof( ogg ) ); + break; + } + } + + Clear(); + +- Sys_LeaveCriticalSection(CRITICAL_SECTION_ONE); ++ Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); + } + + /* +@@ -627,8 +407,7 @@ void idSampleDecoderLocal::ClearDecoder(void) + idSampleDecoderLocal::GetSample + ==================== + */ +-idSoundSample *idSampleDecoderLocal::GetSample(void) const +-{ ++idSoundSample *idSampleDecoderLocal::GetSample( void ) const { + return lastSample; + } + +@@ -637,8 +416,7 @@ idSoundSample *idSampleDecoderLocal::GetSample(void) c + idSampleDecoderLocal::GetLastDecodeTime + ==================== + */ +-int idSampleDecoderLocal::GetLastDecodeTime(void) const +-{ ++int idSampleDecoderLocal::GetLastDecodeTime( void ) const { + return lastDecodeTime; + } + +@@ -647,31 +425,30 @@ int idSampleDecoderLocal::GetLastDecodeTime(void) cons + idSampleDecoderLocal::Decode + ==================== + */ +-void idSampleDecoderLocal::Decode(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest) +-{ ++void idSampleDecoderLocal::Decode( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ) { + int readSamples44k; + +- if (sample->objectInfo.wFormatTag != lastFormat || sample != lastSample) { ++ if ( sample->objectInfo.wFormatTag != lastFormat || sample != lastSample ) { + ClearDecoder(); + } + + lastDecodeTime = soundSystemLocal.CurrentSoundTime; + +- if (failed) { +- memset(dest, 0, sampleCount44k * sizeof(dest[0])); ++ if ( failed ) { ++ memset( dest, 0, sampleCount44k * sizeof( dest[0] ) ); + return; + } + + // samples can be decoded both from the sound thread and the main thread for shakes +- Sys_EnterCriticalSection(CRITICAL_SECTION_ONE); ++ Sys_EnterCriticalSection( CRITICAL_SECTION_ONE ); + +- switch (sample->objectInfo.wFormatTag) { ++ switch( sample->objectInfo.wFormatTag ) { + case WAVE_FORMAT_TAG_PCM: { +- readSamples44k = DecodePCM(sample, sampleOffset44k, sampleCount44k, dest); ++ readSamples44k = DecodePCM( sample, sampleOffset44k, sampleCount44k, dest ); + break; + } + case WAVE_FORMAT_TAG_OGG: { +- readSamples44k = DecodeOGG(sample, sampleOffset44k, sampleCount44k, dest); ++ readSamples44k = DecodeOGG( sample, sampleOffset44k, sampleCount44k, dest ); + break; + } + default: { +@@ -680,10 +457,10 @@ void idSampleDecoderLocal::Decode(idSoundSample *sampl + } + } + +- Sys_LeaveCriticalSection(CRITICAL_SECTION_ONE); ++ Sys_LeaveCriticalSection( CRITICAL_SECTION_ONE ); + +- if (readSamples44k < sampleCount44k) { +- memset(dest + readSamples44k, 0, (sampleCount44k - readSamples44k) * sizeof(dest[0])); ++ if ( readSamples44k < sampleCount44k ) { ++ memset( dest + readSamples44k, 0, ( sampleCount44k - readSamples44k ) * sizeof( dest[0] ) ); + } + } + +@@ -692,8 +469,7 @@ void idSampleDecoderLocal::Decode(idSoundSample *sampl + idSampleDecoderLocal::DecodePCM + ==================== + */ +-int idSampleDecoderLocal::DecodePCM(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest) +-{ ++int idSampleDecoderLocal::DecodePCM( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ) { + const byte *first; + int pos, size, readSamples; + +@@ -704,29 +480,27 @@ int idSampleDecoderLocal::DecodePCM(idSoundSample *sam + int sampleOffset = sampleOffset44k >> shift; + int sampleCount = sampleCount44k >> shift; + +- if (sample->nonCacheData == NULL) { +- //assert(false); // this should never happen ( note: I've seen that happen with the main thread down in idGameLocal::MapClear clearing entities - TTimo ) +- // DG: see comment in DecodeOGG() +- common->Warning( "Called idSampleDecoderLocal::DecodePCM() on idSoundSample '%s' without nonCacheData\n", sample->name.c_str() ); ++ if ( sample->nonCacheData == NULL ) { ++ assert( false ); // this should never happen ( note: I've seen that happen with the main thread down in idGameLocal::MapClear clearing entities - TTimo ) + failed = true; + return 0; + } + +- if (!sample->FetchFromCache(sampleOffset * sizeof(short), &first, &pos, &size, false)) { ++ if ( !sample->FetchFromCache( sampleOffset * sizeof( short ), &first, &pos, &size, false ) ) { + failed = true; + return 0; + } + +- if (size - pos < sampleCount * sizeof(short)) { +- readSamples = (size - pos) / sizeof(short); ++ if ( size - pos < sampleCount * sizeof( short ) ) { ++ readSamples = ( size - pos ) / sizeof( short ); + } else { + readSamples = sampleCount; + } + + // duplicate samples for 44kHz output +- SIMDProcessor->UpSamplePCMTo44kHz(dest, (const short *)(first+pos), readSamples, sample->objectInfo.nSamplesPerSec, sample->objectInfo.nChannels); ++ SIMDProcessor->UpSamplePCMTo44kHz( dest, (const short *)(first+pos), readSamples, sample->objectInfo.nSamplesPerSec, sample->objectInfo.nChannels ); + +- return (readSamples << shift); ++ return ( readSamples << shift ); + } + + /* +@@ -734,8 +508,7 @@ int idSampleDecoderLocal::DecodePCM(idSoundSample *sam + idSampleDecoderLocal::DecodeOGG + ==================== + */ +-int idSampleDecoderLocal::DecodeOGG(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest) +-{ ++int idSampleDecoderLocal::DecodeOGG( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ) { + int readSamples, totalSamples; + + int shift = 22050 / sample->objectInfo.nSamplesPerSec; +@@ -743,69 +516,31 @@ int idSampleDecoderLocal::DecodeOGG(idSoundSample *sam + int sampleCount = sampleCount44k >> shift; + + // open OGG file if not yet opened +- if (lastSample == NULL) { ++ if ( lastSample == NULL ) { + // make sure there is enough space for another decoder +- if (decoderMemoryAllocator.GetFreeBlockMemory() < MIN_OGGVORBIS_MEMORY) { ++ if ( decoderMemoryAllocator.GetFreeBlockMemory() < MIN_OGGVORBIS_MEMORY ) { + return 0; + } +- +- if (sample->nonCacheData == NULL) { +- //assert(false); // this should never happen +- /* DG: turned this assertion into a warning, because this can happen, at least with +- * the Classic Doom3 mod (when starting a new game). There idSoundCache::EndLevelLoad() +- * purges (with idSoundSample::PurgeSoundSample()) sound/music/cdoomtheme.ogg +- * (the music running in the main menu), which free()s nonCacheData. +- * But afterwards (still during loading) idSoundSystemLocal::currentSoundWorld +- * is set back to menuSoundWorld, which still tries to play that sample, +- * which brings us here. Shortly afterwards the sound world is set to +- * the game soundworld (sw) and that sample is not referenced anymore +- * (until opening the menu again, when that sample is apparently properly reloaded) +- * see also https://github.com/dhewm/dhewm3/issues/461 */ +- common->Warning( "Called idSampleDecoderLocal::DecodeOGG() on idSoundSample '%s' without nonCacheData\n", sample->name.c_str() ); ++ if ( sample->nonCacheData == NULL ) { ++ assert( false ); // this should never happen + failed = true; + return 0; + } +- +-#if !defined(_USING_STB_OGG) +- file.SetData((const char *)sample->nonCacheData, sample->objectMemSize); +- +- if (ov_openFile(&file, &ogg) < 0) { ++ file.SetData( (const char *)sample->nonCacheData, sample->objectMemSize ); ++ if ( ov_openFile( &file, &ogg ) < 0 ) { + failed = true; + return 0; + } +-#else +- assert(stbv == NULL); +- int stbVorbErr = 0; +- stbv = stb_vorbis_open_memory( sample->nonCacheData, sample->objectMemSize, &stbVorbErr, NULL ); +- if ( stbv == NULL ) { +- common->Warning( "idSampleDecoderLocal::DecodeOGG() stb_vorbis_open_memory() for %s failed: %s\n", +- sample->name.c_str(), my_stbv_strerror(stbVorbErr) ); +- failed = true; +- return 0; +- } +-#endif +- + lastFormat = WAVE_FORMAT_TAG_OGG; + lastSample = sample; + } + + // seek to the right offset if necessary +- if (sampleOffset != lastSampleOffset) { +-#if !defined(_USING_STB_OGG) +- if (ov_pcm_seek(&ogg, sampleOffset / sample->objectInfo.nChannels) != 0) { ++ if ( sampleOffset != lastSampleOffset ) { ++ if ( ov_pcm_seek( &ogg, sampleOffset / sample->objectInfo.nChannels ) != 0 ) { + failed = true; + return 0; + } +-#else +- if ( stb_vorbis_seek( stbv, sampleOffset / sample->objectInfo.nChannels ) == 0 ) { +- int stbVorbErr = stb_vorbis_get_error( stbv ); +- int offset = sampleOffset / sample->objectInfo.nChannels; +- common->Warning( "idSampleDecoderLocal::DecodeOGG() stb_vorbis_seek(%d) for %s failed: %s\n", +- offset, sample->name.c_str(), my_stbv_strerror( stbVorbErr ) ); +- failed = true; +- return 0; +- } +-#endif + } + + lastSampleOffset = sampleOffset; +@@ -813,64 +548,26 @@ int idSampleDecoderLocal::DecodeOGG(idSoundSample *sam + // decode OGG samples + totalSamples = sampleCount; + readSamples = 0; +- + do { +-#if !defined(_USING_STB_OGG) + float **samples; +- int ret = ov_read_float(&ogg, &samples, totalSamples / sample->objectInfo.nChannels, NULL); +- +- if (ret == 0) { ++ int ret = ov_read_float( &ogg, &samples, totalSamples / sample->objectInfo.nChannels, NULL ); ++ if ( ret == 0 ) { + failed = true; + break; + } +-#else +- // DG: in contrast to libvorbisfile's ov_read_float(), stb_vorbis_get_samples_float() expects you to +- // pass a buffer to store the decoded samples in, so limit it to 4096 samples/channel per iteration +- float samplesBuf[2][MIXBUFFER_SAMPLES]; +- float* samples[2] = { samplesBuf[0], samplesBuf[1] }; +- int reqSamples = Min( MIXBUFFER_SAMPLES, totalSamples / sample->objectInfo.nChannels ); +- int ret = stb_vorbis_get_samples_float( stbv, sample->objectInfo.nChannels, samples, reqSamples ); +- if ( reqSamples == 0 ) { +- // DG: it happened that sampleCount was an odd number in a *stereo* sound file +- // and eventually totalSamples was 1 and thus reqSamples = totalSamples/2 was 0 +- // so this turned into an endless loop.. it shouldn't happen anymore due to changes +- // in idSoundWorldLocal::ReadFromSaveGame(), but better safe than sorry.. +- common->DPrintf( "idSampleDecoderLocal::DecodeOGG() reqSamples == 0\n for %s ?!\n", sample->name.c_str() ); +- readSamples += totalSamples; +- totalSamples = 0; +- break; +- } +- if ( ret == 0 ) { +- int stbVorbErr = stb_vorbis_get_error( stbv ); +- if ( stbVorbErr == VORBIS__no_error && reqSamples < 5 ) { +- // DG: it sometimes happens that 0 is returned when reqSamples was 1 and there is no error. +- // don't really know why; I'll just (arbitrarily) accept up to 5 "dropped" samples +- ret = reqSamples; // pretend decoding went ok +- common->DPrintf( "idSampleDecoderLocal::DecodeOGG() IGNORING stb_vorbis_get_samples_float() dropping %d (%d) samples\n for %s\n", +- reqSamples, totalSamples, sample->name.c_str() ); +- } else { +- common->Warning( "idSampleDecoderLocal::DecodeOGG() stb_vorbis_get_samples_float() %d (%d) samples\n for %s failed: %s\n", +- reqSamples, totalSamples, sample->name.c_str(), my_stbv_strerror( stbVorbErr ) ); +- failed = true; +- break; +- } +- } +-#endif +- +- if (ret < 0) { ++ if ( ret < 0 ) { + failed = true; + return 0; + } +- + ret *= sample->objectInfo.nChannels; + +- SIMDProcessor->UpSampleOGGTo44kHz(dest + (readSamples << shift), samples, ret, sample->objectInfo.nSamplesPerSec, sample->objectInfo.nChannels); ++ SIMDProcessor->UpSampleOGGTo44kHz( dest + ( readSamples << shift ), samples, ret, sample->objectInfo.nSamplesPerSec, sample->objectInfo.nChannels ); + + readSamples += ret; + totalSamples -= ret; +- } while (totalSamples > 0); ++ } while( totalSamples > 0 ); + + lastSampleOffset += readSamples; + +- return (readSamples << shift); ++ return ( readSamples << shift ); + } diff --git a/games/idtech4a-engine/patches/patch-sound_snd_efxfile_cpp b/games/idtech4a-engine/patches/patch-sound_snd_efxfile_cpp new file mode 100644 index 000000000..d6e511845 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_efxfile_cpp @@ -0,0 +1,568 @@ +Index: sound/snd_efxfile.cpp +--- sound/snd_efxfile.cpp.orig ++++ sound/snd_efxfile.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -30,53 +30,12 @@ If you have questions concerning this license or the a + + #include "snd_local.h" + +-#ifdef _OPENAL +-#ifdef _OPENAL_EFX +-#define mB_to_gain(millibels, property) \ +- _mB_to_gain(millibels,AL_EAXREVERB_MIN_ ## property, AL_EAXREVERB_MAX_ ## property) +- +-static inline ALfloat _mB_to_gain(ALfloat millibels, ALfloat min, ALfloat max) { +- return idMath::ClampFloat(min, max, idMath::Pow(10.0f, millibels / 2000.0f)); +-} +- +-idSoundEffect::idSoundEffect() : +- effect(0) { +-} +- +-idSoundEffect::~idSoundEffect() { +- if (soundSystemLocal.alIsEffect(effect)) +- soundSystemLocal.alDeleteEffects(1, &effect); +-} +- +-bool idSoundEffect::alloc() { +- alGetError(); +- +- ALenum e; +- +- soundSystemLocal.alGenEffects(1, &effect); +- e = alGetError(); +- if (e != AL_NO_ERROR) { +- common->Warning("idSoundEffect::alloc: alGenEffects failed: 0x%x", e); +- return false; +- } +- +- soundSystemLocal.alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB); +- e = alGetError(); +- if (e != AL_NO_ERROR) { +- common->Warning("idSoundEffect::alloc: alEffecti failed: 0x%x", e); +- return false; +- } +- +- return true; +-} +- + /* + =============== + idEFXFile::idEFXFile + =============== + */ +-idEFXFile::idEFXFile( void ) { +-} ++idEFXFile::idEFXFile( void ) { } + + /* + =============== +@@ -101,16 +60,16 @@ idEFXFile::~idEFXFile( void ) { + idEFXFile::FindEffect + =============== + */ +-bool idEFXFile::FindEffect( idStr &name, ALuint *effect ) { ++bool idEFXFile::FindEffect( idStr &name, idSoundEffect **effect, int *index ) { + int i; + + for ( i = 0; i < effects.Num(); i++ ) { +- if ( effects[i]->name == name ) { +- *effect = effects[i]->effect; ++ if ( ( effects[i] ) && ( effects[i]->name == name ) ) { ++ *effect = effects[i]; ++ *index = i; + return true; + } + } +- + return false; + } + +@@ -119,363 +78,113 @@ bool idEFXFile::FindEffect( idStr &name, ALuint *effec + idEFXFile::ReadEffect + =============== + */ +-#define efxi(param, value) \ +- do { \ +- ALint _v = value; \ +- EFXprintf("alEffecti(" #param ", %d)\n", _v); \ +- soundSystemLocal.alEffecti(effect->effect, param, _v); \ +- err = alGetError(); \ +- if (err != AL_NO_ERROR) \ +- common->Warning("alEffecti(" # param ", %d) " \ +- "failed: 0x%x", _v, err); \ +- } while (false) +- +-#define efxf(param, value) \ +- do { \ +- ALfloat _v = value; \ +- EFXprintf("alEffectf(" #param ", %.3f)\n", _v); \ +- soundSystemLocal.alEffectf(effect->effect, param, _v); \ +- err = alGetError(); \ +- if (err != AL_NO_ERROR) \ +- common->Warning("alEffectf(" # param ", %.3f) " \ +- "failed: 0x%x", _v, err); \ +- } while (false) +- +-#define efxfv(param, value0, value1, value2) \ +- do { \ +- ALfloat _v[3]; \ +- _v[0] = value0; \ +- _v[1] = value1; \ +- _v[2] = value2; \ +- EFXprintf("alEffectfv(" #param ", %.3f, %.3f, %.3f)\n", \ +- _v[0], _v[1], _v[2]); \ +- soundSystemLocal.alEffectfv(effect->effect, param, _v); \ +- err = alGetError(); \ +- if (err != AL_NO_ERROR) \ +- common->Warning("alEffectfv(" # param ", %.3f, %.3f, %.3f) " \ +- "failed: 0x%x", _v[0], _v[1], _v[2], err); \ +- } while (false) +- + bool idEFXFile::ReadEffect( idLexer &src, idSoundEffect *effect ) { ++#if ID_OPENAL_EAX + idToken name, token; + + if ( !src.ReadToken( &token ) ) + return false; + + // reverb effect +- if ( token != "reverb" ) { +- // other effect (not supported at the moment) +- src.Error( "idEFXFile::ReadEffect: Unknown effect definition" ); +- +- return false; +- } +- +- src.ReadTokenOnLine( &token ); +- name = token; +- +- if ( !src.ReadToken( &token ) ) +- return false; +- +- if ( token != "{" ) { +- src.Error( "idEFXFile::ReadEffect: { not found, found %s", token.c_str() ); +- return false; +- } +- +- ALenum err; +- alGetError(); +- EFXprintf("Loading EFX effect '%s' (#%u)\n", name.c_str(), effect->effect); +- +- do { +- if ( !src.ReadToken( &token ) ) { +- src.Error( "idEFXFile::ReadEffect: EOF without closing brace" ); +- return false; +- } +- +- if ( token == "}" ) { +- effect->name = name; +- break; +- } +- +- if ( token == "environment" ) { +- // <+KittyCat> the "environment" token should be ignored (efx has nothing equatable to it) +- src.ParseInt(); +- } else if ( token == "environment size" ) { +- // +- // The formula for density according to Creative's EFX-Util.lib: +- // density = clamp(pow(size, 3) / 16, 0, 1) +- // +- float size = src.ParseFloat(); +- size = idMath::ClampFloat(0.0f, 1.0f, (size * size * size) / 16.0f); +- efxf(AL_EAXREVERB_DENSITY, size); +- } else if ( token == "environment diffusion" ) { +- efxf(AL_EAXREVERB_DIFFUSION, src.ParseFloat()); +- } else if ( token == "room" ) { +- efxf(AL_EAXREVERB_GAIN, mB_to_gain(src.ParseInt(), GAIN)); +- } else if ( token == "room hf" ) { +- efxf(AL_EAXREVERB_GAINHF, mB_to_gain(src.ParseInt(), GAINHF)); +- } else if ( token == "room lf" ) { +- efxf(AL_EAXREVERB_GAINLF, mB_to_gain(src.ParseInt(), GAINLF)); +- } else if ( token == "decay time" ) { +- efxf(AL_EAXREVERB_DECAY_TIME, src.ParseFloat()); +- } else if ( token == "decay hf ratio" ) { +- efxf(AL_EAXREVERB_DECAY_HFRATIO, src.ParseFloat()); +- } else if ( token == "decay lf ratio" ) { +- efxf(AL_EAXREVERB_DECAY_LFRATIO, src.ParseFloat()); +- } else if ( token == "reflections" ) { +- efxf(AL_EAXREVERB_REFLECTIONS_GAIN, mB_to_gain(src.ParseInt(), REFLECTIONS_GAIN)); +- } else if ( token == "reflections delay" ) { +- efxf(AL_EAXREVERB_REFLECTIONS_DELAY, src.ParseFloat()); +- } else if ( token == "reflections pan" ) { +- efxfv(AL_EAXREVERB_REFLECTIONS_PAN, src.ParseFloat(), src.ParseFloat(), src.ParseFloat()); +- } else if ( token == "reverb" ) { +- efxf(AL_EAXREVERB_LATE_REVERB_GAIN, mB_to_gain(src.ParseInt(), LATE_REVERB_GAIN)); +- } else if ( token == "reverb delay" ) { +- efxf(AL_EAXREVERB_LATE_REVERB_DELAY, src.ParseFloat()); +- } else if ( token == "reverb pan" ) { +- efxfv(AL_EAXREVERB_LATE_REVERB_PAN, src.ParseFloat(), src.ParseFloat(), src.ParseFloat()); +- } else if ( token == "echo time" ) { +- efxf(AL_EAXREVERB_ECHO_TIME, src.ParseFloat()); +- } else if ( token == "echo depth" ) { +- efxf(AL_EAXREVERB_ECHO_DEPTH, src.ParseFloat()); +- } else if ( token == "modulation time" ) { +- efxf(AL_EAXREVERB_MODULATION_TIME, src.ParseFloat()); +- } else if ( token == "modulation depth" ) { +- efxf(AL_EAXREVERB_MODULATION_DEPTH, src.ParseFloat()); +- } else if ( token == "air absorption hf" ) { +- efxf(AL_EAXREVERB_AIR_ABSORPTION_GAINHF, mB_to_gain(src.ParseFloat(), AIR_ABSORPTION_GAINHF)); +- } else if ( token == "hf reference" ) { +- efxf(AL_EAXREVERB_HFREFERENCE, src.ParseFloat()); +- } else if ( token == "lf reference" ) { +- efxf(AL_EAXREVERB_LFREFERENCE, src.ParseFloat()); +- } else if ( token == "room rolloff factor" ) { +- efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, src.ParseFloat()); +- } else if ( token == "flags" ) { ++ if ( token == "reverb" ) { ++ EAXREVERBPROPERTIES *reverb = ( EAXREVERBPROPERTIES * )Mem_Alloc( sizeof( EAXREVERBPROPERTIES ) ); ++ if ( reverb ) { + src.ReadTokenOnLine( &token ); +- unsigned int flags = token.GetUnsignedLongValue(); +- +- efxi(AL_EAXREVERB_DECAY_HFLIMIT, (flags & 0x20) ? AL_TRUE : AL_FALSE); +- // the other SCALE flags have no equivalent in efx +- } else { +- src.ReadTokenOnLine( &token ); +- src.Error( "idEFXFile::ReadEffect: Invalid parameter in reverb definition" ); +- } +- } while ( 1 ); +- +- return true; +-} +- +-/* +-=============== +-idEFXFile::LoadFile +-=============== +-*/ +-bool idEFXFile::LoadFile( const char *filename, bool OSPath ) { +- idLexer src( LEXFL_NOSTRINGCONCAT ); +- idToken token; +- +- src.LoadFile( filename, OSPath ); +- if ( !src.IsLoaded() ) { +- return false; +- } +- +- if ( !src.ExpectTokenString( "Version" ) ) { +- return false; +- } +- +- if ( src.ParseInt() != 1 ) { +- src.Error( "idEFXFile::LoadFile: Unknown file version" ); +- return false; +- } +- +- while ( !src.EndOfFile() ) { +- idSoundEffect *effect = new idSoundEffect; +- +- if (!effect->alloc()) { +- delete effect; +- Clear(); +- return false; +- } +- +- if (ReadEffect(src, effect)) +- effects.Append(effect); +- else +- delete effect; +- }; +- +- return true; +-} +- +- +-/* +-=============== +-idEFXFile::UnloadFile +-=============== +-*/ +-void idEFXFile::UnloadFile(void) +-{ +- Clear(); +-} +- +-#else +-/* +-=============== +-idEFXFile::idEFXFile +-=============== +-*/ +-idEFXFile::idEFXFile(void) { } +- +-/* +-=============== +-idEFXFile::Clear +-=============== +-*/ +-void idEFXFile::Clear(void) +-{ +- effects.DeleteContents(true); +-} +- +-/* +-=============== +-idEFXFile::~idEFXFile +-=============== +-*/ +-idEFXFile::~idEFXFile(void) +-{ +- Clear(); +-} +- +-/* +-=============== +-idEFXFile::FindEffect +-=============== +-*/ +-bool idEFXFile::FindEffect(idStr &name, idSoundEffect **effect, int *index) +-{ +- int i; +- +- for (i = 0; i < effects.Num(); i++) { +- if ((effects[i]) && (effects[i]->name == name)) { +- *effect = effects[i]; +- *index = i; +- return true; +- } +- } +- +- return false; +-} +- +-/* +-=============== +-idEFXFile::ReadEffect +-=============== +-*/ +-bool idEFXFile::ReadEffect(idLexer &src, idSoundEffect *effect) +-{ +- idToken name, token; +- +- if (!src.ReadToken(&token)) +- return false; +- +- // reverb effect +- if (token == "reverb") { +- EAXREVERBPROPERTIES *reverb = (EAXREVERBPROPERTIES *)Mem_Alloc(sizeof(EAXREVERBPROPERTIES)); +- +- if (reverb) { +- src.ReadTokenOnLine(&token); + name = token; + +- if (!src.ReadToken(&token)) { +- Mem_Free(reverb); ++ if ( !src.ReadToken( &token ) ) { ++ Mem_Free( reverb ); + return false; + } + +- if (token != "{") { +- src.Error("idEFXFile::ReadEffect: { not found, found %s", token.c_str()); +- Mem_Free(reverb); ++ if ( token != "{" ) { ++ src.Error( "idEFXFile::ReadEffect: { not found, found %s", token.c_str() ); ++ Mem_Free( reverb ); + return false; + } + + do { +- if (!src.ReadToken(&token)) { +- src.Error("idEFXFile::ReadEffect: EOF without closing brace"); +- Mem_Free(reverb); ++ if ( !src.ReadToken( &token ) ) { ++ src.Error( "idEFXFile::ReadEffect: EOF without closing brace" ); ++ Mem_Free( reverb ); + return false; + } + +- if (token == "}") { ++ if ( token == "}" ) { + effect->name = name; +- effect->data = (void *)reverb; +- effect->datasize = sizeof(EAXREVERBPROPERTIES); ++ effect->data = ( void * )reverb; ++ effect->datasize = sizeof( EAXREVERBPROPERTIES ); + break; + } + +- if (token == "environment") { +- src.ReadTokenOnLine(&token); ++ if ( token == "environment" ) { ++ src.ReadTokenOnLine( &token ); + reverb->ulEnvironment = token.GetUnsignedLongValue(); +- } else if (token == "environment size") { ++ } else if ( token == "environment size" ) { + reverb->flEnvironmentSize = src.ParseFloat(); +- } else if (token == "environment diffusion") { ++ } else if ( token == "environment diffusion" ) { + reverb->flEnvironmentDiffusion = src.ParseFloat(); +- } else if (token == "room") { ++ } else if ( token == "room" ) { + reverb->lRoom = src.ParseInt(); +- } else if (token == "room hf") { ++ } else if ( token == "room hf" ) { + reverb->lRoomHF = src.ParseInt(); +- } else if (token == "room lf") { ++ } else if ( token == "room lf" ) { + reverb->lRoomLF = src.ParseInt(); +- } else if (token == "decay time") { ++ } else if ( token == "decay time" ) { + reverb->flDecayTime = src.ParseFloat(); +- } else if (token == "decay hf ratio") { ++ } else if ( token == "decay hf ratio" ) { + reverb->flDecayHFRatio = src.ParseFloat(); +- } else if (token == "decay lf ratio") { ++ } else if ( token == "decay lf ratio" ) { + reverb->flDecayLFRatio = src.ParseFloat(); +- } else if (token == "reflections") { ++ } else if ( token == "reflections" ) { + reverb->lReflections = src.ParseInt(); +- } else if (token == "reflections delay") { ++ } else if ( token == "reflections delay" ) { + reverb->flReflectionsDelay = src.ParseFloat(); +- } else if (token == "reflections pan") { ++ } else if ( token == "reflections pan" ) { + reverb->vReflectionsPan.x = src.ParseFloat(); + reverb->vReflectionsPan.y = src.ParseFloat(); + reverb->vReflectionsPan.z = src.ParseFloat(); +- } else if (token == "reverb") { ++ } else if ( token == "reverb" ) { + reverb->lReverb = src.ParseInt(); +- } else if (token == "reverb delay") { ++ } else if ( token == "reverb delay" ) { + reverb->flReverbDelay = src.ParseFloat(); +- } else if (token == "reverb pan") { ++ } else if ( token == "reverb pan" ) { + reverb->vReverbPan.x = src.ParseFloat(); + reverb->vReverbPan.y = src.ParseFloat(); + reverb->vReverbPan.z = src.ParseFloat(); +- } else if (token == "echo time") { ++ } else if ( token == "echo time" ) { + reverb->flEchoTime = src.ParseFloat(); +- } else if (token == "echo depth") { ++ } else if ( token == "echo depth" ) { + reverb->flEchoDepth = src.ParseFloat(); +- } else if (token == "modulation time") { ++ } else if ( token == "modulation time" ) { + reverb->flModulationTime = src.ParseFloat(); +- } else if (token == "modulation depth") { ++ } else if ( token == "modulation depth" ) { + reverb->flModulationDepth = src.ParseFloat(); +- } else if (token == "air absorption hf") { ++ } else if ( token == "air absorption hf" ) { + reverb->flAirAbsorptionHF = src.ParseFloat(); +- } else if (token == "hf reference") { ++ } else if ( token == "hf reference" ) { + reverb->flHFReference = src.ParseFloat(); +- } else if (token == "lf reference") { ++ } else if ( token == "lf reference" ) { + reverb->flLFReference = src.ParseFloat(); +- } else if (token == "room rolloff factor") { ++ } else if ( token == "room rolloff factor" ) { + reverb->flRoomRolloffFactor = src.ParseFloat(); +- } else if (token == "flags") { +- src.ReadTokenOnLine(&token); ++ } else if ( token == "flags" ) { ++ src.ReadTokenOnLine( &token ); + reverb->ulFlags = token.GetUnsignedLongValue(); + } else { +- src.ReadTokenOnLine(&token); +- src.Error("idEFXFile::ReadEffect: Invalid parameter in reverb definition"); +- Mem_Free(reverb); ++ src.ReadTokenOnLine( &token ); ++ src.Error( "idEFXFile::ReadEffect: Invalid parameter in reverb definition" ); ++ Mem_Free( reverb ); + } +- } while (1); ++ } while ( 1 ); + + return true; + } + } else { + // other effect (not supported at the moment) +- src.Error("idEFXFile::ReadEffect: Unknown effect definition"); ++ src.Error( "idEFXFile::ReadEffect: Unknown effect definition" ); + } ++#endif + + return false; + } +@@ -486,31 +195,28 @@ bool idEFXFile::ReadEffect(idLexer &src, idSoundEffect + idEFXFile::LoadFile + =============== + */ +-bool idEFXFile::LoadFile(const char *filename, bool OSPath) +-{ +- idLexer src(LEXFL_NOSTRINGCONCAT); ++bool idEFXFile::LoadFile( const char *filename, bool OSPath ) { ++ idLexer src( LEXFL_NOSTRINGCONCAT ); + idToken token; + +- src.LoadFile(filename, OSPath); +- +- if (!src.IsLoaded()) { ++ src.LoadFile( filename, OSPath ); ++ if ( !src.IsLoaded() ) { + return false; + } + +- if (!src.ExpectTokenString("Version")) { ++ if ( !src.ExpectTokenString( "Version" ) ) { + return NULL; + } + +- if (src.ParseInt() != 1) { +- src.Error("idEFXFile::LoadFile: Unknown file version"); ++ if ( src.ParseInt() != 1 ) { ++ src.Error( "idEFXFile::LoadFile: Unknown file version" ); + return false; + } + +- while (!src.EndOfFile()) { ++ while ( !src.EndOfFile() ) { + idSoundEffect *effect = new idSoundEffect; +- +- if (ReadEffect(src, effect)) { +- effects.Append(effect); ++ if ( ReadEffect( src, effect ) ) { ++ effects.Append( effect ); + } + }; + +@@ -523,25 +229,6 @@ bool idEFXFile::LoadFile(const char *filename, bool OS + idEFXFile::UnloadFile + =============== + */ +-void idEFXFile::UnloadFile(void) +-{ ++void idEFXFile::UnloadFile( void ) { + Clear(); + } +- +-const GUID EAXPROPERTYID_EAX40_FXSlot0 = +-{ +- 0xC4D79F1E, +- 0xF1AC, +- 0x436B, +- {0xA8, 0x1D, 0xA7, 0x38, 0xE7, 0x04, 0x54, 0x69} +-}; +- +-const GUID EAXPROPERTYID_EAX40_Source = +-{ +- 0x1B86B823, +- 0x22DF, +- 0x4EAE, +- {0x8B, 0x3C, 0x12, 0x78, 0xCE, 0x54, 0x42, 0x27} +-}; +-#endif +-#endif diff --git a/games/idtech4a-engine/patches/patch-sound_snd_emitter_cpp b/games/idtech4a-engine/patches/patch-sound_snd_emitter_cpp new file mode 100644 index 000000000..547028148 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_emitter_cpp @@ -0,0 +1,1460 @@ +Index: sound/snd_emitter.cpp +--- sound/snd_emitter.cpp.orig ++++ sound/snd_emitter.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -37,8 +37,7 @@ If you have questions concerning this license or the a + idSoundFade::Clear + =================== + */ +-void idSoundFade::Clear() +-{ ++void idSoundFade::Clear() { + fadeStart44kHz = 0; + fadeEnd44kHz = 0; + fadeStartVolume = 0; +@@ -50,20 +49,18 @@ void idSoundFade::Clear() + idSoundFade::FadeDbAt44kHz + =================== + */ +-float idSoundFade::FadeDbAt44kHz(int current44kHz) +-{ ++float idSoundFade::FadeDbAt44kHz( int current44kHz ) { + float fadeDb; + +- if (current44kHz >= fadeEnd44kHz) { ++ if ( current44kHz >= fadeEnd44kHz ) { + fadeDb = fadeEndVolume; +- } else if (current44kHz > fadeStart44kHz) { +- float fraction = (fadeEnd44kHz - fadeStart44kHz); +- float over = (current44kHz - fadeStart44kHz); +- fadeDb = fadeStartVolume + (fadeEndVolume - fadeStartVolume) * over / fraction; ++ } else if ( current44kHz > fadeStart44kHz ) { ++ float fraction = ( fadeEnd44kHz - fadeStart44kHz ); ++ float over = ( current44kHz - fadeStart44kHz ); ++ fadeDb = fadeStartVolume + ( fadeEndVolume - fadeStartVolume ) * over / fraction; + } else { + fadeDb = fadeStartVolume; + } +- + return fadeDb; + } + +@@ -87,12 +84,10 @@ permute 4 = 201 + permute 5 = 210 + ======================= + */ +-void PermuteList_r(int *list, int listLength, int permute, int maxPermute) +-{ +- if (listLength < 2) { ++void PermuteList_r( int *list, int listLength, int permute, int maxPermute ) { ++ if ( listLength < 2 ) { + return; + } +- + permute %= maxPermute; + int swap = permute * listLength / maxPermute; + int old = list[swap]; +@@ -100,57 +95,49 @@ void PermuteList_r(int *list, int listLength, int perm + list[0] = old; + + maxPermute /= listLength; +- PermuteList_r(list + 1, listLength - 1, permute, maxPermute); ++ PermuteList_r( list + 1, listLength - 1, permute, maxPermute ); + } + +-int Factorial(int val) +-{ ++int Factorial( int val ) { + int fact = val; +- +- while (val > 1) { ++ while ( val > 1 ) { + val--; + fact *= val; + } +- + return fact; + } + +-void GeneratePermutedList(int *list, int listLength, int permute) +-{ +- for (int i = 0 ; i < listLength ; i++) { ++void GeneratePermutedList( int *list, int listLength, int permute ) { ++ for ( int i = 0 ; i < listLength ; i++ ) { + list[i] = i; + } + + // we can't calculate > 12 factorial, so we can't easily build a permuted list +- if (listLength > 12) { ++ if ( listLength > 12 ) { + return; + } + + // calculate listLength factorial +- int maxPermute = Factorial(listLength); ++ int maxPermute = Factorial( listLength ); + + // recursively permute +- PermuteList_r(list, listLength, permute, maxPermute); ++ PermuteList_r( list, listLength, permute, maxPermute ); + } + +-void TestPermutations(void) +-{ ++void TestPermutations( void ) { + int list[SOUND_MAX_LIST_WAVS]; + +- for (int len = 1 ; len < 5 ; len++) { +- common->Printf("list length: %i\n", len); ++ for ( int len = 1 ; len < 5 ; len++ ) { ++ common->Printf( "list length: %i\n", len ); + +- int max = Factorial(len); +- +- for (int j = 0 ; j < max * 2 ; j++) { +- GeneratePermutedList(list, len, j); +- common->Printf("%4i : ", j); +- +- for (int k = 0 ; k < len ; k++) { +- common->Printf("%i", list[k]); ++ int max = Factorial( len ); ++ for ( int j = 0 ; j < max * 2 ; j++ ) { ++ GeneratePermutedList( list, len, j ); ++ common->Printf( "%4i : ", j ); ++ for ( int k = 0 ; k < len ; k++ ) { ++ common->Printf( "%i", list[k] ); + } +- +- common->Printf("\n"); ++ common->Printf( "\n" ); + } + } + } +@@ -162,8 +149,7 @@ void TestPermutations(void) + idSoundChannel::idSoundChannel + =================== + */ +-idSoundChannel::idSoundChannel(void) +-{ ++idSoundChannel::idSoundChannel( void ) { + decoder = NULL; + Clear(); + } +@@ -173,8 +159,7 @@ idSoundChannel::idSoundChannel(void) + idSoundChannel::~idSoundChannel + =================== + */ +-idSoundChannel::~idSoundChannel(void) +-{ ++idSoundChannel::~idSoundChannel( void ) { + Clear(); + } + +@@ -183,8 +168,7 @@ idSoundChannel::~idSoundChannel(void) + idSoundChannel::Clear + =================== + */ +-void idSoundChannel::Clear(void) +-{ ++void idSoundChannel::Clear( void ) { + int j; + + Stop(); +@@ -195,12 +179,10 @@ void idSoundChannel::Clear(void) + diversity = 0.0f; + leadinSample = NULL; + trigger44kHzTime = 0; +- +- for (j = 0; j < 6; j++) { ++ for( j = 0; j < 6; j++ ) { + lastV[j] = 0.0f; + } +- +- memset(&parms, 0, sizeof(parms)); ++ memset( &parms, 0, sizeof(parms) ); + #ifdef _HUMANHEAD + parms.subIndex = -1; + #endif +@@ -217,11 +199,9 @@ void idSoundChannel::Clear(void) + idSoundChannel::Start + =================== + */ +-void idSoundChannel::Start(void) +-{ ++void idSoundChannel::Start( void ) { + triggerState = true; +- +- if (decoder == NULL) { ++ if ( decoder == NULL ) { + decoder = idSampleDecoder::Alloc(); + } + } +@@ -231,12 +211,10 @@ void idSoundChannel::Start(void) + idSoundChannel::Stop + =================== + */ +-void idSoundChannel::Stop(void) +-{ ++void idSoundChannel::Stop( void ) { + triggerState = false; +- +- if (decoder != NULL) { +- idSampleDecoder::Free(decoder); ++ if ( decoder != NULL ) { ++ idSampleDecoder::Free( decoder ); + decoder = NULL; + } + } +@@ -246,41 +224,28 @@ void idSoundChannel::Stop(void) + idSoundChannel::ALStop + =================== + */ +-void idSoundChannel::ALStop(void) +-{ +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL) { ++void idSoundChannel::ALStop( void ) { ++ if ( alIsSource( openalSource ) ) { ++ alSourceStop( openalSource ); ++ alSourcei( openalSource, AL_BUFFER, 0 ); ++ soundSystemLocal.FreeOpenALSource( openalSource ); ++ } + +- if (alIsSource(openalSource)) { +- alSourceStop(openalSource); +- alSourcei(openalSource, AL_BUFFER, 0); +-#ifdef _OPENAL_EFX +- // unassociate effect slot from source, so the effect slot can be deleted on shutdown +- // even though the source itself is deleted later (in idSoundSystemLocal::Shutdown()) +- alSource3i( openalSource, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL ); +-#endif +- soundSystemLocal.FreeOpenALSource(openalSource); ++ if ( openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2] ) { ++ alGetError(); ++ alDeleteBuffers( 3, &openalStreamingBuffer[0] ); ++ if ( alGetError() == AL_NO_ERROR ) { ++ openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; + } ++ } + +- if (openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2]) { +- alGetError(); +- alDeleteBuffers(3, &openalStreamingBuffer[0]); +- +- if (alGetError() == AL_NO_ERROR) { +- openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; +- } ++ if ( lastopenalStreamingBuffer[0] && lastopenalStreamingBuffer[1] && lastopenalStreamingBuffer[2] ) { ++ alGetError(); ++ alDeleteBuffers( 3, &lastopenalStreamingBuffer[0] ); ++ if ( alGetError() == AL_NO_ERROR ) { ++ lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; + } +- +- if (lastopenalStreamingBuffer[0] && lastopenalStreamingBuffer[1] && lastopenalStreamingBuffer[2]) { +- alGetError(); +- alDeleteBuffers(3, &lastopenalStreamingBuffer[0]); +- +- if (alGetError() == AL_NO_ERROR) { +- lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; +- } +- } + } +-#endif + } + + /* +@@ -292,22 +257,19 @@ out of the range of the unlooped samples. Handles loo + samples and leadins + =================== + */ +-void idSoundChannel::GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest) const +-{ ++void idSoundChannel::GatherChannelSamples( int sampleOffset44k, int sampleCount44k, float *dest ) const { + float *dest_p = dest; + int len; + + //Sys_DebugPrintf( "msec:%i sample:%i : %i : %i\n", Sys_Milliseconds(), soundSystemLocal.GetCurrent44kHzTime(), sampleOffset44k, sampleCount44k ); //!@# + + // negative offset times will just zero fill +- if (sampleOffset44k < 0) { ++ if ( sampleOffset44k < 0 ) { + len = -sampleOffset44k; +- +- if (len > sampleCount44k) { ++ if ( len > sampleCount44k ) { + len = sampleCount44k; + } +- +- memset(dest_p, 0, len * sizeof(dest_p[0])); ++ memset( dest_p, 0, len * sizeof( dest_p[0] ) ); + dest_p += len; + sampleCount44k -= len; + sampleOffset44k += len; +@@ -315,21 +277,19 @@ void idSoundChannel::GatherChannelSamples(int sampleOf + + // grab part of the leadin sample + idSoundSample *leadin = leadinSample; +- +- if (!leadin || sampleOffset44k < 0 || sampleCount44k <= 0) { +- memset(dest_p, 0, sampleCount44k * sizeof(dest_p[0])); ++ if ( !leadin || sampleOffset44k < 0 || sampleCount44k <= 0 ) { ++ memset( dest_p, 0, sampleCount44k * sizeof( dest_p[0] ) ); + return; + } + +- if (sampleOffset44k < leadin->LengthIn44kHzSamples()) { ++ if ( sampleOffset44k < leadin->LengthIn44kHzSamples() ) { + len = leadin->LengthIn44kHzSamples() - sampleOffset44k; +- +- if (len > sampleCount44k) { ++ if ( len > sampleCount44k ) { + len = sampleCount44k; + } + + // decode the sample +- decoder->Decode(leadin, sampleOffset44k, len, dest_p); ++ decoder->Decode( leadin, sampleOffset44k, len, dest_p ); + + dest_p += len; + sampleCount44k -= len; +@@ -337,34 +297,33 @@ void idSoundChannel::GatherChannelSamples(int sampleOf + } + + // if not looping, zero fill any remaining spots +- if (!soundShader || !(parms.soundShaderFlags & SSF_LOOPING)) { +- memset(dest_p, 0, sampleCount44k * sizeof(dest_p[0])); ++ if ( !soundShader || !( parms.soundShaderFlags & SSF_LOOPING ) ) { ++ memset( dest_p, 0, sampleCount44k * sizeof( dest_p[0] ) ); + return; + } + + // fill the remainder with looped samples + idSoundSample *loop = soundShader->entries[0]; + +- if (!loop) { +- memset(dest_p, 0, sampleCount44k * sizeof(dest_p[0])); ++ if ( !loop ) { ++ memset( dest_p, 0, sampleCount44k * sizeof( dest_p[0] ) ); + return; + } + + sampleOffset44k -= leadin->LengthIn44kHzSamples(); + +- while (sampleCount44k > 0) { ++ while( sampleCount44k > 0 ) { + int totalLen = loop->LengthIn44kHzSamples(); + + sampleOffset44k %= totalLen; + + len = totalLen - sampleOffset44k; +- +- if (len > sampleCount44k) { ++ if ( len > sampleCount44k ) { + len = sampleCount44k; + } + + // decode the sample +- decoder->Decode(loop, sampleOffset44k, len, dest_p); ++ decoder->Decode( loop, sampleOffset44k, len, dest_p ); + + dest_p += len; + sampleCount44k -= len; +@@ -381,8 +340,7 @@ idSoundEmitterLocal::idSoundEmitterLocal + + =============== + */ +-idSoundEmitterLocal::idSoundEmitterLocal(void) +-{ ++idSoundEmitterLocal::idSoundEmitterLocal( void ) { + soundWorld = NULL; + Clear(); + } +@@ -392,8 +350,7 @@ idSoundEmitterLocal::idSoundEmitterLocal(void) + idSoundEmitterLocal::~idSoundEmitterLocal + =============== + */ +-idSoundEmitterLocal::~idSoundEmitterLocal(void) +-{ ++idSoundEmitterLocal::~idSoundEmitterLocal( void ) { + Clear(); + } + +@@ -402,11 +359,10 @@ idSoundEmitterLocal::~idSoundEmitterLocal(void) + idSoundEmitterLocal::Clear + =============== + */ +-void idSoundEmitterLocal::Clear(void) +-{ ++void idSoundEmitterLocal::Clear( void ) { + int i; + +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + channels[i].ALStop(); + channels[i].Clear(); + } +@@ -423,7 +379,7 @@ void idSoundEmitterLocal::Clear(void) + maxDistance = 10.0f; // meters + spatializedOrigin.Zero(); + +- memset(&parms, 0, sizeof(parms)); ++ memset( &parms, 0, sizeof( parms ) ); + #ifdef _HUMANHEAD + parms.subIndex = -1; + #endif +@@ -434,39 +390,33 @@ void idSoundEmitterLocal::Clear(void) + idSoundEmitterLocal::OverrideParms + ================== + */ +-void idSoundEmitterLocal::OverrideParms(const soundShaderParms_t *base, +- const soundShaderParms_t *over, soundShaderParms_t *out) +-{ +- if (!over) { ++void idSoundEmitterLocal::OverrideParms( const soundShaderParms_t *base, ++ const soundShaderParms_t *over, soundShaderParms_t *out ) { ++ if ( !over ) { + *out = *base; + return; + } +- +- if (over->minDistance) { ++ if ( over->minDistance ) { + out->minDistance = over->minDistance; + } else { + out->minDistance = base->minDistance; + } +- +- if (over->maxDistance) { ++ if ( over->maxDistance ) { + out->maxDistance = over->maxDistance; + } else { + out->maxDistance = base->maxDistance; + } +- +- if (over->shakes) { ++ if ( over->shakes ) { + out->shakes = over->shakes; + } else { + out->shakes = base->shakes; + } +- +- if (over->volume) { ++ if ( over->volume ) { + out->volume = over->volume; + } else { + out->volume = base->volume; + } +- +- if (over->soundClass) { ++ if ( over->soundClass ) { + out->soundClass = over->soundClass; + } else { + out->soundClass = base->soundClass; +@@ -497,7 +447,6 @@ void idSoundEmitterLocal::OverrideParms(const soundSha + out->profanityDuration = base->profanityDuration; + } + #endif +- + out->soundShaderFlags = base->soundShaderFlags | over->soundShaderFlags; + } + +@@ -509,87 +458,74 @@ Checks to see if all the channels have completed, clea + Sets the playing and shakes bools. + ================== + */ +-void idSoundEmitterLocal::CheckForCompletion(int current44kHzTime) +-{ ++void idSoundEmitterLocal::CheckForCompletion( int current44kHzTime ) { + bool hasActive; + int i; + + hasActive = false; + hasShakes = false; + +- if (playing) { +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ if ( playing ) { ++ for ( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } +- + const idSoundShader *shader = chan->soundShader; +- +- if (!shader) { ++ if ( !shader ) { + continue; + } + + // see if this channel has completed +- if (!(chan->parms.soundShaderFlags & SSF_LOOPING)) { +-#ifdef _OPENAL ++ if ( !( chan->parms.soundShaderFlags & SSF_LOOPING ) ) { + ALint state = AL_PLAYING; +- if (idSoundSystemLocal::useOpenAL && alIsSource(chan->openalSource)) { +- alGetSourcei(chan->openalSource, AL_SOURCE_STATE, &state); ++ ++ if ( alIsSource( chan->openalSource ) ) { ++ alGetSourcei( chan->openalSource, AL_SOURCE_STATE, &state ); + } +-#endif ++ idSlowChannel slow = GetSlowChannel( chan ); + +- idSlowChannel slow = GetSlowChannel(chan); +- +- if (soundWorld->slowmoActive && slow.IsActive()) { +- if (slow.GetCurrentPosition().time >= chan->leadinSample->LengthIn44kHzSamples() / 2) { ++ if ( soundWorld->slowmoActive && slow.IsActive() ) { ++ if ( slow.GetCurrentPosition().time >= chan->leadinSample->LengthIn44kHzSamples() / 2 ) { + chan->Stop(); +- + // if this was an onDemand sound, purge the sample now +- if (chan->leadinSample->onDemand) { ++ if ( chan->leadinSample->onDemand ) { + chan->leadinSample->PurgeSoundSample(); + } +- + continue; + } +- } else if ((chan->trigger44kHzTime + chan->leadinSample->LengthIn44kHzSamples() < current44kHzTime) +-#ifdef _OPENAL +- || ( state == AL_STOPPED ) //k: 2024 +-#endif +- ) { ++ } else if ( ( chan->trigger44kHzTime + chan->leadinSample->LengthIn44kHzSamples() < current44kHzTime ) || ( state == AL_STOPPED ) ) { + chan->Stop(); + + // free hardware resources + chan->ALStop(); + + // if this was an onDemand sound, purge the sample now +- if (chan->leadinSample->onDemand) { ++ if ( chan->leadinSample->onDemand ) { + chan->leadinSample->PurgeSoundSample(); + } +- + continue; + } + } + + // free decoder memory if no sound was decoded for a while +- if (chan->decoder != NULL && chan->decoder->GetLastDecodeTime() < current44kHzTime - SOUND_DECODER_FREE_DELAY) { ++ if ( chan->decoder != NULL && chan->decoder->GetLastDecodeTime() < current44kHzTime - SOUND_DECODER_FREE_DELAY ) { + chan->decoder->ClearDecoder(); + } + + hasActive = true; + +- if (chan->parms.shakes > 0.0f) { ++ if ( chan->parms.shakes > 0.0f ) { + hasShakes = true; + } + } + } + + // mark the entire sound emitter as non-playing if there aren't any active channels +- if (!hasActive) { ++ if ( !hasActive ) { + playing = false; +- +- if (removeStatus == REMOVE_STATUS_WAITSAMPLEFINISHED) { ++ if ( removeStatus == REMOVE_STATUS_WAITSAMPLEFINISHED ) { + // this can now be reused by the next request for a new soundEmitter + removeStatus = REMOVE_STATUS_SAMPLEFINISHED; + } +@@ -603,24 +539,21 @@ idSoundEmitterLocal::Spatialize + Called once each sound frame by the main thread from idSoundWorldLocal::PlaceOrigin + =================== + */ +-void idSoundEmitterLocal::Spatialize(idVec3 listenerPos, int listenerArea, idRenderWorld *rw) +-{ ++void idSoundEmitterLocal::Spatialize( idVec3 listenerPos, int listenerArea, idRenderWorld *rw ) { + int i; +- bool hasActive = false; + + // + // work out the maximum distance of all the playing channels + // + maxDistance = 0; + +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for ( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } +- +- if (chan->parms.maxDistance > maxDistance) { ++ if ( chan->parms.maxDistance > maxDistance ) { + maxDistance = chan->parms.maxDistance; + } + } +@@ -632,7 +565,7 @@ void idSoundEmitterLocal::Spatialize(idVec3 listenerPo + idVec3 len = listenerPos - realOrigin; + realDistance = len.LengthFast(); + +- if (realDistance >= maxDistance) { ++ if ( realDistance >= maxDistance ) { + // no way to possibly hear it + distance = realDistance; + return; +@@ -642,34 +575,28 @@ void idSoundEmitterLocal::Spatialize(idVec3 listenerPo + // work out virtual origin and distance, which may be from a portal instead of the actual origin + // + distance = maxDistance * METERS_TO_DOOM; +- +- if (listenerArea == -1) { // listener is outside the world ++ if ( listenerArea == -1 ) { // listener is outside the world + return; + } +- +- if (rw) { ++ if ( rw ) { + // we have a valid renderWorld +- int soundInArea = rw->PointInArea(origin); +- +- if (soundInArea == -1) { +- if (lastValidPortalArea == -1) { // sound is outside the world ++ int soundInArea = rw->PointInArea( origin ); ++ if ( soundInArea == -1 ) { ++ if ( lastValidPortalArea == -1 ) { // sound is outside the world + distance = realDistance; + spatializedOrigin = origin; // sound is in our area + return; + } +- + soundInArea = lastValidPortalArea; + } +- + lastValidPortalArea = soundInArea; +- +- if (soundInArea == listenerArea) { ++ if ( soundInArea == listenerArea ) { + distance = realDistance; + spatializedOrigin = origin; // sound is in our area + return; + } + +- soundWorld->ResolveOrigin(0, NULL, soundInArea, 0.0f, origin, this); ++ soundWorld->ResolveOrigin( 0, NULL, soundInArea, 0.0f, origin, this ); + distance /= METERS_TO_DOOM; + } else { + // no portals available +@@ -691,24 +618,22 @@ PUBLIC FUNCTIONS + idSoundEmitterLocal::UpdateEmitter + ===================== + */ +-void idSoundEmitterLocal::UpdateEmitter(const idVec3 &origin, int listenerId, const soundShaderParms_t *parms) +-{ +- if (!parms) { +- common->Error("idSoundEmitterLocal::UpdateEmitter: NULL parms"); ++void idSoundEmitterLocal::UpdateEmitter( const idVec3 &origin, int listenerId, const soundShaderParms_t *parms ) { ++ if ( !parms ) { ++ common->Error( "idSoundEmitterLocal::UpdateEmitter: NULL parms" ); + } +- +- if (soundWorld && soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_UPDATE); +- soundWorld->writeDemo->WriteInt(index); +- soundWorld->writeDemo->WriteVec3(origin); +- soundWorld->writeDemo->WriteInt(listenerId); +- soundWorld->writeDemo->WriteFloat(parms->minDistance); +- soundWorld->writeDemo->WriteFloat(parms->maxDistance); +- soundWorld->writeDemo->WriteFloat(parms->volume); +- soundWorld->writeDemo->WriteFloat(parms->shakes); +- soundWorld->writeDemo->WriteInt(parms->soundShaderFlags); +- soundWorld->writeDemo->WriteInt(parms->soundClass); ++ if ( soundWorld && soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_UPDATE ); ++ soundWorld->writeDemo->WriteInt( index ); ++ soundWorld->writeDemo->WriteVec3( origin ); ++ soundWorld->writeDemo->WriteInt( listenerId ); ++ soundWorld->writeDemo->WriteFloat( parms->minDistance ); ++ soundWorld->writeDemo->WriteFloat( parms->maxDistance ); ++ soundWorld->writeDemo->WriteFloat( parms->volume ); ++ soundWorld->writeDemo->WriteFloat( parms->shakes ); ++ soundWorld->writeDemo->WriteInt( parms->soundShaderFlags ); ++ soundWorld->writeDemo->WriteInt( parms->soundClass ); + } + + this->origin = origin; +@@ -725,24 +650,22 @@ idSoundEmitterLocal::Free + They are never truly freed, just marked so they can be reused by the soundWorld + ===================== + */ +-void idSoundEmitterLocal::Free(bool immediate) +-{ +- if (removeStatus != REMOVE_STATUS_ALIVE) { ++void idSoundEmitterLocal::Free( bool immediate ) { ++ if ( removeStatus != REMOVE_STATUS_ALIVE ) { + return; + } + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("FreeSound (%i,%i)\n", index, (int)immediate); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "FreeSound (%i,%i)\n", index, (int)immediate ); + } +- +- if (soundWorld && soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_FREE); +- soundWorld->writeDemo->WriteInt(index); +- soundWorld->writeDemo->WriteInt(immediate); ++ if ( soundWorld && soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_FREE ); ++ soundWorld->writeDemo->WriteInt( index ); ++ soundWorld->writeDemo->WriteInt( immediate ); + } + +- if (!immediate) { ++ if ( !immediate ) { + removeStatus = REMOVE_STATUS_WAITSAMPLEFINISHED; + } else { + Clear(); +@@ -756,45 +679,44 @@ idSoundEmitterLocal::StartSound + returns the length of the started sound in msec + ===================== + */ +-int idSoundEmitterLocal::StartSound(const idSoundShader *shader, const s_channelType channel, float diversity, int soundShaderFlags, bool allowSlow) +-{ ++int idSoundEmitterLocal::StartSound( const idSoundShader *shader, const s_channelType channel, float diversity, int soundShaderFlags, bool allowSlow ) { + int i; + +- if (!shader) { ++ if ( !shader ) { + return 0; + } + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("StartSound %ims (%i,%i,%s) = ", soundWorld->gameMsec, index, (int)channel, shader->GetName()); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "StartSound %ims (%i,%i,%s) = ", soundWorld->gameMsec, index, (int)channel, shader->GetName() ); + } + +- if (soundWorld && soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_START); +- soundWorld->writeDemo->WriteInt(index); ++ if ( soundWorld && soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_START ); ++ soundWorld->writeDemo->WriteInt( index ); + +- soundWorld->writeDemo->WriteHashString(shader->GetName()); ++ soundWorld->writeDemo->WriteHashString( shader->GetName() ); + +- soundWorld->writeDemo->WriteInt(channel); +- soundWorld->writeDemo->WriteFloat(diversity); +- soundWorld->writeDemo->WriteInt(soundShaderFlags); ++ soundWorld->writeDemo->WriteInt( channel ); ++ soundWorld->writeDemo->WriteFloat( diversity ); ++ soundWorld->writeDemo->WriteInt( soundShaderFlags ); + } + + // build the channel parameters by taking the shader parms and optionally overriding + soundShaderParms_t chanParms; + + chanParms = shader->parms; +- OverrideParms(&chanParms, &this->parms, &chanParms); ++ OverrideParms( &chanParms, &this->parms, &chanParms ); + chanParms.soundShaderFlags |= soundShaderFlags; + +- if (chanParms.shakes > 0.0f) { ++ if ( chanParms.shakes > 0.0f ) { + shader->CheckShakesAndOgg(); + } + + // this is the sample time it will be first mixed + int start44kHz; + +- if (soundWorld->fpa[0]) { ++ if ( soundWorld->fpa[0] ) { + // if we are recording an AVI demo, don't use hardware time + start44kHz = soundWorld->lastAVI44kHz + MIXBUFFER_SAMPLES; + } else { +@@ -804,53 +726,45 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + // + // pick which sound to play from the shader + // +- if (!shader->numEntries) { +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("no samples in sound shader\n"); ++ if ( !shader->numEntries ) { ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "no samples in sound shader\n" ); + } +- + return 0; // no sounds + } +- + int choice; + + // pick a sound from the list based on the passed diversity + choice = (int)(diversity * shader->numEntries); +- +- if (choice < 0 || choice >= shader->numEntries) { ++ if ( choice < 0 || choice >= shader->numEntries ) { + choice = 0; + } + + // bump the choice if the exact sound was just played and we are NO_DUPS +- if (chanParms.soundShaderFlags & SSF_NO_DUPS) { ++ if ( chanParms.soundShaderFlags & SSF_NO_DUPS ) { + idSoundSample *sample; +- +- if (shader->leadins[ choice ]) { ++ if ( shader->leadins[ choice ] ) { + sample = shader->leadins[ choice ]; + } else { + sample = shader->entries[ choice ]; + } +- +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; +- +- if (chan->leadinSample == sample) { +- choice = (choice + 1) % shader->numEntries; ++ if ( chan->leadinSample == sample ) { ++ choice = ( choice + 1 ) % shader->numEntries; + break; + } + } + } + + // PLAY_ONCE sounds will never be restarted while they are running +- if (chanParms.soundShaderFlags & SSF_PLAY_ONCE) { +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ if ( chanParms.soundShaderFlags & SSF_PLAY_ONCE ) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; +- +- if (chan->triggerState && chan->soundShader == shader) { +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("PLAY_ONCE not restarting\n"); ++ if ( chan->triggerState && chan->soundShader == shader ) { ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "PLAY_ONCE not restarting\n" ); + } +- + return 0; + } + } +@@ -858,14 +772,12 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + + // never play the same sound twice with the same starting time, even + // if they are on different channels +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; +- +- if (chan->triggerState && chan->soundShader == shader && chan->trigger44kHzTime == start44kHz) { +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("already started this frame\n"); ++ if ( chan->triggerState && chan->soundShader == shader && chan->trigger44kHzTime == start44kHz ) { ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "already started this frame\n" ); + } +- + return 0; + } + } +@@ -873,23 +785,21 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + Sys_EnterCriticalSection(); + + // kill any sound that is currently playing on this channel +- if (channel != SCHANNEL_ANY) { +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ if ( channel != SCHANNEL_ANY ) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; +- +- if (chan->triggerState && chan->soundShader && chan->triggerChannel == channel) { +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("(override %s)", chan->soundShader->base->GetName()); ++ if ( chan->triggerState && chan->soundShader && chan->triggerChannel == channel ) { ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "(override %s)", chan->soundShader->base->GetName() ); + } + + chan->Stop(); + + // if this was an onDemand sound, purge the sample now +- if (chan->leadinSample->onDemand) { ++ if ( chan->leadinSample->onDemand ) { + chan->ALStop(); + chan->leadinSample->PurgeSoundSample(); + } +- + break; + } + } +@@ -897,58 +807,53 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + + // find a free channel to play the sound on + idSoundChannel *chan; +- +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + chan = &channels[i]; +- +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + break; + } + } + +- if (i == SOUND_MAX_CHANNELS) { ++ if ( i == SOUND_MAX_CHANNELS ) { + // we couldn't find a channel for it + Sys_LeaveCriticalSection(); +- +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("no channels available\n"); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "no channels available\n" ); + } +- + return 0; + } + + chan = &channels[i]; + +- if (shader->leadins[ choice ]) { ++ if ( shader->leadins[ choice ] ) { + chan->leadinSample = shader->leadins[ choice ]; + } else { + chan->leadinSample = shader->entries[ choice ]; + } + + // if the sample is onDemand (voice mails, etc), load it now +- if (chan->leadinSample->purged) { ++ if ( chan->leadinSample->purged ) { + int start = Sys_Milliseconds(); + chan->leadinSample->Load(); + int end = Sys_Milliseconds(); +- session->TimeHitch(end - start); +- ++ session->TimeHitch( end - start ); + // recalculate start44kHz, because loading may have taken a fair amount of time +- if (!soundWorld->fpa[0]) { ++ if ( !soundWorld->fpa[0] ) { + start44kHz = soundSystemLocal.GetCurrent44kHzTime() + MIXBUFFER_SAMPLES; + } + } + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("'%s'\n", chan->leadinSample->name.c_str()); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "'%s'\n", chan->leadinSample->name.c_str() ); + } + +- if (idSoundSystemLocal::s_skipHelltimeFX.GetBool()) { ++ if ( idSoundSystemLocal::s_skipHelltimeFX.GetBool() ) { + chan->disallowSlow = true; + } else { + chan->disallowSlow = !allowSlow; + } + +- ResetSlowChannel(chan); ++ ResetSlowChannel( chan ); + + // the sound will start mixing in the next async mix block + chan->triggered = true; +@@ -965,21 +870,21 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + + // spatialize it immediately, so it will start the next mix block + // even if that happens before the next PlaceOrigin() +- Spatialize(soundWorld->listenerPos, soundWorld->listenerArea, soundWorld->rw); ++ Spatialize( soundWorld->listenerPos, soundWorld->listenerArea, soundWorld->rw ); + + // return length of sound in milliseconds + int length = chan->leadinSample->LengthIn44kHzSamples(); + +- if (chan->leadinSample->objectInfo.nChannels == 2) { ++ if ( chan->leadinSample->objectInfo.nChannels == 2 ) { + length /= 2; // stereo samples + } + + // adjust the start time based on diversity for looping sounds, so they don't all start + // at the same point +- if (chan->parms.soundShaderFlags & SSF_LOOPING && !chan->leadinSample->LengthIn44kHzSamples()) { ++ if ( chan->parms.soundShaderFlags & SSF_LOOPING && !chan->leadinSample->LengthIn44kHzSamples() ) { + chan->trigger44kHzTime -= diversity * length; + chan->trigger44kHzTime &= ~7; // so we don't have to worry about the 22kHz and 11kHz expansions +- // starting in fractional samples ++ // starting in fractional samples + chan->triggerGame44kHzTime -= diversity * length; + chan->triggerGame44kHzTime &= ~7; + } +@@ -996,43 +901,39 @@ int idSoundEmitterLocal::StartSound(const idSoundShade + idSoundEmitterLocal::ModifySound + =================== + */ +-void idSoundEmitterLocal::ModifySound(const s_channelType channel, const soundShaderParms_t *parms) +-{ +- if (!parms) { +- common->Error("idSoundEmitterLocal::ModifySound: NULL parms"); ++void idSoundEmitterLocal::ModifySound( const s_channelType channel, const soundShaderParms_t *parms ) { ++ if ( !parms ) { ++ common->Error( "idSoundEmitterLocal::ModifySound: NULL parms" ); + } +- +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("ModifySound(%i,%i)\n", index, channel); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "ModifySound(%i,%i)\n", index, channel ); + } +- +- if (soundWorld && soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_MODIFY); +- soundWorld->writeDemo->WriteInt(index); +- soundWorld->writeDemo->WriteInt(channel); +- soundWorld->writeDemo->WriteFloat(parms->minDistance); +- soundWorld->writeDemo->WriteFloat(parms->maxDistance); +- soundWorld->writeDemo->WriteFloat(parms->volume); +- soundWorld->writeDemo->WriteFloat(parms->shakes); +- soundWorld->writeDemo->WriteInt(parms->soundShaderFlags); +- soundWorld->writeDemo->WriteInt(parms->soundClass); ++ if ( soundWorld && soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_MODIFY ); ++ soundWorld->writeDemo->WriteInt( index ); ++ soundWorld->writeDemo->WriteInt( channel ); ++ soundWorld->writeDemo->WriteFloat( parms->minDistance ); ++ soundWorld->writeDemo->WriteFloat( parms->maxDistance ); ++ soundWorld->writeDemo->WriteFloat( parms->volume ); ++ soundWorld->writeDemo->WriteFloat( parms->shakes ); ++ soundWorld->writeDemo->WriteInt( parms->soundShaderFlags ); ++ soundWorld->writeDemo->WriteInt( parms->soundClass ); + } + +- for (int i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for ( int i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } +- +- if (channel != SCHANNEL_ANY && chan->triggerChannel != channel) { ++ if ( channel != SCHANNEL_ANY && chan->triggerChannel != channel ) { + continue; + } + +- OverrideParms(&chan->parms, parms, &chan->parms); ++ OverrideParms( &chan->parms, parms, &chan->parms ); + +- if (chan->parms.shakes > 0.0f && chan->soundShader != NULL) { ++ if ( chan->parms.shakes > 0.0f && chan->soundShader != NULL ) { + chan->soundShader->CheckShakesAndOgg(); + } + } +@@ -1045,39 +946,43 @@ idSoundEmitterLocal::StopSound + can pass SCHANNEL_ANY + =================== + */ +-void idSoundEmitterLocal::StopSound(const s_channelType channel) +-{ ++void idSoundEmitterLocal::StopSound( const s_channelType channel ) { + int i; + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("StopSound(%i,%i)\n", index, channel); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "StopSound(%i,%i)\n", index, channel ); + } + +- if (soundWorld && soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_STOP); +- soundWorld->writeDemo->WriteInt(index); +- soundWorld->writeDemo->WriteInt(channel); ++ if ( soundWorld && soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_STOP ); ++ soundWorld->writeDemo->WriteInt( index ); ++ soundWorld->writeDemo->WriteInt( channel ); + } + + Sys_EnterCriticalSection(); + +- for (i = 0; i < SOUND_MAX_CHANNELS; i++) { ++ for( i = 0; i < SOUND_MAX_CHANNELS; i++ ) { + idSoundChannel *chan = &channels[i]; +- if (!chan->triggerState) { ++ ++ if ( !chan->triggerState ) { + continue; + } +- if (channel != SCHANNEL_ANY && chan->triggerChannel != channel) { ++ if ( channel != SCHANNEL_ANY && chan->triggerChannel != channel ) { + continue; + } ++ + // stop it + chan->Stop(); ++ + // free hardware resources + chan->ALStop(); ++ + // if this was an onDemand sound, purge the sample now +- if (chan->leadinSample && chan->leadinSample->onDemand) { ++ if ( chan->leadinSample->onDemand ) { + chan->leadinSample->PurgeSoundSample(); + } ++ + chan->leadinSample = NULL; + chan->soundShader = NULL; + } +@@ -1092,55 +997,51 @@ idSoundEmitterLocal::FadeSound + to is in Db (sigh), over is in seconds + =================== + */ +-void idSoundEmitterLocal::FadeSound(const s_channelType channel, float to, float over) +-{ +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("FadeSound(%i,%i,%f,%f )\n", index, channel, to, over); ++void idSoundEmitterLocal::FadeSound( const s_channelType channel, float to, float over ) { ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "FadeSound(%i,%i,%f,%f )\n", index, channel, to, over ); + } +- +- if (!soundWorld) { ++ if ( !soundWorld ) { + return; + } +- +- if (soundWorld->writeDemo) { +- soundWorld->writeDemo->WriteInt(DS_SOUND); +- soundWorld->writeDemo->WriteInt(SCMD_FADE); +- soundWorld->writeDemo->WriteInt(index); +- soundWorld->writeDemo->WriteInt(channel); +- soundWorld->writeDemo->WriteFloat(to); +- soundWorld->writeDemo->WriteFloat(over); ++ if ( soundWorld->writeDemo ) { ++ soundWorld->writeDemo->WriteInt( DS_SOUND ); ++ soundWorld->writeDemo->WriteInt( SCMD_FADE ); ++ soundWorld->writeDemo->WriteInt( index ); ++ soundWorld->writeDemo->WriteInt( channel ); ++ soundWorld->writeDemo->WriteFloat( to ); ++ soundWorld->writeDemo->WriteFloat( over ); + } + + int start44kHz; + +- if (soundWorld->fpa[0]) { ++ if ( soundWorld->fpa[0] ) { + // if we are recording an AVI demo, don't use hardware time + start44kHz = soundWorld->lastAVI44kHz + MIXBUFFER_SAMPLES; + } else { + start44kHz = soundSystemLocal.GetCurrent44kHzTime() + MIXBUFFER_SAMPLES; + } + +- int length44kHz = soundSystemLocal.MillisecondsToSamples(over * 1000); ++ int length44kHz = soundSystemLocal.MillisecondsToSamples( over * 1000 ); + +- for (int i = 0; i < SOUND_MAX_CHANNELS ; i++) { ++ for( int i = 0; i < SOUND_MAX_CHANNELS ; i++ ) { + idSoundChannel *chan = &channels[i]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } +- +- if (channel != SCHANNEL_ANY && chan->triggerChannel != channel) { ++ if ( channel != SCHANNEL_ANY && chan->triggerChannel != channel ) { + continue; + } + + // if it is already fading to this volume at this rate, don't change it +- if (chan->channelFade.fadeEndVolume == to && +- chan->channelFade.fadeEnd44kHz - chan->channelFade.fadeStart44kHz == length44kHz) { ++ if ( chan->channelFade.fadeEndVolume == to && ++ chan->channelFade.fadeEnd44kHz - chan->channelFade.fadeStart44kHz == length44kHz ) { + continue; + } + + // fade it +- chan->channelFade.fadeStartVolume = chan->channelFade.FadeDbAt44kHz(start44kHz); ++ chan->channelFade.fadeStartVolume = chan->channelFade.FadeDbAt44kHz( start44kHz ); + chan->channelFade.fadeStart44kHz = start44kHz; + chan->channelFade.fadeEnd44kHz = start44kHz + length44kHz; + chan->channelFade.fadeEndVolume = to; +@@ -1152,8 +1053,7 @@ void idSoundEmitterLocal::FadeSound(const s_channelTyp + idSoundEmitterLocal::CurrentlyPlaying + =================== + */ +-bool idSoundEmitterLocal::CurrentlyPlaying(void) const +-{ ++bool idSoundEmitterLocal::CurrentlyPlaying( void ) const { + return playing; + } + +@@ -1162,8 +1062,7 @@ bool idSoundEmitterLocal::CurrentlyPlaying(void) const + idSoundEmitterLocal::Index + =================== + */ +-int idSoundEmitterLocal::Index(void) const +-{ ++int idSoundEmitterLocal::Index( void ) const { + return index; + } + +@@ -1175,26 +1074,25 @@ this is called from the main thread by the material sh + to allow lights and surface flares to vary with the sound amplitude + =================== + */ +-float idSoundEmitterLocal::CurrentAmplitude(void) +-{ +- if (idSoundSystemLocal::s_constantAmplitude.GetFloat() >= 0.0f) { ++float idSoundEmitterLocal::CurrentAmplitude( void ) { ++ if ( idSoundSystemLocal::s_constantAmplitude.GetFloat() >= 0.0f ) { + return idSoundSystemLocal::s_constantAmplitude.GetFloat(); + } + +- if (removeStatus > REMOVE_STATUS_WAITSAMPLEFINISHED) { ++ if ( removeStatus > REMOVE_STATUS_WAITSAMPLEFINISHED ) { + return 0.0; + } + + int localTime = soundSystemLocal.GetCurrent44kHzTime(); + + // see if we can use our cached value +- if (ampTime == localTime) { ++ if ( ampTime == localTime ) { + return amplitude; + } + + // calculate a new value + ampTime = localTime; +- amplitude = soundWorld->FindAmplitude(this, localTime, NULL, SCHANNEL_ANY, false); ++ amplitude = soundWorld->FindAmplitude( this, localTime, NULL, SCHANNEL_ANY, false ); + + return amplitude; + } +@@ -1204,8 +1102,7 @@ float idSoundEmitterLocal::CurrentAmplitude(void) + idSoundEmitterLocal::GetSlowChannel + =================== + */ +-idSlowChannel idSoundEmitterLocal::GetSlowChannel(const idSoundChannel *chan) +-{ ++idSlowChannel idSoundEmitterLocal::GetSlowChannel( const idSoundChannel *chan ) { + return slowChannels[chan - channels]; + } + +@@ -1214,8 +1111,7 @@ idSlowChannel idSoundEmitterLocal::GetSlowChannel(cons + idSoundEmitterLocal::SetSlowChannel + =================== + */ +-void idSoundEmitterLocal::SetSlowChannel(const idSoundChannel *chan, idSlowChannel slow) +-{ ++void idSoundEmitterLocal::SetSlowChannel( const idSoundChannel *chan, idSlowChannel slow ) { + slowChannels[chan - channels] = slow; + } + +@@ -1224,8 +1120,7 @@ void idSoundEmitterLocal::SetSlowChannel(const idSound + idSoundEmitterLocal::ResetSlowChannel + =================== + */ +-void idSoundEmitterLocal::ResetSlowChannel(const idSoundChannel *chan) +-{ ++void idSoundEmitterLocal::ResetSlowChannel( const idSoundChannel *chan ) { + int index = chan - channels; + slowChannels[index].Reset(); + } +@@ -1235,18 +1130,14 @@ void idSoundEmitterLocal::ResetSlowChannel(const idSou + idSlowChannel::Reset + =================== + */ +-void idSlowChannel::Reset() +-{ +- // DG: memset() on this is problematic, because lowpass (SoundFX_LowpassFast) has a vtable +- //memset( this, 0, sizeof( *this ) ); +- active = false; +- chan = NULL; +- playbackState = 0; +- lowpass.Clear(); ++void idSlowChannel::Reset() { ++ memset( this, 0, sizeof( *this ) ); + +- curPosition.Set(0); +- newPosition.Set(0); ++ this->chan = chan; + ++ curPosition.Set( 0 ); ++ newPosition.Set( 0 ); ++ + curSampleOffset = -10000; + newSampleOffset = -10000; + +@@ -1258,8 +1149,7 @@ void idSlowChannel::Reset() + idSlowChannel::AttachSoundChannel + =================== + */ +-void idSlowChannel::AttachSoundChannel(const idSoundChannel *chan) +-{ ++void idSlowChannel::AttachSoundChannel( const idSoundChannel *chan ) { + this->chan = chan; + } + +@@ -1268,11 +1158,10 @@ void idSlowChannel::AttachSoundChannel(const idSoundCh + idSlowChannel::GetSlowmoSpeed + =================== + */ +-float idSlowChannel::GetSlowmoSpeed() +-{ +- idSoundWorldLocal *sw = static_cast(soundSystemLocal.GetPlayingSoundWorld()); ++float idSlowChannel::GetSlowmoSpeed() { ++ idSoundWorldLocal *sw = static_cast( soundSystemLocal.GetPlayingSoundWorld() ); + +- if (sw) { ++ if ( sw ) { + return sw->slowmoSpeed; + } else { + return 0; +@@ -1284,28 +1173,26 @@ float idSlowChannel::GetSlowmoSpeed() + idSlowChannel::GenerateSlowChannel + =================== + */ +-void idSlowChannel::GenerateSlowChannel(FracTime &playPos, int sampleCount44k, float *finalBuffer) +-{ +- idSoundWorldLocal *sw = static_cast(soundSystemLocal.GetPlayingSoundWorld()); ++void idSlowChannel::GenerateSlowChannel( FracTime& playPos, int sampleCount44k, float* finalBuffer ) { ++ idSoundWorldLocal *sw = static_cast( soundSystemLocal.GetPlayingSoundWorld() ); + float in[MIXBUFFER_SAMPLES+3], out[MIXBUFFER_SAMPLES+3], *src, *spline, slowmoSpeed; +- int i, neededSamples, orgTime, zeroedPos, count = 0; ++ int i, neededSamples, zeroedPos, count = 0; + + src = in + 2; + spline = out + 2; + +- if (sw) { ++ if ( sw ) { + slowmoSpeed = sw->slowmoSpeed; +- } else { ++ } ++ else { + slowmoSpeed = 1; + } + + neededSamples = sampleCount44k * slowmoSpeed + 4; +- orgTime = playPos.time; + + // get the channel's samples +- chan->GatherChannelSamples(playPos.time * 2, neededSamples, src); +- +- for (i = 0; i < neededSamples >> 1; i++) { ++ chan->GatherChannelSamples( playPos.time * 2, neededSamples, src ); ++ for ( i = 0; i < neededSamples >> 1; i++ ) { + spline[i] = src[i*2]; + } + +@@ -1313,26 +1200,26 @@ void idSlowChannel::GenerateSlowChannel(FracTime &play + zeroedPos = playPos.time; + playPos.time = 0; + +- for (i = 0; i < sampleCount44k >> 1; i++, count += 2) { ++ for ( i = 0; i < sampleCount44k >> 1; i++, count += 2 ) { + float val; + val = spline[playPos.time]; + src[i] = val; +- playPos.Increment(slowmoSpeed); ++ playPos.Increment( slowmoSpeed ); + } + + // lowpass filter + float *in_p = in + 2, *out_p = out + 2; + int numSamples = sampleCount44k >> 1; + +- lowpass.GetContinuitySamples(in_p[-1], in_p[-2], out_p[-1], out_p[-2]); +- lowpass.SetParms(slowmoSpeed * 15000, 1.2f); ++ lowpass.GetContinuitySamples( in_p[-1], in_p[-2], out_p[-1], out_p[-2] ); ++ lowpass.SetParms( slowmoSpeed * 15000, 1.2f ); + +- for (int i = 0, count = 0; i < numSamples; i++, count += 2) { +- lowpass.ProcessSample(in_p + i, out_p + i); ++ for ( int i = 0, count = 0; i < numSamples; i++, count += 2 ) { ++ lowpass.ProcessSample( in_p + i, out_p + i ); + finalBuffer[count] = finalBuffer[count+1] = out[i]; + } + +- lowpass.SetContinuitySamples(in_p[numSamples-2], in_p[numSamples-3], out_p[numSamples-2], out_p[numSamples-3]); ++ lowpass.SetContinuitySamples( in_p[numSamples-2], in_p[numSamples-3], out_p[numSamples-2], out_p[numSamples-3] ); + + playPos.time += zeroedPos; + } +@@ -1342,8 +1229,7 @@ void idSlowChannel::GenerateSlowChannel(FracTime &play + idSlowChannel::GatherChannelSamples + =================== + */ +-void idSlowChannel::GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest) +-{ ++void idSlowChannel::GatherChannelSamples( int sampleOffset44k, int sampleCount44k, float *dest ) { + int state = 0; + + // setup chan +@@ -1351,14 +1237,14 @@ void idSlowChannel::GatherChannelSamples(int sampleOff + newSampleOffset = sampleOffset44k >> 1; + + // set state +- if (newSampleOffset < curSampleOffset) { ++ if ( newSampleOffset < curSampleOffset ) { + state = PLAYBACK_RESET; +- } else if (newSampleOffset > curSampleOffset) { ++ } else if ( newSampleOffset > curSampleOffset ) { + state = PLAYBACK_ADVANCING; + } + +- if (state == PLAYBACK_RESET) { +- curPosition.Set(newSampleOffset); ++ if ( state == PLAYBACK_RESET ) { ++ curPosition.Set( newSampleOffset ); + } + + // set current vars +@@ -1366,13 +1252,12 @@ void idSlowChannel::GatherChannelSamples(int sampleOff + newPosition = curPosition; + + // do the slow processing +- GenerateSlowChannel(newPosition, sampleCount44k, dest); ++ GenerateSlowChannel( newPosition, sampleCount44k, dest ); + + // finish off +- if (state == PLAYBACK_ADVANCING) ++ if ( state == PLAYBACK_ADVANCING ) + curPosition = newPosition; + } +- + #ifdef _HUMANHEAD + soundShaderParms_t* idSoundEmitterLocal::GetSoundParms(idSoundShader* shader, const s_channelType channel) + { +@@ -1388,5 +1273,4 @@ void idSoundEmitterLocal::ModifySound(idSoundShader* s + if(chan) + parmModifier.ModifyParms(chan->parms); + } +-#endif +- ++#endif +\ No newline at end of file diff --git a/games/idtech4a-engine/patches/patch-sound_snd_local_h b/games/idtech4a-engine/patches/patch-sound_snd_local_h new file mode 100644 index 000000000..858518232 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_local_h @@ -0,0 +1,1290 @@ +Index: sound/snd_local.h +--- sound/snd_local.h.orig ++++ sound/snd_local.h +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -29,73 +29,23 @@ If you have questions concerning this license or the a + #ifndef __SND_LOCAL_H__ + #define __SND_LOCAL_H__ + +-#ifdef _OPENAL +- + // you need the OpenAL headers for build, even if AL is not enabled - http://www.openal.org/ + #ifdef _WIN32 +-#ifdef _OPENAL_SOFT +-#include "../externlibs/openal-soft/include/AL/al.h" +-#include "../externlibs/openal-soft/include/AL/alc.h" +-#include "../externlibs/openal-soft/include/AL/efx.h" +-#include "../openal/idal.h" +-#define ID_ALCHAR (ALubyte *) +-#else +-#include "../openal/include/al.h" +-#include "../openal/include/alc.h" +-#include "../openal/idal.h" ++#include ++#include + // broken OpenAL SDK ? + #define ID_ALCHAR (ALubyte *) +-#endif + #elif defined( MACOS_X ) + #include + #include + #define ID_ALCHAR +-#elif defined(_OPENAL_SOFT) +-#include "../externlibs/openal-soft/include/AL/al.h" +-#include "../externlibs/openal-soft/include/AL/alc.h" +-#include "../externlibs/openal-soft/include/AL/efx.h" +-#include "../openal/idal.h" +-#define ID_ALCHAR (ALubyte *) + #else + #include + #include + #define ID_ALCHAR + #endif +-#include "../openal/include/efxlib.h" ++#include "efxlib.h" + +-#else +- +-#define EFXprintf(...) do { } while (false) +- +-/** 8-bit boolean */ +-typedef char ALboolean; +-/** character */ +-typedef char ALchar; +-/** signed 8-bit 2's complement integer */ +-typedef signed char ALbyte; +-/** unsigned 8-bit integer */ +-typedef unsigned char ALubyte; +-/** signed 16-bit 2's complement integer */ +-typedef short ALshort; +-/** unsigned 16-bit integer */ +-typedef unsigned short ALushort; +-/** signed 32-bit 2's complement integer */ +-typedef int ALint; +-/** unsigned 32-bit integer */ +-typedef unsigned int ALuint; +-/** non-negative 32-bit binary integer size */ +-typedef int ALsizei; +-/** enumerated 32-bit value */ +-typedef int ALenum; +-/** 32-bit IEEE754 floating-point */ +-typedef float ALfloat; +-/** 64-bit IEEE754 floating-point */ +-typedef double ALdouble; +-/** void type (for opaque pointers only) */ +-typedef void ALvoid; +- +-#endif +- + // demo sound commands + typedef enum { + SCMD_STATE, // followed by a load game state +@@ -118,7 +68,6 @@ const float SND_EPSILON = 1.0f / 32768.0f; // if vo + + const int ROOM_SLICES_IN_BUFFER = 10; + +-class idAudioHardware; + class idAudioBuffer; + class idWaveFile; + class idSoundCache; +@@ -150,7 +99,7 @@ struct waveformatex_s { + word nBlockAlign; /* block size of data */ + word wBitsPerSample; /* Number of bits per sample of mono data */ + word cbSize; /* The count in bytes of the size of +- extra information (after cbSize) */ ++ extra information (after cbSize) */ + } PACKED; + + typedef waveformatex_s waveformatex_t; +@@ -196,7 +145,7 @@ struct waveformatextensible_s { + word wReserved; /* If neither applies, set to zero*/ + } Samples; + dword dwChannelMask; /* which channels are */ +- /* present in stream */ ++ /* present in stream */ + int SubFormat; + } PACKED; + +@@ -229,106 +178,64 @@ idWaveFile + =================================================================================== + */ + +-class idWaveFile +-{ +- public: +- idWaveFile(void); +- ~idWaveFile(void); ++class idWaveFile { ++public: ++ idWaveFile( void ); ++ ~idWaveFile( void ); + +- int Open(const char *strFileName, waveformatex_t *pwfx = NULL); +- int OpenFromMemory(short *pbData, int ulDataSize, waveformatextensible_t *pwfx); +- int Read(byte *pBuffer, int dwSizeToRead, int *pdwSizeRead); +- int Seek(int offset); +- int Close(void); +- int ResetFile(void); ++ int Open( const char* strFileName, waveformatex_t* pwfx = NULL ); ++ int OpenFromMemory( short* pbData, int ulDataSize, waveformatextensible_t* pwfx ); ++ int Read( byte* pBuffer, int dwSizeToRead, int *pdwSizeRead ); ++ int Seek( int offset ); ++ int Close( void ); ++ int ResetFile( void ); + +- int GetOutputSize(void) { +- return mdwSize; +- } +- int GetMemorySize(void) { +- return mMemSize; +- } ++ int GetOutputSize( void ) { return mdwSize; } ++ int GetMemorySize( void ) { return mMemSize; } + +- waveformatextensible_t mpwfx; // Pointer to waveformatex structure ++ waveformatextensible_t mpwfx; // Pointer to waveformatex structure + +- private: +- idFile *mhmmio; // I/O handle for the WAVE +- mminfo_t mck; // Multimedia RIFF chunk +- mminfo_t mckRiff; // used when opening a WAVE file +- dword mdwSize; // size in samples +- dword mMemSize; // size of the wave data in memory +- dword mseekBase; +- ID_TIME_T mfileTime; ++private: ++ idFile * mhmmio; // I/O handle for the WAVE ++ mminfo_t mck; // Multimedia RIFF chunk ++ mminfo_t mckRiff; // used when opening a WAVE file ++ dword mdwSize; // size in samples ++ dword mMemSize; // size of the wave data in memory ++ dword mseekBase; ++ ID_TIME_T mfileTime; + +- bool mbIsReadingFromMemory; +- short *mpbData; +- short *mpbDataCur; +- dword mulDataSize; ++ bool mbIsReadingFromMemory; ++ short * mpbData; ++ short * mpbDataCur; ++ dword mulDataSize; + +- void *ogg; // only !NULL when !s_realTimeDecoding +-#ifdef _USING_STB_OGG +- byte* oggData; // the contents of the .ogg for stbi_vorbis (it doesn't support custom reading callbacks) +-#endif +- bool isOgg; ++ void * ogg; // only !NULL when !s_realTimeDecoding ++ bool isOgg; + +- private: +- int ReadMMIO(void); ++private: ++ int ReadMMIO( void ); + +- int OpenOGG(const char *strFileName, waveformatex_t *pwfx = NULL); +- int ReadOGG(byte *pBuffer, int dwSizeToRead, int *pdwSizeRead); +- int CloseOGG(void); ++ int OpenOGG( const char* strFileName, waveformatex_t* pwfx = NULL ); ++ int ReadOGG( byte* pBuffer, int dwSizeToRead, int *pdwSizeRead ); ++ int CloseOGG( void ); + }; + + + /* + =================================================================================== + +-idAudioHardware +- +-=================================================================================== +-*/ +- +-class idAudioHardware +-{ +- public: +- static idAudioHardware *Alloc(); +- +- virtual ~idAudioHardware(); +- +- virtual bool Initialize() = 0; +- +- virtual bool Lock(void **pDSLockedBuffer, ulong *dwDSLockedBufferSize) = 0; +- virtual bool Unlock(void *pDSLockedBuffer, dword dwDSLockedBufferSize) = 0; +- virtual bool GetCurrentPosition(ulong *pdwCurrentWriteCursor) = 0; +- +- // try to write as many sound samples to the device as possible without blocking and prepare for a possible new mixing call +- // returns wether there is *some* space for writing available +- virtual bool Flush(void) = 0; +- +- virtual void Write(bool flushing) = 0; +- +- virtual int GetNumberOfSpeakers(void)= 0; +- virtual int GetMixBufferSize(void) = 0; +- virtual short *GetMixBuffer(void) = 0; +-}; +- +- +-/* +-=================================================================================== +- + Encapsulates functionality of a DirectSound buffer. + + =================================================================================== + */ + +-class idAudioBuffer +-{ +- public: +- virtual int Play(dword dwPriority=0, dword dwFlags=0) = 0; +- virtual int Stop(void) = 0; +- virtual int Reset(void) = 0; +- virtual bool IsSoundPlaying(void) = 0; +- virtual void SetVolume(float x) = 0; ++class idAudioBuffer { ++public: ++ virtual int Play( dword dwPriority=0, dword dwFlags=0 ) = 0; ++ virtual int Stop( void ) = 0; ++ virtual int Reset( void ) = 0; ++ virtual bool IsSoundPlaying( void ) = 0; ++ virtual void SetVolume( float x ) = 0; + }; + + +@@ -347,122 +254,76 @@ typedef enum { + REMOVE_STATUS_SAMPLEFINISHED = 2 + } removeStatus_t; + +-class idSoundFade +-{ +- public: +- int fadeStart44kHz; +- int fadeEnd44kHz; +- float fadeStartVolume; // in dB +- float fadeEndVolume; // in dB ++class idSoundFade { ++public: ++ int fadeStart44kHz; ++ int fadeEnd44kHz; ++ float fadeStartVolume; // in dB ++ float fadeEndVolume; // in dB + +- void Clear(); +- float FadeDbAt44kHz(int current44kHz); ++ void Clear(); ++ float FadeDbAt44kHz( int current44kHz ); + }; + +-class SoundFX +-{ +- protected: +- bool initialized; ++class SoundFX { ++protected: ++ bool initialized; + +- int channel; +- int maxlen; ++ int channel; ++ int maxlen; + +- float *buffer; +- float continuitySamples[4]; ++ float* buffer; ++ float continuitySamples[4]; + +- float param; ++ float param; + +- public: +- SoundFX() { +- channel = 0; +- buffer = NULL; +- initialized = false; +- maxlen = 0; +- memset(continuitySamples, 0, sizeof(float) * 4); +- }; +- virtual ~SoundFX() { +- if (buffer) delete buffer; +- }; ++public: ++ SoundFX() { channel = 0; buffer = NULL; initialized = false; maxlen = 0; memset( continuitySamples, 0, sizeof( float ) * 4 ); }; ++ virtual ~SoundFX() { if ( buffer ) delete buffer; }; + +- virtual void Initialize() { }; +- virtual void ProcessSample(float *in, float *out) = 0; ++ virtual void Initialize() { }; ++ virtual void ProcessSample( float* in, float* out ) = 0; + +- void SetChannel(int chan) { +- channel = chan; +- }; +- int GetChannel() { +- return channel; +- }; ++ void SetChannel( int chan ) { channel = chan; }; ++ int GetChannel() { return channel; }; + +- void SetContinuitySamples(float in1, float in2, float out1, float out2) { +- continuitySamples[0] = in1; +- continuitySamples[1] = in2; +- continuitySamples[2] = out1; +- continuitySamples[3] = out2; +- }; // FIXME? +- void GetContinuitySamples(float &in1, float &in2, float &out1, float &out2) { +- in1 = continuitySamples[0]; +- in2 = continuitySamples[1]; +- out1 = continuitySamples[2]; +- out2 = continuitySamples[3]; +- }; ++ void SetContinuitySamples( float in1, float in2, float out1, float out2 ) { continuitySamples[0] = in1; continuitySamples[1] = in2; continuitySamples[2] = out1; continuitySamples[3] = out2; }; // FIXME? ++ void GetContinuitySamples( float& in1, float& in2, float& out1, float& out2 ) { in1 = continuitySamples[0]; in2 = continuitySamples[1]; out1 = continuitySamples[2]; out2 = continuitySamples[3]; }; + +- void SetParameter(float val) { +- param = val; +- }; ++ void SetParameter( float val ) { param = val; }; + }; + +-class SoundFX_Lowpass : public SoundFX +-{ +- public: +- virtual void ProcessSample(float *in, float *out); ++class SoundFX_Lowpass : public SoundFX { ++public: ++ virtual void ProcessSample( float* in, float* out ); + }; + +-class SoundFX_LowpassFast : public SoundFX +-{ +- float freq; +- float res; +- float a1, a2, a3; +- float b1, b2; ++class SoundFX_LowpassFast : public SoundFX { ++ float freq; ++ float res; ++ float a1, a2, a3; ++ float b1, b2; + +- public: +- virtual void ProcessSample(float *in, float *out); +- void SetParms(float p1 = 0, float p2 = 0, float p3 = 0); +- +- void Clear() { +- freq = res = 0.0f; +- a1 = a2 = a3 = 0.0f; +- b1 = b2 = 0.0f; +- } ++public: ++ virtual void ProcessSample( float* in, float* out ); ++ void SetParms( float p1 = 0, float p2 = 0, float p3 = 0 ); + }; + +-class SoundFX_Comb : public SoundFX +-{ +- int currentTime; ++class SoundFX_Comb : public SoundFX { ++ int currentTime; + +- public: +- virtual void Initialize(); +- virtual void ProcessSample(float *in, float *out); ++public: ++ virtual void Initialize(); ++ virtual void ProcessSample( float* in, float* out ); + }; + +-class FracTime +-{ +- public: +- int time; +- float frac; ++class FracTime { ++public: ++ int time; ++ float frac; + +- void Set(int val) { +- time = val; +- frac = 0; +- }; +- void Increment(float val) { +- frac += val; +- +- while (frac >= 1.f) { +- time++; +- frac--; +- } +- }; ++ void Set( int val ) { time = val; frac = 0; }; ++ void Increment( float val ) { frac += val; while ( frac >= 1.f ) { time++; frac--; } }; + }; + + enum { +@@ -472,102 +333,95 @@ enum { + + class idSoundChannel; + +-class idSlowChannel +-{ +- bool active; +- const idSoundChannel *chan; ++class idSlowChannel { ++ bool active; ++ const idSoundChannel* chan; + +- int playbackState; +- int triggerOffset; ++ int playbackState; ++ int triggerOffset; + +- FracTime newPosition; +- int newSampleOffset; ++ FracTime newPosition; ++ int newSampleOffset; + +- FracTime curPosition; +- int curSampleOffset; ++ FracTime curPosition; ++ int curSampleOffset; + +- SoundFX_LowpassFast lowpass; ++ SoundFX_LowpassFast lowpass; + +- // functions +- void GenerateSlowChannel(FracTime &playPos, int sampleCount44k, float *finalBuffer); ++ // functions ++ void GenerateSlowChannel( FracTime& playPos, int sampleCount44k, float* finalBuffer ); + +- float GetSlowmoSpeed(); ++ float GetSlowmoSpeed(); + +- public: ++public: + +- void AttachSoundChannel(const idSoundChannel *chan); +- void Reset(); ++ void AttachSoundChannel( const idSoundChannel *chan ); ++ void Reset(); + +- void GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest); ++ void GatherChannelSamples( int sampleOffset44k, int sampleCount44k, float *dest ); + +- bool IsActive() { +- return active; +- }; +- FracTime GetCurrentPosition() { +- return curPosition; +- }; ++ bool IsActive() { return active; }; ++ FracTime GetCurrentPosition() { return curPosition; }; + }; + +-class idSoundChannel +-{ +- public: +- idSoundChannel(void); +- ~idSoundChannel(void); ++class idSoundChannel { ++public: ++ idSoundChannel( void ); ++ ~idSoundChannel( void ); + +- void Clear(void); +- void Start(void); +- void Stop(void); +- void GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest) const; +- void ALStop(void); // free OpenAL resources if any ++ void Clear( void ); ++ void Start( void ); ++ void Stop( void ); ++ void GatherChannelSamples( int sampleOffset44k, int sampleCount44k, float *dest ) const; ++ void ALStop( void ); // free OpenAL resources if any + +- bool triggerState; +- int trigger44kHzTime; // hardware time sample the channel started +- int triggerGame44kHzTime; // game time sample time the channel started +- soundShaderParms_t parms; // combines the shader parms and the per-channel overrides +- idSoundSample *leadinSample; // if not looped, this is the only sample +- s_channelType triggerChannel; +- const idSoundShader *soundShader; +- idSampleDecoder *decoder; +- float diversity; +- float lastVolume; // last calculated volume based on distance +- float lastV[6]; // last calculated volume for each speaker, so we can smoothly fade +- idSoundFade channelFade; +- bool triggered; +- ALuint openalSource; +- ALuint openalStreamingOffset; +- ALuint openalStreamingBuffer[3]; +- ALuint lastopenalStreamingBuffer[3]; ++ bool triggerState; ++ int trigger44kHzTime; // hardware time sample the channel started ++ int triggerGame44kHzTime; // game time sample time the channel started ++ soundShaderParms_t parms; // combines the shader parms and the per-channel overrides ++ idSoundSample * leadinSample; // if not looped, this is the only sample ++ s_channelType triggerChannel; ++ const idSoundShader *soundShader; ++ idSampleDecoder * decoder; ++ float diversity; ++ float lastVolume; // last calculated volume based on distance ++ float lastV[6]; // last calculated volume for each speaker, so we can smoothly fade ++ idSoundFade channelFade; ++ bool triggered; ++ ALuint openalSource; ++ ALuint openalStreamingOffset; ++ ALuint openalStreamingBuffer[3]; ++ ALuint lastopenalStreamingBuffer[3]; + +- bool disallowSlow; ++ bool disallowSlow; + + }; + +-class idSoundEmitterLocal : public idSoundEmitter +-{ +- public: ++class idSoundEmitterLocal : public idSoundEmitter { ++public: + +- idSoundEmitterLocal(void); +- virtual ~idSoundEmitterLocal(void); ++ idSoundEmitterLocal( void ); ++ virtual ~idSoundEmitterLocal( void ); + +- //---------------------------------------------- ++ //---------------------------------------------- + +- // the "time" parameters should be game time in msec, which is used to make queries +- // return deterministic values regardless of async buffer scheduling ++ // the "time" parameters should be game time in msec, which is used to make queries ++ // return deterministic values regardless of async buffer scheduling + +- // a non-immediate free will let all currently playing sounds complete +- virtual void Free(bool immediate); ++ // a non-immediate free will let all currently playing sounds complete ++ virtual void Free( bool immediate ); + +- // the parms specified will be the default overrides for all sounds started on this emitter. +- // NULL is acceptable for parms +- virtual void UpdateEmitter(const idVec3 &origin, int listenerId, const soundShaderParms_t *parms); ++ // the parms specified will be the default overrides for all sounds started on this emitter. ++ // NULL is acceptable for parms ++ virtual void UpdateEmitter( const idVec3 &origin, int listenerId, const soundShaderParms_t *parms ); + +- // returns the length of the started sound in msec +- virtual int StartSound(const idSoundShader *shader, const s_channelType channel, float diversity = 0, int shaderFlags = 0, bool allowSlow = true /* D3XP */); ++ // returns the length of the started sound in msec ++ virtual int StartSound( const idSoundShader *shader, const s_channelType channel, float diversity = 0, int shaderFlags = 0, bool allowSlow = true /* D3XP */ ); + +- // can pass SCHANNEL_ANY +- virtual void ModifySound(const s_channelType channel, const soundShaderParms_t *parms); +- virtual void StopSound(const s_channelType channel); +- virtual void FadeSound(const s_channelType channel, float to, float over); ++ // can pass SCHANNEL_ANY ++ virtual void ModifySound( const s_channelType channel, const soundShaderParms_t *parms ); ++ virtual void StopSound( const s_channelType channel ); ++ virtual void FadeSound( const s_channelType channel, float to, float over ); + + #ifdef _RAVEN + virtual void UpdateEmitter(const idVec3& origin, const idVec3& velocity, int listenerId, const soundShaderParms_t* parms) { +@@ -586,57 +440,57 @@ class idSoundEmitterLocal : public idSoundEmitter + + virtual bool CurrentlyPlaying(void) const; + +- // can pass SCHANNEL_ANY +- virtual float CurrentAmplitude(void); ++ // can pass SCHANNEL_ANY ++ virtual float CurrentAmplitude( void ); + +- // used for save games +- virtual int Index(void) const; ++ // used for save games ++ virtual int Index( void ) const; + +- //---------------------------------------------- ++ //---------------------------------------------- + +- void Clear(void); ++ void Clear( void ); + +- void OverrideParms(const soundShaderParms_t *base, const soundShaderParms_t *over, soundShaderParms_t *out); +- void CheckForCompletion(int current44kHzTime); +- void Spatialize(idVec3 listenerPos, int listenerArea, idRenderWorld *rw); ++ void OverrideParms( const soundShaderParms_t *base, const soundShaderParms_t *over, soundShaderParms_t *out ); ++ void CheckForCompletion( int current44kHzTime ); ++ void Spatialize( idVec3 listenerPos, int listenerArea, idRenderWorld *rw ); + +- idSoundWorldLocal *soundWorld; // the world that holds this emitter ++ idSoundWorldLocal * soundWorld; // the world that holds this emitter + +- int index; // in world emitter list +- removeStatus_t removeStatus; ++ int index; // in world emitter list ++ removeStatus_t removeStatus; + +- idVec3 origin; +- int listenerId; +- soundShaderParms_t parms; // default overrides for all channels ++ idVec3 origin; ++ int listenerId; ++ soundShaderParms_t parms; // default overrides for all channels + + +- // the following are calculated in UpdateEmitter, and don't need to be archived +- float maxDistance; // greatest of all playing channel distances +- int lastValidPortalArea; // so an emitter that slides out of the world continues playing +- bool playing; // if false, no channel is active +- bool hasShakes; +- idVec3 spatializedOrigin; // the virtual sound origin, either the real sound origin, +- // or a point through a portal chain +- float realDistance; // in meters +- float distance; // in meters, this may be the straight-line distance, or +- // it may go through a chain of portals. If there +- // is not an open-portal path, distance will be > maxDistance ++ // the following are calculated in UpdateEmitter, and don't need to be archived ++ float maxDistance; // greatest of all playing channel distances ++ int lastValidPortalArea; // so an emitter that slides out of the world continues playing ++ bool playing; // if false, no channel is active ++ bool hasShakes; ++ idVec3 spatializedOrigin; // the virtual sound origin, either the real sound origin, ++ // or a point through a portal chain ++ float realDistance; // in meters ++ float distance; // in meters, this may be the straight-line distance, or ++ // it may go through a chain of portals. If there ++ // is not an open-portal path, distance will be > maxDistance + +- // a single soundEmitter can have many channels playing from the same point +- idSoundChannel channels[SOUND_MAX_CHANNELS]; ++ // a single soundEmitter can have many channels playing from the same point ++ idSoundChannel channels[SOUND_MAX_CHANNELS]; + +- idSlowChannel slowChannels[SOUND_MAX_CHANNELS]; ++ idSlowChannel slowChannels[SOUND_MAX_CHANNELS]; + +- idSlowChannel GetSlowChannel(const idSoundChannel *chan); +- void SetSlowChannel(const idSoundChannel *chan, idSlowChannel slow); +- void ResetSlowChannel(const idSoundChannel *chan); ++ idSlowChannel GetSlowChannel( const idSoundChannel *chan ); ++ void SetSlowChannel( const idSoundChannel *chan, idSlowChannel slow ); ++ void ResetSlowChannel( const idSoundChannel *chan ); + +- // this is just used for feedback to the game or rendering system: +- // flashing lights and screen shakes. Because the material expression +- // evaluation doesn't do common subexpression removal, we cache the +- // last generated value +- int ampTime; +- float amplitude; ++ // this is just used for feedback to the game or rendering system: ++ // flashing lights and screen shakes. Because the material expression ++ // evaluation doesn't do common subexpression removal, we cache the ++ // last generated value ++ int ampTime; ++ float amplitude; + }; + + +@@ -648,23 +502,22 @@ idSoundWorldLocal + =================================================================================== + */ + +-class s_stats +-{ +- public: +- s_stats(void) { +- rinuse = 0; +- runs = 1; +- timeinprocess = 0; +- missedWindow = 0; +- missedUpdateWindow = 0; +- activeSounds = 0; +- } +- int rinuse; +- int runs; +- int timeinprocess; +- int missedWindow; +- int missedUpdateWindow; +- int activeSounds; ++class s_stats { ++public: ++ s_stats( void ) { ++ rinuse = 0; ++ runs = 1; ++ timeinprocess = 0; ++ missedWindow = 0; ++ missedUpdateWindow = 0; ++ activeSounds = 0; ++ } ++ int rinuse; ++ int runs; ++ int timeinprocess; ++ int missedWindow; ++ int missedUpdateWindow; ++ int activeSounds; + }; + + typedef struct soundPortalTrace_s { +@@ -672,84 +525,82 @@ typedef struct soundPortalTrace_s { + const struct soundPortalTrace_s *prevStack; + } soundPortalTrace_t; + +-class idSoundWorldLocal : public idSoundWorld +-{ +- public: +- virtual ~idSoundWorldLocal(void); ++class idSoundWorldLocal : public idSoundWorld { ++public: ++ virtual ~idSoundWorldLocal( void ); + +- // call at each map start +- virtual void ClearAllSoundEmitters(void); +- virtual void StopAllSounds(void); ++ // call at each map start ++ virtual void ClearAllSoundEmitters( void ); ++ virtual void StopAllSounds( void ); + +- // get a new emitter that can play sounds in this world +- virtual idSoundEmitter *AllocSoundEmitter(void); ++ // get a new emitter that can play sounds in this world ++ virtual idSoundEmitter *AllocSoundEmitter( void ); + +- // for load games +- virtual idSoundEmitter *EmitterForIndex(int index); ++ // for load games ++ virtual idSoundEmitter *EmitterForIndex( int index ); + +- // query data from all emitters in the world +- virtual float CurrentShakeAmplitudeForPosition(const int time, const idVec3 &listererPosition); ++ // query data from all emitters in the world ++ virtual float CurrentShakeAmplitudeForPosition( const int time, const idVec3 &listererPosition ); + +- // where is the camera/microphone +- // listenerId allows listener-private sounds to be added +- virtual void PlaceListener(const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr &areaName); ++ // where is the camera/microphone ++ // listenerId allows listener-private sounds to be added ++ virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName ); + +- // fade all sounds in the world with a given shader soundClass +- // to is in Db (sigh), over is in seconds +- virtual void FadeSoundClasses(const int soundClass, const float to, const float over); ++ // fade all sounds in the world with a given shader soundClass ++ // to is in Db (sigh), over is in seconds ++ virtual void FadeSoundClasses( const int soundClass, const float to, const float over ); + +- // dumps the current state and begins archiving commands +- virtual void StartWritingDemo(idDemoFile *demo); +- virtual void StopWritingDemo(void); ++ // dumps the current state and begins archiving commands ++ virtual void StartWritingDemo( idDemoFile *demo ); ++ virtual void StopWritingDemo( void ); + +- // read a sound command from a demo file +- virtual void ProcessDemoCommand(idDemoFile *readDemo); ++ // read a sound command from a demo file ++ virtual void ProcessDemoCommand( idDemoFile *readDemo ); + +- // background music +- virtual void PlayShaderDirectly(const char *name, int channel = -1); ++ // background music ++ virtual void PlayShaderDirectly( const char *name, int channel = -1 ); + +- // pause and unpause the sound world +- virtual void Pause(void); +- virtual void UnPause(void); +- virtual bool IsPaused(void); ++ // pause and unpause the sound world ++ virtual void Pause( void ); ++ virtual void UnPause( void ); ++ virtual bool IsPaused( void ); + +- // avidump +- virtual void AVIOpen(const char *path, const char *name); +- virtual void AVIClose(void); ++ // avidump ++ virtual void AVIOpen( const char *path, const char *name ); ++ virtual void AVIClose( void ); + +- // SaveGame Support +- virtual void WriteToSaveGame(idFile *savefile); +- virtual void ReadFromSaveGame(idFile *savefile); ++ // SaveGame Support ++ virtual void WriteToSaveGame( idFile *savefile ); ++ virtual void ReadFromSaveGame( idFile *savefile ); + +- virtual void ReadFromSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch); +- virtual void ReadFromSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params); +- virtual void WriteToSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch); +- virtual void WriteToSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params); ++ virtual void ReadFromSaveGameSoundChannel( idFile *saveGame, idSoundChannel *ch ); ++ virtual void ReadFromSaveGameSoundShaderParams( idFile *saveGame, soundShaderParms_t *params ); ++ virtual void WriteToSaveGameSoundChannel( idFile *saveGame, idSoundChannel *ch ); ++ virtual void WriteToSaveGameSoundShaderParams( idFile *saveGame, soundShaderParms_t *params ); + +- virtual void SetSlowmo(bool active); +- virtual void SetSlowmoSpeed(float speed); +- virtual void SetEnviroSuit(bool active); ++ virtual void SetSlowmo( bool active ); ++ virtual void SetSlowmoSpeed( float speed ); ++ virtual void SetEnviroSuit( bool active ); + +- //======================================= ++ //======================================= + +- idSoundWorldLocal(void); ++ idSoundWorldLocal( void ); + +- void Shutdown(void); +- void Init(idRenderWorld *rw); +- void ClearBuffer(void); ++ void Shutdown( void ); ++ void Init( idRenderWorld *rw ); + +- // update +- void ForegroundUpdate(int currentTime); +- void OffsetSoundTime(int offset44kHz); ++ // update ++ void ForegroundUpdate( int currentTime ); ++ void OffsetSoundTime( int offset44kHz ); + +- idSoundEmitterLocal *AllocLocalSoundEmitter(); +- void CalcEars(int numSpeakers, idVec3 realOrigin, idVec3 listenerPos, idMat3 listenerAxis, float ears[6], float spatialize); +- void AddChannelContribution(idSoundEmitterLocal *sound, idSoundChannel *chan, +- int current44kHz, int numSpeakers, float *finalMixBuffer); +- void MixLoop(int current44kHz, int numSpeakers, float *finalMixBuffer); +- void AVIUpdate(void); +- void ResolveOrigin(const int stackDepth, const soundPortalTrace_t *prevStack, const int soundArea, const float dist, const idVec3 &soundOrigin, idSoundEmitterLocal *def); +- float FindAmplitude(idSoundEmitterLocal *sound, const int localTime, const idVec3 *listenerPosition, const s_channelType channel, bool shakesOnly); ++ idSoundEmitterLocal * AllocLocalSoundEmitter(); ++ void CalcEars( int numSpeakers, idVec3 realOrigin, idVec3 listenerPos, idMat3 listenerAxis, float ears[6], float spatialize ); ++ void AddChannelContribution( idSoundEmitterLocal *sound, idSoundChannel *chan, ++ int current44kHz, int numSpeakers, float *finalMixBuffer ); ++ void MixLoop( int current44kHz, int numSpeakers, float *finalMixBuffer ); ++ void AVIUpdate( void ); ++ void ResolveOrigin( const int stackDepth, const soundPortalTrace_t *prevStack, const int soundArea, const float dist, const idVec3& soundOrigin, idSoundEmitterLocal *def ); ++ float FindAmplitude( idSoundEmitterLocal *sound, const int localTime, const idVec3 *listenerPosition, const s_channelType channel, bool shakesOnly ); + + #ifdef _HUMANHEAD + virtual void RegisterLocation(int area, const char *locationName) { (void)area; (void)locationName; } +@@ -760,44 +611,36 @@ class idSoundWorldLocal : public idSoundWorld + #endif + //============================================ + +- idRenderWorld *rw; // for portals and debug drawing +- idDemoFile *writeDemo; // if not NULL, archive commands here ++ idRenderWorld * rw; // for portals and debug drawing ++ idDemoFile * writeDemo; // if not NULL, archive commands here + +- idMat3 listenerAxis; +- idVec3 listenerPos; // position in meters +- int listenerPrivateId; +- idVec3 listenerQU; // position in "quake units" +- int listenerArea; +- idStr listenerAreaName; +-#ifdef _OPENAL_EFX +- ALuint listenerEffect; +- ALuint listenerSlot; +- bool listenerAreFiltersInitialized; +- ALuint listenerFilters[2]; // 0 - direct; 1 - send. +- float listenerSlotReverbGain; +-#else ++ idMat3 listenerAxis; ++ idVec3 listenerPos; // position in meters ++ int listenerPrivateId; ++ idVec3 listenerQU; // position in "quake units" ++ int listenerArea; ++ idStr listenerAreaName; + int listenerEnvironmentID; +-#endif + +- int gameMsec; +- int game44kHz; +- int pause44kHz; +- int lastAVI44kHz; // determine when we need to mix and write another block ++ int gameMsec; ++ int game44kHz; ++ int pause44kHz; ++ int lastAVI44kHz; // determine when we need to mix and write another block + +- idListemitters; ++ idListemitters; + +- idSoundFade soundClassFade[SOUND_MAX_CLASSES]; // for global sound fading ++ idSoundFade soundClassFade[SOUND_MAX_CLASSES]; // for global sound fading + +- // avi stuff +- idFile *fpa[6]; +- idStr aviDemoPath; +- idStr aviDemoName; ++ // avi stuff ++ idFile * fpa[6]; ++ idStr aviDemoPath; ++ idStr aviDemoName; + +- idSoundEmitterLocal *localSound; // just for playShaderDirectly() ++ idSoundEmitterLocal * localSound; // just for playShaderDirectly() + +- bool slowmoActive; +- float slowmoSpeed; +- bool enviroSuitActive; ++ bool slowmoActive; ++ float slowmoSpeed; ++ bool enviroSuitActive; + }; + + /* +@@ -870,44 +713,43 @@ class idSoundSystemLocal : public idSoundSystem + isInitialized = false; + } + +- // all non-hardware initialization +- virtual void Init(void); ++ // all non-hardware initialization ++ virtual void Init( void ); + +- // shutdown routine +- virtual void Shutdown(void); +- virtual void ClearBuffer(void); ++ // shutdown routine ++ virtual void Shutdown( void ); + +- // sound is attached to the window, and must be recreated when the window is changed +- virtual bool ShutdownHW(void); +- virtual bool InitHW(void); ++ // sound is attached to the window, and must be recreated when the window is changed ++ virtual bool ShutdownHW( void ); ++ virtual bool InitHW( void ); + +- // async loop, called at 60Hz +- virtual int AsyncUpdate(int time); +- // async loop, when the sound driver uses a write strategy +- virtual int AsyncUpdateWrite(int time); +- // direct mixing called from the sound driver thread for OSes that support it +- virtual int AsyncMix(int soundTime, float *mixBuffer); ++ // async loop, called at 60Hz ++ virtual int AsyncUpdate( int time ); ++ // async loop, when the sound driver uses a write strategy ++ virtual int AsyncUpdateWrite( int time ); ++ // direct mixing called from the sound driver thread for OSes that support it ++ virtual int AsyncMix( int soundTime, float *mixBuffer ); + +- virtual void SetMute(bool mute); ++ virtual void SetMute( bool mute ); + +- virtual cinData_t ImageForTime(const int milliseconds, const bool waveform); ++ virtual cinData_t ImageForTime( const int milliseconds, const bool waveform ); + +- int GetSoundDecoderInfo(int index, soundDecoderInfo_t &decoderInfo); ++ int GetSoundDecoderInfo( int index, soundDecoderInfo_t &decoderInfo ); + +- // if rw == NULL, no portal occlusion or rendered debugging is available +- virtual idSoundWorld *AllocSoundWorld(idRenderWorld *rw); ++ // if rw == NULL, no portal occlusion or rendered debugging is available ++ virtual idSoundWorld *AllocSoundWorld( idRenderWorld *rw ); + +- // specifying NULL will cause silence to be played +- virtual void SetPlayingSoundWorld(idSoundWorld *soundWorld); ++ // specifying NULL will cause silence to be played ++ virtual void SetPlayingSoundWorld( idSoundWorld *soundWorld ); + +- // some tools, like the sound dialog, may be used in both the game and the editor +- // This can return NULL, so check! +- virtual idSoundWorld *GetPlayingSoundWorld(void); ++ // some tools, like the sound dialog, may be used in both the game and the editor ++ // This can return NULL, so check! ++ virtual idSoundWorld *GetPlayingSoundWorld( void ); + +- virtual void BeginLevelLoad(void); +- virtual void EndLevelLoad(const char *mapString); ++ virtual void BeginLevelLoad( void ); ++ virtual void EndLevelLoad( const char *mapString ); + +- virtual void PrintMemInfo(MemInfo_t *mi); ++ virtual void PrintMemInfo( MemInfo_t *mi ); + + virtual int IsEAXAvailable(void); + +@@ -1019,20 +861,19 @@ class idSoundSystemLocal : public idSoundSystem + + //------------------------- + +- int GetCurrent44kHzTime(void) const; +- float dB2Scale(const float val) const; +- int SamplesToMilliseconds(int samples) const; +- int MillisecondsToSamples(int ms) const; ++ int GetCurrent44kHzTime( void ) const; ++ float dB2Scale( const float val ) const; ++ int SamplesToMilliseconds( int samples ) const; ++ int MillisecondsToSamples( int ms ) const; + +- void DoEnviroSuit(float *samples, int numSamples, int numSpeakers); ++ void DoEnviroSuit( float* samples, int numSamples, int numSpeakers ); + +- ALuint AllocOpenALSource(idSoundChannel *chan, bool looping, bool stereo); +- void FreeOpenALSource(ALuint handle); ++ ALuint AllocOpenALSource( idSoundChannel *chan, bool looping, bool stereo ); ++ void FreeOpenALSource( ALuint handle ); + +- idAudioHardware *snd_audio_hw; +- idSoundCache *soundCache; ++ idSoundCache * soundCache; + +- idSoundWorldLocal *currentSoundWorld; // the one to mix each async tic ++ idSoundWorldLocal * currentSoundWorld; // the one to mix each async tic + + int olddwCurrentWritePos; // statistics + int buffers; // statistics +@@ -1040,8 +881,8 @@ class idSoundSystemLocal : public idSoundSystem + + unsigned int nextWriteBlock; + +- float realAccum[6*MIXBUFFER_SAMPLES+16]; +- float *finalMixBuffer; // points inside realAccum at a 16 byte aligned boundary ++ float realAccum[6*MIXBUFFER_SAMPLES+16]; ++ float * finalMixBuffer; // points inside realAccum at a 16 byte aligned boundary + + bool isInitialized; + bool muted; +@@ -1052,51 +893,28 @@ class idSoundSystemLocal : public idSoundSystem + int meterTops[256]; + int meterTopsTime[256]; + +- dword *graph; ++ dword * graph; + + float volumesDB[1200]; // dB to float volume conversion + +- idList fxList; ++ idList fxList; + +-#ifdef _OPENAL + ALCdevice *openalDevice; + ALCcontext *openalContext; + ALsizei openalSourceCount; + openalSource_t openalSources[256]; +- +-#ifdef _OPENAL_EFX +- LPALGENEFFECTS alGenEffects; +- LPALDELETEEFFECTS alDeleteEffects; +- LPALISEFFECT alIsEffect; +- LPALEFFECTI alEffecti; +- LPALEFFECTF alEffectf; +- LPALEFFECTFV alEffectfv; +- LPALGENFILTERS alGenFilters; +- LPALDELETEFILTERS alDeleteFilters; +- LPALISFILTER alIsFilter; +- LPALFILTERI alFilteri; +- LPALFILTERF alFilterf; +- LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots; +- LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots; +- LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot; +- LPALAUXILIARYEFFECTSLOTI alAuxiliaryEffectSloti; +- LPALAUXILIARYEFFECTSLOTF alAuxiliaryEffectSlotf; +- +- static idCVar s_alReverbGain; +-#else ++#if ID_OPENAL_EAX + EAXSet alEAXSet; + EAXGet alEAXGet; + EAXSetBufferMode alEAXSetBufferMode; + EAXGetBufferMode alEAXGetBufferMode; + #endif + idEFXFile EFXDatabase; +-#endif + bool efxloaded; +- // latches +- static bool useOpenAL; +- static bool useEAXReverb; //k: useEFXReverb if using EFX +- // mark available during initialization, or through an explicit test +- static int EAXAvailable; //k: EFXAvailable if using EFX ++ // latches ++ static bool useEAXReverb; ++ // mark available during initialization, or through an explicit test ++ static int EAXAvailable; + + + static idCVar s_noSound; +@@ -1147,104 +965,105 @@ extern idSoundSystemLocal soundSystemLocal; + + + /* +- =================================================================================== ++=================================================================================== + +- This class holds the actual wavefile bitmap, size, and info. ++ This class holds the actual wavefile bitmap, size, and info. + +- =================================================================================== +- */ ++=================================================================================== ++*/ + + const int SCACHE_SIZE = MIXBUFFER_SAMPLES*20; // 1/2 of a second (aroundabout) + +-class idSoundSample +-{ +- public: +- idSoundSample(); +- ~idSoundSample(); ++class idSoundSample { ++public: ++ idSoundSample(); ++ ~idSoundSample(); + +- idStr name; // name of the sample file +- ID_TIME_T timestamp; // the most recent of all images used in creation, for reloadImages command ++ idStr name; // name of the sample file ++ ID_TIME_T timestamp; // the most recent of all images used in creation, for reloadImages command + +- waveformatex_t objectInfo; // what are we caching +- int objectSize; // size of waveform in samples, excludes the header +- int objectMemSize; // object size in memory +- byte *nonCacheData; // if it's not cached +- byte *amplitudeData; // precomputed min,max amplitude pairs +- ALuint openalBuffer; // openal buffer +- bool hardwareBuffer; +- bool defaultSound; +- bool onDemand; +- bool purged; +- bool levelLoadReferenced; // so we can tell which samples aren't needed any more ++ waveformatex_t objectInfo; // what are we caching ++ int objectSize; // size of waveform in samples, excludes the header ++ int objectMemSize; // object size in memory ++ byte * nonCacheData; // if it's not cached ++ byte * amplitudeData; // precomputed min,max amplitude pairs ++ ALuint openalBuffer; // openal buffer ++ bool hardwareBuffer; ++ bool defaultSound; ++ bool onDemand; ++ bool purged; ++ bool levelLoadReferenced; // so we can tell which samples aren't needed any more + +- int LengthIn44kHzSamples() const; +- ID_TIME_T GetNewTimeStamp(void) const; +- void MakeDefault(); // turns it into a beep +- void Load(); // loads the current sound based on name +- void Reload(bool force); // reloads if timestamp has changed, or always if force +- void PurgeSoundSample(); // frees all data +- void CheckForDownSample(); // down sample if required +- bool FetchFromCache(int offset, const byte **output, int *position, int *size, const bool allowIO); ++ int LengthIn44kHzSamples() const; ++ ID_TIME_T GetNewTimeStamp( void ) const; ++ void MakeDefault(); // turns it into a beep ++ void Load(); // loads the current sound based on name ++ void Reload( bool force ); // reloads if timestamp has changed, or always if force ++ void PurgeSoundSample(); // frees all data ++ void CheckForDownSample(); // down sample if required ++ bool FetchFromCache( int offset, const byte **output, int *position, int *size, const bool allowIO ); + }; + + + /* +- =================================================================================== ++=================================================================================== + +- Sound sample decoder. ++ Sound sample decoder. + +- =================================================================================== +- */ ++=================================================================================== ++*/ + +-class idSampleDecoder +-{ +- public: +- static void Init(void); +- static void Shutdown(void); +- static idSampleDecoder *Alloc(void); +- static void Free(idSampleDecoder *decoder); +- static int GetNumUsedBlocks(void); +- static int GetUsedBlockMemory(void); ++class idSampleDecoder { ++public: ++ static void Init( void ); ++ static void Shutdown( void ); ++ static idSampleDecoder *Alloc( void ); ++ static void Free( idSampleDecoder *decoder ); ++ static int GetNumUsedBlocks( void ); ++ static int GetUsedBlockMemory( void ); + +- virtual ~idSampleDecoder(void) {} +- virtual void Decode(idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest) = 0; +- virtual void ClearDecoder(void) = 0; +- virtual idSoundSample *GetSample(void) const = 0; +- virtual int GetLastDecodeTime(void) const = 0; ++ virtual ~idSampleDecoder( void ) {} ++ virtual void Decode( idSoundSample *sample, int sampleOffset44k, int sampleCount44k, float *dest ) = 0; ++ virtual void ClearDecoder( void ) = 0; ++ virtual idSoundSample * GetSample( void ) const = 0; ++ virtual int GetLastDecodeTime( void ) const = 0; + }; + + + /* +- =================================================================================== ++=================================================================================== + +- The actual sound cache. ++ The actual sound cache. + +- =================================================================================== +- */ ++=================================================================================== ++*/ + +-class idSoundCache +-{ +- public: +- idSoundCache(); +- ~idSoundCache(); ++class idSoundCache { ++public: ++ idSoundCache(); ++ ~idSoundCache(); + +- idSoundSample *FindSound(const idStr &fname, bool loadOnDemandOnly); ++ idSoundSample * FindSound( const idStr &fname, bool loadOnDemandOnly ); + +- const int GetNumObjects(void) { +- return listCache.Num(); +- } +- const idSoundSample *GetObject(const int index) const; ++ const int GetNumObjects( void ) { return listCache.Num(); } ++ const idSoundSample * GetObject( const int index ) const; + +- void ReloadSounds(bool force); ++ void ReloadSounds( bool force ); + +- void BeginLevelLoad(); +- void EndLevelLoad(); ++ void BeginLevelLoad(); ++ void EndLevelLoad(); + +- void PrintMemInfo(MemInfo_t *mi); ++ void PrintMemInfo( MemInfo_t *mi ); + +- private: +- bool insideLevelLoad; +- idList listCache; ++private: ++ bool insideLevelLoad; ++ idList listCache; + }; ++ ++#if EFX_VERBOSE ++#define EFXprintf(...) do { common->Printf(__VA_ARGS__); } while (false) ++#else ++#define EFXprintf(...) do { } while (false) ++#endif + + #endif /* !__SND_LOCAL_H__ */ diff --git a/games/idtech4a-engine/patches/patch-sound_snd_shader_cpp b/games/idtech4a-engine/patches/patch-sound_snd_shader_cpp new file mode 100644 index 000000000..5c6934cec --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_shader_cpp @@ -0,0 +1,607 @@ +Index: sound/snd_shader.cpp +--- sound/snd_shader.cpp.orig ++++ sound/snd_shader.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -37,8 +37,7 @@ If you have questions concerning this license or the a + idSoundShader::Init + =============== + */ +-void idSoundShader::Init(void) +-{ ++void idSoundShader::Init( void ) { + desc = ""; + errorDuringParse = false; + onDemand = false; +@@ -63,8 +62,7 @@ void idSoundShader::Init(void) + idSoundShader::idSoundShader + =============== + */ +-idSoundShader::idSoundShader(void) +-{ ++idSoundShader::idSoundShader( void ) { + Init(); + } + +@@ -73,8 +71,7 @@ idSoundShader::idSoundShader(void) + idSoundShader::~idSoundShader + =============== + */ +-idSoundShader::~idSoundShader(void) +-{ ++idSoundShader::~idSoundShader( void ) { + } + + /* +@@ -82,9 +79,8 @@ idSoundShader::~idSoundShader(void) + idSoundShader::Size + ================= + */ +-size_t idSoundShader::Size(void) const +-{ +- return sizeof(idSoundShader); ++size_t idSoundShader::Size( void ) const { ++ return sizeof( idSoundShader ); + } + + /* +@@ -92,8 +88,7 @@ size_t idSoundShader::Size(void) const + idSoundShader::idSoundShader::FreeData + =============== + */ +-void idSoundShader::FreeData() +-{ ++void idSoundShader::FreeData() { + numEntries = 0; + numLeadins = 0; + } +@@ -103,22 +98,21 @@ void idSoundShader::FreeData() + idSoundShader::SetDefaultText + =================== + */ +-bool idSoundShader::SetDefaultText(void) +-{ ++bool idSoundShader::SetDefaultText( void ) { + idStr wavname; + + wavname = GetName(); +- wavname.DefaultFileExtension(".wav"); // if the name has .ogg in it, that will stay ++ wavname.DefaultFileExtension( ".wav" ); // if the name has .ogg in it, that will stay + + // if there exists a wav file with the same name +- if (1) { //fileSystem->ReadFile( wavname, NULL ) != -1 ) { ++ if ( 1 ) { //fileSystem->ReadFile( wavname, NULL ) != -1 ) { + char generated[2048]; +- idStr::snPrintf(generated, sizeof(generated), +- "sound %s // IMPLICITLY GENERATED\n" +- "{\n" +- "%s\n" +- "}\n", GetName(), wavname.c_str()); +- SetText(generated); ++ idStr::snPrintf( generated, sizeof( generated ), ++ "sound %s // IMPLICITLY GENERATED\n" ++ "{\n" ++ "%s\n" ++ "}\n", GetName(), wavname.c_str() ); ++ SetText( generated ); + return true; + } else { + return false; +@@ -130,8 +124,7 @@ bool idSoundShader::SetDefaultText(void) + DefaultDefinition + =================== + */ +-const char *idSoundShader::DefaultDefinition() const +-{ ++const char *idSoundShader::DefaultDefinition() const { + return + "{\n" + #ifdef _RAVEN //k: default is sound/_default.ogg +@@ -157,18 +150,17 @@ bool idSoundShader::Parse(const char *text, const int + { + idLexer src; + +- src.LoadMemory(text, textLength, GetFileName(), GetLineNum()); +- src.SetFlags(DECL_LEXER_FLAGS); +- src.SkipUntilString("{"); ++ src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); ++ src.SetFlags( DECL_LEXER_FLAGS ); ++ src.SkipUntilString( "{" ); + + // deeper functions can set this, which will cause MakeDefault() to be called at the end + errorDuringParse = false; + +- if (!ParseShader(src) || errorDuringParse) { ++ if ( !ParseShader( src ) || errorDuringParse ) { + MakeDefault(); + return false; + } +- + return true; + } + +@@ -177,8 +169,7 @@ bool idSoundShader::Parse(const char *text, const int + idSoundShader::ParseShader + =============== + */ +-bool idSoundShader::ParseShader(idLexer &src) +-{ ++bool idSoundShader::ParseShader( idLexer &src ) { + int i; + idToken token; + +@@ -195,39 +186,37 @@ bool idSoundShader::ParseShader(idLexer &src) + speakerMask = 0; + altSound = NULL; + +- for (i = 0; i < SOUND_MAX_LIST_WAVS; i++) { ++ for( i = 0; i < SOUND_MAX_LIST_WAVS; i++ ) { + leadins[i] = NULL; + entries[i] = NULL; + } +- + numEntries = 0; + numLeadins = 0; + + int maxSamples = idSoundSystemLocal::s_maxSoundsPerShader.GetInteger(); +- +- if (com_makingBuild.GetBool() || maxSamples <= 0 || maxSamples > SOUND_MAX_LIST_WAVS) { ++ if ( com_makingBuild.GetBool() || maxSamples <= 0 || maxSamples > SOUND_MAX_LIST_WAVS ) { + maxSamples = SOUND_MAX_LIST_WAVS; + } + +- while (1) { +- if (!src.ExpectAnyToken(&token)) { ++ while ( 1 ) { ++ if ( !src.ExpectAnyToken( &token ) ) { + return false; + } + // end of definition +- else if (token == "}") { ++ else if ( token == "}" ) { + break; + } + // minimum number of sounds +- else if (!token.Icmp("minSamples")) { +- maxSamples = idMath::ClampInt(src.ParseInt(), SOUND_MAX_LIST_WAVS, maxSamples); ++ else if ( !token.Icmp( "minSamples" ) ) { ++ maxSamples = idMath::ClampInt( src.ParseInt(), SOUND_MAX_LIST_WAVS, maxSamples ); + } + // description +- else if (!token.Icmp("description")) { +- src.ReadTokenOnLine(&token); ++ else if ( !token.Icmp( "description" ) ) { ++ src.ReadTokenOnLine( &token ); + desc = token.c_str(); + } + // mindistance +- else if (!token.Icmp("mindistance")) { ++ else if ( !token.Icmp( "mindistance" ) ) { + parms.minDistance = src.ParseFloat(); + #ifdef _RAVEN // scale + // jmarshall: scale to doom 3 distance +@@ -235,7 +224,7 @@ bool idSoundShader::ParseShader(idLexer &src) + #endif + } + // maxdistance +- else if (!token.Icmp("maxdistance")) { ++ else if ( !token.Icmp( "maxdistance" ) ) { + parms.maxDistance = src.ParseFloat(); + #ifdef _RAVEN // scale + // jmarshall: scale to doom 3 distance +@@ -282,58 +271,55 @@ bool idSoundShader::ParseShader(idLexer &src) + } + #endif + // shakes screen +- else if (!token.Icmp("shakes")) { +- src.ExpectAnyToken(&token); +- +- if (token.type == TT_NUMBER) { ++ else if ( !token.Icmp( "shakes" ) ) { ++ src.ExpectAnyToken( &token ); ++ if ( token.type == TT_NUMBER ) { + parms.shakes = token.GetFloatValue(); + } else { +- src.UnreadToken(&token); ++ src.UnreadToken( &token ); + parms.shakes = 1.0f; + } + } + // reverb +- else if (!token.Icmp("reverb")) { +- int reg0 = src.ParseFloat(); +- +- if (!src.ExpectTokenString(",")) { ++ else if ( !token.Icmp( "reverb" ) ) { ++ src.ParseFloat(); ++ if ( !src.ExpectTokenString( "," ) ) { + src.FreeSource(); + return false; + } +- +- int reg1 = src.ParseFloat(); ++ src.ParseFloat(); + // no longer supported + } + // volume +- else if (!token.Icmp("volume")) { ++ else if ( !token.Icmp( "volume" ) ) { + parms.volume = src.ParseFloat(); + } + // leadinVolume is used to allow light breaking leadin sounds to be much louder than the broken loop +- else if (!token.Icmp("leadinVolume")) { ++ else if ( !token.Icmp( "leadinVolume" ) ) { + leadinVolume = src.ParseFloat(); + } + // speaker mask +- else if (!token.Icmp("mask_center")) { ++ else if ( !token.Icmp( "mask_center" ) ) { + speakerMask |= 1<FindSound(token.c_str()); ++ altSound = declManager->FindSound( token.c_str() ); + } + // ordered +- else if (!token.Icmp("ordered")) { ++ else if ( !token.Icmp( "ordered" ) ) { + // no longer supported + } + // no_dups +- else if (!token.Icmp("no_dups")) { ++ else if ( !token.Icmp( "no_dups" ) ) { + parms.soundShaderFlags |= SSF_NO_DUPS; + } + // no_flicker +- else if (!token.Icmp("no_flicker")) { ++ else if ( !token.Icmp( "no_flicker" ) ) { + parms.soundShaderFlags |= SSF_NO_FLICKER; + } + // plain +- else if (!token.Icmp("plain")) { ++ else if ( !token.Icmp( "plain" ) ) { + // no longer supported + } + // looping +- else if (!token.Icmp("looping")) { ++ else if ( !token.Icmp( "looping" ) ) { + parms.soundShaderFlags |= SSF_LOOPING; + } + // no occlusion +- else if (!token.Icmp("no_occlusion")) { ++ else if ( !token.Icmp( "no_occlusion" ) ) { + parms.soundShaderFlags |= SSF_NO_OCCLUSION; + } + // private +- else if (!token.Icmp("private")) { ++ else if ( !token.Icmp( "private" ) ) { + parms.soundShaderFlags |= SSF_PRIVATE_SOUND; + } + // antiPrivate +- else if (!token.Icmp("antiPrivate")) { ++ else if ( !token.Icmp( "antiPrivate" ) ) { + parms.soundShaderFlags |= SSF_ANTI_PRIVATE_SOUND; + } + // once +- else if (!token.Icmp("playonce")) { ++ else if ( !token.Icmp( "playonce" ) ) { + parms.soundShaderFlags |= SSF_PLAY_ONCE; + } + // global +- else if (!token.Icmp("global")) { ++ else if ( !token.Icmp( "global" ) ) { + parms.soundShaderFlags |= SSF_GLOBAL; + } + // unclamped +- else if (!token.Icmp("unclamped")) { ++ else if ( !token.Icmp( "unclamped" ) ) { + parms.soundShaderFlags |= SSF_UNCLAMPED; + } + // omnidirectional +- else if (!token.Icmp("omnidirectional")) { ++ else if ( !token.Icmp( "omnidirectional" ) ) { + parms.soundShaderFlags |= SSF_OMNIDIRECTIONAL; + } + // onDemand can't be a parms, because we must track all references and overrides would confuse it +- else if (!token.Icmp("onDemand")) { ++ else if ( !token.Icmp( "onDemand" ) ) { + // no longer loading sounds on demand + //onDemand = true; + } +@@ -450,15 +435,14 @@ bool idSoundShader::ParseShader(idLexer &src) + #endif + + // the wave files +- else if (!token.Icmp("leadin")) { ++ else if ( !token.Icmp( "leadin" ) ) { + // add to the leadin list +- if (!src.ReadToken(&token)) { +- src.Warning("Expected sound after leadin"); ++ if ( !src.ReadToken( &token ) ) { ++ src.Warning( "Expected sound after leadin" ); + return false; + } +- +- if (soundSystemLocal.soundCache && numLeadins < maxSamples) { +- leadins[ numLeadins ] = soundSystemLocal.soundCache->FindSound(token.c_str(), onDemand); ++ if ( soundSystemLocal.soundCache && numLeadins < maxSamples ) { ++ leadins[ numLeadins ] = soundSystemLocal.soundCache->FindSound( token.c_str(), onDemand ); + numLeadins++; + } + #ifdef _RAVEN //k: quake4 snd get sound file +@@ -522,7 +506,7 @@ bool idSoundShader::ParseShader(idLexer &src) + } + } else if (token.Find(".wav", false) != -1 || token.Find(".ogg", false) != -1) { + // add to the wav list +- if (soundSystemLocal.soundCache && numEntries < maxSamples) { ++ if ( soundSystemLocal.soundCache && numEntries < maxSamples ) { + token.BackSlashesToSlashes(); + + idStr work = token; +@@ -552,32 +536,29 @@ bool idSoundShader::ParseShader(idLexer &src) + if (lang.Icmp("english") != 0 && token.Find("sound/vo/", false) >= 0) { + idStr work = token; + work.ToLower(); +- work.StripLeading("sound/vo/"); +- work = va("sound/vo/%s/%s", lang.c_str(), work.c_str()); +- +- if (fileSystem->ReadFile(work, NULL, NULL) > 0) { ++ work.StripLeading( "sound/vo/" ); ++ work = va( "sound/vo/%s/%s", lang.c_str(), work.c_str() ); ++ if ( fileSystem->ReadFile( work, NULL, NULL ) > 0 ) { + token = work; + } else { + // also try to find it with the .ogg extension +- work.SetFileExtension(".ogg"); +- +- if (fileSystem->ReadFile(work, NULL, NULL) > 0) { ++ work.SetFileExtension( ".ogg" ); ++ if ( fileSystem->ReadFile( work, NULL, NULL ) > 0 ) { + token = work; + } + } + } +- +- entries[ numEntries ] = soundSystemLocal.soundCache->FindSound(token.c_str(), onDemand); ++ entries[ numEntries ] = soundSystemLocal.soundCache->FindSound( token.c_str(), onDemand ); + numEntries++; + } + #endif + } else { +- src.Warning("unknown token '%s'", token.c_str()); ++ src.Warning( "unknown token '%s'", token.c_str() ); + return false; + } + } + +- if (parms.shakes > 0.0f) { ++ if ( parms.shakes > 0.0f ) { + CheckShakesAndOgg(); + } + +@@ -589,27 +570,24 @@ bool idSoundShader::ParseShader(idLexer &src) + idSoundShader::CheckShakesAndOgg + =============== + */ +-bool idSoundShader::CheckShakesAndOgg(void) const +-{ ++bool idSoundShader::CheckShakesAndOgg( void ) const { + int i; + bool ret = false; + +- for (i = 0; i < numLeadins; i++) { +- if (leadins[ i ]->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) { +- common->Warning("sound shader '%s' has shakes and uses OGG file '%s'", +- GetName(), leadins[ i ]->name.c_str()); ++ for ( i = 0; i < numLeadins; i++ ) { ++ if ( leadins[ i ]->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) { ++ common->Warning( "sound shader '%s' has shakes and uses OGG file '%s'", ++ GetName(), leadins[ i ]->name.c_str() ); + ret = true; + } + } +- +- for (i = 0; i < numEntries; i++) { +- if (entries[ i ]->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) { +- common->Warning("sound shader '%s' has shakes and uses OGG file '%s'", +- GetName(), entries[ i ]->name.c_str()); ++ for ( i = 0; i < numEntries; i++ ) { ++ if ( entries[ i ]->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) { ++ common->Warning( "sound shader '%s' has shakes and uses OGG file '%s'", ++ GetName(), entries[ i ]->name.c_str() ); + ret = true; + } + } +- + return ret; + } + +@@ -618,31 +596,25 @@ bool idSoundShader::CheckShakesAndOgg(void) const + idSoundShader::List + =============== + */ +-void idSoundShader::List() const +-{ ++void idSoundShader::List() const { + idStrList shaders; + +- common->Printf("%4i: %s\n", Index(), GetName()); +- +- if (idStr::Icmp(GetDescription(), "") != 0) { +- common->Printf(" description: %s\n", GetDescription()); ++ common->Printf( "%4i: %s\n", Index(), GetName() ); ++ if ( idStr::Icmp( GetDescription(), "" ) != 0 ) { ++ common->Printf( " description: %s\n", GetDescription() ); + } +- +- for (int k = 0; k < numLeadins ; k++) { ++ for( int k = 0; k < numLeadins ; k++ ) { + const idSoundSample *objectp = leadins[k]; +- +- if (objectp) { +- common->Printf(" %5dms %4dKb %s (LEADIN)\n", soundSystemLocal.SamplesToMilliseconds(objectp->LengthIn44kHzSamples()), (objectp->objectMemSize/1024) +- ,objectp->name.c_str()); ++ if ( objectp ) { ++ common->Printf( " %5dms %4dKb %s (LEADIN)\n", soundSystemLocal.SamplesToMilliseconds(objectp->LengthIn44kHzSamples()), (objectp->objectMemSize/1024) ++ ,objectp->name.c_str() ); + } + } +- +- for (int k = 0; k < numEntries; k++) { ++ for( int k = 0; k < numEntries; k++ ) { + const idSoundSample *objectp = entries[k]; +- +- if (objectp) { +- common->Printf(" %5dms %4dKb %s\n", soundSystemLocal.SamplesToMilliseconds(objectp->LengthIn44kHzSamples()), (objectp->objectMemSize/1024) +- ,objectp->name.c_str()); ++ if ( objectp ) { ++ common->Printf( " %5dms %4dKb %s\n", soundSystemLocal.SamplesToMilliseconds(objectp->LengthIn44kHzSamples()), (objectp->objectMemSize/1024) ++ ,objectp->name.c_str() ); + } + } + } +@@ -652,8 +624,7 @@ void idSoundShader::List() const + idSoundShader::GetAltSound + =============== + */ +-const idSoundShader *idSoundShader::GetAltSound(void) const +-{ ++const idSoundShader *idSoundShader::GetAltSound( void ) const { + return altSound; + } + +@@ -662,8 +633,7 @@ const idSoundShader *idSoundShader::GetAltSound(void) + idSoundShader::GetMinDistance + =============== + */ +-float idSoundShader::GetMinDistance() const +-{ ++float idSoundShader::GetMinDistance() const { + return parms.minDistance; + } + +@@ -672,8 +642,7 @@ float idSoundShader::GetMinDistance() const + idSoundShader::GetMaxDistance + =============== + */ +-float idSoundShader::GetMaxDistance() const +-{ ++float idSoundShader::GetMaxDistance() const { + return parms.maxDistance; + } + +@@ -682,8 +651,7 @@ float idSoundShader::GetMaxDistance() const + idSoundShader::GetDescription + =============== + */ +-const char *idSoundShader::GetDescription() const +-{ ++const char *idSoundShader::GetDescription() const { + return desc; + } + +@@ -692,14 +660,12 @@ const char *idSoundShader::GetDescription() const + idSoundShader::HasDefaultSound + =============== + */ +-bool idSoundShader::HasDefaultSound() const +-{ +- for (int i = 0; i < numEntries; i++) { +- if (entries[i] && entries[i]->defaultSound) { ++bool idSoundShader::HasDefaultSound() const { ++ for ( int i = 0; i < numEntries; i++ ) { ++ if ( entries[i] && entries[i]->defaultSound ) { + return true; + } + } +- + return false; + } + +@@ -708,8 +674,7 @@ bool idSoundShader::HasDefaultSound() const + idSoundShader::GetParms + =============== + */ +-const soundShaderParms_t *idSoundShader::GetParms() const +-{ ++const soundShaderParms_t *idSoundShader::GetParms() const { + return &parms; + } + +@@ -718,8 +683,7 @@ const soundShaderParms_t *idSoundShader::GetParms() co + idSoundShader::GetNumSounds + =============== + */ +-int idSoundShader::GetNumSounds() const +-{ ++int idSoundShader::GetNumSounds() const { + return numLeadins + numEntries; + } + +@@ -728,19 +692,15 @@ int idSoundShader::GetNumSounds() const + idSoundShader::GetSound + =============== + */ +-const char *idSoundShader::GetSound(int index) const +-{ +- if (index >= 0) { +- if (index < numLeadins) { ++const char *idSoundShader::GetSound( int index ) const { ++ if ( index >= 0 ) { ++ if ( index < numLeadins ) { + return leadins[index]->name.c_str(); + } +- + index -= numLeadins; +- +- if (index < numEntries) { ++ if ( index < numEntries ) { + return entries[index]->name.c_str(); + } + } +- + return ""; + } diff --git a/games/idtech4a-engine/patches/patch-sound_snd_system_cpp b/games/idtech4a-engine/patches/patch-sound_snd_system_cpp new file mode 100644 index 000000000..26bfd58e7 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_system_cpp @@ -0,0 +1,1979 @@ +Index: sound/snd_system.cpp +--- sound/snd_system.cpp.orig ++++ sound/snd_system.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -30,74 +30,60 @@ If you have questions concerning this license or the a + #pragma hdrstop + + #include "snd_local.h" +-#include "sound.h" + + #ifdef ID_DEDICATED +-idCVar idSoundSystemLocal::s_noSound("s_noSound", "1", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, ""); ++idCVar idSoundSystemLocal::s_noSound( "s_noSound", "1", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "" ); + #else +-idCVar idSoundSystemLocal::s_noSound("s_noSound", "0", CVAR_SOUND | CVAR_BOOL | CVAR_NOCHEAT, ""); ++idCVar idSoundSystemLocal::s_noSound( "s_noSound", "0", CVAR_SOUND | CVAR_BOOL | CVAR_NOCHEAT, "" ); + #endif +-idCVar idSoundSystemLocal::s_quadraticFalloff("s_quadraticFalloff", "1", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_drawSounds("s_drawSounds", "0", CVAR_SOUND | CVAR_INTEGER, "", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2>); +-idCVar idSoundSystemLocal::s_showStartSound("s_showStartSound", "0", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_useOcclusion("s_useOcclusion", "1", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_maxSoundsPerShader("s_maxSoundsPerShader", "0", CVAR_SOUND | CVAR_ARCHIVE, "", 0, 10, idCmdSystem::ArgCompletion_Integer<0,10>); +-idCVar idSoundSystemLocal::s_showLevelMeter("s_showLevelMeter", "0", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_constantAmplitude("s_constantAmplitude", "-1", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_minVolume6("s_minVolume6", "0", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_dotbias6("s_dotbias6", "0.8", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_minVolume2("s_minVolume2", "0.25", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_dotbias2("s_dotbias2", "1.1", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_spatializationDecay("s_spatializationDecay", "2", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_reverse("s_reverse", "0", CVAR_SOUND | CVAR_ARCHIVE | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_meterTopTime("s_meterTopTime", "2000", CVAR_SOUND | CVAR_ARCHIVE | CVAR_INTEGER, ""); +-idCVar idSoundSystemLocal::s_volume("s_volume_dB", "0", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume in dB"); +-idCVar idSoundSystemLocal::s_playDefaultSound("s_playDefaultSound", "1", CVAR_SOUND | CVAR_ARCHIVE | CVAR_BOOL, "play a beep for missing sounds"); +-idCVar idSoundSystemLocal::s_subFraction("s_subFraction", "0.75", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume to subwoofer in 5.1"); +-idCVar idSoundSystemLocal::s_globalFraction("s_globalFraction", "0.8", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume to all speakers when not spatialized"); +-idCVar idSoundSystemLocal::s_doorDistanceAdd("s_doorDistanceAdd", "150", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "reduce sound volume with this distance when going through a door"); +-idCVar idSoundSystemLocal::s_singleEmitter("s_singleEmitter", "0", CVAR_SOUND | CVAR_INTEGER, "mute all sounds but this emitter"); +-idCVar idSoundSystemLocal::s_numberOfSpeakers("s_numberOfSpeakers", "2", CVAR_SOUND | CVAR_ARCHIVE, "number of speakers"); +-idCVar idSoundSystemLocal::s_force22kHz("s_force22kHz", "0", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_clipVolumes("s_clipVolumes", "1", CVAR_SOUND | CVAR_BOOL, ""); +-idCVar idSoundSystemLocal::s_realTimeDecoding("s_realTimeDecoding", "1", CVAR_SOUND | CVAR_BOOL | CVAR_INIT, ""); ++idCVar idSoundSystemLocal::s_quadraticFalloff( "s_quadraticFalloff", "1", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_drawSounds( "s_drawSounds", "0", CVAR_SOUND | CVAR_INTEGER, "", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> ); ++idCVar idSoundSystemLocal::s_showStartSound( "s_showStartSound", "0", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_useOcclusion( "s_useOcclusion", "1", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_maxSoundsPerShader( "s_maxSoundsPerShader", "0", CVAR_SOUND | CVAR_ARCHIVE, "", 0, 10, idCmdSystem::ArgCompletion_Integer<0,10> ); ++idCVar idSoundSystemLocal::s_showLevelMeter( "s_showLevelMeter", "0", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_constantAmplitude( "s_constantAmplitude", "-1", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_minVolume6( "s_minVolume6", "0", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_dotbias6( "s_dotbias6", "0.8", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_minVolume2( "s_minVolume2", "0.25", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_dotbias2( "s_dotbias2", "1.1", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_spatializationDecay( "s_spatializationDecay", "2", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_reverse( "s_reverse", "0", CVAR_SOUND | CVAR_ARCHIVE | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_meterTopTime( "s_meterTopTime", "2000", CVAR_SOUND | CVAR_ARCHIVE | CVAR_INTEGER, "" ); ++idCVar idSoundSystemLocal::s_volume( "s_volume_dB", "0", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume in dB" ); ++idCVar idSoundSystemLocal::s_playDefaultSound( "s_playDefaultSound", "1", CVAR_SOUND | CVAR_ARCHIVE | CVAR_BOOL, "play a beep for missing sounds" ); ++idCVar idSoundSystemLocal::s_subFraction( "s_subFraction", "0.75", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume to subwoofer in 5.1" ); ++idCVar idSoundSystemLocal::s_globalFraction( "s_globalFraction", "0.8", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "volume to all speakers when not spatialized" ); ++idCVar idSoundSystemLocal::s_doorDistanceAdd( "s_doorDistanceAdd", "150", CVAR_SOUND | CVAR_ARCHIVE | CVAR_FLOAT, "reduce sound volume with this distance when going through a door" ); ++idCVar idSoundSystemLocal::s_singleEmitter( "s_singleEmitter", "0", CVAR_SOUND | CVAR_INTEGER, "mute all sounds but this emitter" ); ++idCVar idSoundSystemLocal::s_numberOfSpeakers( "s_numberOfSpeakers", "2", CVAR_SOUND | CVAR_ARCHIVE, "number of speakers" ); ++idCVar idSoundSystemLocal::s_force22kHz( "s_force22kHz", "0", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_clipVolumes( "s_clipVolumes", "1", CVAR_SOUND | CVAR_BOOL, "" ); ++idCVar idSoundSystemLocal::s_realTimeDecoding( "s_realTimeDecoding", "1", CVAR_SOUND | CVAR_BOOL | CVAR_INIT, "" ); + +-idCVar idSoundSystemLocal::s_slowAttenuate("s_slowAttenuate", "1", CVAR_SOUND | CVAR_BOOL, "slowmo sounds attenuate over shorted distance"); +-idCVar idSoundSystemLocal::s_enviroSuitCutoffFreq("s_enviroSuitCutoffFreq", "2000", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_enviroSuitCutoffQ("s_enviroSuitCutoffQ", "2", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_reverbTime("s_reverbTime", "1000", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_reverbFeedback("s_reverbFeedback", "0.333", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_enviroSuitVolumeScale("s_enviroSuitVolumeScale", "0.9", CVAR_SOUND | CVAR_FLOAT, ""); +-idCVar idSoundSystemLocal::s_skipHelltimeFX("s_skipHelltimeFX", "0", CVAR_SOUND | CVAR_BOOL, ""); ++idCVar idSoundSystemLocal::s_slowAttenuate( "s_slowAttenuate", "1", CVAR_SOUND | CVAR_BOOL, "slowmo sounds attenuate over shorted distance" ); ++idCVar idSoundSystemLocal::s_enviroSuitCutoffFreq( "s_enviroSuitCutoffFreq", "2000", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_enviroSuitCutoffQ( "s_enviroSuitCutoffQ", "2", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_reverbTime( "s_reverbTime", "1000", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_reverbFeedback( "s_reverbFeedback", "0.333", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_enviroSuitVolumeScale( "s_enviroSuitVolumeScale", "0.9", CVAR_SOUND | CVAR_FLOAT, "" ); ++idCVar idSoundSystemLocal::s_skipHelltimeFX( "s_skipHelltimeFX", "0", CVAR_SOUND | CVAR_BOOL, "" ); + + #if ID_OPENAL + // off by default. OpenAL DLL gets loaded on-demand +-#ifdef _WIN32 +-idCVar idSoundSystemLocal::s_libOpenAL("s_libOpenAL", "openal32.dll", CVAR_SOUND | CVAR_ARCHIVE, "OpenAL DLL name/path"); ++idCVar idSoundSystemLocal::s_libOpenAL( "s_libOpenAL", "openal32.dll", CVAR_SOUND | CVAR_ARCHIVE, "Deprecated, kept for compability" ); ++idCVar idSoundSystemLocal::s_useOpenAL( "s_useOpenAL", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "Deprecated, kept for compability" ); ++idCVar idSoundSystemLocal::s_useEAXReverb( "s_useEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "use EAX reverb" ); ++idCVar idSoundSystemLocal::s_muteEAXReverb( "s_muteEAXReverb", "0", CVAR_SOUND | CVAR_BOOL, "mute eax reverb" ); ++idCVar idSoundSystemLocal::s_decompressionLimit( "s_decompressionLimit", "6", CVAR_SOUND | CVAR_INTEGER | CVAR_ARCHIVE, "specifies maximum uncompressed sample length in seconds" ); + #else +-idCVar idSoundSystemLocal::s_libOpenAL("s_libOpenAL", "./libopenal.so", CVAR_SOUND | CVAR_ARCHIVE, "OpenAL DLL name/path"); ++idCVar idSoundSystemLocal::s_libOpenAL( "s_libOpenAL", "openal32.dll", CVAR_SOUND | CVAR_ARCHIVE, "OpenAL is not supported in this build" ); ++idCVar idSoundSystemLocal::s_useOpenAL( "s_useOpenAL", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "OpenAL is not supported in this build" ); ++idCVar idSoundSystemLocal::s_useEAXReverb( "s_useEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "EAX not available in this build" ); ++idCVar idSoundSystemLocal::s_muteEAXReverb( "s_muteEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "mute eax reverb" ); ++idCVar idSoundSystemLocal::s_decompressionLimit( "s_decompressionLimit", "6", CVAR_SOUND | CVAR_INTEGER | CVAR_ROM, "specifies maximum uncompressed sample length in seconds" ); + #endif +-#ifdef _WIN32 //karin: enable OpenAL default on Windows +-idCVar idSoundSystemLocal::s_useOpenAL("s_useOpenAL", "1", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "use OpenAL"); +-idCVar idSoundSystemLocal::s_useEAXReverb("s_useEAXReverb", "1", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "use EAX reverb"); +-#else +-idCVar idSoundSystemLocal::s_useOpenAL("s_useOpenAL", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "use OpenAL"); +-idCVar idSoundSystemLocal::s_useEAXReverb("s_useEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ARCHIVE, "use EAX reverb"); +-#endif +-idCVar idSoundSystemLocal::s_muteEAXReverb("s_muteEAXReverb", "0", CVAR_SOUND | CVAR_BOOL, "mute eax reverb"); +-idCVar idSoundSystemLocal::s_decompressionLimit("s_decompressionLimit", "6", CVAR_SOUND | CVAR_INTEGER | CVAR_ARCHIVE, "specifies maximum uncompressed sample length in seconds"); +-#else +-idCVar idSoundSystemLocal::s_libOpenAL("s_libOpenAL", "openal32.dll", CVAR_SOUND | CVAR_ROM, "OpenAL is not supported in this build"); +-idCVar idSoundSystemLocal::s_useOpenAL("s_useOpenAL", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "OpenAL is not supported in this build"); +-idCVar idSoundSystemLocal::s_useEAXReverb("s_useEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "EAX not available in this build"); +-idCVar idSoundSystemLocal::s_muteEAXReverb("s_muteEAXReverb", "0", CVAR_SOUND | CVAR_BOOL | CVAR_ROM, "mute eax reverb"); +-idCVar idSoundSystemLocal::s_decompressionLimit("s_decompressionLimit", "6", CVAR_SOUND | CVAR_INTEGER | CVAR_ROM, "specifies maximum uncompressed sample length in seconds"); +-#endif +-#ifdef _OPENAL_EFX +-idCVar idSoundSystemLocal::s_alReverbGain( "s_alReverbGain", "0.5", CVAR_SOUND | CVAR_FLOAT | CVAR_ARCHIVE, "reduce reverb strength (0.0 to 1.0)", 0.0f, 1.0f ); +-#endif + +-bool idSoundSystemLocal::useOpenAL = false; + bool idSoundSystemLocal::useEAXReverb = false; + int idSoundSystemLocal::EAXAvailable = -1; + +@@ -111,22 +97,18 @@ SoundReloadSounds_f + this is called from the main thread + =============== + */ +-void SoundReloadSounds_f(const idCmdArgs &args) +-{ +- if (!soundSystemLocal.soundCache) { ++void SoundReloadSounds_f( const idCmdArgs &args ) { ++ if ( !soundSystemLocal.soundCache ) { + return; + } +- + bool force = false; +- +- if (args.Argc() == 2) { ++ if ( args.Argc() == 2 ) { + force = true; + } +- +- soundSystem->SetMute(true); +- soundSystemLocal.soundCache->ReloadSounds(force); +- soundSystem->SetMute(false); +- common->Printf("sound: changed sounds reloaded\n"); ++ soundSystem->SetMute( true ); ++ soundSystemLocal.soundCache->ReloadSounds( force ); ++ soundSystem->SetMute( false ); ++ common->Printf( "sound: changed sounds reloaded\n" ); + } + + /* +@@ -136,13 +118,12 @@ ListSounds_f + Optional parameter to only list sounds containing that string + =============== + */ +-void ListSounds_f(const idCmdArgs &args) +-{ ++void ListSounds_f( const idCmdArgs &args ) { + int i; +- const char *snd = args.Argv(1); ++ const char *snd = args.Argv( 1 ); + +- if (!soundSystemLocal.soundCache) { +- common->Printf("No sound.\n"); ++ if ( !soundSystemLocal.soundCache ) { ++ common->Printf( "No sound.\n" ); + return; + } + +@@ -150,48 +131,39 @@ void ListSounds_f(const idCmdArgs &args) + int totalSamples = 0; + int totalMemory = 0; + int totalPCMMemory = 0; +- +- for (i = 0; i < soundSystemLocal.soundCache->GetNumObjects(); i++) { ++ for( i = 0; i < soundSystemLocal.soundCache->GetNumObjects(); i++ ) { + const idSoundSample *sample = soundSystemLocal.soundCache->GetObject(i); +- +- if (!sample) { ++ if ( !sample ) { + continue; + } +- +- if (snd && sample->name.Find(snd, false) < 0) { ++ if ( snd && sample->name.Find( snd, false ) < 0 ) { + continue; + } + + const waveformatex_t &info = sample->objectInfo; + +- const char *stereo = (info.nChannels == 2 ? "ST" : " "); ++ const char *stereo = ( info.nChannels == 2 ? "ST" : " " ); ++ const char *format = ( info.wFormatTag == WAVE_FORMAT_TAG_OGG ) ? "OGG" : "WAV"; ++ const char *defaulted = ( sample->defaultSound ? "(DEFAULTED)" : sample->purged ? "(PURGED)" : "" ); + +- const char *format = (info.wFormatTag == WAVE_FORMAT_TAG_OGG) ? "OGG" : "WAV"; ++ common->Printf( "%s %dkHz %6dms %5dkB %4s %s%s\n", stereo, sample->objectInfo.nSamplesPerSec / 1000, ++ soundSystemLocal.SamplesToMilliseconds( sample->LengthIn44kHzSamples() ), ++ sample->objectMemSize >> 10, format, sample->name.c_str(), defaulted ); + +- const char *defaulted = (sample->defaultSound ? "(DEFAULTED)" : sample->purged ? "(PURGED)" : ""); +- +- common->Printf("%s %dkHz %6dms %5dkB %4s %s%s\n", stereo, sample->objectInfo.nSamplesPerSec / 1000, +- soundSystemLocal.SamplesToMilliseconds(sample->LengthIn44kHzSamples()), +- sample->objectMemSize >> 10, format, sample->name.c_str(), defaulted); +- +- if (!sample->purged) { ++ if ( !sample->purged ) { + totalSamples += sample->objectSize; +- +- if (info.wFormatTag != WAVE_FORMAT_TAG_OGG) ++ if ( info.wFormatTag != WAVE_FORMAT_TAG_OGG ) + totalPCMMemory += sample->objectMemSize; +- +- if (!sample->hardwareBuffer) ++ if ( !sample->hardwareBuffer ) + totalMemory += sample->objectMemSize; + } +- + totalSounds++; + } +- +- common->Printf("%8d total sounds\n", totalSounds); +- common->Printf("%8d total samples loaded\n", totalSamples); +- common->Printf("%8d kB total system memory used\n", totalMemory >> 10); ++ common->Printf( "%8d total sounds\n", totalSounds ); ++ common->Printf( "%8d total samples loaded\n", totalSamples ); ++ common->Printf( "%8d kB total system memory used\n", totalMemory >> 10 ); + #if ID_OPENAL +- common->Printf("%8d kB total OpenAL audio memory used\n", (alGetInteger(alGetEnumValue((ALubyte *)"AL_EAX_RAM_SIZE")) - alGetInteger(alGetEnumValue((ALubyte *)"AL_EAX_RAM_FREE"))) >> 10); ++ common->Printf( "%8d kB total OpenAL audio memory used\n", ( alGetInteger( alGetEnumValue( "AL_EAX_RAM_SIZE" ) ) - alGetInteger( alGetEnumValue( "AL_EAX_RAM_FREE" ) ) ) >> 10 ); + #endif + } + +@@ -200,74 +172,69 @@ void ListSounds_f(const idCmdArgs &args) + ListSoundDecoders_f + =============== + */ +-void ListSoundDecoders_f(const idCmdArgs &args) +-{ ++void ListSoundDecoders_f( const idCmdArgs &args ) { + int i, j, numActiveDecoders, numWaitingDecoders; + idSoundWorldLocal *sw = soundSystemLocal.currentSoundWorld; + + numActiveDecoders = numWaitingDecoders = 0; + +- for (i = 0; i < sw->emitters.Num(); i++) { ++ for ( i = 0; i < sw->emitters.Num(); i++ ) { + idSoundEmitterLocal *sound = sw->emitters[i]; + +- if (!sound) { ++ if ( !sound ) { + continue; + } + + // run through all the channels +- for (j = 0; j < SOUND_MAX_CHANNELS; j++) { ++ for ( j = 0; j < SOUND_MAX_CHANNELS; j++ ) { + idSoundChannel *chan = &sound->channels[j]; + +- if (chan->decoder == NULL) { ++ if ( chan->decoder == NULL ) { + continue; + } + + idSoundSample *sample = chan->decoder->GetSample(); + +- if (sample != NULL) { ++ if ( sample != NULL ) { + continue; + } + +- const char *format = (chan->leadinSample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) ? "OGG" : "WAV"; ++ const char *format = ( chan->leadinSample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) ? "OGG" : "WAV"; ++ common->Printf( "%3d waiting %s: %s\n", numWaitingDecoders, format, chan->leadinSample->name.c_str() ); + +- common->Printf("%3d waiting %s: %s\n", numWaitingDecoders, format, chan->leadinSample->name.c_str()); +- + numWaitingDecoders++; + } + } + +- for (i = 0; i < sw->emitters.Num(); i++) { ++ for ( i = 0; i < sw->emitters.Num(); i++ ) { + idSoundEmitterLocal *sound = sw->emitters[i]; + +- if (!sound) { ++ if ( !sound ) { + continue; + } + + // run through all the channels +- for (j = 0; j < SOUND_MAX_CHANNELS; j++) { ++ for ( j = 0; j < SOUND_MAX_CHANNELS; j++ ) { + idSoundChannel *chan = &sound->channels[j]; + +- if (chan->decoder == NULL) { ++ if ( chan->decoder == NULL ) { + continue; + } + + idSoundSample *sample = chan->decoder->GetSample(); + +- if (sample == NULL) { ++ if ( sample == NULL ) { + continue; + } + +- const char *format = (sample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) ? "OGG" : "WAV"; ++ const char *format = ( sample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) ? "OGG" : "WAV"; + + int localTime = soundSystemLocal.GetCurrent44kHzTime() - chan->trigger44kHzTime; +- + int sampleTime = sample->LengthIn44kHzSamples() * sample->objectInfo.nChannels; +- + int percent; +- +- if (localTime > sampleTime) { +- if (chan->parms.soundShaderFlags & SSF_LOOPING) { +- percent = (localTime % sampleTime) * 100 / sampleTime; ++ if ( localTime > sampleTime ) { ++ if ( chan->parms.soundShaderFlags & SSF_LOOPING ) { ++ percent = ( localTime % sampleTime ) * 100 / sampleTime; + } else { + percent = 100; + } +@@ -275,16 +242,16 @@ void ListSoundDecoders_f(const idCmdArgs &args) + percent = localTime * 100 / sampleTime; + } + +- common->Printf("%3d decoding %3d%% %s: %s\n", numActiveDecoders, percent, format, sample->name.c_str()); ++ common->Printf( "%3d decoding %3d%% %s: %s\n", numActiveDecoders, percent, format, sample->name.c_str() ); + + numActiveDecoders++; + } + } + +- common->Printf("%d decoders\n", numWaitingDecoders + numActiveDecoders); +- common->Printf("%d waiting decoders\n", numWaitingDecoders); +- common->Printf("%d active decoders\n", numActiveDecoders); +- common->Printf("%d kB decoder memory in %d blocks\n", idSampleDecoder::GetUsedBlockMemory() >> 10, idSampleDecoder::GetNumUsedBlocks()); ++ common->Printf( "%d decoders\n", numWaitingDecoders + numActiveDecoders ); ++ common->Printf( "%d waiting decoders\n", numWaitingDecoders ); ++ common->Printf( "%d active decoders\n", numActiveDecoders ); ++ common->Printf( "%d kB decoder memory in %d blocks\n", idSampleDecoder::GetUsedBlockMemory() >> 10, idSampleDecoder::GetNumUsedBlocks() ); + } + + /* +@@ -294,15 +261,13 @@ TestSound_f + this is called from the main thread + =============== + */ +-void TestSound_f(const idCmdArgs &args) +-{ +- if (args.Argc() != 2) { +- common->Printf("Usage: testSound \n"); ++void TestSound_f( const idCmdArgs &args ) { ++ if ( args.Argc() != 2 ) { ++ common->Printf( "Usage: testSound \n" ); + return; + } +- +- if (soundSystemLocal.currentSoundWorld) { +- soundSystemLocal.currentSoundWorld->PlayShaderDirectly(args.Argv(1)); ++ if ( soundSystemLocal.currentSoundWorld ) { ++ soundSystemLocal.currentSoundWorld->PlayShaderDirectly( args.Argv( 1 ) ); + } + } + +@@ -315,12 +280,11 @@ restart the sound thread + this is called from the main thread + =============== + */ +-void SoundSystemRestart_f(const idCmdArgs &args) +-{ +- soundSystem->SetMute(true); ++void SoundSystemRestart_f( const idCmdArgs &args ) { ++ soundSystem->SetMute( true ); + soundSystemLocal.ShutdownHW(); + soundSystemLocal.InitHW(); +- soundSystem->SetMute(false); ++ soundSystem->SetMute( false ); + } + + #ifdef _HUMANHEAD +@@ -374,10 +338,9 @@ idSoundSystemLocal::Init + initialize the sound system + =============== + */ +-void idSoundSystemLocal::Init() +-{ ++void idSoundSystemLocal::Init() { + +- common->Printf("----- Initializing Sound System ------\n"); ++ common->Printf( "----- Initializing Sound System ------\n" ); + + isInitialized = false; + muted = false; +@@ -392,192 +355,104 @@ void idSoundSystemLocal::Init() + + nextWriteBlock = 0xffffffff; + +- memset(meterTops, 0, sizeof(meterTops)); +- memset(meterTopsTime, 0, sizeof(meterTopsTime)); ++ memset( meterTops, 0, sizeof( meterTops ) ); ++ memset( meterTopsTime, 0, sizeof( meterTopsTime ) ); + +- for (int i = -600; i < 600; i++) { ++ for( int i = -600; i < 600; i++ ) { + float pt = i * 0.1f; +- volumesDB[i+600] = pow(2.0f,(pt * (1.0f / 6.0f))); ++ volumesDB[i+600] = pow( 2.0f,( pt * ( 1.0f / 6.0f ) ) ); + } + + // make a 16 byte aligned finalMixBuffer +- finalMixBuffer = (float *)((((intptr_t)realAccum) + 15) & ~15); ++ finalMixBuffer = (float *) ( ( ( (intptr_t)realAccum ) + 15 ) & ~15 ); + + graph = NULL; + +- if (!s_noSound.GetBool()) { ++ if ( !s_noSound.GetBool() ) { + idSampleDecoder::Init(); + soundCache = new idSoundCache(); + } + + // set up openal device and context +-#if !defined(_OPENAL_SOFT) +- common->StartupVariable("s_useOpenAL", true); +- common->StartupVariable("s_useEAXReverb", true); +-#endif ++ common->StartupVariable( "s_useOpenAL", true ); ++ common->StartupVariable( "s_useEAXReverb", true ); + +-#ifdef _OPENAL +- if (idSoundSystemLocal::s_useOpenAL.GetBool() || idSoundSystemLocal::s_useEAXReverb.GetBool()) { +- // default all true +-#ifdef _OPENAL_SOFT +- idSoundSystemLocal::s_useOpenAL.SetBool(true); +-#endif +- if (!Sys_LoadOpenAL()) { +- idSoundSystemLocal::s_useOpenAL.SetBool(false); +- idSoundSystemLocal::s_useEAXReverb.SetBool(false); +-#ifdef _OPENAL_SOFT +- EAXAvailable = 0; +-#endif +- } else { +- common->Printf("Setup OpenAL device and context... "); +- openalDevice = alcOpenDevice(NULL); +- openalContext = alcCreateContext(openalDevice, NULL); +- alcMakeContextCurrent(openalContext); +- common->Printf("Done.\n"); ++ common->Printf( "Setup OpenAL device and context... " ); ++ openalDevice = alcOpenDevice( NULL ); ++ openalContext = alcCreateContext( openalDevice, NULL ); ++ alcMakeContextCurrent( openalContext ); ++ common->Printf( "Done.\n" ); + +- // log openal info +- common->Printf( "OpenAL vendor: %s\n", alGetString(AL_VENDOR) ); +- common->Printf( "OpenAL renderer: %s\n", alGetString(AL_RENDERER) ); +- common->Printf( "OpenAL version: %s\n", alGetString(AL_VERSION) ); +- +-#ifdef _OPENAL_EFX +- // try to obtain EFX extensions +- if(idSoundSystemLocal::s_useEAXReverb.GetBool()) +- { +- if (alcIsExtensionPresent(openalDevice, "ALC_EXT_EFX")) { +- common->Printf( "OpenAL: found EFX extension\n" ); +- EAXAvailable = 1; +- idSoundSystemLocal::s_useEAXReverb.SetBool( true ); +- +- alGenEffects = (LPALGENEFFECTS)alGetProcAddress(ID_ALCHAR "alGenEffects"); +- alDeleteEffects = (LPALDELETEEFFECTS)alGetProcAddress(ID_ALCHAR "alDeleteEffects"); +- alIsEffect = (LPALISEFFECT)alGetProcAddress(ID_ALCHAR "alIsEffect"); +- alEffecti = (LPALEFFECTI)alGetProcAddress(ID_ALCHAR "alEffecti"); +- alEffectf = (LPALEFFECTF)alGetProcAddress(ID_ALCHAR "alEffectf"); +- alEffectfv = (LPALEFFECTFV)alGetProcAddress(ID_ALCHAR "alEffectfv"); +- alGenFilters = (LPALGENFILTERS)alGetProcAddress(ID_ALCHAR "alGenFilters"); +- alDeleteFilters = (LPALDELETEFILTERS)alGetProcAddress(ID_ALCHAR "alDeleteFilters"); +- alIsFilter = (LPALISFILTER)alGetProcAddress(ID_ALCHAR "alIsFilter"); +- alFilteri = (LPALFILTERI)alGetProcAddress(ID_ALCHAR "alFilteri"); +- alFilterf = (LPALFILTERF)alGetProcAddress(ID_ALCHAR "alFilterf"); +- alGenAuxiliaryEffectSlots = (LPALGENAUXILIARYEFFECTSLOTS)alGetProcAddress(ID_ALCHAR "alGenAuxiliaryEffectSlots"); +- alDeleteAuxiliaryEffectSlots = (LPALDELETEAUXILIARYEFFECTSLOTS)alGetProcAddress(ID_ALCHAR "alDeleteAuxiliaryEffectSlots"); +- alIsAuxiliaryEffectSlot = (LPALISAUXILIARYEFFECTSLOT)alGetProcAddress(ID_ALCHAR "alIsAuxiliaryEffectSlot");; +- alAuxiliaryEffectSloti = (LPALAUXILIARYEFFECTSLOTI)alGetProcAddress(ID_ALCHAR "alAuxiliaryEffectSloti"); +- alAuxiliaryEffectSlotf = (LPALAUXILIARYEFFECTSLOTF)alGetProcAddress(ID_ALCHAR "alAuxiliaryEffectSlotf"); +- } else { +- common->Printf( "OpenAL: EFX extension not found\n" ); +- EAXAvailable = 0; +- idSoundSystemLocal::s_useEAXReverb.SetBool( false ); +- +- alGenEffects = NULL; +- alDeleteEffects = NULL; +- alIsEffect = NULL; +- alEffecti = NULL; +- alEffectf = NULL; +- alEffectfv = NULL; +- alGenFilters = NULL; +- alDeleteFilters = NULL; +- alIsFilter = NULL; +- alFilteri = NULL; +- alFilterf = NULL; +- alGenAuxiliaryEffectSlots = NULL; +- alDeleteAuxiliaryEffectSlots = NULL; +- alIsAuxiliaryEffectSlot = NULL; +- alAuxiliaryEffectSloti = NULL; +- alAuxiliaryEffectSlotf = NULL; +- } +- } +- else +- { +- EAXAvailable = 0; +- } ++#if ID_OPENAL_EAX ++ // try to obtain EAX extensions ++ if ( idSoundSystemLocal::s_useEAXReverb.GetBool() && alIsExtensionPresent( ID_ALCHAR "EAX4.0" ) ) { ++ alEAXSet = (EAXSet)alGetProcAddress( ID_ALCHAR "EAXSet" ); ++ alEAXGet = (EAXGet)alGetProcAddress( ID_ALCHAR "EAXGet" ); ++ common->Printf( "OpenAL: found EAX 4.0 extension\n" ); ++ EAXAvailable = 1; ++ } else { ++ common->Printf( "OpenAL: EAX 4.0 extension not found\n" ); ++ idSoundSystemLocal::s_useEAXReverb.SetBool( false ); ++ alEAXSet = (EAXSet)NULL; ++ alEAXGet = (EAXGet)NULL; ++ EAXAvailable = 0; ++ } + #else +- // try to obtain EAX extensions +- if (idSoundSystemLocal::s_useEAXReverb.GetBool() && alIsExtensionPresent(ID_ALCHAR "EAX4.0")) { +- idSoundSystemLocal::s_useOpenAL.SetBool(true); // EAX presence causes AL enable +- alEAXSet = (EAXSet)alGetProcAddress(ID_ALCHAR "EAXSet"); +- alEAXGet = (EAXGet)alGetProcAddress(ID_ALCHAR "EAXGet"); +- common->Printf("OpenAL: found EAX 4.0 extension\n"); +- } else { +- common->Printf("OpenAL: EAX 4.0 extension not found\n"); +- idSoundSystemLocal::s_useEAXReverb.SetBool(false); +- alEAXSet = (EAXSet)NULL; +- alEAXGet = (EAXGet)NULL; +- } ++ common->Printf("OpenAL: EAX 4.0 not supported in this build\n"); ++ idSoundSystemLocal::s_useEAXReverb.SetBool( false ); ++ EAXAvailable = 0; ++#endif + +- // try to obtain EAX-RAM extension - not required for operation +- if (alIsExtensionPresent(ID_ALCHAR "EAX-RAM") == AL_TRUE) { +- alEAXSetBufferMode = (EAXSetBufferMode)alGetProcAddress(ID_ALCHAR "EAXSetBufferMode"); +- alEAXGetBufferMode = (EAXGetBufferMode)alGetProcAddress(ID_ALCHAR "EAXGetBufferMode"); +- common->Printf("OpenAL: found EAX-RAM extension, %dkB\\%dkB\n", alGetInteger(alGetEnumValue(ID_ALCHAR "AL_EAX_RAM_FREE")) / 1024, alGetInteger(alGetEnumValue(ID_ALCHAR "AL_EAX_RAM_SIZE")) / 1024); +- } else { +- alEAXSetBufferMode = (EAXSetBufferMode)NULL; +- alEAXGetBufferMode = (EAXGetBufferMode)NULL; +- common->Printf("OpenAL: no EAX-RAM extension\n"); +- } ++#if ID_OPENAL_EAX ++ // try to obtain EAX-RAM extension - not required for operation ++ if ( alIsExtensionPresent( ID_ALCHAR "EAX-RAM" ) == AL_TRUE ) { ++ alEAXSetBufferMode = (EAXSetBufferMode)alGetProcAddress( ID_ALCHAR "EAXSetBufferMode" ); ++ alEAXGetBufferMode = (EAXGetBufferMode)alGetProcAddress( ID_ALCHAR "EAXGetBufferMode" ); ++ common->Printf( "OpenAL: found EAX-RAM extension, %dkB\\%dkB\n", alGetInteger( alGetEnumValue( ID_ALCHAR "AL_EAX_RAM_FREE" ) ) / 1024, alGetInteger( alGetEnumValue( ID_ALCHAR "AL_EAX_RAM_SIZE" ) ) / 1024 ); ++ } else { ++ alEAXSetBufferMode = (EAXSetBufferMode)NULL; ++ alEAXGetBufferMode = (EAXGetBufferMode)NULL; ++ common->Printf( "OpenAL: no EAX-RAM extension\n" ); ++ } + #endif + +- if (!idSoundSystemLocal::s_useOpenAL.GetBool()) { +- common->Printf("OpenAL: disabling ( no EAX ). Using legacy mixer.\n"); ++ ALuint handle; ++ openalSourceCount = 0; + +- alcMakeContextCurrent(NULL); ++ while ( openalSourceCount < 256 ) { ++ alGetError(); ++ alGenSources( 1, &handle ); ++ if ( alGetError() != AL_NO_ERROR ) { ++ break; ++ } else { ++ // store in source array ++ openalSources[openalSourceCount].handle = handle; ++ openalSources[openalSourceCount].startTime = 0; ++ openalSources[openalSourceCount].chan = NULL; ++ openalSources[openalSourceCount].inUse = false; ++ openalSources[openalSourceCount].looping = false; + +- alcDestroyContext(openalContext); +- openalContext = NULL; ++ // initialise sources ++ alSourcef( handle, AL_ROLLOFF_FACTOR, 0.0f ); + +- alcCloseDevice(openalDevice); +- openalDevice = NULL; +- } else { +- +- ALuint handle; +- openalSourceCount = 0; +- +- while (openalSourceCount < 256) { +- alGetError(); +- alGenSources(1, &handle); +- +- if (alGetError() != AL_NO_ERROR) { +- break; +- } else { +- // store in source array +- openalSources[openalSourceCount].handle = handle; +- openalSources[openalSourceCount].startTime = 0; +- openalSources[openalSourceCount].chan = NULL; +- openalSources[openalSourceCount].inUse = false; +- openalSources[openalSourceCount].looping = false; +- +- // initialise sources +- alSourcef(handle, AL_ROLLOFF_FACTOR, 0.0f); +- +- // found one source +- openalSourceCount++; +- } +- } +- +- common->Printf("OpenAL: found %s\n", alcGetString(openalDevice, ALC_DEVICE_SPECIFIER)); +- common->Printf("OpenAL: found %d hardware voices\n", openalSourceCount); +- +- // adjust source count to allow for at least eight stereo sounds to play +- openalSourceCount -= 8; +- +-#ifdef _OPENAL_SOFT +- if(idSoundSystemLocal::s_useEAXReverb.GetBool()) +-#endif +- EAXAvailable = 1; +- } ++ // found one source ++ openalSourceCount++; + } + } + +- useOpenAL = idSoundSystemLocal::s_useOpenAL.GetBool(); ++ common->Printf( "OpenAL: found %s\n", alcGetString( openalDevice, ALC_DEVICE_SPECIFIER ) ); ++ common->Printf( "OpenAL: found %d hardware voices\n", openalSourceCount ); ++ ++ // adjust source count to allow for at least eight stereo sounds to play ++ openalSourceCount -= 8; ++ + useEAXReverb = idSoundSystemLocal::s_useEAXReverb.GetBool(); +-#endif + +- cmdSystem->AddCommand("listSounds", ListSounds_f, CMD_FL_SOUND, "lists all sounds"); +- cmdSystem->AddCommand("listSoundDecoders", ListSoundDecoders_f, CMD_FL_SOUND, "list active sound decoders"); +- cmdSystem->AddCommand("reloadSounds", SoundReloadSounds_f, CMD_FL_SOUND|CMD_FL_CHEAT, "reloads all sounds"); +- cmdSystem->AddCommand("testSound", TestSound_f, CMD_FL_SOUND | CMD_FL_CHEAT, "tests a sound", idCmdSystem::ArgCompletion_SoundName); +- cmdSystem->AddCommand("s_restart", SoundSystemRestart_f, CMD_FL_SOUND, "restarts the sound system"); ++ cmdSystem->AddCommand( "listSounds", ListSounds_f, CMD_FL_SOUND, "lists all sounds" ); ++ cmdSystem->AddCommand( "listSoundDecoders", ListSoundDecoders_f, CMD_FL_SOUND, "list active sound decoders" ); ++ cmdSystem->AddCommand( "reloadSounds", SoundReloadSounds_f, CMD_FL_SOUND|CMD_FL_CHEAT, "reloads all sounds" ); ++ cmdSystem->AddCommand( "testSound", TestSound_f, CMD_FL_SOUND | CMD_FL_CHEAT, "tests a sound", idCmdSystem::ArgCompletion_SoundName ); ++ cmdSystem->AddCommand( "s_restart", SoundSystemRestart_f, CMD_FL_SOUND, "restarts the sound system" ); + + #ifdef _HUMANHEAD + sb_subtitleQueue.Clear(); +@@ -596,63 +471,46 @@ void idSoundSystemLocal::Init() + idSoundSystemLocal::Shutdown + =============== + */ +-void idSoundSystemLocal::Shutdown() +-{ ++void idSoundSystemLocal::Shutdown() { + ShutdownHW(); + +-#ifdef _OPENAL + // EAX or not, the list needs to be cleared + EFXDatabase.Clear(); +-#ifdef _RAVEN +- reverb.Clear(); +-#endif + +- // destroy openal sources +- if (useOpenAL) { ++ efxloaded = false; + +- efxloaded = false; ++ // adjust source count back up to allow for freeing of all resources ++ openalSourceCount += 8; + +- // adjust source count back up to allow for freeing of all resources +- openalSourceCount += 8; ++ for ( ALsizei i = 0; i < openalSourceCount; i++ ) { ++ // stop source ++ alSourceStop( openalSources[i].handle ); ++ alSourcei( openalSources[i].handle, AL_BUFFER, 0 ); + +- for (ALsizei i = 0; i < openalSourceCount; i++) { +- // stop source +- alSourceStop(openalSources[i].handle); +- alSourcei(openalSources[i].handle, AL_BUFFER, 0); ++ // delete source ++ alDeleteSources( 1, &openalSources[i].handle ); + +- // delete source +- alDeleteSources(1, &openalSources[i].handle); +- +- // clear entry in source array +- openalSources[i].handle = 0; +- openalSources[i].startTime = 0; +- openalSources[i].chan = NULL; +- openalSources[i].inUse = false; +- openalSources[i].looping = false; +- +- } ++ // clear entry in source array ++ openalSources[i].handle = 0; ++ openalSources[i].startTime = 0; ++ openalSources[i].chan = NULL; ++ openalSources[i].inUse = false; ++ openalSources[i].looping = false; + } +-#endif + + // destroy all the sounds (hardware buffers as well) + delete soundCache; + soundCache = NULL; + +-#ifdef _OPENAL + // destroy openal device and context +- if (useOpenAL) { +- alcMakeContextCurrent(NULL); ++ alcMakeContextCurrent( NULL ); + +- alcDestroyContext(openalContext); +- openalContext = NULL; ++ alcDestroyContext( openalContext ); ++ openalContext = NULL; + +- alcCloseDevice(openalDevice); +- openalDevice = NULL; +- } ++ alcCloseDevice( openalDevice ); ++ openalDevice = NULL; + +- Sys_FreeOpenAL(); +-#endif +- + idSampleDecoder::Shutdown(); + } + +@@ -661,35 +519,22 @@ void idSoundSystemLocal::Shutdown() + idSoundSystemLocal::InitHW + =============== + */ +-bool idSoundSystemLocal::InitHW() +-{ ++bool idSoundSystemLocal::InitHW() { ++ int numSpeakers = s_numberOfSpeakers.GetInteger(); + +- if (s_noSound.GetBool()) { +- return false; ++ if (numSpeakers != 2 && numSpeakers != 6) { ++ common->Warning("invalid value for s_numberOfSpeakers. Use either 2 or 6"); ++ numSpeakers = 2; ++ s_numberOfSpeakers.SetInteger(numSpeakers); + } + +- delete snd_audio_hw; +- snd_audio_hw = idAudioHardware::Alloc(); +- +- if (snd_audio_hw == NULL) { ++ if ( s_noSound.GetBool() ) { + return false; + } + +- if (!useOpenAL) { +- if (!snd_audio_hw->Initialize()) { +- delete snd_audio_hw; +- snd_audio_hw = NULL; +- return false; +- } ++ // put the real number in there ++ s_numberOfSpeakers.SetInteger(numSpeakers); + +- if (snd_audio_hw->GetNumberOfSpeakers() == 0) { +- return false; +- } +- +- // put the real number in there +- s_numberOfSpeakers.SetInteger(snd_audio_hw->GetNumberOfSpeakers()); +- } +- + isInitialized = true; + shutdown = false; + +@@ -701,24 +546,20 @@ bool idSoundSystemLocal::InitHW() + idSoundSystemLocal::ShutdownHW + =============== + */ +-bool idSoundSystemLocal::ShutdownHW() +-{ +- if (!isInitialized) { ++bool idSoundSystemLocal::ShutdownHW() { ++ if ( !isInitialized ) { + return false; + } + + shutdown = true; // don't do anything at AsyncUpdate() time +- Sys_Sleep(100); // sleep long enough to make sure any async sound talking to hardware has returned ++ Sys_Sleep( 100 ); // sleep long enough to make sure any async sound talking to hardware has returned + +- common->Printf("Shutting down sound hardware\n"); ++ common->Printf( "Shutting down sound hardware\n" ); + +- delete snd_audio_hw; +- snd_audio_hw = NULL; +- + isInitialized = false; + +- if (graph) { +- Mem_Free(graph); ++ if ( graph ) { ++ Mem_Free( graph ); + graph = NULL; + } + +@@ -730,67 +571,35 @@ bool idSoundSystemLocal::ShutdownHW() + idSoundSystemLocal::GetCurrent44kHzTime + =============== + */ +-int idSoundSystemLocal::GetCurrent44kHzTime(void) const +-{ +- if (snd_audio_hw +-/*#ifdef _OPENAL +- || useOpenAL +-#endif*/ +- ) { ++int idSoundSystemLocal::GetCurrent44kHzTime( void ) const { ++ if ( isInitialized ) { + return CurrentSoundTime; + } else { +- // NOTE: this would overflow 31bits within about 1h20 ( not that important since we get a snd_audio_hw right away pbly ) ++ // NOTE: this would overflow 31bits within about 1h20 + //return ( ( Sys_Milliseconds()*441 ) / 10 ) * 4; +- return idMath::FtoiFast((float)Sys_Milliseconds() * 176.4f); ++ return idMath::FtoiFast( (float)Sys_Milliseconds() * 176.4f ); + } + } + + /* + =================== +-idSoundSystemLocal::ClearBuffer +-=================== +-*/ +-void idSoundSystemLocal::ClearBuffer(void) +-{ +- +- // check to make sure hardware actually exists +- if (!snd_audio_hw) { +- return; +- } +- +- short *fBlock; +- ulong fBlockLen; +- +- if (!snd_audio_hw->Lock((void **)&fBlock, &fBlockLen)) { +- return; +- } +- +- if (fBlock) { +- SIMDProcessor->Memset(fBlock, 0, fBlockLen); +- snd_audio_hw->Unlock(fBlock, fBlockLen); +- } +-} +- +-/* +-=================== + idSoundSystemLocal::AsyncMix + Mac OSX version. The system uses it's own thread and an IOProc callback + =================== + */ +-int idSoundSystemLocal::AsyncMix(int soundTime, float *mixBuffer) +-{ ++int idSoundSystemLocal::AsyncMix( int soundTime, float *mixBuffer ) { + int inTime, numSpeakers; + +- if (!isInitialized || shutdown || !snd_audio_hw) { ++ if ( !isInitialized || shutdown ) { + return 0; + } + + inTime = Sys_Milliseconds(); +- numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); ++ numSpeakers = s_numberOfSpeakers.GetInteger(); + + // let the active sound world mix all the channels in unless muted or avi demo recording +- if (!muted && currentSoundWorld && !currentSoundWorld->fpa[0]) { +- currentSoundWorld->MixLoop(soundTime, numSpeakers, mixBuffer); ++ if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { ++ currentSoundWorld->MixLoop( soundTime, numSpeakers, mixBuffer ); + } + + CurrentSoundTime = soundTime; +@@ -804,9 +613,9 @@ idSoundSystemLocal::AsyncUpdate + called from async sound thread when com_asyncSound == 1 ( Windows ) + =================== + */ +-int idSoundSystemLocal::AsyncUpdate(int inTime) +-{ +- if (!isInitialized || shutdown || !snd_audio_hw) { ++int idSoundSystemLocal::AsyncUpdate( int inTime ) { ++ ++ if ( !isInitialized || shutdown ) { + return 0; + } + #ifdef _HUMANHEAD +@@ -815,57 +624,30 @@ int idSoundSystemLocal::AsyncUpdate(int inTime) + + ulong dwCurrentWritePos; + dword dwCurrentBlock; +-#ifdef _OPENAL +- // If not using openal, get actual playback position from sound hardware +- if (useOpenAL) { +- // here we do it in samples ( overflows in 27 hours or so ) +- dwCurrentWritePos = idMath::Ftol((float)Sys_Milliseconds() * 44.1f) % (MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER); +- dwCurrentBlock = dwCurrentWritePos / MIXBUFFER_SAMPLES; +- } else +-#endif +- { +- // and here in bytes +- // get the current byte position in the buffer where the sound hardware is currently reading +- if (!snd_audio_hw->GetCurrentPosition(&dwCurrentWritePos)) { +- return 0; +- } + +- // mixBufferSize is in bytes +- dwCurrentBlock = dwCurrentWritePos / snd_audio_hw->GetMixBufferSize(); +- } ++ // here we do it in samples ( overflows in 27 hours or so ) ++ dwCurrentWritePos = idMath::Ftol( (float)Sys_Milliseconds() * 44.1f ) % ( MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER ); ++ dwCurrentBlock = dwCurrentWritePos / MIXBUFFER_SAMPLES; + +- if (nextWriteBlock == 0xffffffff) { ++ if ( nextWriteBlock == 0xffffffff ) { + nextWriteBlock = dwCurrentBlock; + } + +- if (dwCurrentBlock != nextWriteBlock) { ++ if ( dwCurrentBlock != nextWriteBlock ) { + return 0; + } + +- // lock the buffer so we can actually write to it +- short *fBlock = NULL; +- ulong fBlockLen = 0; +- +- if (!useOpenAL) { +- snd_audio_hw->Lock((void **)&fBlock, &fBlockLen); +- +- if (!fBlock) { +- return 0; +- } +- } +- +- int j; + soundStats.runs++; + soundStats.activeSounds = 0; + +- int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); ++ int numSpeakers = s_numberOfSpeakers.GetInteger(); + + nextWriteBlock++; + nextWriteBlock %= ROOM_SLICES_IN_BUFFER; + + int newPosition = nextWriteBlock * MIXBUFFER_SAMPLES; + +- if (newPosition < olddwCurrentWritePos) { ++ if ( newPosition < olddwCurrentWritePos ) { + buffers++; // buffer wrapped + } + +@@ -875,56 +657,29 @@ int idSoundSystemLocal::AsyncUpdate(int inTime) + olddwCurrentWritePos = newPosition; + + // newSoundTime is in multi-channel samples since the sound system was started +- int newSoundTime = (buffers * MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER) + nextWriteSamples; ++ int newSoundTime = ( buffers * MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER ) + nextWriteSamples; + + // check for impending overflow + // FIXME: we don't handle sound wrap-around correctly yet +- if (newSoundTime > 0x6fffffff) { ++ if ( newSoundTime > 0x6fffffff ) { + buffers = 0; + } + +- if ((newSoundTime - CurrentSoundTime) > (int)MIXBUFFER_SAMPLES) { ++ if ( (newSoundTime - CurrentSoundTime) > (int)MIXBUFFER_SAMPLES ) { + soundStats.missedWindow++; + } +-#ifdef _OPENAL +- if (useOpenAL) { +- // enable audio hardware caching +- alcSuspendContext(openalContext); +- } else +-#endif +- { +- // clear the buffer for all the mixing output +- SIMDProcessor->Memset(finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers); +- } + ++ // enable audio hardware caching ++ alcSuspendContext( openalContext ); ++ + // let the active sound world mix all the channels in unless muted or avi demo recording +- if (!muted && currentSoundWorld && !currentSoundWorld->fpa[0]) { +- currentSoundWorld->MixLoop(newSoundTime, numSpeakers, finalMixBuffer); ++ if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { ++ currentSoundWorld->MixLoop( newSoundTime, numSpeakers, finalMixBuffer ); + } +-#ifdef _OPENAL +- if (useOpenAL) { +- // disable audio hardware caching (this updates ALL settings since last alcSuspendContext) +- alcProcessContext(openalContext); +- } +- else +-#endif +- { +- short *dest = fBlock + nextWriteSamples * numSpeakers; + +- SIMDProcessor->MixedSoundToSamples(dest, finalMixBuffer, MIXBUFFER_SAMPLES * numSpeakers); ++ // disable audio hardware caching (this updates ALL settings since last alcSuspendContext) ++ alcProcessContext( openalContext ); + +- // allow swapping the left / right speaker channels for people with miswired systems +- if (numSpeakers == 2 && s_reverse.GetBool()) { +- for (j = 0; j < MIXBUFFER_SAMPLES; j++) { +- short temp = dest[j*2]; +- dest[j*2] = dest[j*2+1]; +- dest[j*2+1] = temp; +- } +- } +- +- snd_audio_hw->Unlock(fBlock, fBlockLen); +- } +- + CurrentSoundTime = newSoundTime; + + soundStats.timeinprocess = Sys_Milliseconds() - inTime; +@@ -943,76 +698,47 @@ we mix MIXBUFFER_SAMPLES at a time, but we feed the au + called by the sound thread when com_asyncSound is 3 ( Linux ) + =================== + */ +-int idSoundSystemLocal::AsyncUpdateWrite(int inTime) +-{ +- if (!isInitialized || shutdown || !snd_audio_hw) { ++int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) { ++ ++ if ( !isInitialized || shutdown ) { + return 0; + } + #ifdef _HUMANHEAD + SB_HideSubtitle(); + #endif + +- if (!useOpenAL) { +- snd_audio_hw->Flush(); +- } ++ //if (!useOpenAL) { ++ // snd_audio_hw->Flush(); ++ //} + +- unsigned int dwCurrentBlock = (unsigned int)(inTime * 44.1f / MIXBUFFER_SAMPLES); ++ unsigned int dwCurrentBlock = (unsigned int)( inTime * 44.1f / MIXBUFFER_SAMPLES ); + +- if (nextWriteBlock == 0xffffffff) { ++ if ( nextWriteBlock == 0xffffffff ) { + nextWriteBlock = dwCurrentBlock; + } + +- if (dwCurrentBlock < nextWriteBlock) { ++ if ( dwCurrentBlock < nextWriteBlock ) { + return 0; + } + +- if (nextWriteBlock != dwCurrentBlock) { +- Sys_Printf("missed %d sound updates\n", dwCurrentBlock - nextWriteBlock); ++ if ( nextWriteBlock != dwCurrentBlock ) { ++ Sys_Printf( "missed %d sound updates\n", dwCurrentBlock - nextWriteBlock ); + } + + int sampleTime = dwCurrentBlock * MIXBUFFER_SAMPLES; +- int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); +-#ifdef _OPENAL +- if (useOpenAL) { +- // enable audio hardware caching +- alcSuspendContext(openalContext); +- } else +-#endif +- { +- // clear the buffer for all the mixing output +- SIMDProcessor->Memset(finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers); +- } ++ int numSpeakers = s_numberOfSpeakers.GetInteger(); + ++ // enable audio hardware caching ++ alcSuspendContext( openalContext ); ++ + // let the active sound world mix all the channels in unless muted or avi demo recording +- if (!muted && currentSoundWorld && !currentSoundWorld->fpa[0]) { +- currentSoundWorld->MixLoop(sampleTime, numSpeakers, finalMixBuffer); ++ if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { ++ currentSoundWorld->MixLoop( sampleTime, numSpeakers, finalMixBuffer ); + } +-#ifdef _OPENAL +- if (useOpenAL) { +- // disable audio hardware caching (this updates ALL settings since last alcSuspendContext) +- alcProcessContext(openalContext); +- } +- else +-#endif +- { +- short *dest = snd_audio_hw->GetMixBuffer(); + +- SIMDProcessor->MixedSoundToSamples(dest, finalMixBuffer, MIXBUFFER_SAMPLES * numSpeakers); ++ // disable audio hardware caching (this updates ALL settings since last alcSuspendContext) ++ alcProcessContext( openalContext ); + +- // allow swapping the left / right speaker channels for people with miswired systems +- if (numSpeakers == 2 && s_reverse.GetBool()) { +- int j; +- +- for (j = 0; j < MIXBUFFER_SAMPLES; j++) { +- short temp = dest[j*2]; +- dest[j*2] = dest[j*2+1]; +- dest[j*2+1] = temp; +- } +- } +- +- snd_audio_hw->Write(false); +- } +- + // only move to the next block if the write was successful + nextWriteBlock = dwCurrentBlock + 1; + CurrentSoundTime = sampleTime; +@@ -1028,17 +754,15 @@ int idSoundSystemLocal::AsyncUpdateWrite(int inTime) + idSoundSystemLocal::dB2Scale + =================== + */ +-float idSoundSystemLocal::dB2Scale(const float val) const +-{ +- if (val == 0.0f) { ++float idSoundSystemLocal::dB2Scale( const float val ) const { ++ if ( val == 0.0f ) { + return 1.0f; // most common +- } else if (val <= -60.0f) { ++ } else if ( val <= -60.0f ) { + return 0.0f; +- } else if (val >= 60.0f) { +- return powf(2.0f, val * (1.0f / 6.0f)); ++ } else if ( val >= 60.0f ) { ++ return powf( 2.0f, val * ( 1.0f / 6.0f ) ); + } +- +- int ival = (int)((val + 60.0f) * 10.0f); ++ int ival = (int)( ( val + 60.0f ) * 10.0f ); + return volumesDB[ival]; + } + +@@ -1047,119 +771,101 @@ float idSoundSystemLocal::dB2Scale(const float val) co + idSoundSystemLocal::ImageForTime + =================== + */ +-cinData_t idSoundSystemLocal::ImageForTime(const int milliseconds, const bool waveform) +-{ ++cinData_t idSoundSystemLocal::ImageForTime( const int milliseconds, const bool waveform ) { + cinData_t ret; + int i, j; + +- if (!isInitialized || !snd_audio_hw) { +- memset(&ret, 0, sizeof(ret)); ++ if ( !isInitialized ) { ++ memset( &ret, 0, sizeof( ret ) ); + return ret; + } + + Sys_EnterCriticalSection(); + +- if (!graph) { +- graph = (dword *)Mem_Alloc(256*128 * 4); ++ if ( !graph ) { ++ graph = (dword *)Mem_Alloc( 256*128 * 4); + } +- +- memset(graph, 0, 256*128 * 4); ++ memset( graph, 0, 256*128 * 4 ); + float *accum = finalMixBuffer; // unfortunately, these are already clamped + int time = Sys_Milliseconds(); + +- int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); ++ int numSpeakers = s_numberOfSpeakers.GetInteger(); + +- if (!waveform) { +- for (j = 0; j < numSpeakers; j++) { ++ if ( !waveform ) { ++ for( j = 0; j < numSpeakers; j++ ) { + int meter = 0; +- +- for (i = 0; i < MIXBUFFER_SAMPLES; i++) { ++ for( i = 0; i < MIXBUFFER_SAMPLES; i++ ) { + float result = idMath::Fabs(accum[i*numSpeakers+j]); +- +- if (result > meter) { ++ if ( result > meter ) { + meter = result; + } + } + + meter /= 256; // 32768 becomes 128 +- +- if (meter > 128) { ++ if ( meter > 128 ) { + meter = 128; + } +- + int offset; + int xsize; +- +- if (numSpeakers == 6) { ++ if ( numSpeakers == 6 ) { + offset = j * 40; + xsize = 20; + } else { + offset = j * 128; + xsize = 63; + } +- + int x,y; + dword color = 0xff00ff00; +- +- for (y = 0; y < 128; y++) { +- for (x = 0; x < xsize; x++) { ++ for ( y = 0; y < 128; y++ ) { ++ for ( x = 0; x < xsize; x++ ) { + graph[(127-y)*256 + offset + x ] = color; + } +- + #if 0 +- +- if (y == 80) { ++ if ( y == 80 ) { + color = 0xff00ffff; +- } else if (y == 112) { ++ } else if ( y == 112 ) { + color = 0xff0000ff; + } +- + #endif +- +- if (y > meter) { ++ if ( y > meter ) { + break; + } + } + +- if (meter > meterTops[j]) { ++ if ( meter > meterTops[j] ) { + meterTops[j] = meter; + meterTopsTime[j] = time + s_meterTopTime.GetInteger(); +- } else if (time > meterTopsTime[j] && meterTops[j] > 0) { ++ } else if ( time > meterTopsTime[j] && meterTops[j] > 0 ) { + meterTops[j]--; +- + if (meterTops[j]) { + meterTops[j]--; + } + } + } + +- for (j = 0; j < numSpeakers; j++) { ++ for( j = 0; j < numSpeakers; j++ ) { + int meter = meterTops[j]; + + int offset; + int xsize; +- +- if (numSpeakers == 6) { ++ if ( numSpeakers == 6 ) { + offset = j*40; + xsize = 20; + } else { + offset = j*128; + xsize = 63; + } +- + int x,y; + dword color; +- +- if (meter <= 80) { ++ if ( meter <= 80 ) { + color = 0xff007f00; +- } else if (meter <= 112) { ++ } else if ( meter <= 112 ) { + color = 0xff007f7f; + } else { + color = 0xff00007f; + } +- +- for (y = meter; y < 128 && y < meter + 4; y++) { +- for (x = 0; x < xsize; x++) { ++ for ( y = meter; y < 128 && y < meter + 4; y++ ) { ++ for ( x = 0; x < xsize; x++ ) { + graph[(127-y)*256 + offset + x ] = color; + } + } +@@ -1167,59 +873,48 @@ cinData_t idSoundSystemLocal::ImageForTime(const int m + } else { + dword colors[] = { 0xff007f00, 0xff007f7f, 0xff00007f, 0xff00ff00, 0xff00ffff, 0xff0000ff }; + +- for (j = 0; j < numSpeakers; j++) { ++ for( j = 0; j < numSpeakers; j++ ) { + int xx = 0; + float fmeter; + int step = MIXBUFFER_SAMPLES / 256; +- +- for (i = 0; i < MIXBUFFER_SAMPLES; i += step) { ++ for( i = 0; i < MIXBUFFER_SAMPLES; i += step ) { + fmeter = 0.0f; +- +- for (int x = 0; x < step; x++) { ++ for( int x = 0; x < step; x++ ) { + float result = accum[(i+x)*numSpeakers+j]; + result = result / 32768.0f; + fmeter += result; + } +- + fmeter /= 4.0f; +- +- if (fmeter < -1.0f) { ++ if ( fmeter < -1.0f ) { + fmeter = -1.0f; +- } else if (fmeter > 1.0f) { ++ } else if ( fmeter > 1.0f ) { + fmeter = 1.0f; + } +- + int meter = (fmeter * 63.0f); +- graph[(meter + 64) * 256 + xx ] = colors[j]; ++ graph[ (meter + 64) * 256 + xx ] = colors[j]; + +- if (meter < 0) { ++ if ( meter < 0 ) { + meter = -meter; + } +- +- if (meter > meterTops[xx]) { ++ if ( meter > meterTops[xx] ) { + meterTops[xx] = meter; + meterTopsTime[xx] = time + 100; +- } else if (time>meterTopsTime[xx] && meterTops[xx] > 0) { ++ } else if ( time>meterTopsTime[xx] && meterTops[xx] > 0 ) { + meterTops[xx]--; +- +- if (meterTops[xx]) { ++ if ( meterTops[xx] ) { + meterTops[xx]--; + } + } +- + xx++; + } + } +- +- for (i = 0; i < 256; i++) { ++ for( i = 0; i < 256; i++ ) { + int meter = meterTops[i]; +- +- for (int y = -meter; y < meter; y++) { +- graph[(y+64)*256 + i ] = colors[j]; ++ for ( int y = -meter; y < meter; y++ ) { ++ graph[ (y+64)*256 + i ] = colors[j]; + } + } + } +- + ret.imageHeight = 128; + ret.imageWidth = 256; + ret.image = (unsigned char *)graph; +@@ -1234,12 +929,11 @@ cinData_t idSoundSystemLocal::ImageForTime(const int m + idSoundSystemLocal::GetSoundDecoderInfo + =================== + */ +-int idSoundSystemLocal::GetSoundDecoderInfo(int index, soundDecoderInfo_t &decoderInfo) +-{ ++int idSoundSystemLocal::GetSoundDecoderInfo( int index, soundDecoderInfo_t &decoderInfo ) { + int i, j, firstEmitter, firstChannel; + idSoundWorldLocal *sw = soundSystemLocal.currentSoundWorld; + +- if (index < 0) { ++ if ( index < 0 ) { + firstEmitter = 0; + firstChannel = 0; + } else { +@@ -1247,44 +941,43 @@ int idSoundSystemLocal::GetSoundDecoderInfo(int index, + firstChannel = index - firstEmitter * SOUND_MAX_CHANNELS + 1; + } + +- for (i = firstEmitter; i < sw->emitters.Num(); i++) { ++ for ( i = firstEmitter; i < sw->emitters.Num(); i++ ) { + idSoundEmitterLocal *sound = sw->emitters[i]; + +- if (!sound) { ++ if ( !sound ) { + continue; + } + + // run through all the channels +- for (j = firstChannel; j < SOUND_MAX_CHANNELS; j++) { ++ for ( j = firstChannel; j < SOUND_MAX_CHANNELS; j++ ) { + idSoundChannel *chan = &sound->channels[j]; + +- if (chan->decoder == NULL) { ++ if ( chan->decoder == NULL ) { + continue; + } + + idSoundSample *sample = chan->decoder->GetSample(); + +- if (sample == NULL) { ++ if ( sample == NULL ) { + continue; + } + + decoderInfo.name = sample->name; +- decoderInfo.format = (sample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG) ? "OGG" : "WAV"; ++ decoderInfo.format = ( sample->objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG ) ? "OGG" : "WAV"; + decoderInfo.numChannels = sample->objectInfo.nChannels; + decoderInfo.numSamplesPerSecond = sample->objectInfo.nSamplesPerSec; + decoderInfo.num44kHzSamples = sample->LengthIn44kHzSamples(); + decoderInfo.numBytes = sample->objectMemSize; +- decoderInfo.looping = (chan->parms.soundShaderFlags & SSF_LOOPING) != 0; ++ decoderInfo.looping = ( chan->parms.soundShaderFlags & SSF_LOOPING ) != 0; + decoderInfo.lastVolume = chan->lastVolume; + decoderInfo.start44kHzTime = chan->trigger44kHzTime; + decoderInfo.current44kHzTime = soundSystemLocal.GetCurrent44kHzTime(); + +- return (i * SOUND_MAX_CHANNELS + j); ++ return ( i * SOUND_MAX_CHANNELS + j ); + } + + firstChannel = 0; + } +- + return -1; + } + +@@ -1293,11 +986,10 @@ int idSoundSystemLocal::GetSoundDecoderInfo(int index, + idSoundSystemLocal::AllocSoundWorld + =================== + */ +-idSoundWorld *idSoundSystemLocal::AllocSoundWorld(idRenderWorld *rw) +-{ ++idSoundWorld *idSoundSystemLocal::AllocSoundWorld( idRenderWorld *rw ) { + idSoundWorldLocal *local = new idSoundWorldLocal; + +- local->Init(rw); ++ local->Init( rw ); + + return local; + } +@@ -1307,8 +999,7 @@ idSoundWorld *idSoundSystemLocal::AllocSoundWorld(idRe + idSoundSystemLocal::SetMute + =================== + */ +-void idSoundSystemLocal::SetMute(bool muteOn) +-{ ++void idSoundSystemLocal::SetMute( bool muteOn ) { + muted = muteOn; + } + +@@ -1317,9 +1008,8 @@ void idSoundSystemLocal::SetMute(bool muteOn) + idSoundSystemLocal::SamplesToMilliseconds + =================== + */ +-int idSoundSystemLocal::SamplesToMilliseconds(int samples) const +-{ +- return (samples / (PRIMARYFREQ/1000)); ++int idSoundSystemLocal::SamplesToMilliseconds( int samples ) const { ++ return ( samples / (PRIMARYFREQ/1000) ); + } + + /* +@@ -1327,9 +1017,8 @@ int idSoundSystemLocal::SamplesToMilliseconds(int samp + idSoundSystemLocal::SamplesToMilliseconds + =================== + */ +-int idSoundSystemLocal::MillisecondsToSamples(int ms) const +-{ +- return (ms * (PRIMARYFREQ/1000)); ++int idSoundSystemLocal::MillisecondsToSamples( int ms ) const { ++ return ( ms * (PRIMARYFREQ/1000) ); + } + + /* +@@ -1339,8 +1028,7 @@ idSoundSystemLocal::SetPlayingSoundWorld + specifying NULL will cause silence to be played + =================== + */ +-void idSoundSystemLocal::SetPlayingSoundWorld(idSoundWorld *soundWorld) +-{ ++void idSoundSystemLocal::SetPlayingSoundWorld( idSoundWorld *soundWorld ) { + currentSoundWorld = static_cast(soundWorld); + } + +@@ -1349,8 +1037,7 @@ void idSoundSystemLocal::SetPlayingSoundWorld(idSoundW + idSoundSystemLocal::GetPlayingSoundWorld + =================== + */ +-idSoundWorld *idSoundSystemLocal::GetPlayingSoundWorld(void) +-{ ++idSoundWorld *idSoundSystemLocal::GetPlayingSoundWorld( void ) { + return currentSoundWorld; + } + +@@ -1360,20 +1047,17 @@ idSoundSystemLocal::BeginLevelLoad + =================== + */ + +-void idSoundSystemLocal::BeginLevelLoad() +-{ +- if (!isInitialized) { ++void idSoundSystemLocal::BeginLevelLoad() { ++ if ( !isInitialized ) { + return; + } +- + soundCache->BeginLevelLoad(); + +-#ifdef _OPENAL +- if (efxloaded) { ++ if ( efxloaded ) { + EFXDatabase.UnloadFile(); + efxloaded = false; + } +-#endif ++ + #ifdef _RAVEN + reverb.UnloadFile(); + #endif +@@ -1384,31 +1068,24 @@ void idSoundSystemLocal::BeginLevelLoad() + idSoundSystemLocal::EndLevelLoad + =================== + */ +-void idSoundSystemLocal::EndLevelLoad(const char *mapstring) +-{ +- if (!isInitialized) { ++void idSoundSystemLocal::EndLevelLoad( const char *mapstring ) { ++ if ( !isInitialized ) { + return; + } +- + soundCache->EndLevelLoad(); + +-#ifdef _OPENAL +-#ifdef _OPENAL_EFX +- if (!useEAXReverb) +- return; +-#endif ++#if ID_OPENAL_EAX ++ idStr efxname( "efxs/" ); ++ idStr mapname( mapstring ); + +- idStr efxname("efxs/"); +- idStr mapname(mapstring); +- +- mapname.SetFileExtension(".efx"); ++ mapname.SetFileExtension( ".efx" ); + mapname.StripPath(); + efxname += mapname; + +- efxloaded = EFXDatabase.LoadFile(efxname); ++ efxloaded = EFXDatabase.LoadFile( efxname ); + +- if (efxloaded) { +- common->Printf("sound: found %s\n", efxname.c_str()); ++ if ( efxloaded ) { ++ common->Printf("sound: found %s\n", efxname.c_str() ); + } else { + #ifdef _RAVEN //karin: Quake4 has efxs/default.efx + efxloaded = EFXDatabase.LoadFile("efxs/default.efx"); +@@ -1439,9 +1116,7 @@ void idSoundSystemLocal::EndLevelLoad(const char *maps + idSoundSystemLocal::AllocOpenALSource + =================== + */ +-ALuint idSoundSystemLocal::AllocOpenALSource(idSoundChannel *chan, bool looping, bool stereo) +-{ +-#ifdef _OPENAL ++ALuint idSoundSystemLocal::AllocOpenALSource( idSoundChannel *chan, bool looping, bool stereo ) { + int timeOldestZeroVolSingleShot = Sys_Milliseconds(); + int timeOldestZeroVolLooping = Sys_Milliseconds(); + int timeOldestSingle = Sys_Milliseconds(); +@@ -1456,47 +1131,47 @@ ALuint idSoundSystemLocal::AllocOpenALSource(idSoundCh + int time = Sys_Milliseconds(); + + // Cycle through all sources +- for (i = 0; i < openalSourceCount; i++) { ++ for ( i = 0; i < openalSourceCount; i++ ) { + // Use any unused source first, + // Then find oldest single shot quiet source, + // Then find oldest looping quiet source and + // Lastly find oldest single shot non quiet source.. +- if (!openalSources[i].inUse) { ++ if ( !openalSources[i].inUse ) { + iUnused = i; + break; +- } else if (!openalSources[i].looping && openalSources[i].chan->lastVolume < SND_EPSILON) { +- if (openalSources[i].startTime < timeOldestZeroVolSingleShot) { ++ } else if ( !openalSources[i].looping && openalSources[i].chan->lastVolume < SND_EPSILON ) { ++ if ( openalSources[i].startTime < timeOldestZeroVolSingleShot ) { + timeOldestZeroVolSingleShot = openalSources[i].startTime; + iOldestZeroVolSingleShot = i; + } +- } else if (openalSources[i].looping && openalSources[i].chan->lastVolume < SND_EPSILON) { +- if (openalSources[i].startTime < timeOldestZeroVolLooping) { ++ } else if ( openalSources[i].looping && openalSources[i].chan->lastVolume < SND_EPSILON ) { ++ if ( openalSources[i].startTime < timeOldestZeroVolLooping ) { + timeOldestZeroVolLooping = openalSources[i].startTime; + iOldestZeroVolLooping = i; + } +- } else if (!openalSources[i].looping) { +- if (openalSources[i].startTime < timeOldestSingle) { ++ } else if ( !openalSources[i].looping ) { ++ if ( openalSources[i].startTime < timeOldestSingle ) { + timeOldestSingle = openalSources[i].startTime; + iOldestSingle = i; + } + } + } + +- if (iUnused != -1) { ++ if ( iUnused != -1 ) { + index = iUnused; +- } else if (iOldestZeroVolSingleShot != - 1) { ++ } else if ( iOldestZeroVolSingleShot != - 1 ) { + index = iOldestZeroVolSingleShot; +- } else if (iOldestZeroVolLooping != -1) { ++ } else if ( iOldestZeroVolLooping != -1 ) { + index = iOldestZeroVolLooping; +- } else if (iOldestSingle != -1) { ++ } else if ( iOldestSingle != -1 ) { + index = iOldestSingle; + } + +- if (index != -1) { ++ if ( index != -1 ) { + // stop the channel that is being ripped off +- if (openalSources[index].chan) { ++ if ( openalSources[index].chan ) { + // stop the channel only when not looping +- if (!openalSources[index].looping) { ++ if ( !openalSources[index].looping ) { + openalSources[index].chan->Stop(); + } else { + openalSources[index].chan->triggered = true; +@@ -1517,9 +1192,6 @@ ALuint idSoundSystemLocal::AllocOpenALSource(idSoundCh + } else { + return 0; + } +-#else +- return 0; +-#endif + } + + /* +@@ -1527,26 +1199,20 @@ ALuint idSoundSystemLocal::AllocOpenALSource(idSoundCh + idSoundSystemLocal::FreeOpenALSource + =================== + */ +-void idSoundSystemLocal::FreeOpenALSource(ALuint handle) +-{ +-#ifdef _OPENAL ++void idSoundSystemLocal::FreeOpenALSource( ALuint handle ) { + ALsizei i; +- +- for (i = 0; i < openalSourceCount; i++) { +- if (openalSources[i].handle == handle) { +- if (openalSources[i].chan) { ++ for ( i = 0; i < openalSourceCount; i++ ) { ++ if ( openalSources[i].handle == handle ) { ++ if ( openalSources[i].chan ) { + openalSources[i].chan->openalSource = 0; + } +- +-#if ID_OPENAL +-#if !defined(_OPENAL_EFX) ++#if ID_OPENAL_EAX + // Reset source EAX ROOM level when freeing stereo source +- if (openalSources[i].stereo && alEAXSet) { ++ if ( openalSources[i].stereo && alEAXSet ) { + long Room = EAXSOURCE_DEFAULTROOM; +- alEAXSet(&EAXPROPERTYID_EAX_Source, EAXSOURCE_ROOM, openalSources[i].handle, &Room, sizeof(Room)); ++ alEAXSet( &EAXPROPERTYID_EAX_Source, EAXSOURCE_ROOM, openalSources[i].handle, &Room, sizeof(Room)); + } + #endif +-#endif + // Initialize structure + openalSources[i].startTime = 0; + openalSources[i].chan = NULL; +@@ -1555,7 +1221,6 @@ void idSoundSystemLocal::FreeOpenALSource(ALuint handl + openalSources[i].stereo = false; + } + } +-#endif + } + + /* +@@ -1569,35 +1234,32 @@ SoundFX and misc effects + idSoundSystemLocal::ProcessSample + =================== + */ +-void SoundFX_Lowpass::ProcessSample(float *in, float *out) +-{ ++void SoundFX_Lowpass::ProcessSample( float* in, float* out ) { + float c, a1, a2, a3, b1, b2; + float resonance = idSoundSystemLocal::s_enviroSuitCutoffQ.GetFloat(); + float cutoffFrequency = idSoundSystemLocal::s_enviroSuitCutoffFreq.GetFloat(); + + Initialize(); + +- c = 1.0 / idMath::Tan16(idMath::PI * cutoffFrequency / 44100); ++ c = 1.0 / idMath::Tan16( idMath::PI * cutoffFrequency / 44100 ); + + // compute coefs +- a1 = 1.0 / (1.0 + resonance * c + c * c); ++ a1 = 1.0 / ( 1.0 + resonance * c + c * c ); + a2 = 2* a1; + a3 = a1; +- b1 = 2.0 * (1.0 - c * c) * a1; +- b2 = (1.0 - resonance * c + c * c) * a1; ++ b1 = 2.0 * ( 1.0 - c * c) * a1; ++ b2 = ( 1.0 - resonance * c + c * c ) * a1; + + // compute output value + out[0] = a1 * in[0] + a2 * in[-1] + a3 * in[-2] - b1 * out[-1] - b2 * out[-2]; + } + +-void SoundFX_LowpassFast::ProcessSample(float *in, float *out) +-{ ++void SoundFX_LowpassFast::ProcessSample( float* in, float* out ) { + // compute output value + out[0] = a1 * in[0] + a2 * in[-1] + a3 * in[-2] - b1 * out[-1] - b2 * out[-2]; + } + +-void SoundFX_LowpassFast::SetParms(float p1, float p2, float p3) +-{ ++void SoundFX_LowpassFast::SetParms( float p1, float p2, float p3 ) { + float c; + + // set the vars +@@ -1605,20 +1267,19 @@ void SoundFX_LowpassFast::SetParms(float p1, float p2, + res = p2; + + // precompute the coefs +- c = 1.0 / idMath::Tan(idMath::PI * freq / 44100); ++ c = 1.0 / idMath::Tan( idMath::PI * freq / 44100 ); + + // compute coefs +- a1 = 1.0 / (1.0 + res * c + c * c); ++ a1 = 1.0 / ( 1.0 + res * c + c * c ); + a2 = 2* a1; + a3 = a1; + +- b1 = 2.0 * (1.0 - c * c) * a1; +- b2 = (1.0 - res * c + c * c) * a1; ++ b1 = 2.0 * ( 1.0 - c * c) * a1; ++ b2 = ( 1.0 - res * c + c * c ) * a1; + } + +-void SoundFX_Comb::Initialize() +-{ +- if (initialized) ++void SoundFX_Comb::Initialize() { ++ if ( initialized ) + return; + + initialized = true; +@@ -1627,8 +1288,7 @@ void SoundFX_Comb::Initialize() + currentTime = 0; + } + +-void SoundFX_Comb::ProcessSample(float *in, float *out) +-{ ++void SoundFX_Comb::ProcessSample( float* in, float* out ) { + float gain = idSoundSystemLocal::s_reverbFeedback.GetFloat(); + int len = idSoundSystemLocal::s_reverbTime.GetFloat() + param; + +@@ -1640,8 +1300,7 @@ void SoundFX_Comb::ProcessSample(float *in, float *out + + // increment current time + currentTime++; +- +- if (currentTime >= len) ++ if ( currentTime >= len ) + currentTime -= len; + } + +@@ -1650,68 +1309,67 @@ void SoundFX_Comb::ProcessSample(float *in, float *out + idSoundSystemLocal::DoEnviroSuit + =================== + */ +-void idSoundSystemLocal::DoEnviroSuit(float *samples, int numSamples, int numSpeakers) +-{ ++void idSoundSystemLocal::DoEnviroSuit( float* samples, int numSamples, int numSpeakers ) { + float out[10000], *out_p = out + 2; + float in[10000], *in_p = in + 2; + +- assert(!idSoundSystemLocal::useOpenAL); ++ // TODO port to OpenAL ++ assert( false ); + +- if (!fxList.Num()) { +- for (int i = 0; i < 6; i++) { +- SoundFX *fx; ++ if ( !fxList.Num() ) { ++ for ( int i = 0; i < 6; i++ ) { ++ SoundFX* fx; + + // lowpass filter + fx = new SoundFX_Lowpass(); +- fx->SetChannel(i); +- fxList.Append(fx); ++ fx->SetChannel( i ); ++ fxList.Append( fx ); + + // comb + fx = new SoundFX_Comb(); +- fx->SetChannel(i); +- fx->SetParameter(i * 100); +- fxList.Append(fx); ++ fx->SetChannel( i ); ++ fx->SetParameter( i * 100 ); ++ fxList.Append( fx ); + + // comb + fx = new SoundFX_Comb(); +- fx->SetChannel(i); +- fx->SetParameter(i * 100 + 5); +- fxList.Append(fx); ++ fx->SetChannel( i ); ++ fx->SetParameter( i * 100 + 5 ); ++ fxList.Append( fx ); + } + } + +- for (int i = 0; i < numSpeakers; i++) { ++ for ( int i = 0; i < numSpeakers; i++ ) { + int j; + + // restore previous samples +- memset(in, 0, 10000 * sizeof(float)); +- memset(out, 0, 10000 * sizeof(float)); ++ memset( in, 0, 10000 * sizeof( float ) ); ++ memset( out, 0, 10000 * sizeof( float ) ); + + // fx loop +- for (int k = 0; k < fxList.Num(); k++) { +- SoundFX *fx = fxList[k]; ++ for ( int k = 0; k < fxList.Num(); k++ ) { ++ SoundFX* fx = fxList[k]; + + // skip if we're not the right channel +- if (fx->GetChannel() != i) ++ if ( fx->GetChannel() != i ) + continue; + + // get samples and continuity +- fx->GetContinuitySamples(in_p[-1], in_p[-2], out_p[-1], out_p[-2]); +- +- for (j = 0; j < numSamples; j++) { ++ fx->GetContinuitySamples( in_p[-1], in_p[-2], out_p[-1], out_p[-2] ); ++ for ( j = 0; j < numSamples; j++ ) { + in_p[j] = samples[j * numSpeakers + i] * s_enviroSuitVolumeScale.GetFloat(); + } + + // process fx loop +- for (j = 0; j < numSamples; j++) { +- fx->ProcessSample(in_p + j, out_p + j); ++ for ( j = 0; j < numSamples; j++ ) { ++ fx->ProcessSample( in_p + j, out_p + j ); + } + + // store samples and continuity +- fx->SetContinuitySamples(in_p[numSamples-2], in_p[numSamples-3], out_p[numSamples-2], out_p[numSamples-3]); ++ fx->SetContinuitySamples( in_p[numSamples-2], in_p[numSamples-3], out_p[numSamples-2], out_p[numSamples-3] ); + +- for (j = 0; j < numSamples; j++) { +- samples[j *numSpeakers + i] = out_p[j]; ++ for ( j = 0; j < numSamples; j++ ) { ++ samples[j * numSpeakers + i] = out_p[j]; + } + } + } +@@ -1722,55 +1380,42 @@ void idSoundSystemLocal::DoEnviroSuit(float *samples, + idSoundSystemLocal::PrintMemInfo + ================= + */ +-void idSoundSystemLocal::PrintMemInfo(MemInfo_t *mi) +-{ +- soundCache->PrintMemInfo(mi); ++void idSoundSystemLocal::PrintMemInfo( MemInfo_t *mi ) { ++ soundCache->PrintMemInfo( mi ); + } + + /* + =============== +-idSoundSystemLocal::EAXAvailable ++idSoundSystemLocal::IsEAXAvailable + =============== + */ +-int idSoundSystemLocal::IsEAXAvailable(void) +-{ +-#if !ID_OPENAL ++int idSoundSystemLocal::IsEAXAvailable( void ) { ++#if !ID_OPENAL || !ID_OPENAL_EAX + return -1; + #else +-#ifdef _OPENAL_EFX +- return EAXAvailable; +-#else + ALCdevice *device; + ALCcontext *context; + +- if (EAXAvailable != -1) { ++ if ( EAXAvailable != -1 ) { + return EAXAvailable; + } + +- if (!Sys_LoadOpenAL()) { +- EAXAvailable = 2; +- return 2; +- } +- + // when dynamically loading the OpenAL subsystem, we need to get a context before alIsExtensionPresent would work +- device = alcOpenDevice(NULL); +- context = alcCreateContext(device, NULL); +- alcMakeContextCurrent(context); +- +- if (alIsExtensionPresent(ID_ALCHAR "EAX4.0")) { +- alcMakeContextCurrent(NULL); +- alcDestroyContext(context); +- alcCloseDevice(device); ++ device = alcOpenDevice( NULL ); ++ context = alcCreateContext( device, NULL ); ++ alcMakeContextCurrent( context ); ++ if ( alIsExtensionPresent( ID_ALCHAR "EAX4.0" ) ) { ++ alcMakeContextCurrent( NULL ); ++ alcDestroyContext( context ); ++ alcCloseDevice( device ); + EAXAvailable = 1; + return 1; + } +- +- alcMakeContextCurrent(NULL); +- alcDestroyContext(context); +- alcCloseDevice(device); ++ alcMakeContextCurrent( NULL ); ++ alcDestroyContext( context ); ++ alcCloseDevice( device ); + EAXAvailable = 0; + return 0; +-#endif + #endif + } + diff --git a/games/idtech4a-engine/patches/patch-sound_snd_wavefile_cpp b/games/idtech4a-engine/patches/patch-sound_snd_wavefile_cpp new file mode 100644 index 000000000..48660db11 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_wavefile_cpp @@ -0,0 +1,426 @@ +Index: sound/snd_wavefile.cpp +--- sound/snd_wavefile.cpp.orig ++++ sound/snd_wavefile.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -37,9 +37,8 @@ If you have questions concerning this license or the a + // Then call Read() as needed. Calling the destructor or Close() + // will close the file. + //----------------------------------------------------------------------------- +-idWaveFile::idWaveFile(void) +-{ +- memset(&mpwfx, 0, sizeof(waveformatextensible_t)); ++idWaveFile::idWaveFile( void ) { ++ memset( &mpwfx, 0, sizeof( waveformatextensible_t ) ); + mhmmio = NULL; + mdwSize = 0; + mseekBase = 0; +@@ -47,66 +46,57 @@ idWaveFile::idWaveFile(void) + mpbData = NULL; + ogg = NULL; + isOgg = false; +-#ifdef _USING_STB_OGG +- oggData = NULL; +-#endif + } + + //----------------------------------------------------------------------------- + // Name: idWaveFile::~idWaveFile() + // Desc: Destructs the class + //----------------------------------------------------------------------------- +-idWaveFile::~idWaveFile(void) +-{ ++idWaveFile::~idWaveFile( void ) { + Close(); + +- if (mbIsReadingFromMemory && mpbData) { +- Mem_Free(mpbData); ++ if ( mbIsReadingFromMemory && mpbData ) { ++ Mem_Free( mpbData ); + } + +- memset(&mpwfx, 0, sizeof(waveformatextensible_t)); ++ memset( &mpwfx, 0, sizeof( waveformatextensible_t ) ); + } + + //----------------------------------------------------------------------------- + // Name: idWaveFile::Open() + // Desc: Opens a wave file for reading + //----------------------------------------------------------------------------- +-int idWaveFile::Open(const char *strFileName, waveformatex_t *pwfx) +-{ ++int idWaveFile::Open( const char* strFileName, waveformatex_t* pwfx ) { + + mbIsReadingFromMemory = false; + + mpbData = NULL; + mpbDataCur = mpbData; + +- if (strFileName == NULL) { ++ if( strFileName == NULL ) { + return -1; + } + + idStr name = strFileName; + + // note: used to only check for .wav when making a build +- name.SetFileExtension(".ogg"); +- +- if (fileSystem->ReadFile(name, NULL, NULL) != -1) { +- return OpenOGG(name, pwfx); ++ name.SetFileExtension( ".ogg" ); ++ if ( fileSystem->ReadFile( name, NULL, NULL ) != -1 ) { ++ return OpenOGG( name, pwfx ); + } + +- memset(&mpwfx, 0, sizeof(waveformatextensible_t)); ++ memset( &mpwfx, 0, sizeof( waveformatextensible_t ) ); + +- mhmmio = fileSystem->OpenFileRead(strFileName); +- +- if (!mhmmio) { ++ mhmmio = fileSystem->OpenFileRead( strFileName ); ++ if ( !mhmmio ) { + mdwSize = 0; + return -1; + } +- +- if (mhmmio->Length() <= 0) { ++ if ( mhmmio->Length() <= 0 ) { + mhmmio = NULL; + return -1; + } +- +- if (ReadMMIO() != 0) { ++ if ( ReadMMIO() != 0 ) { + // ReadMMIO will fail if its an not a wave file + Close(); + return -1; +@@ -114,23 +104,21 @@ int idWaveFile::Open(const char *strFileName, waveform + + mfileTime = mhmmio->Timestamp(); + +- if (ResetFile() != 0) { ++ if ( ResetFile() != 0 ) { + Close(); + return -1; + } + + // After the reset, the size of the wav file is mck.cksize so store it now +- mdwSize = mck.cksize / sizeof(short); ++ mdwSize = mck.cksize / sizeof( short ); + mMemSize = mck.cksize; + +- if (mck.cksize != 0xffffffff) { +- if (pwfx) { +- memcpy(pwfx, (waveformatex_t *)&mpwfx, sizeof(waveformatex_t)); ++ if ( mck.cksize != 0xffffffff ) { ++ if ( pwfx ) { ++ memcpy( pwfx, (waveformatex_t *)&mpwfx, sizeof(waveformatex_t)); + } +- + return 0; + } +- + return -1; + } + +@@ -138,13 +126,12 @@ int idWaveFile::Open(const char *strFileName, waveform + // Name: idWaveFile::OpenFromMemory() + // Desc: copy data to idWaveFile member variable from memory + //----------------------------------------------------------------------------- +-int idWaveFile::OpenFromMemory(short *pbData, int ulDataSize, waveformatextensible_t *pwfx) +-{ ++int idWaveFile::OpenFromMemory( short* pbData, int ulDataSize, waveformatextensible_t* pwfx ) { + mpwfx = *pwfx; + mulDataSize = ulDataSize; + mpbData = pbData; + mpbDataCur = mpbData; +- mdwSize = ulDataSize / sizeof(short); ++ mdwSize = ulDataSize / sizeof( short ); + mMemSize = ulDataSize; + mbIsReadingFromMemory = true; + +@@ -157,82 +144,76 @@ int idWaveFile::OpenFromMemory(short *pbData, int ulDa + // mhmmio must be valid before calling. This function uses it to + // update mckRiff, and mpwfx. + //----------------------------------------------------------------------------- +-int idWaveFile::ReadMMIO(void) +-{ ++int idWaveFile::ReadMMIO( void ) { + mminfo_t ckIn; // chunk info. for general use. + pcmwaveformat_t pcmWaveFormat; // Temp PCM structure to load in. + +- memset(&mpwfx, 0, sizeof(waveformatextensible_t)); ++ memset( &mpwfx, 0, sizeof( waveformatextensible_t ) ); + +- mhmmio->Read(&mckRiff, 12); +- assert(!isOgg); +- mckRiff.ckid = LittleLong(mckRiff.ckid); +- mckRiff.cksize = LittleLong(mckRiff.cksize); +- mckRiff.fccType = LittleLong(mckRiff.fccType); ++ mhmmio->Read( &mckRiff, 12 ); ++ assert( !isOgg ); ++ mckRiff.ckid = LittleLong( mckRiff.ckid ); ++ mckRiff.cksize = LittleLong( mckRiff.cksize ); ++ mckRiff.fccType = LittleLong( mckRiff.fccType ); + mckRiff.dwDataOffset = 12; + + // Check to make sure this is a valid wave file +- if ((mckRiff.ckid != fourcc_riff) || (mckRiff.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) { ++ if( (mckRiff.ckid != fourcc_riff) || (mckRiff.fccType != mmioFOURCC('W', 'A', 'V', 'E') ) ) { + return -1; + } + + // Search the input file for for the 'fmt ' chunk. + ckIn.dwDataOffset = 12; +- + do { +- if (8 != mhmmio->Read(&ckIn, 8)) { ++ if (8 != mhmmio->Read( &ckIn, 8 ) ) { + return -1; + } +- +- assert(!isOgg); +- ckIn.ckid = LittleLong(ckIn.ckid); +- ckIn.cksize = LittleLong(ckIn.cksize); ++ assert( !isOgg ); ++ ckIn.ckid = LittleLong( ckIn.ckid ); ++ ckIn.cksize = LittleLong( ckIn.cksize ); + ckIn.dwDataOffset += ckIn.cksize-8; + } while (ckIn.ckid != mmioFOURCC('f', 'm', 't', ' ')); + + // Expect the 'fmt' chunk to be at least as large as ; + // if there are extra parameters at the end, we'll ignore them +- if (ckIn.cksize < sizeof(pcmwaveformat_t)) { ++ if( ckIn.cksize < sizeof(pcmwaveformat_t) ) { + return -1; + } + + // Read the 'fmt ' chunk into . +- if (mhmmio->Read(&pcmWaveFormat, sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat)) { ++ if( mhmmio->Read( &pcmWaveFormat, sizeof(pcmWaveFormat) ) != sizeof(pcmWaveFormat) ) { + return -1; + } ++ assert( !isOgg ); ++ pcmWaveFormat.wf.wFormatTag = LittleShort( pcmWaveFormat.wf.wFormatTag ); ++ pcmWaveFormat.wf.nChannels = LittleShort( pcmWaveFormat.wf.nChannels ); ++ pcmWaveFormat.wf.nSamplesPerSec = LittleLong( pcmWaveFormat.wf.nSamplesPerSec ); ++ pcmWaveFormat.wf.nAvgBytesPerSec = LittleLong( pcmWaveFormat.wf.nAvgBytesPerSec ); ++ pcmWaveFormat.wf.nBlockAlign = LittleShort( pcmWaveFormat.wf.nBlockAlign ); ++ pcmWaveFormat.wBitsPerSample = LittleShort( pcmWaveFormat.wBitsPerSample ); + +- assert(!isOgg); +- pcmWaveFormat.wf.wFormatTag = LittleShort(pcmWaveFormat.wf.wFormatTag); +- pcmWaveFormat.wf.nChannels = LittleShort(pcmWaveFormat.wf.nChannels); +- pcmWaveFormat.wf.nSamplesPerSec = LittleLong(pcmWaveFormat.wf.nSamplesPerSec); +- pcmWaveFormat.wf.nAvgBytesPerSec = LittleLong(pcmWaveFormat.wf.nAvgBytesPerSec); +- pcmWaveFormat.wf.nBlockAlign = LittleShort(pcmWaveFormat.wf.nBlockAlign); +- pcmWaveFormat.wBitsPerSample = LittleShort(pcmWaveFormat.wBitsPerSample); +- + // Copy the bytes from the pcm structure to the waveformatex_t structure +- memcpy(&mpwfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); ++ memcpy( &mpwfx, &pcmWaveFormat, sizeof(pcmWaveFormat) ); + + // Allocate the waveformatex_t, but if its not pcm format, read the next + // word, and thats how many extra bytes to allocate. +- if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_TAG_PCM) { ++ if( pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_TAG_PCM ) { + mpwfx.Format.cbSize = 0; + } else { + return -1; // we don't handle these (32 bit wavefiles, etc) + #if 0 + // Read in length of extra bytes. + word cbExtraBytes = 0L; +- +- if (mhmmio->Read((char *)&cbExtraBytes, sizeof(word)) != sizeof(word)) ++ if( mhmmio->Read( (char*)&cbExtraBytes, sizeof(word) ) != sizeof(word) ) + return -1; + + mpwfx.Format.cbSize = cbExtraBytes; + + // Now, read those extra bytes into the structure, if cbExtraAlloc != 0. +- if (mhmmio->Read((char *)(((byte *)&(mpwfx.Format.cbSize))+sizeof(word)), cbExtraBytes) != cbExtraBytes) { +- memset(&mpwfx, 0, sizeof(waveformatextensible_t)); ++ if( mhmmio->Read( (char*)(((byte*)&(mpwfx.Format.cbSize))+sizeof(word)), cbExtraBytes ) != cbExtraBytes ) { ++ memset( &mpwfx, 0, sizeof( waveformatextensible_t ) ); + return -1; + } +- + #endif + } + +@@ -244,36 +225,32 @@ int idWaveFile::ReadMMIO(void) + // Desc: Resets the internal mck pointer so reading starts from the + // beginning of the file again + //----------------------------------------------------------------------------- +-int idWaveFile::ResetFile(void) +-{ +- if (mbIsReadingFromMemory) { ++int idWaveFile::ResetFile( void ) { ++ if( mbIsReadingFromMemory ) { + mpbDataCur = mpbData; + } else { +- if (mhmmio == NULL) { ++ if( mhmmio == NULL ) { + return -1; + } + + // Seek to the data +- if (-1 == mhmmio->Seek(mckRiff.dwDataOffset + sizeof(fourcc), FS_SEEK_SET)) { ++ if( -1 == mhmmio->Seek( mckRiff.dwDataOffset + sizeof(fourcc), FS_SEEK_SET ) ) { + return -1; + } + + // Search the input file for for the 'fmt ' chunk. + mck.ckid = 0; +- + do { + byte ioin; +- +- if (!mhmmio->Read(&ioin, 1)) { ++ if ( !mhmmio->Read( &ioin, 1 ) ) { + return -1; + } +- + mck.ckid = (mck.ckid>>8) | (ioin<<24); + } while (mck.ckid != mmioFOURCC('d', 'a', 't', 'a')); + +- mhmmio->Read(&mck.cksize, 4); +- assert(!isOgg); +- mck.cksize = LittleLong(mck.cksize); ++ mhmmio->Read( &mck.cksize, 4 ); ++ assert( !isOgg ); ++ mck.cksize = LittleLong( mck.cksize ); + mseekBase = mhmmio->Tell(); + } + +@@ -288,27 +265,24 @@ int idWaveFile::ResetFile(void) + // subsequent calls will be continue where the last left off unless + // Reset() is called. + //----------------------------------------------------------------------------- +-int idWaveFile::Read(byte *pBuffer, int dwSizeToRead, int *pdwSizeRead) +-{ ++int idWaveFile::Read( byte* pBuffer, int dwSizeToRead, int *pdwSizeRead ) { + +- if (ogg != NULL) { ++ if ( ogg != NULL ) { + +- return ReadOGG(pBuffer, dwSizeToRead, pdwSizeRead); ++ return ReadOGG( pBuffer, dwSizeToRead, pdwSizeRead ); + +- } else if (mbIsReadingFromMemory) { ++ } else if ( mbIsReadingFromMemory ) { + +- if (mpbDataCur == NULL) { ++ if( mpbDataCur == NULL ) { + return -1; + } +- +- if ((byte *)(mpbDataCur + dwSizeToRead) > (byte *)(mpbData + mulDataSize)) { ++ if( (byte*)(mpbDataCur + dwSizeToRead) > (byte*)(mpbData + mulDataSize) ) { + dwSizeToRead = mulDataSize - (int)(mpbDataCur - mpbData); + } +- +- SIMDProcessor->Memcpy(pBuffer, mpbDataCur, dwSizeToRead); ++ SIMDProcessor->Memcpy( pBuffer, mpbDataCur, dwSizeToRead ); + mpbDataCur += dwSizeToRead; + +- if (pdwSizeRead != NULL) { ++ if ( pdwSizeRead != NULL ) { + *pdwSizeRead = dwSizeToRead; + } + +@@ -316,22 +290,20 @@ int idWaveFile::Read(byte *pBuffer, int dwSizeToRead, + + } else { + +- if (mhmmio == NULL) { ++ if( mhmmio == NULL ) { + return -1; + } +- +- if (pBuffer == NULL) { ++ if( pBuffer == NULL ) { + return -1; + } + +- dwSizeToRead = mhmmio->Read(pBuffer, dwSizeToRead); +- ++ dwSizeToRead = mhmmio->Read( pBuffer, dwSizeToRead ); + // this is hit by ogg code, which does it's own byte swapping internally +- if (!isOgg) { +- LittleRevBytes(pBuffer, 2, dwSizeToRead / 2); ++ if ( !isOgg ) { ++ LittleRevBytes( pBuffer, 2, dwSizeToRead / 2 ); + } + +- if (pdwSizeRead != NULL) { ++ if ( pdwSizeRead != NULL ) { + *pdwSizeRead = dwSizeToRead; + } + +@@ -343,46 +315,40 @@ int idWaveFile::Read(byte *pBuffer, int dwSizeToRead, + // Name: idWaveFile::Close() + // Desc: Closes the wave file + //----------------------------------------------------------------------------- +-int idWaveFile::Close(void) +-{ +- if (ogg != NULL) { ++int idWaveFile::Close( void ) { ++ if ( ogg != NULL ) { + return CloseOGG(); + } +- +- if (mhmmio != NULL) { +- fileSystem->CloseFile(mhmmio); ++ if( mhmmio != NULL ) { ++ fileSystem->CloseFile( mhmmio ); + mhmmio = NULL; + } +- + return 0; + } + + //----------------------------------------------------------------------------- + // Name: idWaveFile::Seek() + //----------------------------------------------------------------------------- +-int idWaveFile::Seek(int offset) +-{ ++int idWaveFile::Seek( int offset ) { + +- if (ogg != NULL) { ++ if ( ogg != NULL ) { + +- common->FatalError("idWaveFile::Seek: cannot seek on an OGG file\n"); ++ common->FatalError( "idWaveFile::Seek: cannot seek on an OGG file\n" ); + +- } else if (mbIsReadingFromMemory) { ++ } else if( mbIsReadingFromMemory ) { + + mpbDataCur = mpbData + offset; + + } else { +- if (mhmmio == NULL) { ++ if( mhmmio == NULL ) { + return -1; + } + + if ((int)(offset+mseekBase) == mhmmio->Tell()) { + return 0; + } +- +- mhmmio->Seek(offset + mseekBase, FS_SEEK_SET); ++ mhmmio->Seek( offset + mseekBase, FS_SEEK_SET ); + return 0; + } +- + return -1; + } diff --git a/games/idtech4a-engine/patches/patch-sound_snd_world_cpp b/games/idtech4a-engine/patches/patch-sound_snd_world_cpp new file mode 100644 index 000000000..10ff167a5 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_snd_world_cpp @@ -0,0 +1,2812 @@ +Index: sound/snd_world.cpp +--- sound/snd_world.cpp.orig ++++ sound/snd_world.cpp +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -36,8 +36,7 @@ If you have questions concerning this license or the a + idSoundWorldLocal::Init + ================== + */ +-void idSoundWorldLocal::Init(idRenderWorld *renderWorld) +-{ ++void idSoundWorldLocal::Init( idRenderWorld *renderWorld ) { + rw = renderWorld; + writeDemo = NULL; + +@@ -47,72 +46,20 @@ void idSoundWorldLocal::Init(idRenderWorld *renderWorl + listenerQU.Zero(); + listenerArea = 0; + listenerAreaName = "Undefined"; +-#ifdef _OPENAL_EFX +- if (idSoundSystemLocal::useEAXReverb) { +- if (!soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) { +- alGetError(); +- +- soundSystemLocal.alGenAuxiliaryEffectSlots(1, &listenerSlot); +- ALuint e = alGetError(); +- if (e != AL_NO_ERROR) { +- common->Warning("idSoundWorldLocal::Init: alGenAuxiliaryEffectSlots failed: 0x%x", e); +- listenerSlot = AL_EFFECTSLOT_NULL; +- } +- } +- +- if (!listenerAreFiltersInitialized) { +- listenerAreFiltersInitialized = true; +- +- alGetError(); +- soundSystemLocal.alGenFilters(2, listenerFilters); +- ALuint e = alGetError(); +- if (e != AL_NO_ERROR) { +- common->Warning("idSoundWorldLocal::Init: alGenFilters failed: 0x%x", e); +- listenerFilters[0] = AL_FILTER_NULL; +- listenerFilters[1] = AL_FILTER_NULL; +- } else { +- soundSystemLocal.alFilteri(listenerFilters[0], AL_FILTER_TYPE, AL_FILTER_LOWPASS); +- // original EAX occusion value was -1150 +- // default OCCLUSIONLFRATIO is 0.25 +- // default OCCLUSIONDIRECTRATIO is 1.0 +- +- // pow(10.0, (-1150*0.25*1.0)/2000.0) +- soundSystemLocal.alFilterf(listenerFilters[0], AL_LOWPASS_GAIN, 0.718208f); +- // pow(10.0, (-1150*1.0)/2000.0) +- soundSystemLocal.alFilterf(listenerFilters[0], AL_LOWPASS_GAINHF, 0.266073f); +- +- +- soundSystemLocal.alFilteri(listenerFilters[1], AL_FILTER_TYPE, AL_FILTER_LOWPASS); +- // original EAX occusion value was -1150 +- // default OCCLUSIONLFRATIO is 0.25 +- // default OCCLUSIONROOMRATIO is 1.5 +- +- // pow(10.0, (-1150*(0.25+1.5-1.0))/2000.0) +- soundSystemLocal.alFilterf(listenerFilters[1], AL_LOWPASS_GAIN, 0.370467f); +- // pow(10.0, (-1150*1.5)/2000.0) +- soundSystemLocal.alFilterf(listenerFilters[1], AL_LOWPASS_GAINHF, 0.137246f); +- } +- // allow reducing the gain effect globally via s_alReverbGain CVar +- listenerSlotReverbGain = soundSystemLocal.s_alReverbGain.GetFloat(); +- soundSystemLocal.alAuxiliaryEffectSlotf(listenerSlot, AL_EFFECTSLOT_GAIN, listenerSlotReverbGain); +- } +- } +-#else + listenerEnvironmentID = -2; +-#endif + + gameMsec = 0; + game44kHz = 0; + pause44kHz = -1; + lastAVI44kHz = 0; + +- for (int i = 0 ; i < SOUND_MAX_CLASSES ; i++) { ++ for ( int i = 0 ; i < SOUND_MAX_CLASSES ; i++ ) { + soundClassFade[i].Clear(); + } + + // fill in the 0 index spot + idSoundEmitterLocal *placeHolder = new idSoundEmitterLocal; +- emitters.Append(placeHolder); ++ emitters.Append( placeHolder ); + + fpa[0] = fpa[1] = fpa[2] = fpa[3] = fpa[4] = fpa[5] = NULL; + +@@ -131,14 +78,7 @@ void idSoundWorldLocal::Init(idRenderWorld *renderWorl + idSoundWorldLocal::idSoundWorldLocal + =============== + */ +-idSoundWorldLocal::idSoundWorldLocal() +-{ +-#ifdef _OPENAL_EFX +- listenerEffect = 0; +- listenerSlot = 0; +- listenerAreFiltersInitialized = false; +- listenerSlotReverbGain = 1.0f; +-#endif ++idSoundWorldLocal::idSoundWorldLocal() { + } + + /* +@@ -146,8 +86,7 @@ idSoundWorldLocal::idSoundWorldLocal() + idSoundWorldLocal::~idSoundWorldLocal + =============== + */ +-idSoundWorldLocal::~idSoundWorldLocal() +-{ ++idSoundWorldLocal::~idSoundWorldLocal() { + Shutdown(); + } + +@@ -158,43 +97,21 @@ idSoundWorldLocal::Shutdown + this is called from the main thread + =============== + */ +-void idSoundWorldLocal::Shutdown() +-{ ++void idSoundWorldLocal::Shutdown() { + int i; + +- if (soundSystemLocal.currentSoundWorld == this) { ++ if ( soundSystemLocal.currentSoundWorld == this ) { + soundSystemLocal.currentSoundWorld = NULL; + } + + AVIClose(); + +- for (i = 0; i < emitters.Num(); i++) { +- if (emitters[i]) { ++ for ( i = 0; i < emitters.Num(); i++ ) { ++ if ( emitters[i] ) { + delete emitters[i]; + emitters[i] = NULL; + } + } +-#ifdef _OPENAL_EFX +- if (idSoundSystemLocal::useEAXReverb) { +- if (soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) { +- soundSystemLocal.alAuxiliaryEffectSloti(listenerSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECTSLOT_NULL); +- soundSystemLocal.alDeleteAuxiliaryEffectSlots(1, &listenerSlot); +- listenerSlot = AL_EFFECTSLOT_NULL; +- } +- +- if (listenerAreFiltersInitialized) { +- listenerAreFiltersInitialized = false; +- +- if (listenerFilters[0] != AL_FILTER_NULL && listenerFilters[1] != AL_FILTER_NULL) { +- soundSystemLocal.alDeleteFilters(2, listenerFilters); +- listenerFilters[0] = AL_FILTER_NULL; +- listenerFilters[1] = AL_FILTER_NULL; +- } +- } +- listenerSlotReverbGain = 1.0f; +- } +-#endif +- + localSound = NULL; + } + +@@ -203,19 +120,17 @@ void idSoundWorldLocal::Shutdown() + idSoundWorldLocal::ClearAllSoundEmitters + =================== + */ +-void idSoundWorldLocal::ClearAllSoundEmitters() +-{ ++void idSoundWorldLocal::ClearAllSoundEmitters() { + int i; + + Sys_EnterCriticalSection(); + + AVIClose(); + +- for (i = 0; i < emitters.Num(); i++) { ++ for ( i = 0; i < emitters.Num(); i++ ) { + idSoundEmitterLocal *sound = emitters[i]; + sound->Clear(); + } +- + localSound = NULL; + + Sys_LeaveCriticalSection(); +@@ -226,8 +141,7 @@ void idSoundWorldLocal::ClearAllSoundEmitters() + idSoundWorldLocal::AllocLocalSoundEmitter + =================== + */ +-idSoundEmitterLocal *idSoundWorldLocal::AllocLocalSoundEmitter() +-{ ++idSoundEmitterLocal *idSoundWorldLocal::AllocLocalSoundEmitter() { + int i, index; + idSoundEmitterLocal *def = NULL; + +@@ -235,32 +149,30 @@ idSoundEmitterLocal *idSoundWorldLocal::AllocLocalSoun + + // never use the 0 index spot + +- for (i = 1 ; i < emitters.Num() ; i++) { ++ for ( i = 1 ; i < emitters.Num() ; i++ ) { + def = emitters[i]; + + // check for a completed and freed spot +- if (def->removeStatus >= REMOVE_STATUS_SAMPLEFINISHED) { ++ if ( def->removeStatus >= REMOVE_STATUS_SAMPLEFINISHED ) { + index = i; +- +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("sound: recycling sound def %d\n", i); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "sound: recycling sound def %d\n", i ); + } +- + break; + } + } + +- if (index == -1) { ++ if ( index == -1 ) { + // append a brand new one + def = new idSoundEmitterLocal; + + // we need to protect this from the async thread + Sys_EnterCriticalSection(); +- index = emitters.Append(def); ++ index = emitters.Append( def ); + Sys_LeaveCriticalSection(); + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("sound: appended new sound def %d\n", index); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "sound: appended new sound def %d\n", index ); + } + } + +@@ -279,18 +191,16 @@ idSoundWorldLocal::AllocSoundEmitter + this is called from the main thread + =================== + */ +-idSoundEmitter *idSoundWorldLocal::AllocSoundEmitter() +-{ ++idSoundEmitter *idSoundWorldLocal::AllocSoundEmitter() { + idSoundEmitterLocal *emitter = AllocLocalSoundEmitter(); + +- if (idSoundSystemLocal::s_showStartSound.GetInteger()) { +- common->Printf("AllocSoundEmitter = %i\n", emitter->index); ++ if ( idSoundSystemLocal::s_showStartSound.GetInteger() ) { ++ common->Printf( "AllocSoundEmitter = %i\n", emitter->index ); + } +- +- if (writeDemo) { +- writeDemo->WriteInt(DS_SOUND); +- writeDemo->WriteInt(SCMD_ALLOC_EMITTER); +- writeDemo->WriteInt(emitter->index); ++ if ( writeDemo ) { ++ writeDemo->WriteInt( DS_SOUND ); ++ writeDemo->WriteInt( SCMD_ALLOC_EMITTER ); ++ writeDemo->WriteInt( emitter->index ); + } + + return emitter; +@@ -303,15 +213,14 @@ idSoundWorldLocal::StartWritingDemo + this is called from the main thread + =================== + */ +-void idSoundWorldLocal::StartWritingDemo(idDemoFile *demo) +-{ ++void idSoundWorldLocal::StartWritingDemo( idDemoFile *demo ) { + writeDemo = demo; + +- writeDemo->WriteInt(DS_SOUND); +- writeDemo->WriteInt(SCMD_STATE); ++ writeDemo->WriteInt( DS_SOUND ); ++ writeDemo->WriteInt( SCMD_STATE ); + + // use the normal save game code to archive all the emitters +- WriteToSaveGame(writeDemo); ++ WriteToSaveGame( writeDemo ); + } + + /* +@@ -321,8 +230,7 @@ idSoundWorldLocal::StopWritingDemo + this is called from the main thread + =================== + */ +-void idSoundWorldLocal::StopWritingDemo() +-{ ++void idSoundWorldLocal::StopWritingDemo() { + writeDemo = NULL; + } + +@@ -333,135 +241,138 @@ idSoundWorldLocal::ProcessDemoCommand + this is called from the main thread + =================== + */ +-void idSoundWorldLocal::ProcessDemoCommand(idDemoFile *readDemo) +-{ ++void idSoundWorldLocal::ProcessDemoCommand( idDemoFile *readDemo ) { + int index; + idSoundEmitterLocal *def; + +- if (!readDemo) { ++ if ( !readDemo ) { + return; + } + +- int dc; ++ soundDemoCommand_t dc; + +- if (!readDemo->ReadInt(dc)) { ++ if ( !readDemo->ReadInt( (int&)dc ) ) { + return; + } + +- switch ((soundDemoCommand_t) dc) { +- case SCMD_STATE: +- // we need to protect this from the async thread +- // other instances of calling idSoundWorldLocal::ReadFromSaveGame do this while the sound code is muted +- // setting muted and going right in may not be good enough here, as we async thread may already be in an async tick (in which case we could still race to it) +- Sys_EnterCriticalSection(); +- ReadFromSaveGame(readDemo); +- Sys_LeaveCriticalSection(); +- UnPause(); +- break; +- case SCMD_PLACE_LISTENER: { ++ switch( dc ) { ++ case SCMD_STATE: ++ // we need to protect this from the async thread ++ // other instances of calling idSoundWorldLocal::ReadFromSaveGame do this while the sound code is muted ++ // setting muted and going right in may not be good enough here, as we async thread may already be in an async tick (in which case we could still race to it) ++ Sys_EnterCriticalSection(); ++ ReadFromSaveGame( readDemo ); ++ Sys_LeaveCriticalSection(); ++ UnPause(); ++ break; ++ case SCMD_PLACE_LISTENER: ++ { + idVec3 origin; + idMat3 axis; + int listenerId; + int gameTime; + +- readDemo->ReadVec3(origin); +- readDemo->ReadMat3(axis); +- readDemo->ReadInt(listenerId); +- readDemo->ReadInt(gameTime); ++ readDemo->ReadVec3( origin ); ++ readDemo->ReadMat3( axis ); ++ readDemo->ReadInt( listenerId ); ++ readDemo->ReadInt( gameTime ); + +- PlaceListener(origin, axis, listenerId, gameTime, ""); ++ PlaceListener( origin, axis, listenerId, gameTime, "" ); + }; + break; +- case SCMD_ALLOC_EMITTER: +- readDemo->ReadInt(index); +- +- if (index < 1 || index > emitters.Num()) { +- common->Error("idSoundWorldLocal::ProcessDemoCommand: bad emitter number"); +- } +- +- if (index == emitters.Num()) { +- // append a brand new one +- def = new idSoundEmitterLocal; +- emitters.Append(def); +- } +- +- def = emitters[ index ]; +- def->Clear(); +- def->index = index; +- def->removeStatus = REMOVE_STATUS_ALIVE; +- def->soundWorld = this; +- break; +- case SCMD_FREE: { ++ case SCMD_ALLOC_EMITTER: ++ readDemo->ReadInt( index ); ++ if ( index < 1 || index > emitters.Num() ) { ++ common->Error( "idSoundWorldLocal::ProcessDemoCommand: bad emitter number" ); ++ } ++ if ( index == emitters.Num() ) { ++ // append a brand new one ++ def = new idSoundEmitterLocal; ++ emitters.Append( def ); ++ } ++ def = emitters[ index ]; ++ def->Clear(); ++ def->index = index; ++ def->removeStatus = REMOVE_STATUS_ALIVE; ++ def->soundWorld = this; ++ break; ++ case SCMD_FREE: ++ { + int immediate; + +- readDemo->ReadInt(index); +- readDemo->ReadInt(immediate); +- EmitterForIndex(index)->Free(immediate != 0); ++ readDemo->ReadInt( index ); ++ readDemo->ReadInt( immediate ); ++ EmitterForIndex( index )->Free( immediate != 0 ); + } + break; +- case SCMD_UPDATE: { ++ case SCMD_UPDATE: ++ { + idVec3 origin; + int listenerId; + soundShaderParms_t parms; + +- readDemo->ReadInt(index); +- readDemo->ReadVec3(origin); +- readDemo->ReadInt(listenerId); +- readDemo->ReadFloat(parms.minDistance); +- readDemo->ReadFloat(parms.maxDistance); +- readDemo->ReadFloat(parms.volume); +- readDemo->ReadFloat(parms.shakes); +- readDemo->ReadInt(parms.soundShaderFlags); +- readDemo->ReadInt(parms.soundClass); +- EmitterForIndex(index)->UpdateEmitter(origin, listenerId, &parms); ++ readDemo->ReadInt( index ); ++ readDemo->ReadVec3( origin ); ++ readDemo->ReadInt( listenerId ); ++ readDemo->ReadFloat( parms.minDistance ); ++ readDemo->ReadFloat( parms.maxDistance ); ++ readDemo->ReadFloat( parms.volume ); ++ readDemo->ReadFloat( parms.shakes ); ++ readDemo->ReadInt( parms.soundShaderFlags ); ++ readDemo->ReadInt( parms.soundClass ); ++ EmitterForIndex( index )->UpdateEmitter( origin, listenerId, &parms ); + } + break; +- case SCMD_START: { ++ case SCMD_START: ++ { + const idSoundShader *shader; + int channel; + float diversity; + int shaderFlags; + +- readDemo->ReadInt(index); +- shader = declManager->FindSound(readDemo->ReadHashString()); +- readDemo->ReadInt(channel); +- readDemo->ReadFloat(diversity); +- readDemo->ReadInt(shaderFlags); +- EmitterForIndex(index)->StartSound(shader, (s_channelType)channel, diversity, shaderFlags); ++ readDemo->ReadInt( index ); ++ shader = declManager->FindSound( readDemo->ReadHashString() ); ++ readDemo->ReadInt( channel ); ++ readDemo->ReadFloat( diversity ); ++ readDemo->ReadInt( shaderFlags ); ++ EmitterForIndex( index )->StartSound( shader, (s_channelType)channel, diversity, shaderFlags ); + } + break; +- case SCMD_MODIFY: { ++ case SCMD_MODIFY: ++ { + int channel; + soundShaderParms_t parms; + +- readDemo->ReadInt(index); +- readDemo->ReadInt(channel); +- readDemo->ReadFloat(parms.minDistance); +- readDemo->ReadFloat(parms.maxDistance); +- readDemo->ReadFloat(parms.volume); +- readDemo->ReadFloat(parms.shakes); +- readDemo->ReadInt(parms.soundShaderFlags); +- readDemo->ReadInt(parms.soundClass); +- EmitterForIndex(index)->ModifySound((s_channelType)channel, &parms); ++ readDemo->ReadInt( index ); ++ readDemo->ReadInt( channel ); ++ readDemo->ReadFloat( parms.minDistance ); ++ readDemo->ReadFloat( parms.maxDistance ); ++ readDemo->ReadFloat( parms.volume ); ++ readDemo->ReadFloat( parms.shakes ); ++ readDemo->ReadInt( parms.soundShaderFlags ); ++ readDemo->ReadInt( parms.soundClass ); ++ EmitterForIndex( index )->ModifySound( (s_channelType)channel, &parms ); + } + break; +- case SCMD_STOP: { ++ case SCMD_STOP: ++ { + int channel; + +- readDemo->ReadInt(index); +- readDemo->ReadInt(channel); +- EmitterForIndex(index)->StopSound((s_channelType)channel); ++ readDemo->ReadInt( index ); ++ readDemo->ReadInt( channel ); ++ EmitterForIndex( index )->StopSound( (s_channelType)channel ); + } + break; +- case SCMD_FADE: { ++ case SCMD_FADE: ++ { + int channel; + float to, over; + +- readDemo->ReadInt(index); +- readDemo->ReadInt(channel); +- readDemo->ReadFloat(to); +- readDemo->ReadFloat(over); +- EmitterForIndex(index)->FadeSound((s_channelType)channel, to, over); ++ readDemo->ReadInt( index ); ++ readDemo->ReadInt( channel ); ++ readDemo->ReadFloat( to ); ++ readDemo->ReadFloat( over ); ++ EmitterForIndex( index )->FadeSound((s_channelType)channel, to, over ); + } + break; + } +@@ -474,27 +385,23 @@ idSoundWorldLocal::CurrentShakeAmplitudeForPosition + this is called from the main thread + =================== + */ +-float idSoundWorldLocal::CurrentShakeAmplitudeForPosition(const int time, const idVec3 &listererPosition) +-{ ++float idSoundWorldLocal::CurrentShakeAmplitudeForPosition( const int time, const idVec3 &listererPosition ) { + float amp = 0.0f; + int localTime; + +- if (idSoundSystemLocal::s_constantAmplitude.GetFloat() >= 0.0f) { ++ if ( idSoundSystemLocal::s_constantAmplitude.GetFloat() >= 0.0f ) { + return 0.0f; + } + + localTime = soundSystemLocal.GetCurrent44kHzTime(); + +- for (int i = 1; i < emitters.Num(); i++) { ++ for ( int i = 1; i < emitters.Num(); i++ ) { + idSoundEmitterLocal *sound = emitters[i]; +- +- if (!sound->hasShakes) { ++ if ( !sound->hasShakes ) { + continue; + } +- +- amp += FindAmplitude(sound, localTime, &listererPosition, SCHANNEL_ANY, true); ++ amp += FindAmplitude( sound, localTime, &listererPosition, SCHANNEL_ANY, true ); + } +- + return amp; + } + +@@ -510,67 +417,38 @@ this is normally called from the sound thread, but als + for AVIdemo writing + =================== + */ +-void idSoundWorldLocal::MixLoop(int current44kHz, int numSpeakers, float *finalMixBuffer) +-{ ++void idSoundWorldLocal::MixLoop( int current44kHz, int numSpeakers, float *finalMixBuffer ) { + int i, j; + idSoundEmitterLocal *sound; + + // if noclip flying outside the world, leave silence +- if (listenerArea == -1) { +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL) +- alListenerf(AL_GAIN, 0.0f); +-#endif +- ++ if ( listenerArea == -1 ) { ++ alListenerf( AL_GAIN, 0.0f ); + return; + } + + // update the listener position and orientation +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL) { +- ALfloat listenerPosition[3]; ++ ALfloat listenerPosition[3]; + +- listenerPosition[0] = -listenerPos.y; +- listenerPosition[1] = listenerPos.z; +- listenerPosition[2] = -listenerPos.x; ++ listenerPosition[0] = -listenerPos.y; ++ listenerPosition[1] = listenerPos.z; ++ listenerPosition[2] = -listenerPos.x; + +- ALfloat listenerOrientation[6]; ++ ALfloat listenerOrientation[6]; + +- listenerOrientation[0] = -listenerAxis[0].y; +- listenerOrientation[1] = listenerAxis[0].z; +- listenerOrientation[2] = -listenerAxis[0].x; ++ listenerOrientation[0] = -listenerAxis[0].y; ++ listenerOrientation[1] = listenerAxis[0].z; ++ listenerOrientation[2] = -listenerAxis[0].x; + +- listenerOrientation[3] = -listenerAxis[2].y; +- listenerOrientation[4] = listenerAxis[2].z; +- listenerOrientation[5] = -listenerAxis[2].x; ++ listenerOrientation[3] = -listenerAxis[2].y; ++ listenerOrientation[4] = listenerAxis[2].z; ++ listenerOrientation[5] = -listenerAxis[2].x; + +- alListenerf(AL_GAIN, 1.0f); +- alListenerfv(AL_POSITION, listenerPosition); +- alListenerfv(AL_ORIENTATION, listenerOrientation); ++ alListenerf( AL_GAIN, 1.0f ); ++ alListenerfv( AL_POSITION, listenerPosition ); ++ alListenerfv( AL_ORIENTATION, listenerOrientation ); + +-#if ID_OPENAL +- +-#ifdef _OPENAL_EFX +- if (idSoundSystemLocal::useEAXReverb && soundSystemLocal.efxloaded) { +- ALuint effect = 0; +- idStr s(listenerArea); +- +- // allow reducing the gain effect globally via s_alReverbGain CVar +- float gain = soundSystemLocal.s_alReverbGain.GetFloat(); +- if (listenerSlotReverbGain != gain) { +- listenerSlotReverbGain = gain; +- soundSystemLocal.alAuxiliaryEffectSlotf(listenerSlot, AL_EFFECTSLOT_GAIN, gain); +- } +- +- bool found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect); +- if (!found) { +- s = listenerAreaName; +- found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect); +- } +- if (!found) { +- s = "default"; +- found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect); +- } ++#if ID_OPENAL_EAX + #ifdef _RAVEN + //karin: Quake4's reverb area config in `maps/.reverb` file. + if (!found) { +@@ -591,110 +469,88 @@ void idSoundWorldLocal::MixLoop(int current44kHz, int + found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect); + } + #endif ++ if ( soundSystemLocal.s_useEAXReverb.GetBool() ) { ++ if ( soundSystemLocal.efxloaded ) { ++ idSoundEffect *effect = NULL; ++ int EnvironmentID = -1; ++ idStr defaultStr( "default" ); ++ idStr listenerAreaStr( listenerArea ); + +- // only update if change in settings +- if (found && listenerEffect != effect) { +- EFXprintf("Switching to EFX '%s' (#%u)\n", s.c_str(), effect); +- listenerEffect = effect; +- soundSystemLocal.alAuxiliaryEffectSloti(listenerSlot, AL_EFFECTSLOT_EFFECT, effect); +- } +- } +-#else +- if (soundSystemLocal.s_useEAXReverb.GetBool()) { +- if (soundSystemLocal.efxloaded) { +- idSoundEffect *effect = NULL; +- int EnvironmentID = -1; +- idStr defaultStr("default"); +- idStr listenerAreaStr(listenerArea); ++ soundSystemLocal.EFXDatabase.FindEffect( listenerAreaStr, &effect, &EnvironmentID ); ++ if (!effect) ++ soundSystemLocal.EFXDatabase.FindEffect( listenerAreaName, &effect, &EnvironmentID ); ++ if (!effect) ++ soundSystemLocal.EFXDatabase.FindEffect( defaultStr, &effect, &EnvironmentID ); + +- soundSystemLocal.EFXDatabase.FindEffect(listenerAreaStr, &effect, &EnvironmentID); ++ // only update if change in settings ++ if ( soundSystemLocal.s_muteEAXReverb.GetBool() || ( listenerEnvironmentID != EnvironmentID ) ) { ++ EAXREVERBPROPERTIES EnvironmentParameters; + +- if (!effect) +- soundSystemLocal.EFXDatabase.FindEffect(listenerAreaName, &effect, &EnvironmentID); +- +- if (!effect) +- soundSystemLocal.EFXDatabase.FindEffect(defaultStr, &effect, &EnvironmentID); +- +- // only update if change in settings +- if (soundSystemLocal.s_muteEAXReverb.GetBool() || (listenerEnvironmentID != EnvironmentID)) { +- EAXREVERBPROPERTIES EnvironmentParameters; +- +- // get area reverb setting from EAX Manager +- if ((effect) && (effect->data) && (memcpy(&EnvironmentParameters, effect->data, effect->datasize))) { +- if (soundSystemLocal.s_muteEAXReverb.GetBool()) { +- EnvironmentParameters.lRoom = -10000; +- EnvironmentID = -2; +- } +- +- if (soundSystemLocal.alEAXSet) { +- soundSystemLocal.alEAXSet(&EAXPROPERTYID_EAX_FXSlot0, EAXREVERB_ALLPARAMETERS, 0, &EnvironmentParameters, sizeof(EnvironmentParameters)); +- } ++ // get area reverb setting from EAX Manager ++ if ( ( effect ) && ( effect->data) && ( memcpy( &EnvironmentParameters, effect->data, effect->datasize ) ) ) { ++ if ( soundSystemLocal.s_muteEAXReverb.GetBool() ) { ++ EnvironmentParameters.lRoom = -10000; ++ EnvironmentID = -2; + } +- +- listenerEnvironmentID = EnvironmentID; ++ if ( soundSystemLocal.alEAXSet ) { ++ soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_FXSlot0, EAXREVERB_ALLPARAMETERS, 0, &EnvironmentParameters, sizeof( EnvironmentParameters ) ); ++ } + } ++ listenerEnvironmentID = EnvironmentID; + } + } +-#endif +- +-#endif + } +- + #endif + + // debugging option to mute all but a single soundEmitter +- if (idSoundSystemLocal::s_singleEmitter.GetInteger() > 0 && idSoundSystemLocal::s_singleEmitter.GetInteger() < emitters.Num()) { ++ if ( idSoundSystemLocal::s_singleEmitter.GetInteger() > 0 && idSoundSystemLocal::s_singleEmitter.GetInteger() < emitters.Num() ) { + sound = emitters[idSoundSystemLocal::s_singleEmitter.GetInteger()]; + +- if (sound && sound->playing) { ++ if ( sound && sound->playing ) { + // run through all the channels +- for (j = 0; j < SOUND_MAX_CHANNELS ; j++) { ++ for ( j = 0; j < SOUND_MAX_CHANNELS ; j++ ) { + idSoundChannel *chan = &sound->channels[j]; + + // see if we have a sound triggered on this channel +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + chan->ALStop(); + continue; + } + +- AddChannelContribution(sound, chan, current44kHz, numSpeakers, finalMixBuffer); ++ AddChannelContribution( sound, chan, current44kHz, numSpeakers, finalMixBuffer ); + } + } +- + return; + } + +- for (i = 1; i < emitters.Num(); i++) { ++ for ( i = 1; i < emitters.Num(); i++ ) { + sound = emitters[i]; + +- if (!sound) { ++ if ( !sound ) { + continue; + } +- + // if no channels are active, do nothing +- if (!sound->playing) { ++ if ( !sound->playing ) { + continue; + } +- + // run through all the channels +- for (j = 0; j < SOUND_MAX_CHANNELS ; j++) { ++ for ( j = 0; j < SOUND_MAX_CHANNELS ; j++ ) { + idSoundChannel *chan = &sound->channels[j]; + + // see if we have a sound triggered on this channel +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + chan->ALStop(); + continue; + } + +- AddChannelContribution(sound, chan, current44kHz, numSpeakers, finalMixBuffer); ++ AddChannelContribution( sound, chan, current44kHz, numSpeakers, finalMixBuffer ); + } + } + +-#ifdef _OPENAL +- if (!idSoundSystemLocal::useOpenAL && enviroSuitActive) { +- soundSystemLocal.DoEnviroSuit(finalMixBuffer, MIXBUFFER_SAMPLES, numSpeakers); ++ // TODO port to OpenAL ++ if ( false && enviroSuitActive ) { ++ soundSystemLocal.DoEnviroSuit( finalMixBuffer, MIXBUFFER_SAMPLES, numSpeakers ); + } +-#endif + } + + //============================================================================== +@@ -706,26 +562,25 @@ idSoundWorldLocal::AVIOpen + this is called by the main thread + =================== + */ +-void idSoundWorldLocal::AVIOpen(const char *path, const char *name) +-{ ++void idSoundWorldLocal::AVIOpen( const char *path, const char *name ) { + aviDemoPath = path; + aviDemoName = name; + + lastAVI44kHz = game44kHz - game44kHz % MIXBUFFER_SAMPLES; + +- if (soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers() == 6) { +- fpa[0] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_left.raw"); +- fpa[1] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_right.raw"); +- fpa[2] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_center.raw"); +- fpa[3] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_lfe.raw"); +- fpa[4] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_backleft.raw"); +- fpa[5] = fileSystem->OpenFileWrite(aviDemoPath + "channel_51_backright.raw"); ++ if ( idSoundSystemLocal::s_numberOfSpeakers.GetInteger() == 6 ) { ++ fpa[0] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_left.raw" ); ++ fpa[1] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_right.raw" ); ++ fpa[2] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_center.raw" ); ++ fpa[3] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_lfe.raw" ); ++ fpa[4] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_backleft.raw" ); ++ fpa[5] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_backright.raw" ); + } else { +- fpa[0] = fileSystem->OpenFileWrite(aviDemoPath + "channel_left.raw"); +- fpa[1] = fileSystem->OpenFileWrite(aviDemoPath + "channel_right.raw"); ++ fpa[0] = fileSystem->OpenFileWrite( aviDemoPath + "channel_left.raw" ); ++ fpa[1] = fileSystem->OpenFileWrite( aviDemoPath + "channel_right.raw" ); + } + +- soundSystemLocal.SetMute(true); ++ soundSystemLocal.SetMute( true ); + } + + /* +@@ -737,44 +592,37 @@ writes one block of sound samples if enough time has p + This can be used to write wave files even if no sound hardware exists + =================== + */ +-void idSoundWorldLocal::AVIUpdate() +-{ ++void idSoundWorldLocal::AVIUpdate() { + int numSpeakers; + +- if (game44kHz - lastAVI44kHz < MIXBUFFER_SAMPLES) { ++ if ( game44kHz - lastAVI44kHz < MIXBUFFER_SAMPLES ) { + return; + } + +- if (!soundSystemLocal.snd_audio_hw) { +- numSpeakers = 2; +- } else { +- numSpeakers = soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers(); +- } ++ numSpeakers = idSoundSystemLocal::s_numberOfSpeakers.GetInteger(); + + float mix[MIXBUFFER_SAMPLES*6+16]; +- float *mix_p = (float *)(((intptr_t)mix + 15) & ~15); // SIMD align ++ float *mix_p = (float *)((( intptr_t)mix + 15 ) & ~15); // SIMD align + +- SIMDProcessor->Memset(mix_p, 0, MIXBUFFER_SAMPLES*sizeof(float)*numSpeakers); ++ SIMDProcessor->Memset( mix_p, 0, MIXBUFFER_SAMPLES*sizeof(float)*numSpeakers ); + +- MixLoop(lastAVI44kHz, numSpeakers, mix_p); ++ MixLoop( lastAVI44kHz, numSpeakers, mix_p ); + +- for (int i = 0; i < numSpeakers; i++) { ++ for ( int i = 0; i < numSpeakers; i++ ) { + short outD[MIXBUFFER_SAMPLES]; + +- for (int j = 0; j < MIXBUFFER_SAMPLES; j++) { ++ for( int j = 0; j < MIXBUFFER_SAMPLES; j++ ) { + float s = mix_p[ j*numSpeakers + i]; +- +- if (s < -32768.0f) { ++ if ( s < -32768.0f ) { + outD[j] = -32768; +- } else if (s > 32767.0f) { ++ } else if ( s > 32767.0f ) { + outD[j] = 32767; + } else { +- outD[j] = idMath::FtoiFast(s); ++ outD[j] = idMath::FtoiFast( s ); + } + } +- + // write to file +- fpa[i]->Write(outD, MIXBUFFER_SAMPLES*sizeof(short)); ++ fpa[i]->Write( outD, MIXBUFFER_SAMPLES*sizeof(short) ); + } + + lastAVI44kHz += MIXBUFFER_SAMPLES; +@@ -787,11 +635,10 @@ void idSoundWorldLocal::AVIUpdate() + idSoundWorldLocal::AVIClose + =================== + */ +-void idSoundWorldLocal::AVIClose(void) +-{ ++void idSoundWorldLocal::AVIClose( void ) { + int i; + +- if (!fpa[0]) { ++ if ( !fpa[0] ) { + return; + } + +@@ -800,37 +647,33 @@ void idSoundWorldLocal::AVIClose(void) + AVIUpdate(); + game44kHz -= MIXBUFFER_SAMPLES; + +- for (i = 0; i < 6; i++) { +- if (fpa[i] != NULL) { +- fileSystem->CloseFile(fpa[i]); ++ for ( i = 0; i < 6; i++ ) { ++ if ( fpa[i] != NULL ) { ++ fileSystem->CloseFile( fpa[i] ); + fpa[i] = NULL; + } + } +- +- if (soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers() == 2) { ++ if ( idSoundSystemLocal::s_numberOfSpeakers.GetInteger() == 2 ) { + // convert it to a wave file + idFile *rL, *lL, *wO; + idStr name; + + name = aviDemoPath + aviDemoName + ".wav"; +- wO = fileSystem->OpenFileWrite(name); +- +- if (!wO) { +- common->Error("Couldn't write %s", name.c_str()); ++ wO = fileSystem->OpenFileWrite( name ); ++ if ( !wO ) { ++ common->Error( "Couldn't write %s", name.c_str() ); + } + + name = aviDemoPath + "channel_right.raw"; +- rL = fileSystem->OpenFileRead(name); +- +- if (!rL) { +- common->Error("Couldn't open %s", name.c_str()); ++ rL = fileSystem->OpenFileRead( name ); ++ if ( !rL ) { ++ common->Error( "Couldn't open %s", name.c_str() ); + } + + name = aviDemoPath + "channel_left.raw"; +- lL = fileSystem->OpenFileRead(name); +- +- if (!lL) { +- common->Error("Couldn't open %s", name.c_str()); ++ lL = fileSystem->OpenFileRead( name ); ++ if ( !lL ) { ++ common->Error( "Couldn't open %s", name.c_str() ); + } + + int numSamples = rL->Length()/2; +@@ -838,16 +681,16 @@ void idSoundWorldLocal::AVIClose(void) + pcmwaveformat_t format; + + info.ckid = fourcc_riff; +- info.fccType = mmioFOURCC('W', 'A', 'V', 'E'); ++ info.fccType = mmioFOURCC( 'W', 'A', 'V', 'E' ); + info.cksize = (rL->Length()*2) - 8 + 4 + 16 + 8 + 8; + info.dwDataOffset = 12; + +- wO->Write(&info, 12); ++ wO->Write( &info, 12 ); + +- info.ckid = mmioFOURCC('f', 'm', 't', ' '); ++ info.ckid = mmioFOURCC( 'f', 'm', 't', ' ' ); + info.cksize = 16; + +- wO->Write(&info, 8); ++ wO->Write( &info, 8 ); + + format.wBitsPerSample = 16; + format.wf.nAvgBytesPerSec = 44100*4; // sample rate * block align +@@ -856,31 +699,30 @@ void idSoundWorldLocal::AVIClose(void) + format.wf.wFormatTag = WAVE_FORMAT_TAG_PCM; + format.wf.nBlockAlign = 4; // channels * bits/sample / 8 + +- wO->Write(&format, 16); ++ wO->Write( &format, 16 ); + +- info.ckid = mmioFOURCC('d', 'a', 't', 'a'); ++ info.ckid = mmioFOURCC( 'd', 'a', 't', 'a' ); + info.cksize = rL->Length() * 2; + +- wO->Write(&info, 8); ++ wO->Write( &info, 8 ); + + short s0, s1; +- +- for (i = 0; i < numSamples; i++) { +- lL->Read(&s0, 2); +- rL->Read(&s1, 2); +- wO->Write(&s0, 2); +- wO->Write(&s1, 2); ++ for( i = 0; i < numSamples; i++ ) { ++ lL->Read( &s0, 2 ); ++ rL->Read( &s1, 2 ); ++ wO->Write( &s0, 2 ); ++ wO->Write( &s1, 2 ); + } + +- fileSystem->CloseFile(wO); +- fileSystem->CloseFile(lL); +- fileSystem->CloseFile(rL); ++ fileSystem->CloseFile( wO ); ++ fileSystem->CloseFile( lL ); ++ fileSystem->CloseFile( rL ); + +- fileSystem->RemoveFile(aviDemoPath + "channel_right.raw"); +- fileSystem->RemoveFile(aviDemoPath + "channel_left.raw"); ++ fileSystem->RemoveFile( aviDemoPath + "channel_right.raw" ); ++ fileSystem->RemoveFile( aviDemoPath + "channel_left.raw" ); + } + +- soundSystemLocal.SetMute(false); ++ soundSystemLocal.SetMute( false ); + } + + //============================================================================== +@@ -903,26 +745,23 @@ set at maxDistance + */ + static const int MAX_PORTAL_TRACE_DEPTH = 10; + +-void idSoundWorldLocal::ResolveOrigin(const int stackDepth, const soundPortalTrace_t *prevStack, const int soundArea, const float dist, const idVec3 &soundOrigin, idSoundEmitterLocal *def) +-{ ++void idSoundWorldLocal::ResolveOrigin( const int stackDepth, const soundPortalTrace_t *prevStack, const int soundArea, const float dist, const idVec3& soundOrigin, idSoundEmitterLocal *def ) { + +- if (dist >= def->distance) { ++ if ( dist >= def->distance ) { + // we can't possibly hear the sound through this chain of portals + return; + } + +- if (soundArea == listenerArea) { ++ if ( soundArea == listenerArea ) { + float fullDist = dist + (soundOrigin - listenerQU).LengthFast(); +- +- if (fullDist < def->distance) { ++ if ( fullDist < def->distance ) { + def->distance = fullDist; + def->spatializedOrigin = soundOrigin; + } +- + return; + } + +- if (stackDepth == MAX_PORTAL_TRACE_DEPTH) { ++ if ( stackDepth == MAX_PORTAL_TRACE_DEPTH ) { + // don't spend too much time doing these calculations in big maps + return; + } +@@ -931,15 +770,14 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + newStack.portalArea = soundArea; + newStack.prevStack = prevStack; + +- int numPortals = rw->NumPortalsInArea(soundArea); ++ int numPortals = rw->NumPortalsInArea( soundArea ); ++ for( int p = 0; p < numPortals; p++ ) { ++ exitPortal_t re = rw->GetPortal( soundArea, p ); + +- for (int p = 0; p < numPortals; p++) { +- exitPortal_t re = rw->GetPortal(soundArea, p); +- + float occlusionDistance = 0; + + // air blocking windows will block sound like closed doors +- if ((re.blockingBits & (PS_BLOCK_VIEW | PS_BLOCK_AIR))) { ++ if ( (re.blockingBits & ( PS_BLOCK_VIEW | PS_BLOCK_AIR ) ) ) { + // we could just completely cut sound off, but reducing the volume works better + // continue; + occlusionDistance = idSoundSystemLocal::s_doorDistanceAdd.GetFloat(); +@@ -947,21 +785,18 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + + // what area are we about to go look at + int otherArea = re.areas[0]; +- +- if (re.areas[0] == soundArea) { ++ if ( re.areas[0] == soundArea ) { + otherArea = re.areas[1]; + } + + // if this area is already in our portal chain, don't bother looking into it + const soundPortalTrace_t *prev; +- +- for (prev = prevStack ; prev ; prev = prev->prevStack) { +- if (prev->portalArea == otherArea) { ++ for ( prev = prevStack ; prev ; prev = prev->prevStack ) { ++ if ( prev->portalArea == otherArea ) { + break; + } + } +- +- if (prev) { ++ if ( prev ) { + continue; + } + +@@ -970,29 +805,27 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + idVec3 source; + + idPlane pl; +- re.w->GetPlane(pl); ++ re.w->GetPlane( pl ); + + float scale; + idVec3 dir = listenerQU - soundOrigin; +- +- if (!pl.RayIntersection(soundOrigin, dir, scale)) { ++ if ( !pl.RayIntersection( soundOrigin, dir, scale ) ) { + source = re.w->GetCenter(); + } else { + source = soundOrigin + scale * dir; + + // if this point isn't inside the portal edges, slide it in +- for (int i = 0 ; i < re.w->GetNumPoints() ; i++) { +- int j = (i + 1) % re.w->GetNumPoints(); ++ for ( int i = 0 ; i < re.w->GetNumPoints() ; i++ ) { ++ int j = ( i + 1 ) % re.w->GetNumPoints(); + idVec3 edgeDir = (*(re.w))[j].ToVec3() - (*(re.w))[i].ToVec3(); + idVec3 edgeNormal; + +- edgeNormal.Cross(pl.Normal(), edgeDir); ++ edgeNormal.Cross( pl.Normal(), edgeDir ); + + idVec3 fromVert = source - (*(re.w))[j].ToVec3(); + + float d = edgeNormal * fromVert; +- +- if (d > 0) { ++ if ( d > 0 ) { + // move it in + float div = edgeNormal.Normalize(); + d /= div; +@@ -1001,7 +834,6 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + } + } + } +- + #else + // clip the ray from the listener to the center of the portal by + // all the portal edge planes, then project that point (or the original if not clipped) +@@ -1011,8 +843,8 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + idVec3 mid = re.w->GetCenter(); + bool wasClipped = false; + +- for (int i = 0 ; i < re.w->GetNumPoints() ; i++) { +- int j = (i + 1) % re.w->GetNumPoints(); ++ for ( int i = 0 ; i < re.w->GetNumPoints() ; i++ ) { ++ int j = ( i + 1 ) % re.w->GetNumPoints(); + idVec3 v1 = (*(re.w))[j].ToVec3() - soundOrigin; + idVec3 v2 = (*(re.w))[i].ToVec3() - soundOrigin; + +@@ -1021,46 +853,44 @@ void idSoundWorldLocal::ResolveOrigin(const int stackD + + idVec3 edgeNormal; + +- edgeNormal.Cross(v1, v2); ++ edgeNormal.Cross( v1, v2 ); + + idVec3 fromVert = start - soundOrigin; + float d1 = edgeNormal * fromVert; + +- if (d1 > 0.0f) { ++ if ( d1 > 0.0f ) { + fromVert = mid - (*(re.w))[j].ToVec3(); + float d2 = edgeNormal * fromVert; + + // move it in +- float f = d1 / (d1 - d2); ++ float f = d1 / ( d1 - d2 ); + +- idVec3 clipped = start * (1.0f - f) + mid * f; ++ idVec3 clipped = start * ( 1.0f - f ) + mid * f; + start = clipped; + wasClipped = true; + } + } + + idVec3 source; +- +- if (wasClipped) { ++ if ( wasClipped ) { + // now project it onto the portal plane + idPlane pl; +- re.w->GetPlane(pl); ++ re.w->GetPlane( pl ); + +- float f1 = pl.Distance(start); +- float f2 = pl.Distance(soundOrigin); ++ float f1 = pl.Distance( start ); ++ float f2 = pl.Distance( soundOrigin ); + +- float f = f1 / (f1 - f2); +- source = start * (1.0f - f) + soundOrigin * f; ++ float f = f1 / ( f1 - f2 ); ++ source = start * ( 1.0f - f ) + soundOrigin * f; + } else { + source = soundOrigin; + } +- + #endif + + idVec3 tlen = source - soundOrigin; + float tlenLength = tlen.LengthFast(); + +- ResolveOrigin(stackDepth+1, &newStack, otherArea, dist+tlenLength+occlusionDistance, source, def); ++ ResolveOrigin( stackDepth+1, &newStack, otherArea, dist+tlenLength+occlusionDistance, source, def ); + } + } + +@@ -1072,27 +902,26 @@ idSoundWorldLocal::PlaceListener + this is called by the main thread + =================== + */ +-void idSoundWorldLocal::PlaceListener(const idVec3 &origin, const idMat3 &axis, +- const int listenerId, const int gameTime, const idStr &areaName) +-{ ++void idSoundWorldLocal::PlaceListener( const idVec3& origin, const idMat3& axis, ++ const int listenerId, const int gameTime, const idStr& areaName ) { + + int current44kHzTime; + +- if (!soundSystemLocal.isInitialized) { ++ if ( !soundSystemLocal.isInitialized ) { + return; + } + +- if (pause44kHz >= 0) { ++ if ( pause44kHz >= 0 ){ + return; + } + +- if (writeDemo) { +- writeDemo->WriteInt(DS_SOUND); +- writeDemo->WriteInt(SCMD_PLACE_LISTENER); +- writeDemo->WriteVec3(origin); +- writeDemo->WriteMat3(axis); +- writeDemo->WriteInt(listenerId); +- writeDemo->WriteInt(gameTime); ++ if ( writeDemo ) { ++ writeDemo->WriteInt( DS_SOUND ); ++ writeDemo->WriteInt( SCMD_PLACE_LISTENER ); ++ writeDemo->WriteVec3( origin ); ++ writeDemo->WriteMat3( axis ); ++ writeDemo->WriteInt( listenerId ); ++ writeDemo->WriteInt( gameTime ); + } + + current44kHzTime = soundSystemLocal.GetCurrent44kHzTime(); +@@ -1102,18 +931,17 @@ void idSoundWorldLocal::PlaceListener(const idVec3 &or + // amount, while the hardware 44kHz position will not have changed accordingly, + // which would make sounds (like long character speaches) continue from the + // old time. Fix this by killing all non-looping sounds +- if (gameTime > gameMsec + 500) { +- OffsetSoundTime(- (gameTime - gameMsec) * 0.001f * 44100.0f); ++ if ( gameTime > gameMsec + 500 ) { ++ OffsetSoundTime( - ( gameTime - gameMsec ) * 0.001f * 44100.0f ); + } + + gameMsec = gameTime; +- +- if (fpa[0]) { ++ if ( fpa[0] ) { + // exactly 30 fps so the wave file can be used for exact video frames +- game44kHz = idMath::FtoiFast(gameMsec * ((1000.0f / 60.0f) / 16.0f) * 0.001f * 44100.0f); ++ game44kHz = idMath::FtoiFast( gameMsec * ( ( 1000.0f / 60.0f ) / 16.0f ) * 0.001f * 44100.0f ); + } else { + // the normal 16 msec / frame +- game44kHz = idMath::FtoiFast(gameMsec * 0.001f * 44100.0f); ++ game44kHz = idMath::FtoiFast( gameMsec * 0.001f * 44100.0f ); + } + + listenerPrivateId = listenerId; +@@ -1124,17 +952,17 @@ void idSoundWorldLocal::PlaceListener(const idVec3 &or + listenerAreaName = areaName; + listenerAreaName.ToLower(); + +- if (rw) { +- listenerArea = rw->PointInArea(listenerQU); // where are we? ++ if ( rw ) { ++ listenerArea = rw->PointInArea( listenerQU ); // where are we? + } else { + listenerArea = 0; + } + +- if (listenerArea < 0) { ++ if ( listenerArea < 0 ) { + return; + } + +- ForegroundUpdate(current44kHzTime); ++ ForegroundUpdate( current44kHzTime ); + } + + /* +@@ -1142,19 +970,18 @@ void idSoundWorldLocal::PlaceListener(const idVec3 &or + idSoundWorldLocal::ForegroundUpdate + ================== + */ +-void idSoundWorldLocal::ForegroundUpdate(int current44kHzTime) +-{ ++void idSoundWorldLocal::ForegroundUpdate( int current44kHzTime ) { + int j, k; + idSoundEmitterLocal *def; + +- if (!soundSystemLocal.isInitialized) { ++ if ( !soundSystemLocal.isInitialized ) { + return; + } + + Sys_EnterCriticalSection(); + + // if we are recording an AVI demo, don't use hardware time +- if (fpa[0]) { ++ if ( fpa[0] ) { + current44kHzTime = lastAVI44kHz; + } + +@@ -1164,52 +991,52 @@ void idSoundWorldLocal::ForegroundUpdate(int current44 + // although the sound may still need to play if it has + // just become occluded so it can ramp down to 0 + // +- for (j = 1; j < emitters.Num(); j++) { ++ for ( j = 1; j < emitters.Num(); j++ ) { + def = emitters[j]; + +- if (def->removeStatus >= REMOVE_STATUS_SAMPLEFINISHED) { ++ if ( def->removeStatus >= REMOVE_STATUS_SAMPLEFINISHED ) { + continue; + } + + // see if our last channel just finished +- def->CheckForCompletion(current44kHzTime); ++ def->CheckForCompletion( current44kHzTime ); + +- if (!def->playing) { ++ if ( !def->playing ) { + continue; + } + + // update virtual origin / distance, etc +- def->Spatialize(listenerPos, listenerArea, rw); ++ def->Spatialize( listenerPos, listenerArea, rw ); + + // per-sound debug options +- if (idSoundSystemLocal::s_drawSounds.GetInteger() && rw) { +- if (def->distance < def->maxDistance || idSoundSystemLocal::s_drawSounds.GetInteger() > 1) { ++ if ( idSoundSystemLocal::s_drawSounds.GetInteger() && rw ) { ++ if ( def->distance < def->maxDistance || idSoundSystemLocal::s_drawSounds.GetInteger() > 1 ) { + idBounds ref; + ref.Clear(); +- ref.AddPoint(idVec3(-10, -10, -10)); +- ref.AddPoint(idVec3(10, 10, 10)); ++ ref.AddPoint( idVec3( -10, -10, -10 ) ); ++ ref.AddPoint( idVec3( 10, 10, 10 ) ); + float vis = (1.0f - (def->distance / def->maxDistance)); + + // draw a box +- rw->DebugBounds(idVec4(vis, 0.25f, vis, vis), ref, def->origin); ++ rw->DebugBounds( idVec4( vis, 0.25f, vis, vis ), ref, def->origin ); + + // draw an arrow to the audible position, possible a portal center +- if (def->origin != def->spatializedOrigin) { +- rw->DebugArrow(colorRed, def->origin, def->spatializedOrigin, 4); ++ if ( def->origin != def->spatializedOrigin ) { ++ rw->DebugArrow( colorRed, def->origin, def->spatializedOrigin, 4 ); + } + + // draw the index + idVec3 textPos = def->origin; + textPos[2] -= 8; +- rw->DrawText(va("%i", def->index), textPos, 0.1f, idVec4(1,0,0,1), listenerAxis); ++ rw->DrawText( va("%i", def->index), textPos, 0.1f, idVec4(1,0,0,1), listenerAxis ); + textPos[2] += 8; + + // run through all the channels +- for (k = 0; k < SOUND_MAX_CHANNELS ; k++) { ++ for ( k = 0; k < SOUND_MAX_CHANNELS ; k++ ) { + idSoundChannel *chan = &def->channels[k]; + + // see if we have a sound triggered on this channel +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } + +@@ -1217,9 +1044,9 @@ void idSoundWorldLocal::ForegroundUpdate(int current44 + float min = chan->parms.minDistance; + float max = chan->parms.maxDistance; + const char *defaulted = chan->leadinSample->defaultSound ? "(DEFAULTED)" : ""; +- sprintf(text, "%s (%i/%i %i/%i)%s", chan->soundShader->GetName(), (int)def->distance, +- (int)def->realDistance, (int)min, (int)max, defaulted); +- rw->DrawText(text, textPos, 0.1f, idVec4(1,0,0,1), listenerAxis); ++ sprintf( text, "%s (%i/%i %i/%i)%s", chan->soundShader->GetName(), (int)def->distance, ++ (int)def->realDistance, (int)min, (int)max, defaulted ); ++ rw->DrawText( text, textPos, 0.1f, idVec4(1,0,0,1), listenerAxis ); + textPos[2] += 8; + } + } +@@ -1231,13 +1058,11 @@ void idSoundWorldLocal::ForegroundUpdate(int current44 + // + // the sound meter + // +- if (idSoundSystemLocal::s_showLevelMeter.GetInteger()) { +- const idMaterial *gui = declManager->FindMaterial("guis/assets/soundmeter/audiobg", false); +- +- if (gui) { ++ if ( idSoundSystemLocal::s_showLevelMeter.GetInteger() ) { ++ const idMaterial *gui = declManager->FindMaterial( "guis/assets/soundmeter/audiobg", false ); ++ if ( gui ) { + const shaderStage_t *foo = gui->GetStage(0); +- +- if (!foo->texture.cinematic) { ++ if ( !foo->texture.cinematic ) { + ((shaderStage_t *)foo)->texture.cinematic = new idSndWindow; + } + } +@@ -1246,7 +1071,7 @@ void idSoundWorldLocal::ForegroundUpdate(int current44 + // + // optionally dump out the generated sound + // +- if (fpa[0]) { ++ if ( fpa[0] ) { + AVIUpdate(); + } + } +@@ -1256,19 +1081,17 @@ void idSoundWorldLocal::ForegroundUpdate(int current44 + idSoundWorldLocal::OffsetSoundTime + =================== + */ +-void idSoundWorldLocal::OffsetSoundTime(int offset44kHz) +-{ ++void idSoundWorldLocal::OffsetSoundTime( int offset44kHz ) { + int i, j; + +- for (i = 0; i < emitters.Num(); i++) { +- if (emitters[i] == NULL) { ++ for ( i = 0; i < emitters.Num(); i++ ) { ++ if ( emitters[i] == NULL ) { + continue; + } +- +- for (j = 0; j < SOUND_MAX_CHANNELS; j++) { ++ for ( j = 0; j < SOUND_MAX_CHANNELS; j++ ) { + idSoundChannel *chan = &emitters[i]->channels[ j ]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } + +@@ -1282,13 +1105,12 @@ void idSoundWorldLocal::OffsetSoundTime(int offset44kH + idSoundWorldLocal::WriteToSaveGame + =================== + */ +-void idSoundWorldLocal::WriteToSaveGame(idFile *savefile) +-{ ++void idSoundWorldLocal::WriteToSaveGame( idFile *savefile ) { + int i, j, num, currentSoundTime; + const char *name; + + // the game soundworld is always paused at this point, save that time down +- if (pause44kHz > 0) { ++ if ( pause44kHz > 0 ) { + currentSoundTime = pause44kHz; + } else { + currentSoundTime = soundSystemLocal.GetCurrent44kHzTime(); +@@ -1305,63 +1127,61 @@ void idSoundWorldLocal::WriteToSaveGame(idFile *savefi + num = emitters.Num(); + savefile->WriteInt(num); + +- for (i = 1; i < emitters.Num(); i++) { ++ for ( i = 1; i < emitters.Num(); i++ ) { + idSoundEmitterLocal *def = emitters[i]; + +- if (def->removeStatus != REMOVE_STATUS_ALIVE) { ++ if ( def->removeStatus != REMOVE_STATUS_ALIVE ) { + int skip = -1; +- savefile->Write(&skip, sizeof(skip)); ++ savefile->Write( &skip, sizeof( skip ) ); + continue; + } + + savefile->WriteInt(i); + + // Write the emitter data +- savefile->WriteVec3(def->origin); +- savefile->WriteInt(def->listenerId); +- WriteToSaveGameSoundShaderParams(savefile, &def->parms); +- savefile->WriteFloat(def->amplitude); +- savefile->WriteInt(def->ampTime); +- ++ savefile->WriteVec3( def->origin ); ++ savefile->WriteInt( def->listenerId ); ++ WriteToSaveGameSoundShaderParams( savefile, &def->parms ); ++ savefile->WriteFloat( def->amplitude ); ++ savefile->WriteInt( def->ampTime ); + for (int k = 0; k < SOUND_MAX_CHANNELS; k++) +- WriteToSaveGameSoundChannel(savefile, &def->channels[k]); ++ WriteToSaveGameSoundChannel( savefile, &def->channels[k] ); ++ savefile->WriteFloat( def->distance ); ++ savefile->WriteBool( def->hasShakes ); ++ savefile->WriteInt( def->lastValidPortalArea ); ++ savefile->WriteFloat( def->maxDistance ); ++ savefile->WriteBool( def->playing ); ++ savefile->WriteFloat( def->realDistance ); ++ savefile->WriteInt( def->removeStatus ); ++ savefile->WriteVec3( def->spatializedOrigin ); + +- savefile->WriteFloat(def->distance); +- savefile->WriteBool(def->hasShakes); +- savefile->WriteInt(def->lastValidPortalArea); +- savefile->WriteFloat(def->maxDistance); +- savefile->WriteBool(def->playing); +- savefile->WriteFloat(def->realDistance); +- savefile->WriteInt(def->removeStatus); +- savefile->WriteVec3(def->spatializedOrigin); +- + // write the channel data +- for (j = 0; j < SOUND_MAX_CHANNELS; j++) { ++ for( j = 0; j < SOUND_MAX_CHANNELS; j++ ) { + idSoundChannel *chan = &def->channels[ j ]; + + // Write out any sound commands for this def +- if (chan->triggerState && chan->soundShader && chan->leadinSample) { ++ if ( chan->triggerState && chan->soundShader && chan->leadinSample ) { + +- savefile->WriteInt(j); ++ savefile->WriteInt( j ); + + // write the pointers out separately + name = chan->soundShader->GetName(); +- savefile->WriteString(name); ++ savefile->WriteString( name ); + + name = chan->leadinSample->name; +- savefile->WriteString(name); ++ savefile->WriteString( name ); + } + } + + // End active channels with -1 + int end = -1; +- savefile->WriteInt(end); ++ savefile->WriteInt( end ); + } + + // new in Doom3 v1.2 +- savefile->Write(&slowmoActive, sizeof(slowmoActive)); +- savefile->Write(&slowmoSpeed, sizeof(slowmoSpeed)); +- savefile->Write(&enviroSuitActive, sizeof(enviroSuitActive)); ++ savefile->Write( &slowmoActive, sizeof( slowmoActive ) ); ++ savefile->Write( &slowmoSpeed, sizeof( slowmoSpeed ) ); ++ savefile->Write( &enviroSuitActive, sizeof( enviroSuitActive ) ); + } + + /* +@@ -1369,8 +1189,7 @@ void idSoundWorldLocal::WriteToSaveGame(idFile *savefi + idSoundWorldLocal::WriteToSaveGameSoundShaderParams + =================== + */ +-void idSoundWorldLocal::WriteToSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params) +-{ ++void idSoundWorldLocal::WriteToSaveGameSoundShaderParams( idFile *saveGame, soundShaderParms_t *params ) { + saveGame->WriteFloat(params->minDistance); + saveGame->WriteFloat(params->maxDistance); + saveGame->WriteFloat(params->volume); +@@ -1384,29 +1203,26 @@ void idSoundWorldLocal::WriteToSaveGameSoundShaderPara + idSoundWorldLocal::WriteToSaveGameSoundChannel + =================== + */ +-void idSoundWorldLocal::WriteToSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch) +-{ +- saveGame->WriteBool(ch->triggerState); +- saveGame->WriteUnsignedChar(0); +- saveGame->WriteUnsignedChar(0); +- saveGame->WriteUnsignedChar(0); +- saveGame->WriteInt(ch->trigger44kHzTime); +- saveGame->WriteInt(ch->triggerGame44kHzTime); +- WriteToSaveGameSoundShaderParams(saveGame, &ch->parms); +- saveGame->WriteInt(/* (int)ch->leadinSample */ 0); +- saveGame->WriteInt(ch->triggerChannel); +- saveGame->WriteInt(/* (int)ch->soundShader */ 0); +- saveGame->WriteInt(/* (int)ch->decoder */ 0); +- saveGame->WriteFloat(ch->diversity); +- saveGame->WriteFloat(ch->lastVolume); +- ++void idSoundWorldLocal::WriteToSaveGameSoundChannel( idFile *saveGame, idSoundChannel *ch ) { ++ saveGame->WriteBool( ch->triggerState ); ++ saveGame->WriteUnsignedChar( 0 ); ++ saveGame->WriteUnsignedChar( 0 ); ++ saveGame->WriteUnsignedChar( 0 ); ++ saveGame->WriteInt( ch->trigger44kHzTime ); ++ saveGame->WriteInt( ch->triggerGame44kHzTime ); ++ WriteToSaveGameSoundShaderParams( saveGame, &ch->parms ); ++ saveGame->WriteInt( 0 /* ch->leadinSample */ ); ++ saveGame->WriteInt( ch->triggerChannel ); ++ saveGame->WriteInt( 0 /* ch->soundShader */ ); ++ saveGame->WriteInt( 0 /* ch->decoder */ ); ++ saveGame->WriteFloat(ch->diversity ); ++ saveGame->WriteFloat(ch->lastVolume ); + for (int m = 0; m < 6; m++) +- saveGame->WriteFloat(ch->lastV[m]); +- +- saveGame->WriteInt(ch->channelFade.fadeStart44kHz); +- saveGame->WriteInt(ch->channelFade.fadeEnd44kHz); +- saveGame->WriteFloat(ch->channelFade.fadeStartVolume); +- saveGame->WriteFloat(ch->channelFade.fadeEndVolume); ++ saveGame->WriteFloat( ch->lastV[m] ); ++ saveGame->WriteInt( ch->channelFade.fadeStart44kHz ); ++ saveGame->WriteInt( ch->channelFade.fadeEnd44kHz ); ++ saveGame->WriteFloat( ch->channelFade.fadeStartVolume ); ++ saveGame->WriteFloat( ch->channelFade.fadeEndVolume ); + } + + /* +@@ -1414,8 +1230,7 @@ void idSoundWorldLocal::WriteToSaveGameSoundChannel(id + idSoundWorldLocal::ReadFromSaveGame + =================== + */ +-void idSoundWorldLocal::ReadFromSaveGame(idFile *savefile) +-{ ++void idSoundWorldLocal::ReadFromSaveGame( idFile *savefile ) { + int i, num, handle, listenerId, gameTime, channel; + int savedSoundTime, currentSoundTime, soundTimeOffset; + idSoundEmitterLocal *def; +@@ -1425,12 +1240,12 @@ void idSoundWorldLocal::ReadFromSaveGame(idFile *savef + + ClearAllSoundEmitters(); + +- savefile->ReadVec3(origin); +- savefile->ReadMat3(axis); +- savefile->ReadInt(listenerId); +- savefile->ReadInt(gameTime); +- savefile->ReadInt(game44kHz); +- savefile->ReadInt(savedSoundTime); ++ savefile->ReadVec3( origin ); ++ savefile->ReadMat3( axis ); ++ savefile->ReadInt( listenerId ); ++ savefile->ReadInt( gameTime ); ++ savefile->ReadInt( game44kHz ); ++ savefile->ReadInt( savedSoundTime ); + + // we will adjust the sound starting times from those saved with the demo + currentSoundTime = soundSystemLocal.GetCurrent44kHzTime(); +@@ -1440,78 +1255,72 @@ void idSoundWorldLocal::ReadFromSaveGame(idFile *savef + pause44kHz = currentSoundTime; + + // place listener +- PlaceListener(origin, axis, listenerId, gameTime, "Undefined"); ++ PlaceListener( origin, axis, listenerId, gameTime, "Undefined" ); + + // make sure there are enough + // slots to read the saveGame in. We don't shrink the list + // if there are extras. +- savefile->ReadInt(num); ++ savefile->ReadInt( num ); + +- while (emitters.Num() < num) { ++ while( emitters.Num() < num ) { + def = new idSoundEmitterLocal; +- def->index = emitters.Append(def); ++ def->index = emitters.Append( def ); + def->soundWorld = this; + } + + // read in the state +- for (i = 1; i < num; i++) { ++ for ( i = 1; i < num; i++ ) { + +- savefile->ReadInt(handle); +- +- if (handle < 0) { ++ savefile->ReadInt( handle ); ++ if ( handle < 0 ) { + continue; + } +- +- if (handle != i) { +- common->Error("idSoundWorldLocal::ReadFromSaveGame: index mismatch"); ++ if ( handle != i ) { ++ common->Error( "idSoundWorldLocal::ReadFromSaveGame: index mismatch" ); + } +- + def = emitters[i]; + + def->removeStatus = REMOVE_STATUS_ALIVE; + def->playing = true; // may be reset by the first UpdateListener + +- savefile->ReadVec3(def->origin); +- savefile->ReadInt(def->listenerId); +- ReadFromSaveGameSoundShaderParams(savefile, &def->parms); +- savefile->ReadFloat(def->amplitude); +- savefile->ReadInt(def->ampTime); +- ++ savefile->ReadVec3( def->origin ); ++ savefile->ReadInt( def->listenerId ); ++ ReadFromSaveGameSoundShaderParams( savefile, &def->parms ); ++ savefile->ReadFloat( def->amplitude ); ++ savefile->ReadInt( def->ampTime ); + for (int k = 0; k < SOUND_MAX_CHANNELS; k++) +- ReadFromSaveGameSoundChannel(savefile, &def->channels[k]); ++ ReadFromSaveGameSoundChannel( savefile, &def->channels[k] ); ++ savefile->ReadFloat( def->distance ); ++ savefile->ReadBool( def->hasShakes ); ++ savefile->ReadInt( def->lastValidPortalArea ); ++ savefile->ReadFloat( def->maxDistance ); ++ savefile->ReadBool( def->playing ); ++ savefile->ReadFloat( def->realDistance ); ++ savefile->ReadInt( (int&)def->removeStatus ); ++ savefile->ReadVec3( def->spatializedOrigin ); + +- savefile->ReadFloat(def->distance); +- savefile->ReadBool(def->hasShakes); +- savefile->ReadInt(def->lastValidPortalArea); +- savefile->ReadFloat(def->maxDistance); +- savefile->ReadBool(def->playing); +- savefile->ReadFloat(def->realDistance); +- savefile->ReadInt((int &)def->removeStatus); +- savefile->ReadVec3(def->spatializedOrigin); +- + // read the individual channels +- savefile->ReadInt(channel); ++ savefile->ReadInt( channel ); + +- while (channel >= 0) { +- if (channel > SOUND_MAX_CHANNELS) { +- common->Error("idSoundWorldLocal::ReadFromSaveGame: channel > SOUND_MAX_CHANNELS"); ++ while ( channel >= 0 ) { ++ if ( channel > SOUND_MAX_CHANNELS ) { ++ common->Error( "idSoundWorldLocal::ReadFromSaveGame: channel > SOUND_MAX_CHANNELS" ); + } + + idSoundChannel *chan = &def->channels[channel]; + +- if (!chan->decoder) { ++ if ( !chan->decoder ) { + // The pointer in the save file is not valid, so we grab a new one + chan->decoder = idSampleDecoder::Alloc(); + } + +- savefile->ReadString(soundShader); +- chan->soundShader = declManager->FindSound(soundShader); ++ savefile->ReadString( soundShader ); ++ chan->soundShader = declManager->FindSound( soundShader ); + +- savefile->ReadString(soundShader); +- ++ savefile->ReadString( soundShader ); + // load savegames with s_noSound 1 +- if (soundSystemLocal.soundCache) { +- chan->leadinSample = soundSystemLocal.soundCache->FindSound(soundShader, false); ++ if ( soundSystemLocal.soundCache ) { ++ chan->leadinSample = soundSystemLocal.soundCache->FindSound( soundShader, false ); + } else { + chan->leadinSample = NULL; + } +@@ -1524,20 +1333,20 @@ void idSoundWorldLocal::ReadFromSaveGame(idFile *savef + chan->openalStreamingOffset = currentSoundTime - chan->trigger44kHzTime; + + // adjust the hardware fade time +- if (chan->channelFade.fadeStart44kHz != 0) { ++ if ( chan->channelFade.fadeStart44kHz != 0 ) { + chan->channelFade.fadeStart44kHz += soundTimeOffset; + chan->channelFade.fadeEnd44kHz += soundTimeOffset; + } + + // next command +- savefile->ReadInt(channel); ++ savefile->ReadInt( channel ); + } + } + +- if (session->GetSaveGameVersion() >= 17) { +- savefile->Read(&slowmoActive, sizeof(slowmoActive)); +- savefile->Read(&slowmoSpeed, sizeof(slowmoSpeed)); +- savefile->Read(&enviroSuitActive, sizeof(enviroSuitActive)); ++ if ( session->GetSaveGameVersion() >= 17 ) { ++ savefile->Read( &slowmoActive, sizeof( slowmoActive ) ); ++ savefile->Read( &slowmoSpeed, sizeof( slowmoSpeed ) ); ++ savefile->Read( &enviroSuitActive, sizeof( enviroSuitActive ) ); + } else { + slowmoActive = false; + slowmoSpeed = 0; +@@ -1550,8 +1359,7 @@ void idSoundWorldLocal::ReadFromSaveGame(idFile *savef + idSoundWorldLocal::ReadFromSaveGameSoundShaderParams + =================== + */ +-void idSoundWorldLocal::ReadFromSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params) +-{ ++void idSoundWorldLocal::ReadFromSaveGameSoundShaderParams( idFile *saveGame, soundShaderParms_t *params ) { + saveGame->ReadFloat(params->minDistance); + saveGame->ReadFloat(params->maxDistance); + saveGame->ReadFloat(params->volume); +@@ -1565,34 +1373,31 @@ void idSoundWorldLocal::ReadFromSaveGameSoundShaderPar + idSoundWorldLocal::ReadFromSaveGameSoundChannel + =================== + */ +-void idSoundWorldLocal::ReadFromSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch) +-{ +- saveGame->ReadBool(ch->triggerState); ++void idSoundWorldLocal::ReadFromSaveGameSoundChannel( idFile *saveGame, idSoundChannel *ch ) { ++ saveGame->ReadBool( ch->triggerState ); + char tmp; + int i; +- saveGame->ReadChar(tmp); +- saveGame->ReadChar(tmp); +- saveGame->ReadChar(tmp); +- saveGame->ReadInt(ch->trigger44kHzTime); +- saveGame->ReadInt(ch->triggerGame44kHzTime); +- ReadFromSaveGameSoundShaderParams(saveGame, &ch->parms); +- saveGame->ReadInt(/* (int &)ch->leadinSample */ i); ++ saveGame->ReadChar( tmp ); ++ saveGame->ReadChar( tmp ); ++ saveGame->ReadChar( tmp ); ++ saveGame->ReadInt( ch->trigger44kHzTime ); ++ saveGame->ReadInt( ch->triggerGame44kHzTime ); ++ ReadFromSaveGameSoundShaderParams( saveGame, &ch->parms ); ++ saveGame->ReadInt( i ); + ch->leadinSample = NULL; +- saveGame->ReadInt(ch->triggerChannel); +- saveGame->ReadInt(/* (int &)ch->soundShader */ i); ++ saveGame->ReadInt( ch->triggerChannel ); ++ saveGame->ReadInt( i ); + ch->soundShader = NULL; +- saveGame->ReadInt(/* (int &)ch->decoder */ i); ++ saveGame->ReadInt( i ); + ch->decoder = NULL; +- saveGame->ReadFloat(ch->diversity); +- saveGame->ReadFloat(ch->lastVolume); +- ++ saveGame->ReadFloat(ch->diversity ); ++ saveGame->ReadFloat(ch->lastVolume ); + for (int m = 0; m < 6; m++) +- saveGame->ReadFloat(ch->lastV[m]); +- +- saveGame->ReadInt(ch->channelFade.fadeStart44kHz); +- saveGame->ReadInt(ch->channelFade.fadeEnd44kHz); +- saveGame->ReadFloat(ch->channelFade.fadeStartVolume); +- saveGame->ReadFloat(ch->channelFade.fadeEndVolume); ++ saveGame->ReadFloat( ch->lastV[m] ); ++ saveGame->ReadInt( ch->channelFade.fadeStart44kHz ); ++ saveGame->ReadInt( ch->channelFade.fadeEnd44kHz ); ++ saveGame->ReadFloat( ch->channelFade.fadeStartVolume ); ++ saveGame->ReadFloat( ch->channelFade.fadeEndVolume ); + } + + /* +@@ -1615,7 +1420,6 @@ idSoundEmitter *idSoundWorldLocal::EmitterForIndex(int + if (index >= emitters.Num()) { + common->Error("idSoundWorldLocal::EmitterForIndex: %i > %i", index, emitters.Num()); + } +- + return emitters[index]; + } + +@@ -1626,12 +1430,11 @@ idSoundWorldLocal::StopAllSounds + this is called from the main thread + =============== + */ +-void idSoundWorldLocal::StopAllSounds() +-{ ++void idSoundWorldLocal::StopAllSounds() { + +- for (int i = 0; i < emitters.Num(); i++) { +- idSoundEmitterLocal *def = emitters[i]; +- def->StopSound(SCHANNEL_ANY); ++ for ( int i = 0; i < emitters.Num(); i++ ) { ++ idSoundEmitterLocal * def = emitters[i]; ++ def->StopSound( SCHANNEL_ANY ); + } + } + +@@ -1640,10 +1443,9 @@ void idSoundWorldLocal::StopAllSounds() + idSoundWorldLocal::Pause + =============== + */ +-void idSoundWorldLocal::Pause(void) +-{ +- if (pause44kHz >= 0) { +- common->Warning("idSoundWorldLocal::Pause: already paused"); ++void idSoundWorldLocal::Pause( void ) { ++ if ( pause44kHz >= 0 ) { ++ common->Warning( "idSoundWorldLocal::Pause: already paused" ); + return; + } + +@@ -1655,17 +1457,16 @@ void idSoundWorldLocal::Pause(void) + idSoundWorldLocal::UnPause + =============== + */ +-void idSoundWorldLocal::UnPause(void) +-{ ++void idSoundWorldLocal::UnPause( void ) { + int offset44kHz; + +- if (pause44kHz < 0) { +- common->Warning("idSoundWorldLocal::UnPause: not paused"); ++ if ( pause44kHz < 0 ) { ++ common->Warning( "idSoundWorldLocal::UnPause: not paused" ); + return; + } + + offset44kHz = soundSystemLocal.GetCurrent44kHzTime() - pause44kHz; +- OffsetSoundTime(offset44kHz); ++ OffsetSoundTime( offset44kHz ); + + pause44kHz = -1; + } +@@ -1675,9 +1476,8 @@ void idSoundWorldLocal::UnPause(void) + idSoundWorldLocal::IsPaused + =============== + */ +-bool idSoundWorldLocal::IsPaused(void) +-{ +- return (pause44kHz >= 0); ++bool idSoundWorldLocal::IsPaused( void ) { ++ return ( pause44kHz >= 0 ); + } + + /* +@@ -1689,36 +1489,34 @@ start a music track + this is called from the main thread + =============== + */ +-void idSoundWorldLocal::PlayShaderDirectly(const char *shaderName, int channel) +-{ ++void idSoundWorldLocal::PlayShaderDirectly( const char *shaderName, int channel ) { + +- if (localSound && channel == -1) { +- localSound->StopSound(SCHANNEL_ANY); +- } else if (localSound) { +- localSound->StopSound(channel); ++ if ( localSound && channel == -1 ) { ++ localSound->StopSound( SCHANNEL_ANY ); ++ } else if ( localSound ) { ++ localSound->StopSound( channel ); + } + +- if (!shaderName || !shaderName[0]) { ++ if ( !shaderName || !shaderName[0] ) { + return; + } + +- const idSoundShader *shader = declManager->FindSound(shaderName); +- +- if (!shader) { ++ const idSoundShader *shader = declManager->FindSound( shaderName ); ++ if ( !shader ) { + return; + } + +- if (!localSound) { ++ if ( !localSound ) { + localSound = AllocLocalSoundEmitter(); + } + + static idRandom rnd; + float diversity = rnd.RandomFloat(); + +- localSound->StartSound(shader, (channel == -1) ? SCHANNEL_ONE : channel , diversity, SSF_GLOBAL); ++ localSound->StartSound( shader, ( channel == -1 ) ? SCHANNEL_ONE : channel , diversity, SSF_GLOBAL ); + + // in case we are at the console without a game doing updates, force an update +- ForegroundUpdate(soundSystemLocal.GetCurrent44kHzTime()); ++ ForegroundUpdate( soundSystemLocal.GetCurrent44kHzTime() ); + } + + /* +@@ -1728,9 +1526,8 @@ idSoundWorldLocal::CalcEars + Determine the volumes from each speaker for a given sound emitter + =============== + */ +-void idSoundWorldLocal::CalcEars(int numSpeakers, idVec3 spatializedOrigin, idVec3 listenerPos, +- idMat3 listenerAxis, float ears[6], float spatialize) +-{ ++void idSoundWorldLocal::CalcEars( int numSpeakers, idVec3 spatializedOrigin, idVec3 listenerPos, ++ idMat3 listenerAxis, float ears[6], float spatialize ) { + idVec3 svec = spatializedOrigin - listenerPos; + idVec3 ovec; + +@@ -1740,26 +1537,23 @@ void idSoundWorldLocal::CalcEars(int numSpeakers, idVe + + ovec.Normalize(); + +- if (numSpeakers == 6) { ++ if ( numSpeakers == 6 ) { + static idVec3 speakerVector[6] = { +- idVec3(0.707f, 0.707f, 0.0f), // front left +- idVec3(0.707f, -0.707f, 0.0f), // front right +- idVec3(0.707f, 0.0f, 0.0f), // front center +- idVec3(0.0f, 0.0f, 0.0f), // sub +- idVec3(-0.707f, 0.707f, 0.0f), // rear left +- idVec3(-0.707f, -0.707f, 0.0f) // rear right ++ idVec3( 0.707f, 0.707f, 0.0f ), // front left ++ idVec3( 0.707f, -0.707f, 0.0f ), // front right ++ idVec3( 0.707f, 0.0f, 0.0f ), // front center ++ idVec3( 0.0f, 0.0f, 0.0f ), // sub ++ idVec3( -0.707f, 0.707f, 0.0f ), // rear left ++ idVec3( -0.707f, -0.707f, 0.0f ) // rear right + }; +- +- for (int i = 0 ; i < 6 ; i++) { +- if (i == 3) { ++ for ( int i = 0 ; i < 6 ; i++ ) { ++ if ( i == 3 ) { + ears[i] = idSoundSystemLocal::s_subFraction.GetFloat(); // subwoofer + continue; + } +- + float dot = ovec * speakerVector[i]; +- ears[i] = (idSoundSystemLocal::s_dotbias6.GetFloat() + dot) / (1.0f + idSoundSystemLocal::s_dotbias6.GetFloat()); +- +- if (ears[i] < idSoundSystemLocal::s_minVolume6.GetFloat()) { ++ ears[i] = (idSoundSystemLocal::s_dotbias6.GetFloat() + dot) / ( 1.0f + idSoundSystemLocal::s_dotbias6.GetFloat() ); ++ if ( ears[i] < idSoundSystemLocal::s_minVolume6.GetFloat() ) { + ears[i] = idSoundSystemLocal::s_minVolume6.GetFloat(); + } + } +@@ -1769,23 +1563,22 @@ void idSoundWorldLocal::CalcEars(int numSpeakers, idVe + + // when we are inside the minDistance, start reducing the amount of spatialization + // so NPC voices right in front of us aren't quieter that off to the side +- dotBias += (idSoundSystemLocal::s_spatializationDecay.GetFloat() - dotBias) * (1.0f - spatialize); ++ dotBias += ( idSoundSystemLocal::s_spatializationDecay.GetFloat() - dotBias ) * ( 1.0f - spatialize ); + +- ears[0] = (idSoundSystemLocal::s_dotbias2.GetFloat() + dot) / (1.0f + dotBias); +- ears[1] = (idSoundSystemLocal::s_dotbias2.GetFloat() - dot) / (1.0f + dotBias); ++ ears[0] = (idSoundSystemLocal::s_dotbias2.GetFloat() + dot) / ( 1.0f + dotBias ); ++ ears[1] = (idSoundSystemLocal::s_dotbias2.GetFloat() - dot) / ( 1.0f + dotBias ); + +- if (ears[0] < idSoundSystemLocal::s_minVolume2.GetFloat()) { ++ if ( ears[0] < idSoundSystemLocal::s_minVolume2.GetFloat() ) { + ears[0] = idSoundSystemLocal::s_minVolume2.GetFloat(); + } +- +- if (ears[1] < idSoundSystemLocal::s_minVolume2.GetFloat()) { ++ if ( ears[1] < idSoundSystemLocal::s_minVolume2.GetFloat() ) { + ears[1] = idSoundSystemLocal::s_minVolume2.GetFloat(); + } + + ears[2] = +- ears[3] = +- ears[4] = +- ears[5] = 0.0f; ++ ears[3] = ++ ears[4] = ++ ears[5] = 0.0f; + } + } + +@@ -1800,9 +1593,8 @@ Mixes MIXBUFFER_SAMPLES samples starting at current44k + finalMixBuffer + =============== + */ +-void idSoundWorldLocal::AddChannelContribution(idSoundEmitterLocal *sound, idSoundChannel *chan, +- int current44kHz, int numSpeakers, float *finalMixBuffer) +-{ ++void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSoundChannel *chan, ++ int current44kHz, int numSpeakers, float *finalMixBuffer ) { + int j; + float volume; + +@@ -1812,17 +1604,16 @@ void idSoundWorldLocal::AddChannelContribution(idSound + soundShaderParms_t *parms = &chan->parms; + + // assume we have a sound triggered on this channel +- assert(chan->triggerState); ++ assert( chan->triggerState ); + + // fetch the actual wave file and see if it's valid + idSoundSample *sample = chan->leadinSample; +- +- if (sample == NULL) { ++ if ( sample == NULL ) { + return; + } + + // if you don't want to hear all the beeps from missing sounds +- if (sample->defaultSound && !idSoundSystemLocal::s_playDefaultSound.GetBool()) { ++ if ( sample->defaultSound && !idSoundSystemLocal::s_playDefaultSound.GetBool() ) { + return; + } + +@@ -1830,7 +1621,7 @@ void idSoundWorldLocal::AddChannelContribution(idSound + const idSoundShader *shader = chan->soundShader; + + // this might happen if the foreground thread just deleted the sound emitter +- if (!shader) { ++ if ( !shader ) { + return; + } + +@@ -1838,23 +1629,23 @@ void idSoundWorldLocal::AddChannelContribution(idSound + float mind = parms->minDistance; + + int mask = shader->speakerMask; +- bool omni = (parms->soundShaderFlags & SSF_OMNIDIRECTIONAL) != 0; +- bool looping = (parms->soundShaderFlags & SSF_LOOPING) != 0; +- bool global = (parms->soundShaderFlags & SSF_GLOBAL) != 0; +- bool noOcclusion = (parms->soundShaderFlags & SSF_NO_OCCLUSION) || !idSoundSystemLocal::s_useOcclusion.GetBool(); ++ bool omni = ( parms->soundShaderFlags & SSF_OMNIDIRECTIONAL) != 0; ++ bool looping = ( parms->soundShaderFlags & SSF_LOOPING ) != 0; ++ bool global = ( parms->soundShaderFlags & SSF_GLOBAL ) != 0; ++ bool noOcclusion = ( parms->soundShaderFlags & SSF_NO_OCCLUSION ) || !idSoundSystemLocal::s_useOcclusion.GetBool(); + + // speed goes from 1 to 0.2 +- if (idSoundSystemLocal::s_slowAttenuate.GetBool() && slowmoActive && !chan->disallowSlow) { ++ if ( idSoundSystemLocal::s_slowAttenuate.GetBool() && slowmoActive && !chan->disallowSlow ) { + maxd *= slowmoSpeed; + } + + // stereo samples are always omni +- if (sample->objectInfo.nChannels == 2) { ++ if ( sample->objectInfo.nChannels == 2 ) { + omni = true; + } + + // if the sound is playing from the current listener, it will not be spatialized at all +- if (sound->listenerId == listenerPrivateId) { ++ if ( sound->listenerId == listenerPrivateId ) { + global = true; + } + +@@ -1868,22 +1659,22 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // this isn't exactly correct, because the modified volume will get applied to + // some initial chunk of the loop as well, because the volume is scaled for the + // entire mix buffer +- if (shader->leadinVolume && current44kHz - chan->trigger44kHzTime < sample->LengthIn44kHzSamples()) { +- volume = soundSystemLocal.dB2Scale(shader->leadinVolume); ++ if ( shader->leadinVolume && current44kHz - chan->trigger44kHzTime < sample->LengthIn44kHzSamples() ) { ++ volume = soundSystemLocal.dB2Scale( shader->leadinVolume ); + } else { +- volume = soundSystemLocal.dB2Scale(parms->volume); ++ volume = soundSystemLocal.dB2Scale( parms->volume ); + } + + // global volume scale +- volume *= soundSystemLocal.dB2Scale(idSoundSystemLocal::s_volume.GetFloat()); ++ volume *= soundSystemLocal.dB2Scale( idSoundSystemLocal::s_volume.GetFloat() ); + + + // volume fading +- float fadeDb = chan->channelFade.FadeDbAt44kHz(current44kHz); +- volume *= soundSystemLocal.dB2Scale(fadeDb); ++ float fadeDb = chan->channelFade.FadeDbAt44kHz( current44kHz ); ++ volume *= soundSystemLocal.dB2Scale( fadeDb ); + +- fadeDb = soundClassFade[parms->soundClass].FadeDbAt44kHz(current44kHz); +- volume *= soundSystemLocal.dB2Scale(fadeDb); ++ fadeDb = soundClassFade[parms->soundClass].FadeDbAt44kHz( current44kHz ); ++ volume *= soundSystemLocal.dB2Scale( fadeDb ); + + + // +@@ -1892,11 +1683,10 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // + float spatialize = 1; + idVec3 spatializedOriginInMeters; +- +- if (!global) { ++ if ( !global ) { + float dlen; + +- if (noOcclusion) { ++ if ( noOcclusion ) { + // use the real origin and distance + spatializedOriginInMeters = sound->origin * DOOM_TO_METERS; + dlen = sound->realDistance; +@@ -1907,17 +1697,15 @@ void idSoundWorldLocal::AddChannelContribution(idSound + } + + // reduce volume based on distance +- if (dlen >= maxd) { ++ if ( dlen >= maxd ) { + volume = 0.0f; +- } else if (dlen > mind) { +- float frac = idMath::ClampFloat(0.0f, 1.0f, 1.0f - ((dlen - mind) / (maxd - mind))); +- +- if (idSoundSystemLocal::s_quadraticFalloff.GetBool()) { ++ } else if ( dlen > mind ) { ++ float frac = idMath::ClampFloat( 0.0f, 1.0f, 1.0f - ((dlen - mind) / (maxd - mind))); ++ if ( idSoundSystemLocal::s_quadraticFalloff.GetBool() ) { + frac *= frac; + } +- + volume *= frac; +- } else if (mind > 0.0f) { ++ } else if ( mind > 0.0f ) { + // we tweak the spatialization bias when you are inside the minDistance + spatialize = dlen / mind; + } +@@ -1927,14 +1715,13 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // if it is a private sound, set the volume to zero + // unless we match the listenerId + // +- if (parms->soundShaderFlags & SSF_PRIVATE_SOUND) { +- if (sound->listenerId != listenerPrivateId) { ++ if ( parms->soundShaderFlags & SSF_PRIVATE_SOUND ) { ++ if ( sound->listenerId != listenerPrivateId ) { + volume = 0; + } + } +- +- if (parms->soundShaderFlags & SSF_ANTI_PRIVATE_SOUND) { +- if (sound->listenerId == listenerPrivateId) { ++ if ( parms->soundShaderFlags & SSF_ANTI_PRIVATE_SOUND ) { ++ if ( sound->listenerId == listenerPrivateId ) { + volume = 0; + } + } +@@ -1942,10 +1729,9 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // + // do we have anything to add? + // +- if (volume < SND_EPSILON && chan->lastVolume < SND_EPSILON) { ++ if ( volume < SND_EPSILON && chan->lastVolume < SND_EPSILON ) { + return; + } +- + chan->lastVolume = volume; + + // +@@ -1953,151 +1739,129 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // + int offset = current44kHz - chan->trigger44kHzTime; + float inputSamples[MIXBUFFER_SAMPLES*2+16]; +- float *alignedInputSamples = (float *)((((intptr_t)inputSamples) + 15) & ~15); ++ float *alignedInputSamples = (float *) ( ( ( (intptr_t)inputSamples ) + 15 ) & ~15 ); + + // + // allocate and initialize hardware source + // +-#ifdef _OPENAL +- if (idSoundSystemLocal::useOpenAL && sound->removeStatus < REMOVE_STATUS_SAMPLEFINISHED) { +- if (!alIsSource(chan->openalSource)) { +- chan->openalSource = soundSystemLocal.AllocOpenALSource(chan, !chan->leadinSample->hardwareBuffer || !chan->soundShader->entries[0]->hardwareBuffer || looping, chan->leadinSample->objectInfo.nChannels == 2); ++ if ( sound->removeStatus < REMOVE_STATUS_SAMPLEFINISHED ) { ++ if ( !alIsSource( chan->openalSource ) ) { ++ chan->openalSource = soundSystemLocal.AllocOpenALSource( chan, !chan->leadinSample->hardwareBuffer || !chan->soundShader->entries[0]->hardwareBuffer || looping, chan->leadinSample->objectInfo.nChannels == 2 ); + } + +- if (alIsSource(chan->openalSource)) { ++ if ( alIsSource( chan->openalSource ) ) { + + // stop source if needed.. +- if (chan->triggered) { +- alSourceStop(chan->openalSource); ++ if ( chan->triggered ) { ++ alSourceStop( chan->openalSource ); + } + + // update source parameters +- if (global || omni) { +- alSourcei(chan->openalSource, AL_SOURCE_RELATIVE, AL_TRUE); +- alSource3f(chan->openalSource, AL_POSITION, 0.0f, 0.0f, 0.0f); +- alSourcef(chan->openalSource, AL_GAIN, (volume) < (1.0f) ? (volume) : (1.0f)); ++ if ( global || omni ) { ++ alSourcei( chan->openalSource, AL_SOURCE_RELATIVE, AL_TRUE); ++ alSource3f( chan->openalSource, AL_POSITION, 0.0f, 0.0f, 0.0f ); ++ alSourcef( chan->openalSource, AL_GAIN, ( volume ) < ( 1.0f ) ? ( volume ) : ( 1.0f ) ); + } else { +- alSourcei(chan->openalSource, AL_SOURCE_RELATIVE, AL_FALSE); +- alSource3f(chan->openalSource, AL_POSITION, -spatializedOriginInMeters.y, spatializedOriginInMeters.z, -spatializedOriginInMeters.x); +- alSourcef(chan->openalSource, AL_GAIN, (volume) < (1.0f) ? (volume) : (1.0f)); ++ alSourcei( chan->openalSource, AL_SOURCE_RELATIVE, AL_FALSE); ++ alSource3f( chan->openalSource, AL_POSITION, -spatializedOriginInMeters.y, spatializedOriginInMeters.z, -spatializedOriginInMeters.x ); ++ alSourcef( chan->openalSource, AL_GAIN, ( volume ) < ( 1.0f ) ? ( volume ) : ( 1.0f ) ); + } +- +- alSourcei(chan->openalSource, AL_LOOPING, (looping && chan->soundShader->entries[0]->hardwareBuffer) ? AL_TRUE : AL_FALSE); +-#if defined(_OPENAL_SOFT) +- alSourcef(chan->openalSource, AL_REFERENCE_DISTANCE, mind); +- alSourcef(chan->openalSource, AL_MAX_DISTANCE, maxd); ++ alSourcei( chan->openalSource, AL_LOOPING, ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ? AL_TRUE : AL_FALSE ); ++// TODO is this correct? (was: "!defined(MACOS_X)") ++#if ID_OPENAL_EAX ++ alSourcef( chan->openalSource, AL_REFERENCE_DISTANCE, mind ); ++ alSourcef( chan->openalSource, AL_MAX_DISTANCE, maxd ); + #endif +- alSourcef(chan->openalSource, AL_PITCH, (slowmoActive && !chan->disallowSlow) ? (slowmoSpeed) : (1.0f)); +-#if ID_OPENAL +-#ifdef _OPENAL_EFX +- if (idSoundSystemLocal::useEAXReverb) { +- if (enviroSuitActive) { +- alSourcei(chan->openalSource, AL_DIRECT_FILTER, listenerFilters[0]); +- alSource3i(chan->openalSource, AL_AUXILIARY_SEND_FILTER, listenerSlot, 0, listenerFilters[1]); +- } else { +- alSourcei(chan->openalSource, AL_DIRECT_FILTER, AL_FILTER_NULL); +- alSource3i(chan->openalSource, AL_AUXILIARY_SEND_FILTER, listenerSlot, 0, AL_FILTER_NULL); +- } ++ alSourcef( chan->openalSource, AL_PITCH, ( slowmoActive && !chan->disallowSlow ) ? ( slowmoSpeed ) : ( 1.0f ) ); ++#if ID_OPENAL_EAX ++ long lOcclusion = ( enviroSuitActive ? -1150 : 0); ++ if ( soundSystemLocal.alEAXSet ) { ++ soundSystemLocal.alEAXSet( &EAXPROPERTYID_EAX_Source, EAXSOURCE_OCCLUSION, chan->openalSource, &lOcclusion, sizeof(lOcclusion) ); + } +-#else +- long lOcclusion = (enviroSuitActive ? -1150 : 0); +- +- if (soundSystemLocal.alEAXSet) { +- soundSystemLocal.alEAXSet(&EAXPROPERTYID_EAX_Source, EAXSOURCE_OCCLUSION, chan->openalSource, &lOcclusion, sizeof(lOcclusion)); +- } + #endif +-#endif +- +- if ((!looping && chan->leadinSample->hardwareBuffer) || (looping && chan->soundShader->entries[0]->hardwareBuffer)) { ++ if ( ( !looping && chan->leadinSample->hardwareBuffer ) || ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ) { + // handle uncompressed (non streaming) single shot and looping sounds +- if (chan->triggered) { +- alSourcei(chan->openalSource, AL_BUFFER, looping ? chan->soundShader->entries[0]->openalBuffer : chan->leadinSample->openalBuffer); ++ if ( chan->triggered ) { ++ alSourcei( chan->openalSource, AL_BUFFER, looping ? chan->soundShader->entries[0]->openalBuffer : chan->leadinSample->openalBuffer ); + } + } else { + ALint finishedbuffers; + ALuint buffers[3]; + + // handle streaming sounds (decode on the fly) both single shot AND looping +- if (chan->triggered) { +- alSourcei(chan->openalSource, AL_BUFFER, 0); +- alDeleteBuffers(3, &chan->lastopenalStreamingBuffer[0]); ++ if ( chan->triggered ) { ++ alSourcei( chan->openalSource, AL_BUFFER, 0 ); ++ alDeleteBuffers( 3, &chan->lastopenalStreamingBuffer[0] ); + chan->lastopenalStreamingBuffer[0] = chan->openalStreamingBuffer[0]; + chan->lastopenalStreamingBuffer[1] = chan->openalStreamingBuffer[1]; + chan->lastopenalStreamingBuffer[2] = chan->openalStreamingBuffer[2]; +- alGenBuffers(3, &chan->openalStreamingBuffer[0]); +- +-#if !defined(_OPENAL_EFX) +- if (soundSystemLocal.alEAXSetBufferMode) { +- soundSystemLocal.alEAXSetBufferMode(3, &chan->openalStreamingBuffer[0], alGetEnumValue(ID_ALCHAR "AL_STORAGE_ACCESSIBLE")); ++ alGenBuffers( 3, &chan->openalStreamingBuffer[0] ); ++#if ID_OPENAL_EAX ++ if ( soundSystemLocal.alEAXSetBufferMode ) { ++ soundSystemLocal.alEAXSetBufferMode( 3, &chan->openalStreamingBuffer[0], alGetEnumValue( ID_ALCHAR "AL_STORAGE_ACCESSIBLE" ) ); + } + #endif +- + buffers[0] = chan->openalStreamingBuffer[0]; + buffers[1] = chan->openalStreamingBuffer[1]; + buffers[2] = chan->openalStreamingBuffer[2]; + finishedbuffers = 3; + } else { +- alGetSourcei(chan->openalSource, AL_BUFFERS_PROCESSED, &finishedbuffers); +- alSourceUnqueueBuffers(chan->openalSource, finishedbuffers, &buffers[0]); +- +- if (finishedbuffers == 3) { ++ alGetSourcei( chan->openalSource, AL_BUFFERS_PROCESSED, &finishedbuffers ); ++ alSourceUnqueueBuffers( chan->openalSource, finishedbuffers, &buffers[0] ); ++ if ( finishedbuffers == 3 ) { + chan->triggered = true; + } + } + +- for (j = 0; j < finishedbuffers; j++) { +- chan->GatherChannelSamples(chan->openalStreamingOffset * sample->objectInfo.nChannels, MIXBUFFER_SAMPLES * sample->objectInfo.nChannels, alignedInputSamples); +- +- for (int i = 0; i < (MIXBUFFER_SAMPLES * sample->objectInfo.nChannels); i++) { +- if (alignedInputSamples[i] < -32768.0f) ++ for ( j = 0; j < finishedbuffers; j++ ) { ++ chan->GatherChannelSamples( chan->openalStreamingOffset * sample->objectInfo.nChannels, MIXBUFFER_SAMPLES * sample->objectInfo.nChannels, alignedInputSamples ); ++ for ( int i = 0; i < ( MIXBUFFER_SAMPLES * sample->objectInfo.nChannels ); i++ ) { ++ if ( alignedInputSamples[i] < -32768.0f ) + ((short *)alignedInputSamples)[i] = -32768; +- else if (alignedInputSamples[i] > 32767.0f) ++ else if ( alignedInputSamples[i] > 32767.0f ) + ((short *)alignedInputSamples)[i] = 32767; + else +- ((short *)alignedInputSamples)[i] = idMath::FtoiFast(alignedInputSamples[i]); ++ ((short *)alignedInputSamples)[i] = idMath::FtoiFast( alignedInputSamples[i] ); + } +- +- alBufferData(buffers[j], chan->leadinSample->objectInfo.nChannels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, alignedInputSamples, MIXBUFFER_SAMPLES * sample->objectInfo.nChannels * sizeof(short), 44100); ++ alBufferData( buffers[j], chan->leadinSample->objectInfo.nChannels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, alignedInputSamples, MIXBUFFER_SAMPLES * sample->objectInfo.nChannels * sizeof( short ), 44100 ); + chan->openalStreamingOffset += MIXBUFFER_SAMPLES; + } + +- if (finishedbuffers) { +- alSourceQueueBuffers(chan->openalSource, finishedbuffers, &buffers[0]); ++ if ( finishedbuffers ) { ++ alSourceQueueBuffers( chan->openalSource, finishedbuffers, &buffers[0] ); + } + } + + // (re)start if needed.. +- if (chan->triggered) { +- alSourcePlay(chan->openalSource); ++ if ( chan->triggered ) { ++ alSourcePlay( chan->openalSource ); + chan->triggered = false; + } + } +- } else +-#endif +- { ++ } else { + +- if (slowmoActive && !chan->disallowSlow) { +- idSlowChannel slow = sound->GetSlowChannel(chan); ++ if ( slowmoActive && !chan->disallowSlow ) { ++ idSlowChannel slow = sound->GetSlowChannel( chan ); + +- slow.AttachSoundChannel(chan); ++ slow.AttachSoundChannel( chan ); + +- if (sample->objectInfo.nChannels == 2) { +- // need to add a stereo path, but very few samples go through this +- memset(alignedInputSamples, 0, sizeof(alignedInputSamples[0]) * MIXBUFFER_SAMPLES * 2); +- } else { +- slow.GatherChannelSamples(offset, MIXBUFFER_SAMPLES, alignedInputSamples); +- } ++ if ( sample->objectInfo.nChannels == 2 ) { ++ // need to add a stereo path, but very few samples go through this ++ memset( alignedInputSamples, 0, sizeof( alignedInputSamples[0] ) * MIXBUFFER_SAMPLES * 2 ); ++ } else { ++ slow.GatherChannelSamples( offset, MIXBUFFER_SAMPLES, alignedInputSamples ); ++ } + +- sound->SetSlowChannel(chan, slow); ++ sound->SetSlowChannel( chan, slow ); + } else { +- sound->ResetSlowChannel(chan); ++ sound->ResetSlowChannel( chan ); + + // if we are getting a stereo sample adjust accordingly +- if (sample->objectInfo.nChannels == 2) { ++ if ( sample->objectInfo.nChannels == 2 ) { + // we should probably check to make sure any looping is also to a stereo sample... +- chan->GatherChannelSamples(offset*2, MIXBUFFER_SAMPLES*2, alignedInputSamples); ++ chan->GatherChannelSamples( offset*2, MIXBUFFER_SAMPLES*2, alignedInputSamples ); + } else { +- chan->GatherChannelSamples(offset, MIXBUFFER_SAMPLES, alignedInputSamples); ++ chan->GatherChannelSamples( offset, MIXBUFFER_SAMPLES, alignedInputSamples ); + } + } + +@@ -2105,31 +1869,28 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // work out the left / right ear values + // + float ears[6]; +- +- if (global || omni) { ++ if ( global || omni ) { + // same for all speakers +- for (int i = 0 ; i < 6 ; i++) { ++ for ( int i = 0 ; i < 6 ; i++ ) { + ears[i] = idSoundSystemLocal::s_globalFraction.GetFloat() * volume; + } +- + ears[3] = idSoundSystemLocal::s_subFraction.GetFloat() * volume; // subwoofer + + } else { +- CalcEars(numSpeakers, spatializedOriginInMeters, listenerPos, listenerAxis, ears, spatialize); ++ CalcEars( numSpeakers, spatializedOriginInMeters, listenerPos, listenerAxis, ears, spatialize ); + +- for (int i = 0 ; i < 6 ; i++) { ++ for ( int i = 0 ; i < 6 ; i++ ) { + ears[i] *= volume; + } + } + + // if the mask is 0, it really means do every channel +- if (!mask) { ++ if ( !mask ) { + mask = 255; + } +- + // cleared mask bits set the mix volume to zero +- for (int i = 0 ; i < 6 ; i++) { +- if (!(mask & (1 << i))) { ++ for ( int i = 0 ; i < 6 ; i++ ) { ++ if ( !(mask & ( 1 << i ) ) ) { + ears[i] = 0; + } + } +@@ -2137,9 +1898,9 @@ void idSoundWorldLocal::AddChannelContribution(idSound + // if sounds are generally normalized, using a mixing volume over 1.0 will + // almost always cause clipping noise. If samples aren't normalized, there + // is a good call to allow overvolumes +- if (idSoundSystemLocal::s_clipVolumes.GetBool() && !(parms->soundShaderFlags & SSF_UNCLAMPED)) { +- for (int i = 0 ; i < 6 ; i++) { +- if (ears[i] > 1.0f) { ++ if ( idSoundSystemLocal::s_clipVolumes.GetBool() && !( parms->soundShaderFlags & SSF_UNCLAMPED ) ) { ++ for ( int i = 0 ; i < 6 ; i++ ) { ++ if ( ears[i] > 1.0f ) { + ears[i] = 1.0f; + } + } +@@ -2147,33 +1908,34 @@ void idSoundWorldLocal::AddChannelContribution(idSound + + // if this is the very first mixing block, set the lastV + // to the current volume +- if (current44kHz == chan->trigger44kHzTime) { +- for (j = 0 ; j < 6 ; j++) { ++ if ( current44kHz == chan->trigger44kHzTime ) { ++ for ( j = 0 ; j < 6 ; j++ ) { + chan->lastV[j] = ears[j]; + } + } + +- if (numSpeakers == 6) { +- if (sample->objectInfo.nChannels == 1) { +- SIMDProcessor->MixSoundSixSpeakerMono(finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears); ++ if ( numSpeakers == 6 ) { ++ if ( sample->objectInfo.nChannels == 1 ) { ++ SIMDProcessor->MixSoundSixSpeakerMono( finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears ); + } else { +- SIMDProcessor->MixSoundSixSpeakerStereo(finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears); ++ SIMDProcessor->MixSoundSixSpeakerStereo( finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears ); + } + } else { +- if (sample->objectInfo.nChannels == 1) { +- SIMDProcessor->MixSoundTwoSpeakerMono(finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears); ++ if ( sample->objectInfo.nChannels == 1 ) { ++ SIMDProcessor->MixSoundTwoSpeakerMono( finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears ); + } else { +- SIMDProcessor->MixSoundTwoSpeakerStereo(finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears); ++ SIMDProcessor->MixSoundTwoSpeakerStereo( finalMixBuffer, alignedInputSamples, MIXBUFFER_SAMPLES, chan->lastV, ears ); + } + } + +- for (j = 0 ; j < 6 ; j++) { ++ for ( j = 0 ; j < 6 ; j++ ) { + chan->lastV[j] = ears[j]; + } + + } + + soundSystemLocal.soundStats.activeSounds++; ++ + } + + /* +@@ -2190,9 +1952,8 @@ idSoundWorldLocal::FindAmplitude + which would be problematic in multiplayer + =============== + */ +-float idSoundWorldLocal::FindAmplitude(idSoundEmitterLocal *sound, const int localTime, const idVec3 *listenerPosition, +- const s_channelType channel, bool shakesOnly) +-{ ++float idSoundWorldLocal::FindAmplitude( idSoundEmitterLocal *sound, const int localTime, const idVec3 *listenerPosition, ++ const s_channelType channel, bool shakesOnly ) { + int i, j; + soundShaderParms_t *parms; + float volume; +@@ -2203,11 +1964,11 @@ float idSoundWorldLocal::FindAmplitude(idSoundEmitterL + // work out the distance from the listener to the emitter + float dlen; + +- if (!sound->playing) { ++ if ( !sound->playing ) { + return 0; + } + +- if (listenerPosition) { ++ if ( listenerPosition ) { + // this doesn't do the portal spatialization + idVec3 dist = sound->origin - *listenerPosition; + dlen = dist.Length(); +@@ -2218,14 +1979,14 @@ float idSoundWorldLocal::FindAmplitude(idSoundEmitterL + + activeChannelCount = 0; + +- for (i = 0; i < SOUND_MAX_CHANNELS ; i++) { ++ for ( i = 0; i < SOUND_MAX_CHANNELS ; i++ ) { + idSoundChannel *chan = &sound->channels[ i ]; + +- if (!chan->triggerState) { ++ if ( !chan->triggerState ) { + continue; + } + +- if (channel != SCHANNEL_ANY && chan->triggerChannel != channel) { ++ if ( channel != SCHANNEL_ANY && chan->triggerChannel != channel) { + continue; + } + +@@ -2233,49 +1994,45 @@ float idSoundWorldLocal::FindAmplitude(idSoundEmitterL + + int localTriggerTimes = chan->trigger44kHzTime; + +- bool looping = (parms->soundShaderFlags & SSF_LOOPING) != 0; ++ bool looping = ( parms->soundShaderFlags & SSF_LOOPING ) != 0; + + // check for screen shakes + float shakes = parms->shakes; +- +- if (shakesOnly && shakes <= 0.0f) { ++ if ( shakesOnly && shakes <= 0.0f ) { + continue; + } + + // + // calculate volume + // +- if (!listenerPosition) { ++ if ( !listenerPosition ) { + // just look at the raw wav data for light shader evaluation + volume = 1.0; + } else { + volume = parms->volume; +- volume = soundSystemLocal.dB2Scale(volume); +- +- if (shakesOnly) { ++ volume = soundSystemLocal.dB2Scale( volume ); ++ if ( shakesOnly ) { + volume *= shakes; + } + +- if (listenerPosition && !(parms->soundShaderFlags & SSF_GLOBAL)) { ++ if ( listenerPosition && !( parms->soundShaderFlags & SSF_GLOBAL ) ) { + // check for overrides + float maxd = parms->maxDistance; + float mind = parms->minDistance; + +- if (dlen >= maxd) { ++ if ( dlen >= maxd ) { + volume = 0.0f; +- } else if (dlen > mind) { +- float frac = idMath::ClampFloat(0, 1, 1.0f - ((dlen - mind) / (maxd - mind))); +- +- if (idSoundSystemLocal::s_quadraticFalloff.GetBool()) { ++ } else if ( dlen > mind ) { ++ float frac = idMath::ClampFloat( 0, 1, 1.0f - ((dlen - mind) / (maxd - mind))); ++ if ( idSoundSystemLocal::s_quadraticFalloff.GetBool() ) { + frac *= frac; + } +- + volume *= frac; + } + } + } + +- if (volume <= 0) { ++ if ( volume <= 0 ) { + continue; + } + +@@ -2283,63 +2040,46 @@ float idSoundWorldLocal::FindAmplitude(idSoundEmitterL + // fetch the sound from the cache + // this doesn't handle stereo samples correctly... + // +- if (!listenerPosition && chan->parms.soundShaderFlags & SSF_NO_FLICKER) { ++ if ( !listenerPosition && chan->parms.soundShaderFlags & SSF_NO_FLICKER ) { + // the NO_FLICKER option is to allow a light to still play a sound, but + // not have it effect the intensity +- for (j = 0 ; j < (AMPLITUDE_SAMPLES); j++) { ++ for ( j = 0 ; j < (AMPLITUDE_SAMPLES); j++ ) { + sourceBuffer[j] = j & 1 ? 32767.0f : -32767.0f; + } + } else { + int offset = (localTime - localTriggerTimes); // offset in samples +-#if 0 //k: 2024 check NULL??? +- if ((!looping && !chan->leadinSample)||(looping && !chan->soundShader->entries[0])) +- { +- return 0.0; +- } +-#else +- if ((!looping && !chan->leadinSample)||(looping && !chan->soundShader->entries[0])) +- { +- // get actual sample data +- chan->GatherChannelSamples(offset, AMPLITUDE_SAMPLES, sourceBuffer); +- } +- else +-#endif +- { +- int size = (looping ? chan->soundShader->entries[0]->LengthIn44kHzSamples() : chan->leadinSample->LengthIn44kHzSamples()); +- short *amplitudeData = (short *)(looping ? chan->soundShader->entries[0]->amplitudeData : chan->leadinSample->amplitudeData); +- if (amplitudeData) { ++ int size = ( looping ? chan->soundShader->entries[0]->LengthIn44kHzSamples() : chan->leadinSample->LengthIn44kHzSamples() ); ++ short *amplitudeData = (short *)( looping ? chan->soundShader->entries[0]->amplitudeData : chan->leadinSample->amplitudeData ); ++ ++ if ( amplitudeData ) { + // when the amplitudeData is present use that fill a dummy sourceBuffer + // this is to allow for amplitude based effect on hardware audio solutions +- if (looping) offset %= size; +- +- if (offset < size) { +- for (j = 0 ; j < (AMPLITUDE_SAMPLES); j++) { +- sourceBuffer[j] = j & 1 ? amplitudeData[(offset / 512) * 2 ] : amplitudeData[(offset / 512) * 2 + 1 ]; ++ if ( looping ) offset %= size; ++ if ( offset < size ) { ++ for ( j = 0 ; j < (AMPLITUDE_SAMPLES); j++ ) { ++ sourceBuffer[j] = j & 1 ? amplitudeData[ ( offset / 512 ) * 2 ] : amplitudeData[ ( offset / 512 ) * 2 + 1 ]; + } + } + } else { + // get actual sample data +- chan->GatherChannelSamples(offset, AMPLITUDE_SAMPLES, sourceBuffer); ++ chan->GatherChannelSamples( offset, AMPLITUDE_SAMPLES, sourceBuffer ); + } +- } + } +- + activeChannelCount++; +- +- if (activeChannelCount == 1) { ++ if ( activeChannelCount == 1 ) { + // store to the buffer +- for (j = 0; j < AMPLITUDE_SAMPLES; j++) { ++ for( j = 0; j < AMPLITUDE_SAMPLES; j++ ) { + sumBuffer[ j ] = volume * sourceBuffer[ j ]; + } + } else { + // add to the buffer +- for (j = 0; j < AMPLITUDE_SAMPLES; j++) { ++ for( j = 0; j < AMPLITUDE_SAMPLES; j++ ) { + sumBuffer[ j ] += volume * sourceBuffer[ j ]; + } + } + } + +- if (activeChannelCount == 0) { ++ if ( activeChannelCount == 0 ) { + return 0.0; + } + +@@ -2347,20 +2087,18 @@ float idSoundWorldLocal::FindAmplitude(idSoundEmitterL + float low = 32767.0f; + + // use a 20th of a second +- for (i = 0; i < (AMPLITUDE_SAMPLES); i++) { ++ for( i = 0; i < (AMPLITUDE_SAMPLES); i++ ) { + float fabval = sumBuffer[i]; +- +- if (high < fabval) { ++ if ( high < fabval ) { + high = fabval; + } +- +- if (low > fabval) { ++ if ( low > fabval ) { + low = fabval; + } + } + + float sout; +- sout = atan((high - low) / 32767.0f) / DEG2RAD(45); ++ sout = atan( (high - low) / 32767.0f) / DEG2RAD(45); + + return sout; + } +@@ -2373,25 +2111,24 @@ fade all sounds in the world with a given shader sound + to is in Db (sigh), over is in seconds + ================= + */ +-void idSoundWorldLocal::FadeSoundClasses(const int soundClass, const float to, const float over) +-{ +- if (soundClass < 0 || soundClass >= SOUND_MAX_CLASSES) { +- common->Error("idSoundWorldLocal::FadeSoundClasses: bad soundClass %i", soundClass); ++void idSoundWorldLocal::FadeSoundClasses( const int soundClass, const float to, const float over ) { ++ if ( soundClass < 0 || soundClass >= SOUND_MAX_CLASSES ) { ++ common->Error( "idSoundWorldLocal::FadeSoundClasses: bad soundClass %i", soundClass ); + } + + idSoundFade *fade = &soundClassFade[ soundClass ]; + +- int length44kHz = soundSystemLocal.MillisecondsToSamples(over * 1000); ++ int length44kHz = soundSystemLocal.MillisecondsToSamples( over * 1000 ); + + // if it is already fading to this volume at this rate, don't change it +- if (fade->fadeEndVolume == to && +- fade->fadeEnd44kHz - fade->fadeStart44kHz == length44kHz) { ++ if ( fade->fadeEndVolume == to && ++ fade->fadeEnd44kHz - fade->fadeStart44kHz == length44kHz ) { + return; + } + + int start44kHz; + +- if (fpa[0]) { ++ if ( fpa[0] ) { + // if we are recording an AVI demo, don't use hardware time + start44kHz = lastAVI44kHz + MIXBUFFER_SAMPLES; + } else { +@@ -2399,7 +2136,7 @@ void idSoundWorldLocal::FadeSoundClasses(const int sou + } + + // fade it +- fade->fadeStartVolume = fade->FadeDbAt44kHz(start44kHz); ++ fade->fadeStartVolume = fade->FadeDbAt44kHz( start44kHz ); + fade->fadeStart44kHz = start44kHz; + fade->fadeEnd44kHz = start44kHz + length44kHz; + fade->fadeEndVolume = to; +@@ -2410,8 +2147,7 @@ void idSoundWorldLocal::FadeSoundClasses(const int sou + idSoundWorldLocal::SetSlowmo + ================= + */ +-void idSoundWorldLocal::SetSlowmo(bool active) +-{ ++void idSoundWorldLocal::SetSlowmo( bool active ) { + slowmoActive = active; + } + +@@ -2420,8 +2156,7 @@ void idSoundWorldLocal::SetSlowmo(bool active) + idSoundWorldLocal::SetSlowmoSpeed + ================= + */ +-void idSoundWorldLocal::SetSlowmoSpeed(float speed) +-{ ++void idSoundWorldLocal::SetSlowmoSpeed( float speed ) { + slowmoSpeed = speed; + } + +@@ -2430,8 +2165,6 @@ void idSoundWorldLocal::SetSlowmoSpeed(float speed) + idSoundWorldLocal::SetEnviroSuit + ================= + */ +-void idSoundWorldLocal::SetEnviroSuit(bool active) +-{ ++void idSoundWorldLocal::SetEnviroSuit( bool active ) { + enviroSuitActive = active; + } +- diff --git a/games/idtech4a-engine/patches/patch-sound_sound_h b/games/idtech4a-engine/patches/patch-sound_sound_h new file mode 100644 index 000000000..0997f8841 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sound_sound_h @@ -0,0 +1,387 @@ +Index: sound/sound.h +--- sound/sound.h.orig ++++ sound/sound.h +@@ -4,7 +4,7 @@ + Doom 3 GPL Source Code + Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -245,11 +245,10 @@ const int SOUND_CLASS_MUSICAL = 3; + + // it is somewhat tempting to make this a virtual class to hide the private + // details here, but that doesn't fit easily with the decl manager at the moment. +-class idSoundShader : public idDecl +-{ +- public: +- idSoundShader(void); +- virtual ~idSoundShader(void); ++class idSoundShader : public idDecl { ++public: ++ idSoundShader( void ); ++ virtual ~idSoundShader( void ); + + virtual size_t Size(void) const; + virtual bool SetDefaultText(void); +@@ -262,22 +261,22 @@ class idSoundShader : public idDecl + virtual void FreeData(void); + virtual void List(void) const; + +- virtual const char *GetDescription() const; ++ virtual const char * GetDescription() const; + +- // so the editor can draw correct default sound spheres +- // this is currently defined as meters, which sucks, IMHO. +- virtual float GetMinDistance() const; // FIXME: replace this with a GetSoundShaderParms() +- virtual float GetMaxDistance() const; ++ // so the editor can draw correct default sound spheres ++ // this is currently defined as meters, which sucks, IMHO. ++ virtual float GetMinDistance() const; // FIXME: replace this with a GetSoundShaderParms() ++ virtual float GetMaxDistance() const; + +- // returns NULL if an AltSound isn't defined in the shader. +- // we use this for pairing a specific broken light sound with a normal light sound +- virtual const idSoundShader *GetAltSound() const; ++ // returns NULL if an AltSound isn't defined in the shader. ++ // we use this for pairing a specific broken light sound with a normal light sound ++ virtual const idSoundShader *GetAltSound() const; + +- virtual bool HasDefaultSound() const; ++ virtual bool HasDefaultSound() const; + +- virtual const soundShaderParms_t *GetParms() const; +- virtual int GetNumSounds() const; +- virtual const char *GetSound(int index) const; ++ virtual const soundShaderParms_t *GetParms() const; ++ virtual int GetNumSounds() const; ++ virtual const char * GetSound( int index ) const; + + virtual bool CheckShakesAndOgg(void) const; + #ifdef _RAVEN +@@ -321,15 +320,15 @@ class idSoundShader : public idDecl + friend class idSoundChannel; + friend class idSoundCache; + +- // options from sound shader text +- soundShaderParms_t parms; // can be overriden on a per-channel basis ++ // options from sound shader text ++ soundShaderParms_t parms; // can be overriden on a per-channel basis + +- bool onDemand; // only load when played, and free when finished +- int speakerMask; +- const idSoundShader *altSound; +- idStr desc; // description +- bool errorDuringParse; +- float leadinVolume; // allows light breaking leadin sounds to be much louder than the broken loop ++ bool onDemand; // only load when played, and free when finished ++ int speakerMask; ++ const idSoundShader * altSound; ++ idStr desc; // description ++ bool errorDuringParse; ++ float leadinVolume; // allows light breaking leadin sounds to be much louder than the broken loop + + idSoundSample *leadins[SOUND_MAX_LIST_WAVS]; + int numLeadins; +@@ -349,9 +348,9 @@ class idSoundShader : public idDecl + // RAVEN END + #endif + +- private: +- void Init(void); +- bool ParseShader(idLexer &src); ++private: ++ void Init( void ); ++ bool ParseShader( idLexer &src ); + }; + + /* +@@ -364,20 +363,19 @@ class idSoundShader : public idDecl + + // sound channels + static const int SCHANNEL_ANY = 0; // used in queries and commands to effect every channel at once, in +-// startSound to have it not override any other channel ++ // startSound to have it not override any other channel + static const int SCHANNEL_ONE = 1; // any following integer can be used as a channel number + typedef int s_channelType; // the game uses its own series of enums, and we don't want to require casts + + +-class idSoundEmitter +-{ +- public: +- virtual ~idSoundEmitter(void) {} ++class idSoundEmitter { ++public: ++ virtual ~idSoundEmitter( void ) {} + +- // a non-immediate free will let all currently playing sounds complete +- // soundEmitters are not actually deleted, they are just marked as +- // reusable by the soundWorld +- virtual void Free(bool immediate) = 0; ++ // a non-immediate free will let all currently playing sounds complete ++ // soundEmitters are not actually deleted, they are just marked as ++ // reusable by the soundWorld ++ virtual void Free( bool immediate ) = 0; + + // the parms specified will be the default overrides for all sounds started on this emitter. + // NULL is acceptable for parms +@@ -388,24 +386,24 @@ class idSoundEmitter + // jmarshalll end + #endif + +- // returns the length of the started sound in msec +- virtual int StartSound(const idSoundShader *shader, const s_channelType channel, float diversity = 0, int shaderFlags = 0, bool allowSlow = true) = 0; ++ // returns the length of the started sound in msec ++ virtual int StartSound( const idSoundShader *shader, const s_channelType channel, float diversity = 0, int shaderFlags = 0, bool allowSlow = true ) = 0; + +- // pass SCHANNEL_ANY to effect all channels +- virtual void ModifySound(const s_channelType channel, const soundShaderParms_t *parms) = 0; +- virtual void StopSound(const s_channelType channel) = 0; +- // to is in Db (sigh), over is in seconds +- virtual void FadeSound(const s_channelType channel, float to, float over) = 0; ++ // pass SCHANNEL_ANY to effect all channels ++ virtual void ModifySound( const s_channelType channel, const soundShaderParms_t *parms ) = 0; ++ virtual void StopSound( const s_channelType channel ) = 0; ++ // to is in Db (sigh), over is in seconds ++ virtual void FadeSound( const s_channelType channel, float to, float over ) = 0; + +- // returns true if there are any sounds playing from this emitter. There is some conservative +- // slop at the end to remove inconsistent race conditions with the sound thread updates. +- // FIXME: network game: on a dedicated server, this will always be false +- virtual bool CurrentlyPlaying(void) const = 0; ++ // returns true if there are any sounds playing from this emitter. There is some conservative ++ // slop at the end to remove inconsistent race conditions with the sound thread updates. ++ // FIXME: network game: on a dedicated server, this will always be false ++ virtual bool CurrentlyPlaying( void ) const = 0; + +- // returns a 0.0 to 1.0 value based on the current sound amplitude, allowing +- // graphic effects to be modified in time with the audio. +- // just samples the raw wav file, it doesn't account for volume overrides in the +- virtual float CurrentAmplitude(void) = 0; ++ // returns a 0.0 to 1.0 value based on the current sound amplitude, allowing ++ // graphic effects to be modified in time with the audio. ++ // just samples the raw wav file, it doesn't account for volume overrides in the ++ virtual float CurrentAmplitude( void ) = 0; + + // for save games. Index will always be > 0 + virtual int Index(void) const = 0; +@@ -431,64 +429,63 @@ option existing simultaniously with a live game. + =============================================================================== + */ + +-class idSoundWorld +-{ +- public: +- virtual ~idSoundWorld(void) {} ++class idSoundWorld { ++public: ++ virtual ~idSoundWorld( void ) {} + +- // call at each map start +- virtual void ClearAllSoundEmitters(void) = 0; +- virtual void StopAllSounds(void) = 0; ++ // call at each map start ++ virtual void ClearAllSoundEmitters( void ) = 0; ++ virtual void StopAllSounds( void ) = 0; + +- // get a new emitter that can play sounds in this world +- virtual idSoundEmitter *AllocSoundEmitter(void) = 0; ++ // get a new emitter that can play sounds in this world ++ virtual idSoundEmitter *AllocSoundEmitter( void ) = 0; + +- // for load games, index 0 will return NULL +- virtual idSoundEmitter *EmitterForIndex(int index) = 0; ++ // for load games, index 0 will return NULL ++ virtual idSoundEmitter *EmitterForIndex( int index ) = 0; + +- // query sound samples from all emitters reaching a given position +- virtual float CurrentShakeAmplitudeForPosition(const int time, const idVec3 &listenerPosition) = 0; ++ // query sound samples from all emitters reaching a given position ++ virtual float CurrentShakeAmplitudeForPosition( const int time, const idVec3 &listenerPosition ) = 0; + +- // where is the camera/microphone +- // listenerId allows listener-private and antiPrivate sounds to be filtered +- // gameTime is in msec, and is used to time sound queries and removals so that they are independent +- // of any race conditions with the async update +- virtual void PlaceListener(const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr &areaName) = 0; ++ // where is the camera/microphone ++ // listenerId allows listener-private and antiPrivate sounds to be filtered ++ // gameTime is in msec, and is used to time sound queries and removals so that they are independent ++ // of any race conditions with the async update ++ virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName ) = 0; + +- // fade all sounds in the world with a given shader soundClass +- // to is in Db (sigh), over is in seconds +- virtual void FadeSoundClasses(const int soundClass, const float to, const float over) = 0; ++ // fade all sounds in the world with a given shader soundClass ++ // to is in Db (sigh), over is in seconds ++ virtual void FadeSoundClasses( const int soundClass, const float to, const float over ) = 0; + +- // background music +- virtual void PlayShaderDirectly(const char *name, int channel = -1) = 0; ++ // background music ++ virtual void PlayShaderDirectly( const char *name, int channel = -1 ) = 0; + +- // dumps the current state and begins archiving commands +- virtual void StartWritingDemo(idDemoFile *demo) = 0; +- virtual void StopWritingDemo() = 0; ++ // dumps the current state and begins archiving commands ++ virtual void StartWritingDemo( idDemoFile *demo ) = 0; ++ virtual void StopWritingDemo() = 0; + +- // read a sound command from a demo file +- virtual void ProcessDemoCommand(idDemoFile *demo) = 0; ++ // read a sound command from a demo file ++ virtual void ProcessDemoCommand( idDemoFile *demo ) = 0; + +- // pause and unpause the sound world +- virtual void Pause(void) = 0; +- virtual void UnPause(void) = 0; +- virtual bool IsPaused(void) = 0; ++ // pause and unpause the sound world ++ virtual void Pause( void ) = 0; ++ virtual void UnPause( void ) = 0; ++ virtual bool IsPaused( void ) = 0; + +- // Write the sound output to multiple wav files. Note that this does not use the +- // work done by AsyncUpdate, it mixes explicitly in the foreground every PlaceOrigin(), +- // under the assumption that we are rendering out screenshots and the gameTime is going +- // much slower than real time. +- // path should not include an extension, and the generated filenames will be: +- // _left.raw, _right.raw, or _51left.raw, _51right.raw, +- // _51center.raw, _51lfe.raw, _51backleft.raw, _51backright.raw, +- // If only two channel mixing is enabled, the left and right .raw files will also be +- // combined into a stereo .wav file. +- virtual void AVIOpen(const char *path, const char *name) = 0; +- virtual void AVIClose(void) = 0; ++ // Write the sound output to multiple wav files. Note that this does not use the ++ // work done by AsyncUpdate, it mixes explicitly in the foreground every PlaceOrigin(), ++ // under the assumption that we are rendering out screenshots and the gameTime is going ++ // much slower than real time. ++ // path should not include an extension, and the generated filenames will be: ++ // _left.raw, _right.raw, or _51left.raw, _51right.raw, ++ // _51center.raw, _51lfe.raw, _51backleft.raw, _51backright.raw, ++ // If only two channel mixing is enabled, the left and right .raw files will also be ++ // combined into a stereo .wav file. ++ virtual void AVIOpen( const char *path, const char *name ) = 0; ++ virtual void AVIClose( void ) = 0; + +- // SaveGame / demo Support +- virtual void WriteToSaveGame(idFile *savefile) = 0; +- virtual void ReadFromSaveGame(idFile *savefile) = 0; ++ // SaveGame / demo Support ++ virtual void WriteToSaveGame( idFile *savefile ) = 0; ++ virtual void ReadFromSaveGame( idFile *savefile ) = 0; + + virtual void SetSlowmo(bool active) = 0; + virtual void SetSlowmoSpeed(float speed) = 0; +@@ -528,67 +525,61 @@ typedef struct { + } soundDecoderInfo_t; + + +-class idSoundSystem +-{ +- public: +- virtual ~idSoundSystem(void) {} ++class idSoundSystem { ++public: ++ virtual ~idSoundSystem( void ) {} + +- // all non-hardware initialization +- virtual void Init(void) = 0; ++ // all non-hardware initialization ++ virtual void Init( void ) = 0; + +- // shutdown routine +- virtual void Shutdown(void) = 0; ++ // shutdown routine ++ virtual void Shutdown( void ) = 0; + +- // call ClearBuffer if there is a chance that the AsyncUpdate won't get called +- // for 20+ msec, which would cause a stuttering repeat of the current +- // buffer contents +- virtual void ClearBuffer(void) = 0; ++ // sound is attached to the window, and must be recreated when the window is changed ++ virtual bool InitHW( void ) = 0; ++ virtual bool ShutdownHW( void ) = 0; + +- // sound is attached to the window, and must be recreated when the window is changed +- virtual bool InitHW(void) = 0; +- virtual bool ShutdownHW(void) = 0; ++ // asyn loop, called at 60Hz ++ virtual int AsyncUpdate( int time ) = 0; + +- // asyn loop, called at 60Hz +- virtual int AsyncUpdate(int time) = 0; ++ // async loop, when the sound driver uses a write strategy ++ virtual int AsyncUpdateWrite( int time ) = 0; + +- // async loop, when the sound driver uses a write strategy +- virtual int AsyncUpdateWrite(int time) = 0; ++ // it is a good idea to mute everything when starting a new level, ++ // because sounds may be started before a valid listener origin ++ // is specified ++ virtual void SetMute( bool mute ) = 0; + +- // it is a good idea to mute everything when starting a new level, +- // because sounds may be started before a valid listener origin +- // is specified +- virtual void SetMute(bool mute) = 0; ++ // for the sound level meter window ++ virtual cinData_t ImageForTime( const int milliseconds, const bool waveform ) = 0; + +- // for the sound level meter window +- virtual cinData_t ImageForTime(const int milliseconds, const bool waveform) = 0; ++ // get sound decoder info ++ virtual int GetSoundDecoderInfo( int index, soundDecoderInfo_t &decoderInfo ) = 0; + +- // get sound decoder info +- virtual int GetSoundDecoderInfo(int index, soundDecoderInfo_t &decoderInfo) = 0; ++ // if rw == NULL, no portal occlusion or rendered debugging is available ++ virtual idSoundWorld * AllocSoundWorld( idRenderWorld *rw ) = 0; + +- // if rw == NULL, no portal occlusion or rendered debugging is available +- virtual idSoundWorld *AllocSoundWorld(idRenderWorld *rw) = 0; ++ // specifying NULL will cause silence to be played ++ virtual void SetPlayingSoundWorld( idSoundWorld *soundWorld ) = 0; + +- // specifying NULL will cause silence to be played +- virtual void SetPlayingSoundWorld(idSoundWorld *soundWorld) = 0; ++ // some tools, like the sound dialog, may be used in both the game and the editor ++ // This can return NULL, so check! ++ virtual idSoundWorld * GetPlayingSoundWorld( void ) = 0; + +- // some tools, like the sound dialog, may be used in both the game and the editor +- // This can return NULL, so check! +- virtual idSoundWorld *GetPlayingSoundWorld(void) = 0; ++ // Mark all soundSamples as currently unused, ++ // but don't free anything. ++ virtual void BeginLevelLoad( void ) = 0; + +- // Mark all soundSamples as currently unused, +- // but don't free anything. +- virtual void BeginLevelLoad(void) = 0; ++ // Free all soundSamples marked as unused ++ // We might want to defer the loading of new sounds to this point, ++ // as we do with images, to avoid having a union in memory at one time. ++ virtual void EndLevelLoad( const char *mapString ) = 0; + +- // Free all soundSamples marked as unused +- // We might want to defer the loading of new sounds to this point, +- // as we do with images, to avoid having a union in memory at one time. +- virtual void EndLevelLoad(const char *mapString) = 0; ++ // direct mixing for OSes that support it ++ virtual int AsyncMix( int soundTime, float *mixBuffer ) = 0; + +- // direct mixing for OSes that support it +- virtual int AsyncMix(int soundTime, float *mixBuffer) = 0; +- +- // prints memory info +- virtual void PrintMemInfo(MemInfo_t *mi) = 0; ++ // prints memory info ++ virtual void PrintMemInfo( MemInfo_t *mi ) = 0; + + // is EAX support present - -1: disabled at compile time, 0: no suitable hardware, 1: ok, 2: failed to load OpenAL DLL + virtual int IsEAXAvailable(void) = 0; diff --git a/games/idtech4a-engine/patches/patch-sys_cmake_FindOGG_cmake b/games/idtech4a-engine/patches/patch-sys_cmake_FindOGG_cmake new file mode 100644 index 000000000..19dd383d1 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_cmake_FindOGG_cmake @@ -0,0 +1,87 @@ +Index: sys/cmake/FindOGG.cmake +--- sys/cmake/FindOGG.cmake.orig ++++ sys/cmake/FindOGG.cmake +@@ -0,0 +1,83 @@ ++# Locate OGG ++# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables ++# ++# $OGGDIR is an environment variable that would ++# correspond to the ./configure --prefix=$OGGDIR ++# used in building OGG. ++ ++SET(OGG_SEARCH_PATHS ++ ~/Library/Frameworks ++ /Library/Frameworks ++ /usr/local ++ /usr ++ /sw # Fink ++ /opt/local # DarwinPorts ++ /opt/csw # Blastwave ++ /opt ++) ++ ++SET(MSVC_YEAR_NAME) ++IF (MSVC_VERSION GREATER 1599) # >= 1600 ++ SET(MSVC_YEAR_NAME VS2010) ++ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500 ++ SET(MSVC_YEAR_NAME VS2008) ++ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400 ++ SET(MSVC_YEAR_NAME VS2005) ++ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300 ++ SET(MSVC_YEAR_NAME VS2003) ++ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200 ++ SET(MSVC_YEAR_NAME VS6) ++ENDIF() ++ ++FIND_PATH(OGG_INCLUDE_DIR ++ NAMES ogg/ogg.h ogg/os_types.h ++ HINTS ++ $ENV{OGGDIR} ++ $ENV{OGG_PATH} ++ PATH_SUFFIXES include ++ PATHS ${OGG_SEARCH_PATHS} ++) ++ ++FIND_LIBRARY(OGG_LIBRARY ++ NAMES ogg libogg ++ HINTS ++ $ENV{OGGDIR} ++ $ENV{OGG_PATH} ++ PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release" ++ PATHS ${OGG_SEARCH_PATHS} ++) ++ ++# First search for d-suffixed libs ++FIND_LIBRARY(OGG_LIBRARY_DEBUG ++ NAMES oggd ogg_d liboggd libogg_d ++ HINTS ++ $ENV{OGGDIR} ++ $ENV{OGG_PATH} ++ PATH_SUFFIXES lib lib64 win32/Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${OGG_SEARCH_PATHS} ++) ++ ++IF(NOT OGG_LIBRARY_DEBUG) ++ # Then search for non suffixed libs if necessary, but only in debug dirs ++ FIND_LIBRARY(OGG_LIBRARY_DEBUG ++ NAMES ogg libogg ++ HINTS ++ $ENV{OGGDIR} ++ $ENV{OGG_PATH} ++ PATH_SUFFIXES win32/Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${OGG_SEARCH_PATHS} ++ ) ++ENDIF() ++ ++ ++IF(OGG_LIBRARY) ++ IF(OGG_LIBRARY_DEBUG) ++ SET(OGG_LIBRARIES optimized "${OGG_LIBRARY}" debug "${OGG_LIBRARY_DEBUG}") ++ ELSE() ++ SET(OGG_LIBRARIES "${OGG_LIBRARY}") # Could add "general" keyword, but it is optional ++ ENDIF() ++ENDIF() ++ ++# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE ++INCLUDE(FindPackageHandleStandardArgs) ++FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGG DEFAULT_MSG OGG_LIBRARIES OGG_INCLUDE_DIR) diff --git a/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbisFile_cmake b/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbisFile_cmake new file mode 100644 index 000000000..dc7d03d62 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbisFile_cmake @@ -0,0 +1,95 @@ +Index: sys/cmake/FindVorbisFile.cmake +--- sys/cmake/FindVorbisFile.cmake.orig ++++ sys/cmake/FindVorbisFile.cmake +@@ -0,0 +1,91 @@ ++# Locate VorbisFile ++# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables ++# ++# $VORBISDIR is an environment variable that would ++# correspond to the ./configure --prefix=$VORBISDIR ++# used in building Vorbis. ++ ++SET(VORBISFILE_SEARCH_PATHS ++ ~/Library/Frameworks ++ /Library/Frameworks ++ /usr/local ++ /usr ++ /sw # Fink ++ /opt/local # DarwinPorts ++ /opt/csw # Blastwave ++ /opt ++) ++ ++SET(MSVC_YEAR_NAME) ++IF (MSVC_VERSION GREATER 1599) # >= 1600 ++ SET(MSVC_YEAR_NAME VS2010) ++ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500 ++ SET(MSVC_YEAR_NAME VS2008) ++ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400 ++ SET(MSVC_YEAR_NAME VS2005) ++ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300 ++ SET(MSVC_YEAR_NAME VS2003) ++ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200 ++ SET(MSVC_YEAR_NAME VS6) ++ENDIF() ++ ++FIND_PATH(VORBISFILE_INCLUDE_DIR ++ NAMES vorbis/vorbisfile.h ++ HINTS ++ $ENV{VORBISFILEDIR} ++ $ENV{VORBISFILE_PATH} ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES include ++ PATHS ${VORBISFILE_SEARCH_PATHS} ++) ++ ++FIND_LIBRARY(VORBISFILE_LIBRARY ++ NAMES vorbisfile libvorbisfile ++ HINTS ++ $ENV{VORBISFILEDIR} ++ $ENV{VORBISFILE_PATH} ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release" ++ PATHS ${VORBISFILE_SEARCH_PATHS} ++) ++ ++# First search for d-suffixed libs ++FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG ++ NAMES vorbisfiled vorbisfile_d libvorbisfiled libvorbisfile_d ++ HINTS ++ $ENV{VORBISFILEDIR} ++ $ENV{VORBISFILE_PATH} ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${VORBISFILE_SEARCH_PATHS} ++) ++ ++IF(NOT VORBISFILE_LIBRARY_DEBUG) ++ # Then search for non suffixed libs if necessary, but only in debug dirs ++ FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG ++ NAMES vorbisfile libvorbisfile ++ HINTS ++ $ENV{VORBISFILEDIR} ++ $ENV{VORBISFILE_PATH} ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${VORBISFILE_SEARCH_PATHS} ++ ) ++ENDIF() ++ ++ ++IF(VORBISFILE_LIBRARY) ++ IF(VORBISFILE_LIBRARY_DEBUG) ++ SET(VORBISFILE_LIBRARIES optimized "${VORBISFILE_LIBRARY}" debug "${VORBISFILE_LIBRARY_DEBUG}") ++ ELSE() ++ SET(VORBISFILE_LIBRARIES "${VORBISFILE_LIBRARY}") # Could add "general" keyword, but it is optional ++ ENDIF() ++ENDIF() ++ ++# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE ++INCLUDE(FindPackageHandleStandardArgs) ++FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBISFILE DEFAULT_MSG VORBISFILE_LIBRARIES VORBISFILE_INCLUDE_DIR) diff --git a/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbis_cmake b/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbis_cmake new file mode 100644 index 000000000..f8f34f92a --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_cmake_FindVorbis_cmake @@ -0,0 +1,87 @@ +Index: sys/cmake/FindVorbis.cmake +--- sys/cmake/FindVorbis.cmake.orig ++++ sys/cmake/FindVorbis.cmake +@@ -0,0 +1,83 @@ ++# Locate Vorbis ++# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables ++# ++# $VORBISDIR is an environment variable that would ++# correspond to the ./configure --prefix=$VORBISDIR ++# used in building Vorbis. ++ ++SET(VORBIS_SEARCH_PATHS ++ ~/Library/Frameworks ++ /Library/Frameworks ++ /usr/local ++ /usr ++ /sw # Fink ++ /opt/local # DarwinPorts ++ /opt/csw # Blastwave ++ /opt ++) ++ ++SET(MSVC_YEAR_NAME) ++IF (MSVC_VERSION GREATER 1599) # >= 1600 ++ SET(MSVC_YEAR_NAME VS2010) ++ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500 ++ SET(MSVC_YEAR_NAME VS2008) ++ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400 ++ SET(MSVC_YEAR_NAME VS2005) ++ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300 ++ SET(MSVC_YEAR_NAME VS2003) ++ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200 ++ SET(MSVC_YEAR_NAME VS6) ++ENDIF() ++ ++FIND_PATH(VORBIS_INCLUDE_DIR ++ NAMES vorbis/codec.h ++ HINTS ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES include ++ PATHS ${VORBIS_SEARCH_PATHS} ++) ++ ++FIND_LIBRARY(VORBIS_LIBRARY ++ NAMES vorbis libvorbis ++ HINTS ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES lib lib64 win32/Vorbis_Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release" ++ PATHS ${VORBIS_SEARCH_PATHS} ++) ++ ++# First search for d-suffixed libs ++FIND_LIBRARY(VORBIS_LIBRARY_DEBUG ++ NAMES vorbisd vorbis_d libvorbisd libvorbis_d ++ HINTS ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES lib lib64 win32/Vorbis_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${VORBIS_SEARCH_PATHS} ++) ++ ++IF(NOT VORBIS_LIBRARY_DEBUG) ++ # Then search for non suffixed libs if necessary, but only in debug dirs ++ FIND_LIBRARY(VORBIS_LIBRARY_DEBUG ++ NAMES vorbis libvorbis ++ HINTS ++ $ENV{VORBISDIR} ++ $ENV{VORBIS_PATH} ++ PATH_SUFFIXES win32/Vorbis_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug" ++ PATHS ${VORBIS_SEARCH_PATHS} ++ ) ++ENDIF() ++ ++ ++IF(VORBIS_LIBRARY) ++ IF(VORBIS_LIBRARY_DEBUG) ++ SET(VORBIS_LIBRARIES optimized "${VORBIS_LIBRARY}" debug "${VORBIS_LIBRARY_DEBUG}") ++ ELSE() ++ SET(VORBIS_LIBRARIES "${VORBIS_LIBRARY}") # Could add "general" keyword, but it is optional ++ ENDIF() ++ENDIF() ++ ++# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE ++INCLUDE(FindPackageHandleStandardArgs) ++FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBIS DEFAULT_MSG VORBIS_LIBRARIES VORBIS_INCLUDE_DIR) diff --git a/games/idtech4a-engine/patches/patch-sys_linux_main_cpp b/games/idtech4a-engine/patches/patch-sys_linux_main_cpp new file mode 100644 index 000000000..06f34d853 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_linux_main_cpp @@ -0,0 +1,529 @@ +:Index: sys/linux/main.cpp +Index: sys/linux/main.cpp +--- sys/linux/main.cpp.orig ++++ sys/linux/main.cpp +@@ -2,9 +2,9 @@ + =========================================================================== + + Doom 3 GPL Source Code +-Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. ++Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. + +-This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?). ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). + + Doom 3 Source Code is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by +@@ -37,6 +37,9 @@ If you have questions concerning this license or the a + #include + #include + ++#include ++#include ++ + #ifdef ID_MCHECK + #include + #endif +@@ -44,6 +47,15 @@ If you have questions concerning this license or the a + static idStr basepath; + static idStr savepath; + ++/** ++ * @brief Internal structure, used in cpu_tsc_mark, cpu_tsc_unmark and ++ * cpu_clock_by_mark ++ */ ++struct cpu_mark_t { ++ uint64_t tsc; /*!< Time-stamp from RDTSC */ ++ uint64_t sys_clock; /*!< In microsecond resolution */ ++}; ++ + /* + =========== + Sys_InitScanTable +@@ -58,7 +70,7 @@ void Sys_InitScanTable( void ) { + Sys_AsyncThread + ================= + */ +-void Sys_AsyncThread( void ) { ++THREAD_RETURN_TYPE Sys_AsyncThread( void * ) { + int now; + int next; + int want_sleep; +@@ -69,17 +81,17 @@ void Sys_AsyncThread( void ) { + ticked = now >> 4; + while (1) { + // sleep +- now = Sys_Milliseconds(); ++ now = Sys_Milliseconds(); + next = ( now & 0xFFFFFFF0 ) + 0x10; + want_sleep = ( next-now-1 ) * 1000; + if ( want_sleep > 0 ) { + usleep( want_sleep ); // sleep 1ms less than true target + } +- ++ + // compensate if we slept too long + now = Sys_Milliseconds(); + to_ticked = now >> 4; +- ++ + // show ticking statistics - every 100 ticks, print a summary + #if 0 + #define STAT_BUF 100 +@@ -100,7 +112,7 @@ void Sys_AsyncThread( void ) { + counter = 0; + } + #endif +- ++ + while ( ticked < to_ticked ) { + common->Async(); + ticked++; +@@ -109,6 +121,8 @@ void Sys_AsyncThread( void ) { + // thread exit + pthread_testcancel(); + } ++ ++ return (THREAD_RETURN_TYPE) 0; + } + + /* +@@ -139,7 +153,7 @@ const char *Sys_EXEPath( void ) { + len = readlink( linkpath.c_str(), buf, sizeof( buf ) ); + if ( len == -1 ) { + Sys_Printf("couldn't stat exe path link %s\n", linkpath.c_str()); +- buf[ len ] = '\0'; ++ buf[ 0 ] = '\0'; + } + return buf; + } +@@ -178,12 +192,7 @@ const char *Sys_DefaultBasePath(void) { + } + } + common->Printf( "WARNING: using hardcoded default base path\n" ); +-#ifndef LINUX_DEFAULT_PATH +- #warning undefined data path +- return BASE_GAMEDIR; +-#else + return LINUX_DEFAULT_PATH; +-#endif + } + + /* +@@ -211,9 +220,101 @@ void Sys_Shutdown( void ) { + Sys_GetProcessorId + =============== + */ ++static char cpustring[13] = "generic\0"; ++ ++#if defined(__x86_64__) || defined(__i386__) ++#if __x86_64__ ++# define REG_b "rbx" ++# define REG_S "rsi" ++#elif __i386__ ++# define REG_b "ebx" ++# define REG_S "esi" ++#endif ++ ++#define cpuid(index,eax,ebx,ecx,edx) \ ++ __asm__ volatile \ ++ ( "mov %%" REG_b ", %%" REG_S "\n\t" \ ++ "cpuid\n\t" \ ++ "xchg %%" REG_b ", %%" REG_S \ ++ : "=a" (eax), "=S" (ebx), \ ++ "=c" (ecx), "=d" (edx) \ ++ : "0" (index)); ++ + int Sys_GetProcessorId( void ) { ++ int eax, ebx, ecx, edx; ++ int max_std_level, max_ext_level, std_caps=0, ext_caps=0; ++ union { int i[3]; char c[12]; } vendor; ++ ++ int i = CPUID_GENERIC; ++ ++ cpuid(0, max_std_level, ebx, ecx, edx); ++ vendor.i[0] = ebx; ++ vendor.i[1] = edx; ++ vendor.i[2] = ecx; ++ ++ strncpy(cpustring, vendor.c, 12); ++ cpustring[12] = 0; ++ ++ Sys_Printf("Detected '%s' CPU with", cpustring); ++ ++ if (max_std_level >= 1) { ++ cpuid(1, eax, ebx, ecx, std_caps); ++ ++#ifdef __MMX__ ++ if (std_caps & (1<<23)) { ++ Sys_Printf(" MMX"); ++ i |= CPUID_MMX; ++ } ++#endif ++#ifdef __SSE__ ++ if (std_caps & (1<<25)) { ++ Sys_Printf(" SSE"); ++ i |= CPUID_SSE; ++ } ++#endif ++#ifdef __SSE2__ ++ if (std_caps & (1<<26)) { ++ Sys_Printf(" SSE2"); ++ i |= CPUID_SSE2; ++ } ++#endif ++#ifdef __SSE3__ ++ if (ecx & 1) { ++ Sys_Printf(" SSE3"); ++ i |= CPUID_SSE3; ++ } ++#endif ++ } ++ ++ cpuid(0x80000000, max_ext_level, ebx, ecx, edx); ++ ++ if (max_ext_level >= 0x80000001) { ++ cpuid(0x80000001, eax, ebx, ecx, ext_caps); ++ ++#ifdef __3dNOW__ ++ if (ext_caps & (1U<<31)) { ++ Sys_Printf(" 3DNOW"); ++ i |= CPUID_3DNOW; ++ } ++#endif ++#ifdef __MMX__ ++ if (ext_caps & (1<<23)) { ++ if (!(i & CPUID_MMX)) ++ Sys_Printf(" MMX"); ++ i |= CPUID_MMX; ++ } ++#endif ++ } ++ ++ Sys_Printf("\n"); ++ ++ return i; ++} ++#else ++int Sys_GetProcessorId( void ) { + return CPUID_GENERIC; + } ++#endif + + /* + =============== +@@ -221,7 +322,7 @@ Sys_GetProcessorString + =============== + */ + const char *Sys_GetProcessorString( void ) { +- return "generic"; ++ return cpustring; + } + + /* +@@ -262,8 +363,7 @@ double Sys_GetClockTicks( void ) { + : "=r" (lo), "=r" (hi) ); + return (double) lo + (double) 0xFFFFFFFF * hi; + #else +-#warning unsupported CPU +- return 0; ++ return 0.0; + #endif + } + +@@ -277,7 +377,7 @@ double MeasureClockTicks( void ) { + + t0 = Sys_GetClockTicks( ); + Sys_Sleep( 1000 ); +- t1 = Sys_GetClockTicks( ); ++ t1 = Sys_GetClockTicks( ); + return t1 - t0; + } + +@@ -286,6 +386,137 @@ double MeasureClockTicks( void ) { + Sys_ClockTicksPerSecond + =============== + */ ++// ++// Start libcpuid functions ++// ++// sys_precise_clock ++void sys_precise_clock(uint64_t *result) ++{ ++ struct timeval tv; ++ gettimeofday(&tv, NULL); ++ *result = (uint64_t) tv.tv_sec * (uint64_t) 1000000 + ++ (uint64_t) tv.tv_usec; ++} ++ ++// cpu_rdtsc ++void cpu_rdtsc(uint64_t* result) ++{ ++ uint32_t low_part, hi_part; ++ __asm __volatile ( ++ " rdtsc\n" ++ " mov %%eax, %0\n" ++ " mov %%edx, %1\n" ++ :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" ++ ); ++ ++ *result = (uint64_t)low_part + (((uint64_t) hi_part) << 32); ++} ++ ++// cpu_tsc_mark ++void cpu_tsc_mark(struct cpu_mark_t* mark) ++{ ++ cpu_rdtsc(&mark->tsc); ++ sys_precise_clock(&mark->sys_clock); ++} ++ ++// cpu_clock_by_mark ++int cpu_clock_by_mark(struct cpu_mark_t* mark) ++{ ++ uint64_t result; ++ ++ /* Check if some subtraction resulted in a negative number: */ ++ if ((mark->tsc >> 63) != 0 || (mark->sys_clock >> 63) != 0) return -1; ++ ++ /* Divide-by-zero check: */ ++ if (mark->sys_clock == 0) return -1; ++ ++ /* Check if the result fits in 32bits */ ++ result = mark->tsc / mark->sys_clock; ++ if (result > (uint64_t) 0x7fffffff) return -1; ++ return (int) result; ++} ++ ++ ++/* out = a - b */ ++static void mark_t_subtract(struct cpu_mark_t* a, struct cpu_mark_t* b, struct cpu_mark_t *out) ++{ ++ out->tsc = a->tsc - b->tsc; ++ out->sys_clock = a->sys_clock - b->sys_clock; ++} ++ ++/* Emulate doing useful CPU intensive work */ ++static int busy_loop(int amount) ++{ ++ int i, j, k, s = 0; ++ static volatile int data[42] = {32, 12, -1, 5, 23, 0 }; ++ for (i = 0; i < amount; i++) ++ for (j = 0; j < 65536; j++) ++ for (k = 0; k < 42; k++) ++ s += data[k]; ++ return s; ++} ++ ++// cpu_clock_measure ++int cpu_clock_measure(int millis, int quad_check) ++{ ++ struct cpu_mark_t begin[4], end[4], temp, temp2; ++ int results[4], cycles, n, k, i, j, bi, bj, mdiff, diff, _zero = 0; ++ uint64_t tl; ++ ++ if (millis < 1) return -1; ++ tl = millis * (uint64_t) 1000; ++ if (quad_check) ++ tl /= 4; ++ n = quad_check ? 4 : 1; ++ cycles = 1; ++ for (k = 0; k < n; k++) { ++ cpu_tsc_mark(&begin[k]); ++ end[k] = begin[k]; ++ do { ++ /* Run busy loop, and fool the compiler that we USE the garbishy ++ value it calculates */ ++ _zero |= (1 & busy_loop(cycles)); ++ cpu_tsc_mark(&temp); ++ mark_t_subtract(&temp, &end[k], &temp2); ++ /* If busy loop is too short, increase it */ ++ if (temp2.sys_clock < tl / 8) ++ cycles *= 2; ++ end[k] = temp; ++ } while (end[k].sys_clock - begin[k].sys_clock < tl); ++ mark_t_subtract(&end[k], &begin[k], &temp); ++ results[k] = cpu_clock_by_mark(&temp); ++ } ++ if (n == 1) return results[0]; ++ mdiff = 0x7fffffff; ++ bi = bj = -1; ++ for (i = 0; i < 4; i++) { ++ for (j = i + 1; j < 4; j++) { ++ diff = results[i] - results[j]; ++ if (diff < 0) diff = -diff; ++ if (diff < mdiff) { ++ mdiff = diff; ++ bi = i; ++ bj = j; ++ } ++ } ++ } ++ ASSERT(1 == 1); ++ if (results[bi] == -1) return -1; ++ return (results[bi] + results[bj] + _zero) / 2; ++} ++// ++// END libcpuid functions ++// ++ ++double llCPUSpeedHZ() { ++ int mhz; ++ // Here we use the RDTSC-based routine ++ mhz = cpu_clock_measure(400,1); ++ __int64 tm_llCPUSpeedHZ = mhz * 1000000LL; ++ //CPrintF(TRANSV(" Clock: %.0fMHz\n"), _pTimer->tm_llCPUSpeedHZ/1E6); ++ return (double)tm_llCPUSpeedHZ; ++} ++ + double Sys_ClockTicksPerSecond(void) { + static bool init = false; + static double ret; +@@ -297,17 +528,19 @@ double Sys_ClockTicksPerSecond(void) { + return ret; + } + ++ /* + fd = open( "/proc/cpuinfo", O_RDONLY ); + if ( fd == -1 ) { + common->Printf( "couldn't read /proc/cpuinfo\n" ); + ret = MeasureClockTicks(); + init = true; + common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 ); +- return ret; ++ return ret; + } + len = read( fd, buf, 4096 ); + close( fd ); + pos = 0; ++ + while ( pos < len ) { + if ( !idStr::Cmpn( buf + pos, "cpu MHz", 7 ) ) { + pos = strchr( buf + pos, ':' ) - buf + 2; +@@ -320,7 +553,7 @@ double Sys_ClockTicksPerSecond(void) { + ret = MeasureClockTicks(); + init = true; + common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 ); +- return ret; ++ return ret; + } + common->Printf( "/proc/cpuinfo CPU frequency: %g MHz\n", ret ); + ret *= 1000000; +@@ -329,11 +562,13 @@ double Sys_ClockTicksPerSecond(void) { + } + pos = strchr( buf + pos, '\n' ) - buf + 1; + } +- common->Printf( "failed parsing /proc/cpuinfo\n" ); +- ret = MeasureClockTicks(); ++ */ ++ //common->Printf( "failed parsing /proc/cpuinfo\n" ); ++ //ret = MeasureClockTicks(); ++ ret = llCPUSpeedHZ() + init = true; +- common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 ); +- return ret; ++ common->Printf( "Main: measured CPU frequency: %g MHz\n", ret / 1000000.0 ); ++ return ret; + } + + /* +@@ -350,7 +585,7 @@ int Sys_GetSystemRam( void ) { + if ( count == -1 ) { + common->Printf( "GetSystemRam: sysconf _SC_PHYS_PAGES failed\n" ); + return 512; +- } ++ } + page_size = sysconf( _SC_PAGE_SIZE ); + if ( page_size == -1 ) { + common->Printf( "GetSystemRam: sysconf _SC_PAGE_SIZE failed\n" ); +@@ -371,7 +606,7 @@ the no-fork lets you keep the terminal when you're abo + if the command contains spaces, system() is used. Otherwise the more straightforward execl ( system() blows though ) + ================== + */ +-void Sys_DoStartProcess( const char *exeName, bool dofork ) { ++void Sys_DoStartProcess( const char *exeName, bool dofork ) { + bool use_system = false; + if ( strchr( exeName, ' ' ) ) { + use_system = true; +@@ -389,12 +624,13 @@ void Sys_DoStartProcess( const char *exeName, bool dof + if ( dofork ) { + switch ( fork() ) { + case -1: +- // main thread ++ printf( "fork failed: %s\n", strerror( errno ) ); + break; + case 0: + if ( use_system ) { + printf( "system %s\n", exeName ); +- system( exeName ); ++ if (system( exeName ) == -1) ++ printf( "system failed: %s\n", strerror( errno ) ); + _exit( 0 ); + } else { + printf( "execl %s\n", exeName ); +@@ -403,12 +639,16 @@ void Sys_DoStartProcess( const char *exeName, bool dof + _exit( -1 ); + } + break; ++ default: ++ break; + } + } else { + if ( use_system ) { + printf( "system %s\n", exeName ); +- system( exeName ); +- sleep( 1 ); // on some systems I've seen that starting the new process and exiting this one should not be too close ++ if (system( exeName ) == -1) ++ printf( "system failed: %s\n", strerror( errno ) ); ++ else ++ sleep( 1 ); // on some systems I've seen that starting the new process and exiting this one should not be too close + } else { + printf( "execl %s\n", exeName ); + execl( exeName, exeName, NULL ); +@@ -437,7 +677,7 @@ void idSysLocal::OpenURL( const char *url, bool quit ) + } + + common->Printf( "Open URL: %s\n", url ); +- // opening an URL on *nix can mean a lot of things .. ++ // opening an URL on *nix can mean a lot of things .. + // just spawn a script instead of deciding for the user :-) + + // look in the savepath first, then in the basepath +@@ -543,8 +783,6 @@ void abrt_func( mcheck_status status ) { + + #endif + +-#include +-static intptr_t main_thread = 0; + /* + =============== + main +@@ -556,11 +794,9 @@ int main(int argc, const char **argv) { + mcheck( abrt_func ); + Sys_Printf( "memory consistency checking enabled\n" ); + #endif +- ++ + Posix_EarlyInit( ); + +- main_thread = pthread_self(); +- + if ( argc > 1 ) { + common->Init( argc-1, &argv[1], NULL ); + } else { +@@ -572,14 +808,4 @@ int main(int argc, const char **argv) { + while (1) { + common->Frame(); + } +-} +- +-intptr_t Sys_GetMainThread(void) +-{ +- return main_thread; +-} +- +-const char * Sys_DLLDefaultPath(void) +-{ +- return "./"; +-} +\ No newline at end of file ++} diff --git a/games/idtech4a-engine/patches/patch-sys_linux_sdlmain_cpp b/games/idtech4a-engine/patches/patch-sys_linux_sdlmain_cpp new file mode 100644 index 000000000..0ee91974d --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_linux_sdlmain_cpp @@ -0,0 +1,203 @@ +Index: sys/linux/sdlmain.cpp +--- sys/linux/sdlmain.cpp.orig ++++ sys/linux/sdlmain.cpp +@@ -32,6 +32,10 @@ If you have questions concerning this license or the a + #include + #include + ++#include ++#include ++#include ++ + #include + + #include "../platform.h" +@@ -91,6 +95,15 @@ static char path_argv[PATH_MAX]; + static char path_exe[PATH_MAX]; + static char save_path[PATH_MAX]; + ++/** ++ * @brief Internal structure, used in cpu_tsc_mark, cpu_tsc_unmark and ++ * cpu_clock_by_mark ++ */ ++struct cpu_mark_t { ++ uint64_t tsc; /*!< Time-stamp from RDTSC */ ++ uint64_t sys_clock; /*!< In microsecond resolution */ ++}; ++ + // in main.cpp + /* + =============== +@@ -197,6 +210,138 @@ double MeasureClockTicks( void ) { + Sys_ClockTicksPerSecond + =============== + */ ++ ++// ++// Start libcpuid functions ++// ++// sys_precise_clock ++void sys_precise_clock(uint64_t *result) ++{ ++ struct timeval tv; ++ gettimeofday(&tv, NULL); ++ *result = (uint64_t) tv.tv_sec * (uint64_t) 1000000 + ++ (uint64_t) tv.tv_usec; ++} ++ ++// cpu_rdtsc ++void cpu_rdtsc(uint64_t* result) ++{ ++ uint32_t low_part, hi_part; ++ __asm __volatile ( ++ " rdtsc\n" ++ " mov %%eax, %0\n" ++ " mov %%edx, %1\n" ++ :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" ++ ); ++ ++ *result = (uint64_t)low_part + (((uint64_t) hi_part) << 32); ++} ++ ++// cpu_tsc_mark ++void cpu_tsc_mark(struct cpu_mark_t* mark) ++{ ++ cpu_rdtsc(&mark->tsc); ++ sys_precise_clock(&mark->sys_clock); ++} ++ ++// cpu_clock_by_mark ++int cpu_clock_by_mark(struct cpu_mark_t* mark) ++{ ++ uint64_t result; ++ ++ /* Check if some subtraction resulted in a negative number: */ ++ if ((mark->tsc >> 63) != 0 || (mark->sys_clock >> 63) != 0) return -1; ++ ++ /* Divide-by-zero check: */ ++ if (mark->sys_clock == 0) return -1; ++ ++ /* Check if the result fits in 32bits */ ++ result = mark->tsc / mark->sys_clock; ++ if (result > (uint64_t) 0x7fffffff) return -1; ++ return (int) result; ++} ++ ++ ++/* out = a - b */ ++static void mark_t_subtract(struct cpu_mark_t* a, struct cpu_mark_t* b, struct cpu_mark_t *out) ++{ ++ out->tsc = a->tsc - b->tsc; ++ out->sys_clock = a->sys_clock - b->sys_clock; ++} ++ ++/* Emulate doing useful CPU intensive work */ ++static int busy_loop(int amount) ++{ ++ int i, j, k, s = 0; ++ static volatile int data[42] = {32, 12, -1, 5, 23, 0 }; ++ for (i = 0; i < amount; i++) ++ for (j = 0; j < 65536; j++) ++ for (k = 0; k < 42; k++) ++ s += data[k]; ++ return s; ++} ++ ++// cpu_clock_measure ++int cpu_clock_measure(int millis, int quad_check) ++{ ++ struct cpu_mark_t begin[4], end[4], temp, temp2; ++ int results[4], cycles, n, k, i, j, bi, bj, mdiff, diff, _zero = 0; ++ uint64_t tl; ++ ++ if (millis < 1) return -1; ++ tl = millis * (uint64_t) 1000; ++ if (quad_check) ++ tl /= 4; ++ n = quad_check ? 4 : 1; ++ cycles = 1; ++ for (k = 0; k < n; k++) { ++ cpu_tsc_mark(&begin[k]); ++ end[k] = begin[k]; ++ do { ++ /* Run busy loop, and fool the compiler that we USE the garbishy ++ value it calculates */ ++ _zero |= (1 & busy_loop(cycles)); ++ cpu_tsc_mark(&temp); ++ mark_t_subtract(&temp, &end[k], &temp2); ++ /* If busy loop is too short, increase it */ ++ if (temp2.sys_clock < tl / 8) ++ cycles *= 2; ++ end[k] = temp; ++ } while (end[k].sys_clock - begin[k].sys_clock < tl); ++ mark_t_subtract(&end[k], &begin[k], &temp); ++ results[k] = cpu_clock_by_mark(&temp); ++ } ++ if (n == 1) return results[0]; ++ mdiff = 0x7fffffff; ++ bi = bj = -1; ++ for (i = 0; i < 4; i++) { ++ for (j = i + 1; j < 4; j++) { ++ diff = results[i] - results[j]; ++ if (diff < 0) diff = -diff; ++ if (diff < mdiff) { ++ mdiff = diff; ++ bi = i; ++ bj = j; ++ } ++ } ++ } ++ ASSERT(1 == 1); ++ if (results[bi] == -1) return -1; ++ return (results[bi] + results[bj] + _zero) / 2; ++} ++// ++// END libcpuid functions ++// ++ ++double llCPUSpeedHZ() { ++ int mhz; ++ // Here we use the RDTSC-based routine ++ mhz = cpu_clock_measure(400,1); ++ int64_t tm_llCPUSpeedHZ = mhz * 1000000LL; ++ //CPrintF(TRANSV(" Clock: %.0fMHz\n"), _pTimer->tm_llCPUSpeedHZ/1E6); ++ return (double)tm_llCPUSpeedHZ; ++} ++ + double Sys_ClockTicksPerSecond(void) { + static bool init = false; + static double ret; +@@ -207,7 +352,8 @@ double Sys_ClockTicksPerSecond(void) { + if ( init ) { + return ret; + } +- ++ ++ /* + fd = open( "/proc/cpuinfo", O_RDONLY ); + if ( fd == -1 ) { + common->Printf( "couldn't read /proc/cpuinfo\n" ); +@@ -219,6 +365,7 @@ double Sys_ClockTicksPerSecond(void) { + len = read( fd, buf, 4096 ); + close( fd ); + pos = 0; ++ + while ( pos < len ) { + if ( !idStr::Cmpn( buf + pos, "cpu MHz", 7 ) ) { + pos = strchr( buf + pos, ':' ) - buf + 2; +@@ -240,10 +387,12 @@ double Sys_ClockTicksPerSecond(void) { + } + pos = strchr( buf + pos, '\n' ) - buf + 1; + } +- common->Printf( "failed parsing /proc/cpuinfo\n" ); +- ret = MeasureClockTicks(); ++ */ ++ //common->Printf( "failed parsing /proc/cpuinfo\n" ); ++ //ret = MeasureClockTicks(); ++ ret = llCPUSpeedHZ(); + init = true; +- common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 ); ++ common->Printf( "SDL Main: measured CPU frequency: %g MHz\n", ret / 1000000.0 ); + return ret; + } + diff --git a/games/idtech4a-engine/patches/patch-sys_linux_sound_cpp b/games/idtech4a-engine/patches/patch-sys_linux_sound_cpp new file mode 100644 index 000000000..730c852de --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_linux_sound_cpp @@ -0,0 +1,12 @@ +Index: sys/linux/sound.cpp +--- sys/linux/sound.cpp.orig ++++ sys/linux/sound.cpp +@@ -29,7 +29,7 @@ If you have questions concerning this license or the a + #include + #include + #include +-#include ++#include + #include + #include + // OSS sound interface diff --git a/games/idtech4a-engine/patches/patch-sys_linux_sound_h b/games/idtech4a-engine/patches/patch-sys_linux_sound_h new file mode 100644 index 000000000..8fd3b0070 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_linux_sound_h @@ -0,0 +1,11 @@ +Index: sys/linux/sound.h +--- sys/linux/sound.h.orig ++++ sys/linux/sound.h +@@ -81,6 +81,7 @@ class idAudioHardwareOSS : public idAudioHardware { (p + void ExtractOSSVersion( int version, idStr &str ) const; + }; + ++#define NO_ALSA 1 + #ifndef NO_ALSA + + // libasound2-dev diff --git a/games/idtech4a-engine/patches/patch-sys_scons_SConscript_core b/games/idtech4a-engine/patches/patch-sys_scons_SConscript_core new file mode 100644 index 000000000..367cf09af --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_scons_SConscript_core @@ -0,0 +1,186 @@ +Index: sys/scons/SConscript.core +--- sys/scons/SConscript.core.orig ++++ sys/scons/SConscript.core +@@ -9,133 +9,6 @@ import scons_utils + Import( 'GLOBALS' ) + Import( GLOBALS ) + +-#//k curl +-curl_string = \ +- 'base64.c \ +- connect.c \ +- cookie.c \ +- dict.c \ +- easy.c \ +- escape.c \ +- file.c \ +- formdata.c \ +- ftp.c \ +- getdate.c \ +- getenv.c \ +- getinfo.c \ +- hash.c \ +- hostip.c \ +- http.c \ +- http_chunks.c \ +- if2ip.c \ +- krb4.c \ +- ldap.c \ +- llist.c \ +- memdebug.c \ +- mprintf.c \ +- multi.c \ +- netrc.c \ +- progress.c \ +- security.c \ +- sendf.c \ +- share.c \ +- speedcheck.c \ +- ssluse.c \ +- strequal.c \ +- strtok.c \ +- telnet.c \ +- timeval.c \ +- transfer.c \ +- url.c \ +- version.c \ +- http_digest.c \ +- http_ntlm.c \ +- inet_pton.c \ +- md5.c \ +- content_encoding.c' +-curl_list = scons_utils.BuildList( '../../../../../externlibs/curl/lib/', curl_string ) +- +-jpeg_string = \ +- 'jaricom.c \ +- jcapimin.c \ +- jcapistd.c \ +- jcarith.c \ +- jccoefct.c \ +- jccolor.c \ +- jcdctmgr.c \ +- jchuff.c \ +- jcinit.c \ +- jcmainct.c \ +- jcmarker.c \ +- jcmaster.c \ +- jcomapi.c \ +- jcparam.c \ +- jcprepct.c \ +- jcsample.c \ +- jctrans.c \ +- jdapimin.c \ +- jdapistd.c \ +- jdarith.c \ +- jdatadst.c \ +- jdatasrc.c \ +- jdcoefct.c \ +- jdcolor.c \ +- jddctmgr.c \ +- jdhuff.c \ +- jdinput.c \ +- jdmainct.c \ +- jdmarker.c \ +- jdmaster.c \ +- jdmerge.c \ +- jdpostct.c \ +- jdsample.c \ +- jdtrans.c \ +- jerror.c \ +- jfdctflt.c \ +- jfdctfst.c \ +- jfdctint.c \ +- jidctflt.c \ +- jidctfst.c \ +- jidctint.c \ +- jmemmgr.c \ +- jmemname.c \ +- jquant1.c \ +- jquant2.c \ +- jutils.c' +- +-jpeg_list = scons_utils.BuildList( '../../../../../externlibs/jpeg-8d/', jpeg_string ) +- +-libogg_string = ' \ +- libogg/src/bitwise.c \ +- libogg/src/framing.c \ +- libvorbis/lib/analysis.c \ +- libvorbis/lib/floor1.c \ +- libvorbis/lib/psy.c \ +- libvorbis/lib/tone.c \ +- libvorbis/lib/barkmel.c \ +- libvorbis/lib/info.c \ +- libvorbis/lib/vorbisenc.c \ +- libvorbis/lib/bitrate.c \ +- libvorbis/lib/lookup.c \ +- libvorbis/lib/registry.c \ +- libvorbis/lib/vorbisfile.c \ +- libvorbis/lib/block.c \ +- libvorbis/lib/lpc.c \ +- libvorbis/lib/res0.c \ +- libvorbis/lib/window.c \ +- libvorbis/lib/codebook.c \ +- libvorbis/lib/lsp.c \ +- libvorbis/lib/sharedbook.c \ +- libvorbis/lib/envelope.c \ +- libvorbis/lib/mapping0.c \ +- libvorbis/lib/smallft.c \ +- libvorbis/lib/floor0.c \ +- libvorbis/lib/mdct.c \ +- libvorbis/lib/synthesis.c' +- +-libogg_list = scons_utils.BuildList( '../../../../../externlibs/', libogg_string ) +- +- + renderer_string = ' \ + esTransform.c \ + draw_glsl.cpp \ +@@ -375,8 +248,11 @@ if ( local_dedicated == 0 ): + else: + sys_string += ' linux/glimp.cpp' + else: +- sys_string += ' linux/dedicated.cpp' + ++ sys_string += ' linux/dedicated.cpp \ ++ stub/stub_gl.cpp \ ++ stub/openal_stub.cpp' ++ + sys_list = scons_utils.BuildList( 'sys', sys_string ) + + tools_string = ' \ +@@ -505,8 +381,8 @@ else: + local_env.Append( LIBS = [ 'pthread', 'dl', 'vorbisfile', 'jpeg' ] ) + + if ( local_dedicated == 0 ): +- if g_os == 'Linux': +- local_env.Append( LIBS = [ 'X11' ] ) ++ #if g_os == 'Linux': ++ local_env.Append( LIBS = [ 'X11' ] ) # [ 'X11', 'Xext', 'Xxf86vm' ] ) # 'Xxf86dga', + local_env.Append( LIBPATH = [ '/usr/X11R6/lib' ] ) + local_env.Append( LIBS = [ 'openal' ] ) + if ( local_opengl == 0 ): +@@ -514,12 +390,12 @@ if ( local_dedicated == 0 ): + # local_env.Append( LIBPATH = [ '/opt/ndk/android_4_0_gcc_32/arm-linux-androideabi/lib/armv7-a', '/opt/ndk/android_4_0_gcc_32/sysroot/use/lib' ] ) + # local_env.Append( LIBPATH = [ '/data/data/com.termux/files/home/ndk/android_gcc32/arm-linux-androideabi/lib/armv7-a', '/data/data/com.termux/files/home/ndk/android_gcc32/sysroot/usr/lib' ] ) # //k armv7-a + # local_env.Append( LIBPATH = [ '/data/data/com.termux/files/home/ndk/android-ndk-aide/toolchains/aarch64-linux-android-4.9/prebuilt/linux-arm64/lib/gcc/aarch64-linux-android/4.9.x', '/data/data/com.termux/files/home/ndk/android-ndk-aide/platforms/android-21/arch-arm64/usr/lib', '/data/data/com.termux/files/home/ndk/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a' ] ) # //k arm64-v8a +- else: +- local_env.Append( LIBS = [ 'GL' ] ) ++ #else: ++ # local_env.Append( LIBS = [ 'GL' ] ) + + source_list = core_list + source_list += idlib_objects +-source_list += sound_lib ++#source_list += sound_lib + + if g_os == 'Android': + source_list += jpeg_lib +@@ -529,7 +405,7 @@ if g_os == 'Android': + source_list += curl_lib + #source_list += libvorbis_lib + else: +- source_list += [ '../../openal/stubs.cpp' ] ++ #source_list += [ '../../openal/stubs.cpp' ] + + if g_os == 'Android': + local_env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 diff --git a/games/idtech4a-engine/patches/patch-sys_scons_SConscript_idlib b/games/idtech4a-engine/patches/patch-sys_scons_SConscript_idlib new file mode 100644 index 000000000..745f67e6f --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_scons_SConscript_idlib @@ -0,0 +1,16 @@ +Index: sys/scons/SConscript.idlib +--- sys/scons/SConscript.idlib.orig ++++ sys/scons/SConscript.idlib +@@ -36,6 +36,12 @@ idlib_string = ' \ + math/Rotation.cpp \ + math/Simd.cpp \ + math/Simd_Generic.cpp \ ++ math/Simd_AltiVec.cpp \ ++ math/Simd_MMX.cpp \ ++ math/Simd_3DNow.cpp \ ++ math/Simd_SSE.cpp \ ++ math/Simd_SSE2.cpp \ ++ math/Simd_SSE3.cpp \ + math/Vector.cpp \ + BitMsg.cpp \ + LangDict.cpp \ diff --git a/games/idtech4a-engine/patches/patch-sys_sdl_glimp_cpp b/games/idtech4a-engine/patches/patch-sys_sdl_glimp_cpp new file mode 100644 index 000000000..fd8e9e7b6 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_sdl_glimp_cpp @@ -0,0 +1,11 @@ +Index: sys/sdl/glimp.cpp +--- sys/sdl/glimp.cpp.orig ++++ sys/sdl/glimp.cpp +@@ -420,6 +420,7 @@ bool GLimp_Init(glimpParms_t parms) { + // creating the window succeeded, so adjust r_multiSamples to the value that was actually used + parms.multiSamples = multisamples; + r_multiSamples.SetInteger(multisamples); ++ common->Printf("SDL create window: %dx%d (r_mode = %d)\n",parms.width, parms.width, r_mode.GetInteger()); + } + + /* Check if we're really in the requested display mode. There is diff --git a/games/idtech4a-engine/patches/patch-sys_sdl_threads_cpp b/games/idtech4a-engine/patches/patch-sys_sdl_threads_cpp new file mode 100644 index 000000000..8839d64dd --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_sdl_threads_cpp @@ -0,0 +1,20 @@ +Index: sys/sdl/threads.cpp +--- sys/sdl/threads.cpp.orig ++++ sys/sdl/threads.cpp +@@ -30,6 +30,7 @@ If you have questions concerning this license or the a + #include + #include + #include ++#include + + #include "sys/platform.h" + #include "framework/Common.h" +@@ -274,7 +275,7 @@ Sys_DestroyThread + void Sys_DestroyThread(xthreadInfo& info) { + assert(info.threadHandle); + +- SDL_WaitThread((SDL_Thread *)info.threadHandle, NULL); ++ sleep(1); + + info.name = NULL; + info.threadHandle = NULL; diff --git a/games/idtech4a-engine/patches/patch-sys_stub_openal_stub_cpp b/games/idtech4a-engine/patches/patch-sys_stub_openal_stub_cpp new file mode 100644 index 000000000..8ab5b949c --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_stub_openal_stub_cpp @@ -0,0 +1,139 @@ +Index: sys/stub/openal_stub.cpp +--- sys/stub/openal_stub.cpp.orig ++++ sys/stub/openal_stub.cpp +@@ -0,0 +1,135 @@ ++/* ++=========================================================================== ++ ++Doom 3 GPL Source Code ++Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. ++ ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). ++ ++Doom 3 Source Code is free software: you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation, either version 3 of the License, or ++(at your option) any later version. ++ ++Doom 3 Source Code is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with Doom 3 Source Code. If not, see . ++ ++In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. ++ ++If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. ++ ++=========================================================================== ++*/ ++#include "../../idlib/precompiled.h" ++#include "../../sound/snd_local.h" ++ ++AL_API ALenum AL_APIENTRY alGetError() { ++ return AL_NO_ERROR; ++} ++ ++AL_API ALboolean AL_APIENTRY alIsSource( ALuint sid ) { ++ return AL_FALSE; ++} ++ ++AL_API void AL_APIENTRY alGenBuffers( ALsizei n, ALuint* buffers ) { } ++ ++AL_API void AL_APIENTRY alSourceStop( ALuint sid ) { } ++ ++AL_API void AL_APIENTRY alGetSourcei( ALuint sid, ALenum pname, ALint* value ) { } ++ ++AL_API ALint AL_APIENTRY alGetInteger( ALenum param ) { return 0; } ++ ++ALC_API void ALC_APIENTRY alcSuspendContext( ALCcontext *alcHandle ) { } ++ ++ALC_API ALCdevice * ALC_APIENTRY alcOpenDevice( const ALchar *tokstr ) { ++ return NULL; ++} ++ ++AL_API void AL_APIENTRY alDeleteBuffers( ALsizei n, const ALuint* buffers ) { } ++ ++AL_API ALboolean AL_APIENTRY alIsExtensionPresent( const ALchar* fname ) { ++ return AL_FALSE; ++} ++ ++AL_API void AL_APIENTRY alBufferData( ALuint buffer, ++ ALenum format, ++ const ALvoid* data, ++ ALsizei size, ++ ALsizei freq ) { } ++ ++ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent( ALCcontext *alcHandle ) { ++ return 0; ++} ++ ++ALC_API ALCvoid ALC_APIENTRY alcProcessContext( ALCcontext *alcHandle ) { ++ return; ++} ++ ++ALC_API ALCvoid ALC_APIENTRY alcDestroyContext( ALCcontext *alcHandle ) { ++ return; ++} ++ ++ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *deviceHandle, ALCenum token ) { ++ return NULL; ++} ++ ++AL_API void AL_APIENTRY alBufferData( ALuint buffer, ++ ALenum format, ++ ALvoid* data, ++ ALsizei size, ++ ALsizei freq ) { } ++ ++AL_API void AL_APIENTRY alDeleteBuffers( ALsizei n, ALuint* buffers ) { } ++ ++AL_API ALboolean AL_APIENTRY alIsExtensionPresent( ALubyte* fname ) { ++ return AL_FALSE; ++} ++ ++AL_API void AL_APIENTRY alDeleteSources( ALsizei n, const ALuint* sources ) { } ++ ++AL_API ALenum AL_APIENTRY alGetEnumValue( const ALchar* ename ) { ++ return 0; ++} ++ ++AL_API void* AL_APIENTRY alGetProcAddress( const ALchar* fname ) { ++ return NULL; ++} ++ ++ALC_API ALCcontext * ALC_APIENTRY alcCreateContext( ALCdevice *dev, ++ const ALCint* attrlist ) { ++ return NULL; ++} ++ ++ALC_API ALCdevice * ALC_APIENTRY alcOpenDevice( ALubyte *tokstr ) { ++ return NULL; ++} ++ ++AL_API void AL_APIENTRY alListenerfv( ALenum pname, const ALfloat* param ) { } ++ ++AL_API void AL_APIENTRY alSourceQueueBuffers( ALuint sid, ALsizei numEntries, const ALuint *bids ) { } ++ ++AL_API void AL_APIENTRY alSourcei( ALuint sid, ALenum param, ALint value ) { } ++ ++AL_API void AL_APIENTRY alListenerf( ALenum pname, ALfloat param ) { } ++ ++ALC_API ALCboolean ALC_APIENTRY alcCloseDevice( ALCdevice *dev ) { return false; } ++ ++AL_API ALboolean AL_APIENTRY alIsBuffer( ALuint buffer ) { ++ return AL_FALSE; ++} ++ ++AL_API void AL_APIENTRY alSource3f( ALuint sid, ALenum param, ++ ALfloat f1, ALfloat f2, ALfloat f3 ) { } ++ ++AL_API void AL_APIENTRY alGenSources( ALsizei n, ALuint* sources ) { } ++ ++AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value ) { } ++ ++AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids ) { } ++ ++AL_API void AL_APIENTRY alSourcePlay( ALuint sid ) { } diff --git a/games/idtech4a-engine/patches/patch-sys_stub_stub_gl_cpp b/games/idtech4a-engine/patches/patch-sys_stub_stub_gl_cpp new file mode 100644 index 000000000..14bdf47c7 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_stub_stub_gl_cpp @@ -0,0 +1,399 @@ +Index: sys/stub/stub_gl.cpp +--- sys/stub/stub_gl.cpp.orig ++++ sys/stub/stub_gl.cpp +@@ -0,0 +1,395 @@ ++/* ++=========================================================================== ++ ++Doom 3 GPL Source Code ++Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. ++ ++This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). ++ ++Doom 3 Source Code is free software: you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation, either version 3 of the License, or ++(at your option) any later version. ++ ++Doom 3 Source Code is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with Doom 3 Source Code. If not, see . ++ ++In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. ++ ++If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. ++ ++=========================================================================== ++*/ ++#include "../../idlib/precompiled.h" ++#pragma hdrstop ++ ++#include "../../renderer/tr_local.h" ++ ++void glAccum(GLenum op, GLfloat value){}; ++void glAlphaFunc(GLenum func, GLclampf ref){}; ++GLboolean glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences){ return false; }; ++void glArrayElement(GLint i){}; ++void glBegin(GLenum mode){}; ++void glBindTexture(GLenum target, GLuint texture){}; ++void glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap){}; ++void glBlendFunc(GLenum sfactor, GLenum dfactor){}; ++void glCallList(GLuint list){}; ++void glCallLists(GLsizei n, GLenum type, const GLvoid *lists){}; ++void glClear(GLbitfield mask){}; ++void glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha){}; ++void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){}; ++void glClearDepth(GLclampd depth){}; ++void glClearIndex(GLfloat c){}; ++void glClearStencil(GLint s){}; ++void glClipPlane(GLenum plane, const GLdouble *equation){}; ++void glColor3b(GLbyte red, GLbyte green, GLbyte blue){}; ++void glColor3bv(const GLbyte *v){}; ++void glColor3d(GLdouble red, GLdouble green, GLdouble blue){}; ++void glColor3dv(const GLdouble *v){}; ++void glColor3f(GLfloat red, GLfloat green, GLfloat blue){}; ++void glColor3fv(const GLfloat *v){}; ++void glColor3i(GLint red, GLint green, GLint blue){}; ++void glColor3iv(const GLint *v){}; ++void glColor3s(GLshort red, GLshort green, GLshort blue){}; ++void glColor3sv(const GLshort *v){}; ++void glColor3ub(GLubyte red, GLubyte green, GLubyte blue){}; ++void glColor3ubv(const GLubyte *v){}; ++void glColor3ui(GLuint red, GLuint green, GLuint blue){}; ++void glColor3uiv(const GLuint *v){}; ++void glColor3us(GLushort red, GLushort green, GLushort blue){}; ++void glColor3usv(const GLushort *v){}; ++void glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha){}; ++void glColor4bv(const GLbyte *v){}; ++void glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha){}; ++void glColor4dv(const GLdouble *v){}; ++void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha){}; ++void glColor4fv(const GLfloat *v){}; ++void glColor4i(GLint red, GLint green, GLint blue, GLint alpha){}; ++void glColor4iv(const GLint *v){}; ++void glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha){}; ++void glColor4sv(const GLshort *v){}; ++void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha){}; ++void glColor4ubv(const GLubyte *v){}; ++void glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha){}; ++void glColor4uiv(const GLuint *v){}; ++void glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha){}; ++void glColor4usv(const GLushort *v){}; ++void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha){}; ++void glColorMaterial(GLenum face, GLenum mode){}; ++void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){}; ++void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type){}; ++void glCopyTexImage1D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border){}; ++void glCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border){}; ++void glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width){}; ++void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height){}; ++void glCullFace(GLenum mode){}; ++void glDeleteLists(GLuint list, GLsizei range){}; ++void glDeleteTextures(GLsizei n, const GLuint *textures){}; ++void glDepthFunc(GLenum func){}; ++void glDepthMask(GLboolean flag){}; ++void glDepthRange(GLclampd zNear, GLclampd zFar){}; ++void glDisable(GLenum cap){}; ++void glDisableClientState(GLenum array){}; ++void glDrawArrays(GLenum mode, GLint first, GLsizei count){}; ++void glDrawBuffer(GLenum mode){}; ++void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices){}; ++void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels){}; ++void glEdgeFlag(GLboolean flag){}; ++void glEdgeFlagPointer(GLsizei stride, const GLvoid *pointer){}; ++void glEdgeFlagv(const GLboolean *flag){}; ++void glEnable(GLenum cap){}; ++void glEnableClientState(GLenum array){}; ++void glEnd(void){}; ++void glEndList(void){}; ++void glEvalCoord1d(GLdouble u){}; ++void glEvalCoord1dv(const GLdouble *u){}; ++void glEvalCoord1f(GLfloat u){}; ++void glEvalCoord1fv(const GLfloat *u){}; ++void glEvalCoord2d(GLdouble u, GLdouble v){}; ++void glEvalCoord2dv(const GLdouble *u){}; ++void glEvalCoord2f(GLfloat u, GLfloat v){}; ++void glEvalCoord2fv(const GLfloat *u){}; ++void glEvalMesh1(GLenum mode, GLint i1, GLint i2){}; ++void glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2){}; ++void glEvalPoint1(GLint i){}; ++void glEvalPoint2(GLint i, GLint j){}; ++void glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer){}; ++void glFinish(void){}; ++void glFlush(void){}; ++void glFogf(GLenum pname, GLfloat param){}; ++void glFogfv(GLenum pname, const GLfloat *params){}; ++void glFogi(GLenum pname, GLint param){}; ++void glFogiv(GLenum pname, const GLint *params){}; ++void glFrontFace(GLenum mode){}; ++void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){}; ++GLuint glGenLists(GLsizei range){return 0;}; ++void glGenTextures(GLsizei n, GLuint *textures){}; ++void glGetBooleanv(GLenum pname, GLboolean *params){}; ++void glGetClipPlane(GLenum plane, GLdouble *equation){}; ++void glGetDoublev(GLenum pname, GLdouble *params){}; ++GLenum glGetError(void){return 0;}; ++void glGetFloatv(GLenum pname, GLfloat *params){}; ++void glGetIntegerv(GLenum pname, GLint *params){ ++ switch( pname ) { ++ case GL_MAX_TEXTURE_SIZE: *params = 1024; break; ++ case GL_MAX_TEXTURE_UNITS_ARB: *params = 2; break; ++ default: *params = 0; break; ++ } ++}; ++void glGetLightfv(GLenum light, GLenum pname, GLfloat *params){}; ++void glGetLightiv(GLenum light, GLenum pname, GLint *params){}; ++void glGetMapdv(GLenum target, GLenum query, GLdouble *v){}; ++void glGetMapfv(GLenum target, GLenum query, GLfloat *v){}; ++void glGetMapiv(GLenum target, GLenum query, GLint *v){}; ++void glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params){}; ++void glGetMaterialiv(GLenum face, GLenum pname, GLint *params){}; ++void glGetPixelMapfv(GLenum map, GLfloat *values){}; ++void glGetPixelMapuiv(GLenum map, GLuint *values){}; ++void glGetPixelMapusv(GLenum map, GLushort *values){}; ++void glGetPointerv(GLenum pname, GLvoid* *params){}; ++void glGetPolygonStipple(GLubyte *mask){}; ++const GLubyte * glGetString(GLenum name){ ++ switch( name ) { ++ case GL_EXTENSIONS: return (GLubyte *)"GL_ARB_multitexture GL_ARB_texture_env_combine GL_ARB_texture_cube_map GL_ARB_texture_env_dot3"; ++ } ++ return (const GLubyte *)""; ++}; ++void glGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params){}; ++void glGetTexEnviv(GLenum target, GLenum pname, GLint *params){}; ++void glGetTexGendv(GLenum coord, GLenum pname, GLdouble *params){}; ++void glGetTexGenfv(GLenum coord, GLenum pname, GLfloat *params){}; ++void glGetTexGeniv(GLenum coord, GLenum pname, GLint *params){}; ++void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels){}; ++void glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params){}; ++void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params){}; ++void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params){}; ++void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params){}; ++void glHint(GLenum target, GLenum mode){}; ++void glIndexMask(GLuint mask){}; ++void glIndexPointer(GLenum type, GLsizei stride, const GLvoid *pointer){}; ++void glIndexd(GLdouble c){}; ++void glIndexdv(const GLdouble *c){}; ++void glIndexf(GLfloat c){}; ++void glIndexfv(const GLfloat *c){}; ++void glIndexi(GLint c){}; ++void glIndexiv(const GLint *c){}; ++void glIndexs(GLshort c){}; ++void glIndexsv(const GLshort *c){}; ++void glIndexub(GLubyte c){}; ++void glIndexubv(const GLubyte *c){}; ++void glInitNames(void){}; ++void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer){}; ++GLboolean glIsEnabled(GLenum cap){ return false; }; ++GLboolean glIsList(GLuint list){ return false; }; ++GLboolean glIsTexture(GLuint texture){ return false; }; ++void glLightModelf(GLenum pname, GLfloat param){}; ++void glLightModelfv(GLenum pname, const GLfloat *params){}; ++void glLightModeli(GLenum pname, GLint param){}; ++void glLightModeliv(GLenum pname, const GLint *params){}; ++void glLightf(GLenum light, GLenum pname, GLfloat param){}; ++void glLightfv(GLenum light, GLenum pname, const GLfloat *params){}; ++void glLighti(GLenum light, GLenum pname, GLint param){}; ++void glLightiv(GLenum light, GLenum pname, const GLint *params){}; ++void glLineStipple(GLint factor, GLushort pattern){}; ++void glLineWidth(GLfloat width){}; ++void glListBase(GLuint base){}; ++void glLoadIdentity(void){}; ++void glLoadMatrixd(const GLdouble *m){}; ++void glLoadMatrixf(const GLfloat *m){}; ++void glLoadName(GLuint name){}; ++void glLogicOp(GLenum opcode){}; ++void glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points){}; ++void glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points){}; ++void glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points){}; ++void glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points){}; ++void glMapGrid1d(GLint un, GLdouble u1, GLdouble u2){}; ++void glMapGrid1f(GLint un, GLfloat u1, GLfloat u2){}; ++void glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2){}; ++void glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2){}; ++void glMaterialf(GLenum face, GLenum pname, GLfloat param){}; ++void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params){}; ++void glMateriali(GLenum face, GLenum pname, GLint param){}; ++void glMaterialiv(GLenum face, GLenum pname, const GLint *params){}; ++void glMatrixMode(GLenum mode){}; ++void glMultMatrixd(const GLdouble *m){}; ++void glMultMatrixf(const GLfloat *m){}; ++void glNewList(GLuint list, GLenum mode){}; ++void glNormal3b(GLbyte nx, GLbyte ny, GLbyte nz){}; ++void glNormal3bv(const GLbyte *v){}; ++void glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz){}; ++void glNormal3dv(const GLdouble *v){}; ++void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz){}; ++void glNormal3fv(const GLfloat *v){}; ++void glNormal3i(GLint nx, GLint ny, GLint nz){}; ++void glNormal3iv(const GLint *v){}; ++void glNormal3s(GLshort nx, GLshort ny, GLshort nz){}; ++void glNormal3sv(const GLshort *v){}; ++void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer){}; ++void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){}; ++void glPassThrough(GLfloat token){}; ++void glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values){}; ++void glPixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values){}; ++void glPixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values){}; ++void glPixelStoref(GLenum pname, GLfloat param){}; ++void glPixelStorei(GLenum pname, GLint param){}; ++void glPixelTransferf(GLenum pname, GLfloat param){}; ++void glPixelTransferi(GLenum pname, GLint param){}; ++void glPixelZoom(GLfloat xfactor, GLfloat yfactor){}; ++void glPointSize(GLfloat size){}; ++void glPolygonMode(GLenum face, GLenum mode){}; ++void glPolygonOffset(GLfloat factor, GLfloat units){}; ++void glPolygonStipple(const GLubyte *mask){}; ++void glPopAttrib(void){}; ++void glPopClientAttrib(void){}; ++void glPopMatrix(void){}; ++void glPopName(void){}; ++void glPrioritizeTextures(GLsizei n, const GLuint *textures, const GLclampf *priorities){}; ++void glPushAttrib(GLbitfield mask){}; ++void glPushClientAttrib(GLbitfield mask){}; ++void glPushMatrix(void){}; ++void glPushName(GLuint name){}; ++void glRasterPos2d(GLdouble x, GLdouble y){}; ++void glRasterPos2dv(const GLdouble *v){}; ++void glRasterPos2f(GLfloat x, GLfloat y){}; ++void glRasterPos2fv(const GLfloat *v){}; ++void glRasterPos2i(GLint x, GLint y){}; ++void glRasterPos2iv(const GLint *v){}; ++void glRasterPos2s(GLshort x, GLshort y){}; ++void glRasterPos2sv(const GLshort *v){}; ++void glRasterPos3d(GLdouble x, GLdouble y, GLdouble z){}; ++void glRasterPos3dv(const GLdouble *v){}; ++void glRasterPos3f(GLfloat x, GLfloat y, GLfloat z){}; ++void glRasterPos3fv(const GLfloat *v){}; ++void glRasterPos3i(GLint x, GLint y, GLint z){}; ++void glRasterPos3iv(const GLint *v){}; ++void glRasterPos3s(GLshort x, GLshort y, GLshort z){}; ++void glRasterPos3sv(const GLshort *v){}; ++void glRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w){}; ++void glRasterPos4dv(const GLdouble *v){}; ++void glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w){}; ++void glRasterPos4fv(const GLfloat *v){}; ++void glRasterPos4i(GLint x, GLint y, GLint z, GLint w){}; ++void glRasterPos4iv(const GLint *v){}; ++void glRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w){}; ++void glRasterPos4sv(const GLshort *v){}; ++void glReadBuffer(GLenum mode){}; ++void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels){}; ++void glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2){}; ++void glRectdv(const GLdouble *v1, const GLdouble *v2){}; ++void glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2){}; ++void glRectfv(const GLfloat *v1, const GLfloat *v2){}; ++void glRecti(GLint x1, GLint y1, GLint x2, GLint y2){}; ++void glRectiv(const GLint *v1, const GLint *v2){}; ++void glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2){}; ++void glRectsv(const GLshort *v1, const GLshort *v2){}; ++GLint glRenderMode(GLenum mode){ return 0; }; ++void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z){}; ++void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z){}; ++void glScaled(GLdouble x, GLdouble y, GLdouble z){}; ++void glScalef(GLfloat x, GLfloat y, GLfloat z){}; ++void glScissor(GLint x, GLint y, GLsizei width, GLsizei height){}; ++void glSelectBuffer(GLsizei size, GLuint *buffer){}; ++void glShadeModel(GLenum mode){}; ++void glStencilFunc(GLenum func, GLint ref, GLuint mask){}; ++void glStencilMask(GLuint mask){}; ++void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass){}; ++void glTexCoord1d(GLdouble s){}; ++void glTexCoord1dv(const GLdouble *v){}; ++void glTexCoord1f(GLfloat s){}; ++void glTexCoord1fv(const GLfloat *v){}; ++void glTexCoord1i(GLint s){}; ++void glTexCoord1iv(const GLint *v){}; ++void glTexCoord1s(GLshort s){}; ++void glTexCoord1sv(const GLshort *v){}; ++void glTexCoord2d(GLdouble s, GLdouble t){}; ++void glTexCoord2dv(const GLdouble *v){}; ++void glTexCoord2f(GLfloat s, GLfloat t){}; ++void glTexCoord2fv(const GLfloat *v){}; ++void glTexCoord2i(GLint s, GLint t){}; ++void glTexCoord2iv(const GLint *v){}; ++void glTexCoord2s(GLshort s, GLshort t){}; ++void glTexCoord2sv(const GLshort *v){}; ++void glTexCoord3d(GLdouble s, GLdouble t, GLdouble r){}; ++void glTexCoord3dv(const GLdouble *v){}; ++void glTexCoord3f(GLfloat s, GLfloat t, GLfloat r){}; ++void glTexCoord3fv(const GLfloat *v){}; ++void glTexCoord3i(GLint s, GLint t, GLint r){}; ++void glTexCoord3iv(const GLint *v){}; ++void glTexCoord3s(GLshort s, GLshort t, GLshort r){}; ++void glTexCoord3sv(const GLshort *v){}; ++void glTexCoord4d(GLdouble s, GLdouble t, GLdouble r, GLdouble q){}; ++void glTexCoord4dv(const GLdouble *v){}; ++void glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q){}; ++void glTexCoord4fv(const GLfloat *v){}; ++void glTexCoord4i(GLint s, GLint t, GLint r, GLint q){}; ++void glTexCoord4iv(const GLint *v){}; ++void glTexCoord4s(GLshort s, GLshort t, GLshort r, GLshort q){}; ++void glTexCoord4sv(const GLshort *v){}; ++void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){}; ++void glTexEnvf(GLenum target, GLenum pname, GLfloat param){}; ++void glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params){}; ++void glTexEnvi(GLenum target, GLenum pname, GLint param){}; ++void glTexEnviv(GLenum target, GLenum pname, const GLint *params){}; ++void glTexGend(GLenum coord, GLenum pname, GLdouble param){}; ++void glTexGendv(GLenum coord, GLenum pname, const GLdouble *params){}; ++void glTexGenf(GLenum coord, GLenum pname, GLfloat param){}; ++void glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params){}; ++void glTexGeni(GLenum coord, GLenum pname, GLint param){}; ++void glTexGeniv(GLenum coord, GLenum pname, const GLint *params){}; ++void glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels){}; ++void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {}; ++void glTexParameterf(GLenum target, GLenum pname, GLfloat param){}; ++void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params){}; ++void glTexParameteri(GLenum target, GLenum pname, GLint param){}; ++void glTexParameteriv(GLenum target, GLenum pname, const GLint *params){}; ++void glTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels){}; ++void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels){}; ++void glTranslated(GLdouble x, GLdouble y, GLdouble z){}; ++void glTranslatef(GLfloat x, GLfloat y, GLfloat z){}; ++void glVertex2d(GLdouble x, GLdouble y){}; ++void glVertex2dv(const GLdouble *v){}; ++void glVertex2f(GLfloat x, GLfloat y){}; ++void glVertex2fv(const GLfloat *v){}; ++void glVertex2i(GLint x, GLint y){}; ++void glVertex2iv(const GLint *v){}; ++void glVertex2s(GLshort x, GLshort y){}; ++void glVertex2sv(const GLshort *v){}; ++void glVertex3d(GLdouble x, GLdouble y, GLdouble z){}; ++void glVertex3dv(const GLdouble *v){}; ++void glVertex3f(GLfloat x, GLfloat y, GLfloat z){}; ++void glVertex3fv(const GLfloat *v){}; ++void glVertex3i(GLint x, GLint y, GLint z){}; ++void glVertex3iv(const GLint *v){}; ++void glVertex3s(GLshort x, GLshort y, GLshort z){}; ++void glVertex3sv(const GLshort *v){}; ++void glVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w){}; ++void glVertex4dv(const GLdouble *v){}; ++void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w){}; ++void glVertex4fv(const GLfloat *v){}; ++void glVertex4i(GLint x, GLint y, GLint z, GLint w){}; ++void glVertex4iv(const GLint *v){}; ++void glVertex4s(GLshort x, GLshort y, GLshort z, GLshort w){}; ++void glVertex4sv(const GLshort *v){}; ++void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){}; ++void glViewport(GLint x, GLint y, GLsizei width, GLsizei height){}; ++ ++void GLimp_WakeBackEnd(void*a) {}; ++void GLimp_EnableLogging(bool) {}; ++void GLimp_FrontEndSleep() {}; ++void GLimp_ActivateContext() {}; ++void GLimp_DeactivateContext() {}; ++bool GLimp_SpawnRenderThread(void (*a)()) {return false;}; ++ ++static void StubFunction( void ) {}; ++GLExtension_t GLimp_ExtensionPointer( const char *a) { return StubFunction; }; ++ ++bool GLimp_Init(glimpParms_t a) {return true;}; ++void GLimp_SetGamma(unsigned short*a, unsigned short*b, unsigned short*c) {}; ++void GLimp_Shutdown() {}; ++void GLimp_SwapBuffers() {}; ++void *GLimp_BackEndSleep() {return 0;}; diff --git a/games/idtech4a-engine/patches/patch-sys_sys_local_cpp b/games/idtech4a-engine/patches/patch-sys_sys_local_cpp new file mode 100644 index 000000000..a66f19640 --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_sys_local_cpp @@ -0,0 +1,12 @@ +Index: sys/sys_local.cpp +--- sys/sys_local.cpp.orig ++++ sys/sys_local.cpp +@@ -148,7 +148,7 @@ void idSysLocal::DLL_GetFileName(const char *baseName, + { + #ifdef _WIN32 + idStr::snPrintf(dllName, maxLength, "%s" CPUSTRING ".dll", baseName); +-#elif defined( __linux__ ) ++#elif defined( __OpenBSD__ ) + idStr::snPrintf(dllName, maxLength, "%s" CPUSTRING ".so", baseName); + #elif defined( MACOS_X ) + idStr::snPrintf(dllName, maxLength, "%s" ".dylib", baseName); diff --git a/games/idtech4a-engine/patches/patch-sys_sys_public_h b/games/idtech4a-engine/patches/patch-sys_sys_public_h new file mode 100644 index 000000000..e1df874cf --- /dev/null +++ b/games/idtech4a-engine/patches/patch-sys_sys_public_h @@ -0,0 +1,30 @@ +Index: sys/sys_public.h +--- sys/sys_public.h.orig ++++ sys/sys_public.h +@@ -111,7 +111,7 @@ bool Sys_IsMainThread(); + #endif + + // Linux +-#ifdef __linux__ ++#ifdef __OpenBSD__ + + #ifdef __ANDROID__ //karin: Android arch defines + +@@ -216,7 +216,7 @@ typedef enum { + CPUID_CMOV = 0x02000, // Conditional Move (CMOV) and fast floating point comparison (FCOMI) instructions + CPUID_FTZ = 0x04000, // Flush-To-Zero mode (denormal results are flushed to zero) + CPUID_DAZ = 0x08000 // Denormals-Are-Zero mode (denormal source operands are set to zero) +-} cpuid_t; ++} doom3_cpuid_t; + + typedef enum { + FPU_EXCEPTION_INVALID_OPERATION = 1, +@@ -429,7 +429,7 @@ void Sys_ShowConsole(int visLevel, bool quitOnClose) + + + void Sys_Mkdir(const char *path); +-ID_TIME_T Sys_FileTimeStamp(FILE *fp); ++long Sys_FileTimeStamp(FILE *fp); + // NOTE: do we need to guarantee the same output on all platforms? + const char *Sys_TimeStampToStr(ID_TIME_T timeStamp); + const char *Sys_DefaultCDPath(void); diff --git a/games/idtech4a-engine/pkg/DESCR b/games/idtech4a-engine/pkg/DESCR new file mode 100644 index 000000000..79f7ed1e1 --- /dev/null +++ b/games/idtech4a-engine/pkg/DESCR @@ -0,0 +1,9 @@ +idTech4A++ (Harmattan Edition) The engine provides the +ability to run Doom3/Quake4/Prey games based on the Android SDK +version of the games under the GPL-3 license. See: + +https://github.com/glKarin/idtech4amm_doom3_sdk +https://github.com/glKarin/idtech4amm_quake4_sdk +https://github.com/glKarin/idtech4amm_prey_sdk + +Note: to play the original game you will need a copy of the game data. \ No newline at end of file diff --git a/games/idtech4a-engine/pkg/PLIST b/games/idtech4a-engine/pkg/PLIST new file mode 100644 index 000000000..fc38318e1 --- /dev/null +++ b/games/idtech4a-engine/pkg/PLIST @@ -0,0 +1,22 @@ +@bin bin/idtech4a-doom3 +@bin bin/idtech4a-quake4 +@bin bin/idtech4a-prey +@bin lib/libcdoom.so +@bin lib/libd3le.so +@bin lib/libd3xp.so +@bin lib/libfraggingfree.so +@bin lib/libgame.so +@bin lib/libhardcorps.so +@bin lib/libhardqore.so +@bin lib/libhexeneoc.so +@bin lib/liblibrecoop.so +@bin lib/liblibrecoopxp.so +@bin lib/liboverthinked.so +@bin lib/libperfected.so +@bin lib/libperfected_roe.so +@bin lib/libpreygame.so +@bin lib/libq4game.so +@bin lib/librivensin.so +@bin lib/libsabot.so +@bin lib/libtfphobos.so +share/doc/pkg-readmes/${PKGSTEM} diff --git a/games/idtech4a-engine/pkg/README b/games/idtech4a-engine/pkg/README new file mode 100644 index 000000000..4cacbfe64 --- /dev/null +++ b/games/idtech4a-engine/pkg/README @@ -0,0 +1,17 @@ ++---------------------------------------------------------------------- +| Running ${PKGSTEM} on OpenBSD ++---------------------------------------------------------------------- + +Playing idTech4A++ (Harmattan Edition) Engime games requires the Steam +or GOG copy of the games. Copy all content of the original games to the +appropriate directories: + +~/.local/share/idtech4amm/doom3 +~/.local/share/idtech4amm/quake4 +~/.local/share/idtech4amm/prey + +These direcotories will contain user data, such as game settings, +log, and saves. + +For more information, see: +https://github.com/glKarin/com.n0n3m4.diii4a