Skip to content

Game.EndFrameBarrier

Assembly:
Assembly-CSharp (game code)

Namespace:
Game.Simulation

Type:
class RentAdjustSystem

Base:
GameSystemBase

Summary:
RentAdjustSystem is a simulation system that periodically recalculates rents and rent-related state for buildings. It schedules a Burst-compiled IJobChunk (AdjustRentJob) that iterates building entities (filtered by UpdateFrame) and:

  • Computes rent per renter using building property data, building level, lot size, land value and economy parameters.
  • Updates PropertyRenter components with the current rent and enables PropertySeeker when renters can’t afford rent.
  • Adds or removes PropertyOnMarket components for properties with too few renters.
  • Manages the BuildingFlags.HighRentWarning flag and the associated high-rent notification icon using IconCommandBuffer (via IconCommandSystem).
  • Processes pollution-related building notifications (ground, air, noise) for residential buildings.
  • Enforces maximum renter counts and removes extra renters if necessary.
  • Uses many subsystems and data sources (resource system, pollution maps, tax rates, company/workplace data, etc.) and is optimized with Unity’s DOTS (IJobChunk, ComponentLookup/BufferLookup, SharedComponentTypeHandle, Burst).

The system runs in parallel via JobChunkExtensions.ScheduleParallel and registers readers/writers with EndFrameBarrier, resource/pollution/tax/telecom systems and IconCommandSystem to manage dependencies.


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch
    {{ YOUR_INFO }}
  • Note: The RentAdjustSystem source does not contain a Stopwatch field; instead, it contains a number of private fields and subsystem references used to drive the rent-adjusting logic. Important private fields in this system include:

    • EntityQuery instances for many parameter singletons (EconomyParameterData, PollutionParameterData, BuildingConfigurationData, CitizenHappinessParameterData, etc.) and a building query (m_BuildingQuery) that targets Building entities with Renter buffers.
    • Subsystem references obtained in OnCreate: SimulationSystem, EndFrameBarrier, ResourceSystem, GroundPollutionSystem, AirPollutionSystem, NoisePollutionSystem, TelecomCoverageSystem, CitySystem, TaxSystem, IconCommandSystem.
    • Helper fields like cycles and an internal TypeHandle (__TypeHandle) that caches Component/Buffer type handles for job scheduling.
    • Constants: kUpdatesPerDay = 16 controls how frequently the system updates relative to the simulation frame.
  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    {{ YOUR_INFO }}

  • Note: The compiled source schedules a JobHandle (jobHandle) for the AdjustRentJob and registers that handle with the EndFrameBarrier via m_EndFrameBarrier.AddJobHandleForProducer(jobHandle). The system also adds the job as a reader to resource/pollution/tax/telecom systems and provides the IconCommandSystem with a command buffer writer. This integration ensures proper dependency management between readers and the job producer.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    {{ YOUR_INFO }}
  • Note: The RentAdjustSystem does not expose a public producerHandle property in the provided source. The system manages job handles internally and registers them with the EndFrameBarrier and other systems. For update scheduling, it provides the method GetUpdateInterval which influences when the system runs relative to the simulation frame.

Constructors

  • public EndFrameBarrier()
    {{ YOUR_INFO }}
  • Note: The RentAdjustSystem has a parameterless constructor marked with [Preserve]:
    • [Preserve] public RentAdjustSystem() { }
    • It performs no special construction logic; initialization is done in OnCreate.

Methods

  • protected virtual OnCreate() : System.Void
    {{ YOUR_INFO }}
  • OnCreate (override): Initializes the system by acquiring references to required systems and creating EntityQueries for dependent parameter data and the buildings query:

    • Acquires SimulationSystem, EndFrameBarrier, ResourceSystem, GroundPollutionSystem, AirPollutionSystem, NoisePollutionSystem, TelecomCoverageSystem, CitySystem, TaxSystem, IconCommandSystem via World.GetOrCreateSystemManaged.
    • Sets up EntityQuery instances for EconomyParameterData, DemandParameterData, BuildingConfigurationData, BuildingQuery (buildings with Renter buffer), extractor/healthcare/park/education/telecom/garbage/police/citizen happiness/pollution parameters.
    • Calls RequireForUpdate for queries that must exist for the system to run (so the system won't update if parameter singletons or required data are missing).
    • Also prepares internal type handles and will call __AssignHandles in the compiler orchestration path.
  • protected override void OnUpdate()
    {{ YOUR_INFO }}

  • OnUpdate: Builds and schedules the AdjustRentJob (Burst-compiled inner struct) as a parallel JobChunk that operates on the building query:

    • Computes the current update frame index via SimulationUtils.GetUpdateFrame using m_SimulationSystem.frameIndex, kUpdatesPerDay and the internal sub-step count (16).
    • Retrieves read-only pollution maps from GroundPollutionSystem, AirPollutionSystem, NoisePollutionSystem (these return NativeArray maps and JobHandle outputs for dependency chaining).
    • Gathers singleton parameter data (EconomyParameterData, PollutionParameterData, CitizenHappinessParameterData, BuildingConfigurationData).
    • Populates the AdjustRentJob fields: ComponentLookup/BufferLookup handles, shared UpdateFrame handle, resource prefabs, tax rates, city entity, IconCommandBuffer, and a ParallelWriter EntityCommandBuffer from EndFrameBarrier.
    • Schedules the AdjustRentJob with JobChunkExtensions.ScheduleParallel and combines dependencies with JobUtils.CombineDependencies.
    • Registers the scheduled job handle with EndFrameBarrier and adds the job as a reader to resource/pollution/tax/telecom systems and as a command buffer writer to IconCommandSystem.
    • Stores the job handle into base.Dependency.
  • AdjustRentJob (inner struct) key behaviors:
    {{ YOUR_INFO }}

  • A Burst-compiled IJobChunk that processes building chunks:

    • Uses SharedComponentTypeHandle to process only the buildings which match the current updateFrame index (so the job spreads building updates across frames).
    • For each building entity in the chunk:
    • Reads the building's prefab and checks for BuildingPropertyData and BuildingData to compute building-level parameters (level, lot size).
    • Gets land value from LandValue component on the building's m_RoadEdge if available.
    • Determines area type (residential/industrial/none) via SpawnableBuildingData and ZoneData and whether land value should be ignored via ZonePropertiesData.
    • Calls PropertyUtils.GetRentPricePerRenter to compute rentPricePerRenter using buildingPropertyData, building level, lot size, land value, area type and EconomyParameterData.
    • If building has PropertyOnMarket, updates its m_AskingRent.
    • Iterates renters (DynamicBuffer) in reverse:
      • If renter has PropertyRenter component, determines the renter's available income/worth:
      • For households: sum of household income + money resource amount.
      • For companies: calculates either company max profit per day (if workplace / process data present) or total worth from resources/vehicles/layout elements.
      • Sets PropertyRenter.m_Rent to rentPricePerRenter and writes it.
      • If rent > renter worth, sets PropertySeeker component enabled on the renter via the EntityCommandBuffer parallel writer.
      • Tracks counts to compute proportion of renters who can't afford rent.
      • If renter lacks PropertyRenter, removes it from the renters buffer and marks that renters changed (flag) — may later add PropertyOnMarket to the building.
    • Decides whether to add/remove a high-rent warning icon:
      • If >70% of tracked renters can't afford rent and CanDisplayHighRentWarnIcon returns true, adds high-rent notification icon and sets BuildingFlags.HighRentWarning.
      • Else removes icon and clears the flag.
    • Ensures renters length does not exceed building property count; if too many renters, removes the last renter and removes its PropertyRenter component.
    • If building becomes empty and had HighRentWarning set, removes the icon and clears the flag.
    • If prefabed (spawned) building, not abandoned/destroyed, renters were removed and building now has fewer renters than capacity, adds PropertyOnMarket with asking rent to put building on market.
    • Uses m_IconCommandBuffer (non-parallel) to add/remove icons for buildings and m_CommandBuffer (parallel EntityCommandBuffer) for component adds/removes on renters and buildings.
    • CanDisplayHighRentWarnIcon iterates renters and checks company/worker notifications and the household citizen buffers for any living citizens to decide if high-rent warning icon is appropriate.
    • ProcessPollutionNotification computes local pollution/noise bonuses using CitizenHappinessSystem helper methods and toggles BuildingNotifications (GroundPollution, AirPollution, NoisePollution) and corresponding icons based on thresholds from PollutionParameterData.
  • Other methods / helpers:
    {{ YOUR_INFO }}

  • GetUpdateInterval(SystemUpdatePhase): returns the update interval computed as 262144 / (kUpdatesPerDay * 16). This determines how frequently the system executes relative to simulation ticks.
  • __AssignQueries and OnCreateForCompiler: internal helpers used by the generated/compiled code to assign type handles and queries for DOTS compilation; generally not used by modders directly.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // RentAdjustSystem initializes its queries and subsystem references in OnCreate.
    // As a modder, ensure required singleton parameter entities (EconomyParameterData, PollutionParameterData, etc.)
    // are present if you want RentAdjustSystem to run. You can also read its effects by observing
    // PropertyRenter, PropertyOnMarket, BuildingNotifications and Building flags (HighRentWarning).
}

Notes for modders: - RentAdjustSystem is heavily integrated with the game’s DOTS architecture and many singleton parameter entities. To influence rent calculations you can: - Modify EconomyParameterData, CitizenHappinessParameterData, PollutionParameterData or BuildingConfigurationData singletons. - Change building property/prefab definitions (BuildingPropertyData, BuildingData, SpawnableBuildingData / ZoneData). - Intercept or add icons using IconCommandSystem (the system uses IconCommandBuffer to add/remove icons). - Be careful when interacting with internal ComponentLookups or BufferLookups; if you schedule your own jobs that read/write the same components, manage dependencies by registering readers/writers with the appropriate systems (EndFrameBarrier, resource/pollution systems, IconCommandSystem) or by combining job handles. - The AdjustRentJob is Burst-compiled and uses parallel IJobChunk scheduling; avoid calling managed code inside jobs and prefer the existing component/system primitives.