more work on map analysis

This commit is contained in:
codeimp 2008-10-24 14:53:04 +00:00
parent 180e252163
commit 22d903c630
5 changed files with 453 additions and 10 deletions

View file

@ -45,11 +45,14 @@
<Compile Include="ClassicModes\FindReplaceMode.cs" />
<Compile Include="ClassicModes\MakeSectorMode.cs" />
<Compile Include="ErrorChecks\CheckStuckedThings.cs" />
<Compile Include="ErrorChecks\ResultThingOutside.cs" />
<Compile Include="ErrorChecks\CheckLineReferences.cs" />
<Compile Include="ErrorChecks\ResultLineMissingFront.cs" />
<Compile Include="ErrorChecks\ResultLineMissingSides.cs" />
<Compile Include="ErrorChecks\ResultStuckedThing.cs" />
<Compile Include="ErrorChecks\ErrorResult.cs" />
<Compile Include="ErrorChecks\ErrorCheckerAttribute.cs" />
<Compile Include="ErrorChecks\ErrorChecker.cs" />
<Compile Include="ErrorChecks\ResultThingOutside.cs" />
<Compile Include="FindReplace\FindLinedefTypes.cs" />
<Compile Include="FindReplace\FindReplaceAttribute.cs" />
<Compile Include="FindReplace\FindReplaceObject.cs" />

View file

@ -0,0 +1,100 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.Config;
using System.Threading;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
[ErrorChecker("Check line references", true, 50)]
public class CheckLineReferences : ErrorChecker
{
#region ================== Constants
#endregion
#region ================== Constructor / Destructor
// Constructor
public CheckLineReferences()
{
// Total progress is done when all things are checked
SetTotalProgress(General.Map.Map.Linedefs.Count);
}
#endregion
#region ================== Methods
// This runs the check
public override void Run()
{
// Go for all the liendefs
foreach(Linedef l in General.Map.Map.Linedefs)
{
// Line has a back side but no front side?
if((l.Back != null) && (l.Front == null))
{
SubmitResult(new ResultLineMissingFront(l));
}
// Line has no sides at all?
else if((l.Back == null) && (l.Front == null))
{
SubmitResult(new ResultLineMissingSides(l));
}
// Line is marked double-sided, but has only one side?
else if(l.IsFlagSet(General.Map.Config.DoubleSidedFlag) && (l.Back == null))
{
// ERROR: Linedef is incorrectly marked double-sided
}
// Line is marked single-sided, and has two sides?
else if(!l.IsFlagSet(General.Map.Config.DoubleSidedFlag) && (l.Back != null))
{
// ERROR: Linedef is incorrectly marked single-sided
}
// Handle thread interruption
try { Thread.Sleep(0); }
catch(ThreadInterruptedException) { return; }
// We are making progress!
AddProgress(1);
}
}
#endregion
}
}

View file

@ -0,0 +1,141 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.Config;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
public class ResultLineMissingFront : ErrorResult
{
#region ================== Variables
private Linedef line;
private int buttons;
private Sidedef copysidedef;
#endregion
#region ================== Properties
public override int Buttons { get { return buttons; } }
public override string Button1Text { get { return "Flip Linedef"; } }
public override string Button2Text { get { return "Create Sidedef"; } }
#endregion
#region ================== Constructor / Destructor
// Constructor
public ResultLineMissingFront(Linedef l)
{
// Initialize
this.line = l;
this.description = "This linedef has a back sidedef, but is missing a front sidedef. " +
"A line must have at least a front side and optionally a back side! " +
"Click Flip Linedef if the line is supposed to be single-sided.";
// One solution is to flip the sidedefs
buttons = 1;
// Check if the linedef can join a sector on the side where it is missing a sidedef
bool fixable = false;
List<LinedefSide> sides = Tools.FindPotentialSectorAt(l, true);
if(sides != null)
{
foreach(LinedefSide sd in sides)
{
// If any of the sides lies along a sidedef, then we can copy
// that sidedef to fix the missing sidedef on this line.
if(sd.Front && (sd.Line.Front != null))
{
copysidedef = sd.Line.Front;
fixable = true;
break;
}
else if(!sd.Front && (sd.Line.Back != null))
{
copysidedef = sd.Line.Back;
fixable = true;
break;
}
}
}
// Fixable?
if(fixable)
{
buttons++;
this.description += " Or click Create Sidedef to rebuild the missing sidedef (making the line double-sided).";
}
}
#endregion
#region ================== Methods
// This must return the string that is displayed in the listbox
public override string ToString()
{
return "Linedef is missing front side";
}
// Rendering
public override void PlotSelection(IRenderer2D renderer)
{
renderer.PlotLinedef(line, General.Colors.Selection);
}
// Fix by flipping linedefs
public override bool Button1Click()
{
line.FlipSidedefs();
General.Map.Map.Update();
return true;
}
// Fix by creating a sidedef
public override bool Button2Click()
{
Sidedef newside = General.Map.Map.CreateSidedef(line, true, copysidedef.Sector);
copysidedef.CopyPropertiesTo(newside);
line.ApplySidedFlags();
General.Map.Map.Update();
return true;
}
#endregion
}
}

View file

@ -0,0 +1,199 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.Config;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
public class ResultLineMissingSides : ErrorResult
{
#region ================== Variables
private Linedef line;
private int buttons;
private Sidedef copysidedeffront;
private Sidedef copysidedefback;
#endregion
#region ================== Properties
public override int Buttons { get { return buttons; } }
public override string Button1Text { get { return "Create One Side"; } }
public override string Button2Text { get { return "Create Both Sides"; } }
#endregion
#region ================== Constructor / Destructor
// Constructor
public ResultLineMissingSides(Linedef l)
{
List<LinedefSide> sides;
bool fixable;
// Initialize
this.line = l;
this.description = "This linedef is missing front and back sidedefs." +
"A line must have at least a front side and optionally a back side!";
buttons = 0;
// Check if we can join a sector on the front side
fixable = false;
sides = Tools.FindPotentialSectorAt(l, true);
if(sides != null)
{
foreach(LinedefSide sd in sides)
{
// If any of the sides lies along a sidedef, then we can copy
// that sidedef to fix the missing sidedef on this line.
if(sd.Front && (sd.Line.Front != null))
{
copysidedeffront = sd.Line.Front;
fixable = true;
break;
}
else if(!sd.Front && (sd.Line.Back != null))
{
copysidedeffront = sd.Line.Back;
fixable = true;
break;
}
}
}
// Fixable?
if(fixable) buttons++;
// Check if we can join a sector on the back side
fixable = false;
sides = Tools.FindPotentialSectorAt(l, false);
if(sides != null)
{
foreach(LinedefSide sd in sides)
{
// If any of the sides lies along a sidedef, then we can copy
// that sidedef to fix the missing sidedef on this line.
if(sd.Front && (sd.Line.Front != null))
{
copysidedefback = sd.Line.Front;
fixable = true;
break;
}
else if(!sd.Front && (sd.Line.Back != null))
{
copysidedefback = sd.Line.Back;
fixable = true;
break;
}
}
}
// Fixable?
if(fixable) buttons++;
// Now make a fine description
switch(buttons)
{
case 0: description += " Doom Builder could not find a solution to fix this line."; break;
case 1: description += " Click Create One Side to rebuild a single sidedef, making this line single-sided."; break;
case 2: description += " Click Create Both Side to rebuild both sides of the line, making this line double-sided."; break;
}
}
#endregion
#region ================== Methods
// This must return the string that is displayed in the listbox
public override string ToString()
{
return "Linedef is missing both sides";
}
// Rendering
public override void PlotSelection(IRenderer2D renderer)
{
renderer.PlotLinedef(line, General.Colors.Selection);
}
// Fix a single side
public override bool Button1Click()
{
// On which side can we fix?
if(copysidedeffront != null)
{
// Front
Sidedef newside = General.Map.Map.CreateSidedef(line, true, copysidedeffront.Sector);
copysidedeffront.CopyPropertiesTo(newside);
}
else if(copysidedefback != null)
{
// Back
// Because the line is single-sided, we make the sidedef on the front.
// We will then flip it to make sure to ends up in the right position.
Sidedef newside = General.Map.Map.CreateSidedef(line, true, copysidedefback.Sector);
copysidedefback.CopyPropertiesTo(newside);
line.FlipVertices();
}
line.ApplySidedFlags();
General.Map.Map.Update();
return true;
}
// Fix both sides
public override bool Button2Click()
{
Sidedef newside;
// Front
newside = General.Map.Map.CreateSidedef(line, true, copysidedeffront.Sector);
copysidedeffront.CopyPropertiesTo(newside);
// Back
newside = General.Map.Map.CreateSidedef(line, false, copysidedefback.Sector);
copysidedefback.CopyPropertiesTo(newside);
line.ApplySidedFlags();
General.Map.Map.Update();
return true;
}
#endregion
}
}

View file

@ -75,7 +75,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, 164);
this.results.Size = new System.Drawing.Size(360, 172);
this.results.TabIndex = 2;
this.results.SelectedIndexChanged += new System.EventHandler(this.results_SelectedIndexChanged);
//
@ -89,13 +89,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.resultspanel.Controls.Add(this.results);
this.resultspanel.Location = new System.Drawing.Point(0, 170);
this.resultspanel.Name = "resultspanel";
this.resultspanel.Size = new System.Drawing.Size(383, 306);
this.resultspanel.Size = new System.Drawing.Size(383, 326);
this.resultspanel.TabIndex = 3;
//
// 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, 269);
this.fix3.Location = new System.Drawing.Point(256, 289);
this.fix3.Name = "fix3";
this.fix3.Size = new System.Drawing.Size(114, 26);
this.fix3.TabIndex = 7;
@ -107,7 +107,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, 269);
this.fix2.Location = new System.Drawing.Point(133, 289);
this.fix2.Name = "fix2";
this.fix2.Size = new System.Drawing.Size(114, 26);
this.fix2.TabIndex = 6;
@ -121,16 +121,16 @@ 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, 206);
this.resultinfo.Location = new System.Drawing.Point(12, 212);
this.resultinfo.Name = "resultinfo";
this.resultinfo.Size = new System.Drawing.Size(358, 57);
this.resultinfo.Size = new System.Drawing.Size(358, 74);
this.resultinfo.TabIndex = 5;
this.resultinfo.Text = "Select a result from the list to see more information.\r\n";
this.resultinfo.Text = "Select a result from the list to see more information.";
//
// 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, 269);
this.fix1.Location = new System.Drawing.Point(10, 289);
this.fix1.Name = "fix1";
this.fix1.Size = new System.Drawing.Size(114, 26);
this.fix1.TabIndex = 4;
@ -153,7 +153,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// ErrorCheckForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(380, 475);
this.ClientSize = new System.Drawing.Size(380, 493);
this.Controls.Add(this.resultspanel);
this.Controls.Add(this.buttoncheck);
this.Controls.Add(this.checks);