- Precache player sounds at level load.

SVN r3841 (trunk)
This commit is contained in:
Randy Heit 2012-08-22 23:46:47 +00:00
parent 1d3c26f088
commit 0ac94c5265
4 changed files with 61 additions and 2 deletions

View File

@ -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
{

View File

@ -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)) &&

View File

@ -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

View File

@ -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);