Files
Project-M/Assets/_Project/Scripts/Client/Debug/DevTelemetryReceiveSystem.cs
T
2026-06-09 23:26:20 -07:00

79 lines
3.0 KiB
C#

#if UNITY_EDITOR
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
namespace ProjectM.Client
{
/// <summary>
/// MC-0 — EDITOR-ONLY client receiver for the periodic <see cref="ProjectM.Simulation.DebugTelemetryReport"/>.
/// Drains the snapshot into <see cref="DevTelemetryReadout"/> (a plain static) so the IMGUI <c>DebugOverlay</c>
/// reads NO ECS state directly (the job-safety rule for presentation). Plain client
/// <see cref="SimulationSystemGroup"/>; non-Burst (touches a managed static).
/// </summary>
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial struct DevTelemetryReceiveSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll<ProjectM.Simulation.DebugTelemetryReport, ReceiveRpcCommandRequest>();
state.RequireForUpdate(state.GetEntityQuery(builder));
}
public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Allocator.Temp);
foreach (var (report, reqEntity) in
SystemAPI.Query<RefRO<ProjectM.Simulation.DebugTelemetryReport>>()
.WithAll<ReceiveRpcCommandRequest>().WithEntityAccess())
{
var r = report.ValueRO;
DevTelemetryReadout.Latest = new DevTelemetryReadout.Snapshot
{
DashIFrameNegatedHits = r.DashIFrameNegatedHits,
DashesWasted = r.DashesWasted,
ChargerWhiffWindowsOpened = r.ChargerWhiffWindowsOpened,
ChargerWhiffPunishesLanded = r.ChargerWhiffPunishesLanded,
LiveEnemyCount = r.LiveEnemyCount,
LastSampleTick = r.LastSampleTick,
};
DevTelemetryReadout.HasData = true;
ecb.DestroyEntity(reqEntity);
}
ecb.Playback(state.EntityManager);
ecb.Dispose();
}
}
/// <summary>
/// MC-0 — static bridge from the ECS telemetry receiver to the IMGUI <c>DebugOverlay</c> (so the overlay reads
/// a plain struct, never ECS state). Reset on play-enter so a fast-enter-playmode reload can't show stale data.
/// </summary>
public static class DevTelemetryReadout
{
public struct Snapshot
{
public uint DashIFrameNegatedHits;
public uint DashesWasted;
public uint ChargerWhiffWindowsOpened;
public uint ChargerWhiffPunishesLanded;
public uint LiveEnemyCount;
public uint LastSampleTick;
}
public static Snapshot Latest;
public static bool HasData;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Reset()
{
Latest = default;
HasData = false;
}
}
}
#endif