From 9d82c7fa0e378eccb9f1e407a52a4beeb1b63983 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 22 Aug 2012 22:36:06 +0000 Subject: [PATCH] - Added PrecacheSounds mapinfo option. This takes a list of sounds to preload when the level is loaded. SVN r3837 (trunk) --- src/d_main.cpp | 8 ++++---- src/g_level.h | 4 +++- src/g_mapinfo.cpp | 22 +++++++++++++++++++++- src/s_sound.cpp | 8 +++++++- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 40c724496f..c428059e6b 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2209,15 +2209,15 @@ void D_DoomMain (void) // [RH] Load sound environments S_ParseReverbDef (); + // [RH] Parse any SNDINFO lumps + Printf ("S_InitData: Load sound definitions.\n"); + S_InitData (); + // [RH] Parse through all loaded mapinfo lumps Printf ("G_ParseMapInfo: Load map definitions.\n"); G_ParseMapInfo (iwad_info->MapInfo); ReadStatistics(); - // [RH] Parse any SNDINFO lumps - Printf ("S_InitData: Load sound definitions.\n"); - S_InitData (); - Printf ("Texman.Init: Init texture manager.\n"); TexMan.Init(); C_InitConback(); diff --git a/src/g_level.h b/src/g_level.h index bc30b56036..c246e5b7e6 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -36,8 +36,8 @@ #include "doomtype.h" #include "doomdef.h" -//#include "autosegs.h" #include "sc_man.h" +#include "s_sound.h" struct level_info_t; struct cluster_info_t; @@ -327,6 +327,8 @@ struct level_info_t TArray specialactions; + TArray PrecacheSounds; + level_info_t() { Reset(); diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index 38440c8f00..1d229267ef 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -269,6 +269,7 @@ void level_info_t::Reset() teamdamage = 0.f; specialactions.Clear(); DefaultEnvironment = 0; + PrecacheSounds.Clear(); } @@ -1029,7 +1030,7 @@ DEFINE_MAP_OPTION(specialaction, true) sa->Action = P_FindLineSpecial(parse.sc.String, &min_arg, &max_arg); if (sa->Action == 0 || min_arg < 0) { - parse.sc.ScriptError("Unknown specialaction '%s'"); + parse.sc.ScriptError("Unknown specialaction '%s'", parse.sc.String); } int j = 0; while (j < 5 && parse.sc.CheckString(",")) @@ -1040,6 +1041,25 @@ DEFINE_MAP_OPTION(specialaction, true) if (parse.format_type == parse.FMT_Old) parse.sc.SetCMode(false); } +DEFINE_MAP_OPTION(PrecacheSounds, true) +{ + parse.ParseAssign(); + + do + { + parse.sc.MustGetString(); + FSoundID snd = parse.sc.String; + if (snd == 0) + { + parse.sc.ScriptMessage("Unknown sound \"%s\"", parse.sc.String); + } + else + { + info->PrecacheSounds.Push(snd); + } + } while (parse.sc.CheckString(",")); +} + DEFINE_MAP_OPTION(redirect, true) { parse.ParseAssign(); diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 9749d635c3..dadd1a6d72 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -477,7 +477,8 @@ void S_PrecacheLevel () AActor *actor; TThinkerIterator iterator; - while ( (actor = iterator.Next ()) != NULL ) + // Precache all sounds known to be used by the currently spawned actors. + while ( (actor = iterator.Next()) != NULL ) { S_sfx[actor->SeeSound].bUsed = true; S_sfx[actor->AttackSound].bUsed = true; @@ -486,6 +487,11 @@ void S_PrecacheLevel () S_sfx[actor->ActiveSound].bUsed = true; S_sfx[actor->UseSound].bUsed = true; } + // Precache all extra sounds requested by this map. + for (i = 0; i < level.info->PrecacheSounds.Size(); ++i) + { + S_sfx[level.info->PrecacheSounds[i]].bUsed = true; + } for (i = 1; i < S_sfx.Size(); ++i) {