From 69fc0142ebd9c4422be2e94c8cb4f36c466253c1 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 23 Aug 2012 00:15:41 +0000 Subject: [PATCH] - Precache sounds played by ASoundSequence actors. (This includes Heretic's ambient sounds.) SVN r3845 (trunk) --- src/g_shared/a_soundsequence.cpp | 14 +++++++++++++- src/s_sndseq.cpp | 28 +++++++++++++++++++++++++++- src/s_sndseq.h | 9 +++++---- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/g_shared/a_soundsequence.cpp b/src/g_shared/a_soundsequence.cpp index 94e8e1e600..ab0ee101b4 100644 --- a/src/g_shared/a_soundsequence.cpp +++ b/src/g_shared/a_soundsequence.cpp @@ -105,6 +105,7 @@ public: void PostBeginPlay (); void Activate (AActor *activator); void Deactivate (AActor *activator); + void MarkPrecacheSounds () const; }; IMPLEMENT_CLASS (ASoundSequence) @@ -154,6 +155,18 @@ void ASoundSequence::PostBeginPlay () } } +//========================================================================== +// +// ASoundSequence :: MarkPrecacheSounds +// +//========================================================================== + +void ASoundSequence::MarkPrecacheSounds() const +{ + Super::MarkPrecacheSounds(); + SN_MarkPrecacheSounds(args[0], SEQ_ENVIRONMENT); +} + //========================================================================== // // ASoundSequence :: Activate @@ -175,4 +188,3 @@ void ASoundSequence::Deactivate (AActor *activator) { SN_StopSequence (this); } - diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index 9ba713dcba..cf2957885c 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -760,7 +760,7 @@ static void AddSequence (int curseq, FName seqname, FName slot, int stopsound, c Sequences[curseq] = (FSoundSequence *)M_Malloc (sizeof(FSoundSequence) + sizeof(DWORD)*ScriptTemp.Size()); Sequences[curseq]->SeqName = seqname; Sequences[curseq]->Slot = slot; - Sequences[curseq]->StopSound = stopsound; + Sequences[curseq]->StopSound = FSoundID(stopsound); memcpy (Sequences[curseq]->Script, &ScriptTemp[0], sizeof(DWORD)*ScriptTemp.Size()); Sequences[curseq]->Script[ScriptTemp.Size()] = MakeCommand(SS_CMD_END, 0); } @@ -1311,6 +1311,32 @@ FName SN_GetSequenceSlot (int sequence, seqtype_t type) return NAME_None; } +//========================================================================== +// +// SN_MarkPrecacheSounds +// +// Marks all sounds played by this sequence for precaching. +// +//========================================================================== + +void SN_MarkPrecacheSounds(int sequence, seqtype_t type) +{ + if (TwiddleSeqNum(sequence, type)) + { + FSoundSequence *seq = Sequences[sequence]; + + seq->StopSound.MarkUsed(); + for (int i = 0; GetCommand(seq->Script[i]) != SS_CMD_END; ++i) + { + int cmd = GetCommand(seq->Script[i]); + if (cmd == SS_CMD_PLAY || cmd == SS_CMD_PLAYREPEAT || cmd == SS_CMD_PLAYLOOP) + { + FSoundID(GetData(seq->Script[i])).MarkUsed(); + } + } + } +} + //========================================================================== // // SN_ChangeNodeData diff --git a/src/s_sndseq.h b/src/s_sndseq.h index 41035fb1d8..59b9293c0f 100644 --- a/src/s_sndseq.h +++ b/src/s_sndseq.h @@ -71,10 +71,10 @@ void SN_StopAllSequences (void); struct FSoundSequence { - FName SeqName; - FName Slot; - int StopSound; - SDWORD Script[1]; // + more until end of sequence script + FName SeqName; + FName Slot; + FSoundID StopSound; + SDWORD Script[1]; // + more until end of sequence script }; void S_ParseSndSeq (int levellump); @@ -98,6 +98,7 @@ void SN_DoStop (void *); void SN_ChangeNodeData (int nodeNum, int seqOffset, int delayTics, float volume, int currentSoundID); FName SN_GetSequenceSlot (int sequence, seqtype_t type); +void SN_MarkPrecacheSounds (int sequence, seqtype_t type); bool SN_IsMakingLoopingSound (sector_t *sector); #endif //__S_SNDSEQ_H__