Game.Simulation.NetDeteriorationSystem
Assembly:
Assembly-CSharp (game)
Namespace:
Game.Simulation
Type:
NetDeteriorationSystem
Base:
GameSystemBase
Summary:
System responsible for simulating deterioration of lanes and overall net (edge) condition over time. It updates per-lane wear based on prefab-defined deterioration data, aggregates lane wear into net/edge condition, and issues maintenance requests when a net's condition crosses thresholds. The system is burst-compiled and uses ECS IJobChunk jobs (UpdateLaneConditionJob and UpdateNetConditionJob) to run in parallel. It uses UpdateFrame shared-component filtering to spread work over kUpdatesPerDay slices and schedules maintenance requests via an EndFrameBarrier command buffer.
Fields
-
public static readonly int kUpdatesPerDay = 16
Controls how many update slices per in-game day are used to stagger lane/edge updates. Used to compute update frames and the update interval for the system. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem instance (used to obtain the current simulation frame index for UpdateFrame calculation). -
private EndFrameBarrier m_EndFrameBarrier
Reference to the EndFrameBarrier system used to produce command buffer operations (create maintenance request entities) safely from jobs. -
private EntityQuery m_LaneQuery
EntityQuery selecting lane entities (components: LaneCondition, UpdateFrame; excludes Deleted and Temp) used to schedule and run UpdateLaneConditionJob. -
private EntityQuery m_EdgeQuery
EntityQuery selecting net/edge entities (components: NetCondition, UpdateFrame; excludes Deleted and Temp) used to schedule and run UpdateNetConditionJob and to drive maintenance requests. -
private EntityArchetype m_MaintenanceRequestArchetype
Archetype created for maintenance request entities. Typically includes ServiceRequest, MaintenanceRequest and RequestGroup components and is used when creating requests from jobs. -
private TypeHandle __TypeHandle
Internal aggregated component/buffer/lookup handles used to fetch ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances quickly inside jobs (assigned in OnCreateForCompiler).
Properties
- (none — this system exposes no public properties)
Constructors
public NetDeteriorationSystem()
Default constructor. System initialization logic is implemented in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the system update interval in ticks. Uses kUpdatesPerDay to ensure updates are spread across game frames. The implementation returns262144 / (kUpdatesPerDay * 16)
which guarantees a minimum spacing and is asserted in OnCreate. -
[Preserve] protected override void OnCreate()
Initializes queries, archetypes and references to other systems. Key actions: - Obtains SimulationSystem and EndFrameBarrier instances from the World.
- Creates m_LaneQuery and m_EdgeQuery with UpdateFrame shared component filters (LaneCondition / NetCondition + UpdateFrame).
- Creates m_MaintenanceRequestArchetype (ServiceRequest, MaintenanceRequest, RequestGroup).
- Calls RequireAnyForUpdate with both lane and edge queries so the system runs when either has work.
-
Asserts that (262144 / kUpdatesPerDay) >= 512 to ensure sufficient tick spacing.
-
[Preserve] protected override void OnUpdate()
Main per-frame logic: - Resets and sets UpdateFrame shared-component filters on m_LaneQuery and m_EdgeQuery based on SimulationSystem.frameIndex (using SimulationUtils.GetUpdateFrame with kUpdatesPerDay and slice count 16).
- Constructs and schedules two Burst-compiled IJobChunk jobs:
- UpdateLaneConditionJob: increments each LaneCondition.m_Wear based on PrefabRef and LaneDeteriorationData (capped at 10).
- UpdateNetConditionJob: aggregates lane wear into NetCondition.m_Wear, resets net/lane wear for native lanes, and issues maintenance requests via the EndFrameBarrier command buffer when needed (using RequestMaintenanceIfNeeded).
-
Adds the resulting job handle to the EndFrameBarrier as a producer handle and sets base.Dependency.
-
public static int GetMaintenancePriority(NetCondition condition)
Returns an integer priority for maintenance requests derived from the net's condition. Priority calculation: - Computes max component value of condition.m_Wear (math.cmax),
- Scales to percentage of 10 (divides by 10 and multiplies by 100),
- Subtracts 10 to offset baseline.
-
Result is used to decide whether to request maintenance (priority > 0) and how urgent it is.
-
protected override void OnCreateForCompiler()
Compiler-time helper used to assign internal handles (__AssignQueries and __TypeHandle.__AssignHandles). Called by generated code paths in the engine; ensures component handles are initialized for job scheduling. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Internal helper that prepares any EntityQueryBuilder usage expected by generated code. Present for compiler/IL generation consistency. Not intended for mod usage. -
Nested job:
UpdateLaneConditionJob : IJobChunk
Burst-compiled job that: - Reads PrefabRef and LaneDeteriorationData (ComponentLookup) and updates LaneCondition components on lanes in the chunk.
-
Increments LaneCondition.m_Wear by (1 / kUpdatesPerDay) * LaneDeteriorationData.m_TimeFactor, clamped to 10.
-
Nested job:
UpdateNetConditionJob : IJobChunk
Burst-compiled job that: - For each net/edge entity, aggregates wear from its sub-lanes (Game.Net.SubLane buffer) into NetCondition.m_Wear. Handles special edge lane cases using EdgeLane data (uses math.select for edge delta logic).
- If a chunk contains native lanes (Native component present), it resets both NetCondition.m_Wear and each sub-lane LaneCondition.m_Wear to 0.
-
If the entity has a MaintenanceConsumer component, it uses RequestMaintenanceIfNeeded to create a MaintenanceRequest entity via an EntityCommandBuffer.ParallelWriter when maintenance priority is above zero and no matching request is outstanding.
-
private void RequestMaintenanceIfNeeded(int jobIndex, Entity entity, NetCondition condition, ref MaintenanceConsumer maintenanceConsumer)
(method inside UpdateNetConditionJob)
Checks current maintenance priority (GetMaintenancePriority) and, if > 0 and there is no valid existing request (or it targets a different entity / different dispatch index), creates a new MaintenanceRequest entity using the command buffer and assigns a RequestGroup.
Usage Example
// Example: calling the static helper to compute priority.
// In a mod or other system you can reuse this to determine urgency.
NetCondition exampleCondition = default;
exampleCondition.m_Wear = new float3(3.5f, 2.0f, 1.0f); // per-lane or per-component wear values
int priority = NetDeteriorationSystem.GetMaintenancePriority(exampleCondition);
// priority > 0 indicates a maintenance request should be considered.
Notes and tips for modders: - The system is tuned to run in slices defined by kUpdatesPerDay (16). If you create or modify UpdateFrame values or the way frames are computed, ensure consistency with SimulationUtils.GetUpdateFrame. - Maintenance requests are created via the EndFrameBarrier command buffer in a job-safe manner. If you need to create similar requests from other systems, mimic the use of an EntityArchetype that includes ServiceRequest, MaintenanceRequest and RequestGroup. - GetMaintenancePriority provides a simple priority computation; adjust only if you understand how scaling and subtraction (-10) map to the game's dispatch/priority logic.