Added, Search and Replace mode: "Find Sector Brightness" search mode now supports "<=", "<", ">=" and ">" prefixes.

Fixed, Sound Environment mode: fixed several cases when single-sided lines with only back side could cause either logic errors or crashes.
Fixed, Automap mode: fixed several cases when single-sided lines with only back side could cause logic errors.
Debug: added some debug code to WAD.Insert() to investigate the issue when lumpoffset could become negative.
This commit is contained in:
MaxED 2016-06-25 14:09:39 +00:00
parent 3c62e89ded
commit ea81ad80a8
6 changed files with 53 additions and 10 deletions

View file

@ -364,9 +364,18 @@ namespace CodeImp.DoomBuilder.IO
Lump lump = new Lump(file, this, Lump.MakeFixedName(name, ENCODING), lumpsoffset, datalength); Lump lump = new Lump(file, this, Lump.MakeFixedName(name, ENCODING), lumpsoffset, datalength);
lumps.Insert(position, lump); lumps.Insert(position, lump);
//dbg
int oldlumpoffset = lumpsoffset;
// Advance lumps table offset // Advance lumps table offset
lumpsoffset += datalength; lumpsoffset += datalength;
//dbg
if(lumpsoffset < 0)
{
throw new InvalidOperationException("Invalid lumpsoffset (" + lumpsoffset + ") after inserting lump \"" + name + "\" at position " + position + ", datalength=" + datalength + ". Previous lumpoffset was " + oldlumpoffset);
}
// Write the new headers // Write the new headers
if(writeheaders) WriteHeaders(); if(writeheaders) WriteHeaders();

View file

@ -180,7 +180,7 @@ namespace CodeImp.DoomBuilder.AutomapMode
return ColorSecret; return ColorSecret;
if(ld.IsFlagSet(BuilderPlug.Me.HiddenFlag)) return ColorHiddenFlag; if(ld.IsFlagSet(BuilderPlug.Me.HiddenFlag)) return ColorHiddenFlag;
if(ld.Back == null || ld.IsFlagSet(BuilderPlug.Me.SecretFlag)) return ColorSingleSided; if(ld.Back == null || ld.Front == null || ld.IsFlagSet(BuilderPlug.Me.SecretFlag)) return ColorSingleSided;
if(ld.Front.Sector.FloorHeight != ld.Back.Sector.FloorHeight) return ColorFloorDiff; if(ld.Front.Sector.FloorHeight != ld.Back.Sector.FloorHeight) return ColorFloorDiff;
if(ld.Front.Sector.CeilHeight != ld.Back.Sector.CeilHeight) return ColorCeilDiff; if(ld.Front.Sector.CeilHeight != ld.Back.Sector.CeilHeight) return ColorCeilDiff;
@ -196,8 +196,8 @@ namespace CodeImp.DoomBuilder.AutomapMode
{ {
if(menusform.ShowHiddenLines ^ General.Interface.CtrlState) return true; if(menusform.ShowHiddenLines ^ General.Interface.CtrlState) return true;
if(ld.IsFlagSet(BuilderPlug.Me.HiddenFlag)) return false; if(ld.IsFlagSet(BuilderPlug.Me.HiddenFlag)) return false;
if(ld.Back == null || ld.IsFlagSet(BuilderPlug.Me.SecretFlag)) return true; if(ld.Back == null || ld.Front == null || ld.IsFlagSet(BuilderPlug.Me.SecretFlag)) return true;
if(ld.Back != null && (ld.Front.Sector.FloorHeight != ld.Back.Sector.FloorHeight || ld.Front.Sector.CeilHeight != ld.Back.Sector.CeilHeight)) return true; if(ld.Back != null && ld.Front != null && (ld.Front.Sector.FloorHeight != ld.Back.Sector.FloorHeight || ld.Front.Sector.CeilHeight != ld.Back.Sector.CeilHeight)) return true;
return false; return false;
} }

View file

@ -1,5 +1,6 @@
#region ================== Namespaces #region ================== Namespaces
using System;
using System.Collections.Generic; using System.Collections.Generic;
using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Map;
using System.Windows.Forms; using System.Windows.Forms;
@ -11,6 +12,17 @@ namespace CodeImp.DoomBuilder.BuilderModes
[FindReplace("Sector Brightness", BrowseButton = false)] [FindReplace("Sector Brightness", BrowseButton = false)]
internal class FindSectorBrightness : BaseFindSector internal class FindSectorBrightness : BaseFindSector
{ {
#region ================== Properties
//mxd. Prefixes usage
public override string UsageHint { get { return "Supported prefixes:" + Environment.NewLine
+ "\"<=\" - finds values less or equal to given value;" + Environment.NewLine
+ "\">=\" - finds values greater or equal to given value;" + Environment.NewLine
+ "\"<\" - finds values less than given value;" + Environment.NewLine
+ "\">\" - finds values greater than given value."; } }
#endregion
#region ================== Methods #region ================== Methods
// This is called to perform a search (and replace) // This is called to perform a search (and replace)
@ -37,6 +49,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Interpret the number given // Interpret the number given
int brightness; int brightness;
string prefix = string.Empty; //mxd
//mxd. Check prefixes
value = value.Trim().Replace(" ", "");
if(value.StartsWith(">=") || value.StartsWith("<=")) prefix = value.Substring(0, 2);
else if(value.StartsWith(">") || value.StartsWith("<")) prefix = value.Substring(0, 1);
value = value.Remove(0, prefix.Length);
if(int.TryParse(value, out brightness)) if(int.TryParse(value, out brightness))
{ {
// Where to search? // Where to search?
@ -46,12 +66,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach(Sector s in list) foreach(Sector s in list)
{ {
// Brightness matches? // Brightness matches?
if(s.Brightness == brightness) if(BrightnessMatches(s.Brightness, brightness, prefix))
{ {
// Replace // Replace
if(replace) s.Brightness = replacebrightness; if(replace) s.Brightness = replacebrightness;
objs.Add(new FindReplaceObject(s, "Sector " + s.Index)); objs.Add(new FindReplaceObject(s, "Sector " + s.Index + (!replace ? " (Brightness " + s.Brightness + ")" : "")));
} }
} }
} }
@ -66,6 +86,20 @@ namespace CodeImp.DoomBuilder.BuilderModes
return objs.ToArray(); return objs.ToArray();
} }
//mxd
private static bool BrightnessMatches(int sectorbrightness, int brightness, string prefix)
{
switch(prefix)
{
case "": return sectorbrightness == brightness;
case "<=": return sectorbrightness <= brightness;
case ">=": return sectorbrightness >= brightness;
case "<": return sectorbrightness < brightness;
case ">": return sectorbrightness > brightness;
default: throw new NotImplementedException("Unknown prefix");
}
}
#endregion #endregion
} }

View file

@ -290,7 +290,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
continue; continue;
} }
if(sd.Line.Back == null) continue; if(sd.Other == null) continue;
Sector oppositesector = (sd.Line.Front.Sector == sector ? sd.Line.Back.Sector : sd.Line.Front.Sector); Sector oppositesector = (sd.Line.Front.Sector == sector ? sd.Line.Back.Sector : sd.Line.Front.Sector);

View file

@ -133,7 +133,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
linedefnode.ImageIndex = iconindex; //mxd linedefnode.ImageIndex = iconindex; //mxd
linedefnode.SelectedImageIndex = iconindex; //mxd linedefnode.SelectedImageIndex = iconindex; //mxd
if(ld.Back == null) if(ld.Back == null || ld.Front == null)
{ {
showwarning = true; showwarning = true;
linedefnode.ToolTipText = "This line is single-sided, but has\nthe sound boundary flag set."; linedefnode.ToolTipText = "This line is single-sided, but has\nthe sound boundary flag set.";

View file

@ -60,7 +60,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
if(blocksound) blockinglines.Add(sd.Line); if(blocksound) blockinglines.Add(sd.Line);
// If the line is one sided, the sound can travel nowhere, so try the next one // If the line is one sided, the sound can travel nowhere, so try the next one
if(sd.Line.Back == null || blocksound) continue; if(sd.Other == null || blocksound) continue;
// Get the sector on the other side of the line we're checking right now // Get the sector on the other side of the line we're checking right now
Sector oppositesector = sd.Other.Sector; Sector oppositesector = sd.Other.Sector;
@ -87,7 +87,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
{ {
// Lines that don't have a back side, or where the sound is blocked due to // 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 // the sector heights on each side can be skipped
if(ld.Back == null || IsSoundBlockedByHeight(ld)) continue; if(IsSoundBlockedByHeight(ld)) continue;
if(!sectors.Contains(ld.Front.Sector)) adjacentsectors.Add(ld.Front.Sector); if(!sectors.Contains(ld.Front.Sector)) adjacentsectors.Add(ld.Front.Sector);
if(!sectors.Contains(ld.Back.Sector)) adjacentsectors.Add(ld.Back.Sector); if(!sectors.Contains(ld.Back.Sector)) adjacentsectors.Add(ld.Back.Sector);
} }
@ -111,7 +111,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
private static bool IsSoundBlockedByHeight(Linedef ld) private static bool IsSoundBlockedByHeight(Linedef ld)
{ {
if(ld.Back == null) return false; if(ld.Back == null || ld.Front == null) return false;
Sector s1 = ld.Front.Sector; Sector s1 = ld.Front.Sector;
Sector s2 = ld.Back.Sector; Sector s2 = ld.Back.Sector;