@ work on (G)ZDoom Editing plugin

This commit is contained in:
codeimp 2010-09-14 19:14:44 +00:00
parent ecf6053a50
commit f59094e2bc
16 changed files with 237 additions and 65 deletions

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{760A9BC7-CB73-4C36-858B-994C14996FCD}</ProjectGuid>
<OutputType>Library</OutputType>
@ -56,6 +56,7 @@
<Compile Include="VisualModes\EffectCopySlope.cs" />
<Compile Include="VisualModes\EffectLineSlope.cs" />
<Compile Include="VisualModes\EffectThingLineSlope.cs" />
<Compile Include="VisualModes\EffectThingVertexSlope.cs" />
<Compile Include="VisualModes\IVisualEventReceiver.cs" />
<Compile Include="VisualModes\NullVisualEventReceiver.cs" />
<Compile Include="VisualModes\Effect3DFloor.cs" />

View file

@ -67,9 +67,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Destructor
// Constructor
public BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(vs)
protected BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs) : base(vs)
{
this.level = level;
this.mode = mode;
}
@ -85,7 +84,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Events
// Unused
public abstract bool Setup();
public virtual void OnSelectBegin(){ }
public virtual void OnEditBegin() { }
public virtual void OnMouseMove(MouseEventArgs e) { }
@ -102,6 +100,14 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
public virtual void ApplyUpperUnpegged(bool set) { }
public virtual void ApplyLowerUnpegged(bool set) { }
// Setup this plane
public bool Setup() { return this.Setup(this.level); }
public virtual bool Setup(SectorLevel level)
{
this.level = level;
return false;
}
// Select or deselect
public virtual void OnSelectEnd()
{
@ -207,7 +213,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Copy properties
public virtual void OnCopyProperties()
{
BuilderPlug.Me.CopiedSectorProps = new SectorProperties(Sector.Sector);
BuilderPlug.Me.CopiedSectorProps = new SectorProperties(level.sector);
mode.SetActionResult("Copied sector properties.");
}
@ -218,8 +224,12 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
{
mode.CreateUndo("Paste sector properties");
mode.SetActionResult("Pasted sector properties.");
BuilderPlug.Me.CopiedSectorProps.Apply(Sector.Sector);
Sector.UpdateSectorGeometry(true);
BuilderPlug.Me.CopiedSectorProps.Apply(level.sector);
if(mode.VisualSectorExists(level.sector))
{
BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(level.sector);
vs.UpdateSectorGeometry(true);
}
mode.ShowTargetInfo();
}
}
@ -270,9 +280,11 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Rebuild sector
foreach(Sector s in sectors)
{
VisualSector vs = mode.GetVisualSector(s);
if(vs != null)
(vs as BaseVisualSector).UpdateSectorGeometry(true);
if(mode.VisualSectorExists(s))
{
BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(s);
vs.UpdateSectorGeometry(true);
}
}
}
}

View file

@ -160,11 +160,10 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// This creates vertices from a wall polygon and applies lighting
protected List<WorldVertex> CreatePolygonVertices(WallPolygon poly, TexturePlane tp)
protected List<WorldVertex> CreatePolygonVertices(WallPolygon poly, TexturePlane tp, SectorData sd)
{
List<WallPolygon> polygons = new List<WallPolygon>(2);
List<WorldVertex> verts = new List<WorldVertex>();
SectorData sd = Sector.Data;
polygons.Add(poly);
@ -823,6 +822,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
(vs as BaseVisualSector).Changed = true;
}
}
mode.RebuildSectorData();
}
}
}

View file

@ -19,6 +19,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
@ -441,6 +442,52 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
}
}
// Find sectors with 3 vertices, because they can be sloped
foreach(Sector s in General.Map.Map.Sectors)
{
if(s.Sidedefs.Count == 3)
{
List<Thing> slopeceilingthings = new List<Thing>(3);
List<Thing> slopefloorthings = new List<Thing>(3);
foreach(Sidedef sd in s.Sidedefs)
{
Vertex v;
if(sd.IsFront)
v = sd.Line.End;
else
v = sd.Line.Start;
// Check if a thing is at this vertex
VisualBlockEntry b = blockmap.GetBlock(blockmap.GetBlockCoordinates(v.Position));
foreach(Thing t in b.Things)
{
if((Vector2D)t.Position == v.Position)
{
if(t.Type == 1504)
slopefloorthings.Add(t);
else if(t.Type == 1505)
slopeceilingthings.Add(t);
break;
}
}
}
// Slope any floor vertices?
if(slopefloorthings.Count > 0)
{
SectorData sd = GetSectorData(s);
sd.AddEffectThingVertexSlope(slopefloorthings, true);
}
// Slope any ceiling vertices?
if(slopeceilingthings.Count > 0)
{
SectorData sd = GetSectorData(s);
sd.AddEffectThingVertexSlope(slopeceilingthings, false);
}
}
}
// Find interesting linedefs (such as line slopes)
foreach(Linedef l in General.Map.Map.Linedefs)
{
@ -490,7 +537,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
}
}
// Find interesting things (such as vertex and sector slopes)
// Find interesting things (such as sector slopes)
foreach(Thing t in General.Map.Map.Things)
{
// ========== Copy slope ==========

View file

@ -46,11 +46,10 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
protected BaseVisualMode mode;
protected SectorData data;
protected VisualFloor floor;
protected VisualCeiling ceiling;
protected Dictionary<Effect3DFloor, VisualFloor> extrafloors;
protected Dictionary<Effect3DFloor, VisualCeiling> extraceilings;
protected List<VisualFloor> extrafloors;
protected List<VisualCeiling> extraceilings;
protected Dictionary<Sidedef, VisualSidedefParts> sides;
// If this is set to true, the sector will be rebuilt after the action is performed.
@ -60,7 +59,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Properties
public SectorData Data { get { return data; } }
public VisualFloor Floor { get { return floor; } }
public VisualCeiling Ceiling { get { return ceiling; } }
public bool Changed { get { return changed; } set { changed |= value; } }
@ -73,6 +71,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
public BaseVisualSector(BaseVisualMode mode, Sector s) : base(s)
{
this.mode = mode;
this.extrafloors = new List<VisualFloor>(2);
this.extraceilings = new List<VisualCeiling>(2);
// Initialize
Rebuild();
@ -103,14 +103,23 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Methods
// This retreives the sector data for this sector
public SectorData GetSectorData()
{
return mode.GetSectorData(this.Sector);
}
// This updates this virtual the sector and neightbours if needed
public void UpdateSectorGeometry(bool includeneighbours)
{
// Rebuild sector
this.Changed = true;
data.Reset();
// Not sure what from this part we need, so commented out for now
SectorData data = GetSectorData();
data.Reset();
/*
// Update sectors that rely on this sector
foreach(KeyValuePair<Sector, bool> s in data.UpdateAlso)
{
@ -120,7 +129,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
vs.UpdateSectorGeometry(s.Value);
}
}
*/
// Go for all things in this sector
foreach(Thing t in General.Map.Map.Things)
{
@ -159,37 +169,37 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
base.ClearGeometry();
// Get sector data
data = mode.GetSectorData(this.Sector);
SectorData data = GetSectorData();
if(!data.Updated) data.Update();
// Create floor
floor = floor ?? new VisualFloor(mode, this, data.Floor);
if(floor.Setup())
floor = floor ?? new VisualFloor(mode, this);
if(floor.Setup(data.Floor))
base.AddGeometry(floor);
// Create ceiling
ceiling = ceiling ?? new VisualCeiling(mode, this, data.Ceiling);
if(ceiling.Setup())
ceiling = ceiling ?? new VisualCeiling(mode, this);
if(ceiling.Setup(data.Ceiling))
base.AddGeometry(ceiling);
// Create 3D floors
Dictionary<Effect3DFloor, VisualFloor> oldextrafloors = extrafloors ?? new Dictionary<Effect3DFloor, VisualFloor>(1);
extrafloors = new Dictionary<Effect3DFloor, VisualFloor>(data.ExtraFloors.Count);
Dictionary<Effect3DFloor, VisualCeiling> oldextraceilings = extraceilings ?? new Dictionary<Effect3DFloor, VisualCeiling>(1);
extraceilings = new Dictionary<Effect3DFloor, VisualCeiling>(data.ExtraFloors.Count);
foreach(Effect3DFloor ef in data.ExtraFloors)
for(int i = 0; i < data.ExtraFloors.Count; i++)
{
// Create a floor
VisualFloor vf = oldextrafloors.ContainsKey(ef) ? oldextrafloors[ef] : new VisualFloor(mode, this, ef.Floor);
if(vf.Setup())
base.AddGeometry(vf);
extrafloors.Add(ef, vf);
Effect3DFloor ef = data.ExtraFloors[i];
// Create a floor
VisualFloor vf = (i < extrafloors.Count) ? extrafloors[i] : new VisualFloor(mode, this);
if(vf.Setup(ef.Floor))
base.AddGeometry(vf);
if(i >= extrafloors.Count)
extrafloors.Add(vf);
// Create a ceiling
VisualCeiling vc = oldextraceilings.ContainsKey(ef) ? oldextraceilings[ef] : new VisualCeiling(mode, this, ef.Ceiling);
if(vc.Setup())
VisualCeiling vc = (i < extraceilings.Count) ? extraceilings[i] : new VisualCeiling(mode, this);
if(vc.Setup(ef.Ceiling))
base.AddGeometry(vc);
extraceilings.Add(ef, vc);
if(i >= extraceilings.Count)
extraceilings.Add(vc);
}
// Go for all sidedefs
@ -221,18 +231,20 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Create 3D wall parts
SectorData osd = mode.GetSectorData(sd.Other.Sector);
if(!osd.Updated) osd.Update();
Dictionary<Effect3DFloor, VisualMiddle3D> oldfloors = parts.middle3d ?? new Dictionary<Effect3DFloor, VisualMiddle3D>(2);
Dictionary<Effect3DFloor, VisualMiddle3D> newfloors = new Dictionary<Effect3DFloor, VisualMiddle3D>(2);
foreach(Effect3DFloor ef in osd.ExtraFloors)
List<VisualMiddle3D> middles = parts.middle3d ?? new List<VisualMiddle3D>(2);
for(int i = 0; i < osd.ExtraFloors.Count; i++)
{
VisualMiddle3D vm3 = oldfloors.ContainsKey(ef) ? oldfloors[ef] : new VisualMiddle3D(mode, this, sd, ef);
if(vm3.Setup())
Effect3DFloor ef = osd.ExtraFloors[i];
VisualMiddle3D vm3 = (i < middles.Count) ? middles[i] : new VisualMiddle3D(mode, this, sd);
if(vm3.Setup(ef))
base.AddGeometry(vm3);
newfloors.Add(ef, vm3);
if(i >= middles.Count)
middles.Add(vm3);
}
// Store
sides.Add(sd, new VisualSidedefParts(vu, vl, vm, newfloors));
sides.Add(sd, new VisualSidedefParts(vu, vl, vm, middles));
}
else
{

View file

@ -0,0 +1,73 @@
#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 EffectThingVertexSlope : SectorEffect
{
// Thing used to create this effect
// The thing is in the sector that must receive the slope and the
// Thing's arg 0 indicates the linedef to start the slope at.
private List<Thing> things;
// Floor or ceiling?
private bool slopefloor;
// Constructor
public EffectThingVertexSlope(SectorData data, List<Thing> sourcethings, bool floor) : base(data)
{
things = sourcethings;
slopefloor = floor;
// 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()
{
// Create vertices in clockwise order
Vector3D[] verts = new Vector3D[3];
int index = 0;
foreach(Sidedef sd in data.Sector.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;
// Presume not sloped
if(slopefloor)
verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Floor.plane.GetZ(v.Position));
else
verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Ceiling.plane.GetZ(v.Position));
// Find the thing at this position
foreach(Thing t in things)
{
if((Vector2D)t.Position == v.Position)
verts[index] = t.Position;
}
index++;
}
// Make new plane
if(slopefloor)
data.Floor.plane = new Plane(verts[0], verts[1], verts[2], true);
else
data.Ceiling.plane = new Plane(verts[0], verts[2], verts[1], false);
}
}
}

View file

@ -122,6 +122,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
EffectThingLineSlope e = new EffectThingLineSlope(this, sourcething);
alleffects.Add(e);
}
// Thing vertex slope effect
public void AddEffectThingVertexSlope(List<Thing> sourcethings, bool slopefloor)
{
EffectThingVertexSlope e = new EffectThingVertexSlope(this, sourcethings, slopefloor);
alleffects.Add(e);
}
// This adds a sector for updating
public void AddUpdateSector(Sector s, bool includeneighbours)
@ -148,6 +155,14 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// This is set to false so that this sector is rebuilt the next time it is needed!
updated = false;
// The visual sector associated is now outdated
if(mode.VisualSectorExists(sector))
{
BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(sector);
vs.UpdateSectorGeometry(false);
}
// Also reset the sectors that depend on this sector
foreach(KeyValuePair<Sector, bool> s in updatesectors)
{
SectorData sd = mode.GetSectorData(s.Key);
@ -233,6 +248,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
if(l.brightnessbelow == -1)
l.brightnessbelow = pl.brightnessbelow;
}
// The visual sector associated is now outdated
if(mode.VisualSectorExists(sector))
{
BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(sector);
vs.UpdateSectorGeometry(false);
}
isupdating = false;
}

View file

@ -58,14 +58,14 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Setup
// Constructor
public VisualCeiling(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(mode, vs, level)
public VisualCeiling(BaseVisualMode mode, VisualSector vs) : base(mode, vs)
{
// We have no destructor
GC.SuppressFinalize(this);
}
// This builds the geometry. Returns false when no geometry created.
public override bool Setup()
public override bool Setup(SectorLevel level)
{
WorldVertex[] verts;
WorldVertex v;
@ -73,6 +73,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
float xpan, ypan, xscale, yscale, rotate;
Vector2D texscale;
base.Setup(level);
try
{
// Fetch ZDoom fields

View file

@ -58,20 +58,22 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Setup
// Constructor
public VisualFloor(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(mode, vs, level)
public VisualFloor(BaseVisualMode mode, VisualSector vs) : base(mode, vs)
{
// We have no destructor
GC.SuppressFinalize(this);
}
// This builds the geometry. Returns false when no geometry created.
public override bool Setup()
public override bool Setup(SectorLevel level)
{
WorldVertex[] verts;
Sector s = level.sector;
float xpan, ypan, xscale, yscale, rotate;
Vector2D texscale;
base.Setup(level);
try
{
// Fetch ZDoom fields

View file

@ -80,7 +80,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
}
// Load sector data
SectorData sd = Sector.Data;
SectorData sd = Sector.GetSectorData();
SectorData osd = mode.GetSectorData(Sidedef.Other.Sector);
if(!osd.Updated) osd.Update();
@ -173,7 +173,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
bottom = sd.Floor.plane;
// Process the polygon and create vertices
List<WorldVertex> verts = CreatePolygonVertices(poly, tp);
List<WorldVertex> verts = CreatePolygonVertices(poly, tp, sd);
if(verts.Count > 0)
{
base.SetVertices(verts);

View file

@ -58,20 +58,20 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Setup
// Constructor
public VisualMiddle3D(BaseVisualMode mode, VisualSector vs, Sidedef s, Effect3DFloor extrafloor)
: base(mode, vs, s)
public VisualMiddle3D(BaseVisualMode mode, VisualSector vs, Sidedef s) : base(mode, vs, s)
{
this.extrafloor = extrafloor;
// We have no destructor
GC.SuppressFinalize(this);
}
// This builds the geometry. Returns false when no geometry created.
public override bool Setup()
public override bool Setup() { return this.Setup(this.extrafloor); }
public bool Setup(Effect3DFloor extrafloor)
{
Vector2D vl, vr;
Sidedef sourceside = extrafloor.Linedef.Front;
this.extrafloor = extrafloor;
// Left and right vertices for this sidedef
if(Sidedef.IsFront)
@ -184,7 +184,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
CropPoly(ref poly, extrafloor.Ceiling.plane, false);
// Process the polygon and create vertices
List<WorldVertex> verts = CreatePolygonVertices(poly, tp);
List<WorldVertex> verts = CreatePolygonVertices(poly, tp, sd);
if(verts.Count > 0)
{
if(extrafloor.Alpha < 255)

View file

@ -222,7 +222,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
bottom = osd.Floor.plane;
// Process the polygon and create vertices
List<WorldVertex> verts = CreatePolygonVertices(poly, tp);
List<WorldVertex> verts = CreatePolygonVertices(poly, tp, sd);
if(verts.Count > 0)
{
// Apply alpha to vertices

View file

@ -174,7 +174,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
poly.color = wallcolor.WithAlpha(255).ToInt();
// Process the polygon and create vertices
List<WorldVertex> verts = CreatePolygonVertices(poly, tp);
List<WorldVertex> verts = CreatePolygonVertices(poly, tp, sd);
if(verts.Count > 0)
{
base.SetVertices(verts);

View file

@ -43,10 +43,10 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
public VisualLower lower;
public VisualMiddleDouble middledouble;
public VisualMiddleSingle middlesingle;
public Dictionary<Effect3DFloor, VisualMiddle3D> middle3d;
public List<VisualMiddle3D> middle3d;
// Constructor
public VisualSidedefParts(VisualUpper u, VisualLower l, VisualMiddleDouble m, Dictionary<Effect3DFloor, VisualMiddle3D> e)
public VisualSidedefParts(VisualUpper u, VisualLower l, VisualMiddleDouble m, List<VisualMiddle3D> e)
{
this.upper = u;
this.lower = l;
@ -74,7 +74,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
if(upper != null) upper.Setup();
if(middle3d != null)
{
foreach(VisualMiddle3D m in middle3d.Values)
foreach(VisualMiddle3D m in middle3d)
m.Setup();
}
}

View file

@ -81,7 +81,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
}
// Load sector data
SectorData sd = Sector.Data;
SectorData sd = Sector.GetSectorData();
SectorData osd = mode.GetSectorData(Sidedef.Other.Sector);
if(!osd.Updated) osd.Update();
@ -173,7 +173,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
bottom = osd.Ceiling.plane;
// Process the polygon and create vertices
List<WorldVertex> verts = CreatePolygonVertices(poly, tp);
List<WorldVertex> verts = CreatePolygonVertices(poly, tp, sd);
if(verts.Count > 0)
{
base.SetVertices(verts);

Binary file not shown.