Add fractal terrain debug dump
This commit is contained in:
parent
ad254bae30
commit
3d108406b8
6 changed files with 101 additions and 5 deletions
58
src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs
Normal file
58
src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Aquarium.Engine.Fractal;
|
||||
using Aquarium.Engine.Fractal.Grammar;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Debug;
|
||||
|
||||
public static class FractalDebugDump
|
||||
{
|
||||
public static string Build(
|
||||
FractalOwnershipTree tree,
|
||||
IReadOnlyList<AquariumFractalSummary> summaries,
|
||||
IReadOnlyList<AquariumSelectedCut> selectedCut)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(tree);
|
||||
ArgumentNullException.ThrowIfNull(summaries);
|
||||
ArgumentNullException.ThrowIfNull(selectedCut);
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine($"domain {tree.Domain.Key} kind={tree.Domain.Kind}");
|
||||
builder.AppendLine($"nodes {tree.Nodes.Count} claims {tree.Claims.Count} summaries {summaries.Count} cut {selectedCut.Count}");
|
||||
foreach (var node in tree.Nodes)
|
||||
{
|
||||
builder.AppendLine($"node {node.Key} op={node.Operation} claims={node.ClaimCount} bounds={FormatBounds(node.BoundsMinMax)}");
|
||||
}
|
||||
|
||||
foreach (var claim in tree.Claims)
|
||||
{
|
||||
builder.AppendLine(
|
||||
string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"claim {claim.Key} payload={claim.PayloadKind} center=({claim.Center.X:0.###},{claim.Center.Y:0.###}) radii=({claim.Radii.X:0.###},{claim.Radii.Y:0.###}) amp={claim.Amplitude:0.###} tags={claim.Tags}"));
|
||||
}
|
||||
|
||||
foreach (var summary in summaries)
|
||||
{
|
||||
builder.AppendLine(
|
||||
string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"summary {summary.NodeKey} heightError={summary.MaxHeightError:0.###} cost={summary.EstimatedCost:0.###} descendants={summary.DescendantCount}"));
|
||||
}
|
||||
|
||||
foreach (var cut in selectedCut)
|
||||
{
|
||||
builder.AppendLine(
|
||||
string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"cut {cut.NodeKey} score={cut.Score:0.###} fade={cut.Fade:0.###} summary={cut.UsesSummary} requestChildren={cut.RequestedChildren}"));
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static string FormatBounds(System.Numerics.Vector4 bounds)
|
||||
{
|
||||
return string.Create(CultureInfo.InvariantCulture, $"({bounds.X:0.###},{bounds.Y:0.###})-({bounds.Z:0.###},{bounds.W:0.###})");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
using Aquarium.Engine.Fractal;
|
||||
using Aquarium.Engine.Fractal.Brushes;
|
||||
using Aquarium.Engine.Fractal.Debug;
|
||||
using Aquarium.Engine.Fractal.Grammar;
|
||||
using Aquarium.Engine.Fractal.Lod;
|
||||
using Aquarium.Engine.Render;
|
||||
|
||||
namespace Aquarium.Zyphos;
|
||||
|
|
@ -15,12 +18,16 @@ public static class ZyphosFractalTerrain
|
|||
""";
|
||||
|
||||
private static readonly Lazy<FractalOwnershipTree> Tree = new(() => FractalDslCompiler.Compile(Grammar));
|
||||
private static readonly Lazy<AquariumFractalSummary[]> Summaries = new(() => FractalSummaryBuilder.Build(Tree.Value));
|
||||
private static readonly Lazy<AquariumSelectedCut[]> SelectedCut = new(() => FractalSelectedCutBuilder.Build(Summaries.Value, _ => 8.0f, maxEstimatedCost: 8.0f));
|
||||
private static readonly Lazy<AquariumHeightFieldBrush[]> Brushes = new(() => FractalHeightBrushCompiler.CompileMany(Tree.Value.Claims));
|
||||
|
||||
public static FractalOwnershipTree OwnershipTree => Tree.Value;
|
||||
|
||||
public static AquariumHeightFieldBrush[] HeightBrushes => Brushes.Value;
|
||||
|
||||
public static string DebugDump => FractalDebugDump.Build(OwnershipTree, Summaries.Value, SelectedCut.Value);
|
||||
|
||||
public static string Summary =>
|
||||
$"{OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} node / {HeightBrushes.Length} shaped brushes";
|
||||
$"{OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} node / {SelectedCut.Value.Length} cuts / {HeightBrushes.Length} shaped brushes";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ public sealed class ZyphosRuntime : IAquariumRuntime
|
|||
panel.Readout("Terrain DSL", () => ZyphosFractalTerrain.Summary);
|
||||
panel.Readout("Objects", () => "fractal height DSL, atmosphere, moon");
|
||||
})
|
||||
.Command("zyphos", _ => $"Zyphos: {ZyphosFractalTerrain.Summary}", "Report Zyphos demo status.");
|
||||
.Command("zyphos", _ => $"Zyphos: {ZyphosFractalTerrain.Summary}", "Report Zyphos demo status.")
|
||||
.Command("zyphos-fractal", _ => ZyphosFractalTerrain.DebugDump, "Dump the compiled Zyphos fractal terrain grammar.");
|
||||
}
|
||||
|
||||
public AquariumFrame ComposeFrame(AquariumFrame frame, AquariumFrameInput input)
|
||||
|
|
|
|||
Loading…
Reference in a new issue