Skip to content

Commit

Permalink
reduce precached sounds and add mp_npcidletalk
Browse files Browse the repository at this point in the history
mp_soundvariety affects more sounds and some unused sounds are no longer precached. Model events are not precached for monster animations which require scripted_sequence to use. mp_npcidletalk 0 disables idle sounds for talking NPCs to save more slots.

The minimum amount of sounds precached in a map with every variation of every entity went from 621 -> 479 sounds. This is with mp_soundvariety 1 and mp_npcidletalk 0. Without using those cvars about 50 fewer sounds are precached.
  • Loading branch information
wootguy committed Dec 14, 2024
1 parent f87da11 commit e1a0733
Show file tree
Hide file tree
Showing 48 changed files with 665 additions and 592 deletions.
6 changes: 0 additions & 6 deletions dlls/CWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,6 @@ void CWorld::Precache(void)
PRECACHE_MODEL("models/agibs.mdl");
}

PRECACHE_SOUND("weapons/ric1.wav");
PRECACHE_SOUND("weapons/ric2.wav");
PRECACHE_SOUND("weapons/ric3.wav");
PRECACHE_SOUND("weapons/ric4.wav");
PRECACHE_SOUND("weapons/ric5.wav");

PRECACHE_SOUND("weapons/distant/crack_9mm.wav");
PRECACHE_SOUND("weapons/distant/crack_357.wav");
PRECACHE_SOUND("weapons/distant/crack_556.wav");
Expand Down
2 changes: 1 addition & 1 deletion dlls/env/CAmbientGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void CAmbientGeneric::Precache(void)
{
if (m_isGlobalMp3)
PRECACHE_GENERIC((std::string("sound/") + szSoundFile).c_str());
if (*szSoundFile != '!')
else if (*szSoundFile != '!')
PRECACHE_SOUND(szSoundFile);
}
// init all dynamic modulation parms
Expand Down
20 changes: 13 additions & 7 deletions dlls/env/CEnvSpark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class CEnvSpark : public CBaseEntity
float m_flDelay;
};


TYPEDESCRIPTION CEnvSpark::m_SaveData[] =
{
DEFINE_FIELD(CEnvSpark, m_flDelay, FIELD_FLOAT),
Expand All @@ -33,6 +32,18 @@ IMPLEMENT_SAVERESTORE(CEnvSpark, CBaseEntity)
LINK_ENTITY_TO_CLASS(env_spark, CEnvSpark)
LINK_ENTITY_TO_CLASS(env_debris, CEnvSpark)

const char* g_sparkSounds[6] =
{
// sounds used by other entities and world textures
"buttons/spark5.wav",
"buttons/spark6.wav",

"buttons/spark1.wav",
"buttons/spark2.wav",
"buttons/spark3.wav",
"buttons/spark4.wav",
};

void CEnvSpark::Spawn(void)
{
SetThink(NULL);
Expand Down Expand Up @@ -62,12 +73,7 @@ void CEnvSpark::Spawn(void)

void CEnvSpark::Precache(void)
{
PRECACHE_SOUND("buttons/spark1.wav");
PRECACHE_SOUND("buttons/spark2.wav");
PRECACHE_SOUND("buttons/spark3.wav");
PRECACHE_SOUND("buttons/spark4.wav");
PRECACHE_SOUND("buttons/spark5.wav");
PRECACHE_SOUND("buttons/spark6.wav");
PRECACHE_SOUND_ARRAY(g_sparkSounds);
}

void CEnvSpark::KeyValue(KeyValueData* pkvd)
Expand Down
17 changes: 2 additions & 15 deletions dlls/func/CBaseButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ void CBaseButton::Precache(void)

if (FBitSet(pev->spawnflags, SF_BUTTON_SPARK_IF_OFF))// this button should spark in OFF state
{
PRECACHE_SOUND("buttons/spark1.wav");
PRECACHE_SOUND("buttons/spark2.wav");
PRECACHE_SOUND("buttons/spark3.wav");
PRECACHE_SOUND("buttons/spark4.wav");
PRECACHE_SOUND("buttons/spark5.wav");
PRECACHE_SOUND("buttons/spark6.wav");
PRECACHE_SOUND_ARRAY(g_sparkSounds);
}

// get door button sounds, for doors which require buttons to open
Expand Down Expand Up @@ -288,15 +283,7 @@ void DoSpark(entvars_t* pev, const Vector& location)
UTIL_Sparks(tmp);

float flVolume = RANDOM_FLOAT(0.25, 0.75) * 0.4;//random volume range
switch ((int)(RANDOM_FLOAT(0, 1) * 6))
{
case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark1.wav", flVolume, ATTN_NORM); break;
case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark2.wav", flVolume, ATTN_NORM); break;
case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark3.wav", flVolume, ATTN_NORM); break;
case 3: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark4.wav", flVolume, ATTN_NORM); break;
case 4: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark5.wav", flVolume, ATTN_NORM); break;
case 5: EMIT_SOUND(ENT(pev), CHAN_VOICE, "buttons/spark6.wav", flVolume, ATTN_NORM); break;
}
EMIT_SOUND(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(g_sparkSounds), flVolume, ATTN_NORM);
}

void CBaseButton::ButtonSpark(void)
Expand Down
2 changes: 2 additions & 0 deletions dlls/func/CBaseButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const char* ButtonSound(int sound); // get string of button sound number

void DoSpark(entvars_t* pev, const Vector& location);

extern const char* g_sparkSounds[6];

//
// Generic Button
//
Expand Down
165 changes: 58 additions & 107 deletions dlls/func/CBreakable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ const char* CBreakable::pSoundsGlass[] =
"debris/glass3.wav",
};

const char* CBreakable::pBustSoundsWood[] =
{
"debris/bustcrate1.wav",
"debris/bustcrate2.wav",
};

const char* CBreakable::pBustSoundsFlesh[] =
{
"debris/bustflesh1.wav",
"debris/bustflesh2.wav",
};

const char* CBreakable::pBustSoundsMetal[] =
{
"debris/bustmetal1.wav",
"debris/bustmetal2.wav",
};

const char* CBreakable::pBustSoundsConcrete[] =
{
"debris/bustconcrete1.wav",
"debris/bustconcrete2.wav",
};

const char* CBreakable::pBustSoundsGlass[] =
{
"debris/bustglass1.wav",
"debris/bustglass2.wav",
};

const char** CBreakable::MaterialSoundList(Materials precacheMaterial, int& soundCount)
{
const char** pSoundList = NULL;
Expand Down Expand Up @@ -256,8 +286,7 @@ void CBreakable::MaterialSoundPrecache(Materials precacheMaterial)

pSoundList = MaterialSoundList(precacheMaterial, soundCount);

for (i = 0; i < soundCount; i++)
{
for (i = 0; i < soundCount && i < soundvariety.value; i++) {
PRECACHE_SOUND_ENT(NULL, (char*)pSoundList[i]);
}
}
Expand All @@ -269,8 +298,10 @@ void CBreakable::MaterialSoundRandom(edict_t* pEdict, Materials soundMaterial, f

pSoundList = MaterialSoundList(soundMaterial, soundCount);

if (soundCount)
EMIT_SOUND(pEdict, CHAN_BODY, pSoundList[RANDOM_LONG(0, soundCount - 1)], volume, 1.0);
if (pSoundList) {
int idx = RANDOM_LONG(0, V_min(soundCount, soundvariety.value) - 1);
EMIT_SOUND(pEdict, CHAN_BODY, pSoundList[idx], volume, 1.0);
}
}


Expand All @@ -284,58 +315,55 @@ void CBreakable::Precache(void)
case matWood:
pGibName = "models/woodgibs.mdl";

PRECACHE_SOUND("debris/bustcrate1.wav");
PRECACHE_SOUND("debris/bustcrate2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsWood);
break;
case matFlesh:
pGibName = "models/fleshgibs.mdl";

PRECACHE_SOUND("debris/bustflesh1.wav");
PRECACHE_SOUND("debris/bustflesh2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsFlesh);
break;
case matComputer:
PRECACHE_SOUND("buttons/spark5.wav");
PRECACHE_SOUND("buttons/spark6.wav");
pGibName = "models/computergibs.mdl";

PRECACHE_SOUND("debris/metal1.wav");
PRECACHE_SOUND("debris/metal3.wav");
PRECACHE_SOUND("debris/bustmetal1.wav");
PRECACHE_SOUND("debris/bustmetal2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsMetal);
break;

case matUnbreakableGlass:
case matGlass:
pGibName = "models/glassgibs.mdl";

PRECACHE_SOUND("debris/bustglass1.wav");
PRECACHE_SOUND("debris/bustglass2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsGlass);
break;
case matMetal:
pGibName = "models/metalplategibs.mdl";

PRECACHE_SOUND("debris/bustmetal1.wav");
PRECACHE_SOUND("debris/bustmetal2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsMetal);
break;
case matCinderBlock:
pGibName = "models/cindergibs.mdl";

PRECACHE_SOUND("debris/bustconcrete1.wav");
PRECACHE_SOUND("debris/bustconcrete2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsConcrete);
break;
case matRocks:
pGibName = "models/rockgibs.mdl";

PRECACHE_SOUND("debris/bustconcrete1.wav");
PRECACHE_SOUND("debris/bustconcrete2.wav");
PRECACHE_SOUND_ARRAY(pBustSoundsConcrete);
break;
case matCeilingTile:
pGibName = "models/ceilinggibs.mdl";

PRECACHE_SOUND("debris/bustceiling.wav");
break;
}

MaterialSoundPrecache(m_Material);

if (m_Material == matComputer) {
MaterialSoundPrecache(matMetal);
}

if (m_iszGibModel)
pGibName = STRING(m_iszGibModel);

Expand All @@ -354,8 +382,6 @@ void CBreakable::DamageSound(void)
{
int pitch;
float fvol;
const char* rgpsz[6];
int i;
int material = m_Material;

// if (RANDOM_LONG(0,1))
Expand All @@ -371,58 +397,13 @@ void CBreakable::DamageSound(void)
if (material == matComputer && RANDOM_LONG(0, 1))
material = matMetal;

switch (material)
{
case matComputer:
case matGlass:
case matUnbreakableGlass:
rgpsz[0] = "debris/glass1.wav";
rgpsz[1] = "debris/glass2.wav";
rgpsz[2] = "debris/glass3.wav";
i = 3;
break;

case matWood:
rgpsz[0] = "debris/wood1.wav";
rgpsz[1] = "debris/wood2.wav";
rgpsz[2] = "debris/wood3.wav";
i = 3;
break;

case matMetal:
rgpsz[0] = "debris/metal1.wav";
rgpsz[1] = "debris/metal3.wav";
rgpsz[2] = "debris/metal2.wav";
i = 2;
break;
int soundCount = 0;
const char** dmgSoundList = MaterialSoundList((Materials)material, soundCount);

case matFlesh:
rgpsz[0] = "debris/flesh1.wav";
rgpsz[1] = "debris/flesh2.wav";
rgpsz[2] = "debris/flesh3.wav";
rgpsz[3] = "debris/flesh5.wav";
rgpsz[4] = "debris/flesh6.wav";
rgpsz[5] = "debris/flesh7.wav";
i = 6;
break;

case matRocks:
case matCinderBlock:
rgpsz[0] = "debris/concrete1.wav";
rgpsz[1] = "debris/concrete2.wav";
rgpsz[2] = "debris/concrete3.wav";
i = 3;
break;

default:
case matCeilingTile:
// UNDONE: no ceiling tile shard sound yet
i = 0;
break;
if (dmgSoundList) {
int idx = RANDOM_LONG(0, V_min(soundCount, soundvariety.value)-1);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, dmgSoundList[idx], fvol, ATTN_NORM, 0, pitch);
}

if (i)
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, rgpsz[RANDOM_LONG(0, i - 1)], fvol, ATTN_NORM, 0, pitch);
}

const char* CBreakable::DisplayName() {
Expand Down Expand Up @@ -635,59 +616,29 @@ void CBreakable::Die()
switch (m_Material)
{
case matGlass:
switch (RANDOM_LONG(0, 1))
{
case 0: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustglass1.wav", fvol, ATTN_NORM, 0, pitch);
break;
case 1: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustglass2.wav", fvol, ATTN_NORM, 0, pitch);
break;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pBustSoundsGlass), fvol, ATTN_NORM, 0, pitch);
cFlag = BREAK_GLASS;
break;

case matWood:
switch (RANDOM_LONG(0, 1))
{
case 0: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustcrate1.wav", fvol, ATTN_NORM, 0, pitch);
break;
case 1: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustcrate2.wav", fvol, ATTN_NORM, 0, pitch);
break;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pBustSoundsWood), fvol, ATTN_NORM, 0, pitch);
cFlag = BREAK_WOOD;
break;

case matComputer:
case matMetal:
switch (RANDOM_LONG(0, 1))
{
case 0: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustmetal1.wav", fvol, ATTN_NORM, 0, pitch);
break;
case 1: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustmetal2.wav", fvol, ATTN_NORM, 0, pitch);
break;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pBustSoundsMetal), fvol, ATTN_NORM, 0, pitch);
cFlag = BREAK_METAL;
break;

case matFlesh:
switch (RANDOM_LONG(0, 1))
{
case 0: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustflesh1.wav", fvol, ATTN_NORM, 0, pitch);
break;
case 1: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustflesh2.wav", fvol, ATTN_NORM, 0, pitch);
break;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pBustSoundsFlesh), fvol, ATTN_NORM, 0, pitch);
cFlag = BREAK_FLESH;
break;

case matRocks:
case matCinderBlock:
switch (RANDOM_LONG(0, 1))
{
case 0: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustconcrete1.wav", fvol, ATTN_NORM, 0, pitch);
break;
case 1: EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "debris/bustconcrete2.wav", fvol, ATTN_NORM, 0, pitch);
break;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pBustSoundsConcrete), fvol, ATTN_NORM, 0, pitch);
cFlag = BREAK_CONCRETE;
break;

Expand Down
7 changes: 7 additions & 0 deletions dlls/func/CBreakable.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class CBreakable : public CBaseDelay
static const char* pSoundsGlass[];
static const char* pSoundsMetal[];
static const char* pSoundsConcrete[];

static const char* pBustSoundsWood[];
static const char* pBustSoundsFlesh[];
static const char* pBustSoundsGlass[];
static const char* pBustSoundsMetal[];
static const char* pBustSoundsConcrete[];

static const char* pSpawnObjects[];

static TYPEDESCRIPTION m_SaveData[];
Expand Down
5 changes: 1 addition & 4 deletions dlls/func/CLadder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ void CLadder::Precache(void)

SetUse(&CLadder::Toggle);

PRECACHE_SOUND("player/pl_ladder1.wav");
PRECACHE_SOUND("player/pl_ladder2.wav");
PRECACHE_SOUND("player/pl_ladder3.wav");
PRECACHE_SOUND("player/pl_ladder4.wav");
PRECACHE_FOOTSTEP_SOUNDS(g_stepSoundsLadder)
}


Expand Down
Loading

0 comments on commit e1a0733

Please sign in to comment.