This commit is contained in:
ikpil 2024-01-04 23:38:13 +09:00
parent fdb86134cf
commit 10bf4ce164
6 changed files with 17 additions and 13 deletions

View File

@ -31,7 +31,7 @@ namespace DotRecast.Recast
public static class RcCompacts public static class RcCompacts
{ {
private const int MAX_LAYERS = RC_NOT_CONNECTED - 1; private const int MAX_LAYERS = RC_NOT_CONNECTED - 1;
private const int MAX_HEIGHT = RcConstants.SPAN_MAX_HEIGHT; private const int MAX_HEIGHT = RcConstants.RC_SPAN_MAX_HEIGHT;
/// @} /// @}
/// @name Compact Heightfield Functions /// @name Compact Heightfield Functions

View File

@ -37,11 +37,15 @@ namespace DotRecast.Recast
public const int RC_NOT_CONNECTED = 0x3f; public const int RC_NOT_CONNECTED = 0x3f;
/// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax. /// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.
public const int SPAN_HEIGHT_BITS = 20; public const int RC_SPAN_HEIGHT_BITS = 20;
/// Defines the maximum value for rcSpan::smin and rcSpan::smax. /// Defines the maximum value for rcSpan::smin and rcSpan::smax.
public const int SPAN_MAX_HEIGHT = (1 << SPAN_HEIGHT_BITS) - 1; public const int RC_SPAN_MAX_HEIGHT = (1 << RC_SPAN_HEIGHT_BITS) - 1;
/// The number of spans allocated per span spool.
/// @see rcSpanPool
public const int RC_SPANS_PER_POOL = 2048;
/// Heighfield border flag. /// Heighfield border flag.
/// If a heightfield region ID has this bit set, then the region is a border /// If a heightfield region ID has this bit set, then the region is a border
/// region and its spans are considered unwalkable. /// region and its spans are considered unwalkable.

View File

@ -221,8 +221,8 @@ namespace DotRecast.Recast
int smax = (int)MathF.Ceiling((h[1] - hf.bmin.Y) * ich); int smax = (int)MathF.Ceiling((h[1] - hf.bmin.Y) * ich);
if (smin != smax) if (smin != smax)
{ {
int ismin = Math.Clamp(smin, 0, SPAN_MAX_HEIGHT); int ismin = Math.Clamp(smin, 0, RC_SPAN_MAX_HEIGHT);
int ismax = Math.Clamp(smax, ismin + 1, SPAN_MAX_HEIGHT); int ismax = Math.Clamp(smax, ismin + 1, RC_SPAN_MAX_HEIGHT);
RcRasterizations.AddSpan(hf, x, z, ismin, ismax, area, flagMergeThr); RcRasterizations.AddSpan(hf, x, z, ismin, ismax, area, flagMergeThr);
} }
} }

View File

@ -119,12 +119,12 @@ namespace DotRecast.Recast
} }
int floor = (span.smax); int floor = (span.smax);
int ceiling = span.next != null ? span.next.smin : SPAN_MAX_HEIGHT; int ceiling = span.next != null ? span.next.smin : RC_SPAN_MAX_HEIGHT;
// The difference between this walkable area and the lowest neighbor walkable area. // The difference between this walkable area and the lowest neighbor walkable area.
// This is the difference between the current span and all neighbor spans that have // This is the difference between the current span and all neighbor spans that have
// enough space for an agent to move between, but not accounting at all for surface slope. // enough space for an agent to move between, but not accounting at all for surface slope.
int lowestNeighborFloorDifference = SPAN_MAX_HEIGHT; int lowestNeighborFloorDifference = RC_SPAN_MAX_HEIGHT;
// Min and max height of accessible neighbours. // Min and max height of accessible neighbours.
int lowestTraversableNeighborFloor = span.smax; int lowestTraversableNeighborFloor = span.smax;
@ -146,7 +146,7 @@ namespace DotRecast.Recast
// The most we can step down to the neighbor is the walkableClimb distance. // The most we can step down to the neighbor is the walkableClimb distance.
// Start with the area under the neighbor span // Start with the area under the neighbor span
int neighborCeiling = neighborSpan != null ? neighborSpan.smin : SPAN_MAX_HEIGHT; int neighborCeiling = neighborSpan != null ? neighborSpan.smin : RC_SPAN_MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small. // Skip neightbour if the gap between the spans is too small.
if (Math.Min(ceiling, neighborCeiling) - floor >= walkableHeight) if (Math.Min(ceiling, neighborCeiling) - floor >= walkableHeight)
@ -159,7 +159,7 @@ namespace DotRecast.Recast
for (; neighborSpan != null; neighborSpan = neighborSpan.next) for (; neighborSpan != null; neighborSpan = neighborSpan.next)
{ {
int neighborFloor = neighborSpan.smax; int neighborFloor = neighborSpan.smax;
neighborCeiling = neighborSpan.next != null ? neighborSpan.next.smin : SPAN_MAX_HEIGHT; neighborCeiling = neighborSpan.next != null ? neighborSpan.next.smin : RC_SPAN_MAX_HEIGHT;
// Only consider neighboring areas that have enough overlap to be potentially traversable. // Only consider neighboring areas that have enough overlap to be potentially traversable.
if (Math.Min(ceiling, neighborCeiling) - Math.Max(floor, neighborFloor) < walkableHeight) if (Math.Min(ceiling, neighborCeiling) - Math.Max(floor, neighborFloor) < walkableHeight)
@ -235,7 +235,7 @@ namespace DotRecast.Recast
for (RcSpan span = heightfield.spans[x + z * xSize]; span != null; span = span.next) for (RcSpan span = heightfield.spans[x + z * xSize]; span != null; span = span.next)
{ {
int floor = (span.smax); int floor = (span.smax);
int ceiling = span.next != null ? span.next.smin : SPAN_MAX_HEIGHT; int ceiling = span.next != null ? span.next.smin : RC_SPAN_MAX_HEIGHT;
if ((ceiling - floor) < walkableHeight) if ((ceiling - floor) < walkableHeight)
{ {
span.area = RC_NULL_AREA; span.area = RC_NULL_AREA;

View File

@ -35,7 +35,7 @@ namespace DotRecast.Recast
public const int MAX_TRIS = 255; // Max tris for delaunay is 2n-2-k (n=num verts, k=num hull verts). public const int MAX_TRIS = 255; // Max tris for delaunay is 2n-2-k (n=num verts, k=num hull verts).
public const int MAX_VERTS_PER_EDGE = 32; public const int MAX_VERTS_PER_EDGE = 32;
public const int RC_UNSET_HEIGHT = RcConstants.SPAN_MAX_HEIGHT; public const int RC_UNSET_HEIGHT = RcConstants.RC_SPAN_MAX_HEIGHT;
public const int EV_UNDEF = -1; public const int EV_UNDEF = -1;
public const int EV_HULL = -2; public const int EV_HULL = -2;

View File

@ -343,8 +343,8 @@ namespace DotRecast.Recast
spanMax = by; spanMax = by;
// Snap the span to the heightfield height grid. // Snap the span to the heightfield height grid.
int spanMinCellIndex = Math.Clamp((int)MathF.Floor(spanMin * inverseCellHeight), 0, SPAN_MAX_HEIGHT); int spanMinCellIndex = Math.Clamp((int)MathF.Floor(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
int spanMaxCellIndex = Math.Clamp((int)MathF.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, SPAN_MAX_HEIGHT); int spanMaxCellIndex = Math.Clamp((int)MathF.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
AddSpan(heightfield, x, z, spanMinCellIndex, spanMaxCellIndex, area, flagMergeThreshold); AddSpan(heightfield, x, z, spanMinCellIndex, spanMaxCellIndex, area, flagMergeThreshold);
} }