Replace most big foreach loops by for loops in MapSet

This commit is contained in:
spherallic 2023-04-25 16:09:29 +02:00
parent e3752e8601
commit b54d7a48cc

View file

@ -2199,10 +2199,12 @@ namespace CodeImp.DoomBuilder.Map
List<LinedefSide> edges = new List<LinedefSide>();
if(existing_only)
{
foreach(Linedef l in lines)
int lineCount = lines.Count;
for (int i = 0; i < lineCount; i++)
{
Linedef l = lines[i];
// Add only existing sides as edges (or front side if line has none)
if(l.Front != null || l.Back == null)
if (l.Front != null || l.Back == null)
edges.Add(new LinedefSide(l, true));
if(l.Back != null)
edges.Add(new LinedefSide(l, false));
@ -2210,8 +2212,10 @@ namespace CodeImp.DoomBuilder.Map
}
else
{
foreach(Linedef l in lines)
int lineCount = lines.Count;
for (int i = 0; i < lineCount; i++)
{
Linedef l = lines[i];
// Add front side
edges.Add(new LinedefSide(l, true));
@ -2222,9 +2226,11 @@ namespace CodeImp.DoomBuilder.Map
}
HashSet<Sidedef> sides_correct = new HashSet<Sidedef>();
foreach(LinedefSide ls in edges)
int edgeCount = edges.Count;
for (int i = 0; i < edgeCount; i++)
{
if(ls.Front && ls.Line.Front != null)
LinedefSide ls = edges[i];
if (ls.Front && ls.Line.Front != null)
sides_correct.Add(ls.Line.Front);
else if(!ls.Front && ls.Line.Back != null)
sides_correct.Add(ls.Line.Back);
@ -2242,11 +2248,12 @@ namespace CodeImp.DoomBuilder.Map
SectorBuilder builder = new SectorBuilder();
List<Sector> sectors_reused = new List<Sector>();
foreach(LinedefSide ls in edges)
for (int i = 0; i < edgeCount; i++)
{
LinedefSide ls = edges[i];
// Skip if edge is ignored
//DebugConsole.WriteLine((ls.Ignore ? "Ignoring line " : "Processing line ") + ls.Line.Index);
if(ls.Ignore) continue;
if (ls.Ignore) continue;
// Run sector builder on current edge
if(!builder.TraceSector(ls.Line, ls.Front)) continue; // Don't create sector if trace failed
@ -2264,9 +2271,10 @@ namespace CodeImp.DoomBuilder.Map
if(side_exists && sectorsides.Contains(edge.Front ? edge.Line.Front : edge.Line.Back))
has_dragged_sides = true; //mxd
foreach(LinedefSide ls2 in edges)
for (int k = 0; k < edgeCount; k++)
{
if(ls2.Line == edge.Line)
LinedefSide ls2 = edges[k];
if (ls2.Line == edge.Line)
{
line_is_ours = true;
if(ls2.Front == edge.Front)
@ -2332,9 +2340,10 @@ namespace CodeImp.DoomBuilder.Map
}
// Remove any sides that weren't part of a sector
foreach(LinedefSide ls in edges)
for (int i = 0; i < edgeCount; i++)
{
if(ls.Ignore || ls.Line == null) continue;
LinedefSide ls = edges[i];
if (ls.Ignore || ls.Line == null) continue;
if(ls.Front)
{