- moved sound sequence head of list into FLevelLocals.

This commit is contained in:
Christoph Oelckers 2019-01-28 23:53:40 +01:00
parent 623330f938
commit 50d59e99cb
9 changed files with 67 additions and 62 deletions

View file

@ -315,8 +315,6 @@ static void MarkRoot()
if (playeringame[i]) if (playeringame[i])
players[i].PropagateMark(); players[i].PropagateMark();
} }
// Mark sound sequences.
DSeqNode::StaticMarkHead();
// Mark sectors. // Mark sectors.
if (SectorMarker == nullptr && level.sectors.Size() > 0) if (SectorMarker == nullptr && level.sectors.Size() > 0)
{ {

View file

@ -1984,6 +1984,8 @@ void FLevelLocals::Mark()
GC::Mark(ACSThinker); GC::Mark(ACSThinker);
GC::Mark(automap); GC::Mark(automap);
GC::Mark(interpolator.Head); GC::Mark(interpolator.Head);
GC::Mark(SequenceListHead);
canvasTextureInfo.Mark(); canvasTextureInfo.Mark();
for (auto &c : CorpseQueue) for (auto &c : CorpseQueue)
{ {

View file

@ -87,6 +87,7 @@ struct FPortalBits
class DACSThinker; class DACSThinker;
class DFraggleThinker; class DFraggleThinker;
class DSpotState; class DSpotState;
class DSeqNode;
struct FStrifeDialogueNode; struct FStrifeDialogueNode;
class DAutomapBase; class DAutomapBase;
@ -487,6 +488,9 @@ public:
int airsupply; int airsupply;
int DefaultEnvironment; // Default sound environment. int DefaultEnvironment; // Default sound environment.
int ActiveSequences;
DSeqNode *SequenceListHead;
TArray<DVector2> Scrolls; // NULL if no DScrollers in this level TArray<DVector2> Scrolls; // NULL if no DScrollers in this level
int8_t WallVertLight; // Light diffs for vert/horiz walls int8_t WallVertLight; // Light diffs for vert/horiz walls

View file

@ -528,7 +528,6 @@ FSerializer &Serialize(FSerializer &arc, const char *key, zone_t &z, zone_t *def
void P_SerializeSounds(FLevelLocals *Level, FSerializer &arc) void P_SerializeSounds(FLevelLocals *Level, FSerializer &arc)
{ {
S_SerializeSounds(arc); S_SerializeSounds(arc);
DSeqNode::SerializeSequences (arc);
const char *name = NULL; const char *name = NULL;
uint8_t order; uint8_t order;
float musvol = Level->MusicVolume; float musvol = Level->MusicVolume;
@ -931,6 +930,7 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
DThinker::DestroyAllThinkers(); DThinker::DestroyAllThinkers();
interpolator.ClearInterpolations(); interpolator.ClearInterpolations();
arc.ReadObjects(hubload); arc.ReadObjects(hubload);
ActiveSequences = 0;
} }
arc("multiplayer", multiplayer); arc("multiplayer", multiplayer);
@ -966,7 +966,8 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
("scrolls", Scrolls) ("scrolls", Scrolls)
("automap", automap) ("automap", automap)
("interpolator", interpolator) ("interpolator", interpolator)
("frozenstate", frozenstate); ("frozenstate", frozenstate)
("sndseqlisthead", SequenceListHead);
// Hub transitions must keep the current total time // Hub transitions must keep the current total time
@ -1022,7 +1023,7 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
FWeaponSlots::SetupWeaponSlots(players[i].mo); FWeaponSlots::SetupWeaponSlots(players[i].mo);
} }
} }
AActor::RecreateAllAttachedLights(); AActor::RecreateAllAttachedLights();
InitPortalGroups(this); InitPortalGroups(this);
automap->UpdateShowAllLines(); automap->UpdateShowAllLines();

View file

@ -267,6 +267,8 @@ void FLevelLocals::ClearLevelData()
killed_monsters = found_items = found_secrets = killed_monsters = found_items = found_secrets =
wminfo.maxfrags = 0; wminfo.maxfrags = 0;
SN_StopAllSequences(this);
FStrifeDialogueNode *node; FStrifeDialogueNode *node;
while (StrifeDialogues.Pop (node)) while (StrifeDialogues.Pop (node))
@ -351,7 +353,6 @@ void P_FreeLevelData ()
R_FreePastViewers(); R_FreePastViewers();
P_ClearUDMFKeys(); P_ClearUDMFKeys();
SN_StopAllSequences ();
DThinker::DestroyAllThinkers (); DThinker::DestroyAllThinkers ();
level.ClearLevelData(); level.ClearLevelData();
@ -611,13 +612,13 @@ CCMD(dumpgeometry)
if (seg->linedef) if (seg->linedef)
{ {
Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, linedef %d, side %d", Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, linedef %d, side %d",
seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(), seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(),
seg->Index(), seg->linedef->Index(), seg->sidedef != seg->linedef->sidedef[0]); seg->Index(), seg->linedef->Index(), seg->sidedef != seg->linedef->sidedef[0]);
} }
else else
{ {
Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, miniseg", Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, miniseg",
seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(), seg->Index()); seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(), seg->Index());
} }
if (seg->PartnerSeg) if (seg->PartnerSeg)
{ {

View file

@ -219,8 +219,6 @@ static bool TwiddleSeqNum (int &sequence, seqtype_t type);
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // PUBLIC DATA DEFINITIONS -------------------------------------------------
FSoundSequencePtrArray Sequences; FSoundSequencePtrArray Sequences;
int ActiveSequences;
DSeqNode *DSeqNode::SequenceListHead;
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
@ -289,11 +287,6 @@ static FRandom pr_sndseq ("SndSeq");
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
void DSeqNode::SerializeSequences (FSerializer &arc)
{
arc("sndseqlisthead", SequenceListHead);
}
IMPLEMENT_CLASS(DSeqNode, false, true) IMPLEMENT_CLASS(DSeqNode, false, true)
IMPLEMENT_POINTERS_START(DSeqNode) IMPLEMENT_POINTERS_START(DSeqNode)
@ -345,7 +338,8 @@ void DSeqNode::Serialize(FSerializer &arc)
("parentseqnode", m_ParentSeqNode) ("parentseqnode", m_ParentSeqNode)
("id", id) ("id", id)
("seqname", seqName) ("seqname", seqName)
("numchoices", numchoices); ("numchoices", numchoices)
("level", Level);
// The way this is saved makes it hard to encapsulate so just do it the hard way... // The way this is saved makes it hard to encapsulate so just do it the hard way...
if (arc.isWriting()) if (arc.isWriting())
@ -397,9 +391,9 @@ void DSeqNode::OnDestroy()
m_ParentSeqNode->m_ChildSeqNode = nullptr; m_ParentSeqNode->m_ChildSeqNode = nullptr;
m_ParentSeqNode = nullptr; m_ParentSeqNode = nullptr;
} }
if (SequenceListHead == this) if (Level->SequenceListHead == this)
{ {
SequenceListHead = m_Next; Level->SequenceListHead = m_Next;
GC::WriteBarrier(m_Next); GC::WriteBarrier(m_Next);
} }
if (m_Prev) if (m_Prev)
@ -412,7 +406,7 @@ void DSeqNode::OnDestroy()
m_Next->m_Prev = m_Prev; m_Next->m_Prev = m_Prev;
GC::WriteBarrier(m_Next, m_Prev); GC::WriteBarrier(m_Next, m_Prev);
} }
ActiveSequences--; Level->ActiveSequences--;
Super::OnDestroy(); Super::OnDestroy();
} }
@ -803,21 +797,22 @@ static void AddSequence (int curseq, FName seqname, FName slot, int stopsound, c
Sequences[curseq]->Script[ScriptTemp.Size()] = MakeCommand(SS_CMD_END, 0); Sequences[curseq]->Script[ScriptTemp.Size()] = MakeCommand(SS_CMD_END, 0);
} }
DSeqNode::DSeqNode (int sequence, int modenum) DSeqNode::DSeqNode (FLevelLocals *l, int sequence, int modenum)
: m_ModeNum(modenum), m_SequenceChoices(0) : m_ModeNum(modenum), m_SequenceChoices(0)
{ {
Level = l;
ActivateSequence (sequence); ActivateSequence (sequence);
if (!SequenceListHead) if (!Level->SequenceListHead)
{ {
SequenceListHead = this; Level->SequenceListHead = this;
m_Next = m_Prev = NULL; m_Next = m_Prev = nullptr;
} }
else else
{ {
SequenceListHead->m_Prev = this; GC::WriteBarrier(SequenceListHead->m_Prev, this); Level->SequenceListHead->m_Prev = this; GC::WriteBarrier(Level->SequenceListHead->m_Prev, this);
m_Next = SequenceListHead; GC::WriteBarrier(this, SequenceListHead); m_Next = Level->SequenceListHead; GC::WriteBarrier(this, Level->SequenceListHead);
SequenceListHead = this; Level->SequenceListHead = this;
m_Prev = NULL; m_Prev = nullptr;
} }
GC::WriteBarrier(this); GC::WriteBarrier(this);
m_ParentSeqNode = m_ChildSeqNode = nullptr; m_ParentSeqNode = m_ChildSeqNode = nullptr;
@ -832,24 +827,23 @@ void DSeqNode::ActivateSequence (int sequence)
m_CurrentSoundID = 0; m_CurrentSoundID = 0;
m_Volume = 1; // Start at max volume... m_Volume = 1; // Start at max volume...
m_Atten = ATTN_IDLE; // ...and idle attenuation m_Atten = ATTN_IDLE; // ...and idle attenuation
Level->ActiveSequences++;
ActiveSequences++;
} }
DSeqActorNode::DSeqActorNode (AActor *actor, int sequence, int modenum) DSeqActorNode::DSeqActorNode (AActor *actor, int sequence, int modenum)
: DSeqNode (sequence, modenum), : DSeqNode (actor->Level, sequence, modenum),
m_Actor (actor) m_Actor (actor)
{ {
} }
DSeqPolyNode::DSeqPolyNode (FPolyObj *poly, int sequence, int modenum) DSeqPolyNode::DSeqPolyNode (FPolyObj *poly, int sequence, int modenum)
: DSeqNode (sequence, modenum), : DSeqNode (poly->Level, sequence, modenum),
m_Poly (poly) m_Poly (poly)
{ {
} }
DSeqSectorNode::DSeqSectorNode (sector_t *sec, int chan, int sequence, int modenum) DSeqSectorNode::DSeqSectorNode (sector_t *sec, int chan, int sequence, int modenum)
: DSeqNode (sequence, modenum), : DSeqNode (sec->Level, sequence, modenum),
Channel (chan), Channel (chan),
m_Sector (sec) m_Sector (sec)
{ {
@ -1048,7 +1042,8 @@ static int FindSequence (FName seqname)
DSeqNode *SN_CheckSequence(sector_t *sector, int chan) DSeqNode *SN_CheckSequence(sector_t *sector, int chan)
{ {
for (DSeqNode *node = DSeqNode::FirstSequence(); node; ) auto Level = sector->Level;
for (DSeqNode *node = Level->SequenceListHead; node; )
{ {
DSeqNode *next = node->NextSequence(); DSeqNode *next = node->NextSequence();
if (node->Source() == sector) if (node->Source() == sector)
@ -1079,7 +1074,7 @@ DEFINE_ACTION_FUNCTION(_Sector, CheckSoundSequence)
void SN_StopSequence (AActor *actor) void SN_StopSequence (AActor *actor)
{ {
SN_DoStop (actor); SN_DoStop (actor->Level, actor);
} }
DEFINE_ACTION_FUNCTION(AActor, StopSoundSequence) DEFINE_ACTION_FUNCTION(AActor, StopSoundSequence)
@ -1109,14 +1104,14 @@ DEFINE_ACTION_FUNCTION(_Sector, StopSoundSequence)
void SN_StopSequence (FPolyObj *poly) void SN_StopSequence (FPolyObj *poly)
{ {
SN_DoStop (poly); SN_DoStop (poly->Level, poly);
} }
void SN_DoStop (void *source) void SN_DoStop (FLevelLocals *Level, void *source)
{ {
DSeqNode *node; DSeqNode *node;
for (node = DSeqNode::FirstSequence(); node; ) for (node = Level->SequenceListHead; node; )
{ {
DSeqNode *next = node->NextSequence(); DSeqNode *next = node->NextSequence();
if (node->Source() == source) if (node->Source() == source)
@ -1164,7 +1159,7 @@ bool SN_IsMakingLoopingSound (sector_t *sector)
{ {
DSeqNode *node; DSeqNode *node;
for (node = DSeqNode::FirstSequence (); node; ) for (node = sector->Level->SequenceListHead; node; )
{ {
DSeqNode *next = node->NextSequence(); DSeqNode *next = node->NextSequence();
if (node->Source() == (void *)sector) if (node->Source() == (void *)sector)
@ -1328,7 +1323,7 @@ void DSeqNode::Tick ()
int seqnum = FindSequence (ENamedName(m_SequencePtr[i*2+1])); int seqnum = FindSequence (ENamedName(m_SequencePtr[i*2+1]));
if (seqnum >= 0) if (seqnum >= 0)
{ // Found a match, and it's a good one too. { // Found a match, and it's a good one too.
ActiveSequences--; Level->ActiveSequences--;
ActivateSequence (seqnum); ActivateSequence (seqnum);
break; break;
} }
@ -1359,15 +1354,15 @@ void DSeqNode::Tick ()
} }
} }
void SN_UpdateActiveSequences (void) void SN_UpdateActiveSequences (FLevelLocals *Level)
{ {
DSeqNode *node; DSeqNode *node;
if (!ActiveSequences || paused) if (!Level->ActiveSequences || paused)
{ // No sequences currently playing/game is paused { // No sequences currently playing/game is paused
return; return;
} }
for (node = DSeqNode::FirstSequence(); node; node = node->NextSequence()) for (node =Level->SequenceListHead; node; node = node->NextSequence())
{ {
node->Tick (); node->Tick ();
} }
@ -1379,11 +1374,11 @@ void SN_UpdateActiveSequences (void)
// //
//========================================================================== //==========================================================================
void SN_StopAllSequences (void) void SN_StopAllSequences (FLevelLocals *Level)
{ {
DSeqNode *node; DSeqNode *node;
for (node = DSeqNode::FirstSequence(); node; ) for (node = Level->SequenceListHead; node; )
{ {
DSeqNode *next = node->NextSequence(); DSeqNode *next = node->NextSequence();
node->m_StopSound = 0; // don't play any stop sounds node->m_StopSound = 0; // don't play any stop sounds
@ -1470,14 +1465,14 @@ DEFINE_ACTION_FUNCTION(DSeqNode, MarkPrecacheSounds)
// nodeNum zero is the first node // nodeNum zero is the first node
//========================================================================== //==========================================================================
void SN_ChangeNodeData (int nodeNum, int seqOffset, int delayTics, float volume, void SN_ChangeNodeData (FLevelLocals *Level, int nodeNum, int seqOffset, int delayTics, float volume,
int currentSoundID) int currentSoundID)
{ {
int i; int i;
DSeqNode *node; DSeqNode *node;
i = 0; i = 0;
node = DSeqNode::FirstSequence(); node = Level->SequenceListHead;
while (node && i < nodeNum) while (node && i < nodeNum)
{ {
node = node->NextSequence(); node = node->NextSequence();

View file

@ -28,21 +28,18 @@ public:
void AddChoice (int seqnum, seqtype_t type); void AddChoice (int seqnum, seqtype_t type);
int GetModeNum() const { return m_ModeNum; } int GetModeNum() const { return m_ModeNum; }
FName GetSequenceName() const; FName GetSequenceName() const;
static void StaticMarkHead() { GC::Mark(SequenceListHead); }
virtual void MakeSound (int loop, FSoundID id) {} virtual void MakeSound (int loop, FSoundID id) {}
virtual void *Source () { return NULL; } virtual void *Source () { return NULL; }
virtual bool IsPlaying () { return false; } virtual bool IsPlaying () { return false; }
virtual DSeqNode *SpawnChild (int seqnum) { return NULL; } virtual DSeqNode *SpawnChild (int seqnum) { return NULL; }
inline static DSeqNode *FirstSequence() { return SequenceListHead; }
inline DSeqNode *NextSequence() const { return m_Next; } inline DSeqNode *NextSequence() const { return m_Next; }
static void SerializeSequences (FSerializer &arc);
protected: protected:
DSeqNode (); DSeqNode ();
DSeqNode (int sequence, int modenum); DSeqNode (FLevelLocals *l, int sequence, int modenum);
int32_t *m_SequencePtr; int32_t *m_SequencePtr;
int m_Sequence; int m_Sequence;
@ -54,20 +51,20 @@ protected:
float m_Atten; float m_Atten;
int m_ModeNum; int m_ModeNum;
FLevelLocals *Level;
TArray<int> m_SequenceChoices; TArray<int> m_SequenceChoices;
TObjPtr<DSeqNode*> m_ChildSeqNode; TObjPtr<DSeqNode*> m_ChildSeqNode;
TObjPtr<DSeqNode*> m_ParentSeqNode; TObjPtr<DSeqNode*> m_ParentSeqNode;
private: private:
static DSeqNode *SequenceListHead;
DSeqNode *m_Next, *m_Prev; DSeqNode *m_Next, *m_Prev;
void ActivateSequence (int sequence); void ActivateSequence (int sequence);
friend void SN_StopAllSequences (void); friend void SN_StopAllSequences (FLevelLocals *Level);
}; };
void SN_StopAllSequences (void); void SN_StopAllSequences (FLevelLocals *Level);
struct FSoundSequence struct FSoundSequence
{ {
@ -92,11 +89,10 @@ void SN_StopSequence (sector_t *sector, int chan);
void SN_StopSequence (FPolyObj *poly); void SN_StopSequence (FPolyObj *poly);
bool SN_AreModesSame(int sequence, seqtype_t type, int mode1, int mode2); bool SN_AreModesSame(int sequence, seqtype_t type, int mode1, int mode2);
bool SN_AreModesSame(FName name, int mode1, int mode2); bool SN_AreModesSame(FName name, int mode1, int mode2);
void SN_UpdateActiveSequences (void); void SN_UpdateActiveSequences (FLevelLocals *Level);
ptrdiff_t SN_GetSequenceOffset (int sequence, int32_t *sequencePtr); ptrdiff_t SN_GetSequenceOffset (int sequence, int32_t *sequencePtr);
void SN_DoStop (void *); void SN_DoStop (FLevelLocals *Level, void *);
void SN_ChangeNodeData (int nodeNum, int seqOffset, int delayTics, void SN_ChangeNodeData (FLevelLocals *Level, int nodeNum, int seqOffset, int delayTics, float volume, int currentSoundID);
float volume, int currentSoundID);
FName SN_GetSequenceSlot (int sequence, seqtype_t type); FName SN_GetSequenceSlot (int sequence, seqtype_t type);
void SN_MarkPrecacheSounds (int sequence, seqtype_t type); void SN_MarkPrecacheSounds (int sequence, seqtype_t type);
bool SN_IsMakingLoopingSound (sector_t *sector); bool SN_IsMakingLoopingSound (sector_t *sector);

View file

@ -1751,7 +1751,10 @@ void S_StopSound (const FPolyObj *poly, int channel)
void S_StopAllChannels () void S_StopAllChannels ()
{ {
SN_StopAllSequences(); for (auto Level : AllLevels())
{
SN_StopAllSequences(Level);
}
FSoundChan *chan = Channels; FSoundChan *chan = Channels;
while (chan != NULL) while (chan != NULL)
@ -2178,8 +2181,10 @@ void S_UpdateSounds (AActor *listenactor)
chan->ChanFlags &= ~CHAN_JUSTSTARTED; chan->ChanFlags &= ~CHAN_JUSTSTARTED;
} }
SN_UpdateActiveSequences(); for (auto Level : AllLevels())
{
SN_UpdateActiveSequences(Level);
}
GSnd->UpdateListener(&listener); GSnd->UpdateListener(&listener);
GSnd->UpdateSounds(); GSnd->UpdateSounds();

View file

@ -769,7 +769,10 @@ void WI_Start(wbstartstruct_t *wbstartstruct)
else wbstartstruct->nextname = info->LookupLevelName(); else wbstartstruct->nextname = info->LookupLevelName();
V_SetBlend(0, 0, 0, 0); V_SetBlend(0, 0, 0, 0);
S_StopAllChannels(); S_StopAllChannels();
SN_StopAllSequences(); for (auto Level : AllLevels())
{
SN_StopAllSequences(Level);
}
WI_Screen = cls->CreateNew(); WI_Screen = cls->CreateNew();
IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Start) IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Start)
{ {