mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 22:01:45 +00:00
@ work on (G)ZDoom Editing plugin
This commit is contained in:
parent
21c48f78e0
commit
6e26ced98e
2 changed files with 106 additions and 47 deletions
|
@ -135,7 +135,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Initialize
|
||||
this.gravity = new Vector3D(0.0f, 0.0f, 0.0f);
|
||||
this.selectedobjects = new List<IVisualEventReceiver>();
|
||||
this.sectordata = new Dictionary<Sector, SectorData>(General.Map.Map.Sectors.Count);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
@ -158,20 +157,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
|
||||
#region ================== Methods
|
||||
|
||||
// This requests a sector's extra data
|
||||
internal SectorData GetSectorData(Sector s)
|
||||
{
|
||||
if(sectordata.ContainsKey(s))
|
||||
{
|
||||
return sectordata[s];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Build the sector data now?
|
||||
return new SectorData(this, s);
|
||||
}
|
||||
}
|
||||
|
||||
// This calculates brightness level
|
||||
internal int CalculateBrightness(int level)
|
||||
{
|
||||
|
@ -426,9 +411,56 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Extended Methods
|
||||
|
||||
// This requests a sector's extra data
|
||||
internal SectorData GetSectorData(Sector s)
|
||||
{
|
||||
// Make fresh sector data when it doesn't exist yet
|
||||
if(!sectordata.ContainsKey(s))
|
||||
sectordata[s] = new SectorData(s);
|
||||
|
||||
return sectordata[s];
|
||||
}
|
||||
|
||||
// This rebuilds the sector data
|
||||
internal void RebuildSectorData()
|
||||
{
|
||||
sectordata = new Dictionary<Sector, SectorData>(General.Map.Map.Sectors.Count);
|
||||
|
||||
// Find interesting linedefs (such as line slopes)
|
||||
foreach(Linedef l in General.Map.Map.Linedefs)
|
||||
{
|
||||
// Plane Align (see http://zdoom.org/wiki/Plane_Align)
|
||||
if(l.Action == 181)
|
||||
{
|
||||
// Slope front
|
||||
if(((l.Args[0] == 1) || (l.Args[1] == 1)) && (l.Front != null))
|
||||
{
|
||||
SectorData sd = GetSectorData(l.Front.Sector);
|
||||
sd.AddLinedef(l);
|
||||
}
|
||||
|
||||
// Slope back
|
||||
if(((l.Args[0] == 2) || (l.Args[1] == 2)) && (l.Back != null))
|
||||
{
|
||||
SectorData sd = GetSectorData(l.Back.Sector);
|
||||
sd.AddLinedef(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find interesting things (such as vertex and sector slopes)
|
||||
foreach(Thing t in General.Map.Map.Things)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Events
|
||||
|
||||
|
||||
// Help!
|
||||
public override void OnHelp()
|
||||
{
|
||||
|
@ -443,6 +475,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Read settings
|
||||
cameraflooroffset = General.Map.Config.ReadSetting("cameraflooroffset", cameraflooroffset);
|
||||
cameraceilingoffset = General.Map.Config.ReadSetting("cameraceilingoffset", cameraceilingoffset);
|
||||
|
||||
RebuildSectorData();
|
||||
}
|
||||
|
||||
// When returning to another mode
|
||||
|
@ -562,7 +596,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
protected override void ResourcesReloaded()
|
||||
{
|
||||
base.ResourcesReloaded();
|
||||
sectordata = new Dictionary<Sector, SectorData>(General.Map.Map.Sectors.Count);
|
||||
RebuildSectorData();
|
||||
PickTarget();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,16 +19,25 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
|
||||
// Sector for which this data is
|
||||
private Sector sector;
|
||||
|
||||
// Levels have been built?
|
||||
private bool built;
|
||||
|
||||
// First level is the sector's absolute ceiling
|
||||
// Last level is the sector's absolute floor
|
||||
private List<SectorLevel> levels;
|
||||
|
||||
// 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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public Sector Sector { get { return sector; } }
|
||||
public bool Built { get { return built; } }
|
||||
public List<SectorLevel> Levels { get { return levels; } }
|
||||
|
||||
#endregion
|
||||
|
@ -36,46 +45,62 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
#region ================== Constructor / Destructor
|
||||
|
||||
// Constructor
|
||||
public SectorData(BaseVisualMode mode, Sector s)
|
||||
public SectorData(Sector s)
|
||||
{
|
||||
int color = -1, light = s.Brightness;
|
||||
bool absolute = true;
|
||||
|
||||
// Initialize
|
||||
this.sector = s;
|
||||
this.built = false;
|
||||
this.levels = new List<SectorLevel>(2);
|
||||
|
||||
// Create floor
|
||||
SectorLevel fl = new SectorLevel();
|
||||
fl.type = SectorLevelType.Floor;
|
||||
fl.plane = new Plane(new Vector3D(0, 0, 1), s.FloorHeight);
|
||||
fl.color = -1;
|
||||
this.levels.Add(fl);
|
||||
|
||||
// Create ceiling
|
||||
SectorLevel cl = new SectorLevel();
|
||||
cl.type = SectorLevelType.Ceiling;
|
||||
cl.plane = new Plane(new Vector3D(0, 0, -1), s.CeilHeight);
|
||||
try
|
||||
{
|
||||
// Fetch ZDoom fields
|
||||
color = s.Fields.ContainsKey("lightcolor") ? (int)s.Fields["lightcolor"].Value : -1;
|
||||
light = s.Fields.ContainsKey("lightfloor") ? (int)s.Fields["lightfloor"].Value : 0;
|
||||
absolute = s.Fields.ContainsKey("lightfloorabsolute") ? (bool)s.Fields["lightfloorabsolute"].Value : false;
|
||||
}
|
||||
catch(Exception) { }
|
||||
if(!absolute) light = s.Brightness + light;
|
||||
PixelColor lightcolor = PixelColor.FromInt(color);
|
||||
PixelColor brightness = PixelColor.FromInt(mode.CalculateBrightness(light));
|
||||
PixelColor finalcolor = PixelColor.Modulate(lightcolor, brightness);
|
||||
cl.color = finalcolor.WithAlpha(255).ToInt();
|
||||
this.levels.Add(cl);
|
||||
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); }
|
||||
|
||||
// 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;
|
||||
|
||||
// Create floor
|
||||
SectorLevel fl = new SectorLevel();
|
||||
fl.type = SectorLevelType.Floor;
|
||||
fl.plane = new Plane(new Vector3D(0, 0, 1), sector.FloorHeight);
|
||||
fl.color = -1;
|
||||
levels.Add(fl);
|
||||
|
||||
// Create ceiling
|
||||
SectorLevel cl = new SectorLevel();
|
||||
cl.type = SectorLevelType.Ceiling;
|
||||
cl.plane = new Plane(new Vector3D(0, 0, -1), sector.CeilHeight);
|
||||
try
|
||||
{
|
||||
// Fetch ZDoom fields
|
||||
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;
|
||||
}
|
||||
catch(Exception) { }
|
||||
if(!absolute) light = sector.Brightness + light;
|
||||
PixelColor lightcolor = PixelColor.FromInt(color);
|
||||
PixelColor brightness = PixelColor.FromInt(mode.CalculateBrightness(light));
|
||||
PixelColor finalcolor = PixelColor.Modulate(lightcolor, brightness);
|
||||
cl.color = finalcolor.WithAlpha(255).ToInt();
|
||||
levels.Add(cl);
|
||||
|
||||
// Done
|
||||
built = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue