M7 Automation: deterministic Harvester to Conveyor to Fabricator chains
Server-only production chains (never predicted): components + server systems + pure byte-only math (ProductionMath/ConveyorMath/MachineSlotMath), authoring + 3 machine prefabs wired into the Gameplay subscene, StructureCatalog rows, BuildPlace Direction/RuntimePlacedTag, Tuning, and 35 EditMode tests (catch-up gating, conveyor shuffle-invariance, SaveData v2 round-trip). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using Unity.Entities;
|
||||
|
||||
namespace ProjectM.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// A fixed-yield resource generator — the FRONT of the M7 auto-gather chain (Harvester -> Conveyor ->
|
||||
/// Fabricator). Each period it deposits <see cref="Yield"/> of <see cref="ResourceId"/> into its OWN
|
||||
/// server-only <see cref="MachineOutput"/> buffer (a conveyor pulls it onward). Server-only data (NO
|
||||
/// [GhostField]); the client only ever sees <c>PlacedStructure.Type</c>. Reuses
|
||||
/// <c>PlacedStructure.NextTick</c>/<c>LastProcessedTick</c> for the deterministic, within-session catch-up
|
||||
/// cadence (see <c>HarvesterProductionSystem</c>).
|
||||
/// </summary>
|
||||
public struct Harvester : IComponentData
|
||||
{
|
||||
/// <summary>Resource id produced (a byte; see <see cref="ResourceId"/>).</summary>
|
||||
public byte ResourceId;
|
||||
/// <summary>Units produced per elapsed period.</summary>
|
||||
public int Yield;
|
||||
/// <summary>Server ticks between productions.</summary>
|
||||
public int PeriodTicks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A recipe machine — the BACK of the M7 chain. Consumes <see cref="InAmount"/> of <see cref="InResourceId"/>
|
||||
/// per run from its own <see cref="MachineInput"/> buffer (fed by a conveyor) and deposits <see cref="OutAmount"/>
|
||||
/// of <see cref="OutResourceId"/> into the GLOBAL ledger. Strictly input-limited (never mints from an empty
|
||||
/// slot). Server-only data.
|
||||
/// </summary>
|
||||
public struct Fabricator : IComponentData
|
||||
{
|
||||
public byte InResourceId;
|
||||
public int InAmount;
|
||||
public byte OutResourceId;
|
||||
public int OutAmount;
|
||||
public int PeriodTicks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A directional transport belt — the MIDDLE of the M7 chain. Each period it pulls one item off an adjacent
|
||||
/// upstream <see cref="MachineOutput"/> (when empty) and advances a held <see cref="ConveyorItem"/> exactly one
|
||||
/// cell toward <see cref="Direction"/>. <see cref="Direction"/> is a byte (0=+X,1=-X,2=+Z,3=-Z) — never an enum
|
||||
/// (the cross-assembly enum-in-Burst hazard). Server-only data.
|
||||
/// </summary>
|
||||
public struct Conveyor : IComponentData
|
||||
{
|
||||
/// <summary>Belt facing: 0=+X, 1=-X, 2=+Z, 3=-Z (see <c>ConveyorMath.DirOffset</c>).</summary>
|
||||
public byte Direction;
|
||||
public int PeriodTicks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A machine's INPUT staging buffer (server-only, NO [GhostField] -> never replicated). A DISTINCT element type
|
||||
/// from the global ledger's <see cref="StorageEntry"/> (so <c>GetSingleton<StorageEntry></c> stays
|
||||
/// unambiguous) and from <see cref="MachineOutput"/> (so a machine can carry both without a buffer-type clash).
|
||||
/// </summary>
|
||||
public struct MachineInput : IBufferElementData
|
||||
{
|
||||
public byte ResourceId;
|
||||
public int Count;
|
||||
}
|
||||
|
||||
/// <summary>A machine's OUTPUT staging buffer (server-only, NO [GhostField]). See <see cref="MachineInput"/>.</summary>
|
||||
public struct MachineOutput : IBufferElementData
|
||||
{
|
||||
public byte ResourceId;
|
||||
public int Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The single in-flight item a conveyor carries. An ENABLEABLE component (enabled = the belt is occupied) so a
|
||||
/// transport step is a bit-flip + field copy, never a structural change. Baked DISABLED (an empty belt).
|
||||
/// Server-only.
|
||||
/// </summary>
|
||||
public struct ConveyorItem : IComponentData, IEnableableComponent
|
||||
{
|
||||
public byte ResourceId;
|
||||
public int Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a structure PLACED by a player at runtime (BuildPlaceSystem) or restored from a save — i.e. the
|
||||
/// persistable set, as opposed to anything baked into the subscene. SaveWriteSystem scans only these and
|
||||
/// BaseRestoreSystem re-adds the tag, so save/restore is the single source of truth for player builds.
|
||||
/// Server-only (not replicated).
|
||||
/// </summary>
|
||||
public struct RuntimePlacedTag : IComponentData { }
|
||||
}
|
||||
Reference in New Issue
Block a user