From d888e57c76c7927ff79014919ea72bb950b8b403 Mon Sep 17 00:00:00 2001 From: MaxED Date: Thu, 21 Apr 2016 21:00:58 +0000 Subject: [PATCH] Added, Draw Lines mode: additional guidelines and horizontal/vertical line lengths can now be displayed for currently drawn line using "Show guidelines" top menu button. Changed, Draw Lines mode: line angles are now shown only when "Show guidelines" mode is enabled. Fixed, Draw Lines mode: in some cases "Snap to cardinal directions" mode was snapping only to diagonals. Fixed, Draw Lines mode: snap to geometry behaved incorrectly when "Snap to cardinal directions" mode was enabled. Changed, Things mode: dynamic light shape is now drawn using highlight color when a dynamic light thing is highlighted. Added more sanity checks to MODELDEFS parser. --- .../Core/GZBuilder/GZDoom/ModeldefParser.cs | 19 +- .../GZBuilder/GZDoom/ModeldefStructure.cs | 16 +- Source/Core/Geometry/Line2D.cs | 42 +++- Source/Core/Geometry/Tools.cs | 86 -------- .../Plugins/BuilderModes/BuilderModes.csproj | 3 + .../BuilderModes/ClassicModes/BridgeMode.cs | 2 +- .../ClassicModes/DrawGeometryMode.cs | 201 ++++++++++++++---- .../BuilderModes/ClassicModes/DrawGridMode.cs | 4 +- .../BuilderModes/ClassicModes/LinedefsMode.cs | 6 +- .../BuilderModes/ClassicModes/SectorsMode.cs | 4 +- .../BuilderModes/ClassicModes/ThingsMode.cs | 100 ++++++++- .../BuilderModes/ClassicModes/VerticesMode.cs | 2 +- .../DrawLineOptionsPanel.Designer.cs | 20 +- .../Interface/DrawLineOptionsPanel.cs | 9 + .../Properties/Resources.Designer.cs | 7 + .../BuilderModes/Properties/Resources.resx | 25 ++- .../BuilderModes/Resources/Guidelines.png | Bin 0 -> 1101 bytes Source/Plugins/NodesViewer/NodesViewerMode.cs | 4 +- 18 files changed, 389 insertions(+), 161 deletions(-) create mode 100644 Source/Plugins/BuilderModes/Resources/Guidelines.png diff --git a/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs b/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs index 3e70094b..aa954256 100644 --- a/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs +++ b/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs @@ -109,6 +109,13 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom // Add models foreach(var fs in mds.Frames[targetsprite]) { + // Sanity checks + if(string.IsNullOrEmpty(mds.ModelNames[fs.ModelIndex])) + { + LogWarning("Model definition \"" + classname + "\", frame \"" + fs.SpriteName + " " + fs.FrameName + "\" references undefiend model index " + fs.ModelIndex); + continue; + } + // Texture name will be empty when skin path is embedded in the model string texturename = (!string.IsNullOrEmpty(mds.TextureNames[fs.ModelIndex]) ? mds.TextureNames[fs.ModelIndex].ToLowerInvariant() : string.Empty); @@ -118,8 +125,16 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom md.FrameIndices.Add(fs.FrameIndex); } - // Add to collection - entries[classname] = md; + // More sanity checks... + if(md.ModelNames.Count == 0) + { + LogWarning("Model definition \"" + classname + "\" has no defined models"); + } + else + { + // Add to collection + entries[classname] = md; + } } } } diff --git a/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs b/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs index 52428707..d232f88d 100644 --- a/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs +++ b/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs @@ -335,12 +335,18 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom parser.SkipWhitespace(true); int fimodelindnex; token = parser.ReadToken(); - if(!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out fimodelindnex) || fimodelindnex < 0) + if(!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out fimodelindnex)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return false; } + if(fimodelindnex < 0 || fimodelindnex > MAX_MODELS - 1) + { + // Out of bounds + parser.ReportError("Model index must be in [0.." + (MAX_MODELS - 1) + "] range"); + return false; + } // Frame number parser.SkipWhitespace(true); @@ -407,12 +413,18 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom parser.SkipWhitespace(true); int modelindnex; token = parser.ReadToken(); - if(!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out modelindnex) || modelindnex < 0) + if(!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out modelindnex)) { // Not numeric! parser.ReportError("Expected model index, but got \"" + token + "\""); return false; } + if(modelindnex < 0 || modelindnex > MAX_MODELS - 1) + { + // Out of bounds + parser.ReportError("Model index must be in [0.." + (MAX_MODELS - 1) + "] range"); + return false; + } // Frame name parser.SkipWhitespace(true); diff --git a/Source/Core/Geometry/Line2D.cs b/Source/Core/Geometry/Line2D.cs index 934dad6e..5a8f6e0c 100644 --- a/Source/Core/Geometry/Line2D.cs +++ b/Source/Core/Geometry/Line2D.cs @@ -107,11 +107,35 @@ namespace CodeImp.DoomBuilder.Geometry public static bool GetIntersection(Vector2D v1, Vector2D v2, float x3, float y3, float x4, float y4, out float u_ray) { float u_line; - return GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, out u_line); + return GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, out u_line, true); + } + + //mxd. This tests if the line intersects with the given line coordinates + public static bool GetIntersection(Vector2D v1, Vector2D v2, float x3, float y3, float x4, float y4, out float u_ray, bool bounded) + { + float u_line; + return GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, out u_line, bounded); + } + + //mxd. Gets intersection point between given lines + public static Vector2D GetIntersectionPoint(Line2D line1, Line2D line2, bool bounded) + { + float u_ray, u_line; + if(GetIntersection(line1.v1, line1.v2, line2.v1.x, line2.v1.y, line2.v2.x, line2.v2.y, out u_ray, out u_line, bounded)) + return GetCoordinatesAt(line2.v1, line2.v2, u_ray); + + // No dice... + return new Vector2D(float.NaN, float.NaN); } // This tests if the line intersects with the given line coordinates public static bool GetIntersection(Vector2D v1, Vector2D v2, float x3, float y3, float x4, float y4, out float u_ray, out float u_line) + { + return GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, out u_line, true); + } + + // This tests if the line intersects with the given line coordinates + public static bool GetIntersection(Vector2D v1, Vector2D v2, float x3, float y3, float x4, float y4, out float u_ray, out float u_line, bool bounded) { // Calculate divider float div = (y4 - y3) * (v2.x - v1.x) - (x4 - x3) * (v2.y - v1.y); @@ -126,7 +150,7 @@ namespace CodeImp.DoomBuilder.Geometry u_ray = ((v2.x - v1.x) * (v1.y - y3) - (v2.y - v1.y) * (v1.x - x3)) / div; // Return if intersecting - if(u_ray < 0.0f || u_ray > 1.0f || u_line < 0.0f || u_line > 1.0f) return false; //mxd + if(bounded && (u_ray < 0.0f || u_ray > 1.0f || u_line < 0.0f || u_line > 1.0f)) return false; //mxd return true; } @@ -229,7 +253,12 @@ namespace CodeImp.DoomBuilder.Geometry public bool GetIntersection(float x3, float y3, float x4, float y4, out float u_ray) { - return Line2D.GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray); + return Line2D.GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, true); + } + + public bool GetIntersection(float x3, float y3, float x4, float y4, out float u_ray, bool bounded) + { + return Line2D.GetIntersection(v1, v2, x3, y3, x4, y4, out u_ray, bounded); } public bool GetIntersection(float x3, float y3, float x4, float y4, out float u_ray, out float u_line) @@ -244,7 +273,12 @@ namespace CodeImp.DoomBuilder.Geometry public bool GetIntersection(Line2D ray, out float u_ray) { - return Line2D.GetIntersection(v1, v2, ray.v1.x, ray.v1.y, ray.v2.x, ray.v2.y, out u_ray); + return Line2D.GetIntersection(v1, v2, ray.v1.x, ray.v1.y, ray.v2.x, ray.v2.y, out u_ray, true); + } + + public bool GetIntersection(Line2D ray, out float u_ray, bool bounded) + { + return Line2D.GetIntersection(v1, v2, ray.v1.x, ray.v1.y, ray.v2.x, ray.v2.y, out u_ray, bounded); } public bool GetIntersection(Line2D ray, out float u_ray, out float u_line) diff --git a/Source/Core/Geometry/Tools.cs b/Source/Core/Geometry/Tools.cs index bf3b151e..727542fa 100644 --- a/Source/Core/Geometry/Tools.cs +++ b/Source/Core/Geometry/Tools.cs @@ -2155,92 +2155,6 @@ namespace CodeImp.DoomBuilder.Geometry return (int)t.Position.z; } - public static List GetDynamicLightShapes() - { - List circles = new List(); - const int linealpha = 128; - foreach(Thing t in General.Map.Map.Things) - { - int lightid = Array.IndexOf(GZBuilder.GZGeneral.GZ_LIGHTS, t.Type); - if(lightid == -1) continue; - - // TODO: this basically duplicates VisualThing.UpdateLight()... - // Determine light radiii - int primaryradius; - int secondaryradius = 0; - - if(lightid < GZBuilder.GZGeneral.GZ_LIGHT_TYPES[2]) //if it's gzdoom light - { - int n; - if(lightid < GZBuilder.GZGeneral.GZ_LIGHT_TYPES[0]) n = 0; - else if(lightid < GZBuilder.GZGeneral.GZ_LIGHT_TYPES[1]) n = 10; - else n = 20; - DynamicLightType lightType = (DynamicLightType)(t.Type - 9800 - n); - - if(lightType == DynamicLightType.SECTOR) - { - if(t.Sector == null) t.DetermineSector(); - int scaler = (t.Sector != null ? t.Sector.Brightness / 4 : 2); - primaryradius = (int)Math.Round((t.Args[3] * scaler) * General.Settings.GZDynamicLightRadius); - } - else - { - primaryradius = (int)Math.Round((t.Args[3] * 2) * General.Settings.GZDynamicLightRadius); //works... that.. way in GZDoom - if(lightType > 0) - secondaryradius = (int)Math.Round((t.Args[4] * 2) * General.Settings.GZDynamicLightRadius); - } - } - else //it's one of vavoom lights - { - primaryradius = (int)Math.Round((t.Args[0] * 8) * General.Settings.GZDynamicLightRadius); - } - - // Check radii... - if(primaryradius < 1 && secondaryradius < 1) continue; - - // Determine light color - PixelColor color; - switch(t.Type) - { - case 1502: // Vavoom light - color = new PixelColor(linealpha, 255, 255, 255); - break; - - case 1503: // Vavoom colored light - color = new PixelColor(linealpha, (byte)t.Args[1], (byte)t.Args[2], (byte)t.Args[3]); - break; - - default: - color = new PixelColor(linealpha, (byte)t.Args[0], (byte)t.Args[1], (byte)t.Args[2]); - break; - } - - // Add lines if visible - const int numsides = 24; - if(primaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, primaryradius, numsides)); - if(secondaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, secondaryradius, numsides)); - } - - // Done - return circles; - } - - private static IEnumerable MakeCircleLines(Vector2D pos, PixelColor color, float radius, int numsides) - { - List result = new List(numsides); - Vector2D start = new Vector2D(pos.x, pos.y + radius); - float anglestep = Angle2D.PI2 / numsides; - - for(int i = 1; i < numsides + 1; i++) - { - Vector2D end = pos + new Vector2D((float)Math.Sin(anglestep * i) * radius, (float)Math.Cos(anglestep * i) * radius); - result.Add(new Line3D(start, end, color, false)); - start = end; - } - - return result; - } - #endregion #region ================== Linedefs (mxd) diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj index 2afdcfb6..7558bb97 100644 --- a/Source/Plugins/BuilderModes/BuilderModes.csproj +++ b/Source/Plugins/BuilderModes/BuilderModes.csproj @@ -610,6 +610,9 @@ + + +