UltimateZoneBuilder/Source/Plugins/GZDoomEditing/VisualModes/SectorData.cs

107 lines
3.1 KiB
C#
Raw Normal View History

2010-09-02 20:42:38 +00:00
#region === Copyright (c) 2010 Pascal van der Heiden ===
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.GZDoomEditing
{
internal class SectorData
{
#region ================== Variables
// Sector for which this data is
private Sector sector;
2010-09-03 06:03:28 +00:00
// Levels have been built?
private bool built;
2010-09-02 20:42:38 +00:00
// First level is the sector's absolute ceiling
// Last level is the sector's absolute floor
private List<SectorLevel> levels;
2010-09-03 06:03:28 +00:00
// Linedefs and Things of interest when building the levels
// See RebuildSectorData() in BaseVisualMode.cs for the logic which selects interesting elements
private List<Linedef> linedefs;
private List<Thing> things;
2010-09-02 20:42:38 +00:00
#endregion
#region ================== Properties
public Sector Sector { get { return sector; } }
2010-09-03 06:03:28 +00:00
public bool Built { get { return built; } }
2010-09-02 20:42:38 +00:00
public List<SectorLevel> Levels { get { return levels; } }
#endregion
#region ================== Constructor / Destructor
// Constructor
2010-09-03 06:03:28 +00:00
public SectorData(Sector s)
2010-09-02 20:42:38 +00:00
{
// Initialize
this.sector = s;
2010-09-03 06:03:28 +00:00
this.built = false;
2010-09-02 20:42:38 +00:00
this.levels = new List<SectorLevel>(2);
2010-09-03 06:03:28 +00:00
this.linedefs = new List<Linedef>(1);
this.things = new List<Thing>(1);
}
#endregion
#region ================== Public Methods
// This adds a linedef that of interest to this sector, because it modifies the sector
public void AddLinedef(Linedef l) { linedefs.Add(l); }
// This adds a thing that of interest to this sector, because it modifies the sector
public void AddThing(Thing t) { things.Add(t); }
2010-09-02 20:42:38 +00:00
2010-09-03 06:03:28 +00:00
// This creates the levels with the things and linedefs of interest
public void BuildLevels(BaseVisualMode mode)
{
int color = -1, light = sector.Brightness;
bool absolute = true;
2010-09-02 20:42:38 +00:00
// Create floor
SectorLevel fl = new SectorLevel();
fl.type = SectorLevelType.Floor;
2010-09-03 06:03:28 +00:00
fl.plane = new Plane(new Vector3D(0, 0, 1), sector.FloorHeight);
2010-09-02 20:42:38 +00:00
fl.color = -1;
2010-09-03 06:03:28 +00:00
levels.Add(fl);
2010-09-02 20:42:38 +00:00
// Create ceiling
SectorLevel cl = new SectorLevel();
cl.type = SectorLevelType.Ceiling;
2010-09-03 06:03:28 +00:00
cl.plane = new Plane(new Vector3D(0, 0, -1), sector.CeilHeight);
2010-09-02 20:42:38 +00:00
try
{
// Fetch ZDoom fields
2010-09-03 06:03:28 +00:00
color = sector.Fields.ContainsKey("lightcolor") ? (int)sector.Fields["lightcolor"].Value : -1;
light = sector.Fields.ContainsKey("lightfloor") ? (int)sector.Fields["lightfloor"].Value : 0;
absolute = sector.Fields.ContainsKey("lightfloorabsolute") ? (bool)sector.Fields["lightfloorabsolute"].Value : false;
2010-09-02 20:42:38 +00:00
}
catch(Exception) { }
2010-09-03 06:03:28 +00:00
if(!absolute) light = sector.Brightness + light;
2010-09-02 20:42:38 +00:00
PixelColor lightcolor = PixelColor.FromInt(color);
PixelColor brightness = PixelColor.FromInt(mode.CalculateBrightness(light));
PixelColor finalcolor = PixelColor.Modulate(lightcolor, brightness);
cl.color = finalcolor.WithAlpha(255).ToInt();
2010-09-03 06:03:28 +00:00
levels.Add(cl);
2010-09-02 20:42:38 +00:00
2010-09-03 06:03:28 +00:00
// Done
built = true;
}
2010-09-02 20:42:38 +00:00
#endregion
}
}