Skip to content

Game.UI.InGame.FireAndRescueInfoviewUISystem

Assembly:
Assembly-CSharp

Namespace:
Game.UI.InGame

Type:
class

Base:
InfoviewUISystemBase

Summary:
FireAndRescueInfoviewUISystem is an UI infoview system used by the Fire & Rescue info view. It collects fire-hazard related data for flammable entities (buildings and trees), computes an average fire hazard indicator and updates a bound UI indicator value. The system uses an IJobChunk (FireHazardJob) to scan matching entities in parallel, aggregates results into a NativeArray, and converts that into an IndicatorValue for the UI. It integrates with LocalEffectSystem, ClimateSystem, FireHazardSystem and PrefabSystem and reacts to changes in fire station entities and fire configuration prefabs.


Fields

  • private const string kGroup
    Name of the binding group used by the UI binding ("fireAndRescueInfo").

  • private LocalEffectSystem m_LocalEffectSystem
    Reference to the LocalEffectSystem used to obtain local-effect read data and register job readers.

  • private ClimateSystem m_ClimateSystem
    Reference to the ClimateSystem used to obtain temperature and climate related data for hazard calculation.

  • private FireHazardSystem m_FireHazardSystem
    Reference to the FireHazardSystem used to obtain fire hazard related counters (e.g., noRainDays).

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to fetch prefabs (like FireConfigurationPrefab) required by hazard calculations.

  • private EntityQuery m_FlammableQuery
    EntityQuery that matches flammable entities (Buildings or Trees) that are not fire stations, not on fire, not deleted and not temp. This is the primary query scanned by the FireHazardJob.

  • private EntityQuery m_FireStationsModifiedQuery
    EntityQuery to detect modifications (Created/Deleted/Updated) to fire station entities (used to know when to consider the view "Modified").

  • private EntityQuery m_FireConfigQuery
    EntityQuery to access the FireConfigurationData prefab entity used for configuration.

  • private NativeArray<float> m_Results
    A two-element NativeArray used as an accumulation buffer for the job: index 0 accumulates total risk, index 1 accumulates count of risk-contributing entities. Allocated with Allocator.Persistent and disposed in OnDestroy.

  • private EventHelpers.FireHazardData m_FireHazardData
    Helper struct holding precomputed/lookup data needed by the FireHazardJob and updated each PerformUpdate call (populated from systems/prefab/climate).

  • private ValueBinding<IndicatorValue> m_AverageFireHazard
    UI binding that exposes the computed average fire hazard as an IndicatorValue under the "fireAndRescueInfo" group with key "averageFireHazard".

  • private TypeHandle __TypeHandle
    Internal struct instance holding EntityTypeHandle and ComponentTypeHandle instances used to build the job's type handles.

  • private struct FireHazardJob (nested)
    IJobChunk that scans chunks of flammable entities and accumulates per-chunk risk and count into m_Result (the NativeArray passed in). It reads Building, CurrentDistrict, PrefabRef and optionally Damaged/UnderConstruction components and uses EventHelpers.FireHazardData to compute risk.

  • private struct TypeHandle (nested)
    Small helper struct that stores EntityTypeHandle and ComponentTypeHandle for required component types and provides __AssignHandles to initialize them from a SystemState.

Properties

  • protected override bool Active
    Overrides base Active property to return true when system is active OR when the bound average fire hazard indicator is active. Ensures the infoview remains active while the UI binding is active.

  • protected override bool Modified
    Overrides Modified to indicate if the fire stations set has recent modifications. Implemented as !m_FireStationsModifiedQuery.IsEmptyIgnoreFilter.

Constructors

  • public FireAndRescueInfoviewUISystem()
    Default parameterless constructor. The actual initialization of systems, queries, bindings and NativeArray occurs in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes system references (LocalEffectSystem, ClimateSystem, FireHazardSystem, PrefabSystem), creates entity queries (m_FlammableQuery, m_FireStationsModifiedQuery, m_FireConfigQuery), adds the UI binding (m_AverageFireHazard), allocates the m_Results NativeArray (size 2, persistent) and constructs the EventHelpers.FireHazardData helper. Marked with [Preserve].

  • protected override void OnDestroy()
    Disposes persistent resources created in OnCreate. Specifically disposes m_Results. Calls base.OnDestroy(). Marked with [Preserve].

  • protected override void PerformUpdate()
    Main update loop executed each frame. Steps:

  • Acquire read data from LocalEffectSystem (and its job dependency).
  • Fetch the FireConfigurationPrefab using m_FireConfigQuery.
  • If m_Results contains previous job results, complete base.Dependency, read m_Results, compute average risk (total risk / count or 0 if count == 0) and update m_AverageFireHazard with an IndicatorValue in range 0..100, then zero m_Results.
  • Update m_FireHazardData with environment/state (prefab, temperature, noRainDays).
  • Schedule FireHazardJob over m_FlammableQuery, passing type handles and the m_FireHazardData and m_Results buffer. Combine dependencies with local effect read dependencies and base.Dependency.
  • Register the job handle with LocalEffectSystem.AddLocalEffectReader and set base.Dependency to the returned handle.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper used to assign/query builder state. In the decompiled source it's essentially a placeholder creating/disposing an EntityQueryBuilder; included for compiler-generated path and called from OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler helper called on creation in some assembly configurations. It calls __AssignQueries and __TypeHandle.__AssignHandles to set up type handles for the job.

  • private void __AssignHandles(ref SystemState state) (inside TypeHandle)
    Assigns EntityTypeHandle and ComponentTypeHandle instances from the passed SystemState. Called by OnCreateForCompiler to initialize __TypeHandle.

  • void FireHazardJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The job's execution method (IJobChunk). Iterates the chunk's entities, reads PrefabRef, Building, CurrentDistrict, optional Damaged and UnderConstruction and calls m_FireHazardData.GetFireHazard to compute per-entity riskFactor. It sums riskFactor and counts contributing entities, then atomically adds per-chunk totals into m_Result[0] and m_Result[1] (here additive assignments to the array).

Notes on thread-safety: m_Result is a NativeArray shared across chunks; the job uses simple additions into m_Result[0/1] — in multithreaded contexts this relies on chunk-level execution ordering in this job or must be used carefully; this is how the original code wrote it (e.g., additive accumulation per chunk into a shared two-element NativeArray).

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // base.OnCreate sets up queries, bindings and allocates m_Results.
    // The system will schedule a FireHazardJob each update that populates m_Results,
    // and the PerformUpdate method aggregates into the bound indicator:
    // m_AverageFireHazard.Update(new IndicatorValue(0f, 100f, averageRisk));
}

If you need, I can: - Expand the usage example to show a sample mod workflow that reads the IndicatorValue from code, - Explain how to safely modify the job to use thread-safe accumulation (e.g., using NativeArray with Interlocked or NativeList per-chunk), - Or produce a documentation snippet for the nested FireHazardJob and TypeHandle types.