Game.Rendering.NetColorSystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
NetColorSystem is an ECS system responsible for computing and updating visualization colours for network entities (edges, nodes and lanes) in Cities: Skylines 2. It inspects various "infoview" modes (coverage, resource availability, net geometry, net status such as traffic/wear/pollution and utility flows), samples game simulation data (pollution, land value, flow graphs, connected edges/buildings, etc.) and writes EdgeColor, NodeColor and LaneColor components. The system uses several Burst-compiled IJobChunk jobs (UpdateEdgeColorsJob, UpdateNodeColorsJob, UpdateEdgeColors2Job and LaneColorJob) and a TypeHandle helper to perform the work in parallel and to minimize main-thread overhead.
Fields
-
private EntityQuery m_ZonePreferenceParameterGroup
Holds an EntityQuery used to read global ZonePreferenceData when computing resource availability colours. -
private EntityQuery m_EdgeQuery
Query selecting edge entities (Edge + EdgeColor) used when scheduling the edge-colouring job. -
private EntityQuery m_NodeQuery
Query selecting node entities (Node + NodeColor) used when scheduling the node-colouring job. -
private EntityQuery m_LaneQuery
Query selecting lane entities (Lane + LaneColor, excluding Hidden/Deleted) used by lane colouring. -
private EntityQuery m_InfomodeQuery
Query selecting active infoview definitions (InfomodeActive combined with infoview data components) used to determine which visualisation(s) are active. -
private EntityQuery m_ProcessQuery
Query to read IndustrialProcessData for resource availability calculations. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem (used to detect active tool/infoview state and tool-specific prefabs). -
private ZoneToolSystem m_ZoneToolSystem
Reference to ZoneToolSystem used to determine zone prefab when zoning tool is active. -
private ObjectToolSystem m_ObjectToolSystem
Reference to ObjectToolSystem used to infer zone types for placeholder buildings. -
private IndustrialDemandSystem m_IndustrialDemandSystem
Reference to IndustrialDemandSystem for industrial/storage demand arrays used in resource availability colouring. -
private PrefabSystem m_PrefabSystem
Reference to PrefabSystem used to map tool prefabs to entities. -
private ResourceSystem m_ResourceSystem
Reference to ResourceSystem to get resource-related prefabs used in availability/color calculations. -
private GroundPollutionSystem m_GroundPollutionSystem
Reference to GroundPollutionSystem; the system obtains a read-only pollution map for infoview sampling. -
private ElectricityFlowSystem m_ElectricityFlowSystem
Reference to ElectricityFlowSystem (used by LaneColorJob to compute electricity flows). -
private WaterPipeFlowSystem m_WaterPipeFlowSystem
Reference to WaterPipeFlowSystem (used by LaneColorJob to compute water/sewage flows and sink nodes). -
private TypeHandle __TypeHandle
Internal struct bundling ComponentTypeHandle/BufferTypeHandle/ComponentLookup/BufferLookup used by the jobs. Populated in OnCreateForCompiler. -
private EntityQuery __query_1733354667_0
An internally created query that fetches WaterPipeParameterData (used by lane flow calculations).
Properties
- (This system exposes no public properties.)
Constructors
public NetColorSystem()
Default parameterless constructor. The system is created as part of the ECS world and calls GameSystemBase ctor via inheritance.
Methods
-
protected override void OnCreate()
Initialises the system: retrieves references to many other systems (ToolSystem, ZoneToolSystem, ObjectToolSystem, IndustrialDemandSystem, PrefabSystem, ResourceSystem, GroundPollutionSystem, ElectricityFlowSystem, WaterPipeFlowSystem), sets up EntityQueries for edges, nodes, lanes, infomode definitions and industrial processes. Prepares the system to run OnUpdate by caching queries and system references. -
protected override void OnUpdate()
Main update loop. If there is no active infoview or there are no edge/node entities to update, it returns early. Otherwise it: - Reads zone preference parameters.
- Collects infomode archetype chunks (async).
- Resolves the currently active zone prefab from the active tool (zone/object tool).
- Creates and configures job structs:
- UpdateEdgeColorsJob: computes EdgeColor per edge using service coverage, resource availability, net status or static net-geometry colouring. It reads pollution map, industrial demand arrays, process list, zone preferences, etc.
- UpdateNodeColorsJob: computes NodeColor per node by aggregating attached edges' EdgeColor or selecting net-status/geometry color.
- UpdateEdgeColors2Job: updates edge endpoint values (m_Value0/m_Value1) from node colours when nodes have reliable geometry.
- LaneColorJob: computes LaneColor for lanes — includes several flow implementations (ElectricityFlow, WaterFlow, SewageFlow, ResourceFlow) to sample flows and fill subflow buffers used to pick lane colouring/tile/warning values.
- Schedules jobs in a dependency chain using parallel IJobChunk scheduling, including combining dependencies from asynchronous reads (pollution map, demands, processes).
-
Registers the job handles as readers on some simulation systems (GroundPollutionSystem, IndustrialDemandSystem, ResourceSystem) and sets base.Dependency to the final job handle.
-
protected override void OnCreateForCompiler()
Internal compile-time helper called to assign queries and type handles for the generated job code path. Calls __AssignQueries and TypeHandle.__AssignHandles. -
private void __AssignQueries(ref SystemState state)
Creates and assigns any extra internal EntityQueries required by the system (for example the WaterPipeParameterData query). Called from OnCreateForCompiler. -
Nested job structs (private, BurstCompile):
UpdateEdgeColorsJob : IJobChunk
Evaluates each edge chunk and writes EdgeColor depending on active infoview: service coverage, resource availability, net-status metrics (wear, traffic flow, noise/air pollution, traffic volume, leisure provider) or net geometry (assigns color index per net type). Uses many ComponentTypeHandles and ComponentLookup/BufferLookup for data access; reads pollution map and industrial demand arrays.UpdateNodeColorsJob : IJobChunk
Aggregates colors for nodes based on connected edges, or computes node-specific net-status colours (wear, traffic flow, noise/air pollution, traffic volume). Uses ConnectedEdge buffers to examine attached edges and merges colors intelligently (handles multiple colours, fallbacks, geometry checks).UpdateEdgeColors2Job : IJobChunk
For edges with known node geometry, pulls node colours into edge endpoint values for smooth interpolation along the edge.LaneColorJob : IJobChunk
Most complex job: computes LaneColor for lanes. It contains private IFlowImplementation implementations for ElectricityFlow, WaterFlow, SewageFlow and ResourceFlow. Uses flow graphs, connected nodes/buildings/subobjects, subflow buffers and curve geometry to fill SubFlow arrays and derive lane tile/tiling/warning values. Also handles track/tram lane and utility lane special-cases (track types, utility types), and falls back to owner/object colour when no infoview applies.
Each job struct exposes Execute(in ArchetypeChunk chunk, int ..., bool useEnabledMask, in v128 chunkEnabledMask) and an explicit interface implementation of IJobChunk.Execute; they are Burst-compiled and scheduled in parallel.
- Helper methods inside LaneColorJob and Update* jobs:
- Methods to select the active infoview from m_InfomodeChunks (GetServiceCoverageData, GetResourceAvailabilityData, GetNetStatusType, GetNetGeometryColor, HasNetStatus, HasNetGeometryColor).
- Flow helpers (FillEdgeFlow, FillNodeFlow, FillBuildingFlow, AddTempFlow, GetSubFlow, GetOriginalEdge/GetOriginalNode) used by LaneColorJob to assemble subflows and compute tile/warning values.
- Utility methods used when sampling pollution/land value/process estimates, and when mapping temporary entities to originals.
Notes: - Jobs rely on ComponentTypeHandle/ComponentLookup/BufferLookup passed in via the TypeHandle struct; the system obtains these with InternalCompilerInterface.Get wrappers when creating job instances. - Many of the used component types are game-specific (Edge, Node, EdgeColor, NodeColor, LaneColor, SubFlow, Infoview data types, NetCondition, Road, Pollution, etc.). Understanding the full behaviour often requires looking at helper utilities invoked (InfoviewUtils, NetUtils, GroundPollutionSystem, various GraphUtils).
Usage Example
// Example: the system gets created/managed by the game ECS world.
// Typical override in a derived system or code interacting with NetColorSystem:
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// grab required systems (NetColorSystem does this internally; shown here for illustration)
var toolSystem = World.GetOrCreateSystemManaged<ToolSystem>();
var prefabSystem = World.GetOrCreateSystemManaged<PrefabSystem>();
// set up queries similar to NetColorSystem (example)
var edgeQuery = GetEntityQuery(ComponentType.ReadOnly<Edge>(),
ComponentType.ReadWrite<EdgeColor>(),
ComponentType.Exclude<Deleted>());
// NetColorSystem.OnUpdate will schedule Burst jobs to compute EdgeColor/NodeColor/LaneColor
}
If you want, I can also: - Produce a short diagram of the job dependency chain used in OnUpdate. - Extract and document individual nested job structs in greater detail (parameters, buffers/lookups used).