Route Zyphos brush packets through selected cuts
This commit is contained in:
parent
5fc9d96330
commit
d49200c871
3 changed files with 51 additions and 2 deletions
|
|
@ -68,4 +68,30 @@ public static class FractalHeightBrushCompiler
|
|||
|
||||
return brushes;
|
||||
}
|
||||
|
||||
public static AquariumHeightFieldBrush[] CompileSelectedTree(FractalOwnershipTree tree, IReadOnlyList<AquariumSelectedCut> selectedCut)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(tree);
|
||||
ArgumentNullException.ThrowIfNull(selectedCut);
|
||||
|
||||
var selectedNodes = selectedCut.Select(cut => cut.NodeKey).ToHashSet();
|
||||
var domains = tree.Domains.ToDictionary(domain => domain.Key, domain => domain);
|
||||
var brushes = new List<AquariumHeightFieldBrush>();
|
||||
foreach (var node in tree.Nodes)
|
||||
{
|
||||
if (!selectedNodes.Contains(node.Key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var claimIndex = node.FirstClaimIndex; claimIndex < node.FirstClaimIndex + node.ClaimCount; claimIndex++)
|
||||
{
|
||||
var claim = tree.Claims[claimIndex];
|
||||
domains.TryGetValue(claim.DomainKey, out var domain);
|
||||
brushes.Add(Compile(claim, domain));
|
||||
}
|
||||
}
|
||||
|
||||
return brushes.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ public static class ZyphosFractalTerrain
|
|||
private static readonly Lazy<string> PatchSource = new(() => File.ReadAllText(PatchPath));
|
||||
private static readonly Lazy<FractalOwnershipTree> Tree = new(() => FractalDslCompiler.Compile(PatchSource.Value));
|
||||
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.CompileTree(Tree.Value));
|
||||
private static readonly Lazy<AquariumSelectedCut[]> SelectedCut = new(() => FractalSelectedCutBuilder.Build(Summaries.Value, _ => 8.0f, maxEstimatedCost: 64.0f));
|
||||
private static readonly Lazy<AquariumHeightFieldBrush[]> Brushes = new(() => FractalHeightBrushCompiler.CompileSelectedTree(Tree.Value, SelectedCut.Value));
|
||||
|
||||
public static string PatchPath => Path.Combine(AppContext.BaseDirectory, PatchRelativePath);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System.Numerics;
|
|||
using Aquarium.Engine.Fractal;
|
||||
using Aquarium.Engine.Fractal.Brushes;
|
||||
using Aquarium.Engine.Fractal.Grammar;
|
||||
using Aquarium.Engine.Fractal.Lod;
|
||||
|
||||
namespace Aquarium.Engine.Fractal.Tests;
|
||||
|
||||
|
|
@ -88,4 +89,26 @@ public sealed class FractalHeightBrushCompilerTests
|
|||
Assert.Equal(2.0f, brush.DomainX);
|
||||
Assert.Equal(1.0f, brush.DomainY);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SelectedTreeCompileOnlyLowersSelectedNodes()
|
||||
{
|
||||
const string source = """
|
||||
tile PositiveZ 0 0 0 demo/a
|
||||
height basin 0 0 30 30 0 3 1 -0.18 7 basin
|
||||
tile PositiveX 0 0 0 demo/b
|
||||
height ridge 1 1 4 2 0 3 1 0.08 11 ridge
|
||||
""";
|
||||
var tree = FractalDslCompiler.Compile(source);
|
||||
var selectedNode = Assert.Single(tree.Nodes, node => node.DomainKey.Value.EndsWith(":demo/b", StringComparison.Ordinal));
|
||||
var selectedCut = new[]
|
||||
{
|
||||
new AquariumSelectedCut(selectedNode.Key, Score: 1.0f, Fade: 1.0f, UsesSummary: true, RequestedChildren: false),
|
||||
};
|
||||
|
||||
var brush = Assert.Single(FractalHeightBrushCompiler.CompileSelectedTree(tree, selectedCut));
|
||||
|
||||
Assert.Equal(1.0f, brush.Center.X);
|
||||
Assert.Equal((float)CubeFace.PositiveX, brush.DomainFace);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue