sorting error checkers with highest cost first (estimated CPU usage)

This commit is contained in:
codeimp 2008-10-24 07:39:29 +00:00
parent 46434b8b7c
commit d7a843938a
4 changed files with 21 additions and 4 deletions

View file

@ -39,7 +39,7 @@ using System.Threading;
namespace CodeImp.DoomBuilder.BuilderModes
{
[ErrorChecker("Check for stucked things", true)]
[ErrorChecker("Check for stucked things", true, 1000)]
public class CheckStuckedThings : ErrorChecker
{
#region ================== Constants
@ -78,7 +78,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
float blockingsize = t.Size - ALLOWED_STUCK_DISTANCE;
Vector2D lt = new Vector2D(t.Position.x - blockingsize, t.Position.y - blockingsize);
Vector2D rb = new Vector2D(t.Position.x + blockingsize, t.Position.y + blockingsize);
// Go for all the lines to see if this thing is stucked
foreach(Linedef l in General.Map.Map.Linedefs)
{

View file

@ -38,12 +38,13 @@ using CodeImp.DoomBuilder.Config;
namespace CodeImp.DoomBuilder.BuilderModes
{
public class ErrorChecker
public class ErrorChecker : IComparable<ErrorChecker>
{
#region ================== Variables
private int lastprogress;
private int totalprogress = -1;
protected ErrorCheckerAttribute attribs;
#endregion
@ -59,6 +60,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Override this to determine and set the total progress
public ErrorChecker()
{
// Initialize
object[] attrs = this.GetType().GetCustomAttributes(typeof(ErrorCheckerAttribute), true);
attribs = (ErrorCheckerAttribute)attrs[0];
}
#endregion
@ -96,6 +100,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
this.totalprogress = totalprogress;
}
// This is for sorting by cost
public int CompareTo(ErrorChecker other)
{
return (other.attribs.Cost - this.attribs.Cost);
}
#endregion
}
}

View file

@ -45,6 +45,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
private string displayname;
private bool defaultchecked;
private int cost;
#endregion
@ -52,17 +53,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
public string DisplayName { get { return displayname; } set { displayname = value; } }
public bool DefaultChecked { get { return defaultchecked; } set { defaultchecked = value; } }
public int Cost { get { return cost; } set { cost = value; } }
#endregion
#region ================== Constructor / Destructor
// Constructor
public ErrorCheckerAttribute(string displayname, bool defaultchecked)
public ErrorCheckerAttribute(string displayname, bool defaultchecked, int cost)
{
// Initialize
this.displayname = displayname;
this.defaultchecked = defaultchecked;
this.cost = cost;
}
#endregion

View file

@ -275,6 +275,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
// Sort the checkers with highest cost first
// See CompareTo method in ErrorChecker for sorting comparison
checkers.Sort();
// Setup
SetProgressMaximum(totalprogress);