mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 04:40:55 +00:00
smarter MapSet cloning
This commit is contained in:
parent
0b333dba8f
commit
ed55f4529b
4 changed files with 25 additions and 14 deletions
|
@ -73,6 +73,9 @@ namespace CodeImp.DoomBuilder.Map
|
|||
|
||||
// Selections
|
||||
private int selected;
|
||||
|
||||
// Cloning
|
||||
private Linedef clone;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
@ -96,6 +99,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
public float LengthInv { get { return lengthinv; } }
|
||||
public float Angle { get { return angle; } }
|
||||
public int AngleDeg { get { return (int)(angle * Angle2D.PIDEG); } }
|
||||
public Linedef Clone { get { return clone; } set { clone = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -124,31 +124,25 @@ namespace CodeImp.DoomBuilder.Map
|
|||
// This makes a deep copy and returns a new MapSet
|
||||
public MapSet Clone()
|
||||
{
|
||||
Dictionary<Vertex, Vertex> vertexlink = new Dictionary<Vertex,Vertex>(vertices.Count);
|
||||
Dictionary<Linedef, Linedef> linedeflink = new Dictionary<Linedef, Linedef>(linedefs.Count);
|
||||
Dictionary<Sector, Sector> sectorlink = new Dictionary<Sector, Sector>(sectors.Count);
|
||||
|
||||
// TODO: Try making this faster by giving each element that
|
||||
// requires a lookup (vertex/linedef/sector) a reference to
|
||||
// its clone and remove those references after cloning.
|
||||
|
||||
// Create the map set
|
||||
MapSet newset = new MapSet();
|
||||
|
||||
// TODO: Clone sectors first, then the linedefs and in the same loop
|
||||
// the sidedefs so that the linedefs do not need a clone reference
|
||||
|
||||
// Go for all vertices
|
||||
foreach(Vertex v in vertices)
|
||||
{
|
||||
// Make new vertex
|
||||
Vertex nv = newset.CreateVertex(v.X, v.Y);
|
||||
vertexlink.Add(v, nv);
|
||||
v.Clone = newset.CreateVertex(v.X, v.Y);
|
||||
}
|
||||
|
||||
// Go for all linedefs
|
||||
foreach(Linedef l in linedefs)
|
||||
{
|
||||
// Make new linedef
|
||||
Linedef nl = newset.CreateLinedef(vertexlink[l.Start], vertexlink[l.End]);
|
||||
linedeflink.Add(l, nl);
|
||||
Linedef nl = newset.CreateLinedef(l.Start.Clone, l.End.Clone);
|
||||
l.Clone = nl;
|
||||
|
||||
// Copy properties
|
||||
l.CopyPropertiesTo(nl);
|
||||
|
@ -162,7 +156,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
{
|
||||
// Make new sector
|
||||
Sector ns = newset.CreateSector();
|
||||
sectorlink.Add(s, ns);
|
||||
s.Clone = ns;
|
||||
|
||||
// Copy properties
|
||||
s.CopyPropertiesTo(ns);
|
||||
|
@ -172,7 +166,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
foreach(Sidedef d in sidedefs)
|
||||
{
|
||||
// Make new sidedef
|
||||
Sidedef nd = newset.CreateSidedef(linedeflink[d.Line], d.IsFront, sectorlink[d.Sector]);
|
||||
Sidedef nd = newset.CreateSidedef(d.Line.Clone, d.IsFront, d.Sector.Clone);
|
||||
|
||||
// Copy properties
|
||||
d.CopyPropertiesTo(nd);
|
||||
|
@ -188,6 +182,11 @@ namespace CodeImp.DoomBuilder.Map
|
|||
t.CopyPropertiesTo(nt);
|
||||
}
|
||||
|
||||
// Remove clone references
|
||||
foreach(Vertex v in vertices) v.Clone = null;
|
||||
foreach(Linedef l in linedefs) l.Clone = null;
|
||||
foreach(Sector s in sectors) s.Clone = null;
|
||||
|
||||
// Return the new set
|
||||
return newset;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,9 @@ namespace CodeImp.DoomBuilder.Map
|
|||
// Selections
|
||||
private int selected;
|
||||
|
||||
// Cloning
|
||||
private Sector clone;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
|
@ -82,6 +85,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
public int Tag { get { return tag; } }
|
||||
public int Brightness { get { return brightness; } }
|
||||
public int Selected { get { return selected; } set { selected = value; } }
|
||||
public Sector Clone { get { return clone; } set { clone = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -57,6 +57,9 @@ namespace CodeImp.DoomBuilder.Map
|
|||
// Selections
|
||||
private int selected;
|
||||
|
||||
// Cloning
|
||||
private Vertex clone;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
|
@ -71,6 +74,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
public int Y { get { return y; } }
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
public int Selected { get { return selected; } set { selected = value; } }
|
||||
public Vertex Clone { get { return clone; } set { clone = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Reference in a new issue