Run Re-Do
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user