mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-01 13:21:02 +00:00
e03936a0d6
Fixed, Visual mode: in some cases not all sidedef geometry was updated when updating sectors with Plane Align (181) action. Also fixed some more unnecessary geometry updates. Fixed, Linedefs mode, Things mode: in some cases deleting linedefs/things caused a crash when trying to update text labels. Fixed, Draw Lines mode: in some cases the drawing was prematurely finished when "Auto-finish drawing" option was enabled.
128 lines
4.5 KiB
C#
128 lines
4.5 KiB
C#
#region === Copyright (c) 2010 Pascal van der Heiden ===
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
#endregion
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
{
|
|
internal class EffectLineSlope : SectorEffect
|
|
{
|
|
// Linedef that is used to create this effect
|
|
private readonly Linedef l;
|
|
private Plane storedfloor; //mxd. SectorData recreates floor/ceiling planes before updating effects
|
|
private Plane storedceiling; //mxd
|
|
|
|
// Constructor
|
|
public EffectLineSlope(SectorData data, Linedef sourcelinedef) : base(data)
|
|
{
|
|
l = sourcelinedef;
|
|
|
|
// New effect added: This sector needs an update!
|
|
if(data.Mode.VisualSectorExists(data.Sector))
|
|
{
|
|
BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(data.Sector);
|
|
vs.UpdateSectorGeometry(true);
|
|
}
|
|
}
|
|
|
|
// This makes sure we are updated with the source linedef information
|
|
public override void Update()
|
|
{
|
|
if(l.Front == null || l.Back == null) return; //mxd
|
|
|
|
// Find the vertex furthest from the line
|
|
Vertex foundv = null;
|
|
float founddist = -1.0f;
|
|
foreach(Sidedef sd in data.Sector.Sidedefs)
|
|
{
|
|
Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
|
|
float d = l.DistanceToSq(v.Position, false);
|
|
if(d > founddist)
|
|
{
|
|
foundv = v;
|
|
founddist = d;
|
|
}
|
|
}
|
|
|
|
if(foundv == null) return; //mxd
|
|
bool updatesides = false;
|
|
|
|
// Align floor with back of line
|
|
if((l.Args[0] == 1) && (l.Front.Sector == data.Sector))
|
|
{
|
|
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.FloorHeight);
|
|
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
|
|
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
|
|
data.Floor.plane = (l.SideOfLine(v3) < 0.0f ? new Plane(v1, v2, v3, true) : new Plane(v2, v1, v3, true));
|
|
|
|
//mxd. Update only when actually changed
|
|
if(storedfloor != data.Floor.plane)
|
|
{
|
|
storedfloor = data.Floor.plane;
|
|
updatesides = true;
|
|
}
|
|
}
|
|
// Align floor with front of line
|
|
else if((l.Args[0] == 2) && (l.Back.Sector == data.Sector))
|
|
{
|
|
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.FloorHeight);
|
|
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
|
|
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.FloorHeight);
|
|
data.Floor.plane = (l.SideOfLine(v3) < 0.0f ? new Plane(v1, v2, v3, true) : new Plane(v2, v1, v3, true));
|
|
|
|
//mxd. Update only when actually changed
|
|
if(storedfloor != data.Floor.plane)
|
|
{
|
|
storedfloor = data.Floor.plane;
|
|
updatesides = true;
|
|
}
|
|
}
|
|
|
|
// Align ceiling with back of line
|
|
if((l.Args[1] == 1) && (l.Front.Sector == data.Sector))
|
|
{
|
|
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.CeilHeight);
|
|
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
|
|
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
|
|
data.Ceiling.plane = (l.SideOfLine(v3) > 0.0f ? new Plane(v1, v2, v3, false) : new Plane(v2, v1, v3, false));
|
|
|
|
//mxd. Update only when actually changed
|
|
if(storedceiling != data.Ceiling.plane)
|
|
{
|
|
storedceiling = data.Ceiling.plane;
|
|
updatesides = true;
|
|
}
|
|
}
|
|
// Align ceiling with front of line
|
|
else if((l.Args[1] == 2) && (l.Back.Sector == data.Sector))
|
|
{
|
|
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.CeilHeight);
|
|
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);
|
|
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, data.Sector.CeilHeight);
|
|
data.Ceiling.plane = (l.SideOfLine(v3) > 0.0f ? new Plane(v1, v2, v3, false) : new Plane(v2, v1, v3, false));
|
|
|
|
//mxd. Update only when actually changed
|
|
if(storedceiling != data.Ceiling.plane)
|
|
{
|
|
storedceiling = data.Ceiling.plane;
|
|
updatesides = true;
|
|
}
|
|
}
|
|
|
|
//mxd. Update outer sidedef geometry
|
|
if(updatesides)
|
|
{
|
|
foreach(Sidedef side in data.Sector.Sidedefs)
|
|
{
|
|
if(side.Other != null && side.Other.Sector != null && data.Mode.VisualSectorExists(side.Other.Sector))
|
|
{
|
|
BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(side.Other.Sector);
|
|
vs.GetSidedefParts(side.Other).SetupAllParts();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|