From aa7bfd77c367bfd99826bae29b4ecf4624765c81 Mon Sep 17 00:00:00 2001 From: MaxED Date: Mon, 4 May 2015 07:19:26 +0000 Subject: [PATCH] Applied SoundPropagationMode patch by Boris. --- .../SoundPropagationDomain.cs | 34 +++++++++++-------- .../SoundPropagationMode.cs | 14 ++++++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs b/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs index 1dc4e8a0..1b8cb65e 100644 --- a/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs +++ b/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs @@ -57,27 +57,15 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode foreach (Sidedef sd in sector.Sidedefs) { bool blocksound = sd.Line.IsFlagSet(General.Map.UDMF ? "blocksound" : "64"); - bool blockheight = false; - Sector oppositesector; - if (blocksound) blockinglines.Add(sd.Line); // If the line is one sided, the sound can travel nowhere, so try the next one if (sd.Line.Back == null || blocksound) continue; // Get the sector on the other side of the line we're checking right now - if (sd.Line.Front.Sector == sector) - oppositesector = sd.Line.Back.Sector; - else - oppositesector = sd.Line.Front.Sector; + Sector oppositesector = sd.Other.Sector; - // Check if the sound will be blocked because of sector floor and ceiling heights - // (like closed doors, raised lifts etc.) - if (sector.CeilHeight <= oppositesector.FloorHeight || sector.FloorHeight >= oppositesector.CeilHeight - || oppositesector.CeilHeight <= oppositesector.FloorHeight || sector.CeilHeight <= sector.FloorHeight) - { - blockheight = true; - } + bool blockheight = IsSoundBlockedByHeight(sd.Line); // Try next line if sound will not pass through the current one. The last check makes // sure that the next line is tried if the current line is blocking sound, and the current @@ -97,8 +85,11 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode foreach (Linedef ld in blockinglines) { + // Lines that don't have a back side, or where the sound is blocked due to + // the sector heights on each side can be skipped + if (ld.Back == null || IsSoundBlockedByHeight(ld)) continue; if (!sectors.Contains(ld.Front.Sector)) adjacentsectors.Add(ld.Front.Sector); - if (ld.Back != null && !sectors.Contains(ld.Back.Sector)) adjacentsectors.Add(ld.Back.Sector); + if (!sectors.Contains(ld.Back.Sector)) adjacentsectors.Add(ld.Back.Sector); } List vertices = new List(); @@ -118,6 +109,19 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode } } + private static bool IsSoundBlockedByHeight(Linedef ld) + { + if(ld.Back == null) return false; + + Sector s1 = ld.Front.Sector; + Sector s2 = ld.Back.Sector; + + // Check if the sound will be blocked because of sector floor and ceiling heights + // (like closed doors, raised lifts etc.) + return (s1.CeilHeight <= s2.FloorHeight || s1.FloorHeight >= s2.CeilHeight || + s2.CeilHeight <= s2.FloorHeight || s1.CeilHeight <= s1.FloorHeight); + } + #endregion } } diff --git a/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs b/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs index 4e03e420..4ff1dec7 100644 --- a/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs +++ b/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs @@ -119,6 +119,13 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode private void UpdateSoundPropagation() { huntingThings.Clear(); + + BuilderPlug.Me.BlockingLinedefs.Clear(); + + foreach (Linedef ld in General.Map.Map.Linedefs) + if (ld.IsFlagSet(General.Map.UDMF ? "blocksound" : "64")) + BuilderPlug.Me.BlockingLinedefs.Add(ld); + if (highlighted == null || highlighted.IsDisposed) return; if (!sector2domain.ContainsKey(highlighted)) @@ -126,7 +133,6 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode SoundPropagationDomain spd = new SoundPropagationDomain(highlighted); foreach (Sector s in spd.Sectors) sector2domain[s] = spd; propagationdomains.Add(spd); - BuilderPlug.Me.BlockingLinedefs.AddRange(spd.BlockingLines); } foreach (Sector adjacent in sector2domain[highlighted].AdjacentSectors) @@ -135,11 +141,10 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode { SoundPropagationDomain aspd = new SoundPropagationDomain(adjacent); foreach (Sector s in aspd.Sectors) sector2domain[s] = aspd; - BuilderPlug.Me.BlockingLinedefs.AddRange(aspd.BlockingLines); } } - //mxd. Create the list of sectors, which will be affected by nose made in highlighted sector + //mxd. Create the list of sectors, which will be affected by noise made in highlighted sector SoundPropagationDomain curdomain = sector2domain[highlighted]; Dictionary noisysectors = new Dictionary(curdomain.Sectors.Count); foreach(Sector s in curdomain.Sectors) @@ -209,6 +214,9 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode // Convert geometry selection to sectors only General.Map.Map.ConvertSelection(SelectionType.Sectors); + + UpdateSoundPropagation(); + General.Interface.RedrawDisplay(); } // Mode disengages