62e48a3b0b
The 2026-08-06 audit found the shipping scene was still the abandoned co-op-Hades game with LANTERN combat bolted on, and that a third of the codebase was live code for a direction abandoned on 2026-07-13. Operator chose deletion over freezing: "everything is saved in source control if needed. I want the project to be clean." DELETED (~140 source files, Scripts 335->231, Tests 77->43): - Enemy variants + boss (H3). ChargerAuthoring / SpitterAuthoring / SwarmerAuthoring were attached to ZERO prefabs, so LungeState / SpitterState / SwarmerTag were never baked: ~272 lines of Bursted AI passes, BossAISystem (261 lines) and the whole MixBands escalation curve could not match a single chunk at runtime, while 734 lines of green tests certified them. Both shipping enemy prefabs were already byte-identical in stats. - Run/room lifecycle: RunDirector FSM, RunInfo/RunMap/RoomPlan/RoomTag, route select, portal interact, ready-check, room field/teardown. - Meta shop, prep loadout, boons (incl. KillRewardSystem and DashTrailDamageSystem, which existed only to serve boon flags). - Build palette + structures, shared storage, inventory/equipment (already recorded PAUSED in CLAUDE.md). - The HUD panels driving all of the above (HudSystem 1168 -> 610). KEPT deliberately: BaseGridMath + BaseAnchor (8 systems use PlotCenter for spawn rings, respawn and dynamic light), the resource ledger + StorageMath, the save system, region/relevancy. Three of these were in the delete set until I checked their consumers — worth remembering that the file-level manifest was wrong about them. Also folds in audit finding M5: PlayerClass was a second, server-only copy of the byte FrameId already replicates. It existed for the meta shop; with that gone, FrameId is the single frame identity. Harvest is now single-sink (ledger). HarvestMath keeps its shape so LANTERN's carried-vs-banked cargo split lands in one place, not two. 295/295 EditMode green, zero compile errors. Subscene re-bake and Play validation follow in the next commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
190 lines
11 KiB
C#
190 lines
11 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.NetCode;
|
|
using Unity.Transforms;
|
|
|
|
namespace ProjectM.Client
|
|
{
|
|
/// <summary>
|
|
/// Client-only twin-stick input gather. Samples the new Input System action map (the generated
|
|
/// <c>ProjectMInput</c> wrapper over <c>Assets/Settings/Project M Input.inputactions</c>) once per
|
|
/// frame and writes <see cref="PlayerInput"/> on the locally-owned player ghost (filtered to
|
|
/// <see cref="GhostOwnerIsLocal"/>). Runs in <see cref="GhostInputSystemGroup"/> — NOT the
|
|
/// prediction loop — so devices are read once per frame, never re-read during rollback.
|
|
/// <para>
|
|
/// Implemented as a managed <see cref="SystemBase"/> (not a Burst <c>ISystem</c>) because it holds
|
|
/// and reads the managed Input System wrapper. Fire is an <see cref="InputEvent"/>: the event field
|
|
/// is reset each frame and raised via <c>Set()</c> on the press edge, so a single click fires
|
|
/// exactly once; netcode accumulates the absolute <c>Count</c> into the command buffer across the
|
|
/// frame→tick boundary (read back in <c>AbilityFireSystem</c> as the predicted-spawn key).
|
|
/// </para>
|
|
/// <para>
|
|
/// NOTE: Input System types are fully qualified (e.g. <c>UnityEngine.Vector2</c>) and
|
|
/// <c>using UnityEngine.InputSystem;</c> is intentionally omitted — that namespace defines a
|
|
/// <c>PlayerInput</c> type that collides with <see cref="ProjectM.Simulation.PlayerInput"/> and
|
|
/// makes the Entities generator bind <c>RefRW<PlayerInput></c> to the managed class (a
|
|
/// spurious CS8377). The generated <c>ProjectMInput</c> wrapper lives in this assembly.
|
|
/// </para>
|
|
/// </summary>
|
|
[UpdateInGroup(typeof(GhostInputSystemGroup))]
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
|
public partial class PlayerInputGatherSystem : SystemBase
|
|
{
|
|
private ProjectMInput _controls;
|
|
|
|
// Active input scheme (last meaningful actuation wins). Selects KBM-cursor vs gamepad-stick aim and
|
|
// is published to AimPresentation for the on-screen cursor / world reticle. Starts on mouse+keyboard.
|
|
private byte _scheme = InputSchemeId.KeyboardMouse;
|
|
|
|
// Last valid KBM cursor aim, held when the projection is degenerate (cursor over the player / above the
|
|
// horizon) so facing never snaps to zero while the mouse is the active device.
|
|
private float2 _lastKbmAim = new float2(0f, 1f);
|
|
|
|
// Main camera for cursor -> ground projection; re-resolved when null (e.g. after a domain reload).
|
|
private UnityEngine.Camera _camera;
|
|
|
|
// World radius around the player inside which mouse facing is HELD (no spin when the cursor passes
|
|
// over/near the character). Passed to AimMath.PlanarAimFromRay's deadZoneRadius.
|
|
private const float KbmAimDeadZone = 0.6f;
|
|
|
|
protected override void OnCreate()
|
|
{
|
|
RequireForUpdate<PlayerInput>();
|
|
_controls = new ProjectMInput();
|
|
_controls.Gameplay.Enable();
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
if (_controls != null)
|
|
{
|
|
_controls.Gameplay.Disable();
|
|
_controls.Dispose();
|
|
_controls = null;
|
|
}
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
var gameplay = _controls.Gameplay;
|
|
|
|
// Movement is source-agnostic (WASD or left stick) — read from the merged action.
|
|
float2 move = (float2)gameplay.Move.ReadValue<UnityEngine.Vector2>();
|
|
// MC-4: melee (left-click / pad West) is the PRIMARY verb; ranged (right-click / pad left-trigger) the secondary poke - both read as direct device reads below (after the device locals).
|
|
|
|
// --- Active-device detection: last meaningful actuation wins; hold last when idle ---
|
|
var gamepad = UnityEngine.InputSystem.Gamepad.current;
|
|
var mouse = UnityEngine.InputSystem.Mouse.current;
|
|
var keyboard = UnityEngine.InputSystem.Keyboard.current;
|
|
bool dashPressed = ((keyboard != null && keyboard.leftShiftKey.wasPressedThisFrame) || (gamepad != null && gamepad.buttonEast.wasPressedThisFrame));
|
|
// MC-4 offense rebind: melee combo = PRIMARY (left-click / pad West); ranged demoted to right-click / pad LT.
|
|
bool attackPressed = ((mouse != null && mouse.leftButton.wasPressedThisFrame) || (gamepad != null && gamepad.buttonWest.wasPressedThisFrame));
|
|
bool firePressed = ((mouse != null && mouse.rightButton.wasPressedThisFrame) || (gamepad != null && gamepad.leftTrigger.wasPressedThisFrame));
|
|
// LANTERN 4-socket kit bindings: keyboard 1..4 (+ gamepad RT/LB/RB); socket 0 also fires on the
|
|
// legacy primary (right-click / pad LT). Build-palette suppression removed 2026-08-07.
|
|
bool socket0Pressed = firePressed || ((keyboard != null && keyboard.digit1Key.wasPressedThisFrame));
|
|
bool socket1Pressed = ((keyboard != null && keyboard.digit2Key.wasPressedThisFrame) || (gamepad != null && gamepad.rightTrigger.wasPressedThisFrame));
|
|
bool socket2Pressed = ((keyboard != null && keyboard.digit3Key.wasPressedThisFrame) || (gamepad != null && gamepad.leftShoulder.wasPressedThisFrame));
|
|
bool socket3Pressed = ((keyboard != null && keyboard.digit4Key.wasPressedThisFrame) || (gamepad != null && gamepad.rightShoulder.wasPressedThisFrame));
|
|
|
|
float2 rightStick = float2.zero;
|
|
bool gamepadActive = false;
|
|
if (gamepad != null)
|
|
{
|
|
rightStick = (float2)gamepad.rightStick.ReadValue();
|
|
float2 leftStick = (float2)gamepad.leftStick.ReadValue();
|
|
gamepadActive =
|
|
math.lengthsq(rightStick) > 0.04f || math.lengthsq(leftStick) > 0.04f ||
|
|
gamepad.rightTrigger.isPressed || gamepad.leftTrigger.isPressed ||
|
|
gamepad.buttonSouth.isPressed || gamepad.buttonEast.isPressed ||
|
|
gamepad.buttonWest.isPressed || gamepad.buttonNorth.isPressed;
|
|
}
|
|
|
|
bool kbmActive = false;
|
|
if (mouse != null)
|
|
{
|
|
float2 delta = (float2)mouse.delta.ReadValue();
|
|
kbmActive = math.lengthsq(delta) > 0.5f || mouse.leftButton.isPressed || mouse.rightButton.isPressed;
|
|
}
|
|
if (!kbmActive && keyboard != null)
|
|
{
|
|
kbmActive =
|
|
keyboard.wKey.isPressed || keyboard.aKey.isPressed || keyboard.sKey.isPressed || keyboard.dKey.isPressed ||
|
|
keyboard.upArrowKey.isPressed || keyboard.downArrowKey.isPressed ||
|
|
keyboard.leftArrowKey.isPressed || keyboard.rightArrowKey.isPressed || keyboard.spaceKey.isPressed || keyboard.leftShiftKey.isPressed;
|
|
}
|
|
|
|
if (gamepadActive && kbmActive)
|
|
{
|
|
// Both actuated this frame: break the tie by whichever device updated most recently.
|
|
double gpT = gamepad != null ? gamepad.lastUpdateTime : double.MinValue;
|
|
double kbmT = math.max(
|
|
mouse != null ? mouse.lastUpdateTime : double.MinValue,
|
|
keyboard != null ? keyboard.lastUpdateTime : double.MinValue);
|
|
_scheme = gpT > kbmT ? InputSchemeId.Gamepad : InputSchemeId.KeyboardMouse;
|
|
}
|
|
else if (gamepadActive) _scheme = InputSchemeId.Gamepad;
|
|
else if (kbmActive) _scheme = InputSchemeId.KeyboardMouse;
|
|
// else: neither actuated — keep the previous scheme.
|
|
|
|
// Publish for the presentation layer (cursor visibility / world reticle).
|
|
AimPresentation.Scheme = _scheme;
|
|
|
|
// Mouse cursor projection needs the camera; resolve/cache it (Camera.main or the rig's camera).
|
|
if (_camera == null) _camera = CameraResolver.Resolve();
|
|
UnityEngine.Vector2 cursorScreen = mouse != null ? mouse.position.ReadValue() : default;
|
|
|
|
foreach (var (input, xform) in
|
|
SystemAPI.Query<RefRW<PlayerInput>, RefRO<LocalTransform>>().WithAll<GhostOwnerIsLocal>())
|
|
{
|
|
float2 aim;
|
|
if (_scheme == InputSchemeId.Gamepad)
|
|
{
|
|
// Right-stick directional aim. A resting stick yields zero so PlayerAimSystem falls back to
|
|
// the movement heading (existing controller-first behaviour).
|
|
aim = rightStick;
|
|
if (math.lengthsq(aim) < 0.04f) aim = float2.zero;
|
|
}
|
|
else
|
|
{
|
|
// Mouse: face the cursor. Project the cursor ray onto the player's movement plane and aim
|
|
// from the player toward that point. Held to the last valid aim when degenerate, so the
|
|
// character keeps facing the cursor even while standing still (the core jank fix).
|
|
float3 playerPos = xform.ValueRO.Position;
|
|
if (_camera != null && mouse != null)
|
|
{
|
|
UnityEngine.Ray ray = _camera.ScreenPointToRay(new UnityEngine.Vector3(cursorScreen.x, cursorScreen.y, 0f));
|
|
_lastKbmAim = AimMath.PlanarAimFromRay(
|
|
(float3)ray.origin, (float3)ray.direction, playerPos, playerPos.y, _lastKbmAim, KbmAimDeadZone);
|
|
}
|
|
aim = _lastKbmAim;
|
|
}
|
|
|
|
input.ValueRW.Move = move;
|
|
input.ValueRW.Aim = aim;
|
|
input.ValueRW.Scheme = _scheme;
|
|
|
|
// Reset the per-frame event, then raise it on the press edge. Netcode latches the absolute
|
|
// Count into the command buffer; AbilityFireSystem reads it as the SpawnId key.
|
|
input.ValueRW.Fire = default;
|
|
if (firePressed)
|
|
input.ValueRW.Fire.Set();
|
|
input.ValueRW.Dash = default;
|
|
if (dashPressed)
|
|
input.ValueRW.Dash.Set();
|
|
input.ValueRW.Attack = default;
|
|
if (attackPressed)
|
|
input.ValueRW.Attack.Set();
|
|
// LANTERN 4-socket kit: reset then raise each socket's fire event on the press edge.
|
|
input.ValueRW.Socket0 = default; if (socket0Pressed) input.ValueRW.Socket0.Set();
|
|
input.ValueRW.Socket1 = default; if (socket1Pressed) input.ValueRW.Socket1.Set();
|
|
input.ValueRW.Socket2 = default; if (socket2Pressed) input.ValueRW.Socket2.Set();
|
|
input.ValueRW.Socket3 = default; if (socket3Pressed) input.ValueRW.Socket3.Set();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|