Game.UI.InGame.TrafficInfoviewUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
TrafficInfoviewUISystem is an in-game UI system (ECS System) that collects aggregated traffic flow data from Road components and exposes it to the UI via a RawValueBinding named "trafficInfo" -> "trafficFlow". It schedules a Burst-compiled IJobChunk (UpdateFlowJob) to iterate Road components, accumulates per-lane flow speeds (scaled by 100) and counts, computes averages, and serializes the result as a float array for the UI. The system maintains a persistent NativeArray for intermediate results and a managed float[] for the values sent to the UI.
Fields
-
private const string kGroup
Constant group name used when creating the RawValueBinding ("trafficInfo"). -
private EntityQuery m_AggregateQuery
EntityQuery used to select aggregated road/edge entities. Built in OnCreate to include Aggregated, Edge, Road and to exclude Temp, Deleted, Native. -
private RawValueBinding m_TrafficFlow
Binding that exposes the computed traffic flow values to the UI under group "trafficInfo" and key "trafficFlow". The binding calls UpdateTrafficFlowBinding when it needs to serialize the data. -
private NativeArray<float> m_Results
Persistent NativeArrayof length 5 used by the job to accumulate sums: indices 0-3 store lane flow sums, index 4 stores the count (number of Road entries aggregated). Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy. -
private float[] m_Flow
Managed float array of length 5 used to store the averaged flow values that are written to the IJsonWriter by UpdateTrafficFlowBinding. -
private TypeHandle __TypeHandle
Compiler-generated container for component type handles (here holds a read-only ComponentTypeHandle). Assigned in OnCreateForCompiler / __AssignHandles.
Properties
protected override bool Active { get; }
Returns true if the base system is active or if the m_TrafficFlow binding is active. This ensures the system runs when the UI wants traffic flow updates even if base.Active is false.
Constructors
public TrafficInfoviewUISystem()
Default (parameterless) constructor. Marked with [Preserve] in the source (so it survives stripping). No custom initialization beyond what OnCreate performs.
Methods
-
protected override void OnCreate()
Creates the EntityQuery (m_AggregateQuery), registers the RawValueBinding "trafficInfo"/"trafficFlow" with UpdateTrafficFlowBinding as the serializer callback, allocates m_Flow (float[5]) and m_Results (NativeArray(5, Allocator.Persistent)). Called when the system is created. -
protected override void OnDestroy()
Disposes m_Results and calls base.OnDestroy. Ensures the persistent NativeArray is released. -
protected override void PerformUpdate()
Primary per-frame update: calls Reset() to zero accumulators, schedules the Burst-compiled UpdateFlowJob using JobChunk / JobChunkExtensions.Schedule over m_AggregateQuery (supplying the ComponentTypeHandlevia InternalCompilerInterface.GetComponentTypeHandle), calls .Complete() on the returned job handle, then updates the m_TrafficFlow binding which triggers serialization (UpdateTrafficFlowBinding). -
private void Reset()
Zeros the m_Results NativeArray and the managed m_Flow array before each aggregation pass. -
private void UpdateTrafficFlowBinding(IJsonWriter writer)
Serializes the computed flow values into the provided IJsonWriter as an array of 5 floats. Computes averages for indices 0-3 by dividing accumulated sums by the count (index 4) with a division-protection (uses math.select to avoid divide-by-zero). Copies the first average into m_Flow[4] (presumably as a default/representative value), then writes the array. -
private void __AssignQueries(ref SystemState state)
Compiler-generated placeholder used at compile-time to assign queries. In this decompiled form it creates and disposes a temporary EntityQueryBuilder; left as a stub. -
protected override void OnCreateForCompiler()
Compiler hook that calls __AssignQueries and __TypeHandle.__AssignHandles to prepare component type handles and queries for the runtime/IL2CPP compiled system. -
(Nested) UpdateFlowJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Burst-compiled IJobChunk implementation. Obtains a NativeArrayfrom the chunk using the provided ComponentTypeHandle , iterates all Road elements in the chunk, calls NetUtils.GetTrafficFlowSpeed(road) * 100f to get a float4 with per-lane flow values, and accumulates each lane into m_Results[0..3]. After processing the chunk, adds nativeArray.Length to m_Results[4] (count of processed Road entries). This job sums values across all matching chunks; the system later divides by the count to get averages. -
(Nested) TypeHandle.__AssignHandles(ref SystemState state)
Assigns the __Game_Net_Road_RO_ComponentTypeHandle by calling state.GetComponentTypeHandle(isReadOnly: true). Used by OnCreateForCompiler to prepare the type handle used when scheduling the job.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Build the query to aggregate roads
m_AggregateQuery = GetEntityQuery(
ComponentType.ReadOnly<Aggregated>(),
ComponentType.ReadOnly<Edge>(),
ComponentType.ReadOnly<Road>(),
ComponentType.Exclude<Temp>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Native>());
// Register UI binding that will call UpdateTrafficFlowBinding when serializing
AddBinding(m_TrafficFlow = new RawValueBinding("trafficInfo", "trafficFlow", UpdateTrafficFlowBinding));
// Allocate arrays
m_Flow = new float[5];
m_Results = new NativeArray<float>(5, Unity.Collections.Allocator.Persistent);
}
Notes / Implementation details:
- The aggregate job multiplies the results of NetUtils.GetTrafficFlowSpeed by 100f — ensure this scale is expected by UI consumers.
- The job accumulates per-chunk into a single NativeArray