Drive Move proof surface from runtime ring

This commit is contained in:
Meta Vens 2026-07-08 22:49:42 +01:00
commit 20a296a4a9
7 changed files with 320 additions and 6 deletions

View file

@ -3,6 +3,7 @@ using System.Numerics;
using System.Security.Cryptography;
using System.Text.Json;
using Aquarium.Engine;
using Aquarium.Engine.Input;
using GameCult.Caching;
using GameCult.Caching.MessagePack;
using GameCult.Mesh;
@ -153,6 +154,12 @@ if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-frame-smoke", Strin
return RunMoveProofRuntimeFrameSmoke();
}
if (args.Any(arg => string.Equals(arg, "--move-proof-runtime-driver-smoke", StringComparison.OrdinalIgnoreCase)))
{
return RunMoveProofRuntimeDriverSmoke(
ParseStringOption(args, "--native-reservoir", DefaultNativeReservoirPath()));
}
if (args.Any(arg => string.Equals(arg, "--move-calibration-protocol-smoke", StringComparison.OrdinalIgnoreCase)))
{
return await RunMoveCalibrationProtocolSmokeAsync(
@ -2234,7 +2241,7 @@ static int RunMoveProofRuntimeFrameSmoke()
{
var surface = CreateMoveProofSurfaceSmokeDocument();
var runtime = new MimirRuntime(
new AquariumRuntimeOptions(Headless: true, CultCachePath: null),
new AquariumRuntimeOptions(Headless: true, CultCachePath: ""),
new MimirSynchronizationSettings());
var emptyFrame = runtime.Frame;
runtime.PublishMoveProofSurface(surface);
@ -2256,6 +2263,154 @@ static int RunMoveProofRuntimeFrameSmoke()
: 1;
}
static int RunMoveProofRuntimeDriverSmoke(string nativeReservoirPath)
{
if (!File.Exists(nativeReservoirPath))
{
Console.Error.WriteLine($"move-proof-runtime-driver-smoke missing-native path={nativeReservoirPath}");
return 1;
}
const ulong leftWitnessHash = 0x00000000000A11CE;
const ulong rightWitnessHash = 0x0000000000000B0B;
const string observedAt = "2026-06-11T18:30:00.0040000Z";
var streamId = "muninn:nightwing:move-evidence";
var frame = new MimirMuninnMoveEvidenceStreamFrame(
FrameId: "muninn:nightwing:move-evidence:79",
ProducerPeerId: "muninn:nightwing",
PublishedAtNs: 1_781_202_600_005_000_000,
MarkerCandidates:
[
new MuninnMoveMarkerCandidateDocument(
StreamId: "nightwing:ps3-eye-0:move-marker-candidates",
HostId: "nightwing",
CameraId: "ps3-eye-0",
FrameSequence: 9101,
SourceIdHash: leftWitnessHash,
TileX: 10,
TileY: 10,
CenterXPx: 170.0f,
CenterYPx: 120.0f,
RadiusPx: 12.0f,
AreaPx: 452,
MeanLuma: 0.64f,
PeakLuma: 252,
Score: 0.90f,
ObservedAt: observedAt),
new MuninnMoveMarkerCandidateDocument(
StreamId: "starfire:ps3-eye-1:move-marker-candidates",
HostId: "starfire",
CameraId: "ps3-eye-1",
FrameSequence: 9102,
SourceIdHash: rightWitnessHash,
TileX: 11,
TileY: 10,
CenterXPx: 150.0f,
CenterYPx: 120.0f,
RadiusPx: 12.0f,
AreaPx: 449,
MeanLuma: 0.62f,
PeakLuma: 250,
Score: 0.86f,
ObservedAt: observedAt)
],
ControllerStates:
[
new MuninnMoveControllerStateDocument(
StreamId: "nightwing:move-usb:move-controller-state",
HostId: "nightwing",
MoveId: "move-usb",
Sequence: 79,
SourceTimestampNs: 1_781_202_600_004_000_000,
AccelerometerXyz: [-0.01f, 0.10f, 0.99f],
GyroscopeXyz: [0.02f, -0.01f, 0.04f],
MagnetometerXyz: [0.0f, 0.0f, 0.0f],
TriggerValue: 0.5f,
Buttons: ["move", "trigger"],
Battery01: 0.72f,
ObservedAt: observedAt)
]);
var calibration = new MimirMoveFusionRigCalibration(
CalibrationId: "mimir-move-stage-calibration-v1",
TrackingSpaceId: "mimir-stage-space",
Cameras:
[
new MimirMoveFusionCameraCalibration(
CameraId: "nightwing:ps3-eye-0",
WitnessIdHash: leftWitnessHash,
PositionMeters: new MimirVector3Snapshot(-0.1, 0.0, 0.0),
Orientation: new MimirQuaternionSnapshot(0.0, 0.0, 0.0, 1.0),
FocalLengthXPx: 100.0,
FocalLengthYPx: 100.0,
PrincipalPointXPx: 160.0,
PrincipalPointYPx: 120.0),
new MimirMoveFusionCameraCalibration(
CameraId: "starfire:ps3-eye-1",
WitnessIdHash: rightWitnessHash,
PositionMeters: new MimirVector3Snapshot(0.1, 0.0, 0.0),
Orientation: new MimirQuaternionSnapshot(0.0, 0.0, 0.0, 1.0),
FocalLengthXPx: 100.0,
FocalLengthYPx: 100.0,
PrincipalPointXPx: 160.0,
PrincipalPointYPx: 120.0)
],
MaximumAssociationSkewMilliseconds: 20.0);
var catalog = CultMesh.CreateStreamCatalog();
catalog.Declare(MimirMuninnMoveEvidenceAdapter.CreateStreamDescriptor(
streamId,
"mimir-live",
"muninn:nightwing",
"nightwing:clock"));
using var ring = catalog.CreateSharedMemoryRing(streamId, slotCount: 4, slotByteLength: 8192);
var payload = MimirMuninnMoveEvidenceAdapter.SerializeStreamFrame(frame);
if (!ring.TryPublishCopy(payload, frame.PublishedAtNs, durationNs: 0, out var published))
{
Console.Error.WriteLine("move-proof-runtime-driver-smoke publish-failed");
return 1;
}
catalog.PublishFrame(published);
using var reservoir = new MimirNativeReservoirRuntime(nativeReservoirPath);
var driver = new MimirMoveProofRuntimeDriver(
ring,
reservoir,
calibration,
new MimirMoveProofRuntimeDriverOptions(
MimirEvidenceSourceId: "mimir:starfire:move-evidence",
MimirEvidenceFramePrefix: "mimir:starfire:move-evidence",
MimirPoseFramePrefix: "mimir:starfire:move-pose",
MimirPoseProducerPeerId: "mimir:starfire",
FensalirFramePrefix: "fensalir:starfire:presented-frame"));
var runtime = new MimirRuntime(
new AquariumRuntimeOptions(Headless: true, CultCachePath: ""),
new MimirSynchronizationSettings());
runtime.RegisterMoveProofDriver(driver);
runtime.OnSceneReady();
var input = new InputState();
runtime.Update(0.016f, input);
var proofFrame = runtime.Frame;
var proofSurface = driver.LastResult?.ProofSurface;
var proofSplineCount = proofFrame.Scene.SplineFrame.Splines.Count(spline =>
spline.Id.StartsWith("move-proof-", StringComparison.Ordinal));
runtime.Update(0.016f, input);
var duplicateSuppressed = reservoir.Status.MoveEvidenceCount.ToUInt64() == 1UL;
Console.WriteLine(
$"move-proof-runtime-driver-smoke proof={proofSurface?.ProofId ?? "none"} chain={proofSurface?.MuninnEvidenceFrameId ?? "none"}->{proofSurface?.MimirEvidenceFrameId ?? "none"}->{proofSurface?.MimirPoseFrameId ?? "none"}->{proofSurface?.FensalirFrameId ?? "none"} verdict={proofSurface?.Verdict.ToString() ?? "none"} splines={proofSplineCount} duplicateSuppressed={duplicateSuppressed}");
return proofSurface is not null &&
proofSurface.IsFullPose &&
proofSurface.MuninnEvidenceFrameId == "muninn:nightwing:move-evidence:79" &&
proofSurface.MimirEvidenceFrameId == "mimir:starfire:move-evidence:79" &&
proofSurface.MimirPoseFrameId == "mimir:starfire:move-pose:79" &&
proofSurface.FensalirFrameId == "fensalir:starfire:presented-frame:79" &&
proofFrame.Scene.SplineFrame.HasInput &&
proofSplineCount >= 3 &&
duplicateSuppressed
? 0
: 1;
}
static MimirMoveProofSurfaceDocument CreateMoveProofSurfaceSmokeDocument()
{
var pose = new MimirMoveControllerPoseDocument(

View file

@ -62,6 +62,7 @@ direct
private IReadOnlyList<MimirAudioSynchronizationReport> lastAudioSynchronizationReports = [];
private IReadOnlyList<MimirAudioSpectrumSnapshot> lastAudioSpectra = [];
private readonly Queue<IReadOnlyList<MimirAudioSpectrumSnapshot>> spectrumHistory = new();
private readonly List<MimirMoveProofRuntimeDriver> moveProofDrivers = [];
private MimirMoveProofSurfaceDocument? latestMoveProofSurface;
public MimirRuntime(AquariumRuntimeOptions options)
@ -181,6 +182,12 @@ direct
latestMoveProofSurface = null;
}
public void RegisterMoveProofDriver(MimirMoveProofRuntimeDriver driver)
{
ArgumentNullException.ThrowIfNull(driver);
moveProofDrivers.Add(driver);
}
public static AquariumSplineFrame ComposeFensalirSplineFrame(
AquariumSplineFrame baseFrame,
MimirMoveProofSurfaceDocument? moveProofSurface)
@ -223,6 +230,7 @@ direct
runtimeSeconds += Math.Max(deltaSeconds, 0.0f);
lastPollCount = synchronization.PollSources();
UpdateMoveProofSurfaces();
QueueCalibrationTimeline();
UpdateAudioSpectra();
UpdateAudioSynchronization();
@ -275,6 +283,7 @@ direct
panel.Readout("Chirplet reference", DescribeChirpletReference);
panel.Section("Move Proof");
panel.Readout("Latest proof", DescribeMoveProofSurface);
panel.Readout("Proof drivers", DescribeMoveProofDrivers);
panel.Section("Live FFT");
panel.Readout("Spectrum cadence", () => sceneReady
? $"{lastAudioSpectra.Count} spectra fft={lastAudioSpectra.FirstOrDefault()?.FftSize ?? 0} analyze={lastSpectrumAnalysisMilliseconds:0.00}ms"
@ -301,6 +310,41 @@ direct
return $"{surface.ProofId} verdict={surface.Verdict} confidence={surface.PoseConfidence:0.000} latency={surface.LatencyMilliseconds:0.00}ms chain={surface.MuninnEvidenceFrameId}->{surface.MimirEvidenceFrameId}->{surface.MimirPoseFrameId}->{surface.FensalirFrameId}";
}
private string DescribeMoveProofDrivers()
{
if (moveProofDrivers.Count == 0)
{
return "No Move proof runtime drivers registered.";
}
return string.Join(Environment.NewLine, moveProofDrivers.Select(driver => driver.Describe()));
}
private void UpdateMoveProofSurfaces()
{
if (moveProofDrivers.Count == 0)
{
return;
}
var presentedAtNs = NowUnixNs();
foreach (var driver in moveProofDrivers)
{
if (driver.TryBuildLatest(presentedAtNs, out var result) && result is not null)
{
PublishMoveProofSurface(result.ProofSurface);
}
}
}
private static ulong NowUnixNs()
{
var now = DateTimeOffset.UtcNow;
var secondsNs = checked((ulong)now.ToUnixTimeSeconds() * 1_000_000_000UL);
var tickRemainderNs = checked((ulong)(now.Ticks % TimeSpan.TicksPerSecond) * 100UL);
return checked(secondsNs + tickRemainderNs);
}
private static AquariumRenderPlan CreateRenderPlan()
{
var app = new AquariumApp();

View file

@ -0,0 +1,94 @@
using GameCult.Mesh;
namespace Mimir.Runtime.Synchronization;
public sealed record MimirMoveProofRuntimeDriverOptions(
string MimirEvidenceSourceId,
string MimirEvidenceFramePrefix,
string MimirPoseFramePrefix,
string MimirPoseProducerPeerId,
string FensalirFramePrefix,
string FusionAuthorityId = "mimir.runtime.move-fusion",
string ConsumerContract = "fensalir.move-controller-input");
public sealed class MimirMoveProofRuntimeDriver
{
private readonly CultMeshSharedMemoryFrameRing ring;
private readonly MimirNativeReservoirRuntime reservoir;
private readonly MimirMoveFusionRigCalibration calibration;
private readonly MimirMoveProofRuntimeDriverOptions options;
private string lastFrameId = "";
public MimirMoveProofRuntimeDriver(
CultMeshSharedMemoryFrameRing ring,
MimirNativeReservoirRuntime reservoir,
MimirMoveFusionRigCalibration calibration,
MimirMoveProofRuntimeDriverOptions options)
{
this.ring = ring ?? throw new ArgumentNullException(nameof(ring));
this.reservoir = reservoir ?? throw new ArgumentNullException(nameof(reservoir));
this.calibration = calibration ?? throw new ArgumentNullException(nameof(calibration));
this.options = options ?? throw new ArgumentNullException(nameof(options));
ArgumentException.ThrowIfNullOrWhiteSpace(options.MimirEvidenceSourceId);
ArgumentException.ThrowIfNullOrWhiteSpace(options.MimirEvidenceFramePrefix);
ArgumentException.ThrowIfNullOrWhiteSpace(options.MimirPoseFramePrefix);
ArgumentException.ThrowIfNullOrWhiteSpace(options.MimirPoseProducerPeerId);
ArgumentException.ThrowIfNullOrWhiteSpace(options.FensalirFramePrefix);
}
public MimirMoveProofPipelineResult? LastResult { get; private set; }
public bool TryBuildLatest(ulong fensalirPresentedAtNs, out MimirMoveProofPipelineResult? result)
{
result = null;
if (!ring.TryAcquireLatestRead(out var lease))
{
return false;
}
using (lease)
{
var frame = MimirMuninnMoveEvidenceAdapter.DeserializeStreamFrame(lease.Memory[..lease.Handle.ByteLength]);
if (string.Equals(frame.FrameId, lastFrameId, StringComparison.Ordinal))
{
return false;
}
var sequence = SequenceSuffix(frame.FrameId);
var pipelineOptions = new MimirMoveProofPipelineOptions(
MimirEvidenceSourceId: options.MimirEvidenceSourceId,
MimirEvidenceFrameId: $"{options.MimirEvidenceFramePrefix}:{sequence}",
MimirPoseFrameId: $"{options.MimirPoseFramePrefix}:{sequence}",
MimirPoseProducerPeerId: options.MimirPoseProducerPeerId,
FensalirFrameId: $"{options.FensalirFramePrefix}:{sequence}",
FensalirPresentedAtNs: fensalirPresentedAtNs,
FusionAuthorityId: options.FusionAuthorityId,
ConsumerContract: options.ConsumerContract);
if (!MimirMoveProofPipeline.TryBuild(frame, reservoir, calibration, pipelineOptions, out result))
{
return false;
}
lastFrameId = frame.FrameId;
LastResult = result;
return true;
}
}
public string Describe()
{
var last = LastResult?.ProofSurface;
return last is null
? $"{options.MimirEvidenceSourceId} waiting"
: $"{last.ProofId} verdict={last.Verdict} chain={last.MuninnEvidenceFrameId}->{last.MimirEvidenceFrameId}->{last.MimirPoseFrameId}->{last.FensalirFrameId}";
}
private static string SequenceSuffix(string frameId)
{
var separator = frameId.LastIndexOf(':');
return separator >= 0 && separator < frameId.Length - 1
? frameId[(separator + 1)..]
: frameId;
}
}