using Unity.Burst;
using Unity.Entities;
using Unity.NetCode;
namespace ProjectM.Simulation
{
///
/// Bridges replicated + data-driven into
/// the CC processor's per-tick . Replaces the M5 PlayerMoveSystem:
/// instead of writing PhysicsVelocity, it writes the desired world velocity that
/// lerps toward inside the fixed-step character update. Runs in
/// after (fresh MoveSpeed)
/// and before the predicted fixed-step group (where the character physics steps). Derived purely from
/// replicated input + recomputed stats → identical on server, owning client, and across rollback.
/// Filtered to for predicted ghosts only.
///
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
[UpdateAfter(typeof(StatRecomputeSystem))]
[BurstCompile]
public partial struct PlayerControlSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
foreach (var (control, input, stats) in
SystemAPI.Query, RefRO, RefRO>()
.WithAll().WithDisabled())
{
control.ValueRW.MoveVelocity =
CharacterControlMath.DesiredMovement(input.ValueRO.Move, stats.ValueRO.MoveSpeed);
}
}
}
}