Game.Debug.LandValueDebugSystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary:
LandValueDebugSystem is a debug visualization system used by Cities: Skylines 2 to draw gizmos that represent land values across the terrain. It reads land-value cells and edge land-values from the game's ECS (LandValueSystem and components such as LandValue and LandValueParameterData) and issues draw commands via the GizmosSystem. Visualization is provided in two modes (cell-based and edge-based) which can be toggled through the debug options added by this system. The system schedules two jobs:
- LandValueGizmoJob (IJob) — iterates land-value cells and draws wire cubes for cells above a baseline.
- LandValueEdgeGizmoJob (IJobChunk) — iterates edges (or curves) and draws wire cylinders at edge midpoints or curve midpoints.
The system samples terrain height to position the gizmos correctly and applies a configurable visual height scale. It also integrates with the DefaultToolSystem to toggle debugLandValue when enabled/disabled.
Fields
-
private LandValueSystem m_LandValueSystem
This is the game system that provides the land value map and related data. Used to fetch the land-value map via GetMap for the cell visualization job. -
private GizmosSystem m_GizmosSystem
Used to obtain a GizmoBatcher for issuing batched gizmo draw calls. The system registers writer dependencies on scheduled jobs so batching and synchronization are correct. -
private TerrainSystem m_TerrainSystem
Used to sample terrain heights (TerrainHeightData) so gizmos are placed at correct elevations. -
private DefaultToolSystem m_DefaultToolSystem
Used to flip the debugLandValue flag when this debug system is enabled/disabled (so other UI/tools are aware). -
private EntityQuery m_LandValueEdgeQuery
EntityQuery used to iterate edges with LandValue components for the edge-based visualization job. Constructed in OnCreate to match Edge + LandValue and exclude Deleted/Temp/Hidden. -
private EntityQuery m_LandValueParameterQuery
EntityQuery used to obtain the LandValueParameterData singleton (contains baseline threshold and other parameters). -
public Option m_LandValueCellOption
An Option object representing the "Land value (Cell)" toggle in the debug UI. Default enabled in OnCreate. When enabled the cell-based job is scheduled. -
private Option m_EdgeLandValueOption
An Option object representing the "Land value (Edge)" toggle in the debug UI. Default enabled in OnCreate. When enabled the edge-based job is scheduled. -
private static readonly float heightScale = 1f
Scale factor applied to land-value when computing the height of drawn gizmos (wire cubes/cylinders). Constant in this class with value 1. -
private TypeHandle __TypeHandle
Internal container for ComponentTypeHandle and ComponentLookup instances used when scheduling the job-chunk (cache of handles assigned in OnCreateForCompiler / __AssignHandles). -
private struct LandValueEdgeGizmoJob
(nested)
IJobChunk implementation that draws gizmos per chunk of Edge/LandValue (and optional Curve) entities. It reads Edge, Curve, LandValue components and a Node lookup, samples terrain height and draws wire cylinders at midpoints or curve centers. -
private struct LandValueGizmoJob
(nested)
IJob implementation that iterates the native land-value map (LandValueCell[]), samples terrain height for each cell, checks against the baseline and draws wire cubes for cells above baseline. -
private struct TypeHandle
(nested)
Helper struct that stores ComponentTypeHandle/ComponentLookup references and provides __AssignHandles to initialize them from a SystemState. Used to obtain read-only handles for scheduling jobs.
Properties
- None (this system exposes no public properties).
This class uses fields and options; interaction is through debug UI options and overridden lifecycle methods.
Constructors
public LandValueDebugSystem()
Default constructor. Marked with [Preserve] attribute in the source to avoid stripping (preserve across managed linkers). Initialization of systems and queries occurs in OnCreate rather than the constructor.
Methods
-
protected override void OnCreate()
: System.Void
Initializes the system references (LandValueSystem, GizmosSystem, TerrainSystem, DefaultToolSystem), sets up the EntityQueries (m_LandValueParameterQuery and m_LandValueEdgeQuery), adds the debug options ("Land value (Cell)" and "Land value (Edge)"), and disables the system by default (base.Enabled = false). This is the primary setup entry point for the system. -
public override void OnEnabled(DebugUI.Container container)
: System.Void
Called when the debug system is enabled. Sets DefaultToolSystem.debugLandValue = true so other systems/tools know the land-value debug is active. -
public override void OnDisabled(DebugUI.Container container)
: System.Void
Called when the debug system is disabled. Resets DefaultToolSystem.debugLandValue = false. -
private static Color GetColor(Color a, Color b, Color c, float value, float maxValue1, float maxValue2)
: Color
Utility used by both jobs to map a numeric land value to a color gradient. Below maxValue1 it linearly interpolates between a and b; beyond that it interpolates between b and c up to maxValue2 (saturating beyond). -
protected override JobHandle OnUpdate(JobHandle inputDeps)
: Unity.Jobs.JobHandle
Schedules one or both gizmo jobs depending on the debug options: - If m_LandValueCellOption.enabled: calls m_LandValueSystem.GetMap(readOnly: true, out dependencies) and m_GizmosSystem.GetGizmosBatcher(out dependencies2) to set up dependencies, then schedules LandValueGizmoJob (IJob) combining dependencies and registers the gizmo batcher writer.
- If m_EdgeLandValueOption.enabled: builds a LandValueEdgeGizmoJob with component handles/lookups taken from __TypeHandle via InternalCompilerInterface methods and schedules it as a parallel JobChunk over m_LandValueEdgeQuery; registers the gizmo batcher writer.
- Adds a CPU height reader to m_TerrainSystem (m_TerrainSystem.AddCPUHeightReader) with the combined dependency before returning the final JobHandle.
This method coordinates job dependencies and ensures correct read/write access for batched gizmo drawing and terrain sampling.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
: System.Void
Compiler helper used when building with the code generation path. In this version it constructs and immediately disposes an EntityQueryBuilder (keeps a placeholder for query assignment used by the generated code). -
protected override void OnCreateForCompiler()
: System.Void
Called by generated code path; calls __AssignQueries and __TypeHandle.__AssignHandles to initialize handles when building for odd compiler scenarios. Marked to be preserved as part of the generated OnCreate flow. -
private struct LandValueGizmoJob.Execute()
andprivate struct LandValueEdgeGizmoJob.Execute(...)
The actual job Execute methods are implemented inside the nested structs. They run on worker threads and perform the drawing logic described above. Both check the corresponding option flag early and return if visualization is disabled at schedule time.
Notes about threading and safety: - The jobs use read-only ComponentTypeHandle/ComponentLookup for safe parallel access. - GizmoBatcher is passed into jobs — the system obtains a batcher via GizmosSystem.GetGizmosBatcher(out dependencies) and then registers AddGizmosBatcherWriter to ensure synchronization. - TerrainSystem provides a TerrainHeightData snapshot for CPU access and a CPU height reader is registered for the lifetime of the scheduled jobs.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_LandValueSystem = base.World.GetOrCreateSystemManaged<LandValueSystem>();
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
m_DefaultToolSystem = base.World.GetOrCreateSystemManaged<DefaultToolSystem>();
m_LandValueParameterQuery = GetEntityQuery(ComponentType.ReadOnly<LandValueParameterData>());
m_LandValueEdgeQuery = GetEntityQuery(
ComponentType.ReadOnly<Edge>(),
ComponentType.ReadOnly<LandValue>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Temp>(),
ComponentType.Exclude<Hidden>());
m_LandValueCellOption = AddOption("Land value (Cell)", defaultEnabled: true);
m_EdgeLandValueOption = AddOption("Land value (Edge)", defaultEnabled: true);
base.Enabled = false;
}
Additional notes: - The visualization thresholds (30f and 500f) used in GetColor are hard-coded in this implementation — they determine how colors are mapped to value ranges for edges and cells. - Gizmo visuals: cells are drawn as wire cubes (size 15x land-value-height x15), edges/curves drawn as wire cylinders (radius 5, height proportional to land value). - If you extend or modify this system, ensure JobHandle dependencies and GizmosSystem writers are handled as in OnUpdate to avoid race conditions.