Game.Debug.BuildableAreaDebugSystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: BuildableAreaDebugSystem is a debug/system utility used to visualize and measure how "buildable" the terrain is across the NaturalResource texture grid. It schedules a parallel job (BuildableAreaGizmoJob) across NaturalResourceSystem.kTextureSize * kTextureSize cells to calculate a buildability value per cell (using AreaResourceSystem.CalculateBuildable), draws a colored gizmo box for each cell with buildability > 0, and accumulates an average buildable fraction. The system reads Terrain, Water and NaturalResource data and uses GizmosSystem to draw. It exposes a "Strict" option which, when enabled, overrides the configured buildable land max slope with a stricter Bounds1(0f, 0.3f). The computed average is cached in m_LastBuildableArea and exposed through the buildableArea property.
Fields
-
private TerrainSystem m_TerrainSystem
Used to obtain terrain height data (TerrainHeightData) and to register a CPU height reader for the scheduled job. -
private WaterSystem m_WaterSystem
Used to obtain water surface data (WaterSurfaceData) and to register a surface reader for the scheduled job. -
private NaturalResourceSystem m_NaturalResourceSystem
Used to obtain natural resource cell data (CellMapData) and to register a reader for the scheduled job. -
private GizmosSystem m_GizmosSystem
Used to request a GizmoBatcher to draw gizmo lines from inside the job and to register the batcher writer dependency. -
private Option m_StrictOption
A debug option labelled "Strict" (default disabled). When enabled, uses a stricter max slope bound for buildability calculation (Bounds1(0f, 0.3f)) instead of the value from AreasConfigurationData. -
private NativeAccumulator<AverageFloat> m_BuildableArea
Accumulator used to compute the average buildability across all cells in a thread-safe, job-friendly manner. Allocated with Allocator.Persistent and disposed in OnDestroy. -
private float m_LastBuildableArea
Cached result of the last update's average buildability. Exposed via the buildableArea property. -
private TypeHandle __TypeHandle
Compiler-generated struct for assigning/holding type handles. Internal/implementation detail. -
private EntityQuery __query_1438325908_0
EntityQuery used to fetch AreasConfigurationData (singleton) when the Strict option is not enabled.
Properties
public float buildableArea { get; private set }
Returns the last computed average buildable fraction (m_LastBuildableArea). Updated each OnUpdate from m_BuildableArea.GetResult().average. This is a read-only (public getter) property for external code to inspect the current debug metric.
Constructors
public BuildableAreaDebugSystem()
Default constructor. Typical initialization work is done in OnCreate; the constructor itself does no special work.
Methods
-
protected override void OnCreate()
Initializes the system: grabs references to required systems (GizmosSystem, TerrainSystem, WaterSystem, NaturalResourceSystem), requires AreasConfigurationData for update, allocates the NativeAccumulator for averaging, registers the "Strict" option, and disables the system by default (base.Enabled = false). This is where long-lived resources are created. -
protected override void OnDestroy()
Disposes the NativeAccumulator m_BuildableArea and invokes base.OnDestroy(). Cleans up persistent allocations created in OnCreate. -
protected override JobHandle OnUpdate(JobHandle inputDeps)
Main update: retrieves the previous average from the accumulator and clears it, builds and schedules a BuildableAreaGizmoJob that: - gets a GizmoBatcher (and its dependency),
- reads NaturalResource cell data (and its dependency),
- reads terrain height data and water surface data,
- selects buildable-land max-slope either from AreasConfigurationData or the Strict option,
- writes per-cell buildability into the accumulator as a parallel writer.
Combines dependencies via JobUtils.CombineDependencies and schedules the parallel job across NaturalResourceSystem.kTextureSize * kTextureSize with batch size NaturalResourceSystem.kTextureSize. After scheduling, it registers jobHandle with GizmosSystem, TerrainSystem, WaterSystem and NaturalResourceSystem so they track the job dependencies. Returns the scheduled jobHandle.
-
private void __AssignQueries(ref SystemState state)
Sets up the EntityQuery used to fetch AreasConfigurationData (includes systems). Called from OnCreateForCompiler. Compiler-generated query wiring. -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and assigns type handles. Used to satisfy the ECS code generation/runtime checks.
Nested types / helper methods (job details):
- BuildableAreaGizmoJob : IJobParallelFor (nested struct)
- Execute(int index): For the given natural-resource cell index, computes the cell center, calls AreaResourceSystem.CalculateBuildable to get a 0..1 buildability value (uses natural resource cell size, water surface and terrain height data and provided max-slope bounds). It accumulates the value into m_Average and, if > 0, computes a colored square scaled by sqrt(buildability) and draws its 4 edges using DrawLine.
-
DrawLine(float3 a, float3 b, Color color): Samples terrain heights for endpoints (TerrainUtils.SampleHeight) and issues m_GizmoBatcher.DrawLine with those world-space points.
-
TypeHandle.__AssignHandles(ref SystemState state)
- Empty/aggressive-inlined placeholder in this code; present for codegen reasons.
Usage Example
// Enable the debug system when you want to visualize buildable cells, then read the average.
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Enable the system so it runs every frame while debugging.
Enabled = true;
}
// Elsewhere (e.g. another system or MonoBehaviour), read the last computed average:
var sys = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<Game.Debug.BuildableAreaDebugSystem>();
if (sys != null)
{
float averageBuildable = sys.buildableArea;
Debug.Log($"Average buildable fraction: {averageBuildable}");
}