2010-09-17 17:12:08 +00:00
|
|
|
|
#region === Copyright (c) 2010 Pascal van der Heiden ===
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2012-11-27 21:12:20 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
2010-09-17 17:12:08 +00:00
|
|
|
|
{
|
|
|
|
|
internal class SectorLevelComparer : IComparer<SectorLevel>
|
|
|
|
|
{
|
|
|
|
|
// Center of sector to use for plane comparison
|
|
|
|
|
public Vector2D center;
|
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
public SectorLevelComparer(Sector s)
|
|
|
|
|
{
|
|
|
|
|
this.center = new Vector2D(s.BBox.Left + s.BBox.Width / 2, s.BBox.Top + s.BBox.Height / 2);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 11:33:57 +00:00
|
|
|
|
// Comparer. -1 = x is less than y.
|
2010-09-17 17:12:08 +00:00
|
|
|
|
public int Compare(SectorLevel x, SectorLevel y)
|
|
|
|
|
{
|
2015-04-01 12:51:26 +00:00
|
|
|
|
if(x == y) return 0; //mxd
|
2016-03-25 14:06:00 +00:00
|
|
|
|
|
|
|
|
|
//mxd. Handle surfaces with the same height
|
2020-05-22 20:30:32 +00:00
|
|
|
|
double diff = Math.Round(x.plane.GetZ(center) - y.plane.GetZ(center), 3);
|
2015-04-01 12:51:26 +00:00
|
|
|
|
if(diff == 0)
|
|
|
|
|
{
|
2015-04-14 11:33:57 +00:00
|
|
|
|
bool xislight = (x.type == SectorLevelType.Light || x.type == SectorLevelType.Glow);
|
|
|
|
|
bool yislight = (y.type == SectorLevelType.Light || y.type == SectorLevelType.Glow);
|
2016-03-25 14:06:00 +00:00
|
|
|
|
|
|
|
|
|
// Compare regular and extrafloors
|
|
|
|
|
if(!xislight && ! yislight && x.lighttype == LightLevelType.UNKNOWN && y.lighttype == LightLevelType.UNKNOWN)
|
|
|
|
|
{
|
|
|
|
|
// Both are 3d floors. Push extrafloors above extraceilings
|
|
|
|
|
if(x.extrafloor && y.extrafloor)
|
|
|
|
|
{
|
|
|
|
|
if(x.type == SectorLevelType.Floor) return (y.type == SectorLevelType.Ceiling ? 1 : 0);
|
|
|
|
|
return (y.type == SectorLevelType.Floor ? -1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// None is 3d floor. Push ceilings above floors
|
|
|
|
|
if(!x.extrafloor && !y.extrafloor)
|
|
|
|
|
{
|
|
|
|
|
if(x.type == SectorLevelType.Floor) return (y.type == SectorLevelType.Ceiling ? -1 : 0);
|
|
|
|
|
return (y.type == SectorLevelType.Floor ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One is 3d floor. Push it below the regular surface if it has "disablelighting" flag, and above otherwise
|
|
|
|
|
return ((x.extrafloor && x.disablelighting) || (y.extrafloor && !y.disablelighting) ? -1 : 1);
|
|
|
|
|
}
|
2015-04-14 11:33:57 +00:00
|
|
|
|
|
2016-03-25 14:06:00 +00:00
|
|
|
|
// Push light levels above floor and ceiling levels when height is the same
|
2015-04-14 11:33:57 +00:00
|
|
|
|
if(!xislight) return (yislight ? -1 : 0);
|
|
|
|
|
if(!yislight) return 1;
|
2015-04-01 12:51:26 +00:00
|
|
|
|
|
2016-03-25 14:06:00 +00:00
|
|
|
|
// Push light levels without lighttype (those should be lower levels of type 1 Transfer Brightness effect) above other ones
|
2015-04-14 11:33:57 +00:00
|
|
|
|
if(x.lighttype == y.lighttype) return 0; //TODO: how this should be handled?
|
|
|
|
|
if(x.lighttype == LightLevelType.TYPE1_BOTTOM) return 1;
|
|
|
|
|
return -1;
|
2015-04-01 12:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Math.Sign(diff);
|
2010-09-17 17:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|