diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 004912fe..14b763eb 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -60,7 +60,7 @@ MainForm.cs - + diff --git a/Source/Map/Linedef.cs b/Source/Map/Linedef.cs index 41eaa93f..6e1e0813 100644 --- a/Source/Map/Linedef.cs +++ b/Source/Map/Linedef.cs @@ -28,7 +28,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Variables // Map - private MapManager map; + private MapSet map; // List items private LinkedListNode mainlistitem; @@ -61,6 +61,8 @@ namespace CodeImp.DoomBuilder.Map #region ================== Properties + public Vertex Start { get { return start; } } + public Vertex End { get { return end; } } public Sidedef Front { get { return front; } } public Sidedef Back { get { return back; } } public bool IsDisposed { get { return isdisposed; } } @@ -70,7 +72,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor - public Linedef(MapManager map, LinkedListNode listitem, Vertex start, Vertex end) + public Linedef(MapSet map, LinkedListNode listitem, Vertex start, Vertex end) { // Initialize this.map = map; @@ -145,6 +147,16 @@ namespace CodeImp.DoomBuilder.Map length = (float)Math.Sqrt(lengthsq); //angle = delta.GetAngle(); } + + // This copies all properties to another line + public void CopyPropertiesTo(Linedef l) + { + // Copy properties + l.action = action; + l.args = (byte[])args.Clone(); + l.flags = flags; + l.tag = tag; + } #endregion diff --git a/Source/Map/MapManager.cs b/Source/Map/MapSet.cs similarity index 73% rename from Source/Map/MapManager.cs rename to Source/Map/MapSet.cs index 8818b3bf..0d53e652 100644 --- a/Source/Map/MapManager.cs +++ b/Source/Map/MapSet.cs @@ -19,7 +19,7 @@ using CodeImp.DoomBuilder.Geometry; namespace CodeImp.DoomBuilder.Map { - internal class MapManager : IDisposable + internal class MapSet : IDisposable { #region ================== Constants @@ -53,7 +53,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor for new empty map - public MapManager() + public MapSet() { // Initialize vertices = new LinkedList(); @@ -113,6 +113,73 @@ namespace CodeImp.DoomBuilder.Map #region ================== Management + // This makes a deep copy and returns a new MapSet + public MapSet Clone() + { + Dictionary vertexlink = new Dictionary(vertices.Count); + Dictionary linedeflink = new Dictionary(linedefs.Count); + Dictionary sectorlink = new Dictionary(sectors.Count); + + // Create the map set + MapSet newset = new MapSet(); + + // Go for all vertices + foreach(Vertex v in vertices) + { + // Make new vertex + Vertex nv = newset.CreateVertex(v.Position); + vertexlink.Add(v, nv); + } + + // 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); + + // Copy properties + l.CopyPropertiesTo(nl); + + // Recalculate + l.Recalculate(); + } + + // Go for all sectors + foreach(Sector s in sectors) + { + // Make new sector + Sector ns = newset.CreateSector(); + sectorlink.Add(s, ns); + + // Copy properties + s.CopyPropertiesTo(ns); + } + + // Go for all sidedefs + foreach(Sidedef d in sidedefs) + { + // Make new sidedef + Sidedef nd = newset.CreateSidedef(linedeflink[d.Line], d.IsFront, sectorlink[d.Sector]); + + // Copy properties + d.CopyPropertiesTo(nd); + } + + // Go for all things + foreach(Thing t in things) + { + // Make new thing + Thing nt = newset.CreateThing(t.Type, t.Position); + + // Copy properties + t.CopyPropertiesTo(nt); + } + + // Return the new set + return newset; + } + // This creates a new vertex public Vertex CreateVertex(Vector2D pos) { @@ -270,11 +337,11 @@ namespace CodeImp.DoomBuilder.Map #region ================== Tools // This finds the line closest to the specified position - public Linedef NearestLinedef(Vector2D pos) { return MapManager.NearestLinedef(linedefs, pos); } + public Linedef NearestLinedef(Vector2D pos) { return MapSet.NearestLinedef(linedefs, pos); } // This finds the vertex closest to the specified position - public Vertex NearestVertex(Vector2D pos) { return MapManager.NearestVertex(vertices, pos); } - + public Vertex NearestVertex(Vector2D pos) { return MapSet.NearestVertex(vertices, pos); } + #endregion } } diff --git a/Source/Map/Sector.cs b/Source/Map/Sector.cs index dc42a45b..b0334cb9 100644 --- a/Source/Map/Sector.cs +++ b/Source/Map/Sector.cs @@ -15,7 +15,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Variables // Map - private MapManager map; + private MapSet map; // List items private LinkedListNode mainlistitem; @@ -49,7 +49,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor - public Sector(MapManager map, LinkedListNode listitem) + public Sector(MapSet map, LinkedListNode listitem) { // Initialize this.map = map; @@ -119,6 +119,18 @@ namespace CodeImp.DoomBuilder.Map // This detaches a thing public void DetachThing(LinkedListNode l) { if(!isdisposed) things.Remove(l); } + // This copies all properties to another sector + public void CopyPropertiesTo(Sector s) + { + // Copy properties + s.ceilheight = ceilheight; + s.ceiltexname = ceiltexname; + s.floorheight = floorheight; + s.floortexname = floortexname; + s.special = special; + s.tag = tag; + } + #endregion } } diff --git a/Source/Map/Sidedef.cs b/Source/Map/Sidedef.cs index f1fc6d89..e08b7591 100644 --- a/Source/Map/Sidedef.cs +++ b/Source/Map/Sidedef.cs @@ -15,7 +15,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Variables // Map - private MapManager map; + private MapSet map; // List items private LinkedListNode mainlistitem; @@ -41,6 +41,8 @@ namespace CodeImp.DoomBuilder.Map #region ================== Properties + public bool IsFront { get { return (this == linedef.Front); } } + public Linedef Line { get { return linedef; } } public Sidedef Other { get { if(this == linedef.Front) return linedef.Back; else return linedef.Front; } } public Sector Sector { get { return sector; } } public bool IsDisposed { get { return isdisposed; } } @@ -50,7 +52,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor - public Sidedef(MapManager map, LinkedListNode listitem, Linedef l, bool front, Sector s) + public Sidedef(MapSet map, LinkedListNode listitem, Linedef l, bool front, Sector s) { // Initialize this.map = map; @@ -97,8 +99,19 @@ namespace CodeImp.DoomBuilder.Map #endregion - #region ================== Methods + #region ================== Management + // This copies all properties to another sidedef + public void CopyPropertiesTo(Sidedef s) + { + // Copy properties + s.offsetx = offsetx; + s.offsety = offsety; + s.texnamehigh = texnamehigh; + s.texnamelow = texnamelow; + s.texnamemid = texnamemid; + } + #endregion } } diff --git a/Source/Map/Thing.cs b/Source/Map/Thing.cs index dda67e33..5ffcd428 100644 --- a/Source/Map/Thing.cs +++ b/Source/Map/Thing.cs @@ -16,7 +16,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Variables // Map - private MapManager map; + private MapSet map; // Sector private Sector sector = null; @@ -37,7 +37,8 @@ namespace CodeImp.DoomBuilder.Map #region ================== Properties - // Disposing + public int Type { get { return type; } } + public Vector2D Position { get { return pos; } } public bool IsDisposed { get { return isdisposed; } } #endregion @@ -45,7 +46,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor - public Thing(MapManager map, LinkedListNode listitem, int type, Vector2D pos) + public Thing(MapSet map, LinkedListNode listitem, int type, Vector2D pos) { // Initialize this.map = map; @@ -134,6 +135,14 @@ namespace CodeImp.DoomBuilder.Map } } + // This copies all properties to another thing + public void CopyPropertiesTo(Thing t) + { + // Copy properties + t.type = type; + t.angle = angle; + } + #endregion } } diff --git a/Source/Map/Vertex.cs b/Source/Map/Vertex.cs index 3d847b39..b857c310 100644 --- a/Source/Map/Vertex.cs +++ b/Source/Map/Vertex.cs @@ -28,7 +28,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Variables // Map - private MapManager map; + private MapSet map; // List items private LinkedListNode mainlistitem; @@ -55,7 +55,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Constructor / Disposer // Constructor - public Vertex(MapManager map, LinkedListNode listitem, Vector2D pos) + public Vertex(MapSet map, LinkedListNode listitem, Vector2D pos) { // Initialize this.map = map; @@ -146,7 +146,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Tools // This finds the line closest to the specified position - public Linedef NearestLinedef(Vector2D pos) { return MapManager.NearestLinedef(linedefs, pos); } + public Linedef NearestLinedef(Vector2D pos) { return MapSet.NearestLinedef(linedefs, pos); } #endregion }