Game.Tools.ToolFeedbackSystem
Assembly: Assembly-CSharp (game runtime assembly)
Namespace: Game.Tools
Type: class
Base: GameSystemBase, IPostDeserialize
Summary:
ToolFeedbackSystem collects and processes feedback information for buildings and service-related objects in the game. It computes local and city-wide feedback contributions (coverage, capacity, pollution, transport, utilities, attractiveness, modifiers, etc.), enqueues pathfind/coverage searches, runs multiple Burst jobs (parallelized) to evaluate targets, and issues icon commands (happy/sad/info icons) and recent-feedback updates. The system maintains pools of temporary "feedback container" entities, a RecentMap to smooth/decay feedback deltas over time, and integrates with pathfinding, telecom coverage and icon command systems. Intended for modders: this is the core system that turns building/service stats into player-facing feedback icons and recent changes.
Fields
-
private const float INFINITE_RANGE = 25000f
Used as a fallback range when a prefab has no CoverageData; represents effectively unlimited coverage radius for the coverage search logic. -
private IconCommandSystem m_IconCommandSystem
Reference to IconCommandSystem used to create command buffers for spawning feedback icons (happy/sad/info). -
private PathfindQueueSystem m_PathfindQueueSystem
Reference to PathfindQueueSystem used to enqueue coverage/pathfinding searches for feedback sources. -
private AirwaySystem m_AirwaySystem
Reference to AirwaySystem used to provide airway data when preparing target seekers. -
private SimulationSystem m_SimulationSystem
Reference to SimulationSystem used to read the current simulation frame (for RecentMap updates and timing). -
private TelecomCoverageSystem m_TelecomCoverageSystem
Reference to TelecomCoverageSystem used to sample network quality for telecom feedback. -
private List<Entity> m_FeedbackContainers
Pool of reusable feedback container entities that hold Feedback, ExtraFeedback and CoverageElement buffers while a coverage search is pending or being processed. -
private List<Entity> m_PendingContainers
List of feedback container entities currently pending completion of their coverage search results. -
private NativeParallelHashMap<RecentKey, RecentValue> m_RecentMap
Native hash map storing recent feedback per (entity + metric) key. Used to smooth and clamp feedback deltas so icons/updates are not spammed. Persistent allocator; must be disposed on system destroy. -
private PathfindTargetSeekerData m_TargetSeekerData
Pathfind target seeker configuration/state used for creating PathfindTargetSeeker instances when setting up coverage searches. -
private EntityQuery m_ConfigurationQuery
Query to find FeedbackConfigurationData singleton and related configuration buffers. -
private EntityQuery m_AppliedQuery
Query to detect newly applied/created objects (buildings/upgrades/stops) that require feedback evaluation or removal. -
private EntityQuery m_TargetQuery
Query for all buildings (targets) to evaluate when processing a feedback container; excludes upgrades and invalid states (abandoned/condemned/destroyed/deleted/updated/temp). -
private EntityQuery m_EventQuery
Query to check for CoverageUpdated events (used to move containers from pending to processed). -
private JobHandle m_RecentDeps
JobHandle tracking UpdateRecentMapJob dependency when scheduled; used to correctly sequence Native collections disposal and further jobs. -
private TypeHandle __TypeHandle
Generated struct that holds ComponentLookup/ComponentType handles used by the Burst jobs and JobChunk scheduling. Assigned during OnCreateForCompiler.
Properties
- None exposed (no public C# properties on this class). The system relies on fields and component queries.
Constructors
public ToolFeedbackSystem()
Parameterless constructor (marked with [Preserve] in source). Initializes the system instance; main initialization logic happens in OnCreate.
Methods
[Preserve] protected override void OnCreate()
Initializes system references and data structures:- Gets references to IconCommandSystem, PathfindQueueSystem, AirwaySystem, SimulationSystem and TelecomCoverageSystem.
- Creates pools/lists for feedback containers and pending containers.
- Allocates m_RecentMap (NativeParallelHashMap) with a Persistent allocator.
- Initializes PathfindTargetSeekerData and entity queries (configuration, applied, target, event).
-
Called by the ECS framework when the system is created.
-
[Preserve] protected override void OnDestroy()
Cleans up system resources: - Completes any outstanding m_RecentDeps job.
- Disposes m_RecentMap.
-
Calls base.OnDestroy().
-
public void PostDeserialize(Context context)
IPostDeserialize implementation called after world serialization/deserialization: - Completes pending recent jobs and clears/reconciles m_RecentMap.
-
Moves any pending containers into the active feedback container list so they resume processing after load.
-
protected override void OnGamePreload(Purpose purpose, GameMode mode)
Enables or disables the system depending on the current GameMode (only enabled for actual game mode). Called during game preload. -
[Preserve] protected override void OnUpdate()
Main update tick: - If there are new applied entities and configuration exists, calls ProcessModifications to start new coverage searches.
- If there are pending containers and CoverageUpdated events exist, calls UpdatePending to process finished searches.
-
Schedules and chains jobs; updates base.Dependency appropriately.
-
private void ProcessModifications()
Handles newly applied objects (buildings/objects/upgrades/stops): - Gathers applied entities and creates/allocates feedback container entities from the pool.
- Prepares PathfindTargetSeeker and CoverageAction for each source object, schedules a SetupCoverageSearchJob (IJob) to fill coverage parameters and drive the pathfind seeker.
- Enqueues coverage/pathfind actions to PathfindQueueSystem, marking containers as pending until results arrive.
-
Uses m_TargetSeekerData and feedback configuration to prepare pathfind parameters.
-
private void UpdatePending()
Processes pending feedback containers when their coverage searches are ready: - For each pending container with CoverageElement buffer, builds a temporary NativeParallelHashMap of coverage values and runs FillCoverageMapJob (IJobParallelFor) to populate it.
- Schedules a TargetCheckJob (IJobChunk) to evaluate all targets/buildings against the coverage map and the feedback container. The job:
- Reads many prefab/component lookups to compute per-target deltas for many feedback types (garbage, hospital, electricity, water, sewage, transport, pollution, attractiveness, local/city modifiers, etc.)
- Aggregates per-target totals and enqueues icon commands (happy/sad icons) using an IconCommandBuffer.
- Builds recent updates (RecentUpdate) into a NativeQueue used to update m_RecentMap.
-
After scheduling TargetCheckJob, schedules UpdateRecentMapJob (IJob) to apply, decay, and merge recent feedback deltas into m_RecentMap.
-
private void __AssignQueries(ref SystemState state)
Generated helper (called in OnCreateForCompiler) to initialize entity query builders/assignments required by the compiled job code. Typically empty stub in decompiled form but required by compiled pipeline. -
protected override void OnCreateForCompiler()
Compiler-generated method used by the generated code to assign queries and component handles; it calls __AssignQueries and assigns handles inside __TypeHandle. -
Inner job structs and helper methods (documented briefly):
- SetupCoverageSearchJob : IJob (BurstCompile)
- Prepares CoverageAction parameters and sets up PathfindTargetSeeker targets for a given feedback source/prefab/backside.
- FillCoverageMapJob : IJobParallelFor (BurstCompile)
- Writes CoverageElement entries into a NativeParallelHashMap
for fast lookup by TargetCheckJob.
- Writes CoverageElement entries into a NativeParallelHashMap
- TargetCheckJob : IJobChunk (BurstCompile)
- Core parallel evaluation: computes feedback contributions for each building/target, applies recent-map clamping logic, enqueues icon commands and collects RecentUpdate entries for later merging.
- Contains helper methods AddToTempListForUpgrade(...) and AddEffect(...) used to handle upgrade stacking and delta filtering/clamping against m_RecentMap.
- UpdateRecentMapJob : IJob (BurstCompile)
- Applies time-based decay to existing entries in m_RecentMap and applies new RecentUpdate values from the NativeQueue, adding/removing entries as needed.
- TypeHandle struct
- Holds component lookup/type handles (ComponentLookup, ComponentTypeHandle, BufferLookup) used by the Burst jobs; __AssignHandles populates these from SystemState.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization logic from the system:
m_IconCommandSystem = World.GetOrCreateSystemManaged<IconCommandSystem>();
m_PathfindQueueSystem = World.GetOrCreateSystemManaged<PathfindQueueSystem>();
m_AirwaySystem = World.GetOrCreateSystemManaged<AirwaySystem>();
m_SimulationSystem = World.GetOrCreateSystemManaged<SimulationSystem>();
m_TelecomCoverageSystem = World.GetOrCreateSystemManaged<TelecomCoverageSystem>();
m_FeedbackContainers = new List<Entity>();
m_PendingContainers = new List<Entity>();
// Reserve recent feedback map (persistent; must be disposed in OnDestroy)
m_RecentMap = new NativeParallelHashMap<RecentKey, RecentValue>(1000, Allocator.Persistent);
// Prepare target seeker data and entity queries
m_TargetSeekerData = new PathfindTargetSeekerData(this);
m_ConfigurationQuery = GetEntityQuery(ComponentType.ReadOnly<FeedbackConfigurationData>());
// ...setup other queries similarly...
}
Notes for modders: - ToolFeedbackSystem is tightly coupled to the game's component types (CoverageData, various Prefab data types, building component types, and FeedbackConfigurationData). If you add new feedback metrics or change prefab component shapes, adjust TargetCheckJob calculations and RecentKey construction accordingly. - m_RecentMap uses a custom RecentKey (entity + typed discriminator) and RecentValue (frame + delta); UpdateRecentMapJob decays values each update and merges new RecentUpdate entries. To influence icon spam/clamping, tune FeedbackConfigurationData or the recent logic. - The system heavily uses Unity Jobs/Burst and Native collections; be careful when reading/writing related Native collections or scheduling jobs that depend on these (respect dependencies / complete JobHandles when accessing NativeParallelHashMap on the main thread).