Skip to content

Game.Simulation.WeatherPhenomenonSystem

Assembly: Assembly-CSharp (game runtime assembly)
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
WeatherPhenomenonSystem drives the simulation of weather phenomena (storms, lightning, accident-inducing events, etc.) in the game's ECS world. It schedules a parallel IJobChunk (WeatherPhenomenonJob) that, per weather event entity, updates intensity, moves the phenomenon and hotspot according to wind and instability, emits lightning strikes, identifies affected static objects and network lanes, creates event effects (FaceWeather, Impact, Endanger, Ignite), and informs other systems (wind, terrain, water, render, search systems) about readers/writers required for safety. The system runs on a fixed interval (every 16 frames) and integrates DOTS data (ComponentLookup/BufferLookup, NativeQuadTree searches, EntityCommandBuffer) to spawn/queue event-related entities and components efficiently.


Fields

  • private SimulationSystem m_SimulationSystem
    The SimulationSystem instance used to read the current simulation frame and other global simulation state.

  • private WindSystem m_WindSystem
    Reference to the WindSystem used to sample wind cell data.

  • private TerrainSystem m_TerrainSystem
    Reference to the TerrainSystem used to obtain terrain height data for sampling.

  • private WaterSystem m_WaterSystem
    Reference to the WaterSystem used to read water surface heights.

  • private CitySystem m_CitySystem
    Reference to the CitySystem used to query city-level data and modifiers.

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Search system providing a static-object spatial search tree used to query buildings and other static objects.

  • private Game.Net.SearchSystem m_NetSearchSystem
    Network search system that provides a spatial search tree for net (road/lane) queries.

  • private ClimateRenderSystem m_ClimateRenderSystem
    Renderer-facing system used for queuing lightning strike visuals and related render data.

  • private EndFrameBarrier m_EndFrameBarrier
    An EndFrameBarrier used to create an EntityCommandBuffer that defers structural changes until end of frame.

  • private EntityQuery m_PhenomenonQuery
    Query used to find all active WeatherPhenomenon event entities (excludes Deleted/Temp).

  • private EntityArchetype m_FaceWeatherArchetype
    Archetype used when creating FaceWeather event entities (component set: Event + FaceWeather).

  • private EntityArchetype m_ImpactArchetype
    Archetype used for Impact event entities (Event + Impact).

  • private EntityArchetype m_EndangerArchetype
    Archetype used to create Endanger event entities (Event + Endanger).

  • private EntityArchetype m_EventIgniteArchetype
    Archetype used for Ignite event entities (Event + Ignite).

  • private EntityQuery m_EDWSBuildingQuery
    Query that collects buildings that host Early Disaster Warning Systems (used to notify them when events end).

  • private TypeHandle __TypeHandle
    Container for all ComponentTypeHandle/BufferTypeHandle/ComponentLookup fields used by the job; assigned in OnCreateForCompiler to cache handles for fast access inside jobs.

  • private struct WeatherPhenomenonJob (nested)
    Nested burst-compiled IJobChunk that does the per-chunk processing of WeatherPhenomenon entities. Contains multiple helper nested iterators (LightningTargetIterator, EndangeredStaticObjectIterator, AffectedStaticObjectIterator, AffectedNetIterator) as well as the main Execute implementation that updates weather phenomenon state and spawns event effects.

Properties

  • None (no public properties exposed by this system)

Constructors

  • public WeatherPhenomenonSystem()
    Default constructor. The system is initialized by the ECS/World framework. Most initialization is done in OnCreate().

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the update interval (16 frames) indicating how often this system runs. Used by the engine scheduling.

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns the update offset (0). Used by the engine scheduling.

  • [Preserve] protected override void OnCreate()
    Sets up references to dependent systems (SimulationSystem, WindSystem, TerrainSystem, WaterSystem, CitySystem, SearchSystems, ClimateRenderSystem, EndFrameBarrier), creates archetypes (FaceWeather, Impact, Endanger, Ignite), builds required queries (phenomenon query, EDWS building query), caches entity query for update requirement, and calls RequireForUpdate to ensure the system only runs when phenomena exist.

  • [Preserve] protected override void OnUpdate()
    Creates and populates a WeatherPhenomenonJob instance with current read/write handles and external data (wind/terrain/water data, search trees, city modifiers, archetypes, random seed, command buffer writers, queues). Schedules the job as a parallel JobChunk, adds appropriate readers/writers to other systems for dependency tracking, and stores the returned JobHandle into base.Dependency. Also disposes temporary NativeArray of early disaster warning system entities once the job is scheduled.

  • protected override void OnCreateForCompiler()
    Compiler-time helper that assigns component/handle fields inside __TypeHandle. Called by framework when creating systems compiled with the Entities compiler support.

  • private void __AssignQueries(ref SystemState state)
    Internal helper stub used to initialize entity queries required by generated code paths. (In this file it is implemented as a no-op builder disposal, used by the code-gen flow.)

  • private void __AssignHandles(ref SystemState state) (indirect, inside TypeHandle)
    Populates ComponentTypeHandle, BufferTypeHandle and ComponentLookup fields used by the job. Called from OnCreateForCompiler to cache handles for later job usage.

  • Nested job methods (defined inside WeatherPhenomenonJob):

  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Core chunk processing logic: updates duration/intensity, moves phenomenon and hotspot using wind and instability logic, updates hotspot frame buffers, creates FaceWeather, Endanger, Impact, Ignite entities as appropriate, queues lightning strikes, and deletes event entity when finished.
  • LightningStrike(ref Random random, int jobIndex, Entity eventEntity, Game.Events.WeatherPhenomenon weatherPhenomenon, PrefabRef eventPrefabRef)
    Finds a lightning target (building) using a specialized quad-tree iterator, enqueues a LightningStrike for render, and may spawn an Ignite event if prefab fire data indicates ignition probability and target supports fire hazards.
  • FindEndangeredObjects(...)
    Uses a line sweep based on wind to find buildings that should receive an Endanger component (evacuation/stay-indoors).
  • FindAffectedObjects(...)
    Queries static objects inside the hotspot circle and enqueues FaceWeather events where severity exceeds previously recorded severity.
  • FindAffectedEdges(...)
    Iterates net search tree to probabilistically pick traffic subjects (cars) and create Impact events (accidents) according to TrafficAccidentData.

  • NOTE: WeatherPhenomenonJob contains several nested iterator structs:

  • LightningTargetIterator — finds the best building to receive a lightning strike inside quad-tree bounds.
  • EndangeredStaticObjectIterator — evaluates buildings along a wind-extended line to mark them as endangered and create Endanger entities.
  • AffectedStaticObjectIterator — checks buildings inside hotspot circle to create FaceWeather events.
  • AffectedNetIterator — scans net (sub-lane) structures to pick moving cars that may be impacted; creates Impact events and modifies Moving/velocity deltas when appropriate.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Typical initialization performed by this system: cache dependent systems,
    // create archetypes and queries, and require updates only if phenomena exist.
    m_SimulationSystem = base.World.GetOrCreateSystemManaged<SimulationSystem>();
    m_WindSystem = base.World.GetOrCreateSystemManaged<WindSystem>();
    m_PhenomenonQuery = GetEntityQuery(
        ComponentType.ReadWrite<Game.Events.WeatherPhenomenon>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Temp>());

    m_FaceWeatherArchetype = base.EntityManager.CreateArchetype(
        ComponentType.ReadWrite<Game.Common.Event>(),
        ComponentType.ReadWrite<FaceWeather>());

    RequireForUpdate(m_PhenomenonQuery);
}

If you plan to modify or extend this system in a mod: - Be careful with scheduler/handle integration (AddReader/AddWriter calls and EndFrameBarrier/command buffer usage). - Respect data ownership: use ComponentLookup/BufferLookup with correct read-only flags and update handles via the TypeHandle pattern used here. - When adding new event effects, create appropriate archetypes and ensure other systems (render, search, water/terrain) are informed about readers/writers to avoid race conditions.