Game.Rendering.EffectRangeRenderSystem
Assembly:
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
EffectRangeRenderSystem is an ECS system that draws visual overlays (range circles) for local effects provided by building prefabs and their installed upgrades when the corresponding infomode is active. It gathers all active infoview local-effect descriptors, builds a bitmask of the modifier types to render, and schedules a Burst-compiled IJobChunk (EffectRangeRenderJob) that iterates provider chunks (entities with LocalEffectProvider) to collect LocalModifierData from prefabs and upgrades. For each modifier it calculates a radius (optionally scaled by building efficiency) and issues draw commands to an OverlayRenderSystem.Buffer to render projected circle overlays. The system uses EntityQuery filters to require presence of LocalEffectProvider and infomode data and integrates with Unity Jobs/Collections/Burst for parallel, high-performance rendering of many providers.
Fields
-
private EntityQuery m_ProviderQuery
Used to select entities that provide local effects (ComponentType.ReadOnly) and exclude hidden/deleted/destroyed entities. This query drives which provider archetype chunks are traversed by the scheduled job. -
private EntityQuery m_InfomodeQuery
Query selecting infomode entries (ComponentType.ReadOnly(), ComponentType.ReadOnly ()). The system reads these chunks to determine which local-effect types are currently requested for rendering. -
private OverlayRenderSystem m_OverlayRenderSystem
Reference to the OverlayRenderSystem managed system. The system obtains a drawing buffer from this overlay system and registers itself as a writer so the overlay rendering pipeline can consume the circle draw calls issued by the job. -
private TypeHandle __TypeHandle
Holds ComponentTypeHandle / BufferTypeHandle / ComponentLookup / BufferLookup instances used by the Burst job. These handles are assigned during OnCreateForCompiler / __AssignHandles and then converted to actual handles via InternalCompilerInterface when scheduling the job.
Properties
- (none public)
This system exposes no public properties. All state is internal/private and used to configure and schedule the internal job.
Constructors
public EffectRangeRenderSystem()
Default constructor (marked with [Preserve] in the original code). No custom construction logic beyond the base constructor.
Methods
-
protected override void OnCreate()
Initializes the system: obtains the OverlayRenderSystem, constructs the provider and infomode EntityQueries, and calls RequireForUpdate on both queries so the system only runs when there are providers and the relevant infomode is active. This sets up the conditions for the system to run and acquire the overlay buffer. -
protected override void OnUpdate()
Main update: asynchronously collects archetype chunks matching the infomode query (ToArchetypeChunkListAsync) and obtains an OverlayRenderSystem.Buffer (with a JobHandle dependency). It then constructs and schedules the Burst-compiled EffectRangeRenderJob, handing it: - the list of infomode chunks,
- the overlay buffer to write draw calls to,
-
component / buffer handles and lookups converted via InternalCompilerInterface from the cached TypeHandle. The method disposes the infomode chunk list once the job completes, registers the overlay buffer writer for synchronization, and stores the returned job handle in base.Dependency.
-
protected override void OnCreateForCompiler()
Internal setup used by generated/compiled systems: calls __AssignQueries and assigns component/buffer handles by invoking __TypeHandle.__AssignHandles(ref base.CheckedStateRef). This prepares the TypeHandle for later conversion to runtime handles when scheduling jobs. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
A generated helper used for query assignment during compilation/setup. In this implementation it creates and disposes an EntityQueryBuilder (used by compiler-generated code patterns). -
(Nested) private struct EffectRangeRenderJob : IJobChunk (BurstCompile)
Summary of the job behavior: - Input: NativeList
m_InfomodeChunks (read-only) representing all infoview local-effect chunks currently active. - Writes draw calls to OverlayRenderSystem.Buffer m_OverlayBuffer.
- Uses various ComponentTypeHandle, BufferTypeHandle, ComponentLookup, BufferLookup for:
- Transform, FirewatchTower, PrefabRef, Temp components
- InstalledUpgrade and Efficiency buffers
- LocalModifierData buffer lookup for prefab-local modifiers
- For each provider entity in the chunk:
- Builds a temporary NativeList
of modifiers coming from the prefab and from installed upgrades (using InitializeTempList and AddToTempList). - Computes a bitmask of modifier types present in active infomode chunks (GetModifierTypes) to quickly skip irrelevant modifiers.
- For each relevant LocalModifierData:
- Attempts to resolve a current efficiency value — either from a Temp component referencing an original building or directly from an Efficiency buffer on the provider. Special handling for FirewatchTower flags (coverage) is present.
- Calls CheckModifier(...) which:
- Finds matching InfoviewLocalEffectData entries whose type equals the modifier type.
- Computes orientation (math.forward(transform.m_Rotation)), radius (lerp between min/max scaled by sqrt(efficiency) when efficiency is provided), and color.
- Issues m_OverlayBuffer.DrawCircle with stroke width scaled by radius0.02f, projected style flag, center at transform.m_Position, and total diameter radius2f. The fill color's alpha is set to 0 to draw only the outline (derived from infoview color).
- Builds a temporary NativeList
- The job disposes the temp NativeList and is Burst-compiled for performance.
Important job helper methods:
- InitializeTempList(NativeList
Notes on threading and memory: - The job uses Allocator.Temp for NativeList tempModifierList per Execute invocation and disposes it before returning. - infomodeChunks is produced with ToArchetypeChunkListAsync(Allocator.TempJob) and disposed on the main thread after job scheduling (Dispose(jobHandle)). - The overlay buffer is obtained with m_OverlayRenderSystem.GetBuffer(out dependencies) and the overlay system is notified with AddBufferWriter(jobHandle) to synchronize access.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// EffectRangeRenderSystem's OnCreate already acquires the overlay system and sets up queries.
// If you need to interact with this system from another system, get it from World:
// var effectRangeSystem = World.GetOrCreateSystemManaged<Game.Rendering.EffectRangeRenderSystem>();
}
Additional notes: - The system is designed to run only when there are both LocalEffectProvider entities and at least one active InfomodeLocalEffect entry (RequireForUpdate was set for both queries). - Rendering parameters (stroke scale, diameter multiplier) are hard-coded in the job (0.02f and 2f respectively) — modders can copy and adapt this logic if custom visualization is required. - The job is decorated with [BurstCompile]; any change to job code should respect Burst-compatible types and API usage.