added stuff

This commit is contained in:
codeimp 2007-06-14 12:37:46 +00:00
parent f7e6133848
commit 84a3749f6e
16 changed files with 724 additions and 27 deletions

Binary file not shown.

BIN
Build/Interop.CodeSense.dll Normal file

Binary file not shown.

BIN
Build/SlimDX.dll Normal file

Binary file not shown.

BIN
Build/cmcs21.dll Normal file

Binary file not shown.

BIN
Build/cmcs21.ocx Normal file

Binary file not shown.

BIN
Resources/Icons/NewMap.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Resources/Icons/OpenMap.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Resources/Icons/SaveMap.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Resources/thingicon.cpt Normal file

Binary file not shown.

View file

@ -61,7 +61,9 @@
</Compile>
<Compile Include="Map\Linedef.cs" />
<Compile Include="Map\MapManager.cs" />
<Compile Include="Map\Sector.cs" />
<Compile Include="Map\Sidedef.cs" />
<Compile Include="Map\Thing.cs" />
<Compile Include="Map\Vertex.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
@ -70,6 +72,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="SlimDX, Version=1.0.2721.819, Culture=neutral, processorArchitecture=x86">
<Aliases>global</Aliases>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
@ -91,4 +96,30 @@
<ItemGroup>
<None Include="Resources\Splash2.png" />
</ItemGroup>
<ItemGroup>
<COMReference Include="AxCodeSense">
<Guid>{665BF2B8-F41F-4EF4-A8D0-303FBFFC475E}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="CodeSense">
<Guid>{665BF2B8-F41F-4EF4-A8D0-303FBFFC475E}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="stdole">
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
</Project>

View file

@ -15,6 +15,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
namespace CodeImp.DoomBuilder.Map
{
@ -26,6 +27,14 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Variables
// Map
private MapManager map;
// List items
private LinkedListNode<Linedef> mainlistitem;
private LinkedListNode<Linedef> startvertexlistitem;
private LinkedListNode<Linedef> endvertexlistitem;
// Vertices
private Vertex start;
private Vertex end;
@ -34,6 +43,11 @@ namespace CodeImp.DoomBuilder.Map
private Sidedef front;
private Sidedef back;
// Cache
private float lengthsq;
private float length;
//private float angle;
// Properties
private int flags;
private int action;
@ -47,7 +61,8 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
// Disposing
public Sidedef Front { get { return front; } }
public Sidedef Back { get { return back; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
@ -55,12 +70,21 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Constructor / Disposer
// Constructor
public Linedef(Vertex start, Vertex end)
public Linedef(MapManager map, LinkedListNode<Linedef> listitem, Vertex start, Vertex end)
{
// Initialize
this.map = map;
this.mainlistitem = listitem;
this.start = start;
this.end = end;
// Attach to vertices
startvertexlistitem = start.AttachLinedef(this);
endvertexlistitem = end.AttachLinedef(this);
// Calculate values
Recalculate();
// We have no destructor
GC.SuppressFinalize(this);
}
@ -71,29 +95,100 @@ namespace CodeImp.DoomBuilder.Map
// Not already disposed?
if(!isdisposed)
{
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Detach from vertices
start.Detach(this);
end.Detach(this);
start.DetachLinedef(startvertexlistitem);
end.DetachLinedef(endvertexlistitem);
// Dispose sidedefs
front.Dispose();
back.Dispose();
// Clean up
mainlistitem = null;
startvertexlistitem = null;
endvertexlistitem = null;
start = null;
end = null;
front = null;
back = null;
// Done
isdisposed = true;
map = null;
}
}
#endregion
#region ================== Methods
#region ================== Management
// This attaches a sidedef on the front
public void AttachFront(Sidedef s) { if(front == null) front = s; else throw new Exception("Linedef already has a front Sidedef."); }
// This attaches a sidedef on the back
public void AttachBack(Sidedef s) { if(back == null) back = s; else throw new Exception("Linedef already has a back Sidedef."); }
// This detaches a sidedef from the front
public void DetachSidedef(Sidedef s) { if(front == s) front = null; else if(back == s) back = null; else throw new Exception("Specified Sidedef is not attached to this Linedef."); }
// This recalculates cached values
public void Recalculate()
{
// Delta vector
Vector2D delta = end.Position - start.Position;
// Recalculate values
lengthsq = delta.GetLengthSq();
length = (float)Math.Sqrt(lengthsq);
//angle = delta.GetAngle();
}
#endregion
#region ================== Mathematics
// This returns the shortest distance from given coordinates to line
public float DistanceToSq(Vector2D p, bool bounded)
{
Vector2D v1 = start.Position;
Vector2D v2 = end.Position;
// Calculate intersection offset
float u = ((p.x - v1.x) * (v2.x - v1.x) + (p.y - v1.y) * (v2.y - v1.y)) / lengthsq;
// Limit intersection offset to the line
if(bounded) if(u < 0f) u = 0f; else if(u > 1f) u = 1f;
// Calculate intersection point
Vector2D i = v1 + u * (v2 - v1);
// Return distance between intersection and point
// which is the shortest distance to the line
float ldx = p.x - i.x;
float ldy = p.y - i.y;
return ldx * ldx + ldy * ldy;
}
// This returns the shortest distance from given coordinates to line
public float DistanceTo(Vector2D p, bool bounded)
{
return (float)Math.Sqrt(DistanceToSq(p, bounded));
}
// This tests on which side of the line the given coordinates are
// returns < 0 for front (right) side, > 0 for back (left) side and 0 if on the line
public float SideOfLine(Vector2D p)
{
Vector2D v1 = start.Position;
Vector2D v2 = end.Position;
// Calculate and return side information
return (p.y - v1.y) * (v2.x - v1.x) - (p.x - v1.x) * (v2.y - v1.y);
}
#endregion
}
}

View file

@ -15,6 +15,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
namespace CodeImp.DoomBuilder.Map
{
@ -26,6 +27,13 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Variables
// Map structures
private LinkedList<Vertex> vertices;
private LinkedList<Linedef> linedefs;
private LinkedList<Sidedef> sidedefs;
private LinkedList<Sector> sectors;
private LinkedList<Thing> things;
// Disposing
private bool isdisposed = false;
@ -33,17 +41,26 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
// Disposing
public ICollection<Vertex> Vertices { get { return vertices; } }
public ICollection<Linedef> Linedefs { get { return linedefs; } }
public ICollection<Sidedef> Sidedefs { get { return sidedefs; } }
public ICollection<Sector> Sectors { get { return sectors; } }
public ICollection<Thing> Things { get { return things; } }
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
// Constructor for new empty map
public MapManager()
{
// Initialize
vertices = new LinkedList<Vertex>();
linedefs = new LinkedList<Linedef>();
sidedefs = new LinkedList<Sidedef>();
sectors = new LinkedList<Sector>();
things = new LinkedList<Thing>();
// We have no destructor
GC.SuppressFinalize(this);
@ -52,11 +69,41 @@ namespace CodeImp.DoomBuilder.Map
// Diposer
public void Dispose()
{
ArrayList list;
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Dispose all things
list = new ArrayList(things);
foreach(Thing t in list) t.Dispose();
// Dispose all sectors
list = new ArrayList(sectors);
foreach(Sector s in list) s.Dispose();
// Dispose all sidedefs
list = new ArrayList(sidedefs);
foreach(Sidedef sd in list) sd.Dispose();
// Dispose all linedefs
list = new ArrayList(linedefs);
foreach(Linedef l in list) l.Dispose();
// Dispose all vertices
list = new ArrayList(vertices);
foreach(Vertex v in list) v.Dispose();
// Clean up
vertices = null;
linedefs = null;
sidedefs = null;
sectors = null;
things = null;
// Done
isdisposed = true;
}
@ -64,8 +111,170 @@ namespace CodeImp.DoomBuilder.Map
#endregion
#region ================== Methods
#region ================== Management
// This creates a new vertex
public Vertex CreateVertex(Vector2D pos)
{
LinkedListNode<Vertex> listitem;
Vertex v;
// Make a list item
listitem = new LinkedListNode<Vertex>(null);
// Make the vertex
v = new Vertex(this, listitem, pos);
listitem.Value = v;
// Add vertex to the list
vertices.AddLast(listitem);
// Return result
return v;
}
// This creates a new linedef
public Linedef CreateLinedef(Vertex start, Vertex end)
{
LinkedListNode<Linedef> listitem;
Linedef l;
// Make a list item
listitem = new LinkedListNode<Linedef>(null);
// Make the linedef
l = new Linedef(this, listitem, start, end);
listitem.Value = l;
// Add linedef to the list
linedefs.AddLast(listitem);
// Return result
return l;
}
// This creates a new sidedef
public Sidedef CreateSidedef(Linedef l, bool front, Sector s)
{
LinkedListNode<Sidedef> listitem;
Sidedef sd;
// Make a list item
listitem = new LinkedListNode<Sidedef>(null);
// Make the sidedef
sd = new Sidedef(this, listitem, l, front, s);
listitem.Value = sd;
// Add sidedef to the list
sidedefs.AddLast(listitem);
// Return result
return sd;
}
// This creates a new sector
public Sector CreateSector()
{
LinkedListNode<Sector> listitem;
Sector s;
// Make a list item
listitem = new LinkedListNode<Sector>(null);
// Make the sector
s = new Sector(this, listitem);
listitem.Value = s;
// Add sector to the list
sectors.AddLast(listitem);
// Return result
return s;
}
// This creates a new thing
public Thing CreateThing(int type, Vector2D pos)
{
LinkedListNode<Thing> listitem;
Thing t;
// Make a list item
listitem = new LinkedListNode<Thing>(null);
// Make the thing
t = new Thing(this, listitem, type, pos);
listitem.Value = t;
// Add thing to the list
things.AddLast(listitem);
// Return result
return t;
}
#endregion
#region ================== Static Tools
// This finds the line closest to the specified position
public static Linedef NearestLinedef(ICollection<Linedef> selection, Vector2D pos)
{
Linedef closest = null;
float distance = float.MaxValue;
float d;
// Go for all linedefs in selection
foreach(Linedef l in selection)
{
// Calculate distance and check if closer than previous find
d = l.DistanceToSq(pos, true);
if(d < distance)
{
// This one is closer
closest = l;
distance = d;
}
}
// Return result
return closest;
}
// This finds the vertex closest to the specified position
public static Vertex NearestVertex(ICollection<Vertex> selection, Vector2D pos)
{
Vertex closest = null;
float distance = float.MaxValue;
float d;
// Go for all vertices in selection
foreach(Vertex v in selection)
{
// Calculate distance and check if closer than previous find
d = v.DistanceToSq(pos);
if(d < distance)
{
// This one is closer
closest = v;
distance = d;
}
}
// Return result
return closest;
}
#endregion
#region ================== Tools
// This finds the line closest to the specified position
public Linedef NearestLinedef(Vector2D pos) { return MapManager.NearestLinedef(linedefs, pos); }
// This finds the vertex closest to the specified position
public Vertex NearestVertex(Vector2D pos) { return MapManager.NearestVertex(vertices, pos); }
#endregion
}
}

124
Source/Map/Sector.cs Normal file
View file

@ -0,0 +1,124 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace CodeImp.DoomBuilder.Map
{
internal class Sector : IDisposable
{
#region ================== Constants
#endregion
#region ================== Variables
// Map
private MapManager map;
// List items
private LinkedListNode<Sector> mainlistitem;
// Sidedefs
private LinkedList<Sidedef> sidedefs;
// Things
private LinkedList<Thing> things;
// Properties
private int floorheight;
private int ceilheight;
private string floortexname;
private string ceiltexname;
private int special;
private int tag;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
// Disposing
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public Sector(MapManager map, LinkedListNode<Sector> listitem)
{
// Initialize
this.map = map;
this.mainlistitem = listitem;
this.sidedefs = new LinkedList<Sidedef>();
this.things = new LinkedList<Thing>();
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Dispose the sidedefs that are attached to this sector
// because a sidedef cannot exist without reference to its sector.
foreach(Sidedef sd in sidedefs) sd.Dispose();
// Determine new sector references on things
foreach(Thing t in things) t.DetermineSector();
// Clean up
mainlistitem = null;
sidedefs = null;
things = null;
map = null;
}
}
#endregion
#region ================== Management
// This attaches a sidedef and returns the listitem
public LinkedListNode<Sidedef> AttachSidedef(Sidedef sd) { return sidedefs.AddLast(sd); }
// This detaches a sidedef
public void DetachSidedef(LinkedListNode<Sidedef> l)
{
// Not disposing?
if(!isdisposed)
{
// Remove sidedef
sidedefs.Remove(l);
// No more sidedefs left?
if(sidedefs.Count == 0)
{
// This sector is now useless, dispose it
this.Dispose();
}
}
}
// This attaches a thing and returns the listitem
public LinkedListNode<Thing> AttachThing(Thing t) { return things.AddLast(t); }
// This detaches a thing
public void DetachThing(LinkedListNode<Thing> l) { if(!isdisposed) things.Remove(l); }
#endregion
}
}

View file

@ -14,6 +14,26 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Variables
// Map
private MapManager map;
// List items
private LinkedListNode<Sidedef> mainlistitem;
private LinkedListNode<Sidedef> sectorlistitem;
// Owner
private Linedef linedef;
// Sector
private Sector sector;
// Properties
private int offsetx;
private int offsety;
private string texnamehigh;
private string texnamemid;
private string texnamelow;
// Disposing
private bool isdisposed = false;
@ -21,7 +41,8 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
// Disposing
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; } }
#endregion
@ -29,9 +50,19 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Constructor / Disposer
// Constructor
public Sidedef()
public Sidedef(MapManager map, LinkedListNode<Sidedef> listitem, Linedef l, bool front, Sector s)
{
// Initialize
this.map = map;
this.mainlistitem = listitem;
this.linedef = l;
this.sector = s;
// Attach to the linedef
if(front) l.AttachFront(this); else l.AttachBack(this);
// Attach to sector
sectorlistitem = s.AttachSidedef(this);
// We have no destructor
GC.SuppressFinalize(this);
@ -43,10 +74,24 @@ namespace CodeImp.DoomBuilder.Map
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Done
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Detach from linedef
linedef.DetachSidedef(this);
// Detach from sector
sector.DetachSidedef(sectorlistitem);
// Clean up
mainlistitem = null;
sectorlistitem = null;
linedef = null;
map = null;
sector = null;
}
}

139
Source/Map/Thing.cs Normal file
View file

@ -0,0 +1,139 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
namespace CodeImp.DoomBuilder.Map
{
internal class Thing : IDisposable
{
#region ================== Constants
#endregion
#region ================== Variables
// Map
private MapManager map;
// Sector
private Sector sector = null;
// List items
private LinkedListNode<Thing> mainlistitem;
private LinkedListNode<Thing> sectorlistitem;
// Properties
private int type;
private Vector2D pos;
private float angle;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
// Disposing
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public Thing(MapManager map, LinkedListNode<Thing> listitem, int type, Vector2D pos)
{
// Initialize
this.map = map;
this.mainlistitem = listitem;
this.type = type;
this.pos = pos;
// Determine current sector
DetermineSector();
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Remove from sector
if(sector != null) sector.DetachThing(sectorlistitem);
// Clean up
mainlistitem = null;
sectorlistitem = null;
map = null;
sector = null;
}
}
#endregion
#region ================== Management
// This determines which sector the thing is in and links it
public void DetermineSector()
{
Sector newsector = null;
Vertex nv;
Linedef nl;
// Find the nearest vertex on the map
nv = map.NearestVertex(pos);
if(nv != null)
{
// Find the nearest linedef on the vertex
nl = nv.NearestLinedef(pos);
if(nl != null)
{
// Check what side of line we are at
if(nl.SideOfLine(pos) < 0f)
{
// Front side
if(nl.Front != null) newsector = nl.Front.Sector;
}
else
{
// Back side
if(nl.Back != null) newsector = nl.Back.Sector;
}
}
}
// Currently attached to a sector and sector changes?
if((sector != null) && (newsector != sector))
{
// Remove from current sector
sector.DetachThing(sectorlistitem);
sectorlistitem = null;
sector = null;
}
// Attach to new sector?
if((newsector != null) && (newsector != sector))
{
// Attach to new sector
sector = newsector;
sectorlistitem = sector.AttachThing(this);
}
}
#endregion
}
}

View file

@ -27,11 +27,17 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Variables
// Map
private MapManager map;
// List items
private LinkedListNode<Vertex> mainlistitem;
// Position
private Vector2D pos;
// References
private List<Linedef> linedefs;
private LinkedList<Linedef> linedefs;
// Disposing
private bool isdisposed = false;
@ -40,7 +46,7 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Properties
public List<Linedef> Linedefs { get { return linedefs; } }
public ICollection<Linedef> Linedefs { get { return linedefs; } }
public Vector2D Position { get { return pos; } }
public bool IsDisposed { get { return isdisposed; } }
@ -49,9 +55,12 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Constructor / Disposer
// Constructor
public Vertex(Vector2D pos)
public Vertex(MapManager map, LinkedListNode<Vertex> listitem, Vector2D pos)
{
// Initialize
this.map = map;
this.linedefs = new LinkedList<Linedef>();
this.mainlistitem = listitem;
this.pos = pos;
// We have no destructor
@ -64,27 +73,47 @@ namespace CodeImp.DoomBuilder.Map
// Not already disposed?
if(!isdisposed)
{
// Already set isdisposed so that changes can be prohibited
isdisposed = true;
// Remove from main list
mainlistitem.List.Remove(mainlistitem);
// Dispose the lines that are attached to this vertex
// because a linedef cannot exist without 2 vertices.
foreach(Linedef l in linedefs) l.Dispose();
// Clean up
linedefs = null;
// Done
isdisposed = true;
mainlistitem = null;
map = null;
}
}
#endregion
#region ================== Methods
#region ================== Management
// This attaches a linedef
public void Attach(Linedef l) { linedefs.Add(l); }
// This attaches a linedef and returns the listitem
public LinkedListNode<Linedef> AttachLinedef(Linedef l) { return linedefs.AddLast(l); }
// This detaches a linedef
public void Detach(Linedef l) { linedefs.Remove(l); }
public void DetachLinedef(LinkedListNode<Linedef> l)
{
// Not disposing?
if(!isdisposed)
{
// Remove linedef
linedefs.Remove(l);
// No more linedefs left?
if(linedefs.Count == 0)
{
// This vertex is now useless, dispose it
this.Dispose();
}
}
}
// This rounds the coordinates to integrals
public void Round()
@ -95,5 +124,30 @@ namespace CodeImp.DoomBuilder.Map
}
#endregion
#region ================== Mathematics
// This returns the distance from given coordinates
public float DistanceToSq(Vector2D p)
{
Vector2D delta = p - pos;
return delta.GetLengthSq();
}
// This returns the distance from given coordinates
public float DistanceTo(Vector2D p)
{
Vector2D delta = p - pos;
return delta.GetLength();
}
#endregion
#region ================== Tools
// This finds the line closest to the specified position
public Linedef NearestLinedef(Vector2D pos) { return MapManager.NearestLinedef(linedefs, pos); }
#endregion
}
}