Game.Simulation.TelecomEfficiencySystem
Assembly:
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
This system updates telecom-related efficiency for buildings that consume telecom services. It schedules a parallel IJobChunk (TelecomEfficiencyJob) that iterates building chunks, optionally applies installed upgrade stats to consumption data, samples the telecom network quality from the TelecomCoverage system, computes a telecom efficiency factor (based on BuildingEfficiencyParameterData.m_TelecomBaseline and the building's telecom need) and writes that factor into each building's Efficiency buffer. The system runs periodically (GetUpdateInterval returns 32) and batches updates using an update-frame index computed from SimulationUtils.GetUpdateFrame with a per-day update resolution constant (kUpdatesPerDay = 512). If the telecom service prefab is locked, updates are skipped.
Fields
-
private const int kUpdatesPerDay = 512
This constant is used when computing the update-frame index (SimulationUtils.GetUpdateFrame). It defines the number of discrete update slots per simulated day for telecom updates. -
private SimulationSystem m_SimulationSystem
Reference to the global SimulationSystem used to obtain the current frame index for determining which subset of buildings to update this tick. -
private TelecomCoverageSystem m_TelecomCoverageSystem
Reference to the TelecomCoverageSystem. The system obtains a read-only CellMapDatafrom this system and registers as a reader to ensure proper job synchronization. -
private EntityQuery m_BuildingQuery
EntityQuery selecting all buildings that consume telecom: reads TelecomConsumer, Efficiency buffer, Building, UpdateFrame, Transform, PrefabRef and excludes Deleted and Temp. This query is used to schedule the TelecomEfficiencyJob over relevant entities. -
private TypeHandle __TypeHandle
Internal struct instance holding component type handles and component lookups (shared/regular/buffer type handles) used by the job. Assigned in OnCreateForCompiler. -
private EntityQuery __query_450882671_0
Internal EntityQuery used to fetch the singleton TelecomParameterData. Built with IncludeSystems option. -
private EntityQuery __query_450882671_1
Internal EntityQuery used to fetch the singleton BuildingEfficiencyParameterData. Built with IncludeSystems option. -
private struct TelecomEfficiencyJob
(nested private)
IJobChunk implementation that: - Checks UpdateFrame shared component against the current update-frame index to only process a subset of entities each tick.
- Reads PrefabRef, Transform, InstalledUpgrade buffers and writes to Efficiency buffer.
- Uses component lookups for PrefabRef and ConsumptionData to read base consumption data.
- Applies upgrades via UpgradeUtils.CombineStats when applicable.
- Samples telecom network quality via TelecomCoverage.SampleNetworkQuality and computes the telecom efficiency factor using a baseline and the building's telecom need. The computed factor is stored via BuildingUtils.SetEfficiencyFactor.
Internal method GetTelecomEfficiency(position, telecomNeed) computes: - float q = TelecomCoverage.SampleNetworkQuality(...) - if q < baseline: penalty = (1 - q/baseline)^2 * -0.01f * telecomNeed - return 1f + penalty
Properties
- This class does not expose any public properties.
Internal state is accessed via fields and queries; component access inside the job uses type handles populated in the TypeHandle struct.
Constructors
public TelecomEfficiencySystem()
Default constructor. Instance initialization is mostly handled in OnCreate / OnCreateForCompiler where type handles and queries are assigned and required systems/queries are registered.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 32. The system requests updates at this interval (frames) from the simulation framework; this determines how often OnUpdate is invoked relative to system scheduling. -
[Preserve] protected override void OnCreate()
Initializes references and queries: - Obtains SimulationSystem and TelecomCoverageSystem from the world.
- Builds m_BuildingQuery to select telecom-consuming buildings and calls RequireForUpdate on that query.
- Requires TelecomParameterData and BuildingEfficiencyParameterData singletons for update (RequireForUpdate
). -
This method sets up the prerequisites for OnUpdate to run.
-
[Preserve] protected override void OnUpdate()
Main update entry: - Reads the TelecomParameterData singleton and checks whether the telecom service prefab is locked (skips update when locked).
- Computes an update-frame index using SimulationUtils.GetUpdateFrame(m_SimulationSystem.frameIndex, kUpdatesPerDay, 16) to divide updates across frames.
- Constructs and schedules a TelecomEfficiencyJob with the relevant type handles, lookups, the telecom coverage CellMapData (obtained from m_TelecomCoverageSystem.GetData) and BuildingEfficiencyParameterData singleton.
-
Schedules the job in parallel using JobChunkExtensions.ScheduleParallel and combines dependencies; registers the job as a reader on m_TelecomCoverageSystem to enforce proper synchronization.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Internal helper used by the compiler-generated OnCreateForCompiler to build internal entity queries (__query_450882671_0 and __query_450882671_1) for the required singleton parameter data. Uses EntityQueryBuilder with IncludeSystems option. -
protected override void OnCreateForCompiler()
Compiler helper that assigns queries and component type handles via __AssignQueries and __TypeHandle.__AssignHandles. Called during system creation in compiled builds to set up the TypeHandle and internal queries. -
private struct TypeHandle
(nested)
Contains SharedComponentTypeHandle, ComponentTypeHandle and BufferTypeHandle instances used to access component arrays/buffers in the job. Method __AssignHandles(ref SystemState state) populates these handles from the SystemState.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Cache references to other systems and build the query selecting telecom-consuming buildings:
m_SimulationSystem = base.World.GetOrCreateSystemManaged<SimulationSystem>();
m_TelecomCoverageSystem = base.World.GetOrCreateSystemManaged<TelecomCoverageSystem>();
m_BuildingQuery = GetEntityQuery(
ComponentType.ReadOnly<TelecomConsumer>(),
ComponentType.ReadWrite<Efficiency>(),
ComponentType.ReadOnly<Building>(),
ComponentType.ReadOnly<UpdateFrame>(),
ComponentType.ReadOnly<Transform>(),
ComponentType.ReadOnly<PrefabRef>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Temp>()
);
RequireForUpdate(m_BuildingQuery);
RequireForUpdate<TelecomParameterData>();
RequireForUpdate<BuildingEfficiencyParameterData>();
}
Notes and modder tips: - The telecom efficiency formula applies a small negative quadratic penalty when sampled network quality falls below the configured baseline. The penalty scales with the building's telecom need via ConsumptionData.m_TelecomNeed. - The system updates a fraction of buildings each tick using the UpdateFrame shared component and the computed update-frame index; this is to spread work across frames. - When reading/writing buffers and component lookups inside jobs, ensure you understand Unity's Jobs/Entities synchronization patterns — this system acquires and combines dependencies and registers as a reader of TelecomCoverageSystem to avoid race conditions. - To modify behavior, consider adjusting BuildingEfficiencyParameterData or swapping the telecom baseline, or extending UpgradeUtils.CombineStats to alter how upgrades influence consumption data before efficiency evaluation.