From a845e9f59600c6443cfca0517d9c30ee9f0904b9 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 26 Oct 2004 07:37:19 +0000 Subject: [PATCH] S_LoadSound now automatically tries both with and without sound/ when loading sounds, which allows quake3 maps to work better, since their target_speaker entities include sound/ in the filenames, this also got rid of the stdpath parameter in the S_PrecacheSound/S_FindName/S_LocalSound calls) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4710 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_shared.c | 4 +- cl_parse.c | 16 ++++---- console.c | 2 +- dpvsimpledecode.c | 2 +- menu.c | 100 +++++++++++++++++++++++----------------------- prvm_cmds.c | 4 +- snd_main.c | 27 ++++++------- snd_mem.c | 43 ++++++++++++-------- snd_null.c | 4 +- sound.h | 4 +- 10 files changed, 107 insertions(+), 99 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index c0f0514c..d9d753d7 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -112,10 +112,10 @@ void CDAudio_Play (qbyte track, qboolean looping) CDAudio_Stop (); // Try playing a fake track (sound file) first - sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, true, false); + sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, false); // FIXME: perhaps force it to be always %03u (but for compatibility?): if (!sfx) - sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, true, false); + sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, false); if (sfx != NULL) { faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0); diff --git a/cl_parse.c b/cl_parse.c index ab11ec65..6272ccf2 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -431,7 +431,7 @@ void CL_ParseServerInfo (void) CL_KeepaliveMessage(); // Don't lock the sfx here, S_ServerSounds already did that - cl.sound_precache[i] = S_PrecacheSound(parse_sound_precache[i], true, true, false); + cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false); } // local state @@ -841,13 +841,13 @@ CL_ParseTEnt */ void CL_InitTEnts (void) { - cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav", false, true, true); - cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav", false, true, true); - cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav", false, true, true); - cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav", false, true, true); - cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav", false, true, true); - cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav", false, true, true); - cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav", false, true, true); + cl_sfx_wizhit = S_PrecacheSound ("sound/wizard/hit.wav", false, true); + cl_sfx_knighthit = S_PrecacheSound ("sound/hknight/hit.wav", false, true); + cl_sfx_tink1 = S_PrecacheSound ("sound/weapons/tink1.wav", false, true); + cl_sfx_ric1 = S_PrecacheSound ("sound/weapons/ric1.wav", false, true); + cl_sfx_ric2 = S_PrecacheSound ("sound/weapons/ric2.wav", false, true); + cl_sfx_ric3 = S_PrecacheSound ("sound/weapons/ric3.wav", false, true); + cl_sfx_r_exp3 = S_PrecacheSound ("sound/weapons/r_exp3.wav", false, true); } void CL_ParseBeam (model_t *m, int lightning) diff --git a/console.c b/console.c index e9c8797e..b5c3a14c 100644 --- a/console.c +++ b/console.c @@ -480,7 +480,7 @@ void Con_PrintToHistory(const char *txt) if (txt[0] == 1) { mask = 128; // go to colored text - S_LocalSound ("misc/talk.wav", true); + S_LocalSound ("sound/misc/talk.wav"); // play talk wav txt++; } diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index f403401b..9927a760 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -398,7 +398,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) StripExtension(filename, wavename); strcat(wavename, ".wav"); - sfx = S_PrecacheSound (wavename, false, false, false); + sfx = S_PrecacheSound (wavename, false, false); if (sfx != NULL) s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0); else diff --git a/menu.c b/menu.c index 7cc80ea8..2f0bde72 100644 --- a/menu.c +++ b/menu.c @@ -330,7 +330,7 @@ void M_Demo_Key (int k, char ascii) break; case K_ENTER: - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); m_state = m_none; key_dest = key_game; Cbuf_AddText (va ("playdemo %s\n", NehahraDemos[demo_cursor].name)); @@ -338,7 +338,7 @@ void M_Demo_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); demo_cursor--; if (demo_cursor < 0) demo_cursor = NumberOfNehahraDemos-1; @@ -346,7 +346,7 @@ void M_Demo_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); demo_cursor++; if (demo_cursor >= NumberOfNehahraDemos) demo_cursor = 0; @@ -432,13 +432,13 @@ void M_Main_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (++m_main_cursor >= MAIN_ITEMS) m_main_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (--m_main_cursor < 0) m_main_cursor = MAIN_ITEMS - 1; break; @@ -657,13 +657,13 @@ void M_SinglePlayer_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (++m_singleplayer_cursor >= SINGLEPLAYER_ITEMS) m_singleplayer_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (--m_singleplayer_cursor < 0) m_singleplayer_cursor = SINGLEPLAYER_ITEMS - 1; break; @@ -807,7 +807,7 @@ void M_Load_Key (int k, char ascii) break; case K_ENTER: - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); if (!loadable[load_cursor]) return; m_state = m_none; @@ -819,7 +819,7 @@ void M_Load_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); load_cursor--; if (load_cursor < 0) load_cursor = MAX_SAVEGAMES-1; @@ -827,7 +827,7 @@ void M_Load_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); load_cursor++; if (load_cursor >= MAX_SAVEGAMES) load_cursor = 0; @@ -852,7 +852,7 @@ void M_Save_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); load_cursor--; if (load_cursor < 0) load_cursor = MAX_SAVEGAMES-1; @@ -860,7 +860,7 @@ void M_Save_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); load_cursor++; if (load_cursor >= MAX_SAVEGAMES) load_cursor = 0; @@ -910,13 +910,13 @@ void M_MultiPlayer_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (++m_multiplayer_cursor >= MULTIPLAYER_ITEMS) m_multiplayer_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (--m_multiplayer_cursor < 0) m_multiplayer_cursor = MULTIPLAYER_ITEMS - 1; break; @@ -1081,14 +1081,14 @@ void M_Setup_Key (int k, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); setup_cursor--; if (setup_cursor < 0) setup_cursor = NUM_SETUP_CMDS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); setup_cursor++; if (setup_cursor >= NUM_SETUP_CMDS) setup_cursor = 0; @@ -1097,7 +1097,7 @@ void M_Setup_Key (int k, char ascii) case K_LEFTARROW: if (setup_cursor < 1) return; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); if (setup_cursor == 1) setup_top = setup_top - 1; if (setup_cursor == 2) @@ -1114,7 +1114,7 @@ void M_Setup_Key (int k, char ascii) if (setup_cursor < 1) return; forward: - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); if (setup_cursor == 1) setup_top = setup_top + 1; if (setup_cursor == 2) @@ -1230,7 +1230,7 @@ extern cvar_t r_textshadow; void M_Menu_Options_AdjustSliders (int dir) { int optnum; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); optnum = 7; if (options_cursor == optnum++) @@ -1452,14 +1452,14 @@ void M_Options_Key (int k, char ascii) return; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_cursor--; if (options_cursor < 0) options_cursor = OPTIONS_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_cursor++; if (options_cursor >= OPTIONS_ITEMS) options_cursor = 0; @@ -1519,7 +1519,7 @@ extern cvar_t r_lightningbeam_qmbtexture; void M_Menu_Options_Effects_AdjustSliders (int dir) { int optnum; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); optnum = 0; if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8)); @@ -1630,14 +1630,14 @@ void M_Options_Effects_Key (int k, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_effects_cursor--; if (options_effects_cursor < 0) options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_effects_cursor++; if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS) options_effects_cursor = 0; @@ -1676,7 +1676,7 @@ extern cvar_t r_shadow_realtime_world_shadows; void M_Menu_Options_Graphics_AdjustSliders (int dir) { int optnum; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); optnum = 0; @@ -1729,14 +1729,14 @@ void M_Options_Graphics_Key (int k, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_graphics_cursor--; if (options_graphics_cursor < 0) options_graphics_cursor = OPTIONS_GRAPHICS_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_graphics_cursor++; if (options_graphics_cursor >= OPTIONS_GRAPHICS_ITEMS) options_graphics_cursor = 0; @@ -1772,7 +1772,7 @@ void M_Menu_Options_ColorControl_AdjustSliders (int dir) { int optnum; float f; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); optnum = 1; if (options_colorcontrol_cursor == optnum++) @@ -1976,14 +1976,14 @@ void M_Options_ColorControl_Key (int k, char ascii) return; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_colorcontrol_cursor--; if (options_colorcontrol_cursor < 0) options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); options_colorcontrol_cursor++; if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS) options_colorcontrol_cursor = 0; @@ -2322,7 +2322,7 @@ void M_Keys_Key (int k, char ascii) if (bind_grab) { // defining a key - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); if (k == K_ESCAPE) { bind_grab = false; @@ -2345,7 +2345,7 @@ void M_Keys_Key (int k, char ascii) case K_LEFTARROW: case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); do { keys_cursor--; @@ -2357,7 +2357,7 @@ void M_Keys_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); do { keys_cursor++; @@ -2369,7 +2369,7 @@ void M_Keys_Key (int k, char ascii) case K_ENTER: // go into bind mode M_FindKeysForCommand (bindnames[keys_cursor][0], keys); - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); if (keys[NUMKEYS - 1] != -1) M_UnbindCommand (bindnames[keys_cursor][0]); bind_grab = true; @@ -2377,7 +2377,7 @@ void M_Keys_Key (int k, char ascii) case K_BACKSPACE: // delete bindings case K_DEL: // delete bindings - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); M_UnbindCommand (bindnames[keys_cursor][0]); break; } @@ -2505,7 +2505,7 @@ void M_Video_Draw (void) void M_Menu_Video_AdjustSliders (int dir) { - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); switch (video_cursor) { @@ -2551,7 +2551,7 @@ void M_Video_Key (int key, char ascii) Cvar_SetValueQuick(&vid_height, current_vid_height); Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel); - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); M_Menu_Options_f (); break; @@ -2569,14 +2569,14 @@ void M_Video_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); video_cursor--; if (video_cursor < 0) video_cursor = VIDEO_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); video_cursor++; if (video_cursor >= VIDEO_ITEMS) video_cursor = 0; @@ -2880,14 +2880,14 @@ void M_LanConfig_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); lanConfig_cursor--; if (lanConfig_cursor < 0) lanConfig_cursor = NUM_LANCONFIG_CMDS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); lanConfig_cursor++; if (lanConfig_cursor >= NUM_LANCONFIG_CMDS) lanConfig_cursor = 0; @@ -3719,14 +3719,14 @@ void M_GameOptions_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); gameoptions_cursor--; if (gameoptions_cursor < 0) gameoptions_cursor = NUM_GAMEOPTIONS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); gameoptions_cursor++; if (gameoptions_cursor >= NUM_GAMEOPTIONS) gameoptions_cursor = 0; @@ -3735,19 +3735,19 @@ void M_GameOptions_Key (int key, char ascii) case K_LEFTARROW: if (gameoptions_cursor == 0) break; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); M_NetStart_Change (-1); break; case K_RIGHTARROW: if (gameoptions_cursor == 0) break; - S_LocalSound ("misc/menu3.wav", true); + S_LocalSound ("sound/misc/menu3.wav"); M_NetStart_Change (1); break; case K_ENTER: - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); if (gameoptions_cursor == 0) { if (sv.active) @@ -3862,7 +3862,7 @@ void M_ServerList_Key(int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); slist_cursor--; if (slist_cursor < 0) slist_cursor = hostCacheCount - 1; @@ -3870,14 +3870,14 @@ void M_ServerList_Key(int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound("misc/menu1.wav", true); + S_LocalSound ("sound/misc/menu1.wav"); slist_cursor++; if (slist_cursor >= hostCacheCount) slist_cursor = 0; break; case K_ENTER: - S_LocalSound("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname)); break; @@ -4069,7 +4069,7 @@ void M_Draw (void) if (m_entersound) { - S_LocalSound ("misc/menu2.wav", true); + S_LocalSound ("sound/misc/menu2.wav"); m_entersound = false; } diff --git a/prvm_cmds.c b/prvm_cmds.c index c9ecfc4f..5dc7a50c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -627,7 +627,7 @@ void VM_localsound(void) s = PRVM_G_STRING(OFS_PARM0); - if(!S_LocalSound(s, true)) + if(!S_LocalSound (s)) { Con_Printf("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME); PRVM_G_FLOAT(OFS_RETURN) = -4; @@ -1138,7 +1138,7 @@ void VM_precache_sound (void) PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); VM_CheckEmptyString (s); - if(!S_PrecacheSound(s,true, true, true)) + if(!S_PrecacheSound (s,true, true)) Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME); } diff --git a/snd_main.c b/snd_main.c index a3609065..143eeaa8 100644 --- a/snd_main.c +++ b/snd_main.c @@ -227,29 +227,26 @@ S_FindName ================== */ -sfx_t *S_FindName (const char *name, qboolean stdpath) +sfx_t *S_FindName (const char *name) { sfx_t *sfx; - size_t len; - char namebuffer [MAX_QPATH]; if (!snd_initialized.integer) return NULL; // Add the default sound directory to the path - len = snprintf (namebuffer, sizeof (namebuffer), stdpath ? "sound/%s" : "%s", name); - if (len >= sizeof (namebuffer)) + if (strlen (name) >= sizeof (sfx->name)) Host_Error ("S_FindName: sound name too long (%s)", name); // Look for this sound in the list of known sfx for (sfx = known_sfx; sfx != NULL; sfx = sfx->next) - if(!strcmp (sfx->name, namebuffer)) + if(!strcmp (sfx->name, name)) return sfx; // Add a sfx_t struct for this sound sfx = Mem_Alloc (snd_mempool, sizeof (*sfx)); memset (sfx, 0, sizeof(*sfx)); - strlcpy (sfx->name, namebuffer, sizeof (sfx->name)); + strlcpy (sfx->name, name, sizeof (sfx->name)); sfx->next = known_sfx; known_sfx = sfx; @@ -306,8 +303,8 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds) unsigned int i; // Start the ambient sounds and make them loop - channels[AMBIENT_WATER].sfx = S_PrecacheSound ("ambience/water1.wav", false, true, true); - channels[AMBIENT_SKY].sfx = S_PrecacheSound ("ambience/wind2.wav", false, true, true); + channels[AMBIENT_WATER].sfx = S_PrecacheSound ("sound/ambience/water1.wav", false, true); + channels[AMBIENT_SKY].sfx = S_PrecacheSound ("sound/ambience/wind2.wav", false, true); for (i = 0; i < NUM_AMBIENTS; i++) channels[i].flags |= CHANNELFLAG_FORCELOOP; @@ -322,7 +319,7 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds) // Add 1 lock and the SFXFLAG_SERVERSOUND flag to each sfx in "serversound" for (i = 1; i < numsounds; i++) { - sfx = S_FindName (serversound[i], true); + sfx = S_FindName (serversound[i]); if (sfx != NULL) { sfx->locks++; @@ -351,14 +348,14 @@ S_PrecacheSound ================== */ -sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean stdpath, qboolean lock) +sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock) { sfx_t *sfx; if (!snd_initialized.integer) return NULL; - sfx = S_FindName (name, stdpath); + sfx = S_FindName (name); if (sfx == NULL) return NULL; @@ -941,7 +938,7 @@ static void S_Play_Common(float fvol, float attenuation) snprintf(name, sizeof(name), "%s.wav", Cmd_Argv(i)); else strlcpy(name, Cmd_Argv(i), sizeof(name)); - sfx = S_PrecacheSound(name, true, true, false); + sfx = S_PrecacheSound (name, true, false); // If we need to get the volume from the command line if (fvol == -1.0f) @@ -1003,7 +1000,7 @@ void S_SoundList(void) } -qboolean S_LocalSound (const char *sound, qboolean stdpath) +qboolean S_LocalSound (const char *sound) { sfx_t *sfx; int ch_ind; @@ -1011,7 +1008,7 @@ qboolean S_LocalSound (const char *sound, qboolean stdpath) if (!snd_initialized.integer || nosound.integer) return true; - sfx = S_PrecacheSound (sound, true, stdpath, false); + sfx = S_PrecacheSound (sound, true, false); if (!sfx) { Con_Printf("S_LocalSound: can't precache %s\n", sound); diff --git a/snd_mem.c b/snd_mem.c index a2f4e479..f152120e 100644 --- a/snd_mem.c +++ b/snd_mem.c @@ -153,9 +153,8 @@ S_LoadSound */ qboolean S_LoadSound (sfx_t *s, qboolean complain) { - char namebuffer[MAX_QPATH]; + char namebuffer[MAX_QPATH + 16]; size_t len; - qboolean modified_name = false; if (!shm || !shm->format.speed) return false; @@ -172,31 +171,43 @@ qboolean S_LoadSound (sfx_t *s, qboolean complain) return true; } - len = strlcpy (namebuffer, s->name, sizeof (namebuffer)); + // LordHavoc: if the sound filename does not begin with sound/, try adding it + if (strncasecmp(s->name, "sound/", 6)) + { + len = snprintf (namebuffer, sizeof(namebuffer), "sound/%s", s->name); + if (len >= sizeof (namebuffer)) + { + // name too long + Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", s->name); + return false; + } + if (S_LoadWavFile (namebuffer, s)) + return true; + if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav")) + strcpy (namebuffer + len - 3, "ogg"); + if (OGG_LoadVorbisFile (namebuffer, s)) + return true; + } + + // LordHavoc: then try without the added sound/ as wav and ogg + len = snprintf (namebuffer, sizeof(namebuffer), "%s", s->name); if (len >= sizeof (namebuffer)) + { + // name too long + Con_DPrintf("S_LoadSound: name \"%s\" is too long\n", s->name); return false; - - // Try to load it as a WAV file + } if (S_LoadWavFile (namebuffer, s)) return true; - - // Else, try to load it as an Ogg Vorbis file - if (!strcasecmp (namebuffer + len - 4, ".wav")) - { + if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav")) strcpy (namebuffer + len - 3, "ogg"); - modified_name = true; - } if (OGG_LoadVorbisFile (namebuffer, s)) return true; // Can't load the sound! s->flags |= SFXFLAG_FILEMISSING; if (complain) - { - if (modified_name) - strcpy (namebuffer + len - 3, "wav"); - Con_Printf("Couldn't load %s\n", namebuffer); - } + Con_Printf("S_LoadSound: Couldn't load \"%s\"\n", s->name); return false; } diff --git a/snd_null.c b/snd_null.c index 6e089e6f..c276f725 100755 --- a/snd_null.c +++ b/snd_null.c @@ -78,7 +78,7 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol) { } -sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath, qboolean lock) +sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock) { return NULL; } @@ -99,7 +99,7 @@ void S_ExtraUpdate (void) { } -qboolean S_LocalSound (const char *s, qboolean stdpath) +qboolean S_LocalSound (const char *s) { return false; } diff --git a/sound.h b/sound.h index 27682799..b571be4e 100644 --- a/sound.h +++ b/sound.h @@ -62,13 +62,13 @@ void S_Shutdown (void); void S_Update(const matrix4x4_t *listenermatrix); void S_ExtraUpdate (void); -sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath, qboolean lock); +sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean lock); void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds); void S_UnlockSfx (sfx_t *sfx); // S_StartSound returns the channel index, or -1 if an error occurred int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); -qboolean S_LocalSound (const char *s, qboolean stdpath); +qboolean S_LocalSound (const char *s); void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation); void S_StopSound (int entnum, int entchannel); -- 2.39.2