Tuning Knobs
This commit is contained in:
@@ -38,6 +38,8 @@ namespace ProjectM.Client
|
||||
public static void Kill() => Send(DebugOp.KillPlayer);
|
||||
public static void AdvanceGoal(int by) => Send(DebugOp.AdvanceGoal, by);
|
||||
public static void SetHeat(int heat) => Send(DebugOp.SetHeat, heat);
|
||||
/// <summary>Set the <see cref="ProjectM.Simulation.TuningKnob"/> knob to value (server-applied, x1000 fixed-point; MC-0).</summary>
|
||||
public static void SetTuning(byte knob, float value) => Send(DebugOp.SetTuning, knob, Mathf.RoundToInt(value * 1000f));
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void ResetOnEnterPlayMode() => s_Pending.Clear();
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace ProjectM.Client
|
||||
bool _open = true;
|
||||
int _siegeSize = 5;
|
||||
int _grantAmount = 50;
|
||||
bool _tuningOpen;
|
||||
Vector2 _scroll;
|
||||
|
||||
void OnDisable() => AimPresentation.ForceCursorVisible = false;
|
||||
|
||||
@@ -29,8 +31,10 @@ namespace ProjectM.Client
|
||||
if (!_open)
|
||||
return;
|
||||
|
||||
GUILayout.BeginArea(new Rect(Screen.width - 232, 40, 222, 540), GUI.skin.box);
|
||||
float panelH = Mathf.Min(760f, Screen.height - 50f);
|
||||
GUILayout.BeginArea(new Rect(Screen.width - 232, 40, 222, panelH), GUI.skin.box);
|
||||
GUILayout.Label("DEV TOOLS");
|
||||
_scroll = GUILayout.BeginScrollView(_scroll);
|
||||
|
||||
GUILayout.Label("- World -");
|
||||
_siegeSize = IntField("Siege size", _siegeSize);
|
||||
@@ -76,6 +80,23 @@ namespace ProjectM.Client
|
||||
GUILayout.Label("(waiting for server telemetry...)");
|
||||
}
|
||||
|
||||
GUILayout.Space(6);
|
||||
_tuningOpen = GUILayout.Toggle(_tuningOpen, "- Tuning (MC-0) -");
|
||||
if (_tuningOpen)
|
||||
{
|
||||
TuningRow("Dash dist", TuningKnob.DashDistance, 0.5f, "0.0");
|
||||
TuningRow("Dash iframe t", TuningKnob.IFrameWindowTicks, 1f, "0");
|
||||
TuningRow("Dash recover t", TuningKnob.RecoverTailTicks, 1f, "0");
|
||||
TuningRow("Dash cd t", TuningKnob.DashCooldownTicks, 1f, "0");
|
||||
TuningRow("Dash sharp", TuningKnob.DashSharpness, 25f, "0");
|
||||
TuningRow("Chgr windup t", TuningKnob.ChargerWindupTicks, 1f, "0");
|
||||
TuningRow("Chgr lunge spd", TuningKnob.ChargerLungeSpeed, 1f, "0.0");
|
||||
TuningRow("Chgr lunge t", TuningKnob.ChargerLungeDurationTicks, 1f, "0");
|
||||
TuningRow("Chgr stagger t", TuningKnob.ChargerWhiffStaggerTicks, 1f, "0");
|
||||
TuningRow("Grunt windup t", TuningKnob.GruntWindupTicks, 1f, "0");
|
||||
}
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
@@ -87,6 +108,25 @@ namespace ProjectM.Client
|
||||
GUILayout.EndHorizontal();
|
||||
return int.TryParse(s, out var v) ? v : value;
|
||||
}
|
||||
|
||||
// One live-tuning row: shows the current value (from the readout) + step buttons. A nudge fires the
|
||||
// authoritative server RPC AND an optimistic local apply (so the tuner's own predicted dash uses it now).
|
||||
static void TuningRow(string label, byte knob, float step, string fmt)
|
||||
{
|
||||
float cur = ProjectM.Simulation.TuningConfig.Get(TuningReadout.Current, knob);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(label, GUILayout.Width(92));
|
||||
GUILayout.Label(cur.ToString(fmt), GUILayout.Width(40));
|
||||
if (GUILayout.Button("-", GUILayout.Width(26))) Nudge(knob, cur - step);
|
||||
if (GUILayout.Button("+", GUILayout.Width(26))) Nudge(knob, cur + step);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
static void Nudge(byte knob, float value)
|
||||
{
|
||||
DebugCommandSendSystem.SetTuning(knob, value); // authoritative (server applies + broadcasts; clamped)
|
||||
TuningReadout.SetLocal(knob, value); // optimistic local (instant feel for the tuner; clamped)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#if UNITY_EDITOR
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// MC-0 — EDITOR-ONLY client owner of the local <see cref="TuningConfig"/> singleton (the value the PREDICTED
|
||||
/// DashSystem reads on this client). Each tick it (1) drains any authoritative <see cref="DebugTuningReport"/>
|
||||
/// into the <see cref="TuningReadout"/> static, then (2) pushes <see cref="TuningReadout.Current"/> into the
|
||||
/// client TuningConfig singleton. The overlay mutates the readout OPTIMISTICALLY via
|
||||
/// <see cref="TuningReadout.SetLocal"/> (so the tuner's own dash uses a nudged value instantly — instant, then
|
||||
/// EVENTUALLY CONSISTENT with the server within ~1 RTT once the SetTuning RPC lands and the next report
|
||||
/// reconciles). Runs EVERY tick (no RequireForUpdate) so an overlay-only change with no report still reaches the
|
||||
/// singleton. Plain client <see cref="SimulationSystemGroup"/> (mutated at most once/tick → the predicted
|
||||
/// re-sim reads a per-tick-constant value); non-Burst (touches a managed static). This DELIBERATELY extends the
|
||||
/// DevTelemetry pattern (which writes only a static) with a per-world singleton; the release path has no such
|
||||
/// system, so DashSystem's <c>TryGetSingleton ? : Defaults()</c> fallback is the permanent release behaviour.
|
||||
/// </summary>
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
||||
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||
public partial struct DevTuningReceiveSystem : ISystem
|
||||
{
|
||||
public void OnCreate(ref SystemState state)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// (1) Authoritative server snapshot wins — overwrite the readout (FULL state).
|
||||
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
||||
foreach (var (report, reqEntity) in
|
||||
SystemAPI.Query<RefRO<DebugTuningReport>>()
|
||||
.WithAll<ReceiveRpcCommandRequest>().WithEntityAccess())
|
||||
{
|
||||
TuningReadout.Current = TuningConfig.FromReport(report.ValueRO);
|
||||
TuningReadout.Initialized = true;
|
||||
ecb.DestroyEntity(reqEntity);
|
||||
}
|
||||
ecb.Playback(state.EntityManager);
|
||||
ecb.Dispose();
|
||||
|
||||
// (2) Push the readout (authoritative, or optimistic SetLocal, or Defaults()) into the client singleton.
|
||||
if (SystemAPI.TryGetSingletonEntity<TuningConfig>(out var cfgEntity))
|
||||
state.EntityManager.SetComponentData(cfgEntity, TuningReadout.Current);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MC-0 — static bridge from the ECS tuning receiver to the IMGUI <c>DebugOverlay</c> (so the overlay reads/sets
|
||||
/// a plain struct, never ECS state). <see cref="Current"/> seeds to <see cref="TuningConfig.Defaults"/> on
|
||||
/// play-enter (so it matches the server's seeded Defaults before the first report). <see cref="SetLocal"/> is the
|
||||
/// overlay's OPTIMISTIC apply — it runs the same <see cref="TuningConfig.Apply"/> clamp so an overlay nudge can
|
||||
/// never feed a 0/negative into the predicted DashSystem.
|
||||
/// </summary>
|
||||
public static class TuningReadout
|
||||
{
|
||||
public static TuningConfig Current;
|
||||
|
||||
/// <summary>True once an authoritative server report has been received (else <see cref="Current"/> is Defaults()).</summary>
|
||||
public static bool Initialized;
|
||||
|
||||
/// <summary>Optimistic local apply (overlay button) — clamped via <see cref="TuningConfig.Apply"/>.</summary>
|
||||
public static void SetLocal(byte knob, float value) => TuningConfig.Apply(ref Current, knob, value);
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void Reset()
|
||||
{
|
||||
Current = TuningConfig.Defaults();
|
||||
Initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f4b5a00778a9f44f8c07543d471beb6
|
||||
Reference in New Issue
Block a user