From 0ac94c5265854e08d2ed8fc0eba83a2075a16dae Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 22 Aug 2012 23:46:47 +0000 Subject: [PATCH] - Precache player sounds at level load. SVN r3841 (trunk) --- src/d_player.h | 3 ++- src/p_user.cpp | 14 +++++++++++++- src/s_advsound.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/s_sound.h | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 67f03db44..fa14c49a9 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -90,6 +90,7 @@ public: virtual void AddInventory (AInventory *item); virtual void RemoveInventory (AInventory *item); virtual bool UseInventory (AInventory *item); + virtual void MarkPrecacheSounds () const; virtual void PlayIdle (); virtual void PlayRunning (); @@ -107,7 +108,7 @@ public: void GiveDefaultInventory (); void PlayAttacking (); void PlayAttacking2 (); - const char *GetSoundClass (); + const char *GetSoundClass () const; enum EInvulState { diff --git a/src/p_user.cpp b/src/p_user.cpp index b8dfd339c..8339262b7 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -475,6 +475,18 @@ void APlayerPawn::Serialize (FArchive &arc) } } +//=========================================================================== +// +// APlayerPawn :: MarkPrecacheSounds +// +//=========================================================================== + +void APlayerPawn::MarkPrecacheSounds() const +{ + Super::MarkPrecacheSounds(); + S_MarkPlayerSounds(GetSoundClass()); +} + //=========================================================================== // // APlayerPawn :: BeginPlay @@ -968,7 +980,7 @@ void APlayerPawn::FilterCoopRespawnInventory (APlayerPawn *oldplayer) // //=========================================================================== -const char *APlayerPawn::GetSoundClass () +const char *APlayerPawn::GetSoundClass() const { if (player != NULL && (player->mo == NULL || !(player->mo->flags4 &MF4_NOSKIN)) && diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index ad6be7875..12ebc94a0 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -100,6 +100,7 @@ public: void AddSound (int player_sound_id, int sfx_id); int LookupSound (int player_sound_id); FPlayerSoundHashTable &operator= (const FPlayerSoundHashTable &other); + void MarkUsed(); protected: struct Entry @@ -830,6 +831,25 @@ int FPlayerSoundHashTable::LookupSound (int player_sound_id) return entry != NULL ? entry->SfxID : 0; } +//========================================================================== +// +// FPlayerSoundHashTable :: Mark +// +// Marks all sounds defined for this class/gender as used. +// +//========================================================================== + +void FPlayerSoundHashTable::MarkUsed() +{ + for (size_t i = 0; i < NUM_BUCKETS; ++i) + { + for (Entry *probe = Buckets[i]; probe != NULL; probe = probe->Next) + { + S_sfx[probe->SfxID].bUsed = true; + } + } +} + //========================================================================== // // S_ClearSoundData @@ -1912,6 +1932,31 @@ void sfxinfo_t::MarkUsed() bUsed = true; } +//========================================================================== +// +// S_MarkPlayerSounds +// +// Marks all sounds from a particular player class for precaching. +// +//========================================================================== + +void S_MarkPlayerSounds (const char *playerclass) +{ + int classidx = S_FindPlayerClass(playerclass); + if (classidx < 0) + { + classidx = DefPlayerClass; + } + for (int g = 0; g < 3; ++g) + { + int listidx = PlayerClassLookups[classidx].ListIndex[0]; + if (listidx != 0xffff) + { + PlayerSounds[listidx].MarkUsed(); + } + } +} + //========================================================================== // // CCMD soundlist diff --git a/src/s_sound.h b/src/s_sound.h index 2c2a398ae..8b0e4ddea 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -357,6 +357,7 @@ int S_AddSoundLump (const char *logicalname, int lump); // Add sound by lump ind int S_AddPlayerSound (const char *playerclass, const int gender, int refid, const char *lumpname); int S_AddPlayerSound (const char *playerclass, const int gender, int refid, int lumpnum, bool fromskin=false); int S_AddPlayerSoundExisting (const char *playerclass, const int gender, int refid, int aliasto, bool fromskin=false); +void S_MarkPlayerSounds (const char *playerclass); void S_ShrinkPlayerSoundLists (); void S_UnloadSound (sfxinfo_t *sfx); sfxinfo_t *S_LoadSound(sfxinfo_t *sfx);