First attempt at rendering polyobject previews.

This commit is contained in:
spherallic 2022-03-05 13:12:25 +01:00
parent 953312482d
commit 2f55a6897a
2 changed files with 388 additions and 244 deletions

View file

@ -68,6 +68,8 @@ namespace CodeImp.DoomBuilder.Rendering
void PlotVerticesSet(ICollection<Vertex> vertices);
void RenderThing(Thing t, PixelColor c, float alpha);
void RenderThingSet(ICollection<Thing> things, float alpha);
void RenderWaypoints();
void RenderPolyobjects();
void RenderNiGHTSPath();
void RenderRectangle(RectangleF rect, float bordersize, PixelColor c, bool transformrect);
void RenderRectangleFilled(RectangleF rect, PixelColor c, bool transformrect);

View file

@ -124,6 +124,21 @@ namespace CodeImp.DoomBuilder.Rendering
// Presentation
private Presentation present;
// SRB2 stuff
private List<Thing> axes;
private List<Thing> axistransferlines;
private List<Thing> waypoints;
private List<Thing> polyanchors;
private List<Thing> polyspawns;
private List<Linedef> firstlines;
private Vector2D[] starts;
private Vector2D[] ends;
private TextLabel waypointlabel;
private TextLabel spawnlabel;
private TextLabel anchorlabel;
#endregion
#region ================== Properties
@ -156,6 +171,39 @@ namespace CodeImp.DoomBuilder.Rendering
// Create rendertargets
CreateRendertargets();
anchorlabel = new TextLabel(3) // create sequence ID label
{
Text = "0",
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.GetNiGHTSColor(8),
Backcolor = General.Colors.Background,
Scale = 16f,
TransformCoords = true
};
spawnlabel = new TextLabel(3) // create sequence ID label
{
Text = "0",
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.GetNiGHTSColor(7),
Backcolor = General.Colors.Background,
Scale = 16f,
TransformCoords = true
};
waypointlabel = new TextLabel(3) // create sequence ID label
{
Text = "0",
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.WaypointColor,
Backcolor = General.Colors.Background,
Scale = 16f,
TransformCoords = true
};
// We have no destructor
GC.SuppressFinalize(this);
}
@ -1435,49 +1483,22 @@ namespace CodeImp.DoomBuilder.Rendering
RenderThingsBatch(things, alpha, false, new PixelColor());
}
public void RenderNiGHTSPath()
{
if (!General.Settings.RenderNiGHTSPath) return;
ICollection<Thing> things = General.Map.Map.Things;
List<Thing> axes = new List<Thing>();
List<Thing> axistransferlines = new List<Thing>();
List<Thing> waypoints = new List<Thing>();
foreach (Thing t in things)
{
int type = t.SRB2Type;
if (type == General.Map.FormatInterface.AxisType) axes.Add(t);
if (type == General.Map.FormatInterface.AxisTransferLineType) axistransferlines.Add(t);
if (type == General.Map.FormatInterface.WaypointType) waypoints.Add(t);
}
//Sort waypoints by angle
waypoints.Sort((x,y) => (x.AngleDoom.CompareTo(y.AngleDoom)));
//Sort by axis number and mare number.
axistransferlines.Sort((x, y) => (x.GetFlagsValue() | (x.Parameter)<<16).CompareTo((y.GetFlagsValue() | (y.Parameter) << 16)));
//Render (zoom tube) waypoint sequences.
public void RenderWaypoints()
{
int i = 0;
int size = waypoints.Count;
int seqStart = 0;
TextLabel[] sequencelabels = new TextLabel[256];
while (i < size)
{
int iNext = i + 1;
if (waypoints[i].AngleDoom % 256 == 0) // start of a new sequence?
{
seqStart = i;
sequencelabels[waypoints[i].AngleDoom / 256] = new TextLabel(3) // create sequence ID label
{
Text = (waypoints[i].AngleDoom / 256).ToString(),
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.WaypointColor,
Backcolor = General.Colors.Background,
Scale = 16f,
TransformCoords = true,
Rectangle = new RectangleF(waypoints[i].Position.x, waypoints[i].Position.y, 0.0f, 0.0f)
};
waypointlabel.Text = (waypoints[i].AngleDoom / 256).ToString();
waypointlabel.Left = waypoints[i].Position.x;
waypointlabel.Top = waypoints[i].Position.y;
RenderText(waypointlabel);
}
if (iNext < size && waypoints[iNext].AngleDoom == waypoints[i].AngleDoom + 1)
{
@ -1502,13 +1523,134 @@ namespace CodeImp.DoomBuilder.Rendering
}
i = iNext;
}
}
for (i = 0; i < 256; i++)
if (sequencelabels[i] != null) RenderText(sequencelabels[i]);
public void RenderPolyobjects()
{
starts = new Vector2D[4096];
ends = new Vector2D[4096];
int i = 0, j = 0, k = 0, v = 0;
while (i < polyanchors.Count && j < polyspawns.Count && k < firstlines.Count)
{
while (j + 1 < polyspawns.Count && polyanchors[i].AngleDoom > polyspawns[j].AngleDoom)
{
// Mark invalid spawnpoints
spawnlabel.Text = polyspawns[j].AngleDoom.ToString();
spawnlabel.Left = polyspawns[j].Position.x;
spawnlabel.Top = polyspawns[j].Position.y;
spawnlabel.Color = PixelColor.FromColor(Color.Red);
RenderText(spawnlabel);
j++;
}
while (k+1 < firstlines.Count && polyanchors[i].AngleDoom > firstlines[k].Tag) k++;
Sector s = null;
if (polyanchors[i].AngleDoom == firstlines[k].Tag)
s = firstlines[k].Back.Sector;
if (polyanchors[i].AngleDoom == polyspawns[j].AngleDoom && s != null)
{
while (j+1 < polyspawns.Count && polyspawns[j].AngleDoom == polyspawns[j + 1].AngleDoom)
{
spawnlabel.Text = polyspawns[j].AngleDoom.ToString();
spawnlabel.Left = polyspawns[j].Position.x;
spawnlabel.Top = polyspawns[j].Position.y;
spawnlabel.Color = PixelColor.FromColor(Color.Red);
RenderText(spawnlabel);
j++;
}
float xdiff = polyanchors[i].Position.x - polyspawns[j].Position.x;
float ydiff = polyanchors[i].Position.y - polyspawns[j].Position.y;
foreach (Sidedef side in s.Sidedefs)
{
Vector2D start = side.Line.Start.Position;
Vector2D end = side.Line.End.Position;
start.x -= xdiff;
start.y -= ydiff;
end.x -= xdiff;
end.y -= ydiff;
starts[v] = start;
ends[v] = end;
v++;
}
anchorlabel.Color = General.Colors.GetNiGHTSColor(8);
spawnlabel.Color = General.Colors.GetNiGHTSColor(7);
spawnlabel.Text = polyspawns[j].AngleDoom.ToString();
spawnlabel.Left = polyspawns[j].Position.x;
spawnlabel.Top = polyspawns[j].Position.y;
RenderText(spawnlabel);
}
else
{
// Mark invalid points
anchorlabel.Color = PixelColor.FromColor(Color.Red);
}
anchorlabel.Text = polyanchors[i].AngleDoom.ToString();
anchorlabel.Left = polyanchors[i].Position.x;
anchorlabel.Top = polyanchors[i].Position.y;
RenderText(anchorlabel);
i++;
}
RenderLines(starts, ends, 1.0f, General.Colors.GetNiGHTSColor(7), true);
}
public void RenderNiGHTSPath()
{
if (!General.Settings.RenderNiGHTSPath)
{
return;
}
axes = new List<Thing>();
axistransferlines = new List<Thing>();
waypoints = new List<Thing>();
polyanchors = new List<Thing>();
polyspawns = new List<Thing>();
firstlines = new List<Linedef>();
foreach (Thing t in General.Map.Map.Things)
{
int type = t.SRB2Type;
if (type == General.Map.FormatInterface.AxisType) axes.Add(t);
if (type == General.Map.FormatInterface.AxisTransferLineType) axistransferlines.Add(t);
if (type == General.Map.FormatInterface.WaypointType) waypoints.Add(t);
if (type == 760) polyanchors.Add(t);
if (type == 761 || type == 762) polyspawns.Add(t);
}
foreach (Linedef l in General.Map.Map.Linedefs)
{
if (l.Action == 20) firstlines.Add(l);
}
//Sort waypoints by angle
waypoints.Sort((x,y) => (x.AngleDoom.CompareTo(y.AngleDoom)));
// Sort polyobject stuff by "angle"/tag
polyanchors.Sort((x, y) => (x.AngleDoom.CompareTo(y.AngleDoom)));
polyspawns.Sort((x, y) => (x.AngleDoom.CompareTo(y.AngleDoom)));
firstlines.Sort((x, y) => (x.Tag.CompareTo(y.Tag)));
//Sort by axis number and mare number.
axistransferlines.Sort((x, y) => (x.GetFlagsValue() | (x.Parameter)<<16).CompareTo((y.GetFlagsValue() | (y.Parameter) << 16)));
//Render zoom tubes and polyobjects
RenderWaypoints();
RenderPolyobjects();
//Render axis transfer lines.
i = 0;
size = axistransferlines.Count;
int i = 0;
int size = axistransferlines.Count;
while (i < size - 1)
{
int iNext = i;