Skip to content

Game.ZoningInfoSystem

Assembly: Game
Namespace: Game.Tools

Type: class

Base: GameSystemBase, IZoningInfoSystem

Summary:
ZoningInfoSystem is an ECS system used by the zoning tool to evaluate potential zoning placements. It collects data from several game systems (zone tool & prefab data, pollution maps, resource/prefab systems, industrial demand and process data, land value, and zoning preferences) and produces a sorted list of zoning evaluation results (ZoneEvaluationUtils.ZoningEvaluationResult) stored in a persistent NativeList. The system runs when industrial process data is present and when the tool raycast returns a valid target; it completes required job dependencies, gathers required buffers/arrays, calls ZoneEvaluationUtils.GetFactors to compute scores, and sorts the results.


Fields

  • private EntityQuery m_ZoningPreferenceGroup
    Holds an EntityQuery targeting ZonePreferenceData (read-only). Used to read the current zoning preferences that influence evaluation.

  • private EntityQuery m_ProcessQuery
    EntityQuery for IndustrialProcessData (read-only). Required for update; used to fetch industrial process definitions used in evaluations.

  • private NativeList<ZoneEvaluationUtils.ZoningEvaluationResult> m_EvaluationResults
    Persistent NativeList that stores evaluation results produced in OnUpdate. Cleared at the start of each update and disposed in OnDestroy.

  • private ZoneToolSystem m_ZoneToolSystem
    Cached reference to the ZoneToolSystem (tool and currently selected prefab/area/office flags).

  • private IndustrialDemandSystem m_IndustrialDemandSystem
    Cached reference to the IndustrialDemandSystem to obtain industrial resource demand arrays.

  • private GroundPollutionSystem m_GroundPollutionSystem
    Cached reference to read ground pollution map.

  • private AirPollutionSystem m_AirPollutionSystem
    Cached reference to read air pollution map.

  • private NoisePollutionSystem m_NoisePollutionSystem
    Cached reference to read noise pollution map.

  • private PrefabSystem m_PrefabSystem
    Cached reference to PrefabSystem to get the entity/prefab for the zone being evaluated.

  • private ResourceSystem m_ResourceSystem
    Cached reference to ResourceSystem to get resource prefabs and data.

  • private ToolRaycastSystem m_ToolRaycastSystem
    Cached reference to ToolRaycastSystem used to get the current raycast result from the tool (where the player is pointing).

  • private TypeHandle __TypeHandle
    Compiler-generated handle structure that caches BufferLookup/ComponentLookup handles used in job/OnUpdate. Populated by __AssignHandles in OnCreateForCompiler.


Properties

  • public NativeList<ZoneEvaluationUtils.ZoningEvaluationResult> evaluationResults { get }
    Read-only accessor exposing the m_EvaluationResults list. Contains the results produced by the last OnUpdate. Note: this is a NativeList managed by the system (persistent) — read it only after the system has updated (and after its job dependencies are completed). If you need the results for your own jobs, copy them to another Native container or convert to a NativeArray/managed array and manage lifetimes appropriately.

Constructors

  • public ZoningInfoSystem()
    Default constructor. Standard compiler-generated constructor for an ECS system. Initialization of fields and system references happens in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes the system: gets references to required managed systems (ZoneToolSystem, IndustrialDemandSystem, pollution systems, PrefabSystem, ResourceSystem, ToolRaycastSystem), creates EntityQueries (m_ProcessQuery for IndustrialProcessData and m_ZoningPreferenceGroup for ZonePreferenceData), allocates the persistent NativeList m_EvaluationResults, and calls RequireForUpdate(m_ProcessQuery) so the system only updates when industrial process data exists.

  • protected override void OnDestroy()
    Disposes the persistent m_EvaluationResults NativeList and calls base.OnDestroy. Ensures no Native memory leak.

  • protected override void OnUpdate()
    Core evaluation logic:

  • Clears m_EvaluationResults.
  • Uses m_ToolRaycastSystem.GetRaycastResult to get the tool hit result; checks for Block and Owner components for the hit owner entity.
  • Completes base.Dependency to ensure job safety before accessing managed/component data.
  • Retrieves BufferLookup/ComponentLookup handles via InternalCompilerInterface (through __TypeHandle).
  • Reads ZonePreferenceData via m_ZoningPreferenceGroup.ToComponentDataArray.
  • Gets industrial resource demand array from m_IndustrialDemandSystem (async JobHandle handled and completed).
  • Gets resource prefabs from m_ResourceSystem and ResourceData ComponentLookup.
  • Reads pollution maps (ground, air, noise) from respective systems (async returns and handles completed).
  • Computes combined pollution at the hit position.
  • Reads land value for the owner and adjusts it based on the prefab's ZonePropertiesData (space multipliers / residential scaling).
  • Gets the prefab entity and its ProcessEstimate buffer (read-only).
  • Reads IndustrialProcessData list via m_ProcessQuery.ToComponentDataListAsync and completes that handle.
  • Calls ZoneEvaluationUtils.GetFactors(...) with all gathered data to populate m_EvaluationResults.
  • Disposes temporary NativeArrays and NativeLists used for queries and sorts m_EvaluationResults.

Important notes: the method carefully completes outstanding JobHandles when needed to safely access native data synchronously, and uses temporary Native containers (allocated with TempJob/Temp) that are disposed in the same frame.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper used by OnCreateForCompiler; here it currently creates and disposes an EntityQueryBuilder (no runtime query assignment beyond what OnCreate does).

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to populate component/buffer lookup handles used by the system (generated pattern for source-generated ECS compatibility).

  • TypeHandle.__AssignHandles(ref SystemState state)
    Assigns BufferLookup, ComponentLookup, and ComponentLookup to the TypeHandle fields with read-only flags. Used by OnCreateForCompiler so lookups are available in OnUpdate.


Usage Example

// Example: read evaluation results from another managed system or MonoBehaviour after the world updates.
// Ensure you access results after ZoningInfoSystem.OnUpdate has run for this frame.

var zoningInfoSystem = World.DefaultGameObjectInjectionWorld
    .GetExistingSystemManaged<Game.Tools.ZoningInfoSystem>();

if (zoningInfoSystem != null)
{
    // The system populates evaluationResults during its OnUpdate.
    // If calling from another system's OnUpdate you must ensure ordering (update after ZoningInfoSystem),
    // and complete any dependencies if you will use the data on jobs.
    var results = zoningInfoSystem.evaluationResults;

    // example: copy results into a managed array for safe use on the main thread
    var copy = results.ToArray(); // ZoneEvaluationUtils.ZoningEvaluationResult[]
    // ... examine copy array ...

    // Note: Do NOT dispose zoningInfoSystem.evaluationResults (managed by the system).
}

Additional notes: - evaluationResults is a persistent NativeList allocated with Allocator.Persistent by the system; it is cleared each update and disposed in OnDestroy. Do not dispose it yourself. - If you want to use evaluationResults on a job, copy contents to a separate NativeArray/NativeList and manage job dependencies and lifetimes correctly (complete the system's dependency where necessary). - This system relies on several other game systems; ensure those systems are present in the world when interacting with ZoningInfoSystem.