Game.FireSimulationSystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
FireSimulationSystem is the ECS system responsible for simulating fire events in the game. It updates OnFire components, escalates or decays fire intensity, applies damage, requests fire rescue services, spawns destroy/damage/ignite events, and performs fire spread checks. Internally it schedules two Burst-compiled IJobChunk jobs (FireSimulationJob and FireSpreadCheckJob) and uses several game subsystems (simulation, search, prefab, telecom coverage, time, climate, fire hazard, icon command, local effects) and archetypes for event creation. The system runs at a fixed update interval (64 frames). It also holds helper data structures for fire hazard and structural integrity calculations and coordinates command buffers via an EndFrameBarrier.
Fields
-
private SimulationSystem m_SimulationSystem
Internal reference to the global SimulationSystem used to read simulation frame index and scheduling. -
private Game.Objects.SearchSystem m_SearchSystem
Used to query nearby objects for fire spread calculations (provides static search quad tree). -
private IconCommandSystem m_IconCommandSystem
Used to add/remove UI icons (fire notifications) for entities. -
private LocalEffectSystem m_LocalEffectSystem
Used to apply local modifiers (e.g., forest fire response time). -
private PrefabSystem m_PrefabSystem
Used to obtain prefabs and prefab-based data (e.g., FireConfigurationPrefab). -
private TelecomCoverageSystem m_TelecomCoverageSystem
Used to factor telecom coverage into response time calculations. -
private TimeSystem m_TimeSystem
Provides normalized time of day for darkness-based modifiers. -
private ClimateSystem m_ClimateSystem
Provides climate state (temperature, no-rain days) used for hazard calculations. -
private FireHazardSystem m_FireHazardSystem
Provides data for fire hazard calculation and tuning. -
private EndFrameBarrier m_EndFrameBarrier
Barrier used to create command buffers for jobs to produce entity events safely. -
private EntityQuery m_FireQuery
Query selecting entities with OnFire (and excluding Deleted/Temp) to process fires. -
private EntityQuery m_ConfigQuery
Query selecting the FireConfigurationData singleton. -
private EntityArchetype m_FireRescueRequestArchetype
Archetype used to create FireRescueRequest service request entities. -
private EntityArchetype m_DamageEventArchetype
Archetype used to create Damage event entities. -
private EntityArchetype m_DestroyEventArchetype
Archetype used to create Destroy event entities. -
private EntityArchetype m_IgniteEventArchetype
Archetype used to create Ignite event entities (when fire spreads to other objects). -
private EventHelpers.FireHazardData m_FireHazardData
Helper object used to compute fire hazard for prefabs/objects. -
private EventHelpers.StructuralIntegrityData m_StructuralIntegrityData
Helper object used to compute structural integrity factors used when applying damage from fire. -
private TypeHandle __TypeHandle
Generated type handle container used to cache Entity/Component/Buffer type handles and lookups for jobs.
Properties
- None (no public properties exposed by the system)
This system uses internal fields and job data; external interaction is via ECS components/events and configuration singletons.
Constructors
public FireSimulationSystem()
Default constructor (preserved). System initialization occurs in OnCreate rather than the constructor.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval for this system. Always returns 64, so the system is scheduled every 64 simulation frames. -
[Preserve] protected override void OnCreate()
Initializes subsystem references (GetOrCreateSystemManaged for many subsystems), sets up entity queries, creates archetypes for event entities (FireRescueRequest, Damage, Destroy, Ignite), constructs fire hazard/structural integrity helpers, and calls RequireForUpdate on the fire query so the system only updates when there are OnFire entities. -
[Preserve] protected override void OnUpdate()
Main scheduling method. Reads FireConfigurationData and FireConfigurationPrefab, updates helper data (m_FireHazardData, m_StructuralIntegrityData), prepares and schedules two Burst IJobChunk jobs: - FireSimulationJob: updates OnFire/Damaged/Efficiency, creates damage/destroy/fire rescue events, manages icons and resource updates.
-
FireSpreadCheckJob: checks for fire spread using a quad-tree search and emits Ignite events. It wires job dependencies with various subsystem readers/writers (TelecomCoverageSystem, LocalEffectSystem, IconCommandSystem, SearchSystem) and adds the producer job handle to the EndFrameBarrier so command buffers produced by the jobs are played back safely.
-
protected override void OnCreateForCompiler()
Auto-generated helper invoked by the runtime/compilation pipeline to assign queries and type handles for the system. Calls __AssignQueries and assigns the type handles through __TypeHandle. -
private void __AssignQueries(ref SystemState state)
Generated stub that sets up any additional queries at compile time; in this compiled class it currently builds and disposes an EntityQueryBuilder (no-op here).
Notes about nested job types (internal helpers):
- FireSimulationJob (IJobChunk, BurstCompiled)
Processes OnFire-containing entities in chunks: escalates/decays intensity, applies damage based on structural integrity and prefab fire escalation rate, creates Damage/Destroy events, requests fire rescue (FireRescueRequest) when appropriate, manages icons and efficiency factors, and sets up request frames based on time-of-day, telecom coverage, district modifiers, and local effects.
Key helper methods inside the job: - InitializeRequestFrame(...) — computes when to request rescue based on response time ranges, darkness/telecom modifiers, district/local modifiers, then sets onFire.m_RequestFrame. - RequestFireRescueIfNeeded(...) — creates FireRescueRequest entity if request frame has been reached and none exists.
- FireSpreadCheckJob (IJobChunk, BurstCompiled)
For each OnFire entity, uses a Random and FireData spread parameters to probabilistically attempt to ignite nearby objects. Uses a NativeQuadTree iterator (ObjectSpreadIterator) to query nearby entities (buildings/trees), compute fire hazard for targets and potentially create Ignite events.
ObjectSpreadIterator handles intersection tests with quad-tree bounds and TrySpreadFire which checks a randomness condition to create an Ignite event (via the command buffer) for susceptible nearby entities.
Concurrency and safety: - Jobs use EntityCommandBuffer.ParallelWriter created from m_EndFrameBarrier to safely create entities/components from background threads. - Several ComponentLookup/BufferLookup handles are used as read-only or write to pass state into the jobs. - SearchSystem static search tree and other subsystems are registered as readers and writers with corresponding job handles to ensure correct synchronization.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization the system performs: get references to required systems and set up queries/archetypes.
var simSystem = World.GetOrCreateSystemManaged<SimulationSystem>();
var prefabSystem = World.GetOrCreateSystemManaged<PrefabSystem>();
// For modders: you usually don't need to instantiate or modify FireSimulationSystem directly.
// Instead, interact with ECS components (e.g., add an OnFire component or adjust FireConfigurationData).
}