From bbfb569d0f62b72e75930b9efae3f17029815726 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Sat, 2 Jan 2016 14:21:15 +0100 Subject: [PATCH] Vertex slopes are now rendered in Visual Mode. --- Source/Core/Config/GameConfiguration.cs | 3 + Source/Core/General/MapManager.cs | 1 + Source/Core/IO/DoomMapSetIO.cs | 4 + Source/Core/IO/HexenMapSetIO.cs | 4 + Source/Core/IO/IMapSetIO.cs | 2 + Source/Core/IO/MapSetIO.cs | 2 + Source/Core/IO/SRB2MapSetIO.cs | 11 + Source/Core/IO/UniversalMapSetIO.cs | 4 + Source/Core/Map/Linedef.cs | 13 +- Source/Core/Map/Thing.cs | 10 +- .../Plugins/BuilderModes/BuilderModes.csproj | 3 +- .../VisualModes/BaseVisualMode.cs | 230 +++++++++++------- .../VisualModes/EffectSRB2ThingVertexSlope.cs | 55 +++++ .../BuilderModes/VisualModes/SectorData.cs | 11 +- 14 files changed, 259 insertions(+), 94 deletions(-) create mode 100644 Source/Plugins/BuilderModes/VisualModes/EffectSRB2ThingVertexSlope.cs diff --git a/Source/Core/Config/GameConfiguration.cs b/Source/Core/Config/GameConfiguration.cs index dba4563..ccb18d5 100644 --- a/Source/Core/Config/GameConfiguration.cs +++ b/Source/Core/Config/GameConfiguration.cs @@ -97,6 +97,7 @@ namespace CodeImp.DoomBuilder.Config private readonly bool doommapformat; private readonly bool hexenmapformat; private readonly bool universalmapformat; + private readonly bool srb2mapformat; // Texture/flat/voxel sources private readonly IDictionary textureranges; @@ -213,6 +214,7 @@ namespace CodeImp.DoomBuilder.Config public bool UDMF { get { return universalmapformat; } } public bool HEXEN { get { return hexenmapformat; } } public bool DOOM { get { return doommapformat; } } + public bool SRB2 { get { return srb2mapformat; } } // Texture/flat/voxel sources public IDictionary TextureRanges { get { return textureranges; } } @@ -354,6 +356,7 @@ namespace CodeImp.DoomBuilder.Config universalmapformat = (formatinterface == "UniversalMapSetIO"); hexenmapformat = (formatinterface == "HexenMapSetIO"); doommapformat = (formatinterface == "DoomMapSetIO"); + srb2mapformat = (formatinterface == "SRB2MapSetIO"); //mxd. Texture names length longtexturenames = cfg.ReadSetting("longtexturenames", false); diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index 48000a5..95f7790 100644 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -126,6 +126,7 @@ namespace CodeImp.DoomBuilder public bool UDMF { get { return config.UDMF; } } public bool HEXEN { get { return config.HEXEN; } } public bool DOOM { get { return config.DOOM; } } + public bool SRB2 { get { return config.SRB2; } } //mxd. Scripts internal Dictionary NamedScripts { get { return namedscripts; } } diff --git a/Source/Core/IO/DoomMapSetIO.cs b/Source/Core/IO/DoomMapSetIO.cs index 4cc7ad5..c0f0949 100644 --- a/Source/Core/IO/DoomMapSetIO.cs +++ b/Source/Core/IO/DoomMapSetIO.cs @@ -38,6 +38,7 @@ namespace CodeImp.DoomBuilder.IO protected Dictionary threeDFloorTypes; protected Dictionary slopeTypes; protected Dictionary slopeCopyTypes; + protected Dictionary vertexSlopeTypes; #endregion #region ================== Constructor / Disposer @@ -48,6 +49,7 @@ namespace CodeImp.DoomBuilder.IO threeDFloorTypes = new Dictionary() { { 160, new int[3] { -1, -1, -1 } } }; slopeTypes = new Dictionary() { { 181, new int[2] { -1, -1 } } }; slopeCopyTypes = new Dictionary() { { 118, new int[2] { -1, -1 } } }; + vertexSlopeTypes = new Dictionary() { }; } #endregion @@ -99,6 +101,8 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary ThreeDFloorTypes { get { return threeDFloorTypes; } } public override Dictionary SlopeTypes { get { return slopeTypes; } } public override Dictionary SlopeCopyTypes { get { return slopeCopyTypes; } } + public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } + public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } #endregion diff --git a/Source/Core/IO/HexenMapSetIO.cs b/Source/Core/IO/HexenMapSetIO.cs index cc352e4..8660cbd 100644 --- a/Source/Core/IO/HexenMapSetIO.cs +++ b/Source/Core/IO/HexenMapSetIO.cs @@ -38,6 +38,7 @@ namespace CodeImp.DoomBuilder.IO protected Dictionary threeDFloorTypes; protected Dictionary slopeTypes; protected Dictionary slopeCopyTypes; + protected Dictionary vertexSlopeTypes; #endregion #region ================== Constructor / Disposer @@ -48,6 +49,7 @@ namespace CodeImp.DoomBuilder.IO threeDFloorTypes = new Dictionary() { { 160, new int[3] { -1, -1, -1 } } }; slopeTypes = new Dictionary() { { 181, new int[2] { -1, -1 } } }; slopeCopyTypes = new Dictionary() { { 118, new int[2] { -1, -1 } } }; + vertexSlopeTypes = new Dictionary() { }; } #endregion @@ -99,6 +101,8 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary ThreeDFloorTypes { get { return threeDFloorTypes; } } public override Dictionary SlopeTypes { get { return slopeTypes; } } public override Dictionary SlopeCopyTypes { get { return slopeCopyTypes; } } + public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } + public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } #endregion diff --git a/Source/Core/IO/IMapSetIO.cs b/Source/Core/IO/IMapSetIO.cs index 3ad3a5c..c6c9a35 100644 --- a/Source/Core/IO/IMapSetIO.cs +++ b/Source/Core/IO/IMapSetIO.cs @@ -73,6 +73,8 @@ namespace CodeImp.DoomBuilder.IO Dictionary ThreeDFloorTypes { get; } Dictionary SlopeTypes { get; } Dictionary SlopeCopyTypes { get; } + Dictionary VertexSlopeTypes { get; } + int SlopeVertexType { get; } int Custom3DFloorType { get; } } } diff --git a/Source/Core/IO/MapSetIO.cs b/Source/Core/IO/MapSetIO.cs index edd97b8..5d2e783 100644 --- a/Source/Core/IO/MapSetIO.cs +++ b/Source/Core/IO/MapSetIO.cs @@ -94,6 +94,8 @@ namespace CodeImp.DoomBuilder.IO public abstract Dictionary ThreeDFloorTypes { get; } public abstract Dictionary SlopeTypes { get; } public abstract Dictionary SlopeCopyTypes { get; } + public abstract Dictionary VertexSlopeTypes { get; } + public abstract int SlopeVertexType { get; } public abstract int Custom3DFloorType { get; } #endregion diff --git a/Source/Core/IO/SRB2MapSetIO.cs b/Source/Core/IO/SRB2MapSetIO.cs index a9126e8..c330bce 100644 --- a/Source/Core/IO/SRB2MapSetIO.cs +++ b/Source/Core/IO/SRB2MapSetIO.cs @@ -120,6 +120,16 @@ namespace CodeImp.DoomBuilder.IO { 721, new int[2] { 0, 1 } }, { 722, new int[2] { 1, 1 } }, }; + + //Dictionary contents: + //1. 0 = slope front, 1 = slope back + //2. 0 = slope floor, 1 = slope ceiling + vertexSlopeTypes = new Dictionary() { + { 704, new int[2] { 0, 0 } }, + { 705, new int[2] { 0, 1 } }, + { 714, new int[2] { 1, 0 } }, + { 715, new int[2] { 1, 1 } }, + }; } #endregion @@ -129,6 +139,7 @@ namespace CodeImp.DoomBuilder.IO public override bool HasLinedefParameters { get { return false; } } public override bool HasTranslucent3DFloors { get { return true; } } public override int Custom3DFloorType { get { return 259; } } + public override int SlopeVertexType { get { return 750; } } public override int MaxThingHeight { get { return 4095; } } public override int MinThingHeight { get { return 0; } } #endregion diff --git a/Source/Core/IO/UniversalMapSetIO.cs b/Source/Core/IO/UniversalMapSetIO.cs index c8d2e34..3391287 100644 --- a/Source/Core/IO/UniversalMapSetIO.cs +++ b/Source/Core/IO/UniversalMapSetIO.cs @@ -41,6 +41,7 @@ namespace CodeImp.DoomBuilder.IO protected Dictionary threeDFloorTypes; protected Dictionary slopeTypes; protected Dictionary slopeCopyTypes; + protected Dictionary vertexSlopeTypes; #endregion #region ================== Constructor / Disposer @@ -53,6 +54,7 @@ namespace CodeImp.DoomBuilder.IO threeDFloorTypes = new Dictionary() { { 160, new int[3] { -1, -1, -1 } } }; slopeTypes = new Dictionary() { { 181, new int[2] { -1, -1 } } }; slopeCopyTypes = new Dictionary() { { 118, new int[2] { -1, -1 } } }; + vertexSlopeTypes = new Dictionary() { }; // Make configuration Configuration config = new Configuration(); @@ -149,6 +151,8 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary ThreeDFloorTypes { get { return threeDFloorTypes; } } public override Dictionary SlopeTypes { get { return slopeTypes; } } public override Dictionary SlopeCopyTypes { get { return slopeCopyTypes; } } + public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } + public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } #endregion diff --git a/Source/Core/Map/Linedef.cs b/Source/Core/Map/Linedef.cs index 0afba22..00ba08e 100644 --- a/Source/Core/Map/Linedef.cs +++ b/Source/Core/Map/Linedef.cs @@ -94,6 +94,7 @@ namespace CodeImp.DoomBuilder.Map public bool Is3DFloor { get { return General.Map.FormatInterface.ThreeDFloorTypes.ContainsKey(Action); } } public bool IsSlope { get { return General.Map.FormatInterface.SlopeTypes.ContainsKey(Action); } } public bool IsSlopeCopy { get { return General.Map.FormatInterface.SlopeCopyTypes.ContainsKey(Action); } } + public bool IsVertexSlope { get { return General.Map.FormatInterface.VertexSlopeTypes.ContainsKey(Action); } } public int Tag { get { return tags[0]; } set { BeforePropsChange(); tags[0] = value; if((value < General.Map.FormatInterface.MinTag) || (value > General.Map.FormatInterface.MaxTag)) throw new ArgumentOutOfRangeException("Tag", "Invalid tag number"); } } //mxd public List Tags { get { return tags; } set { BeforePropsChange(); tags = value; } } //mxd public float LengthSq { get { return lengthsq; } } @@ -801,7 +802,7 @@ namespace CodeImp.DoomBuilder.Map //Read settings for preconfigured 3D floor type int[] settings = General.Map.FormatInterface.ThreeDFloorTypes[Action]; Args[1] = settings[0]; - Args[2] = Flags.ContainsKey("64") && Flags["64"] ? settings[3] : settings[1]; //Flags may depend on whether the noclimb flag is set + Args[2] = IsFlagSet("64") ? settings[3] : settings[1]; //Flags may depend on whether the noclimb flag is set switch (settings[2]) { case 0: @@ -864,6 +865,16 @@ namespace CodeImp.DoomBuilder.Map Args[4] = 0; //share (irrelevant for SRB2) } + //Set slope arguments for SRB2-style vertex slopes. These are fake arguments I invented to make their handling easier. + //Args[0]: 0 = slope front sector, 1 = slope back sector + //Args[1]: 0 = slope floor, 1 = slope ceiling + public void SetVertexSlopeArgs() + { + int[] settings = General.Map.FormatInterface.VertexSlopeTypes[Action]; + Args[0] = settings[0]; + Args[1] = settings[1]; + } + // This checks and returns a flag without creating it public bool IsFlagSet(string flagname) { diff --git a/Source/Core/Map/Thing.cs b/Source/Core/Map/Thing.cs index fc76188..5e2956c 100644 --- a/Source/Core/Map/Thing.cs +++ b/Source/Core/Map/Thing.cs @@ -119,13 +119,15 @@ namespace CodeImp.DoomBuilder.Map public bool IsModel { get { return ismodel; } } //mxd public bool IsDirectional { get { return directional; } } //mxd public bool Highlighted { get { return highlighted; } set { highlighted = value; } } //mxd + public bool IsSlopeVertex { get { return General.Map.FormatInterface.SlopeVertexType == this.Type; } } - #endregion - #region ================== Constructor / Disposer + #endregion - // Constructor - internal Thing(MapSet map, int listindex) + #region ================== Constructor / Disposer + + // Constructor + internal Thing(MapSet map, int listindex) { // Initialize this.elementtype = MapElementType.THING; //mxd diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj index 1d24919..2a832b6 100644 --- a/Source/Plugins/BuilderModes/BuilderModes.csproj +++ b/Source/Plugins/BuilderModes/BuilderModes.csproj @@ -415,6 +415,7 @@ + @@ -509,7 +510,7 @@ WavefrontSettingsForm.cs - + diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index ec0ee48..5647a4b 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -833,57 +833,60 @@ namespace CodeImp.DoomBuilder.BuilderModes } } - // Find sectors with 3 vertices, because they can be sloped - foreach(Sector s in General.Map.Map.Sectors) - { - // ========== Thing vertex slope, vertices with UDMF vertex offsets ========== - if(s.Sidedefs.Count == 3) - { - if(General.Map.UDMF) GetSectorData(s).AddEffectVertexOffset(); //mxd - List slopeceilingthings = new List(3); - List slopefloorthings = new List(3); - - foreach(Sidedef sd in s.Sidedefs) - { - Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start; + if (!General.Map.SRB2) + { + // Find sectors with 3 vertices, because they can be sloped + foreach (Sector s in General.Map.Map.Sectors) + { + // ========== Thing vertex slope, vertices with UDMF vertex offsets ========== + if (s.Sidedefs.Count == 3) + { + if (General.Map.UDMF) GetSectorData(s).AddEffectVertexOffset(); //mxd + List slopeceilingthings = new List(3); + List slopefloorthings = new List(3); - // 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) - { - switch(t.Type) - { - //case 1504: slopefloorthings.Add(t); break; - //case 1505: slopeceilingthings.Add(t); break; - } - } - } - } + foreach (Sidedef sd in s.Sidedefs) + { + Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start; - // Slope any floor vertices? - if(slopefloorthings.Count > 0) - { - SectorData sd = GetSectorData(s); - sd.AddEffectThingVertexSlope(slopefloorthings, true); - } + // 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) + { + switch (t.Type) + { + case 1504: slopefloorthings.Add(t); break; + case 1505: slopeceilingthings.Add(t); break; + } + } + } + } - // Slope any ceiling vertices? - if(slopeceilingthings.Count > 0) - { - SectorData sd = GetSectorData(s); - sd.AddEffectThingVertexSlope(slopeceilingthings, false); - } - } - - // ========== mxd. Glowing flats ========== - if(General.Map.Data.GlowingFlats.ContainsKey(s.LongFloorTexture) || General.Map.Data.GlowingFlats.ContainsKey(s.LongCeilTexture)) - { - SectorData sd = GetSectorData(s); - sd.AddEffectGlowingFlat(s); - } - } + // 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); + } + } + + // ========== mxd. Glowing flats ========== + if (General.Map.Data.GlowingFlats.ContainsKey(s.LongFloorTexture) || General.Map.Data.GlowingFlats.ContainsKey(s.LongCeilTexture)) + { + SectorData sd = GetSectorData(s); + sd.AddEffectGlowingFlat(s); + } + } + } // Find interesting linedefs (such as line slopes) foreach (Linedef l in General.Map.Map.Linedefs) @@ -945,6 +948,58 @@ namespace CodeImp.DoomBuilder.BuilderModes } } + // MascaraSnake: Vertex slopes, SRB2-style + if (General.Map.SRB2 && l.IsVertexSlope) + { + l.SetVertexSlopeArgs(); + bool slopefloor = l.Args[1] == 0; + List slopevertices = new List(3); + Sector s = (l.Args[0] == 0) ? l.Front.Sector : l.Back.Sector; + + //If NOKNUCKLES is set, use tag, X offset and Y offset to search for slope vertices. + if (l.IsFlagSet("8192")) + { + bool foundtag = false; + bool foundxoffset = false; + bool foundyoffset = false; + foreach (Thing t in General.Map.Map.Things) + { + if (t.IsSlopeVertex) + { + if (!foundtag && (int)t.AngleDoom == l.Tag) + { + slopevertices.Add(t); + foundtag = true; + } + if (!foundxoffset && (int)t.AngleDoom == l.Front.OffsetX) + { + slopevertices.Add(t); + foundxoffset = true; + } + if (!foundyoffset && (int)t.AngleDoom == l.Front.OffsetY) + { + slopevertices.Add(t); + foundyoffset = true; + } + } + } + + } + //Otherwise, just use tag. + else + { + foreach (Thing t in General.Map.Map.Things) + { + if (t.IsSlopeVertex && (int)t.AngleDoom == l.Tag) slopevertices.Add(t); + } + } + if (slopevertices.Count >= 3) + { + SectorData sd = GetSectorData(s); + sd.AddEffectSRB2ThingVertexSlope(slopevertices, slopefloor); + } + } + // MascaraSnake: 3D floor handling // ========== Sector 3D floor (see http://zdoom.org/wiki/Sector_Set3dFloor) ========== if (l.Is3DFloor) @@ -966,7 +1021,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } } - if (General.Map.FormatInterface.HasLinedefParameters) + if (!General.Map.SRB2) { switch (l.Action) { @@ -1012,45 +1067,48 @@ namespace CodeImp.DoomBuilder.BuilderModes } } - // Find interesting things (such as sector slopes) - foreach(Thing t in General.Map.Map.Things) - { - switch(t.Type) - { - // ========== Copy slope ========== - case 9511: - case 9510: - t.DetermineSector(blockmap); - if(t.Sector != null) - { - SectorData sd = GetSectorData(t.Sector); - sd.AddEffectCopySlope(t); - } - break; + if (!General.Map.SRB2) + { + // Find interesting things (such as sector slopes) + foreach (Thing t in General.Map.Map.Things) + { + switch (t.Type) + { + // ========== Copy slope ========== + case 9511: + case 9510: + t.DetermineSector(blockmap); + if (t.Sector != null) + { + SectorData sd = GetSectorData(t.Sector); + sd.AddEffectCopySlope(t); + } + break; - // ========== Thing line slope ========== - case 9501: - case 9500: - t.DetermineSector(blockmap); - if(t.Sector != null) - { - SectorData sd = GetSectorData(t.Sector); - sd.AddEffectThingLineSlope(t); - } - break; + // ========== Thing line slope ========== + case 9501: + case 9500: + t.DetermineSector(blockmap); + if (t.Sector != null) + { + SectorData sd = GetSectorData(t.Sector); + sd.AddEffectThingLineSlope(t); + } + break; - // ========== Thing slope ========== - case 9503: - case 9502: - t.DetermineSector(blockmap); - if(t.Sector != null) - { - SectorData sd = GetSectorData(t.Sector); - sd.AddEffectThingSlope(t); - } - break; - } - } + // ========== Thing slope ========== + case 9503: + case 9502: + t.DetermineSector(blockmap); + if (t.Sector != null) + { + SectorData sd = GetSectorData(t.Sector); + sd.AddEffectThingSlope(t); + } + break; + } + } + } } #endregion diff --git a/Source/Plugins/BuilderModes/VisualModes/EffectSRB2ThingVertexSlope.cs b/Source/Plugins/BuilderModes/VisualModes/EffectSRB2ThingVertexSlope.cs new file mode 100644 index 0000000..ad09784 --- /dev/null +++ b/Source/Plugins/BuilderModes/VisualModes/EffectSRB2ThingVertexSlope.cs @@ -0,0 +1,55 @@ +#region === Copyright (c) 2010 Pascal van der Heiden === + +using System.Collections.Generic; +using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Map; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + internal class EffectSRB2ThingVertexSlope : SectorEffect + { + // Things used to create this effect. + private List things; + + // Floor or ceiling? + private bool slopefloor; + + // Constructor + public EffectSRB2ThingVertexSlope(SectorData data, List 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 (Thing t in things) + { + ThingData td = data.Mode.GetThingData(t); + td.AddUpdateSector(data.Sector, true); + verts[index] = t.Position; + index++; + if (index > 2) break; //Only the first three vertices are used + } + + // 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); + } + } +} diff --git a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs index 92d3c12..360ed6c 100644 --- a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs +++ b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs @@ -174,8 +174,15 @@ namespace CodeImp.DoomBuilder.BuilderModes alleffects.Add(e); } - //mxd. Add UDMF vertex offset effect - public void AddEffectVertexOffset() + // SRB2-style Thing vertex slope effect + public void AddEffectSRB2ThingVertexSlope(List sourcethings, bool slopefloor) + { + EffectSRB2ThingVertexSlope e = new EffectSRB2ThingVertexSlope(this, sourcethings, slopefloor); + alleffects.Add(e); + } + + //mxd. Add UDMF vertex offset effect + public void AddEffectVertexOffset() { EffectUDMFVertexOffset e = new EffectUDMFVertexOffset(this); alleffects.Add(e);