Game.Simulation.OutsideConnectionDelaySystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
OutsideConnectionDelaySystem updates "outside connection" delays for network lanes (borders/edges connected to outside-of-map connections) and pushes corresponding TimeActionData entries into the pathfind queue. It scans nodes that have Game.Net.OutsideConnection components, accumulates delays from connected edges' lanes (taking into account slave/master lane relationships and lane objects that impose delay), computes an average delay per originating lane, writes that delay into the Game.Net.OutsideConnection component, then enqueues TimeActionData entries (border cost + computed delay) into the PathfindQueueSystem. The main work is performed inside a Burst-compiled IJobChunk (OutsideConnectionDelayJob) and is scheduled in parallel. This system is intended to run infrequently and aggregate delays for pathfinding border costs.
Fields
-
private struct AccumulationData
Stores accumulation state used within the job: the source lane Entity and a float2 where x == accumulated delay sum and y == count of contributors (used to compute an average). -
private const int UPDATES_PER_DAY = 64
A constant defined on the type. (Not actively used inside the provided code, likely informational for update cadence.) -
private PathfindQueueSystem m_PathfindQueueSystem
Reference to the PathfindQueueSystem used to enqueue TimeAction/TimeActionData results from the job. The system obtains this in OnCreate via World.GetOrCreateSystemManaged(). -
private EntityQuery m_NodeQuery
EntityQuery selecting nodes that should be processed by this system: nodes with Node and Game.Net.OutsideConnection components, excluding Deleted and Temp. Used with RequireForUpdate to control whether the system runs. -
private TypeHandle __TypeHandle
Internal struct holding BufferTypeHandle/ComponentLookup/BufferLookup instances used when scheduling the IJobChunk. This is initialized in OnCreateForCompiler (the compiler-generated helper). -
private struct OutsideConnectionDelayJob
(nested)
Burst-compiled IJobChunk that performs the scanning and accumulation described in the summary. It reads buffers and components, uses a NativeParallelHashMapto aggregate per-start-node, computes per-lane averages, writes Game.Net.OutsideConnection components, and enqueues TimeActionData into a NativeQueue (TimeAction.m_TimeData) via ParallelWriter. -
private struct TypeHandle
(nested)
Compiler-generated container used to cache the handles/lookups required by the job. It exposes __AssignHandles(ref SystemState) to bind the handles before scheduling.
Properties
- None (the system does not expose public properties).
Constructors
public OutsideConnectionDelaySystem()
Default parameterless constructor with [Preserve] attribute on lifecycle methods; the system is created by the ECS world as usual. No special construction logic in the constructor body itself.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the system update interval. In this implementation it returns 4096 — the system is expected to be scheduled at an infrequent interval (game-specific scheduler uses that to decide when to run). -
[Preserve] protected override void OnCreate()
Initializes the system: - Calls base.OnCreate().
- Acquires (or creates) the PathfindQueueSystem via base.World.GetOrCreateSystemManaged
() and stores it in m_PathfindQueueSystem. - Builds an EntityQuery selecting nodes with Game.Net.OutsideConnection (and Node) and excluding Deleted and Temp, stores in m_NodeQuery.
-
Calls RequireForUpdate(m_NodeQuery) so the system only runs when matching entities exist.
-
[Preserve] protected override void OnUpdate()
Schedules the OutsideConnectionDelayJob as a parallel IJobChunk over m_NodeQuery: - Builds a TimeAction container (TimeAction action = new TimeAction(Allocator.Persistent)).
- Constructs OutsideConnectionDelayJob with the appropriate BufferTypeHandle/ComponentLookup/BufferLookup retrieved through InternalCompilerInterface.Get* using __TypeHandle.
- Schedules the job in parallel (JobChunkExtensions.ScheduleParallel) and obtains the JobHandle.
- Enqueues the TimeAction into m_PathfindQueueSystem with the produced jobHandle so the pathfind queue will process the enqueued TimeActionData once the job completes.
- Stores the job handle into base.Dependency.
Important notes:
- The job uses a NativeQueue
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper stub to initialize any queries required for compiler workflows. In this compiled form it just creates and disposes an EntityQueryBuilder temporary; the real query is created in OnCreate. -
protected override void OnCreateForCompiler()
Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to prepare the TypeHandle lookups for the job in ahead-of-time compiled builds. -
private float CalculateDelay(Entity lane)
(inside job)
Utility used by the IJobChunk to compute extra delay for a lane by examining its LaneObject buffer and summing the durations of any CarCurrentLane components found that have the CarLaneFlags.ResetSpeed flag set. This sum is used to increase the computed border delay for lanes that have lane objects which temporarily reset speed. -
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
(job explicit interface)
Interface implementation forwarding to the job's Execute method.
Usage Example
// Example: The system is mostly self-contained and scheduled by the ECS world.
// The following snippet mirrors the OnCreate behavior you might call when building a similar system.
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Ensure we have the pathfind queue system reference
m_PathfindQueueSystem = World.GetOrCreateSystemManaged<PathfindQueueSystem>();
// Only run when nodes with outside connections exist
m_NodeQuery = GetEntityQuery(
ComponentType.ReadOnly<Node>(),
ComponentType.ReadOnly<Game.Net.OutsideConnection>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Temp>());
RequireForUpdate(m_NodeQuery);
}
// The OnUpdate schedules the burst job which writes Game.Net.OutsideConnection.m_Delay
// and enqueues TimeActionData items into the pathfind queue for border cost updates.
Additional notes and modder cautions: - The heavy lifting is inside a Burst-compiled job; avoid modifying component layout/state that the job expects without ensuring the TypeHandle and lookups are updated accordingly. - The job uses temporary NativeParallelHashMap allocations per chunk; if adapting or reusing this logic in other contexts, prefer reusing pooled containers or lowering allocation frequency if performance is a concern. - TimeActionData enqueued here relies on downstream PathfindQueueSystem processing; ensure that system is present and compatible when you change queued data semantics. - Be careful when accessing or modifying Game.Net.OutsideConnection or lane-related components from other systems to avoid race conditions — this job writes those components via ComponentLookup outside of the chunk iteration and expects the ECS scheduling/dependency model to be respected.