RynthSuite as of 2026-12-04 (internal 88a02e2): release 2026.12.4.2
This commit is contained in:
parent
ba4ea691fe
commit
03b9069168
34 changed files with 1206 additions and 28 deletions
|
|
@ -99,6 +99,79 @@ internal static class NavPathQuery
|
|||
return r;
|
||||
}
|
||||
|
||||
// ── Crumbs (2026-12-03, the Yanshi Thread B470) ──────────────────────────────────────────────────
|
||||
// The mesh keeps its agent radius from every wall, and in a doorway that can leave a few polygons of its
|
||||
// own: a crumb, joined to nothing. A walk planned from one reaches nowhere. The hunt stood for minutes in
|
||||
// building #3's doorway with thirty monsters round it, every walk "the goal can't be reached" or ending on
|
||||
// the crumb; two steps back, on the street, it hunted again. A walk that starts on a crumb steps off it
|
||||
// first: to the nearest ground of a bigger piece within CrumbStepUnits, a step the character can take.
|
||||
|
||||
/// <summary>A piece of the mesh of at most this many polygons, joined to nothing bigger, is a crumb.</summary>
|
||||
public const int CrumbMaxPolys = 24;
|
||||
/// <summary>How far round a start on a crumb the ground it was cut off from is looked for (world units).</summary>
|
||||
public const float CrumbStepUnits = 3.0f;
|
||||
/// <summary>How far up or down from the start that ground may be (world units).</summary>
|
||||
public const float CrumbStepRise = 2.0f;
|
||||
|
||||
/// <summary>The polygons of <paramref name="start"/>'s piece when it is a crumb (at most <see cref="CrumbMaxPolys"/>), else null.</summary>
|
||||
internal static HashSet<long>? CrumbOf(DtNavMeshQuery q, long start)
|
||||
{
|
||||
if (start == 0) return null;
|
||||
DtNavMesh nav = q.GetAttachedNavMesh();
|
||||
var seen = new HashSet<long> { start };
|
||||
var stack = new Stack<long>();
|
||||
stack.Push(start);
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
long r = stack.Pop();
|
||||
if (nav.GetTileAndPolyByRef(r, out DtMeshTile tile, out DtPoly poly).Failed() || tile?.links == null || poly == null) continue;
|
||||
for (int i = poly.firstLink; i != DtDetour.DT_NULL_LINK && i >= 0 && i < tile.links.Length; i = tile.links[i].next)
|
||||
{
|
||||
long nb = tile.links[i].refs;
|
||||
if (nb == 0 || !seen.Add(nb)) continue;
|
||||
if (seen.Count > CrumbMaxPolys) return null;
|
||||
stack.Push(nb);
|
||||
}
|
||||
}
|
||||
return seen;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ground nearest <paramref name="start"/> (Detour axes) within <paramref name="reach"/> across and
|
||||
/// <see cref="CrumbStepRise"/> up or down that isn't on <paramref name="crumb"/> or another crumb. 0 when
|
||||
/// there is none. Every polygon in the box is looked at (Detour's nearest-polygon lookup would keep
|
||||
/// handing back the crumb itself).
|
||||
/// </summary>
|
||||
internal static long StepOffCrumb(DtNavMeshQuery q, RcVec3f start, HashSet<long> crumb, IDtQueryFilter filter, out RcVec3f pt,
|
||||
float reach = CrumbStepUnits)
|
||||
{
|
||||
pt = default;
|
||||
var polys = new long[256];
|
||||
q.QueryPolygons(start, new RcVec3f(reach, CrumbStepRise, reach), filter, polys, out int pc, polys.Length);
|
||||
long best = 0;
|
||||
double bestD = double.MaxValue;
|
||||
var small = new HashSet<long>(crumb); // polygons known to be on a crumb
|
||||
var big = new HashSet<long>(); // and on a bigger piece
|
||||
for (int i = 0; i < pc; i++)
|
||||
{
|
||||
long r = polys[i];
|
||||
if (small.Contains(r)) continue;
|
||||
if (q.ClosestPointOnPoly(r, start, out RcVec3f cp, out _).Failed()) continue;
|
||||
double flat = Math.Sqrt((cp.X - start.X) * (cp.X - start.X) + (cp.Z - start.Z) * (cp.Z - start.Z));
|
||||
double rise = Math.Abs(cp.Y - start.Y);
|
||||
if (flat > reach || rise > CrumbStepRise) continue;
|
||||
double d = flat + 0.5 * rise;
|
||||
if (d >= bestD) continue;
|
||||
if (!big.Contains(r))
|
||||
{
|
||||
if (CrumbOf(q, r) is HashSet<long> other) { small.UnionWith(other); continue; }
|
||||
big.Add(r);
|
||||
}
|
||||
best = r; bestD = d; pt = cp;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How far past a circle's edge the plain corridor's straight path must stay, everywhere, for it to be
|
||||
/// taken over the corridor round the circles (<see cref="Corridor"/>): the corners pushed off the walls
|
||||
|
|
@ -249,6 +322,22 @@ internal static class NavPathQuery
|
|||
q.FindNearestPoly(new RcVec3f((float)gx, (float)gz, (float)gy), WideExtents, plain, out long gRef, out RcVec3f gPt, out _);
|
||||
if (gRef == 0) return r.Fail(RynthNavPathApiV1.ResultNoMesh, "no navmesh at the goal");
|
||||
|
||||
// A start on a crumb (unless the goal is on it too): the walk steps off it first. A goal on one: the
|
||||
// walk goes to the ground beside it and steps onto it last.
|
||||
RcVec3f crumbStart = sPt, crumbGoal = gPt;
|
||||
bool stepped = false, steppedGoal = false;
|
||||
HashSet<long>? sCrumb = CrumbOf(q, sRef), gCrumb = CrumbOf(q, gRef);
|
||||
if (sCrumb != null && !sCrumb.Contains(gRef) && StepOffCrumb(q, sPt, sCrumb, plain, out RcVec3f sOff) is long sNew && sNew != 0)
|
||||
{
|
||||
sRef = sNew; sPt = sOff; stepped = true;
|
||||
r.SteppedOff = FlatUnits(crumbStart, sOff);
|
||||
}
|
||||
if (gCrumb != null && !gCrumb.Contains(sRef) && StepOffCrumb(q, gPt, gCrumb, plain, out RcVec3f gOff) is long gNew && gNew != 0)
|
||||
{
|
||||
gRef = gNew; gPt = gOff; steppedGoal = true;
|
||||
r.GoalSteppedOff = FlatUnits(crumbGoal, gOff);
|
||||
}
|
||||
|
||||
bool avoid = (flags & RynthNavPathApiV1.PathAvoidPortals) != 0 && portals != null && portals.Portals.Count > 0;
|
||||
if (avoid) { portals!.AllowA = sRef; portals.AllowB = gRef; }
|
||||
r.Portals = avoid ? portals!.Portals.Count : 0;
|
||||
|
|
@ -298,6 +387,11 @@ internal static class NavPathQuery
|
|||
r.Bent = wps.Count - before;
|
||||
}
|
||||
if ((flags & RynthNavPathApiV1.PathWallClearance) != 0) r.Pushed = PushFromWalls(q, wps, wallClearance, plain, ZAt);
|
||||
// Stepped off a crumb: the walk starts where the character stands, the step its first leg; a goal on
|
||||
// one is its last leg.
|
||||
if (stepped) wps.Insert(0, (crumbStart.X, crumbStart.Z));
|
||||
bool goalLeg = steppedGoal && !partial; // only on a walk that gets beside it
|
||||
if (goalLeg) wps.Add((crumbGoal.X, crumbGoal.Z));
|
||||
|
||||
int limit = Math.Max(2, maxCorners);
|
||||
if (wps.Count > limit)
|
||||
|
|
@ -305,7 +399,7 @@ internal static class NavPathQuery
|
|||
if ((flags & RynthNavPathApiV1.PathAllowPartial) == 0)
|
||||
return r.Fail(RynthNavPathApiV1.ResultNoPath, $"{wps.Count} corners, room for {limit}");
|
||||
wps.RemoveRange(limit, wps.Count - limit); // the first stretch of the way; plan again from its end
|
||||
partial = true; r.Truncated = true;
|
||||
partial = true; r.Truncated = true; goalLeg = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < wps.Count; i++)
|
||||
|
|
@ -314,6 +408,8 @@ internal static class NavPathQuery
|
|||
double z = double.NaN;
|
||||
for (int k = 0; k < ox.Length && double.IsNaN(z); k++)
|
||||
if (ox[k] == x && oy[k] == y) z = oz[k]; // a corner Detour gave: its own height
|
||||
if (double.IsNaN(z) && stepped && i == 0) z = crumbStart.Y; // the crumb's own height
|
||||
if (double.IsNaN(z) && goalLeg && i == wps.Count - 1) z = crumbGoal.Y;
|
||||
if (double.IsNaN(z)) z = HeightAt(q, plain, x, y, ZAt(x, y));
|
||||
r.Corners.Add((x, y, z));
|
||||
if (i > 0)
|
||||
|
|
@ -329,6 +425,8 @@ internal static class NavPathQuery
|
|||
return r.Code;
|
||||
}
|
||||
|
||||
private static double FlatUnits(RcVec3f a, RcVec3f b) => Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Z - b.Z) * (a.Z - b.Z));
|
||||
|
||||
/// <summary>The mesh's height under (x, y) near <paramref name="zGuess"/>; the guess when there's no polygon there.</summary>
|
||||
private static double HeightAt(DtNavMeshQuery q, IDtQueryFilter filter, double x, double y, float zGuess)
|
||||
{
|
||||
|
|
@ -373,6 +471,10 @@ internal sealed class PathExResult
|
|||
/// <summary>The plain corridor was taken: shorter than the way round the circles, and clear of them all (NavPathQuery.Corridor).</summary>
|
||||
public bool PlainClear;
|
||||
public int Polys, Portals, Bent, Pushed;
|
||||
/// <summary>The start was on a crumb (NavPathQuery.CrumbOf): how far the walk's first leg steps off it; 0 = it wasn't.</summary>
|
||||
public double SteppedOff;
|
||||
/// <summary>The goal was on a crumb: how far its last leg steps onto it; 0 = it wasn't.</summary>
|
||||
public double GoalSteppedOff;
|
||||
public string Note = "";
|
||||
|
||||
public void Reset()
|
||||
|
|
@ -382,6 +484,7 @@ internal sealed class PathExResult
|
|||
Length = EndDistance = 0;
|
||||
Partial = Truncated = FellBack = PlainClear = false;
|
||||
Polys = Portals = Bent = Pushed = 0;
|
||||
SteppedOff = GoalSteppedOff = 0;
|
||||
Note = "";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue