Display flat alignment in classic (2D) modes.

This commit is contained in:
sphere 2021-03-13 02:16:24 +01:00
parent 25eeb0c9e2
commit a754bf447a
2 changed files with 119 additions and 4 deletions

View file

@ -401,7 +401,20 @@ namespace CodeImp.DoomBuilder.Windows
}
MakeUndo(); //mxd
// Get tagged sectors and old tag (hack for flat alignment)
int oldtag = 0;
Dictionary<int, List<Sector>> sectortags = new Dictionary<int, List<Sector>>();
foreach (Sector s in General.Map.Map.Sectors)
{
foreach (int tag in s.Tags)
{
if (tag == 0) continue;
if (!sectortags.ContainsKey(tag)) sectortags[tag] = new List<Sector>();
sectortags[tag].Add(s);
}
}
// Go for all the lines
int tagoffset = 0; //mxd
foreach(Linedef l in lines)
@ -409,8 +422,9 @@ namespace CodeImp.DoomBuilder.Windows
// Apply chosen activation flag
if(activation.SelectedIndex > -1)
l.Activate = (activation.SelectedItem as LinedefActivateInfo).Index;
// Action/tags
oldtag = l.Tag;
l.Tag = General.Clamp(tagSelector.GetSmartTag(l.Tag, tagoffset++), General.Map.FormatInterface.MinTag, General.Map.FormatInterface.MaxTag); //mxd
if(!action.Empty) l.Action = action.Value;
@ -466,11 +480,45 @@ namespace CodeImp.DoomBuilder.Windows
}
}
}
// (Re)set hacky flat alignment
if (l.IsFlatAlignment || l.Action == 0)
{
if (l.Tag == 0)
{
l.Front.Sector.UpdateFloorSurface();
l.Front.Sector.UpdateCeilingSurface();
if (oldtag != 0 && sectortags.ContainsKey(oldtag))
{
foreach (Sector s in sectortags[oldtag])
{
s.UpdateFloorSurface();
s.UpdateCeilingSurface();
}
}
}
else if (sectortags.ContainsKey(l.Tag))
{
foreach (Sector s in sectortags[l.Tag])
{
s.UpdateFloorSurface();
s.UpdateCeilingSurface();
}
if (oldtag != 0 && sectortags.ContainsKey(oldtag))
{
foreach (Sector s in sectortags[oldtag])
{
s.UpdateFloorSurface();
s.UpdateCeilingSurface();
}
}
}
}
}
// Update the used textures
General.Map.Data.UpdateUsedTextures();
// Done
General.Map.IsChanged = true;
if(OnValuesChanged != null) OnValuesChanged(this, EventArgs.Empty); //mxd
@ -528,7 +576,7 @@ namespace CodeImp.DoomBuilder.Windows
IDictionary<string, string> newFlags = (li == null || li.Flags.Count == 0) ? General.Map.Config.LinedefFlags : li.Flags;
flags.UpdateCheckboxes(newFlags);
}
}
}
// Browse Action clicked
private void browseaction_Click(object sender, EventArgs e)

View file

@ -323,6 +323,27 @@ namespace CodeImp.DoomBuilder.BuilderModes
copiedsectorprops = null;
}
// Full credit to Justburner for the actual math
private void HandleSurfaceFlatAlignment(Linedef l, Sector s, FlatVertex[] vertices, ImageData img)
{
bool useoffsets = l.IsFlagSet("8192");
float xoffset = useoffsets ? l.Front.OffsetX : -l.Start.Position.x;
float yoffset = useoffsets ? -l.Front.OffsetY : -l.Start.Position.y;
float rotation = General.ClampAngle(90f - l.Angle * Angle2D.PIDEG);
// Affine offset, this got me a few headaches of why both rotation and offset didn't worked at same time
float rotationrad = rotation / Angle2D.PIDEG;
float cos = (float)Math.Cos(rotationrad);
float sin = (float)Math.Sin(rotationrad);
float rx = cos * xoffset - sin * yoffset;
float ry = sin * xoffset + cos * yoffset;
xoffset = rx;
yoffset = -ry;
Vector2D offset = new Vector2D(xoffset, yoffset);
SetupSurfaceVertices(vertices, s, img, offset, new Vector2D(1.0f, 1.0f), rotation, -1, 0, false);
}
#endregion
#region ================== Events
@ -375,6 +396,29 @@ namespace CodeImp.DoomBuilder.BuilderModes
vertices[i].u = vertices[i].u * sw;
vertices[i].v = -vertices[i].v * sh;
}
bool sidealignment = false;
foreach (Sidedef side in s.Sidedefs)
{
if (side.Line.IsFlatAlignment && !side.Line.IsFlagSet("2048") && side.Line.Tag == 0 && side.Line.Front.Sector == s)
{
sidealignment = true;
HandleSurfaceFlatAlignment(side.Line, s, vertices, img);
}
}
if (!sidealignment)
{
if (s.Tag != 0)
{
foreach (Linedef l in General.Map.Map.Linedefs)
if (l.IsFlatAlignment && !l.IsFlagSet("2048") && (l.Tag == s.Tag))
HandleSurfaceFlatAlignment(l, s, vertices, img);
}
else
SetupSurfaceVertices(vertices, s, img, new Vector2D(0.0f, 0.0f), new Vector2D(1.0f, 1.0f), 0.0f, -1, 0, false);
}
}
}
}
@ -427,6 +471,29 @@ namespace CodeImp.DoomBuilder.BuilderModes
vertices[i].u = vertices[i].u * sw;
vertices[i].v = -vertices[i].v * sh;
}
bool sidealignment = false;
foreach (Sidedef side in s.Sidedefs)
{
if (side.Line.IsFlatAlignment && !side.Line.IsFlagSet("4096") && side.Line.Tag == 0 && side.Line.Front.Sector == s)
{
sidealignment = true;
HandleSurfaceFlatAlignment(side.Line, s, vertices, img);
}
}
if (!sidealignment)
{
if (s.Tag != 0)
{
foreach (Linedef l in General.Map.Map.Linedefs)
if (l.IsFlatAlignment && !l.IsFlagSet("4096") && (l.Tag == s.Tag))
HandleSurfaceFlatAlignment(l, s, vertices, img);
}
else
SetupSurfaceVertices(vertices, s, img, new Vector2D(0.0f, 0.0f), new Vector2D(1.0f, 1.0f), 0.0f, -1, 0, false);
}
}
}
}