Run Re-Do
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side ready-toggle sender: a static enqueue (HUD button at Step 14 / the T dev key / execute_code)
|
||||
/// drained into <see cref="ReadyToggleRequest"/> RPC entities — the BuildSendSystem queue+drain idiom. The local
|
||||
/// bool tracks only the toggle DIRECTION; the server-replicated <see cref="PlayerReady"/> is the truth the HUD
|
||||
/// renders. Statics reset on play-enter (statics survive fast-enter-playmode reloads — the stale-bridge hazard).
|
||||
/// </summary>
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
||||
public partial class ReadySendSystem : SystemBase
|
||||
{
|
||||
static int s_Pending; // queued explicit sets
|
||||
static byte s_PendingValue;
|
||||
static bool s_LocalReady; // last requested state (toggle direction only, not authority)
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void ResetStatics()
|
||||
{
|
||||
s_Pending = 0;
|
||||
s_PendingValue = 0;
|
||||
s_LocalReady = false;
|
||||
}
|
||||
|
||||
/// <summary>Queue an explicit ready set (HUD button / execute_code).</summary>
|
||||
public static void SetReady(bool ready)
|
||||
{
|
||||
s_PendingValue = (byte)(ready ? 1 : 0);
|
||||
s_Pending++;
|
||||
s_LocalReady = ready;
|
||||
}
|
||||
|
||||
/// <summary>Queue a toggle of the last requested state (the T dev key; HUD replaces this at Step 14).</summary>
|
||||
public static void ToggleReady() => SetReady(!s_LocalReady);
|
||||
|
||||
protected override void OnCreate()
|
||||
{
|
||||
RequireForUpdate<NetworkId>();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
var keyboard = UnityEngine.InputSystem.Keyboard.current;
|
||||
if (keyboard != null && keyboard.tKey.wasPressedThisFrame && !PauseMenuController.Open)
|
||||
ToggleReady();
|
||||
|
||||
while (s_Pending > 0)
|
||||
{
|
||||
s_Pending--;
|
||||
var req = EntityManager.CreateEntity(typeof(ReadyToggleRequest), typeof(SendRpcCommandRequest));
|
||||
EntityManager.SetComponentData(req, new ReadyToggleRequest { Ready = s_PendingValue });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7047cb8f6861ba8498f33698c9948dc8
|
||||
@@ -0,0 +1,60 @@
|
||||
using ProjectM.Simulation;
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ProjectM.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-side route-pick sender: a static enqueue (the Step-14 map panel's option buttons / execute_code)
|
||||
/// drained into <see cref="RouteSelectRequest"/> RPCs. The request is stamped from the CLIENT's replicated
|
||||
/// <see cref="RunInfo"/>: <c>ForRunEpoch = (int)RunSeed</c> (the re-meaned run-identity token — the server-only
|
||||
/// RunEpoch is not client-knowable) and <c>ForLayer = CurrentRoom</c> VERBATIM (during a gate that is still the
|
||||
/// just-cleared layer — never +1). The server re-validates everything; a stale/possessed pick is simply dropped.
|
||||
/// Statics reset on play-enter (the stale-bridge hazard).
|
||||
/// </summary>
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
||||
public partial class RouteSendSystem : SystemBase
|
||||
{
|
||||
static int s_Pending;
|
||||
static byte s_PendingIndex;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void ResetStatics()
|
||||
{
|
||||
s_Pending = 0;
|
||||
s_PendingIndex = 0;
|
||||
}
|
||||
|
||||
/// <summary>Queue a route pick (0..RouteOptionCount-1). HUD map panel + execute_code drive this.</summary>
|
||||
public static void PickRoute(byte optionIndex)
|
||||
{
|
||||
s_PendingIndex = optionIndex;
|
||||
s_Pending++;
|
||||
}
|
||||
|
||||
protected override void OnCreate()
|
||||
{
|
||||
RequireForUpdate<NetworkId>();
|
||||
RequireForUpdate<RunInfo>();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (s_Pending == 0)
|
||||
return;
|
||||
var runInfo = SystemAPI.GetSingleton<RunInfo>();
|
||||
while (s_Pending > 0)
|
||||
{
|
||||
s_Pending--;
|
||||
var req = EntityManager.CreateEntity(typeof(RouteSelectRequest), typeof(SendRpcCommandRequest));
|
||||
EntityManager.SetComponentData(req, new RouteSelectRequest
|
||||
{
|
||||
OptionIndex = s_PendingIndex,
|
||||
ForRunEpoch = (int)runInfo.RunSeed, // the re-meaned replicated run token
|
||||
ForLayer = runInfo.CurrentRoom, // the gate's un-incremented cleared layer
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c22921cccedc3564b86d12491d88488e
|
||||
Reference in New Issue
Block a user