feat: expand cache to nearly all mobiles + dynamic-obstacle pass (#2447)

## Summary

Builds on PR #2446's cache-direct A*. The previous PR conservatively routed players + creatures with capability flags entirely through the slow path. This PR pushes that line: most mobile classes now use the cache, with the right rule set layered on top per-mobile, and the cache fast-path now does the dynamic items / mobiles check that PR #2446 had silently skipped.

## What changed

- **Non-GM players** now use the cache. Diagonal corner-cut applies the strict AND-rule (BOTH cardinal partners walkable) by reading the same source-cell mask byte the creature OR-rule reads — both rules are evaluable from one byte.
- **Creatures with `CanOpenDoors` / `CanMoveOverObstacles`** now use the cache. Reading `MovementImpl` confirmed those flags only affect dynamic items, never static tiles, so they were over-conservatively excluded before.
- **Swim creatures** now use the cache via a capability overlay. `StepProbe` bakes a second rule set (`canSwim=true, cantWalk=true`) producing `WetMask` + `SwimZ_*`. The algorithm composes `effectiveMask = (walkMask & !cantWalk) | (wetMask & canSwim)` per direction; walk Z preferred when both apply.
- **Dynamic-obstacle pass.** Cache fast-path now mirrors `MovementImpl`'s per-cell items + mobiles collision check (`GetItemsAt` / `GetMobilesAt` at the target cell, with `CanOpenDoors` / `CanMoveOverObstacles` / spell-field overrides). This closes a correctness gap from PR #2446 — the cache fast-path was silently skipping dynamic obstacles entirely.
- **`StepCache.TryGetMask` returns `StepMask` struct** instead of 11 out parameters. `HitKind` rolls into the struct with an `IsHit` accessor. Sets up wet/swim without ballooning the call site.
- **`StepChunk.MultiZCells` is lazy-init.** Most chunks are entirely single-Z; allocating the 32-byte bitmap up-front wasted ~256KB at full cap.
- **Admin commands.** `[PathCacheStats` (resident chunks + hit/miss/eviction counters) and `[PathCacheClear` (drop everything, zero counters).
- **Feature flag.** `bitmap_pathfinding_cache` (default true) gates the cache fast-path. Flipped off, every cell expansion routes to `MovementImpl` — equivalent to PR #2446's slow-path-only behavior. Safety net for shipping the new behavior.

`RequiresSlowPath` shrinks to just `CanFly` — flying creatures Z-jump arbitrarily, which the cache's static-Z model can't accommodate.
This commit is contained in:
Kamron Batman 2026-05-06 00:14:08 -07:00 • committed by GitHub
parent 6a3804addc
commit 9066e8fd00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 856 additions and 290 deletions

View file

@ -19,10 +19,10 @@ public class StepProbeTests
{
var result = StepProbe.ComputeMaskAt(null, 100, 100, 0);
Assert.Equal(0, result.Mask);
Assert.Equal(0, result.WalkMask);
for (var d = 0; d < 8; d++)
{
Assert.Equal(0, result.GetDestZ((Direction)d));
Assert.Equal(0, result.GetWalkZ((Direction)d));
}
}
@ -31,10 +31,10 @@ public class StepProbeTests
{
var result = StepProbe.ComputeMaskAt(Map.Internal, 100, 100, 0);
Assert.Equal(0, result.Mask);
Assert.Equal(0, result.WalkMask);
for (var d = 0; d < 8; d++)
{
Assert.Equal(0, result.GetDestZ((Direction)d));
Assert.Equal(0, result.GetWalkZ((Direction)d));
}
}
@ -98,7 +98,7 @@ public class StepProbeTests
var sourceZ = (sbyte)avgZ;
var result = StepProbe.ComputeMaskAt(map, x, y, sourceZ);
if (result.Mask != 0xFF)
if (result.WalkMask != 0xFF)
{
continue;
}
@ -106,7 +106,7 @@ public class StepProbeTests
var allSameZ = true;
for (var d = 0; d < 8; d++)
{
if (result.GetDestZ((Direction)d) != sourceZ)
if (result.GetWalkZ((Direction)d) != sourceZ)
{
allSameZ = false;
break;
@ -143,7 +143,7 @@ public class StepProbeTests
var sourceZ = (sbyte)avgZ;
var result = StepProbe.ComputeMaskAt(map, x, y, sourceZ);
if (result.Mask != 0xFF)
if (result.WalkMask != 0xFF)
{
blockedCellCount++;
}
@ -172,12 +172,12 @@ public class StepProbeTests
var second = StepProbe.ComputeMaskAt(map, x, y, sourceZ);
var third = StepProbe.ComputeMaskAt(map, x, y, sourceZ);
Assert.Equal(first.Mask, second.Mask);
Assert.Equal(first.Mask, third.Mask);
Assert.Equal(first.WalkMask, second.WalkMask);
Assert.Equal(first.WalkMask, third.WalkMask);
for (var d = 0; d < 8; d++)
{
Assert.Equal(first.GetDestZ((Direction)d), second.GetDestZ((Direction)d));
Assert.Equal(first.GetDestZ((Direction)d), third.GetDestZ((Direction)d));
Assert.Equal(first.GetWalkZ((Direction)d), second.GetWalkZ((Direction)d));
Assert.Equal(first.GetWalkZ((Direction)d), third.GetWalkZ((Direction)d));
}
}
@ -198,7 +198,7 @@ public class StepProbeTests
var result = StepProbe.ComputeMaskAt(map, 1500, 1600, sourceZ);
Assert.Equal((sbyte)10, sourceZ);
Assert.Equal((byte)0xC1, result.Mask);
Assert.Equal((byte)0xC1, result.WalkMask);
Assert.True(result.IsWalkable(Direction.North));
Assert.False(result.IsWalkable(Direction.Right));
@ -209,9 +209,9 @@ public class StepProbeTests
Assert.True(result.IsWalkable(Direction.West));
Assert.True(result.IsWalkable(Direction.Up));
Assert.Equal((sbyte)10, result.GetDestZ(Direction.North));
Assert.Equal((sbyte)10, result.GetDestZ(Direction.West));
Assert.Equal((sbyte)10, result.GetDestZ(Direction.Up));
Assert.Equal((sbyte)10, result.GetWalkZ(Direction.North));
Assert.Equal((sbyte)10, result.GetWalkZ(Direction.West));
Assert.Equal((sbyte)10, result.GetWalkZ(Direction.Up));
}
[Fact]
@ -229,7 +229,7 @@ public class StepProbeTests
var result = StepProbe.ComputeMaskAt(map, 1480, 1610, sourceZ);
Assert.Equal((sbyte)20, sourceZ);
Assert.Equal((byte)0x3F, result.Mask);
Assert.Equal((byte)0x3F, result.WalkMask);
Assert.True(result.IsWalkable(Direction.North));
Assert.True(result.IsWalkable(Direction.Right));
@ -242,7 +242,7 @@ public class StepProbeTests
for (var d = 0; d < 6; d++)
{
Assert.Equal((sbyte)20, result.GetDestZ((Direction)d));
Assert.Equal((sbyte)20, result.GetWalkZ((Direction)d));
}
}
}