Skip to content

Game.UI.InGame.GarbageInfoviewUISystem

Assembly: Assembly-CSharp (Game)
Namespace: Game.UI.InGame

Type: class

Base: InfoviewUISystemBase

Summary:
GarbageInfoviewUISystem is an infoview UI system that aggregates data from all garbage facilities and related storage areas to provide UI bindings for the in-game garbage info panel. It collects processing rate, landfill capacity, and stored garbage totals by scheduling a Burst-compiled IJobChunk (UpdateGarbageJob) over an EntityQuery of garbage facilities. The system exposes bindings (GetterValueBinding) used by the UI and keeps an internal NativeArray (m_Results) of three running totals. It also reads the global garbage accumulation from GarbageAccumulationSystem for production/availability indicators.


Fields

  • private enum Result
    Used as indexes into m_Results: ProcessingRate = 0, GarbageCapacity = 1, StoredGarbage = 2. The system accumulates those three metrics into m_Results.

  • private const string kGroup = "garbageInfo"
    String constant used as the binding group id when creating GetterValueBinding instances.

  • private GarbageAccumulationSystem m_GarbageAccumulationSystem
    Reference to the world/system that tracks global garbage accumulation (used for production/availability indicators).

  • private GetterValueBinding<int> m_Capacity
    Getter binding that provides the total garbage capacity (landfills/long-term storage) to the UI.

  • private GetterValueBinding<int> m_StoredGarbage
    Getter binding that provides the total stored garbage to the UI.

  • private GetterValueBinding<float> m_ProcessingRate
    Getter binding that provides total processing rate (garbage processing speed) to the UI.

  • private GetterValueBinding<float> m_GarbageRate
    Getter binding that exposes the global garbage accumulation rate from GarbageAccumulationSystem.

  • private GetterValueBinding<IndicatorValue> m_ProcessingAvailability
    Getter binding that provides an IndicatorValue describing processing availability (comparing processing capacity to garbage accumulation).

  • private GetterValueBinding<IndicatorValue> m_LandfillAvailability
    Getter binding that provides an IndicatorValue for landfill/long-term storage availability (capacity vs stored).

  • private EntityQuery m_GarbageFacilityQuery
    EntityQuery selecting active garbage facility entities to iterate in the update job.

  • private EntityQuery m_GarbageFacilityModifiedQuery
    EntityQuery used to detect modifications (Created/Updated/Deleted) to garbage facilities for the Modified property.

  • private NativeArray<float> m_Results
    NativeArray length 3 (allocated with Allocator.Persistent) that stores aggregated results: index 0 = processing rate, 1 = garbage capacity, 2 = stored garbage. It must be disposed in OnDestroy (the system does so).

  • private TypeHandle __TypeHandle
    Container for EntityTypeHandle, BufferTypeHandle and ComponentLookup handles required by UpdateGarbageJob. Populated via __TypeHandle.__AssignHandles(ref state) in OnCreateForCompiler.

  • private struct UpdateGarbageJob (nested)
    Burst-compiled IJobChunk that iterates chunks of garbage facility entities and accumulates per-facility stats into the provided m_Results NativeArray. It reads PrefabRef, efficiencies, installed upgrades, storage and geometry components, resources and subareas to compute processing speed, long-term capacity and stored garbage totals.

  • private struct TypeHandle (nested)
    Holds strongly-typed handles (EntityTypeHandle, BufferTypeHandle, ComponentTypeHandle, ComponentLookup, BufferLookup) used by UpdateGarbageJob and assigned from SystemState.

Properties

  • protected override bool Active { get; }
    Determines whether the system should be active. Returns true when base.Active is true or any of the UI bindings (capacity, stored garbage, processing rate, garbage rate, processing availability, landfill availability) are active. This prevents work when no UI consumers are present.

  • protected override bool Modified { get; }
    Returns true if m_GarbageFacilityModifiedQuery reports modifications (Created/Updated/Deleted) among matching garbage facility entities. Used by the infoview system to know when values changed.

Constructors

  • public GarbageInfoviewUISystem()
    Default parameterless constructor. The system logic primarily initializes in OnCreate.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system:
  • Obtains the GarbageAccumulationSystem instance from the world.
  • Builds the EntityQuery for garbage facilities and a modified-query that looks for Created/Updated/Deleted flags.
  • Registers GetterValueBinding instances for "garbageInfo" keys: capacity, storedGarbage, processingRate, productionRate (from GarbageAccumulationSystem), processingAvailability, landfillAvailability.
  • Allocates m_Results = new NativeArray(3, Allocator.Persistent). These bindings are what the UI reads to populate the infoview.

  • [Preserve] protected override void OnDestroy()
    Cleans up the system by disposing the m_Results NativeArray and calling base.OnDestroy().

  • protected override void PerformUpdate()
    Performs the aggregation update each frame (when Active). Steps:

  • ResetResults() zeroes m_Results.
  • Constructs and schedules the UpdateGarbageJob with the appropriate type/component handles (using InternalCompilerInterface.Get*Handle to obtain handles based on __TypeHandle and the system state).
  • Schedules the job over m_GarbageFacilityQuery and immediately completes it (job.Complete()) so results are available synchronously for the UI update cycle.
  • Calls Update() on each GetterValueBinding to push the fresh values to the UI.

  • private void ResetResults()
    Zeros all entries in m_Results (the loop sets each element to 0f). Called before scheduling the job.

  • private int GetGarbageCapacity()
    Reader bound to m_Capacity. Returns (int)m_Results[1] (index 1 is garbage/landfill capacity).

  • private int GetStoredGarbage()
    Reader bound to m_StoredGarbage. Returns (int)m_Results[2] (index 2 is stored garbage).

  • private float GetProcessingRate()
    Reader bound to m_ProcessingRate. Returns m_Results[0] (index 0 is processing rate).

  • private IndicatorValue GetLandfillAvailability()
    Reader bound to m_LandfillAvailability. Uses IndicatorValue.Calculate(totalCapacity, stored, 0f) to compute an availability indicator for long-term storage.

  • private IndicatorValue GetProcessingAvailability()
    Reader bound to m_ProcessingAvailability. Compares processing capacity (m_Results[0]) against the current garbage accumulation rate (m_GarbageAccumulationSystem.garbageAccumulation, clamped to >= 0) to return an IndicatorValue.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler-generated helper; here it constructs/disposes a temporary EntityQueryBuilder. Present for compiler/IL weaving compatibility.

  • protected override void OnCreateForCompiler()
    Compiler-time helper that calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to ensure handles are assigned for the Burst job when compiled.

  • void IJobChunk.Execute(...) (UpdateGarbageJob explicit interface implementation)
    For compatibility with the IJobChunk interface; calls the job's Execute method.

Notes about UpdateGarbageJob behavior: - For each matching chunk/entity, it: - Reads PrefabRef and building efficiency (via buffer accessor BuildingUtils.GetEfficiency). - Skips entities with 0 efficiency. - Looks up GarbageFacilityData from prefab component; applies installed upgrades via UpgradeUtils.CombineStats if present. - Sums resources buffer entries for Resource.Garbage to accumulate stored garbage. - Iterates SubArea buffers to include storage area capacities: reads Storage component on area entities and StorageAreaData from area prefab to compute area storage capacity via AreaUtils.CalculateStorageCapacity(geometry, storageAreaData) and adds current Storage.m_Amount to stored totals. - Accumulates efficiency * processingSpeed into processing rate total; adds long-term capacity and stored amounts only for facilities marked as long-term storage. - The job is Burst-compiled and uses ComponentLookup/BufferLookup to access cross-entity data efficiently.

Usage Example

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

    // Typical initialization performed by this system:
    m_GarbageAccumulationSystem = World.GetOrCreateSystemManaged<GarbageAccumulationSystem>();
    m_GarbageFacilityQuery = GetEntityQuery(
        ComponentType.ReadOnly<Game.Buildings.GarbageFacility>(),
        ComponentType.ReadOnly<Building>(),
        ComponentType.ReadOnly<ServiceDispatch>(),
        ComponentType.ReadOnly<PrefabRef>(),
        ComponentType.Exclude<Temp>(),
        ComponentType.Exclude<Deleted>()
    );

    AddBinding(m_Capacity = new GetterValueBinding<int>("garbageInfo", "capacity", GetGarbageCapacity));
    AddBinding(m_StoredGarbage = new GetterValueBinding<int>("garbageInfo", "storedGarbage", GetStoredGarbage));
    AddBinding(m_ProcessingRate = new GetterValueBinding<float>("garbageInfo", "processingRate", GetProcessingRate));
    // ...
    m_Results = new NativeArray<float>(3, Allocator.Persistent);
}

Additional notes: - m_Results uses a fixed mapping given by the internal Result enum: index 0 = processing rate, 1 = capacity, 2 = stored garbage — this mapping is relied upon across the system. - The UpdateGarbageJob completes synchronously (Complete()) so UI bindings can be updated in the same frame; this simplifies access at the cost of blocking until the job finishes. - The system relies on various other utilities and component types (BuildingUtils, UpgradeUtils, AreaUtils, EconomyUtils, Prefab/GarbageFacilityData, Storage, Geometry, Resources, SubArea) that are part of the game's ECS domain model. When extending or reusing this system, ensure matching component types and lookups are available.