2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Map
|
|
|
|
{
|
|
|
|
public sealed class Vertex : SelectableElement
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
public const int BUFFERVERTICES = 1;
|
|
|
|
public const int RENDERPRIMITIVES = 1;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Map
|
|
|
|
private MapSet map;
|
|
|
|
|
|
|
|
// List items
|
|
|
|
private LinkedListNode<Vertex> selecteditem;
|
|
|
|
|
|
|
|
// Position
|
|
|
|
private Vector2D pos;
|
|
|
|
|
2013-07-08 13:13:28 +00:00
|
|
|
//mxd. Height
|
|
|
|
private float zfloor;
|
|
|
|
private float zceiling;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// References
|
|
|
|
private LinkedList<Linedef> linedefs;
|
|
|
|
|
|
|
|
// Cloning
|
|
|
|
private Vertex clone;
|
|
|
|
private int serializedindex;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public MapSet Map { get { return map; } }
|
|
|
|
public ICollection<Linedef> Linedefs { get { return linedefs; } }
|
|
|
|
public Vector2D Position { get { return pos; } }
|
|
|
|
internal Vertex Clone { get { return clone; } set { clone = value; } }
|
|
|
|
internal int SerializedIndex { get { return serializedindex; } set { serializedindex = value; } }
|
2013-07-08 13:13:28 +00:00
|
|
|
public float ZCeiling { //mxd
|
|
|
|
get { return zceiling; }
|
|
|
|
set {
|
2014-12-03 23:15:26 +00:00
|
|
|
if(zceiling != value)
|
|
|
|
{
|
2013-07-08 13:13:28 +00:00
|
|
|
BeforeFieldsChange();
|
|
|
|
zceiling = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public float ZFloor { //mxd
|
|
|
|
get { return zfloor; }
|
|
|
|
set {
|
2014-12-03 23:15:26 +00:00
|
|
|
if(zfloor != value)
|
|
|
|
{
|
2013-07-08 13:13:28 +00:00
|
|
|
BeforeFieldsChange();
|
|
|
|
zfloor = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2009-06-05 19:03:56 +00:00
|
|
|
internal Vertex(MapSet map, int listindex, Vector2D pos)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
Removed "Paste Properties Options" action.
Added "Paste Properties Special" actions in "Classic" and "Visual" categories. They work the same way as "Paste Special" action.
Added: "Copy Properties", "Paste Properties" and "Paste Properties Special" options are now shown in the Edit menu if current classic mode supports them.
Changed, Paste Properties Special window: only options relevant to current map format are now displayed.
Changed, Paste Properties Special window, UDMF: all UI-managed options are now available.
Fixed: MAPINFO parser was unable to process "include" directives.
Fixed, General interface: selection info was reset to "Nothing selected" after few seconds regardless of current selection.
Fixed, Visual mode: thing bounding boxes were not updated when changing things positions using Randomize mode.
Fixed, Visual mode: event lines were displayed at incorrect height when entering Visual mode for the first time.
Fixed, Texture Browser window: when MixTexturesFlats Game Configuration option is disabled, textures/flats are no longer shown in the Used group when flats/textures with the same names are used in the map.
Fixed(?): probably fixed an exception some users reported when trying to initialize a Classic mode after switching from Visual mode with "Sync cameras" option enabled.
Changed, Game configurations, Thing Categories: a block must have at least one thing category property to be recognized as a thing category.
Changed, Visplane Explorer: the plugin now outputs more info when it fails to initialize vpo.dll.
Cosmetic, Thing Edit window, Doom/Hexen map format: adjusted UI layout so thing flags control no longer displays scrollbars in Hexen map format.
Internal: merged methods from UDMFTools into UniFields, removed UDMFTools.
Updated Inno Setup script (added VC++ 2008 SP1 distributive).
Updated ZDoom_DECORATE.cfg (A_CheckBlock).
Updated documentation (added "System Requirements" page).
2015-10-09 12:38:12 +00:00
|
|
|
this.elementtype = MapElementType.VERTEX; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
this.map = map;
|
|
|
|
this.linedefs = new LinkedList<Linedef>();
|
2009-06-05 19:03:56 +00:00
|
|
|
this.listindex = listindex;
|
2009-04-19 18:07:22 +00:00
|
|
|
this.pos = pos;
|
2013-07-08 13:13:28 +00:00
|
|
|
this.zceiling = float.NaN; //mxd
|
|
|
|
this.zfloor = float.NaN; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2009-06-11 21:21:20 +00:00
|
|
|
if(map == General.Map.Map)
|
|
|
|
General.Map.UndoRedo.RecAddVertex(this);
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Already set isdisposed so that changes can be prohibited
|
|
|
|
isdisposed = true;
|
2009-06-11 21:21:20 +00:00
|
|
|
|
2009-06-07 10:26:06 +00:00
|
|
|
if(map.AutoRemove)
|
|
|
|
{
|
|
|
|
// Dispose the lines that are attached to this vertex
|
|
|
|
// because a linedef cannot exist without 2 vertices.
|
|
|
|
foreach(Linedef ld in linedefs) ld.Dispose();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Detach from linedefs
|
2009-06-11 21:21:20 +00:00
|
|
|
foreach(Linedef ld in linedefs) ld.DetachVertexP(this);
|
2009-06-07 10:26:06 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2009-06-19 07:59:38 +00:00
|
|
|
if(map == General.Map.Map)
|
|
|
|
General.Map.UndoRedo.RecRemVertex(this);
|
|
|
|
|
|
|
|
// Remove from main list
|
|
|
|
map.RemoveVertex(listindex);
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Clean up
|
|
|
|
linedefs = null;
|
|
|
|
map = null;
|
|
|
|
|
2015-09-16 20:22:20 +00:00
|
|
|
//mxd. Restore isdisposed so base classes can do their disposal job
|
|
|
|
isdisposed = false;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Dispose base
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Management
|
|
|
|
|
2009-06-11 21:21:20 +00:00
|
|
|
// Call this before changing properties
|
|
|
|
protected override void BeforePropsChange()
|
|
|
|
{
|
|
|
|
if(map == General.Map.Map)
|
|
|
|
General.Map.UndoRedo.RecPrpVertex(this);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This attaches a linedef and returns the listitem
|
2009-06-11 21:21:20 +00:00
|
|
|
internal LinkedListNode<Linedef> AttachLinedefP(Linedef l)
|
|
|
|
{
|
|
|
|
return linedefs.AddLast(l);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This detaches a linedef
|
2009-06-11 21:21:20 +00:00
|
|
|
internal void DetachLinedefP(LinkedListNode<Linedef> l)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Not disposing?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Remove linedef
|
|
|
|
linedefs.Remove(l);
|
|
|
|
|
|
|
|
// No more linedefs left?
|
2009-06-07 10:26:06 +00:00
|
|
|
if((linedefs.Count == 0) && map.AutoRemove)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// This vertex is now useless, dispose it
|
|
|
|
this.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize / deserialize
|
2013-03-18 13:52:27 +00:00
|
|
|
new internal void ReadWrite(IReadWriteStream s)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2009-06-11 21:21:20 +00:00
|
|
|
if(!s.IsWriting) BeforePropsChange();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
base.ReadWrite(s);
|
|
|
|
|
|
|
|
s.rwVector2D(ref pos);
|
2013-07-08 13:13:28 +00:00
|
|
|
s.rwFloat(ref zceiling); //mxd
|
|
|
|
s.rwFloat(ref zfloor); //mxd
|
2009-06-11 21:21:20 +00:00
|
|
|
|
|
|
|
if(s.IsWriting)
|
|
|
|
{
|
|
|
|
// Let all lines know they need an update
|
|
|
|
foreach(Linedef l in linedefs) l.NeedUpdate();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Selected
|
|
|
|
protected override void DoSelect()
|
|
|
|
{
|
|
|
|
base.DoSelect();
|
|
|
|
selecteditem = map.SelectedVertices.AddLast(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deselect
|
|
|
|
protected override void DoUnselect()
|
|
|
|
{
|
|
|
|
base.DoUnselect();
|
|
|
|
if(selecteditem.List != null) selecteditem.List.Remove(selecteditem);
|
|
|
|
selecteditem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This copies all properties to another thing
|
|
|
|
public void CopyPropertiesTo(Vertex v)
|
|
|
|
{
|
2009-06-11 21:21:20 +00:00
|
|
|
v.BeforePropsChange();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Copy properties
|
|
|
|
v.pos = pos;
|
2013-07-08 13:13:28 +00:00
|
|
|
v.zceiling = zceiling; //mxd
|
|
|
|
v.zfloor = zfloor; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
base.CopyPropertiesTo(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the distance from given coordinates
|
|
|
|
public float DistanceToSq(Vector2D p)
|
|
|
|
{
|
|
|
|
return (p.x - pos.x) * (p.x - pos.x) + (p.y - pos.y) * (p.y - pos.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the distance from given coordinates
|
|
|
|
public float DistanceTo(Vector2D p)
|
|
|
|
{
|
|
|
|
return Vector2D.Distance(p, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This finds the line closest to the specified position
|
|
|
|
public Linedef NearestLinedef(Vector2D pos) { return MapSet.NearestLinedef(linedefs, pos); }
|
|
|
|
|
|
|
|
// This moves the vertex
|
|
|
|
public void Move(Vector2D newpos)
|
|
|
|
{
|
|
|
|
// Do we actually move?
|
|
|
|
if(newpos != pos)
|
|
|
|
{
|
2009-06-11 21:21:20 +00:00
|
|
|
BeforePropsChange();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Change position
|
|
|
|
pos = newpos;
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
if(float.IsNaN(pos.x) || float.IsNaN(pos.y) ||
|
|
|
|
float.IsInfinity(pos.x) || float.IsInfinity(pos.y))
|
|
|
|
{
|
|
|
|
General.Fail("Invalid vertex position! The given vertex coordinates cannot be NaN or Infinite.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Let all lines know they need an update
|
|
|
|
foreach(Linedef l in linedefs) l.NeedUpdate();
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This snaps the vertex to the map format accuracy
|
|
|
|
public void SnapToAccuracy()
|
2015-06-19 19:19:41 +00:00
|
|
|
{
|
|
|
|
SnapToAccuracy(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This snaps the vertex to the map format accuracy
|
|
|
|
public void SnapToAccuracy(bool usepreciseposition)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Round the coordinates
|
2015-06-19 19:19:41 +00:00
|
|
|
Vector2D newpos = new Vector2D((float)Math.Round(pos.x, (usepreciseposition ? General.Map.FormatInterface.VertexDecimals : 0)),
|
|
|
|
(float)Math.Round(pos.y, (usepreciseposition ? General.Map.FormatInterface.VertexDecimals : 0)));
|
2009-04-19 18:07:22 +00:00
|
|
|
this.Move(newpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This snaps the vertex to the grid
|
|
|
|
public void SnapToGrid()
|
|
|
|
{
|
|
|
|
// Calculate nearest grid coordinates
|
|
|
|
this.Move(General.Map.Grid.SnappedToGrid(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This joins another vertex
|
|
|
|
// Which means this vertex is removed and the other is kept!
|
|
|
|
public void Join(Vertex other)
|
|
|
|
{
|
|
|
|
// If either of the two vertices was selected, keep the other selected
|
|
|
|
if(this.Selected) other.Selected = true;
|
|
|
|
if(this.marked) other.marked = true;
|
|
|
|
|
|
|
|
// Any linedefs to move?
|
|
|
|
if(linedefs.Count > 0)
|
|
|
|
{
|
|
|
|
// Detach all linedefs and attach them to the other
|
|
|
|
// This will automatically dispose this vertex
|
|
|
|
while(linedefs != null)
|
|
|
|
{
|
|
|
|
// Move the line to the other vertex
|
|
|
|
if(linedefs.First.Value.Start == this)
|
|
|
|
linedefs.First.Value.SetStartVertex(other);
|
|
|
|
else
|
|
|
|
linedefs.First.Value.SetEndVertex(other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No lines attached
|
|
|
|
// Dispose manually
|
|
|
|
this.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// String representation
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return "Vertex (" + pos + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|