Skip to content

Game.Rendering.BatchInstanceSystem

Assembly: Assembly-CSharp
Namespace: Game.Rendering

Type: class

Base: GameSystemBase

Summary:
BatchInstanceSystem is a high-level ECS system responsible for translating pre-culling updates into rendering batch instance changes. It iterates updated pre-culling entries and determines which mesh instances to add, update, fade or remove from BatchManager's native batch instance storage. The system schedules burst-parallel jobs (BatchInstanceJob, GroupActionJob, DequeueFadesJob) to perform instance creation/removal and to enqueue actions processed by the BatchManager. It cooperates with PreCullingSystem, BatchManagerSystem and RenderingSystem and uses multiple native queues to batch group actions, fade operations and velocity sampling for smooth LOD cross-fading.


Fields

  • private RenderingSystem m_RenderingSystem
    This is a reference to the global RenderingSystem (retrieved in OnCreate). Used to read rendering-related state such as frame index, frame time, marker/unspawned visibility and LOD fade flags.

  • private BatchManagerSystem m_BatchManagerSystem
    Reference to the BatchManagerSystem which owns native batch instances and sub-batches. The system requests read/write access and registers readers/writers around scheduled jobs.

  • private PreCullingSystem m_PreCullingSystem
    Reference to the PreCullingSystem used to obtain updated culling data (which entries changed visibility or content) and fade container/visibility masks.

  • private UndergroundViewSystem m_UndergroundViewSystem
    Used to get underground utility type dilation (utilities visible in underground view), so lane/pipeline meshes determine LOD limits correctly.

  • private CityConfigurationSystem m_CityConfigurationSystem
    Used to read city-wide configuration such as left-hand traffic flag.

  • private ToolSystem m_ToolSystem
    Used to detect editor mode (tool state) to decide whether to include editor-only meshes.

  • private Groups m_Groups
    An instance of the nested Groups class (a sub-system) that handles dispatching GroupAction/ Fade/Velocity queues and finalizing group updates. This Groups instance creates the per-update Native queues and parallel queue and consumes results from the BatchInstanceJob.

  • private TypeHandle __TypeHandle
    Compiler-generated struct containing ComponentLookup/BufferLookup handles used when scheduling jobs. Assigned during OnCreateForCompiler.

Properties

  • (none public)
    All important data is exposed via fields (internal references) or passed into jobs through job structs. No public properties are defined on the top-level system.

Constructors

  • public BatchInstanceSystem()
    Default constructor. Marked with [Preserve] by the compiler in generated code. OnCreate is used to initialize subsystem references.

Methods

  • protected override void OnCreate()
    Initializes references to required systems (RenderingSystem, BatchManagerSystem, PreCullingSystem, UndergroundViewSystem, CityConfigurationSystem, ToolSystem) and creates/gets the nested Groups system. This prepares the system for OnUpdate (scheduling jobs and acquiring native buffers).

  • protected override void OnUpdate()
    Main per-frame update. Creates/allocates NativeParallelQueue/NativeQueue instances in m_Groups for group actions, velocities and fades, constructs and schedules the BatchInstanceJob which processes PreCullingData and fills queues, registers job dependencies with BatchManagerSystem and PreCullingSystem, and stores the job handle in m_Groups for downstream processing. This method also obtains native batch instance handles for read access while scheduling.

  • protected override void OnCreateForCompiler()
    Compiler helper used to assign queries and the __TypeHandle's ComponentLookup/BufferLookup handles. Called by generated code to ensure job handle/lookup assignments are available.

  • (nested types and jobs) BatchInstanceSystem declares the following important nested types (high-level summary):

  • Groups (GameSystemBase) — creates and schedules the GroupActionJob and DequeueFadesJob after BatchInstanceJob finishes; manages the Native queues and the job dependency linking with BatchManagerSystem.
  • BatchInstanceJob : IJobParallelForDefer — the core burst-enabled parallel job that iterates updated PreCullingData and calls UpdateObjectInstances, UpdateNetInstances, UpdateLaneInstances, UpdateZoneInstances, UpdateFadeInstances or RemoveInstances as appropriate. It enqueues GroupActionData, FadeData and VelocityData used to update the actual native batch instances.
  • GroupActionJob : IJobParallelFor — consumes grouped GroupActionData (sorted per group) and applies adds/removes to the NativeBatchInstances via a ParallelInstanceUpdater, updating MeshBatch DynamicBuffers on entities to reflect instance indices.
  • DequeueFadesJob : IJob — drains the fade queue and creates fade entries on the fade container entity, associating velocities (if sampled) for LOD cross-fade movement.

Note: The system makes heavy use of ComponentLookup, BufferLookup, NativeBatchInstances and DynamicBuffer/ and integrates with the game's culling and batch management subsystems.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Typical initialization performed by the system:
    m_RenderingSystem = base.World.GetOrCreateSystemManaged<RenderingSystem>();
    m_BatchManagerSystem = base.World.GetOrCreateSystemManaged<BatchManagerSystem>();
    m_PreCullingSystem = base.World.GetOrCreateSystemManaged<PreCullingSystem>();
    m_UndergroundViewSystem = base.World.GetOrCreateSystemManaged<UndergroundViewSystem>();
    m_CityConfigurationSystem = base.World.GetOrCreateSystemManaged<CityConfigurationSystem>();
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
    m_Groups = base.World.GetOrCreateSystemManaged<Groups>();
}

If you want documentation for any nested type (Groups, the job structs or the data structs such as GroupActionData/FadeData/VelocityData), tell me which one and I will produce a dedicated section documenting its fields, behavior and examples of expected data flow between jobs and the BatchManagerSystem.