RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c33e24a610
commit
12ca25f911
426 changed files with 108239 additions and 7521 deletions
|
|
@ -4,18 +4,25 @@ using RynthCore.PluginSdk;
|
|||
namespace RynthCore.Plugin.RynthVision.Overlays;
|
||||
|
||||
/// <summary>
|
||||
/// Draws a horizontal ring on the ground centred on the player at the radar
|
||||
/// detection range. Needs no terrain data — just the player pose — so it's the
|
||||
/// reference for the Nav3D render path being wired correctly.
|
||||
/// Draws a ring centred on the player at the radar detection range. When
|
||||
/// terrain data is loaded (slopes or water on) the ring is built from Nav3D
|
||||
/// triangles that follow the ground under each segment, so it doesn't float
|
||||
/// over valleys or sink into hills; otherwise it is the engine's flat ring at
|
||||
/// the player's height (terrain is never loaded just for the ring).
|
||||
/// </summary>
|
||||
internal sealed class RadarRingOverlay
|
||||
{
|
||||
private const float SegmentLength = 16f; // metres of ring per segment
|
||||
private const int MinSegments = 32, MaxSegments = 96;
|
||||
private const float GroundBias = 0.10f;
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private readonly VisionSettings _settings;
|
||||
|
||||
// Auto-diagnostic: log the first submit per landblock so the user can
|
||||
// verify the ring centre matches the character (not the camera) without
|
||||
// having to remember the `/rv debug` opt-in.
|
||||
private float[] _cos = Array.Empty<float>(), _sin = Array.Empty<float>();
|
||||
|
||||
// /rv debug: log the first submit per landblock (where the ring centre
|
||||
// projects on screen) to confirm it tracks the character, not the camera.
|
||||
private uint _lastLoggedLandblock;
|
||||
|
||||
public RadarRingOverlay(RynthCoreHost host, VisionSettings settings)
|
||||
|
|
@ -24,37 +31,88 @@ internal sealed class RadarRingOverlay
|
|||
_settings = settings;
|
||||
}
|
||||
|
||||
public void Submit()
|
||||
public void Submit(TickContext ctx)
|
||||
{
|
||||
if (!_settings.ShowRadarRing)
|
||||
if (!_settings.ShowRadarRing || !ctx.OnLandscape)
|
||||
return;
|
||||
|
||||
try
|
||||
float radius = MathF.Max(5f, _settings.RadarRangeWorld);
|
||||
if (ctx.Terrain != null && _host.HasNav3DTriangle)
|
||||
{
|
||||
SubmitGroundRing(ctx, ctx.Terrain, radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_host.TryGetPlayerPose(out uint cellId, out float east, out float north, out float up,
|
||||
out _, out _, out _, out _))
|
||||
return;
|
||||
if ((cellId >> 16) == 0) return; // portalspace / not in the world
|
||||
if ((cellId & 0xFFFF) >= 0x100) return; // indoor — pose is cell-local, not landblock-local
|
||||
|
||||
// Nav3D world frame is Y-up: (x=east, y=up, z=north). The player
|
||||
// pose is AC convention (x=east, y=north, z=up), so swap y/z here.
|
||||
// (See RynthAi's TerrainPassabilityOverlay for the same mapping.)
|
||||
float radius = MathF.Max(5f, _settings.RadarRangeWorld);
|
||||
_host.Nav3DAddRingEx(east, up, north, radius,
|
||||
_host.Nav3DAddRingEx(ctx.X, ctx.Z, ctx.Y, radius,
|
||||
_settings.RadarRingThickness, _settings.RadarRingHeight,
|
||||
_settings.RadarRingColorArgb);
|
||||
|
||||
uint landblock = cellId >> 16;
|
||||
if (landblock != _lastLoggedLandblock)
|
||||
{
|
||||
_lastLoggedLandblock = landblock;
|
||||
LogRingPlacement(cellId, east, north, up, radius);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (ctx.Debug && ctx.Landblock != _lastLoggedLandblock)
|
||||
{
|
||||
_host.Log($"[RynthVision] RadarRing: {ex.Message}");
|
||||
_lastLoggedLandblock = ctx.Landblock;
|
||||
LogRingPlacement(ctx, radius);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wall (lower band at the ring colour, upper band fainter, like the
|
||||
/// engine ring's fade) plus a flat rim, every vertex on the ground below it.
|
||||
/// </summary>
|
||||
private void SubmitGroundRing(TickContext ctx, LandblockWindow terrain, float radius)
|
||||
{
|
||||
int segs = Math.Clamp((int)MathF.Ceiling(2f * MathF.PI * radius / SegmentLength), MinSegments, MaxSegments);
|
||||
EnsureTrig(segs);
|
||||
|
||||
uint color = _settings.RadarRingColorArgb;
|
||||
uint alpha = color >> 24;
|
||||
uint colorTop = (color & 0x00FFFFFFu) | ((alpha * 35 / 100) << 24);
|
||||
float half = MathF.Max(_settings.RadarRingHeight, 0.1f) * 0.5f;
|
||||
float thick = MathF.Max(_settings.RadarRingThickness, 0.05f);
|
||||
float inner = MathF.Max(0.01f, radius - thick), outer = radius + thick;
|
||||
|
||||
float px = ctx.X, py = ctx.Y;
|
||||
float prevX = 0, prevY = 0, prevG = 0, prevIx = 0, prevIy = 0, prevOx = 0, prevOy = 0;
|
||||
for (int i = 0; i <= segs; i++)
|
||||
{
|
||||
float c = _cos[i % segs], s = _sin[i % segs];
|
||||
float x = px + radius * c, y = py + radius * s;
|
||||
float g = (terrain.TryGetTerrainZ(x, y, out float tz) ? tz : ctx.Z) + GroundBias;
|
||||
float ix = px + inner * c, iy = py + inner * s;
|
||||
float ox = px + outer * c, oy = py + outer * s;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
// Nav3D (x=east, y=up, z=north).
|
||||
Quad(prevX, prevG, prevY, x, g, y, x, g + half, y, prevX, prevG + half, prevY, color);
|
||||
Quad(prevX, prevG + half, prevY, x, g + half, y, x, g + 2 * half, y, prevX, prevG + 2 * half, prevY, colorTop);
|
||||
Quad(prevIx, prevG, prevIy, prevOx, prevG, prevOy, ox, g, oy, ix, g, iy, color);
|
||||
}
|
||||
|
||||
prevX = x; prevY = y; prevG = g;
|
||||
prevIx = ix; prevIy = iy; prevOx = ox; prevOy = oy;
|
||||
}
|
||||
}
|
||||
|
||||
private void Quad(float ax, float ay, float az, float bx, float by, float bz,
|
||||
float cx, float cy, float cz, float dx, float dy, float dz, uint color)
|
||||
{
|
||||
_host.Nav3DAddTriangle(ax, ay, az, bx, by, bz, cx, cy, cz, color);
|
||||
_host.Nav3DAddTriangle(ax, ay, az, cx, cy, cz, dx, dy, dz, color);
|
||||
}
|
||||
|
||||
private void EnsureTrig(int segs)
|
||||
{
|
||||
if (_cos.Length == segs) return;
|
||||
_cos = new float[segs];
|
||||
_sin = new float[segs];
|
||||
for (int i = 0; i < segs; i++)
|
||||
{
|
||||
float a = 2f * MathF.PI * i / segs;
|
||||
_cos[i] = MathF.Cos(a);
|
||||
_sin[i] = MathF.Sin(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,17 +120,14 @@ internal sealed class RadarRingOverlay
|
|||
// is near the viewport's horizontal middle and roughly at the character's
|
||||
// feet, the ring is anchored to the player. If it tracks the camera-look
|
||||
// direction instead, either TryGetPlayerPose is returning the wrong object
|
||||
// (e.g. SmartBox+0xF8 reassigned during freelook) or the engine view matrix
|
||||
// (built from SmartBox+0x08 'viewer' Position) is misaligned with what AC
|
||||
// is actually rendering. The screen X/Y in the log makes either case
|
||||
// obvious without needing to enable /rv debug.
|
||||
private void LogRingPlacement(uint cellId, float east, float north, float up, float radius)
|
||||
// or the engine view matrix is misaligned with what AC is rendering.
|
||||
private void LogRingPlacement(TickContext ctx, float radius)
|
||||
{
|
||||
string screen = "n/a";
|
||||
if (_host.HasWorldToScreen && _host.WorldToScreen(east, up, north, out float sx, out float sy))
|
||||
if (_host.HasWorldToScreen && _host.WorldToScreen(ctx.X, ctx.Z, ctx.Y, out float sx, out float sy))
|
||||
screen = $"({sx:F0},{sy:F0})";
|
||||
string vp = _host.TryGetViewportSize(out uint vpW, out uint vpH) ? $"{vpW}x{vpH}" : "n/a";
|
||||
_host.Log($"[RynthVision] RadarRing placed cell=0x{cellId:X8} centre=({east:F1},{north:F1},{up:F1}) " +
|
||||
$"r={radius:F0} screen={screen} vp={vp}");
|
||||
_host.Log($"[RynthVision] RadarRing placed cell=0x{ctx.CellId:X8} centre=({ctx.X:F1},{ctx.Y:F1},{ctx.Z:F1}) " +
|
||||
$"r={radius:F0} ground={(ctx.Terrain != null)} screen={screen} vp={vp}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ namespace RynthCore.Plugin.RynthVision.Overlays;
|
|||
/// the slope so the player sees precisely the area they can't traverse.
|
||||
///
|
||||
/// Coverage extends past the player's landblock — at high radii the iteration
|
||||
/// reaches into the neighbouring 8 landblocks and renders their slopes too.
|
||||
/// All coordinates are emitted in PLAYER-landblock-local space; the engine's
|
||||
/// view-matrix capture shifts the camera into the same frame so the markers
|
||||
/// stay anchored to the world even when the camera orbits across a landblock
|
||||
/// boundary and AC re-anchors its rendering origin to a different landblock.
|
||||
/// reaches up to 3 landblocks out (<see cref="LandblockWindow"/>) and renders
|
||||
/// their slopes too. All coordinates are emitted in PLAYER-landblock-local
|
||||
/// space; the engine's view-matrix capture shifts the camera into the same
|
||||
/// frame so the markers stay anchored to the world even when the camera orbits
|
||||
/// across a landblock boundary and AC re-anchors its rendering origin to a
|
||||
/// different landblock.
|
||||
///
|
||||
/// Each 24 m cell is split along an AC-PRNG-selected diagonal (SW→NE or
|
||||
/// SE→NW — <see cref="TerrainSampler.SwToNeCut"/>); only the unwalkable half
|
||||
|
|
@ -24,52 +25,32 @@ namespace RynthCore.Plugin.RynthVision.Overlays;
|
|||
/// </summary>
|
||||
internal sealed class SlopeOverlay
|
||||
{
|
||||
private const float Cell = 24f;
|
||||
private const int CellsPerSide = 8;
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private readonly VisionSettings _settings;
|
||||
private readonly TerrainSampler _terrain;
|
||||
|
||||
public SlopeOverlay(RynthCoreHost host, VisionSettings settings, TerrainSampler terrain)
|
||||
public SlopeOverlay(RynthCoreHost host, VisionSettings settings)
|
||||
{
|
||||
_host = host;
|
||||
_settings = settings;
|
||||
_terrain = terrain;
|
||||
}
|
||||
|
||||
public void Submit()
|
||||
public void Submit(TickContext ctx)
|
||||
{
|
||||
if (!_settings.ShowUnclimbableSlopes || !_host.HasNav3D || !_terrain.IsReady)
|
||||
if (!_settings.ShowUnclimbableSlopes || ctx.Terrain == null || !ctx.OnLandscape)
|
||||
return;
|
||||
if (!_host.HasNav3DTriangle) // requires API v60+
|
||||
return;
|
||||
|
||||
if (!_host.TryGetPlayerPose(out uint cellId, out float px, out float py, out _,
|
||||
out _, out _, out _, out _))
|
||||
return;
|
||||
if ((cellId & 0xFFFF) >= 0x100) return; // indoor
|
||||
if ((cellId >> 16) == 0) return; // portalspace
|
||||
|
||||
int playerLbX = (int)((cellId >> 24) & 0xFF);
|
||||
int playerLbY = (int)((cellId >> 16) & 0xFF);
|
||||
LandblockWindow window = ctx.Terrain;
|
||||
const int cells = TerrainPaint.CellsPerSide;
|
||||
// Player's cell within their landblock.
|
||||
int playerCX = Math.Clamp((int)(px / Cell), 0, CellsPerSide - 1);
|
||||
int playerCY = Math.Clamp((int)(py / Cell), 0, CellsPerSide - 1);
|
||||
int radius = Math.Clamp(_settings.SlopeRenderRadius, 1, 24);
|
||||
int playerCX = Math.Clamp((int)(ctx.X / TerrainPaint.Cell), 0, cells - 1);
|
||||
int playerCY = Math.Clamp((int)(ctx.Y / TerrainPaint.Cell), 0, cells - 1);
|
||||
int radius = Math.Clamp(_settings.SlopeRenderRadius, 1, VisionSettings.MaxRenderRadius);
|
||||
uint color = _settings.SlopeColorArgb;
|
||||
float floorZ = Math.Clamp(_settings.SlopeFloorZ, 0.05f, 0.999f);
|
||||
float bias = Math.Clamp(_settings.SlopeHeightBias, 0f, 5f);
|
||||
|
||||
// Per-tick landblock cache so a single Submit doesn't reload the same
|
||||
// landblock 50 times. The TerrainSampler also caches, but that's a
|
||||
// dictionary lookup per cell — this is a small local array indexed by
|
||||
// (lbDX+2, lbDY+2) covering up to ±2 landblocks (24-cell radius caps
|
||||
// at 3-landblock extent each direction).
|
||||
const int LbSpan = 5; // -2..+2
|
||||
var lbCache = new LandblockData?[LbSpan * LbSpan];
|
||||
var lbCacheLoaded = new bool[LbSpan * LbSpan];
|
||||
|
||||
// Iterate outward in cell rings so the nearest cells are submitted
|
||||
// first — they survive if the engine's triangle budget is hit.
|
||||
for (int r = 0; r <= radius; r++)
|
||||
|
|
@ -82,32 +63,12 @@ internal sealed class SlopeOverlay
|
|||
|
||||
int absCellX = playerCX + dx;
|
||||
int absCellY = playerCY + dy;
|
||||
int lbDX = TerrainPaint.FloorDiv(absCellX, cells);
|
||||
int lbDY = TerrainPaint.FloorDiv(absCellY, cells);
|
||||
int localCX = absCellX - lbDX * cells;
|
||||
int localCY = absCellY - lbDY * cells;
|
||||
|
||||
// Decompose into (landblock-delta, local-cell) using
|
||||
// arithmetic that handles negative values cleanly.
|
||||
int lbDX = FloorDiv(absCellX, CellsPerSide);
|
||||
int lbDY = FloorDiv(absCellY, CellsPerSide);
|
||||
int localCX = absCellX - lbDX * CellsPerSide;
|
||||
int localCY = absCellY - lbDY * CellsPerSide;
|
||||
|
||||
int lbX = playerLbX + lbDX;
|
||||
int lbY = playerLbY + lbDY;
|
||||
if (lbX < 0 || lbX > 0xFF || lbY < 0 || lbY > 0xFF) continue;
|
||||
if (lbDX < -2 || lbDX > 2 || lbDY < -2 || lbDY > 2) continue;
|
||||
|
||||
int cacheIdx = (lbDX + 2) * LbSpan + (lbDY + 2);
|
||||
LandblockData? lb;
|
||||
if (lbCacheLoaded[cacheIdx])
|
||||
{
|
||||
lb = lbCache[cacheIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
uint lbKey = (uint)((lbX << 8) | lbY);
|
||||
lb = _terrain.LoadLandblock(lbKey);
|
||||
lbCache[cacheIdx] = lb;
|
||||
lbCacheLoaded[cacheIdx] = true;
|
||||
}
|
||||
LandblockData? lb = window.Get(lbDX, lbDY);
|
||||
if (lb == null) continue;
|
||||
|
||||
bool swToNe = TerrainSampler.SwToNeCut(lb.LandblockKey, localCX, localCY);
|
||||
|
|
@ -115,45 +76,9 @@ internal sealed class SlopeOverlay
|
|||
out bool t1ok, out bool t2ok, floorZ);
|
||||
if (t1ok && t2ok) continue;
|
||||
|
||||
// World coords in PLAYER-landblock-local frame: cell SW
|
||||
// corner is (lbDX*192 + localCX*24, lbDY*192 + localCY*24).
|
||||
float x0 = lbDX * 192f + localCX * Cell;
|
||||
float x1 = x0 + Cell;
|
||||
float z0 = lbDY * 192f + localCY * Cell;
|
||||
float z1 = z0 + Cell;
|
||||
float h00 = lb.GetVertexZ(localCX, localCY) + bias;
|
||||
float h10 = lb.GetVertexZ(localCX + 1, localCY) + bias;
|
||||
float h01 = lb.GetVertexZ(localCX, localCY + 1) + bias;
|
||||
float h11 = lb.GetVertexZ(localCX + 1, localCY + 1) + bias;
|
||||
|
||||
if (swToNe)
|
||||
{
|
||||
// SE half (SW, SE, NE) below the SW→NE diagonal
|
||||
if (!t1ok)
|
||||
_host.Nav3DAddTriangle(x0, h00, z0, x1, h10, z0, x1, h11, z1, color);
|
||||
// NW half (SW, NE, NW) above the SW→NE diagonal
|
||||
if (!t2ok)
|
||||
_host.Nav3DAddTriangle(x0, h00, z0, x1, h11, z1, x0, h01, z1, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
// SW half (SW, SE, NW) below the SE→NW diagonal
|
||||
if (!t1ok)
|
||||
_host.Nav3DAddTriangle(x0, h00, z0, x1, h10, z0, x0, h01, z1, color);
|
||||
// NE half (SE, NE, NW) above the SE→NW diagonal
|
||||
if (!t2ok)
|
||||
_host.Nav3DAddTriangle(x1, h10, z0, x1, h11, z1, x0, h01, z1, color);
|
||||
}
|
||||
TerrainPaint.EmitCell(_host, lb, lbDX, lbDY, localCX, localCY, swToNe, !t1ok, !t2ok, bias, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Floor division that handles negatives the way we need: FloorDiv(-1, 8) = -1, not 0.
|
||||
private static int FloorDiv(int a, int b)
|
||||
{
|
||||
int q = a / b;
|
||||
if ((a % b != 0) && ((a < 0) != (b < 0))) q--;
|
||||
return q;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
138
Plugins/RynthCore.Plugin.RynthVision/Overlays/TickContext.cs
Normal file
138
Plugins/RynthCore.Plugin.RynthVision/Overlays/TickContext.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.TerrainData;
|
||||
|
||||
namespace RynthCore.Plugin.RynthVision.Overlays;
|
||||
|
||||
/// <summary>
|
||||
/// What every overlay needs for one tick, sampled once in OnTick so the radar
|
||||
/// ring, slopes and water all draw from the same player pose (sampling it per
|
||||
/// overlay let one of them land on the other side of a landblock boundary).
|
||||
/// </summary>
|
||||
internal sealed class TickContext
|
||||
{
|
||||
public const float BlockLength = 192f;
|
||||
|
||||
public uint CellId;
|
||||
public float X, Y, Z; // AC frame: X=east, Y=north, Z=up, landblock-local metres
|
||||
|
||||
/// <summary>
|
||||
/// True when the pose is in landscape coordinates: an outdoor cell, or a
|
||||
/// building interior on the landscape (see RynthVisionPlugin.IsOnLandscape).
|
||||
/// </summary>
|
||||
public bool OnLandscape;
|
||||
|
||||
/// <summary>The terrain around the player, or null while terrain data isn't loaded.</summary>
|
||||
public LandblockWindow? Terrain;
|
||||
|
||||
/// <summary>/rv debug: per-crossing diagnostics.</summary>
|
||||
public bool Debug;
|
||||
|
||||
public uint Landblock => CellId >> 16;
|
||||
public int LandblockX => (int)((CellId >> 24) & 0xFF);
|
||||
public int LandblockY => (int)((CellId >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The landblocks within ±<see cref="Span"/> of the player's, loaded on first
|
||||
/// use each tick and shared by every overlay. Reset per tick; the arrays are
|
||||
/// reused. Radius 24 cells from any cell of the player's landblock reaches at
|
||||
/// most 3 landblocks away, so ±3 covers every radius the settings allow.
|
||||
/// </summary>
|
||||
internal sealed class LandblockWindow
|
||||
{
|
||||
public const int Span = 3;
|
||||
private const int Size = 2 * Span + 1;
|
||||
|
||||
private readonly TerrainSampler _terrain;
|
||||
private readonly LandblockData?[] _data = new LandblockData?[Size * Size];
|
||||
private readonly bool[] _loaded = new bool[Size * Size];
|
||||
private int _baseX, _baseY;
|
||||
|
||||
public LandblockWindow(TerrainSampler terrain) => _terrain = terrain;
|
||||
|
||||
public void Reset(int playerLbX, int playerLbY)
|
||||
{
|
||||
_baseX = playerLbX;
|
||||
_baseY = playerLbY;
|
||||
Array.Clear(_loaded);
|
||||
Array.Clear(_data);
|
||||
}
|
||||
|
||||
/// <summary>Landblock at (dx, dy) landblocks from the player's; null outside the window, the map, or the dat.</summary>
|
||||
public LandblockData? Get(int lbDX, int lbDY)
|
||||
{
|
||||
if (lbDX < -Span || lbDX > Span || lbDY < -Span || lbDY > Span) return null;
|
||||
int lbX = _baseX + lbDX, lbY = _baseY + lbDY;
|
||||
if (lbX < 0 || lbX > 0xFF || lbY < 0 || lbY > 0xFF) return null;
|
||||
|
||||
int idx = (lbDX + Span) * Size + (lbDY + Span);
|
||||
if (!_loaded[idx])
|
||||
{
|
||||
_data[idx] = _terrain.LoadLandblock((uint)((lbX << 8) | lbY));
|
||||
_loaded[idx] = true;
|
||||
}
|
||||
return _data[idx];
|
||||
}
|
||||
|
||||
/// <summary>Ground Z at (x, y) in player-landblock-local metres (may lie in a neighbouring landblock).</summary>
|
||||
public bool TryGetTerrainZ(float x, float y, out float z)
|
||||
{
|
||||
int lbDX = (int)MathF.Floor(x / TickContext.BlockLength);
|
||||
int lbDY = (int)MathF.Floor(y / TickContext.BlockLength);
|
||||
LandblockData? lb = Get(lbDX, lbDY);
|
||||
if (lb == null) { z = 0f; return false; }
|
||||
z = TerrainSampler.GetTerrainZ(lb, x - lbDX * TickContext.BlockLength, y - lbDY * TickContext.BlockLength);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Cell geometry shared by the slope and water overlays.</summary>
|
||||
internal static class TerrainPaint
|
||||
{
|
||||
public const float Cell = 24f;
|
||||
public const int CellsPerSide = 8;
|
||||
|
||||
/// <summary>Floor division: FloorDiv(-1, 8) = -1, not 0.</summary>
|
||||
public static int FloorDiv(int a, int b)
|
||||
{
|
||||
int q = a / b;
|
||||
if ((a % b != 0) && ((a < 0) != (b < 0))) q--;
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submits the chosen halves of cell (cx, cy) of the landblock at
|
||||
/// (lbDX, lbDY) from the player's, in player-landblock-local coordinates,
|
||||
/// lifted by <paramref name="bias"/>. Halves follow AC's split
|
||||
/// (<see cref="TerrainSampler.SwToNeCut"/>): with swToNe, t1 = SE half
|
||||
/// (SW,SE,NE) and t2 = NW half (SW,NE,NW); otherwise t1 = SW half
|
||||
/// (SW,SE,NW) and t2 = NE half (SE,NE,NW) — the same pairing as
|
||||
/// <see cref="TerrainSampler.GetTrianglePassability(LandblockData,int,int,bool,out bool,out bool,float)"/>.
|
||||
/// Nav3D is Y-up: (x=east, y=up, z=north).
|
||||
/// </summary>
|
||||
public static void EmitCell(RynthCoreHost host, LandblockData lb, int lbDX, int lbDY, int cx, int cy,
|
||||
bool swToNe, bool t1, bool t2, float bias, uint color)
|
||||
{
|
||||
float x0 = lbDX * TickContext.BlockLength + cx * Cell;
|
||||
float x1 = x0 + Cell;
|
||||
float z0 = lbDY * TickContext.BlockLength + cy * Cell;
|
||||
float z1 = z0 + Cell;
|
||||
float h00 = lb.GetVertexZ(cx, cy) + bias;
|
||||
float h10 = lb.GetVertexZ(cx + 1, cy) + bias;
|
||||
float h01 = lb.GetVertexZ(cx, cy + 1) + bias;
|
||||
float h11 = lb.GetVertexZ(cx + 1, cy + 1) + bias;
|
||||
|
||||
if (swToNe)
|
||||
{
|
||||
if (t1) host.Nav3DAddTriangle(x0, h00, z0, x1, h10, z0, x1, h11, z1, color);
|
||||
if (t2) host.Nav3DAddTriangle(x0, h00, z0, x1, h11, z1, x0, h01, z1, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t1) host.Nav3DAddTriangle(x0, h00, z0, x1, h10, z0, x0, h01, z1, color);
|
||||
if (t2) host.Nav3DAddTriangle(x1, h10, z0, x1, h11, z1, x0, h01, z1, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.TerrainData;
|
||||
|
|
@ -6,23 +7,25 @@ using RynthCore.TerrainData;
|
|||
namespace RynthCore.Plugin.RynthVision.Overlays;
|
||||
|
||||
/// <summary>
|
||||
/// Highlights LANDBLOCKS that AC's physics treats as fully impassable water
|
||||
/// — every vertex is a water terrain type (the "EntirelyWater" branch of
|
||||
/// ACE LandblockStruct.CalcWater). When a regular character enters such a
|
||||
/// landblock, LandCell.find_terrain_poly returns TransitionState.Collided
|
||||
/// outright — no depth check needed, the player can't enter at all. Those
|
||||
/// are the open-ocean / deep-lake landblocks the user can't walk through.
|
||||
/// Highlights water the player can't walk through.
|
||||
///
|
||||
/// Partial-water landblocks (shorelines, wadeable rivers/ponds) are
|
||||
/// intentionally NOT painted here: AC determines passability per position
|
||||
/// via get_water_depth() against a water surface Z we don't have access
|
||||
/// to from the dat files alone, so any heuristic over-marks or
|
||||
/// under-marks. Use the SLOPE overlay alongside for shoreline drop-offs.
|
||||
/// Fully-water landblocks — every vertex a water terrain type, the
|
||||
/// "EntirelyWater" branch of ACE LandblockStruct.CalcWater — are painted solid:
|
||||
/// a regular character can't enter them at all (open ocean, deep lakes).
|
||||
///
|
||||
/// Iterates landblocks in a cell-radius around the player that can extend
|
||||
/// into the 8 surrounding landblocks; emits triangles in PLAYER-landblock-
|
||||
/// local coordinates so the engine's view-matrix shift keeps them anchored
|
||||
/// when the camera crosses a landblock boundary.
|
||||
/// Elsewhere (shorelines, rivers, ponds) a cell counts as water when ANY of its
|
||||
/// four corners is a water type (<see cref="VisionSettings.WaterAnyCorner"/>)
|
||||
/// or, with that off, when all four are. AC decides how deep you can wade from
|
||||
/// a water-surface depth the dat files don't give us, so with
|
||||
/// <see cref="VisionSettings.WaterImpassableOnly"/> on (the default) only the
|
||||
/// water cells' unwalkable triangles are painted — the seafloor drop-offs AC's
|
||||
/// slope physics blocks, which are certainly impassable. With it off every
|
||||
/// water cell is painted: a "where is water" view, not an impassability one.
|
||||
///
|
||||
/// Cells are visited nearest-first out to the water radius (up to 3 landblocks
|
||||
/// away, <see cref="LandblockWindow"/>) and emitted in PLAYER-landblock-local
|
||||
/// coordinates so the engine's view-matrix shift keeps them anchored when the
|
||||
/// camera crosses a landblock boundary.
|
||||
/// </summary>
|
||||
internal sealed class WaterOverlay
|
||||
{
|
||||
|
|
@ -30,166 +33,139 @@ internal sealed class WaterOverlay
|
|||
// surface usually sits exactly at the mesh Z, so even tiny z-fighting
|
||||
// here is visible.
|
||||
private const float HeightBias = 0.20f;
|
||||
|
||||
private const float Cell = 24f;
|
||||
private const int CellsPerSide = 8;
|
||||
private const int MaxInfoCache = 128;
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private readonly VisionSettings _settings;
|
||||
private readonly TerrainSampler _terrain;
|
||||
|
||||
// Auto-diagnostic: one log per landblock entry summarising what we found
|
||||
// (cell count, types present, types matched). Mirrors RadarRingOverlay's
|
||||
// pattern — saves the user from having to type /rv watertypes when water
|
||||
// isn't being marked where they expect it.
|
||||
// Per-landblock water masks, rebuilt when the water-type list changes
|
||||
// (VisionSettings replaces the array on every change, so a reference
|
||||
// check is enough). Well above the 49 landblocks of a full window.
|
||||
private sealed class WaterInfo
|
||||
{
|
||||
public ulong AnyCornerMask; // bit cx*8+cy: some corner of the cell is water
|
||||
public ulong AllCornerMask; // bit cx*8+cy: every corner is water
|
||||
public bool FullyWater; // all 81 vertices are water
|
||||
}
|
||||
private readonly Dictionary<uint, WaterInfo> _info = new();
|
||||
private int[]? _infoTypes;
|
||||
|
||||
// /rv debug: one log per landblock entry summarising what we found.
|
||||
private uint _lastDiagLandblock;
|
||||
|
||||
public WaterOverlay(RynthCoreHost host, VisionSettings settings, TerrainSampler terrain)
|
||||
public WaterOverlay(RynthCoreHost host, VisionSettings settings)
|
||||
{
|
||||
_host = host;
|
||||
_settings = settings;
|
||||
_terrain = terrain;
|
||||
}
|
||||
|
||||
public void Submit()
|
||||
public void Submit(TickContext ctx)
|
||||
{
|
||||
if (!_settings.ShowImpassableWater || !_host.HasNav3D || !_terrain.IsReady)
|
||||
if (!_settings.ShowImpassableWater || ctx.Terrain == null || !ctx.OnLandscape)
|
||||
return;
|
||||
if (!_host.HasNav3DTriangle) // requires API v60+
|
||||
return;
|
||||
|
||||
if (!_host.TryGetPlayerPose(out uint cellId, out float px, out float py, out _,
|
||||
out _, out _, out _, out _))
|
||||
return;
|
||||
if ((cellId & 0xFFFF) >= 0x100) return; // indoor
|
||||
if ((cellId >> 16) == 0) return; // portalspace
|
||||
|
||||
int playerLbX = (int)((cellId >> 24) & 0xFF);
|
||||
int playerLbY = (int)((cellId >> 16) & 0xFF);
|
||||
int playerCX = Math.Clamp((int)(px / Cell), 0, CellsPerSide - 1);
|
||||
int playerCY = Math.Clamp((int)(py / Cell), 0, CellsPerSide - 1);
|
||||
int radius = Math.Clamp(_settings.WaterRenderRadius, 1, 24);
|
||||
LandblockWindow window = ctx.Terrain;
|
||||
const int cells = TerrainPaint.CellsPerSide;
|
||||
int playerCX = Math.Clamp((int)(ctx.X / TerrainPaint.Cell), 0, cells - 1);
|
||||
int playerCY = Math.Clamp((int)(ctx.Y / TerrainPaint.Cell), 0, cells - 1);
|
||||
int radius = Math.Clamp(_settings.WaterRenderRadius, 1, VisionSettings.MaxRenderRadius);
|
||||
uint color = _settings.WaterColorArgb;
|
||||
bool anyCorner = _settings.WaterAnyCorner;
|
||||
bool impassableOnly = _settings.WaterImpassableOnly;
|
||||
float floorZ = Math.Clamp(_settings.SlopeFloorZ, 0.05f, 0.999f);
|
||||
|
||||
const int LbSpan = 5; // -2..+2
|
||||
var lbCache = new LandblockData?[LbSpan * LbSpan];
|
||||
var lbCacheLoaded = new bool[LbSpan * LbSpan];
|
||||
// Per-landblock "fully water" flag — when every one of the 81 vertices
|
||||
// in a landblock matches a water terrain type, the entire 192×192 m
|
||||
// area is open sea / impassable lake. Paint all 64 cells regardless
|
||||
// of the per-cell corner rule, so deep open-water landblocks fill
|
||||
// solidly instead of leaving gaps where the per-cell filter is too
|
||||
// strict.
|
||||
var lbFullyWater = new bool[LbSpan * LbSpan];
|
||||
if (!ReferenceEquals(_infoTypes, _settings.WaterTerrainTypes))
|
||||
{
|
||||
_info.Clear();
|
||||
_infoTypes = _settings.WaterTerrainTypes;
|
||||
}
|
||||
|
||||
int submittedCells = 0;
|
||||
uint playerLandblock = cellId >> 16;
|
||||
|
||||
for (int dx = -radius; dx <= radius; dx++)
|
||||
for (int r = 0; r <= radius; r++)
|
||||
{
|
||||
for (int dy = -radius; dy <= radius; dy++)
|
||||
for (int dx = -r; dx <= r; dx++)
|
||||
{
|
||||
int absCellX = playerCX + dx;
|
||||
int absCellY = playerCY + dy;
|
||||
|
||||
int lbDX = FloorDiv(absCellX, CellsPerSide);
|
||||
int lbDY = FloorDiv(absCellY, CellsPerSide);
|
||||
int localCX = absCellX - lbDX * CellsPerSide;
|
||||
int localCY = absCellY - lbDY * CellsPerSide;
|
||||
|
||||
int lbX = playerLbX + lbDX;
|
||||
int lbY = playerLbY + lbDY;
|
||||
if (lbX < 0 || lbX > 0xFF || lbY < 0 || lbY > 0xFF) continue;
|
||||
if (lbDX < -2 || lbDX > 2 || lbDY < -2 || lbDY > 2) continue;
|
||||
|
||||
int cacheIdx = (lbDX + 2) * LbSpan + (lbDY + 2);
|
||||
LandblockData? lb;
|
||||
if (lbCacheLoaded[cacheIdx])
|
||||
for (int dy = -r; dy <= r; dy++)
|
||||
{
|
||||
lb = lbCache[cacheIdx];
|
||||
if (Math.Abs(dx) < r && Math.Abs(dy) < r) continue;
|
||||
|
||||
int absCellX = playerCX + dx;
|
||||
int absCellY = playerCY + dy;
|
||||
int lbDX = TerrainPaint.FloorDiv(absCellX, cells);
|
||||
int lbDY = TerrainPaint.FloorDiv(absCellY, cells);
|
||||
int localCX = absCellX - lbDX * cells;
|
||||
int localCY = absCellY - lbDY * cells;
|
||||
|
||||
LandblockData? lb = window.Get(lbDX, lbDY);
|
||||
if (lb == null) continue;
|
||||
WaterInfo info = GetInfo(lb);
|
||||
|
||||
bool swToNe = TerrainSampler.SwToNeCut(lb.LandblockKey, localCX, localCY);
|
||||
if (info.FullyWater)
|
||||
{
|
||||
TerrainPaint.EmitCell(_host, lb, lbDX, lbDY, localCX, localCY, swToNe, true, true, HeightBias, color);
|
||||
submittedCells++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong bit = 1UL << (localCX * cells + localCY);
|
||||
if (((anyCorner ? info.AnyCornerMask : info.AllCornerMask) & bit) == 0)
|
||||
continue;
|
||||
|
||||
bool paintT1 = true, paintT2 = true;
|
||||
if (impassableOnly)
|
||||
{
|
||||
TerrainSampler.GetTrianglePassability(lb, localCX, localCY, swToNe,
|
||||
out bool t1ok, out bool t2ok, floorZ);
|
||||
paintT1 = !t1ok;
|
||||
paintT2 = !t2ok;
|
||||
if (!paintT1 && !paintT2) continue;
|
||||
}
|
||||
|
||||
TerrainPaint.EmitCell(_host, lb, lbDX, lbDY, localCX, localCY, swToNe, paintT1, paintT2, HeightBias, color);
|
||||
submittedCells++;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint lbKey = (uint)((lbX << 8) | lbY);
|
||||
lb = _terrain.LoadLandblock(lbKey);
|
||||
lbCache[cacheIdx] = lb;
|
||||
lbCacheLoaded[cacheIdx] = true;
|
||||
if (lb != null) lbFullyWater[cacheIdx] = ComputeFullyWater(lb);
|
||||
}
|
||||
if (lb == null) continue;
|
||||
|
||||
// Only paint fully-water (EntirelyWater) landblocks — that's
|
||||
// the precise AC condition for "physics collides immediately,
|
||||
// no depth math". Partial-water landblocks deliberately skipped
|
||||
// (see class-summary).
|
||||
if (!lbFullyWater[cacheIdx]) continue;
|
||||
|
||||
float x0 = lbDX * 192f + localCX * Cell;
|
||||
float x1 = x0 + Cell;
|
||||
float z0 = lbDY * 192f + localCY * Cell;
|
||||
float z1 = z0 + Cell;
|
||||
float h00 = lb.GetVertexZ(localCX, localCY) + HeightBias;
|
||||
float h10 = lb.GetVertexZ(localCX + 1, localCY) + HeightBias;
|
||||
float h01 = lb.GetVertexZ(localCX, localCY + 1) + HeightBias;
|
||||
float h11 = lb.GetVertexZ(localCX + 1, localCY + 1) + HeightBias;
|
||||
|
||||
// Water cells get both triangles filled — we don't care which
|
||||
// diagonal AC's PRNG picked; either pair of triangles covers
|
||||
// the same flat-ish square. Use SW→NE split for simplicity.
|
||||
_host.Nav3DAddTriangle(x0, h00, z0, x1, h10, z0, x1, h11, z1, color);
|
||||
_host.Nav3DAddTriangle(x0, h00, z0, x1, h11, z1, x0, h01, z1, color);
|
||||
submittedCells++;
|
||||
}
|
||||
}
|
||||
|
||||
// One-shot per-landblock diagnostic. Whenever we cross to a new
|
||||
// landblock, log what we found: which terrain types are present in
|
||||
// the player's landblock, and how many cells we painted as water.
|
||||
// If the user expects water marked here but submittedCells=0, the
|
||||
// log will show what types ARE present so they can adjust
|
||||
// VisionSettings.WaterTerrainTypes.
|
||||
if (playerLandblock != _lastDiagLandblock)
|
||||
if (ctx.Debug && ctx.Landblock != _lastDiagLandblock)
|
||||
{
|
||||
_lastDiagLandblock = playerLandblock;
|
||||
LogWaterDiag(_terrain.LoadLandblock(playerLandblock), submittedCells, radius);
|
||||
_lastDiagLandblock = ctx.Landblock;
|
||||
LogWaterDiag(window.Get(0, 0), submittedCells, radius);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogWaterDiag(LandblockData? lb, int submittedCells, int radius)
|
||||
private WaterInfo GetInfo(LandblockData lb)
|
||||
{
|
||||
if (lb == null) return;
|
||||
var seen = new System.Collections.Generic.SortedSet<int>();
|
||||
if (_info.TryGetValue(lb.LandblockKey, out WaterInfo? info))
|
||||
return info;
|
||||
|
||||
info = new WaterInfo();
|
||||
bool fully = true;
|
||||
Span<bool> water = stackalloc bool[81];
|
||||
for (int ix = 0; ix < 9; ix++)
|
||||
for (int iy = 0; iy < 9; iy++)
|
||||
seen.Add(TerrainSampler.GetTerrainType(lb, ix, iy));
|
||||
string types = string.Join(",", seen);
|
||||
string configured = string.Join(",", _settings.WaterTerrainTypes);
|
||||
string anyMatch = "false";
|
||||
foreach (int t in seen)
|
||||
foreach (int w in _settings.WaterTerrainTypes)
|
||||
if (t == w) { anyMatch = "true"; goto done; }
|
||||
done:
|
||||
bool fullyWater = ComputeFullyWater(lb);
|
||||
_host.Log($"[RynthVision] Water lb=0x{lb.LandblockKey:X4} cellsPainted={submittedCells} r={radius} " +
|
||||
$"presentTypes=[{types}] configured=[{configured}] anyMatch={anyMatch} " +
|
||||
$"anyCorner={_settings.WaterAnyCorner} fullyWaterLb={fullyWater}");
|
||||
}
|
||||
{
|
||||
bool w = IsWater(lb, ix, iy);
|
||||
water[ix * 9 + iy] = w;
|
||||
fully &= w;
|
||||
}
|
||||
for (int cx = 0; cx < 8; cx++)
|
||||
for (int cy = 0; cy < 8; cy++)
|
||||
{
|
||||
bool sw = water[cx * 9 + cy], se = water[(cx + 1) * 9 + cy];
|
||||
bool nw = water[cx * 9 + cy + 1], ne = water[(cx + 1) * 9 + cy + 1];
|
||||
ulong bit = 1UL << (cx * 8 + cy);
|
||||
if (sw || se || nw || ne) info.AnyCornerMask |= bit;
|
||||
if (sw && se && nw && ne) info.AllCornerMask |= bit;
|
||||
}
|
||||
info.FullyWater = fully;
|
||||
|
||||
// VisionSettings.WaterAnyCorner toggles between "any corner is water" (catches
|
||||
// shorelines, default) and "all four corners are water" (skips shoreline
|
||||
// cells, marks only fully-water cells). AC's own impassability check is
|
||||
// depth-based and not derivable from terrain types alone — for the
|
||||
// "actually impassable" signal, enable the SLOPE overlay alongside; the
|
||||
// overlap of red (slope-blocked) and blue (water) is where you can't walk.
|
||||
private bool IsWaterCell(LandblockData lb, int cx, int cy)
|
||||
{
|
||||
bool sw = IsWater(lb, cx, cy);
|
||||
bool se = IsWater(lb, cx + 1, cy);
|
||||
bool nw = IsWater(lb, cx, cy + 1);
|
||||
bool ne = IsWater(lb, cx + 1, cy + 1);
|
||||
return _settings.WaterAnyCorner
|
||||
? (sw || se || nw || ne)
|
||||
: (sw && se && nw && ne);
|
||||
if (_info.Count >= MaxInfoCache) _info.Clear();
|
||||
_info[lb.LandblockKey] = info;
|
||||
return info;
|
||||
}
|
||||
|
||||
private bool IsWater(LandblockData lb, int ix, int iy)
|
||||
|
|
@ -201,22 +177,19 @@ internal sealed class WaterOverlay
|
|||
return false;
|
||||
}
|
||||
|
||||
// True only when every one of the landblock's 81 vertices is a configured
|
||||
// water-type. That means there's NO dry land anywhere in the landblock,
|
||||
// so the entire 192×192 m area is open water and the player can't enter
|
||||
// any of it — paint the whole thing solid rather than risking gaps.
|
||||
private bool ComputeFullyWater(LandblockData lb)
|
||||
private void LogWaterDiag(LandblockData? lb, int submittedCells, int radius)
|
||||
{
|
||||
if (lb == null) return;
|
||||
var seen = new SortedSet<int>();
|
||||
for (int ix = 0; ix < 9; ix++)
|
||||
for (int iy = 0; iy < 9; iy++)
|
||||
if (!IsWater(lb, ix, iy)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int FloorDiv(int a, int b)
|
||||
{
|
||||
int q = a / b;
|
||||
if ((a % b != 0) && ((a < 0) != (b < 0))) q--;
|
||||
return q;
|
||||
seen.Add(TerrainSampler.GetTerrainType(lb, ix, iy));
|
||||
bool anyMatch = false;
|
||||
foreach (int t in seen)
|
||||
if (Array.IndexOf(_settings.WaterTerrainTypes, t) >= 0) { anyMatch = true; break; }
|
||||
_host.Log($"[RynthVision] Water lb=0x{lb.LandblockKey:X4} cellsPainted={submittedCells} r={radius} " +
|
||||
$"presentTypes=[{string.Join(",", seen)}] configured=[{string.Join(",", _settings.WaterTerrainTypes)}] " +
|
||||
$"anyMatch={anyMatch} anyCorner={_settings.WaterAnyCorner} impassableOnly={_settings.WaterImpassableOnly} " +
|
||||
$"fullyWaterLb={GetInfo(lb).FullyWater}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ using RynthCore.PluginSdk;
|
|||
|
||||
namespace RynthCore.Plugin.RynthVision;
|
||||
|
||||
/// <summary>
|
||||
/// C ABI exports. Nothing may throw out of an [UnmanagedCallersOnly] method (it
|
||||
/// would take acclient.exe down): the lifecycle and event exports go through
|
||||
/// RynthPluginRuntime, which catches and logs; the rest catch here.
|
||||
/// </summary>
|
||||
public static unsafe class PluginExports
|
||||
{
|
||||
private static readonly RynthPluginRuntime<RynthVisionPlugin> Runtime = new();
|
||||
|
|
@ -15,7 +20,20 @@ public static unsafe class PluginExports
|
|||
private static int Init(RynthCoreApiNative* api) => Runtime.Init(api);
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginShutdown", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void Shutdown() => Runtime.Shutdown();
|
||||
public static void Shutdown()
|
||||
{
|
||||
Runtime.Shutdown();
|
||||
try
|
||||
{
|
||||
// The engine copies the settings string as soon as it gets it, on
|
||||
// the same (pump) thread that shuts us down, so nothing still
|
||||
// reads this buffer.
|
||||
IntPtr old = Interlocked.Exchange(ref _settingsPtr, IntPtr.Zero);
|
||||
if (old != IntPtr.Zero)
|
||||
Marshal.FreeHGlobal(old);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLoginComplete", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnLoginComplete() => Runtime.OnLoginComplete();
|
||||
|
|
@ -23,26 +41,32 @@ public static unsafe class PluginExports
|
|||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLogout", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnLogout() => Runtime.OnLogout();
|
||||
|
||||
// Name/version are UTF-8 literals: the compiler stores them null-terminated
|
||||
// in the module's read-only data, so there is nothing to allocate or free,
|
||||
// and they stay valid for as long as the module is loaded (the engine
|
||||
// copies them right after loading, before Init).
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginName", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static IntPtr GetName() => RynthVisionPlugin.NamePointer;
|
||||
public static IntPtr GetName() => LiteralPointer("RynthVision"u8);
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginVersion", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static IntPtr GetVersion() => RynthVisionPlugin.VersionPointer;
|
||||
public static IntPtr GetVersion() => LiteralPointer("0.1.0"u8);
|
||||
|
||||
private static IntPtr LiteralPointer(ReadOnlySpan<byte> literal)
|
||||
{
|
||||
fixed (byte* p = literal)
|
||||
return (IntPtr)p;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginTick", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void Tick() => Runtime.OnTick();
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginRender", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void Render() => Runtime.OnRender();
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatBarEnter", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnChatBarEnter(IntPtr textUtf16, IntPtr eatFlag) => Runtime.OnChatBarEnter(textUtf16, eatFlag);
|
||||
|
||||
// ── Avalonia settings-panel bridge (engine RynthVisionPanel) ──────────────
|
||||
// The panel reads RynthVisionGetSettingsJson to populate its controls and
|
||||
// pushes changes via RynthVisionSetSettings. The pointer swap (alloc-new →
|
||||
// swap → free-old) keeps the UI-thread caller safe without a lock, matching
|
||||
// the RynthChat scrollback bridge.
|
||||
// ── Settings bridge for the engine's Vision panels (UI/Data/VisionData.cs) ──
|
||||
// The engine calls these on the plugin pump thread (UiDataHub). The
|
||||
// pointer swap (alloc-new → swap → free-old) keeps the previous buffer
|
||||
// alive until the next call; the engine copies it immediately.
|
||||
|
||||
private static IntPtr _settingsPtr = IntPtr.Zero;
|
||||
|
||||
|
|
@ -64,6 +88,7 @@ public static unsafe class PluginExports
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Applies any subset of the settings keys (the panels send only the changed field).</summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthVisionSetSettings", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void SetSettings(IntPtr ansiJson)
|
||||
{
|
||||
|
|
@ -78,5 +103,9 @@ public static unsafe class PluginExports
|
|||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthVisionInspectTerrain", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void InspectTerrain() => Runtime.Plugin?.InspectTerrain();
|
||||
public static void InspectTerrain()
|
||||
{
|
||||
try { Runtime.Plugin?.InspectTerrain(); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,10 @@
|
|||
<PublishDir>C:\Games\RynthSuite\RynthVision\</PublishDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="ImGui.NET" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginCore\RynthCore.PluginCore.csproj" />
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginSdk\RynthCore.PluginSdk.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\RynthCore.TerrainData\RynthCore.TerrainData.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="RemoveBundledImGuiNativeFromBuild" AfterTargets="Build">
|
||||
<Delete Files="$(OutputPath)cimgui.dll" Condition="Exists('$(OutputPath)cimgui.dll')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="RemoveBundledImGuiNativeFromPublish" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||
<Delete Files="$(PublishDir)cimgui.dll" Condition="Exists('$(PublishDir)cimgui.dll')" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.Plugin.RynthVision.Overlays;
|
||||
using RynthCore.PluginCore;
|
||||
|
|
@ -11,45 +11,52 @@ namespace RynthCore.Plugin.RynthVision;
|
|||
/// <summary>
|
||||
/// World-space visualization plugin (a RynthCore-native take on Decal's
|
||||
/// SkunkVision): highlights unclimbable slopes, impassable water, and a
|
||||
/// radar-range ring using the engine's Nav3D overlay API. Settings are driven by
|
||||
/// the engine's Avalonia "Vision" panel (via the bridge methods below) or the
|
||||
/// /rv chat command, and persist to %APPDATA%\RynthCore\rynthvision.json.
|
||||
/// radar-range ring using the engine's Nav3D overlay API. Settings come from
|
||||
/// the engine's Vision panels (ImGui face and the Avalonia twin, through the
|
||||
/// JSON exports in PluginExports) or the /rv chat command, and persist to
|
||||
/// %APPDATA%\RynthCore\rynthvision.json.
|
||||
///
|
||||
/// Terrain data (the portal/cell .dat files) is opened on the first in-world
|
||||
/// tick that has slopes or water switched on, never while they're off.
|
||||
/// </summary>
|
||||
public sealed class RynthVisionPlugin : RynthPluginBase
|
||||
{
|
||||
internal static readonly IntPtr NamePointer = Marshal.StringToHGlobalAnsi("RynthVision");
|
||||
internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi("0.1.0");
|
||||
// An EnvCell pose more than this far below the ground is a dungeon under
|
||||
// the landscape, not a building interior (see IsOnLandscape).
|
||||
private const float BelowGroundLimit = 10f;
|
||||
|
||||
private readonly VisionSettings _settings = new();
|
||||
private readonly TerrainSampler _terrain = new();
|
||||
private readonly TickContext _ctx = new();
|
||||
private LandblockWindow? _window;
|
||||
|
||||
private RadarRingOverlay? _radarRing;
|
||||
private SlopeOverlay? _slopes;
|
||||
private WaterOverlay? _water;
|
||||
|
||||
// Diagnostic: /rv debug streams the player pose so we can tell whether it
|
||||
// tracks the character or the camera (the radar-ring placement bug).
|
||||
private bool _debugPose;
|
||||
// Lazy terrain init: one attempt per login, or per time slopes/water are
|
||||
// switched back on, so a missing dat doesn't retry every tick.
|
||||
private bool _terrainAttempted;
|
||||
private bool _terrainWanted;
|
||||
|
||||
// Diagnostic: /rv debug streams the player pose and turns on the
|
||||
// per-landblock ring/water logs.
|
||||
private bool _debug;
|
||||
private int _dbgTick;
|
||||
|
||||
public override int Initialize()
|
||||
{
|
||||
_settings.Load();
|
||||
_window = new LandblockWindow(_terrain);
|
||||
_radarRing = new RadarRingOverlay(Host, _settings);
|
||||
_slopes = new SlopeOverlay(Host, _settings, _terrain);
|
||||
_water = new WaterOverlay(Host, _settings, _terrain);
|
||||
_slopes = new SlopeOverlay(Host, _settings);
|
||||
_water = new WaterOverlay(Host, _settings);
|
||||
|
||||
Host.Log("[RynthVision] Initialized. Use the Vision panel, or /rv [radar|slopes|water|watertypes|debug].");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void OnLoginComplete()
|
||||
{
|
||||
if (_terrain.Initialize())
|
||||
Host.Log("[RynthVision] Terrain data ready.");
|
||||
else
|
||||
Host.Log($"[RynthVision] Terrain data unavailable: {_terrain.Status} (slopes/water disabled).");
|
||||
}
|
||||
public override void OnLoginComplete() => _terrainAttempted = false;
|
||||
|
||||
public override void OnLogout() => Host.Log("[RynthVision] Logout.");
|
||||
|
||||
|
|
@ -63,17 +70,81 @@ public sealed class RynthVisionPlugin : RynthPluginBase
|
|||
if (!Host.HasNav3D)
|
||||
return;
|
||||
|
||||
_radarRing?.Submit();
|
||||
_slopes?.Submit();
|
||||
_water?.Submit();
|
||||
// One pose for every overlay this tick.
|
||||
if (!Host.TryGetPlayerPose(out uint cellId, out float x, out float y, out float z,
|
||||
out _, out _, out _, out _) || (cellId >> 16) == 0)
|
||||
return; // not in the world / portalspace
|
||||
|
||||
if (_debugPose && (++_dbgTick % 30 == 0))
|
||||
bool wanted = _settings.ShowUnclimbableSlopes || _settings.ShowImpassableWater;
|
||||
if (wanted && !_terrainWanted) _terrainAttempted = false; // switched on again: retry
|
||||
_terrainWanted = wanted;
|
||||
if (wanted && !_terrain.IsReady && !_terrainAttempted)
|
||||
InitTerrain();
|
||||
|
||||
TickContext ctx = _ctx;
|
||||
ctx.CellId = cellId;
|
||||
ctx.X = x; ctx.Y = y; ctx.Z = z;
|
||||
ctx.Debug = _debug;
|
||||
ctx.Terrain = null;
|
||||
if (_terrain.IsReady && _window != null)
|
||||
{
|
||||
_window.Reset(ctx.LandblockX, ctx.LandblockY);
|
||||
ctx.Terrain = _window;
|
||||
}
|
||||
ctx.OnLandscape = IsOnLandscape(ctx);
|
||||
|
||||
_radarRing?.Submit(ctx);
|
||||
_slopes?.Submit(ctx);
|
||||
_water?.Submit(ctx);
|
||||
|
||||
if (_debug && (++_dbgTick % 30 == 0))
|
||||
LogPose();
|
||||
}
|
||||
|
||||
private bool InitTerrain()
|
||||
{
|
||||
_terrainAttempted = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
bool ok = _terrain.Initialize();
|
||||
if (ok)
|
||||
Host.Log($"[RynthVision] Terrain data ready ({sw.Elapsed.TotalMilliseconds:F0} ms).");
|
||||
else
|
||||
Host.Log($"[RynthVision] Terrain data unavailable: {_terrain.Status} (slopes/water disabled).");
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the pose is in landscape coordinates. AC keeps every Position
|
||||
/// landblock-relative, EnvCells included (the classic coordinates formula
|
||||
/// lbX*8 + x/24 works unchanged indoors), so building interiors on the
|
||||
/// landscape sit in the same frame as the outdoor cells around them. An
|
||||
/// EnvCell counts when its landblock has real terrain (ACE treats a
|
||||
/// landblock whose heights are all 0 as a dungeon block), the position is
|
||||
/// inside the block, and it isn't well below the ground (a dungeon under
|
||||
/// the landscape). Deciding that needs the terrain, so without it EnvCells
|
||||
/// stay off, as before.
|
||||
/// </summary>
|
||||
private static bool IsOnLandscape(TickContext ctx)
|
||||
{
|
||||
if ((ctx.CellId & 0xFFFF) < 0x100) return true;
|
||||
if (ctx.Terrain == null) return false;
|
||||
if (ctx.X < 0f || ctx.Y < 0f || ctx.X >= TickContext.BlockLength || ctx.Y >= TickContext.BlockLength) return false;
|
||||
|
||||
LandblockData? lb = ctx.Terrain.Get(0, 0);
|
||||
if (lb == null || lb.HeightIndices == null) return false;
|
||||
bool hasTerrain = false;
|
||||
foreach (byte h in lb.HeightIndices)
|
||||
if (h != 0) { hasTerrain = true; break; }
|
||||
if (!hasTerrain) return false;
|
||||
|
||||
return ctx.Z >= TerrainSampler.GetTerrainZ(lb, ctx.X, ctx.Y) - BelowGroundLimit;
|
||||
}
|
||||
|
||||
public override void OnChatBarEnter(string? text, ref int eat)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text) || !text.StartsWith("/rv", StringComparison.OrdinalIgnoreCase))
|
||||
// "/rv" alone or followed by whitespace; "/rvanything" isn't ours.
|
||||
if (string.IsNullOrWhiteSpace(text) || !text.StartsWith("/rv", StringComparison.OrdinalIgnoreCase)
|
||||
|| (text.Length > 3 && !char.IsWhiteSpace(text[3])))
|
||||
return;
|
||||
|
||||
eat = 1; // consume — don't send to the server as chat
|
||||
|
|
@ -85,7 +156,7 @@ public sealed class RynthVisionPlugin : RynthPluginBase
|
|||
case "slopes": _settings.ShowUnclimbableSlopes = !_settings.ShowUnclimbableSlopes; break;
|
||||
case "water": _settings.ShowImpassableWater = !_settings.ShowImpassableWater; break;
|
||||
case "watertypes": InspectTerrain(); return;
|
||||
case "debug": _debugPose = !_debugPose; Host.Log($"[RynthVision] pose debug = {_debugPose}"); return;
|
||||
case "debug": _debug = !_debug; Host.Log($"[RynthVision] debug = {_debug}"); return;
|
||||
case "": break;
|
||||
default:
|
||||
Host.Log($"[RynthVision] Unknown option '{arg}'. Use radar | slopes | water | watertypes | debug.");
|
||||
|
|
@ -96,10 +167,11 @@ public sealed class RynthVisionPlugin : RynthPluginBase
|
|||
Host.Log($"[RynthVision] radar={_settings.ShowRadarRing} slopes={_settings.ShowUnclimbableSlopes} water={_settings.ShowImpassableWater}");
|
||||
}
|
||||
|
||||
// ── Bridge methods called from PluginExports (engine Avalonia panel) ───────
|
||||
// ── Bridge methods called from PluginExports (engine Vision panels) ───────
|
||||
|
||||
internal string BuildSettingsJson() => _settings.ToJson();
|
||||
|
||||
/// <summary>Applies any subset of the settings keys (panels send one field at a time).</summary>
|
||||
internal void ApplySettingsJson(string json)
|
||||
{
|
||||
_settings.ApplyJson(json);
|
||||
|
|
@ -112,42 +184,31 @@ public sealed class RynthVisionPlugin : RynthPluginBase
|
|||
// where the player actually is on screen (≈ viewport centre).
|
||||
private void LogPose()
|
||||
{
|
||||
if (!Host.TryGetPlayerPose(out uint cellId, out float x, out float y, out float z,
|
||||
out _, out _, out _, out _))
|
||||
{
|
||||
Host.Log("[RynthVision] DBG pose unavailable");
|
||||
return;
|
||||
}
|
||||
|
||||
TickContext ctx = _ctx;
|
||||
float terrainZ = float.NaN;
|
||||
if (_terrain.IsReady && (cellId & 0xFFFF) < 0x100 && (cellId >> 16) != 0)
|
||||
{
|
||||
LandblockData? lb = _terrain.LoadLandblock(cellId >> 16);
|
||||
if (lb != null)
|
||||
terrainZ = lb.GetVertexZ(Math.Clamp((int)(x / 24f), 0, 8), Math.Clamp((int)(y / 24f), 0, 8));
|
||||
}
|
||||
if (ctx.Terrain != null && ctx.Terrain.TryGetTerrainZ(ctx.X, ctx.Y, out float tz))
|
||||
terrainZ = tz;
|
||||
|
||||
// Project the exact ring-centre coords (east=x, up=z, north=y) to screen.
|
||||
string w2s = "n/a";
|
||||
if (Host.HasWorldToScreen && Host.WorldToScreen(x, z, y, out float sx, out float sy))
|
||||
if (Host.HasWorldToScreen && Host.WorldToScreen(ctx.X, ctx.Z, ctx.Y, out float sx, out float sy))
|
||||
w2s = $"({sx:F0},{sy:F0})";
|
||||
Host.TryGetViewportSize(out uint vpW, out uint vpH);
|
||||
|
||||
Host.Log($"[RynthVision] DBG cell=0x{cellId:X8} pose=({x:F1},{y:F1},{z:F1}) terrainZ={terrainZ:F1} w2s={w2s} vp={vpW}x{vpH}");
|
||||
Host.Log($"[RynthVision] DBG cell=0x{ctx.CellId:X8} pose=({ctx.X:F1},{ctx.Y:F1},{ctx.Z:F1}) terrainZ={terrainZ:F1} " +
|
||||
$"landscape={ctx.OnLandscape} w2s={w2s} vp={vpW}x{vpH}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs the terrain-type index at the player's exact cell plus all distinct
|
||||
/// types in the landblock — stand on impassable vs passable water to find
|
||||
/// which indices belong in VisionSettings.WaterTerrainTypes.
|
||||
/// which indices belong in VisionSettings.WaterTerrainTypes. An explicit
|
||||
/// request, so it opens the terrain data if the overlays haven't.
|
||||
/// </summary>
|
||||
internal void InspectTerrain()
|
||||
{
|
||||
if (!_terrain.IsReady)
|
||||
{
|
||||
Host.Log($"[RynthVision] Terrain not ready: {_terrain.Status}");
|
||||
if (!_terrain.IsReady && !InitTerrain())
|
||||
return;
|
||||
}
|
||||
if (!Host.TryGetPlayerPose(out uint cellId, out float px, out float py, out _, out _, out _, out _, out _) ||
|
||||
(cellId & 0xFFFF) >= 0x100 || (cellId >> 16) == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,15 +9,14 @@ namespace RynthCore.Plugin.RynthVision;
|
|||
/// <summary>
|
||||
/// Feature toggles and colours for RynthVision overlays. Colours are ARGB
|
||||
/// (0xAARRGGBB) to match the engine's Nav3D API. Persists to
|
||||
/// %APPDATA%\RynthCore\rynthvision.json; the engine's Avalonia panel reads and
|
||||
/// writes these through the plugin's JSON bridge exports.
|
||||
/// %APPDATA%\RynthCore\rynthvision.json; the engine's Vision panels (ImGui face
|
||||
/// and Avalonia twin) read and write these through the plugin's JSON exports.
|
||||
/// </summary>
|
||||
internal sealed class VisionSettings
|
||||
{
|
||||
public bool ShowRadarRing = true;
|
||||
public bool ShowUnclimbableSlopes = false;
|
||||
public bool ShowImpassableWater = false;
|
||||
public bool ShowDungeonLighting = false;
|
||||
|
||||
public uint SlopeColorArgb = 0x60FF2020; // semi-transparent red
|
||||
public uint WaterColorArgb = 0x600060FF; // semi-transparent blue
|
||||
|
|
@ -30,15 +29,15 @@ internal sealed class VisionSettings
|
|||
// landscape without becoming visually heavy. Default 3 m, range 0.5–30.
|
||||
public float RadarRingHeight = 3.0f;
|
||||
|
||||
// Cell-radius around the player. 1 cell = 24 m. Slopes can extend across
|
||||
// adjacent landblocks (see SlopeOverlay), so values above 8 cross
|
||||
// landblock boundaries and pull in extra terrain data on demand. Default
|
||||
// 12 cells (~288 m) gives roughly one landblock of look-ahead each
|
||||
// direction; 24 cells is the practical max before the triangle budget
|
||||
// becomes the bottleneck.
|
||||
// Cell-radius around the player (1 cell = 24 m, 8 cells per landblock).
|
||||
// The overlays read up to 3 landblocks out in each direction
|
||||
// (LandblockWindow), which covers the whole square for any radius up to
|
||||
// MaxRenderRadius from any cell of the player's landblock. Default 12 cells
|
||||
// (~288 m); 24 is the cap, where the engine's triangle budget (8192) is
|
||||
// already the limit (49×49 cells × 2 triangles for slopes alone).
|
||||
public const int MaxRenderRadius = 24;
|
||||
public int SlopeRenderRadius = 12;
|
||||
// Same cell-radius idea as SlopeRenderRadius — extends across landblock
|
||||
// boundaries when set large. Default 12 matches slopes for parity.
|
||||
// Same cell-radius idea as SlopeRenderRadius. Default 12 matches slopes.
|
||||
public int WaterRenderRadius = 12;
|
||||
|
||||
// Cell normal.Z threshold below which a triangle is treated as
|
||||
|
|
@ -61,33 +60,33 @@ internal sealed class VisionSettings
|
|||
// 0x12 = 18 WaterShallowSea
|
||||
// 0x13 = 19 WaterShallowStillSea
|
||||
// 0x14 = 20 WaterDeepSea
|
||||
// The overlay only paints landblocks whose every vertex is one of these
|
||||
// types ("EntirelyWater" landblocks per ACE LandblockStruct.CalcWater),
|
||||
// because that's exactly the condition AC's LandCell.find_terrain_poly
|
||||
// turns into TransitionState.Collided for a regular character. Partial-
|
||||
// water landblocks rely on per-position depth checks we don't have
|
||||
// surface-Z data for, so we don't speculate.
|
||||
public int[] WaterTerrainTypes = { 0x10, 0x11, 0x12, 0x13, 0x14 };
|
||||
// Landblocks whose every vertex is one of these ("EntirelyWater" per ACE
|
||||
// LandblockStruct.CalcWater) are always painted solid: a regular
|
||||
// character can't enter them. Other water cells follow the two options
|
||||
// below. Replaced (never mutated) on change; WaterOverlay relies on that.
|
||||
// An empty or all-invalid list from the panel resets to these defaults.
|
||||
private static readonly int[] DefaultWaterTerrainTypes = { 0x10, 0x11, 0x12, 0x13, 0x14 };
|
||||
public int[] WaterTerrainTypes = (int[])DefaultWaterTerrainTypes.Clone();
|
||||
|
||||
// Default true: a cell counts as water if ANY of its four corners is a
|
||||
// water-type. With WaterImpassableOnly=true (also default), the cell
|
||||
// additionally needs a too-steep triangle — so the visible result is
|
||||
// "shoreline cells where the seafloor drops below walkable angle", i.e.
|
||||
// the actual spots AC blocks you. all-four-corners was too strict at
|
||||
// typical shorelines where only 1-2 vertices fall in deep water.
|
||||
// Outside fully-water landblocks: true = a cell is water if ANY of its
|
||||
// four corners is a water type (catches shorelines, where often only 1-2
|
||||
// vertices are water); false = only when all four corners are.
|
||||
public bool WaterAnyCorner = true;
|
||||
|
||||
// When true, the water overlay only paints cells that are BOTH water
|
||||
// AND have an unwalkable triangle (steep underwater slope). That's
|
||||
// the actual "impassable water" — the deep parts where AC's slope
|
||||
// physics blocks you at the shore drop-off. When false, every cell
|
||||
// matching WaterTerrainTypes is painted regardless of walkability —
|
||||
// useful as a "where is water" awareness overlay but does not signal
|
||||
// impassability. Uses SlopeFloorZ as the steepness threshold.
|
||||
// Outside fully-water landblocks: true = paint only the water cells'
|
||||
// unwalkable triangles (normal Z below SlopeFloorZ) — the seafloor
|
||||
// drop-offs AC's slope physics blocks, i.e. water that is certainly
|
||||
// impassable (AC's wading depth check needs a water surface height the
|
||||
// dats don't give us). false = paint every water cell: a "where is
|
||||
// water" view that doesn't signal impassability.
|
||||
public bool WaterImpassableOnly = true;
|
||||
|
||||
// ── JSON bridge (manual build + JsonDocument parse — both AOT-safe) ───────
|
||||
|
||||
/// <summary>
|
||||
/// Every setting. <see cref="ApplyJson"/> takes any subset of these keys,
|
||||
/// so a panel can send just the field that changed.
|
||||
/// </summary>
|
||||
public string ToJson()
|
||||
{
|
||||
var ci = CultureInfo.InvariantCulture;
|
||||
|
|
@ -134,14 +133,11 @@ internal sealed class VisionSettings
|
|||
{
|
||||
var list = new List<int>();
|
||||
foreach (var e in v.EnumerateArray())
|
||||
if (e.TryGetInt32(out int n)) list.Add(n);
|
||||
// Self-heal: an earlier version of the panel could push an empty
|
||||
// array on first-edit (Populate race) which then persisted. An
|
||||
// empty array means "match nothing" → no water ever painted. If
|
||||
// the JSON has zero entries, keep the constructor defaults
|
||||
// instead so the overlay works out-of-the-box.
|
||||
if (list.Count > 0)
|
||||
WaterTerrainTypes = list.ToArray();
|
||||
if (e.TryGetInt32(out int n) && n >= 0 && n <= 31 && !list.Contains(n)) list.Add(n);
|
||||
// An empty (or all-invalid) list would match nothing and paint no
|
||||
// water ever, so it means "back to the defaults". The panels then
|
||||
// re-read the settings and show the defaults.
|
||||
WaterTerrainTypes = list.Count > 0 ? list.ToArray() : (int[])DefaultWaterTerrainTypes.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue