acdream/tests/AcDream.Core.Tests/Conformance/RetailTrace.cs
Erik b35e491f12 test(p0): retail find_cell_list trace parser + cdb value-capture tooling
P0 Task 5. RetailTrace parses the [fcl] golden format (seed/pos/picked,
RetailCellPick); 4 TDD tests green. find-cell-list-capture.cdb targets
CPhysicsObj::change_cell (commit-on-diff) to capture retail's accepted
membership sequence at the doorway; README is the operator runbook
(dt offset verification + decode_retail_hex float decode). The live run
is P0's one user-gated step (Task 6 mines existing traces first).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 14:26:24 +02:00

52 lines
2 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Numerics;
using System.Text.RegularExpressions;
namespace AcDream.Core.Tests.Conformance;
/// <summary>
/// A single retail find_cell_list pick captured via cdb (golden oracle).
/// <paramref name="SeedCellId"/> is the seed/current cell at find_cell_list
/// entry; <paramref name="PickedCellId"/> is the chosen containing cell
/// (retail <c>*arg5</c> in CObjCell::find_cell_list @ 0x52b4e0 pc:308742).
/// </summary>
public sealed record RetailCellPick(uint SeedCellId, Vector3 Position, uint PickedCellId);
/// <summary>Parser for the <c>find-cell-list-capture.cdb</c> log format.</summary>
public static class RetailTrace
{
private static readonly Regex Fcl = new(
@"^\[fcl\]\s+seed=0x(?<seed>[0-9A-Fa-f]{1,8})\s+" +
@"px=(?<px>-?\d+(\.\d+)?)\s+py=(?<py>-?\d+(\.\d+)?)\s+pz=(?<pz>-?\d+(\.\d+)?)\s+" +
@"picked=0x(?<picked>[0-9A-Fa-f]{1,8})\s*$",
RegexOptions.Compiled);
public static RetailCellPick? ParseFindCellList(string line)
{
if (string.IsNullOrEmpty(line)) return null;
var m = Fcl.Match(line);
if (!m.Success) return null;
var ci = CultureInfo.InvariantCulture;
return new RetailCellPick(
SeedCellId: Convert.ToUInt32(m.Groups["seed"].Value, 16),
Position: new Vector3(
float.Parse(m.Groups["px"].Value, ci),
float.Parse(m.Groups["py"].Value, ci),
float.Parse(m.Groups["pz"].Value, ci)),
PickedCellId: Convert.ToUInt32(m.Groups["picked"].Value, 16));
}
/// <summary>Parse a log, skipping every non-matching line (noise/banner/other BPs).</summary>
public static IReadOnlyList<RetailCellPick> ParseAll(IEnumerable<string> lines)
{
var list = new List<RetailCellPick>();
foreach (var line in lines)
{
var rec = ParseFindCellList(line);
if (rec is not null) list.Add(rec);
}
return list;
}
}