Skip to content

Commit

Permalink
DotRecast optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Mar 5, 2024
1 parent 4eb1d57 commit ce2f884
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DotRecast
Submodule DotRecast updated 154 files
29 changes: 16 additions & 13 deletions vnavmesh/Debug/DebugSolidHeightfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ public DebugSolidHeightfield(RcHeightfield hf, UITree tree, DebugDrawer dd)
for (int x = 0; x < hf.width; ++x)
{
_spanCellOffsets[x, z] = _numNullSpans + _numWalkableSpans;
var span = hf.spans[icell++];
while (span != null)
var spanIndex = hf.spans[icell++];
while (spanIndex != 0)
{
ref var span = ref hf.Span(spanIndex);
if (span.area == 0)
++_numNullSpans;
else
++_numWalkableSpans;
span = span.next;
spanIndex = span.next;
}
}
}
Expand Down Expand Up @@ -70,8 +71,8 @@ public void Draw()
UITree.NodeRaii? nz = null;
for (int x = 0; x < _hf.width; ++x)
{
var span = _hf.spans[z * _hf.width + x];
if (span == null)
var spanIndex = _hf.spans[z * _hf.width + x];
if (spanIndex == 0)
continue;

nz ??= _tree.Node($"[*x{z}]");
Expand All @@ -84,11 +85,12 @@ public void Draw()
if (nx.Opened)
{
int ispan = 0;
while (span != null)
while (spanIndex != 0)
{
ref var span = ref _hf.Span(spanIndex);
if (_tree.LeafNode($"{span.smin}-{span.smax} = {span.area:X}").SelectedOrHovered)
VisualizeSpan(_spanCellOffsets[x, z] + ispan);
span = span.next;
spanIndex = span.next;
++ispan;
}
}
Expand Down Expand Up @@ -118,14 +120,15 @@ private EffectMesh.Data GetOrInitVisualizer()
world.M41 = x0;
for (int x = 0; x < _hf.width; ++x)
{
var span = _hf.spans[icell++];
while (span != null)
var spanIndex = _hf.spans[icell++];
while (spanIndex != 0)
{
ref var span = ref _hf.Span(spanIndex);
world.M22 = (span.smax - span.smin) * chh;
world.M42 = _hf.bmin.Y + (span.smin + span.smax) * chh;
builder.AddInstance(new(world, AreaColor(span.area)));
builder.AddMesh(box.FirstVertex, box.FirstPrimitive, box.NumPrimitives, icnt++, 1);
span = span.next;
spanIndex = span.next;
}
world.M41 += _hf.cs;
}
Expand All @@ -144,11 +147,11 @@ private void Visualize()
private void VisualizeCell(int x, int z)
{
int numSpans = 0;
var span = _hf.spans[z * _hf.width + x];
while (span != null)
var spanIndex = _hf.spans[z * _hf.width + x];
while (spanIndex != 0)
{
++numSpans;
span = span.next;
spanIndex = _hf.Span(spanIndex).next;
}
if (numSpans > 0)
_dd.EffectMesh?.DrawSubset(_dd.RenderContext, GetOrInitVisualizer(), _spanCellOffsets[x, z], numSpans);
Expand Down
7 changes: 4 additions & 3 deletions vnavmesh/NavVolume/VoxelMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,14 @@ public void AddFromHeightfield(RcHeightfield hf)
float x = x0;
for (int ix = hf.borderSize; ix < hf.width - hf.borderSize; ++ix)
{
var span = hf.spans[iz * hf.width + ix];
while (span != null)
var spanIndex = hf.spans[iz * hf.width + ix];
while (spanIndex != 0)
{
ref var span = ref hf.Span(spanIndex);
float y0 = hf.bmin.Y + span.smin * hf.ch;
float y1 = hf.bmin.Y + span.smax * hf.ch;
AddFromHeightfieldSpan(RootTile, x, z, y0, y1);
span = span.next;
spanIndex = span.next;
}
x += hf.cs;
}
Expand Down
2 changes: 1 addition & 1 deletion vnavmesh/NavmeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Navmesh;
// individual tiles can be built concurrently
public class NavmeshBuilder
{
public RcTelemetry Telemetry = new();
public RcContext Telemetry = new();
public NavmeshSettings Settings;
public SceneExtractor Scene;
public Vector3 BoundsMin;
Expand Down
6 changes: 3 additions & 3 deletions vnavmesh/NavmeshRasterizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Navmesh;
public class NavmeshRasterizer
{
private RcHeightfield _heightfield;
private RcTelemetry _telemetry;
private RcContext _telemetry;
private float[] _vertices = new float[3 * 256];
private int _walkableClimbThreshold; // if two spans have maximums within this number of voxels, their area is 'merged' (higher is selected)
private float _walkableNormalThreshold; // triangle is considered 'walkable' if it's world-space normal's Y coordinate is >= this

public NavmeshRasterizer(RcHeightfield heightfield, Angle walkableMaxSlope, int walkableMaxClimb, RcTelemetry telemetry)
public NavmeshRasterizer(RcHeightfield heightfield, Angle walkableMaxSlope, int walkableMaxClimb, RcContext telemetry)
{
_heightfield = heightfield;
_telemetry = telemetry;
Expand Down Expand Up @@ -68,7 +68,7 @@ public unsafe void Rasterize(SceneExtractor geom, bool includeTerrain, bool incl
}

var areaId = walkable ? RcConstants.RC_WALKABLE_AREA : 0;
RcRasterizations.RasterizeTriangle(_heightfield, _vertices, p.V1, p.V2, p.V3, areaId, _walkableClimbThreshold, _telemetry);
RcRasterizations.RasterizeTriangle(_telemetry, _vertices, p.V1, p.V2, p.V3, areaId, _heightfield, _walkableClimbThreshold);
}
}
}
Expand Down

0 comments on commit ce2f884

Please sign in to comment.