2010-09-11 20:14:36 +00:00
|
|
|
|
#region === Copyright (c) 2010 Pascal van der Heiden ===
|
|
|
|
|
|
2016-05-15 00:38:41 +00:00
|
|
|
|
using System.Collections.Generic;
|
2010-09-11 20:14:36 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2012-11-27 21:12:20 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
2010-09-11 20:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
internal class EffectLineSlope : SectorEffect
|
|
|
|
|
{
|
|
|
|
|
// Linedef that is used to create this effect
|
2015-04-15 12:49:28 +00:00
|
|
|
|
private readonly Linedef l;
|
2016-04-22 13:28:23 +00:00
|
|
|
|
private Plane storedfloor; //mxd. SectorData recreates floor/ceiling planes before updating effects
|
|
|
|
|
private Plane storedceiling; //mxd
|
2010-09-11 20:14:36 +00:00
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
public EffectLineSlope(SectorData data, Linedef sourcelinedef) : base(data)
|
|
|
|
|
{
|
2015-04-15 12:49:28 +00:00
|
|
|
|
l = sourcelinedef;
|
2010-09-13 06:07:11 +00:00
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
2010-09-11 20:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This makes sure we are updated with the source linedef information
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
2015-04-15 12:49:28 +00:00
|
|
|
|
if(l.Front == null || l.Back == null) return; //mxd
|
2010-09-11 20:14:36 +00:00
|
|
|
|
|
|
|
|
|
// Find the vertex furthest from the line
|
|
|
|
|
Vertex foundv = null;
|
2020-05-21 12:20:02 +00:00
|
|
|
|
double founddist = -1.0f;
|
2010-09-11 20:14:36 +00:00
|
|
|
|
foreach(Sidedef sd in data.Sector.Sidedefs)
|
|
|
|
|
{
|
|
|
|
|
Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
|
2020-05-21 12:20:02 +00:00
|
|
|
|
double d = l.DistanceToSq(v.Position, false);
|
2010-09-11 20:14:36 +00:00
|
|
|
|
if(d > founddist)
|
|
|
|
|
{
|
|
|
|
|
foundv = v;
|
|
|
|
|
founddist = d;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-19 20:40:42 +00:00
|
|
|
|
|
|
|
|
|
if(foundv == null) return; //mxd
|
2016-04-22 13:28:23 +00:00
|
|
|
|
bool updatesides = false;
|
2010-09-11 20:14:36 +00:00
|
|
|
|
|
|
|
|
|
// Align floor with back of line
|
2015-04-15 12:49:28 +00:00
|
|
|
|
if((l.Args[0] == 1) && (l.Front.Sector == data.Sector))
|
2010-09-11 20:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2016-04-22 13:28:23 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2010-09-11 20:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
// Align floor with front of line
|
2015-04-15 12:49:28 +00:00
|
|
|
|
else if((l.Args[0] == 2) && (l.Back.Sector == data.Sector))
|
2010-09-11 20:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2016-04-22 13:28:23 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2010-09-11 20:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Align ceiling with back of line
|
2015-04-15 12:49:28 +00:00
|
|
|
|
if((l.Args[1] == 1) && (l.Front.Sector == data.Sector))
|
2010-09-11 20:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2016-04-22 13:28:23 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2010-09-11 20:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
// Align ceiling with front of line
|
2015-04-15 12:49:28 +00:00
|
|
|
|
else if((l.Args[1] == 2) && (l.Back.Sector == data.Sector))
|
2010-09-11 20:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2016-04-22 13:28:23 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2016-05-15 00:38:41 +00:00
|
|
|
|
UpdateSectorSides(data.Sector);
|
|
|
|
|
|
|
|
|
|
// Update sectors with PlaneCopySlope Effect...
|
|
|
|
|
List<SectorData> toupdate = new List<SectorData>();
|
|
|
|
|
foreach(Sector s in data.UpdateAlso.Keys)
|
2016-04-22 13:28:23 +00:00
|
|
|
|
{
|
2016-05-15 00:38:41 +00:00
|
|
|
|
SectorData osd = data.Mode.GetSectorDataEx(s);
|
|
|
|
|
if(osd == null) continue;
|
|
|
|
|
foreach(SectorEffect e in osd.Effects)
|
2016-04-22 13:28:23 +00:00
|
|
|
|
{
|
2016-05-15 00:38:41 +00:00
|
|
|
|
if(e is EffectPlaneCopySlope)
|
|
|
|
|
{
|
|
|
|
|
toupdate.Add(osd);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-04-22 13:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 00:38:41 +00:00
|
|
|
|
|
|
|
|
|
// Do it in 2 steps, because SectorData.Reset() may change SectorData.UpdateAlso collection...
|
|
|
|
|
foreach(SectorData sd in toupdate)
|
|
|
|
|
{
|
|
|
|
|
// Update PlaneCopySlope Effect...
|
|
|
|
|
sd.Reset(false);
|
|
|
|
|
|
|
|
|
|
// Update outer sides...
|
|
|
|
|
UpdateSectorSides(sd.Sector);
|
|
|
|
|
}
|
2016-10-04 09:53:38 +00:00
|
|
|
|
|
|
|
|
|
// Update all things in the sector
|
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
|
{
|
|
|
|
|
if(t.Sector == data.Sector)
|
|
|
|
|
{
|
|
|
|
|
if(data.Mode.VisualThingExists(t))
|
|
|
|
|
{
|
|
|
|
|
// Update thing
|
|
|
|
|
BaseVisualThing vt = (BaseVisualThing)data.Mode.GetVisualThing(t);
|
|
|
|
|
vt.Changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 00:38:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
|
private void UpdateSectorSides(Sector s)
|
|
|
|
|
{
|
|
|
|
|
foreach(Sidedef side in s.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();
|
|
|
|
|
}
|
2010-09-11 20:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|