diff --git a/src/p_effect.cpp b/src/p_effect.cpp index d6543b16e..c9e7d70d4 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -701,7 +701,7 @@ void P_DrawRailTrail(AActor *source, TArray &portalhits, int color1, { if (shortest == NULL || shortest->sounddist > seg.sounddist) shortest = &seg; } - S_Sound (DVector3(shortest->soundpos, r_viewpoint.Pos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM); + S_Sound (source->Level, DVector3(shortest->soundpos, r_viewpoint.Pos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM); } } } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index e87760ae0..9a3b747cd 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -6058,7 +6058,7 @@ foundone: } else { - S_Sound(pos, CHAN_ITEM, smallsplash ? + S_Sound(thing->Level, pos, CHAN_ITEM, smallsplash ? splash->SmallSplashSound : splash->NormalSplashSound, 1, ATTN_IDLE); } @@ -6266,7 +6266,7 @@ void P_PlaySpawnSound(AActor *missile, AActor *spawner) // If there is no spawner use the spawn position. // But not in a silenced sector. if (!(missile->Sector->Flags & SECF_SILENT)) - S_Sound (missile->Pos(), CHAN_WEAPON, missile->SeeSound, 1, ATTN_NORM); + S_Sound (missile->Level, missile->Pos(), CHAN_WEAPON, missile->SeeSound, 1, ATTN_NORM); } } } diff --git a/src/p_switch.cpp b/src/p_switch.cpp index 667ff1e3e..918a76d60 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -302,7 +302,7 @@ bool P_ChangeSwitchTexture (side_t *side, int useAgain, uint8_t special, bool *q } if (playsound) { - S_Sound (DVector3(pt, 0), CHAN_VOICE|CHAN_LISTENERZ, sound, 1, ATTN_STATIC); + S_Sound (side->GetLevel(), DVector3(pt, 0), CHAN_VOICE|CHAN_LISTENERZ, sound, 1, ATTN_STATIC); } if (quest != NULL) { @@ -398,7 +398,7 @@ void DActiveButton::Tick () if (def != NULL) { m_Frame = -1; - S_Sound (DVector3(m_Pos, 0), CHAN_VOICE|CHAN_LISTENERZ, + S_Sound (Level, DVector3(m_Pos, 0), CHAN_VOICE|CHAN_LISTENERZ, def->Sound != 0 ? FSoundID(def->Sound) : FSoundID("switches/normbutn"), 1, ATTN_STATIC); bFlippable = false; diff --git a/src/r_defs.h b/src/r_defs.h index 91f248f85..e22fd3f62 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1195,6 +1195,11 @@ struct side_t Light = l; } + FLevelLocals *GetLevel() + { + return sector->Level; + } + FTextureID GetTexture(int which) const { return textures[which].texture; diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 535956583..6dbb6ff88 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -140,7 +140,7 @@ static bool MusicPaused; // whether music is paused MusPlayingInfo mus_playing; // music currently being played static FString LastSong; // last music that was played static FPlayList *PlayList; -static int RestartEvictionsAt; // do not restart evicted channels before this level.time +static int RestartEvictionsAt; // do not restart evicted channels before this time // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -402,16 +402,16 @@ void S_Start () FString LocalSndSeq; // To be certain better check whether level is valid! - if (level.info) + if (currentUILevel->info) { - LocalSndInfo = level.info->SoundInfo; - LocalSndSeq = level.info->SndSeq; + LocalSndInfo = currentUILevel->info->SoundInfo; + LocalSndSeq = currentUILevel->info->SndSeq; } bool parse_ss = false; // This level uses a different local SNDINFO - if (LastLocalSndInfo.CompareNoCase(LocalSndInfo) != 0 || !level.info) + if (LastLocalSndInfo.CompareNoCase(LocalSndInfo) != 0 || !currentUILevel->info) { // First delete the old sound list for(unsigned i = 1; i < S_sfx.Size(); i++) @@ -456,10 +456,10 @@ void S_Start () // Don't start the music if loading a savegame, because the music is stored there. // Don't start the music if revisiting a level in a hub for the same reason. - if (!level.IsReentering()) + if (!currentUILevel->IsReentering()) { - if (level.cdtrack == 0 || !S_ChangeCDMusic (level.cdtrack, level.cdid)) - S_ChangeMusic (level.Music, level.musicorder); + if (currentUILevel->cdtrack == 0 || !S_ChangeCDMusic (currentUILevel->cdtrack, currentUILevel->cdid)) + S_ChangeMusic (currentUILevel->Music, currentUILevel->musicorder); } } @@ -499,7 +499,7 @@ void S_PrecacheLevel () FSoundID(snd).MarkUsed(); } // Precache all extra sounds requested by this map. - for (auto snd : level.info->PrecacheSounds) + for (auto snd : currentUILevel->info->PrecacheSounds) { FSoundID(snd).MarkUsed(); } @@ -706,7 +706,7 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, if(type == SOURCE_Unattached) { sector_t *sec = P_PointInSector(pt[0], pt[2]); - DVector2 disp = level.Displacements.getOffset(pgroup, sec->PortalGroup); + DVector2 disp = currentUILevel->Displacements.getOffset(pgroup, sec->PortalGroup); pos->X = pt[0] - (float)disp.X; pos->Y = !(chanflags & CHAN_LISTENERZ) ? pt[1] : (float)listenpos.Z; pos->Z = pt[2] - (float)disp.Y; @@ -723,7 +723,7 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, //assert(actor != NULL); if (actor != NULL) { - DVector2 disp = level.Displacements.getOffset(pgroup, actor->Sector->PortalGroup); + DVector2 disp = currentUILevel->Displacements.getOffset(pgroup, actor->Sector->PortalGroup); DVector3 posi = actor->Pos() - disp; *pos = { (float)posi.X, (float)posi.Z, (float)posi.Y }; } @@ -733,7 +733,7 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, assert(sector != NULL); if (sector != NULL) { - DVector2 disp = level.Displacements.getOffset(pgroup, sector->PortalGroup); + DVector2 disp = currentUILevel->Displacements.getOffset(pgroup, sector->PortalGroup); if (chanflags & CHAN_AREA) { // listener must be reversely offset to calculate the proper sound origin. @@ -755,7 +755,7 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, assert(poly != NULL); if (poly != NULL) { - DVector2 disp = level.Displacements.getOffset(pgroup, poly->CenterSubsector->sector->PortalGroup); + DVector2 disp = currentUILevel->Displacements.getOffset(pgroup, poly->CenterSubsector->sector->PortalGroup); CalcPolyobjSoundOrg(listenpos + disp, poly, *pos); pos->X -= (float)disp.X; pos->Z -= (float)disp.Y; @@ -916,7 +916,7 @@ static void CalcPolyobjSoundOrg(const DVector3 &listenpos, const FPolyObj *poly, // // S_StartSound // -// 0 attenuation means full volume over whole level. +// 0 attenuation means full volume over whole currentUILevel-> // 0 < attenuation means to scale the distance by that amount when // calculating volume. // @@ -1337,9 +1337,9 @@ DEFINE_ACTION_FUNCTION(DObject, S_Sound) void S_Sound (AActor *ent, int channel, FSoundID sound_id, float volume, float attenuation) { - if (ent == NULL || ent->Sector->Flags & SECF_SILENT) + if (ent == nullptr || ent->Sector->Flags & SECF_SILENT || ent->Level != currentUILevel) return; - S_StartSound (ent, NULL, NULL, NULL, channel, sound_id, volume, attenuation); + S_StartSound (ent, nullptr, nullptr, nullptr, channel, sound_id, volume, attenuation); } //========================================================================== @@ -1352,7 +1352,7 @@ void S_Sound (AActor *ent, int channel, FSoundID sound_id, float volume, float a void S_SoundMinMaxDist(AActor *ent, int channel, FSoundID sound_id, float volume, float mindist, float maxdist) { - if (ent == NULL || ent->Sector->Flags & SECF_SILENT) + if (ent == nullptr || ent->Sector->Flags & SECF_SILENT || ent->Level != currentUILevel) return; FRolloffInfo rolloff; @@ -1360,7 +1360,7 @@ void S_SoundMinMaxDist(AActor *ent, int channel, FSoundID sound_id, float volume rolloff.RolloffType = ROLLOFF_Linear; rolloff.MinDistance = mindist; rolloff.MaxDistance = maxdist; - S_StartSound(ent, NULL, NULL, NULL, channel, sound_id, volume, 1, &rolloff); + S_StartSound(ent, nullptr, nullptr, nullptr, channel, sound_id, volume, 1, &rolloff); } //========================================================================== @@ -1371,7 +1371,8 @@ void S_SoundMinMaxDist(AActor *ent, int channel, FSoundID sound_id, float volume void S_Sound (const FPolyObj *poly, int channel, FSoundID sound_id, float volume, float attenuation) { - S_StartSound (NULL, NULL, poly, NULL, channel, sound_id, volume, attenuation); + if (poly->GetLevel() != currentUILevel) return; + S_StartSound (nullptr, nullptr, poly, nullptr, channel, sound_id, volume, attenuation); } //========================================================================== @@ -1380,11 +1381,12 @@ void S_Sound (const FPolyObj *poly, int channel, FSoundID sound_id, float volume // //========================================================================== -void S_Sound(const DVector3 &pos, int channel, FSoundID sound_id, float volume, float attenuation) +void S_Sound(FLevelLocals *Level, const DVector3 &pos, int channel, FSoundID sound_id, float volume, float attenuation) { + if (Level != currentUILevel) return; // The sound system switches Y and Z around. FVector3 p((float)pos.X, (float)pos.Z, (float)pos.Y); - S_StartSound (NULL, NULL, NULL, &p, channel, sound_id, volume, attenuation); + S_StartSound (nullptr, nullptr, nullptr, &p, channel, sound_id, volume, attenuation); } //========================================================================== @@ -1395,7 +1397,8 @@ void S_Sound(const DVector3 &pos, int channel, FSoundID sound_id, float volume, void S_Sound (const sector_t *sec, int channel, FSoundID sfxid, float volume, float attenuation) { - S_StartSound (NULL, sec, NULL, NULL, channel, sfxid, volume, attenuation); + if (sec->Level != currentUILevel) return; + S_StartSound (nullptr, sec, nullptr, nullptr, channel, sfxid, volume, attenuation); } //========================================================================== @@ -1408,7 +1411,7 @@ void S_Sound (const sector_t *sec, int channel, FSoundID sfxid, float volume, fl void S_PlaySound(AActor *a, int chan, FSoundID sid, float vol, float atten, bool local) { - if (a == nullptr) + if (a == nullptr || a->Sector->Flags & SECF_SILENT || a->Level != currentUILevel) return; if (!local) @@ -2182,7 +2185,7 @@ void S_UpdateSounds (AActor *listenactor) GSnd->UpdateListener(&listener); GSnd->UpdateSounds(); - if (level.time >= RestartEvictionsAt) + if (currentUILevel->time >= RestartEvictionsAt) { RestartEvictionsAt = 0; S_RestoreEvictedChannels(); @@ -2208,8 +2211,8 @@ static void S_SetListener(SoundListener &listener, AActor *listenactor) listener.velocity.Zero(); listener.position = listenactor->SoundPos(); listener.underwater = listenactor->waterlevel == 3; - assert(level.Zones.Size() > listenactor->Sector->ZoneNumber); - listener.Environment = level.Zones[listenactor->Sector->ZoneNumber].Environment; + assert(currentUILevel->Zones.Size() > listenactor->Sector->ZoneNumber); + listener.Environment = currentUILevel->Zones[listenactor->Sector->ZoneNumber].Environment; listener.valid = true; } else @@ -2487,7 +2490,7 @@ void S_SerializeSounds(FSerializer &arc) // playing before the wipe, and depending on the synchronization // between the main thread and the mixer thread at the time, the // sounds might be heard briefly before pausing for the wipe. - RestartEvictionsAt = level.time + 2; + RestartEvictionsAt = currentUILevel->time + 2; } GSnd->Sync(false); GSnd->UpdateSounds(); @@ -2577,8 +2580,8 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) { if (gamestate == GS_LEVEL || gamestate == GS_TITLELEVEL) { - musicname = level.Music; - order = level.musicorder; + musicname = currentUILevel->Music; + order = currentUILevel->musicorder; } else { diff --git a/src/s_sound.h b/src/s_sound.h index 7b971c046..a5f3c17a0 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -34,6 +34,7 @@ class AActor; class FScanner; class FSerializer; +struct FLevelLocals; // // SoundFX struct. @@ -228,7 +229,7 @@ void S_Sound (AActor *ent, int channel, FSoundID sfxid, float volume, float atte void S_SoundMinMaxDist (AActor *ent, int channel, FSoundID sfxid, float volume, float mindist, float maxdist); void S_Sound (const FPolyObj *poly, int channel, FSoundID sfxid, float volume, float attenuation); void S_Sound (const sector_t *sec, int channel, FSoundID sfxid, float volume, float attenuation); -void S_Sound(const DVector3 &pos, int channel, FSoundID sfxid, float volume, float attenuation); +void S_Sound(FLevelLocals *Level, const DVector3 &pos, int channel, FSoundID sfxid, float volume, float attenuation); // [Nash] Used by ACS and DECORATE void S_PlaySound(AActor *a, int chan, FSoundID sid, float vol, float atten, bool local);