Game.Debug.AvailabilityDebugSystem
Assembly: Game (inferred from file path)
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: AvailabilityDebugSystem is a debug visualization system that draws gizmos showing resource availability along network edges. It queries entities that have EdgeGeometry and a ResourceAvailability buffer and, for each enabled AvailableResource option, schedules a job (AvailabilityGizmoJob) to sample the availability buffer and draw colored vertical lines and connecting segments along the edge geometry to indicate availability from red (low) to green (high). The system is disabled by default and exposes per-resource options in the debug UI to toggle visualizations.
Fields
-
private EntityQuery m_AvailabilityGroup
This query selects entities that contain a ResourceAvailability buffer and EdgeGeometry component and excludes Deleted and Temp entities. The system requires this query for update. -
private GizmosSystem m_GizmosSystem
Reference to the GizmosSystem used to obtain a GizmosBatcher for drawing debug lines from jobs. -
private Dictionary<AvailableResource, Option> m_AvailabilityOptions
Holds toggle options for each AvailableResource enum value (except the Count sentinel). These options are used to enable/disable the visualization of each resource type. -
private TypeHandle __TypeHandle
Container for component and buffer type handles (EdgeGeometry and ResourceAvailability). Used to cache and assign handles for safe access in the scheduled job. -
private struct AvailabilityGizmoJob
(nested) A Burst-compiled IJobChunk which iterates chunks selected by m_AvailabilityGroup, reads EdgeGeometry and ResourceAvailability buffer data, and issues draw calls to a GizmoBatcher to visualize availability along edges. -
private struct TypeHandle
(nested) Holds read-only ComponentTypeHandleand BufferTypeHandle and provides an inline __AssignHandles method to initialize those handles from a SystemState.
Properties
- This class exposes no public properties. {{ The system uses internal TypeHandle fields and local job fields rather than public properties. The gizmo toggles are stored in m_AvailabilityOptions and exposed via the debug UI Option objects. }}
Constructors
public AvailabilityDebugSystem()
Default constructor annotated with [Preserve].
{{ The constructor is empty; initialization is performed in the overridden OnCreate method. The Preserve attribute prevents the method from being stripped by the engine's managed code stripping. }}
Methods
-
protected override void OnCreate()
Initializes the system: acquires the GizmosSystem, sets up the EntityQuery (m_AvailabilityGroup), builds m_AvailabilityOptions by enumerating the AvailableResource enum (skipping AvailableResource.Count), registers each option via AddOption, calls RequireForUpdate for the group and sets base.Enabled = false so the system is disabled by default.
{{ OnCreate wires up the debug options (one per AvailableResource) so the user can toggle visualizations for each resource in the debug UI. }} -
protected override JobHandle OnUpdate(JobHandle inputDeps)
Schedules AvailabilityGizmoJob instances (one per enabled resource option). For each enabled resource, it: - Obtains component/buffer type handles via InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle using the cached __TypeHandle fields and the system's CheckedStateRef.
- Obtains a GizmosBatcher from m_GizmosSystem (returns an out dependency).
- Schedules the AvailabilityGizmoJob in parallel across m_AvailabilityGroup with combined dependencies.
-
Registers the JobHandle with the GizmosSystem via AddGizmosBatcherWriter and combines job dependencies into the returned JobHandle.
Returns a JobHandle representing all scheduled jobs combined with inputDeps.
{{ The job is Burst compiled and intended to run on worker threads; drawing is performed via a GizmosBatcher obtained for the job. The system only schedules jobs for options that are enabled in m_AvailabilityOptions. }} -
protected override void OnCreateForCompiler()
Called by generated/compiled code paths. It calls base.OnCreateForCompiler(), assigns queries via __AssignQueries (no-op builder here) and assigns the cached type handles via __TypeHandle.__AssignHandles(ref base.CheckedStateRef).
{{ This method ensures the type handles and any generated query initialization are set up when compiler-generated code requires them. }} -
private void __AssignQueries(ref SystemState state)
A small method that currently creates and disposes a temporary EntityQueryBuilder (no persistent query assignments). It exists to centralize query assignment steps required by code generation.
{{ Kept for compatibility with ECS codegen patterns; real query construction happens in OnCreate. }} -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Assigns read-only component/buffer type handles from the provided SystemState: - __Game_Net_EdgeGeometry_RO_ComponentTypeHandle = state.GetComponentTypeHandle
(isReadOnly: true) -
__Game_Net_ResourceAvailability_RO_BufferTypeHandle = state.GetBufferTypeHandle
(isReadOnly: true)
{{ This method is called from OnCreateForCompiler to initialize handles used later when scheduling jobs. }} -
AvailabilityGizmoJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Core job logic: - Reads EdgeGeometry array and ResourceAvailability buffer accessor for the current chunk.
- Iterates over each entity in the chunk, skipping those where the ResourceAvailability buffer is empty.
- For each entity: samples the ResourceAvailability for the selected AvailableResource index (m_Resource), computes two colors interpolated from red to green based on availability components, computes sampling points along the start and end side of the edge geometry, and draws vertical lines (scaled by availability * 10) and connecting lines between successive points to form a "profile" of availability along the edge using m_GizmoBatcher.DrawLine.
The job also implements the IJobChunk explicit interface method to forward to the strongly typed Execute method.
{{ The job is Burst compiled and uses math and Colossal types (Line3, MathUtils) to compute positions. The color interpolation uses Color.Lerp# Game.Debug.AvailabilityDebugSystem
Assembly: Game (inferred from file path)
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: AvailabilityDebugSystem is a debug visualization system that draws gizmos showing resource availability along network edges. It queries entities that have EdgeGeometry and a ResourceAvailability buffer and, for each enabled AvailableResource option, schedules a Burst-compiled job (AvailabilityGizmoJob) to sample the availability buffer and draw colored vertical lines and connectors along the edge geometry. The visualization interpolates between red (low availability) and green (high availability). The system registers one toggle Option per AvailableResource enum value (except the Count sentinel) so the user can enable/disable visualizations for each resource type via the debug UI. The system is disabled by default.
Fields
-
private EntityQuery m_AvailabilityGroup
Query selecting entities with ResourceAvailability (buffer) and EdgeGeometry components, excluding Deleted and Temp. Required for update. -
private GizmosSystem m_GizmosSystem
Reference to the GizmosSystem used to obtain a GizmosBatcher for issuing draw calls from jobs. -
private Dictionary<AvailableResource, Option> m_AvailabilityOptions
Maps each AvailableResource to an Option (toggle) created via AddOption; used to determine which resources should be visualized this frame. -
private TypeHandle __TypeHandle
Caches component and buffer type handles (EdgeGeometry read-only, ResourceAvailability read-only buffer) used when scheduling jobs. -
private struct AvailabilityGizmoJob
(nested)
Burst-compiled IJobChunk that reads EdgeGeometry and ResourceAvailability data from chunks and draws gizmos using a provided GizmoBatcher. -
private struct TypeHandle
(nested)
Container for ComponentTypeHandleand BufferTypeHandle plus an inline __AssignHandles method.
Properties
- This class exposes no public properties.
{{ The system stores its runtime toggles in m_AvailabilityOptions (Option objects) rather than exposing typed public properties. }}
Constructors
public AvailabilityDebugSystem()
{{ Default parameterless constructor; annotated with [Preserve] to avoid being stripped. Initialization is performed in OnCreate. }}
Methods
protected override void OnCreate()
Initializes the system:- Gets or creates the GizmosSystem instance.
- Constructs m_AvailabilityGroup to select entities with ResourceAvailability buffer and EdgeGeometry, excluding Deleted and Temp.
- Builds m_AvailabilityOptions by enumerating the AvailableResource enum and creating an Option for each value except AvailableResource.Count (first option enabled by default).
-
Calls RequireForUpdate(m_AvailabilityGroup) and sets base.Enabled = false.
{{ OnCreate wires up debug UI toggles and ensures the system only runs when there are matching entities. }} -
protected override JobHandle OnUpdate(JobHandle inputDeps)
For each enabled AvailableResource option in m_AvailabilityOptions: - Prepares an AvailabilityGizmoJob struct with:
- m_Resource set to the resource to visualize.
- Component/buffer type handles obtained through InternalCompilerInterface.GetComponentTypeHandle and GetBufferTypeHandle using the cached __TypeHandle fields and the system's CheckedStateRef.
- A GizmosBatcher instance from m_GizmosSystem.GetGizmosBatcher(out dependencies).
- Schedules the job in parallel across m_AvailabilityGroup, combining inputDeps and the gizmo batcher dependency.
-
Registers the job with the GizmosSystem via AddGizmosBatcherWriter and combines its JobHandle into the returned dependency.
Returns a combined JobHandle representing all scheduled visualization jobs.
{{ The job draws from worker threads via the GizmosBatcher; only enabled resource options result in scheduled jobs. }} -
protected override void OnCreateForCompiler()
Called by generated code paths. Calls base.OnCreateForCompiler(), invokes __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to ensure type handles are assigned for scheduling. -
private void __AssignQueries(ref SystemState state)
Present to match ECS codegen patterns; currently constructs and disposes a temporary EntityQueryBuilder.
{{ Query setup primarily occurs in OnCreate; this method exists for compatibility with compiled/system-generated code. }} -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Assigns read-only type handles: - __Game_Net_EdgeGeometry_RO_ComponentTypeHandle = state.GetComponentTypeHandle
(isReadOnly: true) -
__Game_Net_ResourceAvailability_RO_BufferTypeHandle = state.GetBufferTypeHandle
(isReadOnly: true)
{{ Called from OnCreateForCompiler to initialize handles used when scheduling the job. }} -
AvailabilityGizmoJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Job logic summary: - Obtains a NativeArray
for the chunk and a BufferAccessor . - Iterates entities in the chunk; for each entity with a non-empty ResourceAvailability buffer:
- Reads the EdgeGeometry and the ResourceAvailability entry for the job's m_Resource.
- Computes two colors (start/end) by lerping between Color.red and Color.green based on availability components.
- Samples positions across the start and end sides of the edge geometry (using middle lengths, MathUtils.Position and linear interpolation).
- Draws vertical line segments whose height is availability * 10 and connects successive segments to form a continuous profile, issuing draw calls via m_GizmoBatcher.DrawLine.
The job implements IJobChunk explicitly to forward calls to the typed Execute method.
{{ The visualization uses floating-point interpolation to blend availability values and colors along the edge; the job is Burst-compiled for performance. }}
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// typical initialization performed by the system itself:
// - it registers per-AvailableResource options to toggle visualization,
// - sets up the EntityQuery for EdgeGeometry+ResourceAvailability,
// - retrieves the GizmosSystem for drawing.
// The system is disabled by default; enable it via:
// World.GetOrCreateSystemManaged<AvailabilityDebugSystem>().Enabled = true;
}
{{ NOTES: - This system is intended for debug builds and editor-side visualization of resource availability along network edges. - The AvailabilityGizmoJob uses a GizmosBatcher obtained from GizmosSystem so that draw calls are recorded from a job and later consumed/rendered by the GizmosSystem on the main thread. - The job reads EdgeGeometry and ResourceAvailability as read-only; any modifications to the data should not be attempted from this job. - The coloring and vertical scaling factor (availability * 10) are implementation details visible in the job; adjust if you copy/paste this logic into other debug systems. }}