60 lines
2.7 KiB
C#
60 lines
2.7 KiB
C#
#if UNITY_EDITOR
|
|
using ProjectM.Simulation;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.NetCode;
|
|
|
|
namespace ProjectM.Server
|
|
{
|
|
/// <summary>
|
|
/// MC-0 — EDITOR-ONLY server owner of the authoritative <see cref="TuningConfig"/> singleton. Ensures+seeds it
|
|
/// to <see cref="TuningConfig.Defaults"/> in OnCreate, then every <see cref="BroadcastPeriodTicks"/> ships the
|
|
/// FULL config to every connection as a <see cref="DebugTuningReport"/> (so a PREDICTING client's DashSystem —
|
|
/// including an MPPM thin client that has no overlay — converges on the tuned values; full state, not a delta,
|
|
/// so a late-joiner converges in one report). The singleton is mutated by <c>DebugCommandReceiveSystem</c>'s
|
|
/// SetTuning op (same plain server group). Verbatim <c>DevTelemetrySystem</c> shape. Plain server
|
|
/// <see cref="SimulationSystemGroup"/> (NOT the predicted loop); non-Burst (managed-simple, editor-only).
|
|
/// Stripped from builds; the wire TYPE <see cref="DebugTuningReport"/> + <see cref="TuningConfig"/> are
|
|
/// unconditional, so in a release build no system creates the singleton and consumers fall back to Defaults().
|
|
/// </summary>
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
|
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
|
public partial struct TuningBroadcastSystem : ISystem
|
|
{
|
|
const uint BroadcastPeriodTicks = 15;
|
|
|
|
public void OnCreate(ref SystemState state)
|
|
{
|
|
state.RequireForUpdate<NetworkTime>();
|
|
if (state.GetEntityQuery(ComponentType.ReadWrite<TuningConfig>()).IsEmpty)
|
|
{
|
|
var e = state.EntityManager.CreateEntity(typeof(TuningConfig));
|
|
state.EntityManager.SetComponentData(e, TuningConfig.Defaults());
|
|
}
|
|
}
|
|
|
|
public void OnUpdate(ref SystemState state)
|
|
{
|
|
var serverTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
|
|
if (!serverTick.IsValid)
|
|
return;
|
|
uint now = serverTick.TickIndexForValidTick;
|
|
if (now == 0 || (now % BroadcastPeriodTicks) != 0)
|
|
return;
|
|
|
|
var report = TuningConfig.ToReport(SystemAPI.GetSingleton<TuningConfig>());
|
|
|
|
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
|
foreach (var (netId, connEnt) in SystemAPI.Query<RefRO<NetworkId>>().WithEntityAccess())
|
|
{
|
|
var req = ecb.CreateEntity();
|
|
ecb.AddComponent(req, report);
|
|
ecb.AddComponent(req, new SendRpcCommandRequest { TargetConnection = connEnt });
|
|
}
|
|
ecb.Playback(state.EntityManager);
|
|
ecb.Dispose();
|
|
}
|
|
}
|
|
}
|
|
#endif
|