diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index bdf69362f..88d0b8e1c 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -709,7 +709,6 @@ set (PCH_SOURCES build/src/a-c.cpp build/src/animvpx.cpp build/src/baselayer.cpp - build/src/cache1d.cpp build/src/clip.cpp build/src/colmatch.cpp build/src/common.cpp diff --git a/source/blood/src/common_game.h b/source/blood/src/common_game.h index e12eeb48f..07f0dec8c 100644 --- a/source/blood/src/common_game.h +++ b/source/blood/src/common_game.h @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #pragma once #include "baselayer.h" #include "build.h" -#include "cache1d.h" + #include "common.h" #include "pragmas.h" #include "misc.h" diff --git a/source/blood/src/config.cpp b/source/blood/src/config.cpp index d0e9b7b45..c37acc228 100644 --- a/source/blood/src/config.cpp +++ b/source/blood/src/config.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "baselayer.h" #include "common_game.h" #include "build.h" -#include "cache1d.h" + #include "sndcards.h" #include "hash.h" #include "renderlayer.h" diff --git a/source/blood/src/resource.cpp b/source/blood/src/resource.cpp index 7139f2598..6057ba44a 100644 --- a/source/blood/src/resource.cpp +++ b/source/blood/src/resource.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include "compat.h" -#include "cache1d.h" + #include "common_game.h" #include "misc.h" diff --git a/source/build/include/build.h b/source/build/include/build.h index 30acb47cc..6203bebaa 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -27,7 +27,7 @@ static_assert('\xff' == 255, "Char must be unsigned!"); #include "palette.h" #include "pragmas.h" -#include "cache1d.h" + #include "textures.h" #include "c_cvars.h" diff --git a/source/build/include/cache1d.h b/source/build/include/cache1d.h deleted file mode 100644 index 4e6983879..000000000 --- a/source/build/include/cache1d.h +++ /dev/null @@ -1,15 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jf@jonof.id.au) -// by the EDuke32 team (development@voidpoint.com) - -#ifndef cache1d_h_ -#define cache1d_h_ - -void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *newlockptr); - -#endif // cache1d_h_ - diff --git a/source/build/include/common.h b/source/build/include/common.h index c91407641..12c7546ca 100644 --- a/source/build/include/common.h +++ b/source/build/include/common.h @@ -7,7 +7,7 @@ #ifndef EDUKE32_COMMON_H_ #define EDUKE32_COMMON_H_ -#include "cache1d.h" + #include "compat.h" #include "pragmas.h" // klabs #include "scriptfile.h" diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 411d118f5..46a2e9343 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -7,7 +7,7 @@ #include "compat.h" #include "baselayer.h" #include "build.h" -#include "cache1d.h" + #include "matrix.h" #include "../../glbackend/glbackend.h" diff --git a/source/build/src/baselayer.cpp b/source/build/src/baselayer.cpp index f8253425c..e58a76b6a 100644 --- a/source/build/src/baselayer.cpp +++ b/source/build/src/baselayer.cpp @@ -7,7 +7,7 @@ #include "a.h" #include "polymost.h" -#include "cache1d.h" + #include "inputstate.h" #include "d_event.h" #include "../../glbackend/glbackend.h" diff --git a/source/build/src/cache1d.cpp b/source/build/src/cache1d.cpp deleted file mode 100644 index ce903189b..000000000 --- a/source/build/src/cache1d.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jf@jonof.id.au) -// by the EDuke32 team (development@voidpoint.com) - -#include -#include "tarray.h" -#include "cache1d.h" - -// Only the sound code still uses this - but it never frees the data. -// So we may just toss out the cache and do regular allocations. -// The TArray is merely for taking down the data before shutdown. -static TArray> pseudocache; - -void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *) -{ - pseudocache.Reserve(1); - auto& buffer = pseudocache.Last(); - buffer.Resize(newbytes); - *newhandle = reinterpret_cast(buffer.Data()); -} - diff --git a/source/build/src/common.cpp b/source/build/src/common.cpp index 5531f8d81..643b6476c 100644 --- a/source/build/src/common.cpp +++ b/source/build/src/common.cpp @@ -2,7 +2,7 @@ #include "compat.h" #include "build.h" #include "scriptfile.h" -#include "cache1d.h" + #include "baselayer.h" #include "common.h" diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 1dbb1c7aa..afa086d75 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -10,7 +10,7 @@ #include "engine_priv.h" #include "baselayer.h" #include "scriptfile.h" -#include "cache1d.h" + #include "common.h" #include "mdsprite.h" // md3model_t #include "colmatch.h" diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index bce1a3be7..7b3192d46 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -11,7 +11,7 @@ #include "a.h" #include "baselayer.h" #include "build.h" -#include "cache1d.h" + #include "colmatch.h" #include "common.h" #include "compat.h" diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index a7d1191e0..db9fc050e 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -10,7 +10,7 @@ #include "hightile.h" #include "polymost.h" #include "mdsprite.h" -#include "cache1d.h" + #include "common.h" #include "palette.h" #include "textures.h" diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index cf4c07e0e..49944fc74 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -11,7 +11,7 @@ #include "engine_priv.h" #include "baselayer.h" #include "colmatch.h" -#include "cache1d.h" + #include "palette.h" #include "a.h" #include "superfasthash.h" diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 16f27e654..8e8bc4da9 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -10,7 +10,7 @@ #include "a.h" #include "build.h" -#include "cache1d.h" + #include "common.h" #include "compat.h" #include "engine_priv.h" diff --git a/source/build/src/tiles.cpp b/source/build/src/tiles.cpp index 09b301025..4af93859d 100644 --- a/source/build/src/tiles.cpp +++ b/source/build/src/tiles.cpp @@ -10,7 +10,7 @@ #include "build.h" #include "baselayer.h" #include "engine_priv.h" -#include "cache1d.h" + // // copytilepiece diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 112f1d1c8..6c8254c40 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -10,7 +10,7 @@ #include "hightile.h" #include "polymost.h" #include "mdsprite.h" -#include "cache1d.h" + #include "palette.h" #include "../../glbackend/glbackend.h" diff --git a/source/common/fonts/v_font.cpp b/source/common/fonts/v_font.cpp index a11beba66..50037405c 100644 --- a/source/common/fonts/v_font.cpp +++ b/source/common/fonts/v_font.cpp @@ -47,7 +47,7 @@ #include "v_text.h" #include "image.h" #include "utf8.h" -#include "cache1d.h" + #include "m_png.h" #include "printf.h" #include "filesystem.h" diff --git a/source/common/openaudio.cpp b/source/common/openaudio.cpp index 423a17525..32d5eac60 100644 --- a/source/common/openaudio.cpp +++ b/source/common/openaudio.cpp @@ -1,5 +1,5 @@ -#include "cache1d.h" + #include "openaudio.h" #include "gamecvars.h" diff --git a/source/common/sound/s_soundinternal.h b/source/common/sound/s_soundinternal.h index f3823b5cd..0a4afa05b 100644 --- a/source/common/sound/s_soundinternal.h +++ b/source/common/sound/s_soundinternal.h @@ -216,6 +216,7 @@ enum // This cannot be remain as this, but for now it has to suffice. SOURCE_Actor, // Sound is coming from an actor. SOURCE_Ambient, // Sound is coming from a blood ambient definition. SOURCE_Unattached, // Sound is not attached to any particular emitter. + SOURCE_Player, // SW player sound (player in SW is not connected to a sprite so needs to be special.) }; @@ -310,7 +311,7 @@ public: void RelinkSound(int sourcetype, const void* from, const void* to, const FVector3* optpos); void ChangeSoundVolume(int sourcetype, const void* source, int channel, double dvolume); void ChangeSoundPitch(int sourcetype, const void* source, int channel, double pitch, int sound_id = -1); - bool IsSourcePlayingSomething(int sourcetype, const void* actor, int channel, int sound_id); + bool IsSourcePlayingSomething(int sourcetype, const void* actor, int channel, int sound_id = -1); // Stop and resume music, during game PAUSE. int GetSoundPlayingInfo(int sourcetype, const void* source, int sound_id); @@ -372,7 +373,7 @@ public: } bool isValidSoundId(int id) { - return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative; + return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative && S_sfx[id].lumpnum != sfx_empty; } template bool EnumerateChannels(func callback) diff --git a/source/common/textures/buildtiles.cpp b/source/common/textures/buildtiles.cpp index b0c6c8dd0..d061d84b1 100644 --- a/source/common/textures/buildtiles.cpp +++ b/source/common/textures/buildtiles.cpp @@ -37,7 +37,7 @@ #include "zstring.h" #include "textures.h" #include "image.h" -#include "cache1d.h" + #include "baselayer.h" #include "palette.h" #include "m_crc32.h" diff --git a/source/common/textures/formats/arttexture.cpp b/source/common/textures/formats/arttexture.cpp index b5c1157fd..624640d48 100644 --- a/source/common/textures/formats/arttexture.cpp +++ b/source/common/textures/formats/arttexture.cpp @@ -37,7 +37,7 @@ #include "templates.h" #include "bitmap.h" #include "image.h" -#include "cache1d.h" + #include "build.h" diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index e96b6e432..fb1fd4005 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "a.h" #include "baselayer.h" #include "build.h" -#include "cache1d.h" + #include "compat.h" #include "pragmas.h" #include "polymost.h" diff --git a/source/platform/win32/startwin.game.cpp b/source/platform/win32/startwin.game.cpp index c98b2c647..49cefd927 100644 --- a/source/platform/win32/startwin.game.cpp +++ b/source/platform/win32/startwin.game.cpp @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define ONLY_USERDEFS #include "build.h" -#include "cache1d.h" + #include "compat.h" #include "startwin.game.h" #include "windows_inc.h" diff --git a/source/platform/win32/winbits.cpp b/source/platform/win32/winbits.cpp index d68b23149..6b3ccafe7 100644 --- a/source/platform/win32/winbits.cpp +++ b/source/platform/win32/winbits.cpp @@ -6,7 +6,7 @@ #include "build.h" #include "baselayer.h" #include "osd.h" -#include "cache1d.h" + #include "zstring.h" #include "winbits.h" diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index 1c3991fd7..ec950d659 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "a.h" #include "baselayer.h" #include "build.h" -#include "cache1d.h" + #include "compat.h" #include "pragmas.h" diff --git a/source/sw/src/anim.cpp b/source/sw/src/anim.cpp index 7e892296f..65f52a614 100644 --- a/source/sw/src/anim.cpp +++ b/source/sw/src/anim.cpp @@ -26,7 +26,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "ns.h" #include "build.h" -#include "cache1d.h" + #include "keys.h" #include "mytypes.h" diff --git a/source/sw/src/demo.cpp b/source/sw/src/demo.cpp index 37afdfaee..7fc518b16 100644 --- a/source/sw/src/demo.cpp +++ b/source/sw/src/demo.cpp @@ -28,7 +28,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms //#define MAIN //#define QUIET #include "build.h" -#include "cache1d.h" + #include "keys.h" #include "names2.h" diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index edec0f361..ad53274fc 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -28,7 +28,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #define QUIET #include "build.h" #include "pragmas.h" -#include "cache1d.h" + #include "keys.h" #include "names2.h" diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 0b4f48db7..469e0cb45 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -44,7 +44,7 @@ Things required to make savegames work: #define QUIET #include "build.h" #include "baselayer.h" -#include "cache1d.h" + #include "osd.h" #include "renderlayer.h" @@ -274,7 +274,6 @@ int krandcount; void BOT_DeleteAllBots(void); void BotPlayerInsert(PLAYERp pp); void SybexScreen(void); -void DosScreen(void); void PlayTheme(void); void MenuLevel(void); void StatScreen(PLAYERp mpp); @@ -634,14 +633,8 @@ void TerminateGame(void) engineUnInit(); - //Terminate3DSounds(); // Kill the sounds linked list - UnInitSound(); - timerUninit(); - - if (CleanExit) - DosScreen(); - + Bexit(0); } bool LoadLevel(const char *filename) @@ -731,7 +724,6 @@ void MultiSharewareCheck(void) //uninitmultiplayers(); //uninitkeys(); engineUnInit(); - UnInitSound(); timerUninit(); Bexit(0); } @@ -1318,8 +1310,7 @@ TerminateLevel(void) StopSound(); Terminate3DSounds(); // Kill the 3d sounds linked list - //ClearSoundLocks(); - + // Clear all anims and any memory associated with them // Clear before killing sprites - save a little time //AnimClear(); @@ -2795,15 +2786,6 @@ void RunLevel(void) ready2send = 0; } -void swexit(int exitval) -{ - exit(exitval); -} - -void DosScreen(void) -{ -} - typedef struct { char notshareware; @@ -2813,20 +2795,7 @@ typedef struct const char *arg_descr; } CLI_ARG; -#if DEBUG -CLI_ARG cli_dbg_arg[] = -{ - {0, "/demosyncrecord", 13, "-demosyncrecord", "Demo sync record" }, - {0, "/demosynctest", 13, "-demosynctest", "Demo sync test" }, - {0, "/cam", 4, "-cam", "Camera test mode" }, - {0, "/debugactor", 11, "-debugactor", "No Actors" }, - {0, "/debuganim", 10, "-debuganim", "No Anims" }, - {0, "/debugso", 8, "-debugso", "No Sector Objects" }, - {0, "/debugsector", 12, "-debugsector", "No Sector Movement" }, - {0, "/debugpanel", 11, "-debugpanel", "No Panel" }, - {0, "/mono", 5, "-mono", "Mono" }, -}; -#endif + CLI_ARG cli_arg[] = diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 5d9de1bdb..4a1be8660 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1204,9 +1204,6 @@ struct PLAYERstruct SWBOOL IsAI; // Is this and AI character? short fta,ftq; // First time active and first time quote, for talking in multiplayer games short NumFootPrints; // Number of foot prints left to lay down - SWBOOL PlayerTalking; // Is player currently talking - int TalkVocnum; // Number of sound that player is using - int TalkVocHandle; // Handle of sound in sound queue, to access in Dose's code unsigned char WpnUziType; // Toggle between single or double uzi's if you own 2. unsigned char WpnShotgunType; // Shotgun has normal or fully automatic fire unsigned char WpnShotgunAuto; // 50-0 automatic shotgun rounds @@ -2277,8 +2274,10 @@ extern void DoPaletteFlash(PLAYERp pp); extern unsigned char palette_data[256][3]; extern SWBOOL NightVision; -int _PlayerSound(const char *file, int line, int num, int *x, int *y, int *z, Voc3D_Flags flags, PLAYERp pp); -#define PlayerSound(num, x, y, z, flags, pp) _PlayerSound(__FILE__, __LINE__, (num), (x), (y), (z), (flags), (pp)) +int _PlayerSound(int num, PLAYERp pp); +inline int PlayerSound(int num, int x, int y, int z, int flags, PLAYERp pp) { return _PlayerSound(num, pp); } +void StopPlayerSound(PLAYERp pp); + #define MAXSO (INT32_MAX) diff --git a/source/sw/src/mfile.h b/source/sw/src/mfile.h index 6ee541090..d8bdb9668 100644 --- a/source/sw/src/mfile.h +++ b/source/sw/src/mfile.h @@ -25,7 +25,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms //------------------------------------------------------------------------- #include "compat.h" -#include "cache1d.h" + #include "savegamehelp.h" BEGIN_SW_NS diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 286e088f9..7d57ee680 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -3648,7 +3648,6 @@ DoPlayerFall(PLAYERp pp) short i; int recoil_amt; int depth; - static int handle=0; // reset flag key for double jumps if (!TEST_SYNC_KEY(pp, SK_JUMP)) @@ -3680,7 +3679,6 @@ DoPlayerFall(PLAYERp pp) { PlayerSound(DIGI_FALLSCREAM, &pp->posx, &pp->posy, &pp->posz, v3df_dontpan|v3df_doppler|v3df_follow,pp); - handle = pp->TalkVocHandle; // Save id for later } else if (pp->jump_speed > 1300) { @@ -3730,15 +3728,6 @@ DoPlayerFall(PLAYERp pp) PlaySound(DIGI_HITGROUND, &pp->posx, &pp->posy, &pp->posz, v3df_follow|v3df_dontpan); } - if (FX_SoundValidAndActive(handle)) - { - // My sound code will detect the sound has stopped and clean up - // for you. - FX_StopSound(handle); - pp->PlayerTalking = FALSE; - handle = 0; - } - // i any kind of crawl key get rid of recoil if (DoPlayerTestCrawl(pp) || TEST_SYNC_KEY(pp, SK_CRAWL)) { @@ -5160,12 +5149,7 @@ DoPlayerStopDiveNoWarp(PLAYERp pp) if (!NoMeters) SetRedrawScreen(pp); - if (FX_SoundValidAndActive(pp->TalkVocHandle)) - { - FX_StopSound(pp->TalkVocHandle); - pp->TalkVocHandle = 0; - pp->PlayerTalking = FALSE; - } + StopPlayerSound(pp); // stop diving no warp PlayerSound(DIGI_SURFACE,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_follow|v3df_doppler,pp); @@ -5196,12 +5180,7 @@ DoPlayerStopDive(PLAYERp pp) if (!NoMeters) SetRedrawScreen(pp); - if (FX_SoundValidAndActive(pp->TalkVocHandle)) - { - FX_StopSound(pp->TalkVocHandle); - pp->TalkVocHandle = 0; - pp->PlayerTalking = FALSE; - } + StopPlayerSound(pp); // stop diving with warp PlayerSound(DIGI_SURFACE,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_follow|v3df_doppler,pp); diff --git a/source/sw/src/scrip2.cpp b/source/sw/src/scrip2.cpp index c98ce0b2c..d9b8016a2 100644 --- a/source/sw/src/scrip2.cpp +++ b/source/sw/src/scrip2.cpp @@ -27,7 +27,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "ns.h" // scriplib.c #include "build.h" -#include "cache1d.h" + #include "keys.h" #include "names2.h" diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index b62d47236..e8258a5ee 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -26,7 +26,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "ns.h" #include "compat.h" #include "build.h" -#include "cache1d.h" + #include "keys.h" @@ -52,16 +52,11 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "config.h" #include "menu/menu.h" #include "z_music.h" - -#ifdef _WIN32 -#include "sdlayer.h" -#endif +#include "sound/s_soundinternal.h" +#include "filesystem/filesystem.h" BEGIN_SW_NS -extern USERp User[MAXSPRITES]; -void DumpSounds(void); - // Parentally locked sounds list int PLocked_Sounds[] = { @@ -72,6 +67,79 @@ int PLocked_Sounds[] = 558,557 }; +// +// Includes digi.h to build the table +// + +#define DIGI_TABLE +VOC_INFO voc[] = +{ +#include "digi.h" +}; + +#undef DIGI_TABLE + +// +// Includes ambient.h to build the table of ambient sounds for game +// + +#define AMBIENT_TABLE +AMB_INFO ambarray[] = +{ +#include "ambient.h" +}; +#undef AMBIENT_TABLE +#define MAX_AMBIENT_SOUNDS 82 + + +//========================================================================== +// +// +// +//========================================================================== + +void InitFX(void) +{ + auto &S_sfx = soundEngine->GetSounds(); + S_sfx.Resize(countof(voc)); + for (auto& sfx : S_sfx) { sfx.Clear(); sfx.lumpnum = sfx_empty; } + for (size_t i = 1; i < countof(voc); i++) + { + auto& entry = voc[i]; + auto lump = fileSystem.FindFile(entry.name); + if (lump > 0) + { + auto& newsfx = S_sfx[i]; + newsfx.name = entry.name; + newsfx.lumpnum = lump; + newsfx.NearLimit = 6; + newsfx.UserData.Resize(sizeof(void*)); + auto p = (VOC_INFOp *)newsfx.UserData.Data(); + *p = &entry; // store a link to the static data. + } + } + soundEngine->HashSounds(); + for (auto& sfx : S_sfx) + { + soundEngine->CacheSound(&sfx); + } +} + + +//========================================================================== +// +// +// +//========================================================================== + + + + + +extern USERp User[MAXSPRITES]; +void DumpSounds(void); + + // Global vars used by ambient sounds to set spritenum of ambient sounds for later lookups in // the sprite array so FAFcansee can know the sound sprite's current sector location @@ -100,30 +168,6 @@ int loopflag; extern SWBOOL DemoMode; -// -// Includes digi.h to build the table -// - -#define DIGI_TABLE -VOC_INFO voc[] = -{ -#include "digi.h" -}; - -#undef DIGI_TABLE - -// -// Includes ambient.h to build the table of ambient sounds for game -// - -#define AMBIENT_TABLE -AMB_INFO ambarray[] = -{ -#include "ambient.h" -}; -#undef AMBIENT_TABLE -#define MAX_AMBIENT_SOUNDS 82 - SWBOOL OpenSound(VOC_INFOp vp, FileReader &handle, int *length); int ReadSound(FileReader & handle, VOC_INFOp vp, int length); @@ -134,56 +178,6 @@ VOC3D_INFOp Insert3DSound(void); // Routine called when a sound is finished playing // -void -SoundCallBack(intptr_t num) -{ - VOC_INFOp vp; - - if ((int) num == MUSIC_ID) - { - return; - } - - // RTS sounds are negative - if ((int)num < 0) - { - return; - } - - vp = &voc[num]; -} - -// - -void -ClearSoundLocks(void) -{ -} - -void -UnInitSound(void) -{ - SoundShutdown(); - Mus_Stop(); -} - -void -InitFX(void) -{ - VOC_INFOp vp; - short i; - - // Select which cards to use - SoundStartup(); - - for (vp = voc; vp < &voc[SIZ(voc)]; vp++) - { - vp->playing = 0; - } - - // Set up our fx callback so we can display the sounds that are playing - FX_SetCallBack(SoundCallBack); -} void @@ -276,96 +270,6 @@ short SoundAngle(int x, int y) return delta_angle >> 4; } -int _PlayerSound(const char *file, int line, int num, int *x, int *y, int *z, Voc3D_Flags flags, PLAYERp pp) -{ - int handle; - VOC_INFOp vp; - - if (Prediction) - return 0; - - if (pp < Player || pp >= Player + MAX_SW_PLAYERS) - { - TerminateGame(); - printf("Player Sound invalid player: file %s, line %d\n",file,line); - exit(0); - } - - PRODUCTION_ASSERT(pp >= Player && pp < Player+MAX_SW_PLAYERS); - PRODUCTION_ASSERT(num >= 0 && num < DIGI_MAX); - - if (TEST(pp->Flags, PF_DEAD)) return 0; // You're dead, no talking! - - // If this is a player voice and he's already yacking, forget it. - vp = &voc[num]; - if (vp == NULL) - { - TerminateGame(); - printf("vp == NULL in PlayerSound, num = %d\n",num); - exit(0); - } - - // Not a player voice, bail. - if (vp->priority != PRI_PLAYERVOICE && vp->priority != PRI_PLAYERDEATH) - return 0; - - // He wasn't talking, but he will be now. - if (!pp->PlayerTalking) - { - pp->PlayerTalking = TRUE; - pp->TalkVocnum = num; // Set the voc number - pp->TalkVocHandle = PlaySound(num, x, y, z, flags); // Play the sound - if (pp->TalkVocHandle < 0) - { - pp->PlayerTalking = FALSE; - pp->TalkVocnum = -1; - pp->TalkVocHandle = -1; - } - } - - return 0; -} - -void LockSound(int num) -{ -} - -SWBOOL CacheSound(int num, int type) -{ - VOC_INFOp vp = &voc[num]; - - PRODUCTION_ASSERT(num >= 0 && num < DIGI_MAX); - - // if no data we need to cache it in - if (!vp->data) - { - FileReader handle; - int length; - - if (!OpenSound(vp, handle, &length)) - { - sprintf(ds,"Could not open sound %s, num %d, priority %d\n",vp->name,num,vp->priority); - OSD_Printf("%s", ds); - return FALSE; - } - - if (vp != NULL) - { - vp->lock = CACHE_UNLOCK_MAX; - - cacheAllocateBlock((intptr_t*)&vp->data, length, &vp->lock); - - /////// - - ASSERT(vp->data); - ReadSound(handle, vp, length); - - } - } - - return TRUE; -} - //////////////////////////////////////////////////////////////////////////// // Play a sound //////////////////////////////////////////////////////////////////////////// @@ -489,7 +393,6 @@ int PlaySound(int num, int *x, int *y, int *z, Voc3D_Flags flags) tx=sp->x; ty=sp->y; tz=sp->z; - //CON_Message("Using sp to set tx=%ld,ty=%ld,tz=%ld",tx,ty,tz); } // Calculate sound angle @@ -507,9 +410,6 @@ int PlaySound(int num, int *x, int *y, int *z, Voc3D_Flags flags) v3p->doplr_delta = sound_dist; // Save of distance for doppler // effect -// //DSPRINTF(ds,"sound dist = %d\n",sound_dist); -// MONO_PRINT(ds); - // Can the ambient sound see the player? If not, tone it down some. if ((vp->voc_flags & vf_loop) && Use_SoundSpriteNum && SoundSpriteNum >= 0) { @@ -534,6 +434,7 @@ int PlaySound(int num, int *x, int *y, int *z, Voc3D_Flags flags) priority = v3p->priority; } + /* if (!CacheSound(num, CACHE_SOUND_PLAY)) { v3p->flags = v3df_kill; @@ -541,9 +442,7 @@ int PlaySound(int num, int *x, int *y, int *z, Voc3D_Flags flags) v3p->dist = 0; v3p->deleted = TRUE; // Sound init failed, remove it! return -1; - } - - LockSound(num); + }*/ if (sound_dist < 5) angle = 0; @@ -626,65 +525,6 @@ void PlaySoundRTS(int rts_num) voice = FX_Play3D(rtsptr, RTS_SoundLength(rts_num - 1), FX_ONESHOT, 0, 0, 0, 255, 1.f, -rts_num); // [JM] Float volume here too I bet. !CHECKME! } -/////////////////////////////////////////////// - -SWBOOL -OpenSound(VOC_INFOp vp, FileReader &handle, int *length) -{ - handle = fileSystem.OpenFileReader(vp->name, 0); - - if (!handle.isOpen()) - { - return FALSE; - } - - *length = handle.GetLength(); - - return TRUE; -} - - -int -ReadSound(FileReader &handle, VOC_INFOp vp, int length) -{ - if (handle.Read(vp->data, length) != length) - { - TerminateGame(); - printf("Error reading file '%s'.\n", vp->name); - exit(0); - } - - vp->datalen = length; - return 0; -} - -void -SoundStartup(void) -{ - void *initdata = 0; - - -#ifdef MIXERTYPEWIN - initdata = (void *) win_gethwnd(); -#endif - - //snd_enabled = TRUE; - - - int status = FX_Init(snd_numvoices, snd_numchannels, snd_mixrate, initdata); - if (status != FX_Ok) - { - buildprintf("Sound error: %s\n", FX_ErrorString(status)); - return; - } - - FxInitialized = TRUE; - snd_fxvolume.Callback(); - snd_reversestereo.Callback(); - - FX_SetCallBack(SoundCallBack); -} - /* =================== = @@ -693,19 +533,6 @@ SoundStartup(void) =================== */ -void -SoundShutdown(void) -{ - if (!FxInitialized) - return; - - int status = FX_Shutdown(); - if (status != FX_Ok) - { - buildprintf("Sound error: %s\n", FX_ErrorString(status)); - } -} - void COVER_SetReverb(int amt) { @@ -905,23 +732,6 @@ Delete3DSounds(void) { printf("Delete3DSounds(): NULL vp->vp\n"); } - else // JBF: added null check - if (vp->vp->priority == PRI_PLAYERVOICE || vp->vp->priority == PRI_PLAYERDEATH) - { - int16_t pnum; - - TRAVERSE_CONNECT(pnum) - { - pp = &Player[pnum]; - - if (vp->num == pp->TalkVocnum) - { - pp->PlayerTalking = FALSE; - pp->TalkVocnum = -1; - pp->TalkVocHandle = -1; - } - } - } dp = vp; // Point to sound to be deleted if (vp->prev) @@ -1008,10 +818,6 @@ DoTimedSound(VOC3D_INFOp p) } p->tics = 0; - //while (p->tics >= p->maxtics) // Really stupid thing to do! - // { - // p->tics -= p->maxtics; - // } } } @@ -1355,7 +1161,6 @@ Terminate3DSounds(void) } Delete3DSounds(); // Now delete all remaining sounds - ClearSoundLocks(); } @@ -1483,13 +1288,58 @@ int PlayerYellVocs[] = DIGI_PLAYERYELL3 }; -/* -============================================================================ -= -= PLays music -= -============================================================================ -*/ + + +//========================================================================== +// +// +// +//========================================================================== + +int _PlayerSound(int num, PLAYERp pp) +{ + int handle; + VOC_INFOp vp; + + if (Prediction) + return 0; + + if (pp < Player || pp >= Player + MAX_SW_PLAYERS) + { + return 0; + } + + if (num < 0 || num >= DIGI_MAX || !soundEngine->isValidSoundId(num)) + return 0; + + if (TEST(pp->Flags, PF_DEAD)) return 0; // You're dead, no talking! + + // If this is a player voice and he's already yacking, forget it. + vp = &voc[num]; + + // Not a player voice, bail. + if (vp->priority != PRI_PLAYERVOICE && vp->priority != PRI_PLAYERDEATH) + return 0; + + // He wasn't talking, but he will be now. + if (!soundEngine->IsSourcePlayingSomething(SOURCE_Player, pp, CHAN_VOICE)) + { + soundEngine->StartSound(SOURCE_Player, pp, nullptr, CHAN_VOICE, 0, num, 1.f, ATTN_NORM); + } + + return 0; +} + +void StopPlayerSound(PLAYERp pp) +{ + soundEngine->StopSound(SOURCE_Player, pp, CHAN_VOICE); +} + +//========================================================================== +// +// PLays music +// +//========================================================================== extern short Level; CVAR(Bool, sw_nothememidi, false, CVAR_ARCHIVE) diff --git a/source/sw/src/sounds.h b/source/sw/src/sounds.h index e5b4af630..5d9d27635 100644 --- a/source/sw/src/sounds.h +++ b/source/sw/src/sounds.h @@ -143,7 +143,7 @@ struct VOCstruct int16_t voc_num; // Backward reference to parent sound int voc_distance; // Sound's distance effectiveness Voc_Flags voc_flags; // Various allowable flag settings for voc - uint8_t lock; // locking byte for caching + uint16_t lock; // locking byte for caching uint8_t playing; // number of this type of sound currently playing };