Game.Simulation.CityDangerLevelSystem
Assembly:
Assembly-CSharp
Namespace:
Game.Simulation
Type:
class
Base:
GameSystemBase
Summary:
Aggregates danger-level information reported by event entities and writes the maximum danger level into the single City DangerLevel component. The system collects Game.Events.DangerLevel components across entities (in parallel, using a Burst-compiled IJobChunk), reduces them with a NativeAccumulator
Fields
-
private CitySystem m_CitySystem
Reference to the CitySystem used to obtain the city entity (m_CitySystem.City) where the aggregated danger value is written. -
private EntityQuery m_DangerLevelQuery
EntityQuery used to find entities that have Game.Events.DangerLevel components (and are not Deleted). If the query is empty the chunk job is skipped. -
private TypeHandle __TypeHandle
Internal struct that holds component type handles and component lookups used by the jobs. It contains: - a read-only ComponentTypeHandle
and -
a ComponentLookup
for writing. -
(nested)
private struct DangerLevelJob : IJobChunk
Burst-compiled job that iterates over chunks of Game.Events.DangerLevel and accumulates the maximum danger value into a NativeAccumulator. Uses ComponentTypeHandle and a ParallelWriter to the accumulator. -
(nested)
private struct UpdateCityJob : IJob
Job that reads the accumulated MaxFloat result and writes the final float into the Game.City.DangerLevel component on the city entity. Uses ComponentLookupand an Entity for the target city. -
(nested)
private struct TypeHandle
Holds component handles/lookups and provides an __AssignHandles method that binds them from a SystemState.
Properties
- None (no public properties exposed by this system)
Constructors
public CityDangerLevelSystem()
Default parameterless constructor. The system further initializes references in OnCreate/OnCreateForCompiler.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
: System.Int32
Returns 128. The system is intended to run every 128 frames (or ticks) for the given update phase. -
[Preserve] protected override void OnCreate()
: System.Void
Creates/gets the CitySystem, sets up the m_DangerLevelQuery to read Game.Events.DangerLevel and exclude Deleted entities, and calls RequireForUpdate() to ensure the CityDangerLevel component exists and the system will be scheduled only when relevant. -
[Preserve] protected override void OnUpdate()
: System.Void
Main update logic: - Allocates a NativeAccumulator
(Allocator.TempJob). - If m_DangerLevelQuery is not empty, schedules a Burst-compiled DangerLevelJob (IJobChunk) in parallel to read Game.Events.DangerLevel components and accumulate the maximum danger value.
- Schedules an UpdateCityJob (IJob) that writes the accumulator's result into the city's Game.City.DangerLevel component.
-
Disposes the NativeAccumulator with the combined job dependency to ensure safe deallocation after jobs complete.
-
private void __AssignQueries(ref SystemState state)
: System.Void
Compiler-generated helper that (here) creates and disposes an EntityQueryBuilder (used by the generated code path). Present to satisfy compiler/IL post-processing. -
protected override void OnCreateForCompiler()
: System.Void
Compiler-time initialization invoked by generated code. Calls __AssignQueries and __TypeHandle.__AssignHandles to bind component handles/lookups. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
: System.Void
Assigns the ComponentTypeHandle(read-only) and ComponentLookup (read/write) from the provided SystemState. -
Nested job method details:
DangerLevelJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Iterates the chunk's Game.Events.DangerLevel components and calls m_Result.Accumulate(new MaxFloat(value)) for each entry.UpdateCityJob.Execute()
Reads m_Result.GetResult().m_Value and writes it to m_DangerLevel[m_City] (Game.City.DangerLevel.m_DangerLevel).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Initialize references and queries similar to the system's implementation:
m_CitySystem = World.GetOrCreateSystemManaged<CitySystem>();
m_DangerLevelQuery = GetEntityQuery(
ComponentType.ReadOnly<Game.Events.DangerLevel>(),
ComponentType.Exclude<Deleted>());
// Ensure the city's DangerLevel component exists and this system runs only when relevant.
RequireForUpdate<Game.City.DangerLevel>();
}
Notes and implementation tips:
- The system uses Burst-compiled jobs and a NativeAccumulator