From 5d6e077efb528354161ad7c4521e800627460ed4 Mon Sep 17 00:00:00 2001 From: codeimp Date: Tue, 12 May 2009 18:20:03 +0000 Subject: [PATCH] - Added check to remove zero-length linedefs when opening a map that has any - Some minor interface polishing --- Source/Core/IO/DoomMapSetIO.cs | 114 ++++++++++-------- Source/Core/IO/HexenMapSetIO.cs | 114 ++++++++++-------- Source/Core/IO/UniversalStreamReader.cs | 48 +++++--- .../ErrorChecks/CheckStuckedThings.cs | 2 +- .../Interface/ErrorCheckForm.Designer.cs | 20 +-- .../Interface/ErrorCheckForm.resx | 33 +++++ 6 files changed, 194 insertions(+), 137 deletions(-) diff --git a/Source/Core/IO/DoomMapSetIO.cs b/Source/Core/IO/DoomMapSetIO.cs index 56a0ff8f..c919843f 100644 --- a/Source/Core/IO/DoomMapSetIO.cs +++ b/Source/Core/IO/DoomMapSetIO.cs @@ -300,75 +300,83 @@ namespace CodeImp.DoomBuilder.IO // Create new linedef if(vertexlink.ContainsKey(v1) && vertexlink.ContainsKey(v2)) { - l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); - l.Update(stringflags, 0, tag, action, new int[Linedef.NUM_ARGS]); - l.UpdateCache(); - - // Line has a front side? - if(s1 != ushort.MaxValue) + // Check if not zero-length + if(Vector2D.ManhattanDistance(vertexlink[v1].Position, vertexlink[v2].Position) > 0.0001f) { - // Read front sidedef - if((s1 * 30L) <= (sidedefsmem.Length - 30L)) - { - sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin); - offsetx = readside.ReadInt16(); - offsety = readside.ReadInt16(); - thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - sc = readside.ReadUInt16(); + l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); + l.Update(stringflags, 0, tag, action, new int[Linedef.NUM_ARGS]); + l.UpdateCache(); - // Create front sidedef - if(sectorlink.ContainsKey(sc)) + // Line has a front side? + if(s1 != ushort.MaxValue) + { + // Read front sidedef + if((s1 * 30L) <= (sidedefsmem.Length - 30L)) { - s = map.CreateSidedef(l, true, sectorlink[sc]); - s.Update(offsetx, offsety, thigh, tmid, tlow); + sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin); + offsetx = readside.ReadInt16(); + offsety = readside.ReadInt16(); + thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + sc = readside.ReadUInt16(); + + // Create front sidedef + if(sectorlink.ContainsKey(sc)) + { + s = map.CreateSidedef(l, true, sectorlink[sc]); + s.Update(offsetx, offsety, thigh, tmid, tlow); + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s1 + " references invalid sector " + sc + ". Sidedef has been removed."); + } } else { - General.ErrorLogger.Add(ErrorType.Warning, "Sidedef references invalid sector " + sc + ". Sidedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef " + s1 + ". Sidedef has been removed."); } } - else + + // Line has a back side? + if(s2 != ushort.MaxValue) { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); + // Read back sidedef + if((s2 * 30L) <= (sidedefsmem.Length - 30L)) + { + sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin); + offsetx = readside.ReadInt16(); + offsety = readside.ReadInt16(); + thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + sc = readside.ReadUInt16(); + + // Create back sidedef + if(sectorlink.ContainsKey(sc)) + { + s = map.CreateSidedef(l, false, sectorlink[sc]); + s.Update(offsetx, offsety, thigh, tmid, tlow); + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s2 + " references invalid sector " + sc + ". Sidedef has been removed."); + } + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s2 + ". Sidedef has been removed."); + } } } - - // Line has a back side? - if(s2 != ushort.MaxValue) + else { - // Read back sidedef - if((s2 * 30L) <= (sidedefsmem.Length - 30L)) - { - sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin); - offsetx = readside.ReadInt16(); - offsety = readside.ReadInt16(); - thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - sc = readside.ReadUInt16(); - - // Create back sidedef - if(sectorlink.ContainsKey(sc)) - { - s = map.CreateSidedef(l, false, sectorlink[sc]); - s.Update(offsetx, offsety, thigh, tmid, tlow); - } - else - { - General.ErrorLogger.Add(ErrorType.Warning, "Sidedef references invalid sector " + sc + ". Sidedef has been removed."); - } - } - else - { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); - } + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " is zero-length. Linedef has been removed."); } } else { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references one or more invalid vertices. Linedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references one or more invalid vertices. Linedef has been removed."); } } diff --git a/Source/Core/IO/HexenMapSetIO.cs b/Source/Core/IO/HexenMapSetIO.cs index 320f59ec..b54642bd 100644 --- a/Source/Core/IO/HexenMapSetIO.cs +++ b/Source/Core/IO/HexenMapSetIO.cs @@ -315,75 +315,83 @@ namespace CodeImp.DoomBuilder.IO // Create new linedef if(vertexlink.ContainsKey(v1) && vertexlink.ContainsKey(v2)) { - l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); - l.Update(stringflags, (flags & manager.Config.LinedefActivationsFilter), 0, action, args); - l.UpdateCache(); - - // Line has a front side? - if(s1 != ushort.MaxValue) + // Check if not zero-length + if(Vector2D.ManhattanDistance(vertexlink[v1].Position, vertexlink[v2].Position) > 0.0001f) { - // Read front sidedef - sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin); - if((s1 * 30L) <= (sidedefsmem.Length - 30L)) - { - offsetx = readside.ReadInt16(); - offsety = readside.ReadInt16(); - thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - sc = readside.ReadUInt16(); + l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); + l.Update(stringflags, (flags & manager.Config.LinedefActivationsFilter), 0, action, args); + l.UpdateCache(); - // Create front sidedef - if(sectorlink.ContainsKey(sc)) + // Line has a front side? + if(s1 != ushort.MaxValue) + { + // Read front sidedef + sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin); + if((s1 * 30L) <= (sidedefsmem.Length - 30L)) { - s = map.CreateSidedef(l, true, sectorlink[sc]); - s.Update(offsetx, offsety, thigh, tmid, tlow); + offsetx = readside.ReadInt16(); + offsety = readside.ReadInt16(); + thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + sc = readside.ReadUInt16(); + + // Create front sidedef + if(sectorlink.ContainsKey(sc)) + { + s = map.CreateSidedef(l, true, sectorlink[sc]); + s.Update(offsetx, offsety, thigh, tmid, tlow); + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s1 + " references invalid sector " + sc + ". Sidedef has been removed."); + } } else { - General.ErrorLogger.Add(ErrorType.Warning, "Sidedef references invalid sector " + sc + ". Sidedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s1 + ". Sidedef has been removed."); } } - else + + // Line has a back side? + if(s2 != ushort.MaxValue) { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); + // Read back sidedef + sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin); + if((s2 * 30L) <= (sidedefsmem.Length - 30L)) + { + offsetx = readside.ReadInt16(); + offsety = readside.ReadInt16(); + thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); + sc = readside.ReadUInt16(); + + // Create back sidedef + if(sectorlink.ContainsKey(sc)) + { + s = map.CreateSidedef(l, false, sectorlink[sc]); + s.Update(offsetx, offsety, thigh, tmid, tlow); + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s2 + " references invalid sector " + sc + ". Sidedef has been removed."); + } + } + else + { + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s2 + ". Sidedef has been removed."); + } } } - - // Line has a back side? - if(s2 != ushort.MaxValue) + else { - // Read back sidedef - sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin); - if((s2 * 30L) <= (sidedefsmem.Length - 30L)) - { - offsetx = readside.ReadInt16(); - offsety = readside.ReadInt16(); - thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING); - sc = readside.ReadUInt16(); - - // Create back sidedef - if(sectorlink.ContainsKey(sc)) - { - s = map.CreateSidedef(l, false, sectorlink[sc]); - s.Update(offsetx, offsety, thigh, tmid, tlow); - } - else - { - General.ErrorLogger.Add(ErrorType.Warning, "Sidedef references invalid sector " + sc + ". Sidedef has been removed."); - } - } - else - { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); - } + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " is zero-length. Linedef has been removed."); } } else { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references one or more invalid vertices. Linedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references one or more invalid vertices. Linedef has been removed."); } } diff --git a/Source/Core/IO/UniversalStreamReader.cs b/Source/Core/IO/UniversalStreamReader.cs index 6c373eb2..41dca57c 100644 --- a/Source/Core/IO/UniversalStreamReader.cs +++ b/Source/Core/IO/UniversalStreamReader.cs @@ -230,33 +230,41 @@ namespace CodeImp.DoomBuilder.IO // Create new linedef if(vertexlink.ContainsKey(v1) && vertexlink.ContainsKey(v2)) { - Linedef l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); - l.Update(stringflags, 0, tag, special, args); - l.UpdateCache(); - - // Custom fields - ReadCustomFields(lc, l, "linedef"); - - // Read sidedefs and connect them to the line - if(s1 > -1) + // Check if not zero-length + if(Vector2D.ManhattanDistance(vertexlink[v1].Position, vertexlink[v2].Position) > 0.0001f) { - if(s1 < sidescolls.Count) - ReadSidedef(map, sidescolls[s1], l, true, sectorlink); - else - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); + Linedef l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]); + l.Update(stringflags, 0, tag, special, args); + l.UpdateCache(); + + // Custom fields + ReadCustomFields(lc, l, "linedef"); + + // Read sidedefs and connect them to the line + if(s1 > -1) + { + if(s1 < sidescolls.Count) + ReadSidedef(map, sidescolls[s1], l, true, sectorlink); + else + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid front sidedef " + s1 + ". Sidedef has been removed."); + } + + if(s2 > -1) + { + if(s2 < sidescolls.Count) + ReadSidedef(map, sidescolls[s2], l, false, sectorlink); + else + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid back sidedef " + s1 + ". Sidedef has been removed."); + } } - - if(s2 > -1) + else { - if(s2 < sidescolls.Count) - ReadSidedef(map, sidescolls[s2], l, false, sectorlink); - else - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef. Sidedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " is zero-length. Linedef has been removed."); } } else { - General.ErrorLogger.Add(ErrorType.Warning, "Linedef references one or more invalid vertices. Linedef has been removed."); + General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references one or more invalid vertices. Linedef has been removed."); } } } diff --git a/Source/Plugins/BuilderModes/ErrorChecks/CheckStuckedThings.cs b/Source/Plugins/BuilderModes/ErrorChecks/CheckStuckedThings.cs index bdab310d..4b247614 100644 --- a/Source/Plugins/BuilderModes/ErrorChecks/CheckStuckedThings.cs +++ b/Source/Plugins/BuilderModes/ErrorChecks/CheckStuckedThings.cs @@ -40,7 +40,7 @@ using System.Drawing; namespace CodeImp.DoomBuilder.BuilderModes { - [ErrorChecker("Check for stuck things", true, 1000)] + [ErrorChecker("Check stuck things", true, 1000)] public class CheckStuckedThings : ErrorChecker { #region ================== Constants diff --git a/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.Designer.cs b/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.Designer.cs index 0b32f88b..5fce384b 100644 --- a/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.Designer.cs @@ -50,13 +50,13 @@ namespace CodeImp.DoomBuilder.BuilderModes this.checks.Location = new System.Drawing.Point(10, 15); this.checks.Margin = new System.Windows.Forms.Padding(1); this.checks.Name = "checks"; - this.checks.Size = new System.Drawing.Size(360, 108); + this.checks.Size = new System.Drawing.Size(360, 63); this.checks.TabIndex = 0; // // buttoncheck // this.buttoncheck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttoncheck.Location = new System.Drawing.Point(254, 134); + this.buttoncheck.Location = new System.Drawing.Point(254, 89); this.buttoncheck.Margin = new System.Windows.Forms.Padding(1); this.buttoncheck.Name = "buttoncheck"; this.buttoncheck.Size = new System.Drawing.Size(116, 25); @@ -76,7 +76,7 @@ namespace CodeImp.DoomBuilder.BuilderModes this.results.Location = new System.Drawing.Point(10, 34); this.results.Margin = new System.Windows.Forms.Padding(1); this.results.Name = "results"; - this.results.Size = new System.Drawing.Size(360, 172); + this.results.Size = new System.Drawing.Size(360, 175); this.results.TabIndex = 0; this.results.SelectedIndexChanged += new System.EventHandler(this.results_SelectedIndexChanged); // @@ -88,15 +88,15 @@ namespace CodeImp.DoomBuilder.BuilderModes this.resultspanel.Controls.Add(this.fix1); this.resultspanel.Controls.Add(this.progress); this.resultspanel.Controls.Add(this.results); - this.resultspanel.Location = new System.Drawing.Point(0, 170); + this.resultspanel.Location = new System.Drawing.Point(0, 124); this.resultspanel.Name = "resultspanel"; - this.resultspanel.Size = new System.Drawing.Size(383, 326); + this.resultspanel.Size = new System.Drawing.Size(383, 329); this.resultspanel.TabIndex = 2; // // fix3 // this.fix3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.fix3.Location = new System.Drawing.Point(256, 289); + this.fix3.Location = new System.Drawing.Point(256, 292); this.fix3.Name = "fix3"; this.fix3.Size = new System.Drawing.Size(114, 26); this.fix3.TabIndex = 3; @@ -108,7 +108,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // fix2 // this.fix2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.fix2.Location = new System.Drawing.Point(133, 289); + this.fix2.Location = new System.Drawing.Point(133, 292); this.fix2.Name = "fix2"; this.fix2.Size = new System.Drawing.Size(114, 26); this.fix2.TabIndex = 2; @@ -122,7 +122,7 @@ namespace CodeImp.DoomBuilder.BuilderModes this.resultinfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.resultinfo.Enabled = false; - this.resultinfo.Location = new System.Drawing.Point(12, 212); + this.resultinfo.Location = new System.Drawing.Point(12, 215); this.resultinfo.Name = "resultinfo"; this.resultinfo.Size = new System.Drawing.Size(358, 74); this.resultinfo.TabIndex = 5; @@ -131,7 +131,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // fix1 // this.fix1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.fix1.Location = new System.Drawing.Point(10, 289); + this.fix1.Location = new System.Drawing.Point(10, 292); this.fix1.Name = "fix1"; this.fix1.Size = new System.Drawing.Size(114, 26); this.fix1.TabIndex = 1; @@ -168,7 +168,7 @@ namespace CodeImp.DoomBuilder.BuilderModes this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.CancelButton = this.closebutton; - this.ClientSize = new System.Drawing.Size(380, 493); + this.ClientSize = new System.Drawing.Size(380, 453); this.Controls.Add(this.closebutton); this.Controls.Add(this.resultspanel); this.Controls.Add(this.buttoncheck); diff --git a/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.resx b/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.resx index ff31a6db..41956585 100644 --- a/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.resx +++ b/Source/Plugins/BuilderModes/Interface/ErrorCheckForm.resx @@ -117,4 +117,37 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file