Map Analysis mode can now check the map for unconnected vertices.

This commit is contained in:
MaxED 2013-05-30 15:50:46 +00:00
parent e5dd1fa9c5
commit c67331eaf6
3 changed files with 88 additions and 0 deletions

View file

@ -233,10 +233,12 @@
<Compile Include="ClassicModes\FloorAlignMode.cs" />
<Compile Include="ClassicModes\SnapVerticesMode.cs" />
<Compile Include="ErrorChecks\CheckMissingTextures.cs" />
<Compile Include="ErrorChecks\CheckStrayVertices.cs" />
<Compile Include="ErrorChecks\CheckUnknownFlats.cs" />
<Compile Include="ErrorChecks\CheckUnknownTextures.cs" />
<Compile Include="ErrorChecks\CheckUnknownThings.cs" />
<Compile Include="ErrorChecks\ResultNoErrors.cs" />
<Compile Include="ErrorChecks\ResultStrayVertex.cs" />
<Compile Include="ErrorChecks\ResultStuckThingInThing.cs" />
<Compile Include="ErrorChecks\ResultTextureMissing.cs" />
<Compile Include="ErrorChecks\ResultUnknownFlat.cs" />

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeImp.DoomBuilder.Map;
using System.Threading;
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
{
[ErrorChecker("Check unconnected vertices", true, 50)]
public class CheckStrayVertices : ErrorChecker
{
private int PROGRESS_STEP = 1000;
// Constructor
public CheckStrayVertices() {
// Total progress is done when all vertices are checked
SetTotalProgress(General.Map.Map.Vertices.Count / PROGRESS_STEP);
}
// This runs the check
public override void Run() {
int progress = 0;
int stepprogress = 0;
// Go for all things
foreach(Vertex v in General.Map.Map.Vertices) {
if(v.Linedefs == null || v.Linedefs.Count == 0)
SubmitResult(new ResultStrayVertex(v));
// Handle thread interruption
try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; }
// We are making progress!
if((++progress / PROGRESS_STEP) > stepprogress) {
stepprogress = (progress / PROGRESS_STEP);
AddProgress(1);
}
}
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using System.Drawing;
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
{
public class ResultStrayVertex : ErrorResult
{
public override int Buttons { get { return 1; } }
public override string Button1Text { get { return "Delete Vertex"; } }
private Vertex vertex;
// Constructor
public ResultStrayVertex(Vertex v) {
// Initialize
this.vertex = v;
this.viewobjects.Add(v);
this.description = "This vertex is not connected to any linedef.";
}
// This must return the string that is displayed in the listbox
public override string ToString() {
return "Vertex " + vertex.Index + " at " + vertex.Position.x + ", " + vertex.Position.y + " is not connected to any linedef.";
}
// Rendering
public override void RenderOverlaySelection(IRenderer2D renderer) {
renderer.RenderRectangleFilled(new RectangleF(vertex.Position.x - 3, vertex.Position.y - 3, 6f, 6f), General.Colors.Selection, true);
}
// This removes the vertex
public override bool Button1Click() {
General.Map.UndoRedo.CreateUndo("Delete vertex");
vertex.Dispose();
General.Map.IsChanged = true;
General.Map.ThingsFilter.Update();
return true;
}
}
}