Game.SubBlockSystem
Assembly:
Assembly-CSharp (inferred)
Namespace:
Game.Serialization
Type:
class
Base:
GameSystemBase
Summary:
SubBlockSystem is an ECS system that collects "sub-block" references for block entities that have an Owner component. It iterates over all entities matching the query (Block + Owner) and, for each entity, appends a SubBlock(buffer entry) to the SubBlock dynamic buffer on the owner entity. The system uses a Burst-compiled IJobChunk (SubBlockJob) and BufferLookup to write to owner buffers efficiently on worker threads. It also contains a compiler-assist TypeHandle struct used to cache Entity/Component/Buffer handles for scheduling.
Fields
-
private EntityQuery m_Query
Holds the entity query used to find all entities that have both Block and Owner components. The query is created in OnCreate and the system calls RequireForUpdate(m_Query) to run only when matching entities exist. -
private TypeHandle __TypeHandle
A generated helper struct instance that caches: - EntityTypeHandle
- ComponentTypeHandle
(read-only) -
BufferLookup
(read/write) This field is used to obtain the low-level handles required by the job and is initialized via __AssignHandles in OnCreateForCompiler. -
private struct SubBlockJob
(nested)
Describes the Burst-compiled IJobChunk implementation that performs the per-chunk iteration. Its important members: EntityTypeHandle m_EntityType
— used to read the chunk's entity array.ComponentTypeHandle<Owner> m_OwnerType
(ReadOnly) — used to read Owner components in the chunk.-
BufferLookup<SubBlock> m_SubBlocks
— used to write into owners' SubBlock buffers. The job's Execute reads entities and owners in parallel and does m_SubBlocks[owner.m_Owner].Add(new SubBlock(block)). -
private struct TypeHandle
(nested)
Contains the concrete type handles and a method __AssignHandles(ref SystemState) that fills them from the system state. This is used by OnCreateForCompiler to initialize the cached handles.
Properties
- This type does not define any public properties.
(Internals use cached handles in __TypeHandle and job-local handles passed at schedule time.)
Constructors
public SubBlockSystem()
Default constructor. The system is constructed and then OnCreate/OnCreateForCompiler will be invoked by the runtime.
Methods
-
protected override void OnCreate()
Creates the entity query: GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly ()) and calls RequireForUpdate(m_Query). This prevents the system from running when there are no matching Block+Owner entities. -
protected override void OnUpdate()
Builds a SubBlockJob instance by acquiring runtime handles via InternalCompilerInterface.GetEntityTypeHandle / GetComponentTypeHandle / GetBufferLookup using the cached __TypeHandle entries and base.CheckedStateRef. The job is scheduled with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and the returned JobHandle is stored into base.Dependency. -
protected override void OnCreateForCompiler()
Called by generated/compiled code paths to initialize internal structures: it calls __AssignQueries(ref base.CheckedStateRef) (no-op here besides a temp EntityQueryBuilder Dispose) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to populate the cached handles used at schedule time. -
private void __AssignQueries(ref SystemState state)
A generated helper that currently creates/disposes an EntityQueryBuilder (no additional queries are added here). Present to satisfy the codegen pattern. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
(Fills the TypeHandle fields) Sets: - __Unity_Entities_Entity_TypeHandle = state.GetEntityTypeHandle();
- __Game_Common_Owner_RO_ComponentTypeHandle = state.GetComponentTypeHandle
(isReadOnly: true); -
__Game_Zones_SubBlock_RW_BufferLookup = state.GetBufferLookup
(); -
private struct SubBlockJob.Execute(in ArchetypeChunk chunk, ...)
Per-chunk logic: obtains NativeArrayand NativeArray from the chunk, iterates entities, and appends new SubBlock entries into the owner's buffer using m_SubBlocks[owner.m_Owner].Add(new SubBlock(block)). Implemented as a Burst-compiled IJobChunk for performance.
Notes:
- The job is annotated with [BurstCompile], so ensure Burst is supported in the build environment for the best performance.
- BufferLookup
Usage Example
// Typical usage: ensure owner entities have a SubBlock buffer before this system runs.
// Example: when creating an owner entity:
Entity owner = entityManager.CreateEntity(typeof(SomeOwnerTag));
entityManager.AddBuffer<SubBlock>(owner);
// The SubBlockSystem will run automatically (when entities with Block+Owner exist).
// Its OnCreate registers the query:
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The system's OnCreate already does:
// m_Query = GetEntityQuery(ComponentType.ReadOnly<Block>(), ComponentType.ReadOnly<Owner>());
// RequireForUpdate(m_Query);
}
// The system's OnUpdate schedules a Burst IJobChunk that appends SubBlock entries to each owner.