From 6c68a5635ec9310e938e5b5f4e57b452ee993c28 Mon Sep 17 00:00:00 2001 From: codeimp Date: Thu, 16 Sep 2010 17:07:30 +0000 Subject: [PATCH] @ Fixed immediate update of target sector lighting when control sector of ExtraFloor_LightOnly effect is changed. Fixed some inaccuracy problems with the Edit Selection mode. --- .../ClassicModes/EditSelectionMode.cs | 103 ++++++++++++++++-- .../VisualModes/BaseVisualGeometrySidedef.cs | 2 +- .../VisualModes/EffectBrightnessLevel.cs | 2 +- 3 files changed, 96 insertions(+), 11 deletions(-) diff --git a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs index 922a9122..de93d890 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs @@ -612,6 +612,42 @@ namespace CodeImp.DoomBuilder.BuilderModes return p; } + + // This applies the current rotation and resize to a point + private Vector2D TransformedPointNoScale(Vector2D p) + { + // Rotate + Vector2D center = baseoffset + size * 0.5f; + Vector2D po = p - center; + p = po.GetRotated(rotation); + p += center; + + // Translate + p += offset - baseoffset; + + return p; + } + + // This applies the current rotation and resize to a point + private Vector2D TransformedPointNoRotate(Vector2D p) + { + // Resize + p = (p - baseoffset) * (size / basesize) + baseoffset; + + // Translate + p += offset - baseoffset; + + return p; + } + + // This applies the current rotation and resize to a point + private Vector2D TransformedPointNoRotateNoScale(Vector2D p) + { + // Translate + p += offset - baseoffset; + + return p; + } // This checks if a point is in a rect private bool PointInRectF(RectangleF rect, Vector2D point) @@ -630,17 +666,66 @@ namespace CodeImp.DoomBuilder.BuilderModes // This moves all things and vertices to match the current transformation private void UpdateGeometry() { - int index = 0; - foreach(Vertex v in selectedvertices) - { - v.Move(TransformedPoint(vertexpos[index++])); - } - index = 0; - foreach(Thing t in selectedthings) + // We use optimized versions of the TransformedPoint depending on what needs to be done. + // This is mainly done because 0.0 rotation and 1.0 scale may still give slight inaccuracies. + bool norotate = Math.Abs(rotation) < 0.0001f; + bool noscale = Math.Abs(size.x - basesize.x) + Math.Abs(size.y - basesize.y) < 0.0001f; + if(norotate && noscale) { - t.Rotate(Angle2D.Normalized(thingangle[index] + rotation)); - t.Move(TransformedPoint(thingpos[index++])); + int index = 0; + foreach(Vertex v in selectedvertices) + { + v.Move(TransformedPointNoRotateNoScale(vertexpos[index++])); + } + index = 0; + foreach(Thing t in selectedthings) + { + t.Rotate(Angle2D.Normalized(thingangle[index] + rotation)); + t.Move(TransformedPointNoRotateNoScale(thingpos[index++])); + } + } + else if(norotate) + { + int index = 0; + foreach(Vertex v in selectedvertices) + { + v.Move(TransformedPointNoRotate(vertexpos[index++])); + } + index = 0; + foreach(Thing t in selectedthings) + { + t.Rotate(Angle2D.Normalized(thingangle[index] + rotation)); + t.Move(TransformedPointNoRotate(thingpos[index++])); + } + } + else if(noscale) + { + int index = 0; + foreach(Vertex v in selectedvertices) + { + v.Move(TransformedPointNoScale(vertexpos[index++])); + } + index = 0; + foreach(Thing t in selectedthings) + { + t.Rotate(Angle2D.Normalized(thingangle[index] + rotation)); + t.Move(TransformedPointNoScale(thingpos[index++])); + } + } + else + { + int index = 0; + foreach(Vertex v in selectedvertices) + { + v.Move(TransformedPoint(vertexpos[index++])); + } + index = 0; + foreach(Thing t in selectedthings) + { + t.Rotate(Angle2D.Normalized(thingangle[index] + rotation)); + t.Move(TransformedPoint(thingpos[index++])); + } } // This checks if the lines should be flipped diff --git a/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualGeometrySidedef.cs b/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualGeometrySidedef.cs index 7b25ae0f..2f3ab078 100644 --- a/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualGeometrySidedef.cs @@ -901,7 +901,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing Sector.Sector.UpdateCache(); // Rebuild sector - Sector.Changed = true; + Sector.UpdateSectorGeometry(false); // Go for all things in this sector foreach(Thing t in General.Map.Map.Things) diff --git a/Source/Plugins/GZDoomEditing/VisualModes/EffectBrightnessLevel.cs b/Source/Plugins/GZDoomEditing/VisualModes/EffectBrightnessLevel.cs index 092f7228..56a3f3ee 100644 --- a/Source/Plugins/GZDoomEditing/VisualModes/EffectBrightnessLevel.cs +++ b/Source/Plugins/GZDoomEditing/VisualModes/EffectBrightnessLevel.cs @@ -40,7 +40,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing { SectorData sd = data.Mode.GetSectorData(linedef.Front.Sector); if(!sd.Updated) sd.Update(); - data.AddUpdateSector(linedef.Front.Sector, false); + sd.AddUpdateSector(data.Sector, false); if(level == null) {