From 72247651945f6d0a3a80f5fc91829c781f07556a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 17 Jul 2026 03:54:33 +0100 Subject: [PATCH] Persist held weapon group state in daemon --- Aetheria.State.Daemon.Smoke/Program.cs | 52 +++++++++++++++---- .../AetheriaRuntimeDaemonOperations.cs | 12 ++++- .../AetheriaRuntimeDaemonSimulation.cs | 43 ++++++++++----- ...AetheriaRuntimeInputCapabilityDocuments.cs | 7 ++- .../AetheriaRuntimeSnapshotDocuments.cs | 3 ++ docs/aetheria-perfect-machine-map.md | 8 ++- docs/original-game-migration-matrix.md | 2 +- 7 files changed, 100 insertions(+), 27 deletions(-) diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index d942c58bd..a8a662dc1 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -659,6 +659,20 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "weapon press must reach the daemon intent owner exactly once"); Require(pressed.Intents.WeaponGroups[0].Active, "weapon press must activate the exact advertised group"); + Require(entity.ActiveWeaponGroups.SequenceEqual(new[] { true }), + "weapon press must persist the daemon-owned held state beyond its command frame"); + var heldCapability = AetheriaRuntimeInputCapabilityDocument.FromFrame(frame); + RequireEqual("1", heldCapability.Actions.Single(value => value.ActionId == "weapon-group.0.fire") + .Payload["currentValue"], + "the Eve lever must derive its current value from the daemon-owned held state"); + var restartedRun = MessagePack.MessagePackSerializer.Deserialize( + MessagePack.MessagePackSerializer.Serialize(run)); + var restartedFrame = AetheriaRuntimeDaemonFrameDocument.Create( + restartedRun, "smoke", "weapon-input-restart", 2, 0.2, 0.1); + Require(restartedRun.Zones[0].Entities[0].ActiveWeaponGroups.SequenceEqual(new[] { true }) && + AetheriaRuntimeInputCapabilityDocument.FromFrame(restartedFrame).Actions + .Single(value => value.ActionId == "weapon-group.0.fire").Payload["currentValue"] == "1", + "daemon restart must retain held weapon-group truth and re-advertise it through Eve"); var released = AetheriaRuntimeDaemonOperations.Execute( run, [Translate("0")], new AetheriaRuntimeDaemonOperationContext()); @@ -666,6 +680,8 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "weapon release must reach the daemon intent owner exactly once"); Require(!released.Intents.WeaponGroups[0].Active, "weapon release must deactivate the exact advertised group"); + Require(entity.ActiveWeaponGroups.SequenceEqual(new[] { false }), + "weapon release must clear the daemon-owned held state"); } private static void DockedRefitSurfacePublishesGenericCommands() @@ -2078,13 +2094,20 @@ internal sealed class AetheriaDaemonYmirSmokeChecks ]); var catalog = new AetheriaRuntimeCatalogSnapshot( [CatalogItem("test-beam", payload), CatalogItem("test-beam-capacitor", CapacitorPayload(10, 1))], [], []); - var intents = new AetheriaRuntimeDaemonIntentState(); - intents.WeaponGroups.Add(new AetheriaRuntimeDaemonWeaponGroupIntent - { - ActorEntityKey = "zone.0.entity.0", WeaponGroup = 0, Fire = true, Active = true - }); + var press = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.SetWeaponGroupActive, + "pilot", + run.RunId, + 0, + run.CurrentEntityKey); + press.CommandId = "constant-weapon-press"; + press.WeaponGroup = 0; + press.ScalarValue = 1; + var pressed = AetheriaRuntimeDaemonOperations.Execute( + run, [press], new AetheriaRuntimeDaemonOperationContext()); for (var frame = 0; frame < 7; frame++) - AetheriaRuntimeDaemonSimulation.Step(run, intents, 0.1, + AetheriaRuntimeDaemonSimulation.Step(run, + frame == 0 ? pressed.Intents : new AetheriaRuntimeDaemonIntentState(), 0.1, new AetheriaRuntimeDaemonSimulationSettings(), NewPhysics(), catalog, frame, frame * 0.1); @@ -2106,14 +2129,25 @@ internal sealed class AetheriaDaemonYmirSmokeChecks Require(source.BehaviorStates.Single(value => value.BehaviorKind == "Capacitor").CapacitorCharge < 10, "constant weapon must pay elapsed-time energy through canonical capacitor state"); for (var frame = 7; frame < 11; frame++) - AetheriaRuntimeDaemonSimulation.Step(run, intents, 0.1, + AetheriaRuntimeDaemonSimulation.Step(run, new AetheriaRuntimeDaemonIntentState(), 0.1, new AetheriaRuntimeDaemonSimulationSettings(), NewPhysics(), catalog, frame, frame * 0.1); - AetheriaRuntimeDaemonSimulation.Step(run, new AetheriaRuntimeDaemonIntentState(), 0.1, + var release = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.SetWeaponGroupActive, + "pilot", + run.RunId, + 11, + run.CurrentEntityKey); + release.CommandId = "constant-weapon-release"; + release.WeaponGroup = 0; + release.ScalarValue = 0; + var released = AetheriaRuntimeDaemonOperations.Execute( + run, [release], new AetheriaRuntimeDaemonOperationContext()); + AetheriaRuntimeDaemonSimulation.Step(run, released.Intents, 0.1, new AetheriaRuntimeDaemonSimulationSettings(), NewPhysics(), catalog, 11, 1.1); Require(!state.Firing && run.GameEvents.Count(value => value.Kind == "weapon.firing.stopped") == 2, - "releasing held fire must stop the persisted constant weapon and publish its transition"); + "one release command must stop daemon-latched constant fire and publish its transition"); var surface = AetheriaRuntimeDaemonGameSurfaceBuilder.Build( new AetheriaRuntimeDaemonFrameDocument { FrameId = 11, Run = run }, new AetheriaRuntimeDaemonHealthDocument(), diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index 7da3cb653..c71495da8 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -1408,11 +1408,21 @@ namespace GameCult.Aetheria.State.Verse return false; } + var existingActiveGroups = entity.ActiveWeaponGroups ?? Array.Empty(); + var activeGroups = Enumerable.Range(0, entity.WeaponGroups?.Count ?? 0) + .Select(index => index < existingActiveGroups.Count && existingActiveGroups[index]) + .ToArray(); + var active = command.ScalarValue > 0.5; + var pressed = active && !activeGroups[command.WeaponGroup]; + activeGroups[command.WeaponGroup] = active; + entity.ActiveWeaponGroups = activeGroups; + intents.WeaponGroups.Add(new AetheriaRuntimeDaemonWeaponGroupIntent { ActorEntityKey = actor, WeaponGroup = command.WeaponGroup, - Active = command.ScalarValue > 0.5 + Fire = pressed, + Active = active }); return true; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index 710db1d6c..3808b3f4e 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -511,7 +511,7 @@ namespace GameCult.Aetheria.State.Verse foreach (var weapon in weapons) { weapon.State.Firing = false; - if (requestedWeapons.Contains(weapon.State.OwnerIndex, weapon.State.BehaviorIndex)) + if (requestedWeapons.ContainsPulse(weapon.State.OwnerIndex, weapon.State.BehaviorIndex)) weapon.State.TriggerPending = true; if (weapon.State.Reloading) { @@ -1419,6 +1419,11 @@ namespace GameCult.Aetheria.State.Verse { var triggers = new WeaponTriggerSet(); var groups = attacker.WeaponGroups ?? Array.Empty>(); + var activeGroups = attacker.ActiveWeaponGroups ?? Array.Empty(); + for (var groupIndex = 0; groupIndex < groups.Count && groupIndex < activeGroups.Count; groupIndex++) + if (activeGroups[groupIndex]) + foreach (var equipmentIndex in groups[groupIndex] ?? Array.Empty()) + triggers.HoldEquipment(equipmentIndex); foreach (var intent in (intents == null ? Enumerable.Empty() : intents.WeaponGroups) @@ -1430,7 +1435,7 @@ namespace GameCult.Aetheria.State.Verse if (intent.WeaponGroup < 0 || intent.WeaponGroup >= groups.Count) continue; foreach (var equipmentIndex in groups[intent.WeaponGroup] ?? Array.Empty()) - triggers.RequestEquipment(equipmentIndex); + triggers.PulseEquipment(equipmentIndex); } foreach (var request in AetheriaRuntimeTurretControllerSimulation.StepEntity( @@ -1481,7 +1486,7 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeDaemonSimulationSettings settings) { return AetheriaRuntimeEquippedBehaviorQueries.FindOperational(entity, catalog, AetheriaRuntimeBehaviorKinds.DeployableWeapon) - .Where(behavior => requestedWeapons.Contains(behavior.EquipmentIndex, behavior.BehaviorIndex)) + .Where(behavior => requestedWeapons.ContainsPulse(behavior.EquipmentIndex, behavior.BehaviorIndex)) .Select(behavior => new ResolvedDeployableWeapon( ResolveAuthoredWeapon(entity, behavior, settings), Math.Max(0, ReadNumber(behavior.Payload, 26)), @@ -1832,7 +1837,7 @@ namespace GameCult.Aetheria.State.Verse .Where(value => string.Equals(value.Payload.Kind, AetheriaRuntimeBehaviorKinds.ChargedWeapon, StringComparison.Ordinal)) .Select(value => new ResolvedChargedWeapon( ResolveAuthoredWeapon(entity, value, settings), value.Item, - requestedWeapons.Contains(value.EquipmentIndex, value.BehaviorIndex), + requestedWeapons.ContainsPulse(value.EquipmentIndex, value.BehaviorIndex), PositiveOr(value.EvaluateStat(21), 1), Math.Max(0, value.EvaluateStat(22)), Math.Max(0, value.EvaluateStat(23)), ReadNumber(value.Payload, 25), PositiveOr(ReadNumber(value.Payload, 26), 1), @@ -2042,19 +2047,33 @@ namespace GameCult.Aetheria.State.Verse private sealed class WeaponTriggerSet { - private readonly HashSet _requestedEquipment = new HashSet(); - private readonly HashSet<(int EquipmentIndex, int BehaviorIndex)> _requestedBehaviors = + private readonly HashSet _pulsedEquipment = new HashSet(); + private readonly HashSet _heldEquipment = new HashSet(); + private readonly HashSet<(int EquipmentIndex, int BehaviorIndex)> _pulsedBehaviors = + new HashSet<(int EquipmentIndex, int BehaviorIndex)>(); + private readonly HashSet<(int EquipmentIndex, int BehaviorIndex)> _heldBehaviors = new HashSet<(int EquipmentIndex, int BehaviorIndex)>(); - public void RequestEquipment(int equipmentIndex) => - _requestedEquipment.Add(equipmentIndex); + public void PulseEquipment(int equipmentIndex) => + _pulsedEquipment.Add(equipmentIndex); - public void RequestBehavior(int equipmentIndex, int behaviorIndex) => - _requestedBehaviors.Add((equipmentIndex, behaviorIndex)); + public void HoldEquipment(int equipmentIndex) => + _heldEquipment.Add(equipmentIndex); + + public void RequestBehavior(int equipmentIndex, int behaviorIndex) + { + _pulsedBehaviors.Add((equipmentIndex, behaviorIndex)); + _heldBehaviors.Add((equipmentIndex, behaviorIndex)); + } + + public bool ContainsPulse(int equipmentIndex, int behaviorIndex) => + _pulsedEquipment.Contains(equipmentIndex) || + _pulsedBehaviors.Contains((equipmentIndex, behaviorIndex)); public bool Contains(int equipmentIndex, int behaviorIndex) => - _requestedEquipment.Contains(equipmentIndex) || - _requestedBehaviors.Contains((equipmentIndex, behaviorIndex)); + ContainsPulse(equipmentIndex, behaviorIndex) || + _heldEquipment.Contains(equipmentIndex) || + _heldBehaviors.Contains((equipmentIndex, behaviorIndex)); } private enum WeaponRoundResult { Fired, ReloadStarted, InsufficientEnergy, NoAmmo } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs index dbc4cadfc..5aa3efb9f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs @@ -91,7 +91,7 @@ namespace GameCult.Aetheria.State.Verse } if (entity != null) { - actions.AddRange((entity.WeaponGroups ?? Array.Empty>()).Select((_, index) => WeaponGroupAction(run, index))); + actions.AddRange((entity.WeaponGroups ?? Array.Empty>()).Select((_, index) => WeaponGroupAction(run, entity, index))); actions.AddRange(EquipmentBehaviorActions(run, entity, catalog)); actions.AddRange((entity.CargoContents ?? Array.Empty()) .SelectMany(bay => bay.Items) @@ -190,8 +190,11 @@ namespace GameCult.Aetheria.State.Verse private static AetheriaRuntimeInputActionDocument WeaponGroupAction( AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeEntitySnapshotCommit entity, int weaponGroup) { + var activeGroups = entity.ActiveWeaponGroups ?? Array.Empty(); + var active = weaponGroup < activeGroups.Count && activeGroups[weaponGroup]; var action = Action( $"weapon-group.{weaponGroup}.fire", $"Fire Weapon Group {weaponGroup + 1}", @@ -200,7 +203,7 @@ namespace GameCult.Aetheria.State.Verse $"{run.CurrentEntityKey}#weapon-group/{weaponGroup}", ("weaponGroup", weaponGroup.ToString()), ("active", "0"), - ("currentValue", "0")); + ("currentValue", active ? "1" : "0")); action.InputValue = new AetheriaRuntimeInputValueDocument { Model = "button-hold.v1", diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs index c1a8bcce8..8050a0b1f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs @@ -1127,6 +1127,9 @@ namespace GameCult.Aetheria.State.Verse [Key(53)] public AetheriaRuntimeWormholeTransitionCommit? WormholeTransition { get; set; } + + [Key(54)] + public IReadOnlyList ActiveWeaponGroups { get; set; } = Array.Empty(); } [MessagePackObject] diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index e134cd0c4..281d03407 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -109,8 +109,12 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. non-consumable inventory drops and creates consumable bindings around typed catalog rows. Weapon groups publish the fossil press/release lifecycle as generic `button-hold.v1` values routed to the daemon-owned - `SetWeaponGroupActive` command; `FireWeaponGroup` remains a one-shot - compatibility operation but is not the public binding contract. The provider + `SetWeaponGroupActive` command. The entity snapshot owns the reconnectable + active-group latch: a press edge pulses instant/charged weapons once while + constant weapons remain selected until the release command clears the latch. + Generic clients send transitions, not frame-frequency keepalive commands. + `FireWeaponGroup` remains a one-shot compatibility operation for autonomous + agents and command buttons but is not the public binding contract. The provider input capability derives equipment controls from exact installed payload indices: `Switch` and `Trigger` publish generic `button-hold.v1` values, while adjustable `Thermotoggle` publishes a diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 88f9eda0d..9c7a3cf76 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -31,7 +31,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Wormhole travel | `ActionGameManager.EnterWormhole` plus `Ship` enter/exit state | daemon fixed-step transition plus Ymir exclusion | current-entity transition state and feedback chronology | provider-selected generic transition lowering | command acceptance no longer moves an entity immediately; player interact, explicit travel, and agent routing derive the same canonical adjacent-zone wormhole and proximity gate, then persist four-second `entering`, authoritative transfer, four-second `exiting`, and one-frame `completed` phases. The daemon owns smootherstep XZ motion, the fossil 1000-unit visual-depth lever, deterministic 20-unit exit direction, 50-unit exit radius, target-adjacency discovery, and exactly-once start/transfer/completion events. Flight and every world-physics implementation receive no transitioning body; Ymir resumes on the tick after completion. Smoke serializes and rehydrates mid-entry and proves agents traverse multi-edge routes through the same command boundary | generic provider transition effect/camera lowering and live multi-zone pilot witness | | Inventory/equipment | `Entity.ItemFits`, `TryEquip`, `TryUnequip`, `EquippedCargoBay.ItemFits`/`TryStore`, inventory panels + ServerShared | daemon atomic inventory transactions | typed inventory/equipment state, commands, exact receipts | generic UI | generated cargo and docking bays now occupy their typed collections instead of masquerading as ordinary equipment; docked equip/reposition/store validates the complete destination on cloned state before committing either side, uses authored hull interior and hardpoint geometry, forces hardpoint rotation, rejects occupied cells and deployed ships, preserves exact item instance fields and weapon-group membership, routes bay categories with aligned content/assignment arrays, and refuses to unequip nonempty/occupied bays. Cargo transfer now uses the same plan-first rule with typed bay interiors, rotated item footprints, deterministic free-cell search, exact stack maxima, and no partial source/destination mutation on rejection; exact reasons reach generic Eve receipts | live generic refit controls, reconnect after accepted and rejected moves, commodity multi-stack chronology, and full fossil inventory feedback parity | | Trade | trade UI/economy | daemon | stock, quote, purchase/sale commands | generic UI | daemon derives station, stock row, catalog item, current price, quantity, credits, target capacity, and hull-vs-cargo result; purchases ignore client opinions about price and destination kind. Docked sales identify only the source stack and quantity: the daemon derives station, instance-sensitive value, payout, deterministic typed stock placement, and commits cargo/credits atomically; generic Eve advertises available buy and sell actions. The generic Unity live witness receives an authoritative purchase receipt while paused | live sale receipt witness, quote expiry, contested stock, and full trade surface parity | -| Action bar/input | input shell and rebinding UI | daemon advertises actions; client owns bindings | input capability and action descriptors | universal binding UI | contracts wired; cargo actions are catalog-filtered to consumables the current actor can actually activate, including suppression of active non-stackable items. Weapon groups advertise the fossil press/release lifecycle as generic `button-hold.v1` values routed to `SetWeaponGroupActive`; the one-shot compatibility command is no longer the public input contract. Equipment actions derive from exact installed catalog payload/state pairs instead of blindly activating behavior zero: Switch and Trigger expose generic hold values, adjustable Thermotoggle exposes a scalar Kelvin target/current value, fixed/non-interactive rows are omitted, and offline rows retain identity as unavailable. Every value form translates through generic Eve requests into typed daemon commands under provider identity `aetheria` | runtime action-bar quantity/fill proof and generic scalar-control lowering | +| Action bar/input | input shell and rebinding UI | daemon advertises actions; client owns bindings | input capability and action descriptors | universal binding UI | contracts wired; cargo actions are catalog-filtered to consumables the current actor can actually activate, including suppression of active non-stackable items. Weapon groups advertise the fossil press/release lifecycle as generic `button-hold.v1` values routed to `SetWeaponGroupActive`; daemon entity state persists the active-group latch, press edges pulse instant/charged weapons once, constant weapons remain selected without client keepalives, release clears the latch, and the one-shot compatibility command is not the public input contract. Equipment actions derive from exact installed catalog payload/state pairs instead of blindly activating behavior zero: Switch and Trigger expose generic hold values, adjustable Thermotoggle exposes a scalar Kelvin target/current value, fixed/non-interactive rows are omitted, and offline rows retain identity as unavailable. Every value form translates through generic Eve requests into typed daemon commands under provider identity `aetheria` | runtime action-bar quantity/fill proof and generic scalar-control lowering | | Pilot camera | ARPG follow/dock cameras | Eve view semantics + runtime | camera rig and semantic view id | EveUnity camera rig | daemon dock state selects distinct contracts instead of collapsing both fossil cameras: undocked flight advertises the entity-forward `Third Person Rig` framing (distance 30, screen 0.64/0.19, FOV 60, lens 1-4096) and the shared `aim.presentation` convergence point as its look-at; Aetheria translates the fossil Cinemachine top-origin screen Y of `0.81` to Eve's bottom-origin viewport Y of `0.19`; EveUnity solves native pose while preserving both optical aim and advertised entity framing, without provider types; the retained dock projection remains separate | reproduce the dock camera's separate follow/look-at subjects, blend timeline, noise, and reconnect state | | Render channels | Unity layers/culling masks | provider surface policy + runtime asset variant | semantic channel exclusions | EveUnity native layer mapping | wired, exclusive, and lowered: the pilot surface excludes the semantic `map` channel; the Unity asset variant maps `map` to its authored native layer; EveUnity subtracts that layer from the configured camera mask; portable state contains no Unity layer or mask; provider conversion preserves the source icon shader's unlit lighting model; the released witness proves the pilot camera excludes map glyphs while the map camera retains readable white glyphs without a scene light | preserve the channel proof while world presentation and transport continue to evolve | | Minimap/tactical map | `ZoneRenderer`, map cameras | daemon world facts | explicit map projections | Unity and Electron | facts fragmented; generic lowerers absent | same state in both runtimes |