Skip to content

Game.Simulation.TelecomCoverageSystem

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: class

Base: CellMapSystem, IJobSerializable

Summary:
TelecomCoverageSystem computes the city's telecom (mobile/wireless) coverage and network load on a 128x128 cell map. It gathers residential/work density from citizens and employees, iterates telecom facility entities, computes per-cell signal strength, accumulates network capacity and load, and produces both a TelecomCoverage texture/map and an aggregate TelecomStatus. The heavy per-frame work is performed in a Burst-compiled job (TelecomCoverageJob) using NativeCollections and Unity.Entities chunk queries; terrain height sampling and city modifiers are considered when calculating obstruction and capacity. The system schedules the job, manages lifetime of native arrays used for status, and integrates with the game's terrain and city systems.


Fields

  • public const int TEXTURE_SIZE = 128
    Defines the resolution (128) of the square coverage texture/map (resulting texture size = 128x128).

  • private TerrainSystem m_TerrainSystem
    Reference to the world's TerrainSystem used to fetch height data for obstruction and LOS (line-of-sight) calculations.

  • private CitySystem m_CitySystem
    Reference to the CitySystem used to access the city entity (and city-wide modifiers).

  • private EntityQuery m_DensityQuery
    EntityQuery used to gather archetype chunks that contain citizen density sources (household citizens and employees).

  • private EntityQuery m_FacilityQuery
    EntityQuery used to gather telecom facility entities (telecom buildings including transforms and prefabs; excludes temporary/deleted/service-upgrade markers).

  • private NativeArray<TelecomStatus> m_Status
    Persistent NativeArray used to store the computed TelecomStatus for the city (capacity, load, quality). Kept with Allocator.Persistent and disposed on destroy.

  • private TypeHandle __TypeHandle
    Internal cached type handles and lookups for component types and buffer types used by the scheduled job (for fast access to ComponentTypeHandle, BufferTypeHandle and ComponentLookup objects).

  • private struct TelecomCoverageJob (nested)
    Burst-compiled IJob that performs the main computation: collects density, computes signal strengths and obstruction, distributes network capacity across cells, aggregates per-cell TelecomCoverage and overall TelecomStatus.

  • private struct TypeHandle (nested)
    Container struct that stores ComponentTypeHandle / BufferTypeHandle / ComponentLookup references and exposes __AssignHandles to initialize them from SystemState.

Properties

  • public int2 TextureSize => new int2(128, 128)
    Returns the coverage texture size as an int2 (width, height). Useful for consumers needing the map dimensions (maps use 128 x 128 cells).

Constructors

  • public TelecomCoverageSystem()
    Default constructor. The system performs initialization in OnCreate; the constructor itself does no special work besides standard object instantiation.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes required systems (TerrainSystem, CitySystem), builds the EntityQuery objects for density and facilities, allocates m_Status (NativeArray) and calls CreateTextures(128) to prepare the map textures. This is where the system wires up its dependencies and persistent native memory.

  • [Preserve] protected override void OnDestroy()
    Disposes the persistent m_Status NativeArray and calls base.OnDestroy. Ensures native resources are released on system destruction.

  • [Preserve] protected override void OnUpdate()
    Main update entry. If terrain height data is available, it:

  • asynchronously gets archetype chunk lists for density and facility queries,
  • configures and schedules the TelecomCoverageJob (Burst compiled) with appropriate component handles, lookups and buffers,
  • disposes chunk lists after scheduling,
  • registers the job with TerrainSystem as a CPU reader (for height sampling),
  • registers the job as a writer for the owned map data and assigns base.Dependency to the scheduled job handle. The job computes the per-cell coverage map and updates m_Status.

  • protected override void OnCreateForCompiler()
    Compiler helper used to assign queries and type handles when systems are compiled/initialized by the runtime. Calls __AssignQueries and populates __TypeHandle by invoking __AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Internal method that sets up any entity queries at compile-time; used by OnCreateForCompiler. (In this implementation the method body contains a no-op EntityQueryBuilder call.)

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Initializes ComponentTypeHandle, BufferTypeHandle and ComponentLookup fields used by the job from the provided SystemState. Called during system setup to cache handles for fast access.

  • private helpers inside TelecomCoverageJob (listed here because they are central to how the system works):

  • Execute() — entry point for the IJob. Allocates temporary NativeArray buffers for density and facility data, collects density, calculates signal strengths for each facility, computes network capacity distribution and writes TelecomCoverage cells and TelecomStatus. Disposes temporaries at end.
  • CalculateSignalStrength(...) (overloads) — compute per-cell signal strengths either ignoring terrain penetration (takes terrain into account, sampling heights and obstruct slopes) or simple un-obstructed distance-based strength.
  • CalculateCellSignalStrength(...) — computes signal strength at one cell considering terrain obstruction slope and applies attenuation.
  • CalculateNetworkUsers(...) — for a facility's area, compute the number of network users that would connect (weighted by signal share).
  • AddNetworkCapacity(...) — distribute a facility's capacity into the facilityData cells weighted by per-cell signal contribution.
  • AddSignalStrengths(...) — accumulate multiple facilities' contributions into each cell (combining probabilities so that final coverage is 1 - Π(1 - s_i)).
  • AddDensity(...) — add population/employee counts into the densityData per-cell.
  • CalculateTelecomCoverage(...) — finalizes per-cell TelecomCoverage entries (encodes signal strength and load into bytes).
  • CalculateTelecomQuality(...) — computes a single quality metric across the map (density-weighted coverage quality).
  • GetEfficiencyFactor(...) — reads building efficiency (or temp/original prefab buffers) and returns an efficiency multiplier used to scale range and capacity.

Notes about job design: - The job uses many Native containers (NativeArray, NativeList) allocated with Allocator.Temp and disposed inside Execute. - It uses chunk access (ArchetypeChunk.GetNativeArray, GetBufferAccessor) with pre-captured ComponentTypeHandles and BufferTypeHandles. - Terrain sampling is performed via TerrainHeightData passed into the job and TerrainSystem registered as CPU reader for safe concurrent height reads. - City modifiers and installed upgrades are applied to facility stats before computing effective range/capacity.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // The TelecomCoverageSystem initializes its textures and queries in its OnCreate.
    // You can query the texture size if you need to allocate buffers or read the map:
    var size = this.World.GetOrCreateSystemManaged<Game.Simulation.TelecomCoverageSystem>().TextureSize;
    UnityEngine.Debug.Log($"Telecom coverage texture size: {size.x} x {size.y}");
}

Additional notes for modders: - The system exposes the coverage map via the CellMapSystem base. To read the per-cell coverage data you must access the map created by the system (GetMap) or tap into the relevant ECS components if you need runtime values. - If you need to alter facility behavior (range, capacity), modify TelecomFacilityData on the prefab or apply CityModifier entries of type CityModifierType.TelecomCapacity. - Be careful when interacting with internal NativeArray fields (like m_Status) — they are private; preferred approach is to expose readonly queries or create a separate system that reads the map via the CellMapSystem API to avoid race conditions. - The job uses BurstCompile for performance; any changes to the job must remain compatible with Burst (avoid managed references inside the job structs).