Permalink
Browse files

- Changed the sound system to ignore sounds not from the primary level.

This is a task for later when other things actually work, but until then, any sound from a sub-level should simply not play at all.
This required giving the positioned S_Sound version a Level argument so that the sound engine can check which level such a sound belongs to.
  • Loading branch information...
coelckers committed Jan 9, 2019
1 parent 00b4928 commit 45a4bc88a2b7a0cede3cb267c4c6d360f40d9334
Showing with 27 additions and 20 deletions.
  1. +1 −1 src/p_effect.cpp
  2. +2 −2 src/p_mobj.cpp
  3. +2 −2 src/p_switch.cpp
  4. +21 −14 src/s_sound.cpp
  5. +1 −1 src/s_sound.h
@@ -701,7 +701,7 @@ void P_DrawRailTrail(AActor *source, TArray<SPortalHit> &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 (mo->Level, DVector3(shortest->soundpos, r_viewpoint.Pos.Z), CHAN_WEAPON, sound, 1, ATTN_NORM);
}
}
}
@@ -6076,7 +6076,7 @@ bool P_HitWater (AActor * thing, sector_t * sec, const DVector3 &pos, bool check
}
else
{
S_Sound(pos, CHAN_ITEM, smallsplash ?
S_Sound(sec->Level, pos, CHAN_ITEM, smallsplash ?
splash->SmallSplashSound : splash->NormalSplashSound,
1, ATTN_IDLE);
}
@@ -6284,7 +6284,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);
}
}
}
@@ -303,7 +303,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->sector->Level, DVector3(pt, 0), CHAN_VOICE|CHAN_LISTENERZ, sound, 1, ATTN_STATIC);
}
if (quest != NULL)
{
@@ -412,7 +412,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;
@@ -130,12 +130,13 @@ static void CalcPosVel(int type, const AActor *actor, const sector_t *sector, co
const float pt[3], int channel, int chanflags, FVector3 *pos, FVector3 *vel);
static void CalcSectorSoundOrg(const DVector3 &listenpos, const sector_t *sec, int channum, FVector3 &res);
static void CalcPolyobjSoundOrg(const DVector3 &listenpos, const FPolyObj *poly, FVector3 &res);
static FSoundChan *S_StartSound(AActor *mover, const sector_t *sec, const FPolyObj *poly,
static FSoundChan *S_StartSound(FLevelLocals *Level, AActor *mover, const sector_t *sec, const FPolyObj *poly,
const FVector3 *pt, int channel, FSoundID sound_id, float volume, float attenuation, FRolloffInfo *rolloff);
static void S_SetListener(SoundListener &listener, AActor *listenactor);

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static FLevelLocals *SoundMainLevel; // this is the level for which sound should be played.
static bool SoundPaused; // whether sound is paused
static bool MusicPaused; // whether music is paused
MusPlayingInfo mus_playing; // music currently being played
@@ -394,6 +395,7 @@ void S_Start (FLevelLocals *Level)
{
if (GSnd)
{
SoundMainLevel = Level;
// kill all playing sounds at start of level (trust me - a good idea)
S_StopAllChannels();

@@ -691,29 +693,27 @@ static void CalcPosVel( int type, const AActor *actor, const sector_t *sector,
DVector3 listenpos;
int pgroup;
AActor *listener = players[consoleplayer].camera;
FLevelLocals *Level;
FLevelLocals *Level = SoundMainLevel;

if (listener != nullptr)
{
listenpos = listener->Pos();
*pos = listener->SoundPos();
pgroup = listener->Sector->PortalGroup;
Level = listener->Level;
}
else
{
listenpos.Zero();
pos->Zero();
pgroup = 0;
type = SOURCE_None; // No level means that no level sound placement should be performed.
Level = nullptr;
}

// [BL] Moved this case out of the switch statement to make code easier
// on static analysis.
if(type == SOURCE_Unattached)
{
assert(Level != nullptr);
assert(Level != NULL);
sector_t *sec = P_PointInSector(pt[0], pt[2]);
DVector2 disp = Level->Displacements.getOffset(pgroup, sec->PortalGroup);
pos->X = pt[0] - (float)disp.X;
@@ -766,7 +766,8 @@ static void CalcPosVel( int type, const AActor *actor, const sector_t *sector,
assert(poly != NULL);
if (poly != NULL)
{
assert(Level != nullptr);
assert(Level != NULL);
// Todo: Level offsetting
DVector2 disp = Level->Displacements.getOffset(pgroup, poly->CenterSubsector->sector->PortalGroup);
CalcPolyobjSoundOrg(listenpos + disp, poly, *pos);
pos->X -= (float)disp.X;
@@ -934,7 +935,7 @@ static void CalcPolyobjSoundOrg(const DVector3 &listenpos, const FPolyObj *poly,
//
//==========================================================================

static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyObj *poly,
static FSoundChan *S_StartSound(FLevelLocals *Level, AActor *actor, const sector_t *sec, const FPolyObj *poly,
const FVector3 *pt, int channel, FSoundID sound_id, float volume, float attenuation,
FRolloffInfo *forcedrolloff=NULL)
{
@@ -951,6 +952,12 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO
if (sound_id <= 0 || volume <= 0 || nosfx || nosound )
return NULL;

// Playing sounds from other than the primary level is a job for later. For now, just do not play them.
if (Level && Level != SoundMainLevel)
{
return nullptr;
}

int type;

if (actor != NULL)
@@ -1327,7 +1334,7 @@ void S_RestartSound(FSoundChan *chan)

void S_Sound (int channel, FSoundID sound_id, float volume, float attenuation)
{
S_StartSound (NULL, NULL, NULL, NULL, channel, sound_id, volume, attenuation);
S_StartSound (NULL, NULL, NULL, NULL, NULL, channel, sound_id, volume, attenuation);
}

DEFINE_ACTION_FUNCTION(DObject, S_Sound)
@@ -1351,7 +1358,7 @@ void S_Sound (AActor *ent, int channel, FSoundID sound_id, float volume, float a
{
if (ent == NULL || ent->Sector->Flags & SECF_SILENT)
return;
S_StartSound (ent, NULL, NULL, NULL, channel, sound_id, volume, attenuation);
S_StartSound (ent->Level, ent, NULL, NULL, NULL, channel, sound_id, volume, attenuation);
}

//==========================================================================
@@ -1372,7 +1379,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->Level, ent, NULL, NULL, NULL, channel, sound_id, volume, 1, &rolloff);
}

//==========================================================================
@@ -1383,7 +1390,7 @@ 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);
S_StartSound (poly->GetLevel(), NULL, NULL, poly, NULL, channel, sound_id, volume, attenuation);
}

//==========================================================================
@@ -1392,11 +1399,11 @@ 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)
{
// 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 (Level, NULL, NULL, NULL, &p, channel, sound_id, volume, attenuation);
}

//==========================================================================
@@ -1407,7 +1414,7 @@ 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);
S_StartSound (sec->Level, NULL, sec, NULL, NULL, channel, sfxid, volume, attenuation);
}

//==========================================================================
@@ -229,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);

0 comments on commit 45a4bc8

Please sign in to comment.