From 1f016fc7dc178366cb8bdae16493162d3103d779 Mon Sep 17 00:00:00 2001 From: codeimp Date: Sat, 10 Jan 2009 00:57:05 +0000 Subject: [PATCH] added wrapping of texture coordinates by texture size when auto-aligning (to prevent ridiculous high offsets on long walls) --- .../VisualModes/BaseVisualGeometrySidedef.cs | 9 +++---- Source/Geometry/Tools.cs | 27 +++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs index 82d4f934..4de444f1 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -206,12 +206,11 @@ namespace CodeImp.DoomBuilder.BuilderModes { General.Map.UndoRedo.CreateUndo("Auto-align textures"); - // Get the texture long name - string texname = GetTextureName(); - long longtexname = General.Map.Data.GetLongImageName(texname); - + // Make sure the texture is loaded (we need the texture size) + if(!base.Texture.IsImageLoaded) base.Texture.LoadImage(); + // Do the alignment - Tools.AutoAlignTextures(this.Sidedef, longtexname, alignx, aligny, true); + Tools.AutoAlignTextures(this.Sidedef, base.Texture, alignx, aligny, true); // Get the changed sidedefs List changes = General.Map.Map.GetMarkedSidedefs(true); diff --git a/Source/Geometry/Tools.cs b/Source/Geometry/Tools.cs index d4bb0088..1cab3aeb 100644 --- a/Source/Geometry/Tools.cs +++ b/Source/Geometry/Tools.cs @@ -27,6 +27,7 @@ using SlimDX.Direct3D9; using System.Drawing; using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Data; #endregion @@ -1231,7 +1232,7 @@ namespace CodeImp.DoomBuilder.Geometry // When resetsidemarks is set to true, all sidedefs will first be marked false (not aligned). // Setting resetsidemarks to false is usefull to align only within a specific selection // (set the marked property to true for the sidedefs outside the selection) - public static void AutoAlignTextures(Sidedef start, long texturelongname, bool alignx, bool aligny, bool resetsidemarks) + public static void AutoAlignTextures(Sidedef start, ImageData texture, bool alignx, bool aligny, bool resetsidemarks) { Stack todo = new Stack(50); @@ -1263,13 +1264,21 @@ namespace CodeImp.DoomBuilder.Geometry int backwardoffset = j.offsetx; j.sidedef.Marked = true; + // Wrap the value within the width of the texture (to prevent ridiculous values) + // NOTE: We don't use ScaledWidth here because the texture offset is in pixels, not mappixels + if(texture.IsImageLoaded) + { + j.sidedef.OffsetX %= texture.Width; + j.sidedef.OffsetY %= texture.Height; + } + // Add sidedefs forward (connected to the right vertex) v = j.sidedef.IsFront ? j.sidedef.Line.End : j.sidedef.Line.Start; - AddSidedefsForAlignment(todo, v, true, forwardoffset, j.offsety, texturelongname); + AddSidedefsForAlignment(todo, v, true, forwardoffset, j.offsety, texture.LongName); // Add sidedefs backward (connected to the left vertex) v = j.sidedef.IsFront ? j.sidedef.Line.Start : j.sidedef.Line.End; - AddSidedefsForAlignment(todo, v, false, backwardoffset, j.offsety, texturelongname); + AddSidedefsForAlignment(todo, v, false, backwardoffset, j.offsety, texture.LongName); } else { @@ -1282,13 +1291,21 @@ namespace CodeImp.DoomBuilder.Geometry int backwardoffset = j.offsetx - (int)Math.Round(j.sidedef.Line.Length); j.sidedef.Marked = true; + // Wrap the value within the width of the texture (to prevent ridiculous values) + // NOTE: We don't use ScaledWidth here because the texture offset is in pixels, not mappixels + if(texture.IsImageLoaded) + { + j.sidedef.OffsetX %= texture.Width; + j.sidedef.OffsetY %= texture.Height; + } + // Add sidedefs backward (connected to the left vertex) v = j.sidedef.IsFront ? j.sidedef.Line.Start : j.sidedef.Line.End; - AddSidedefsForAlignment(todo, v, false, backwardoffset, j.offsety, texturelongname); + AddSidedefsForAlignment(todo, v, false, backwardoffset, j.offsety, texture.LongName); // Add sidedefs forward (connected to the right vertex) v = j.sidedef.IsFront ? j.sidedef.Line.End : j.sidedef.Line.Start; - AddSidedefsForAlignment(todo, v, true, forwardoffset, j.offsety, texturelongname); + AddSidedefsForAlignment(todo, v, true, forwardoffset, j.offsety, texture.LongName); } } }