- Added check for unused sectors and automatic removal when opening a map

This commit is contained in:
codeimp 2009-05-17 14:37:34 +00:00
parent 622ff71056
commit 79116a2a42
2 changed files with 32 additions and 0 deletions

View file

@ -361,6 +361,9 @@ namespace CodeImp.DoomBuilder
maplocation = new DataLocation(DataLocation.RESOURCE_WAD, filepathname, options.StrictPatches, false);
data.Load(configinfo.Resources, options.Resources, maplocation);
// Remove unused sectors
map.RemoveUnusedSectors(true);
// Update structures
options.ApplyGridSettings();
map.UpdateConfiguration();

View file

@ -1885,6 +1885,35 @@ namespace CodeImp.DoomBuilder.Map
return count;
}
// This removes unused sectors and returns the number of removed sectors
public int RemoveUnusedSectors(bool reportwarnings)
{
int count = 0;
LinkedListNode<Sector> n = sectors.First;
// Go for all sectors
int index = 0;
while(n != null)
{
LinkedListNode<Sector> nn = n.Next;
// Remove when unused
if(n.Value.Sidedefs.Count == 0)
{
if(reportwarnings)
General.ErrorLogger.Add(ErrorType.Warning, "Sector " + index + " was unused and has been removed.");
n.Value.Dispose();
count++;
}
index++;
n = nn;
}
return count;
}
// This joins overlapping lines together
// Returns the number of joins made