Game.InitializeSystem
Assembly: Assembly-CSharp (Game)
Namespace: Game.Net
Type: class
Base: GameSystemBase
Summary:
InitializeSystem is an ECS system used during entity initialization for the networking/edge (pipe) entities in the game. It runs for entities marked Created and that have any of the buffers/components ServiceCoverage, ResourceAvailability or WaterPipeConnection (and are not Temp). The system schedules a Burst-compiled IJobChunk (InitializeEdgesJob) that:
- Resizes and zero-initializes ServiceCoverage buffers to length 9,
- Resizes and zero-initializes ResourceAvailability buffers to length 34,
- Initializes WaterPipeConnection component fields (fresh/sewage/storm capacities) from the corresponding Prefab's WaterPipeConnectionData using the entity's PrefabRef.
The system uses a TypeHandle struct to cache component/buffer handles and a query (m_CreatedEdgesQuery) to limit updates. The job is scheduled in parallel using JobChunkExtensions.ScheduleParallel.
Fields
-
private EntityQuery m_CreatedEdgesQuery
This query selects entities that are newly created (Created) and contain at least one of ServiceCoverage, ResourceAvailability, or WaterPipeConnection, excluding entities marked Temp. The system calls RequireForUpdate(m_CreatedEdgesQuery) in OnCreate so the system only runs when such entities exist. -
private TypeHandle __TypeHandle
Holds cached ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances (wrapped fields) used by the scheduled job. __TypeHandle.__AssignHandles(ref state) is called during OnCreateForCompiler to initialize these cached handles from the SystemState. -
private struct InitializeEdgesJob
(nested)
Burst-compiled IJobChunk that performs the per-chunk initialization described in Summary. It contains ComponentTypeHandle/BufferTypeHandle/ComponentLookup fields for the components and buffers it reads/writes. -
private struct TypeHandle
(nested)
A helper struct that stores the component and buffer handles/lookup references and exposes __AssignHandles(ref SystemState) to populate them from the system state.
Properties
- (none publicly exposed)
This system does not declare any public properties. It uses internal TypeHandle fields and the ECS SystemState/EntityQuery API.
Constructors
public InitializeSystem()
Default constructor. Marked with [Preserve] in code. The constructor does not perform special initialization; component/query setup happens in OnCreate and OnCreateForCompiler.
Methods
protected override void OnCreate()
: System.Void
Preserved override. Creates and stores m_CreatedEdgesQuery with the following query description:- All: Created (read-only)
- Any: ServiceCoverage (read/write), ResourceAvailability (read/write), WaterPipeConnection (read/write)
-
None: Temp (read-only) Calls RequireForUpdate(m_CreatedEdgesQuery) so the system only updates when matching entities exist.
-
protected override void OnUpdate()
: System.Void
Builds an InitializeEdgesJob instance by obtaining runtime component/buffer handles via InternalCompilerInterface.Get... using the cached handles in __TypeHandle and schedules the job in parallel with JobChunkExtensions.ScheduleParallel(jobData, m_CreatedEdgesQuery, base.Dependency). The job performs the buffer resizing/zero-initialization and copies capacity values from prefab data into WaterPipeConnection components. -
protected override void OnCreateForCompiler()
: System.Void
Called by generated code path; calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to prepare query & type handles as part of the system bootstrap used by the compiler/runtime. -
private void __AssignQueries(ref SystemState state)
: System.Void
Generated helper that currently only creates and disposes an EntityQueryBuilder(Allocator.Temp) placeholder in this implementation. The query used at runtime is created at OnCreate. -
void TypeHandle.__AssignHandles(ref SystemState state)
: System.Void
Populates the TypeHandle's cached handles: - ComponentTypeHandle
(read-only) - ComponentLookup
(read-only) - BufferTypeHandle
(read/write) - BufferTypeHandle
(read/write) -
ComponentTypeHandle
(read/write) -
void InitializeEdgesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
: System.Void
Main job logic — per chunk: - Gets NativeArray
, BufferAccessor , BufferAccessor , and NativeArray for the chunk. - For each ServiceCoverage buffer in the chunk, resizes it to length 9 and assigns default(ServiceCoverage) to every element (zero-initializes).
- For each ResourceAvailability buffer in the chunk, resizes it to length 34 and assigns default(ResourceAvailability) to every element (zero-initializes).
-
For each WaterPipeConnection component in the chunk, looks up the corresponding WaterPipeConnectionData using the entity's PrefabRef and assigns m_FreshCapacity, m_SewageCapacity, and m_StormCapacity from the prefab data into the component instance.
-
void IJobChunk.Execute(...)
(explicit interface implementation)
Forwards to the strongly-typed Execute(in ArchetypeChunk, ...). The job is marked [BurstCompile] to enable Burst optimizations.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_CreatedEdgesQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[1] { ComponentType.ReadOnly<Created>() },
Any = new ComponentType[3]
{
ComponentType.ReadWrite<ServiceCoverage>(),
ComponentType.ReadWrite<ResourceAvailability>(),
ComponentType.ReadWrite<WaterPipeConnection>()
},
None = new ComponentType[1] { ComponentType.ReadOnly<Temp>() }
});
RequireForUpdate(m_CreatedEdgesQuery);
}
[Preserve]
protected override void OnUpdate()
{
var jobData = new InitializeEdgesJob
{
m_PrefabRefType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Prefabs_PrefabRef_RO_ComponentTypeHandle, ref base.CheckedStateRef),
m_WaterPipeConnectionData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Prefabs_WaterPipeConnectionData_RO_ComponentLookup, ref base.CheckedStateRef),
m_ServiceCoverageType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_ServiceCoverage_RW_BufferTypeHandle, ref base.CheckedStateRef),
m_ResourceAvailabilityType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_ResourceAvailability_RW_BufferTypeHandle, ref base.CheckedStateRef),
m_WaterPipeConnectionType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Net_WaterPipeConnection_RW_ComponentTypeHandle, ref base.CheckedStateRef)
};
base.Dependency = JobChunkExtensions.ScheduleParallel(jobData, m_CreatedEdgesQuery, base.Dependency);
}
Notes and tips:
- The job resizes buffers to fixed lengths (9 for ServiceCoverage, 34 for ResourceAvailability). If mod code changes expected sizes, update these constants accordingly.
- The job expects PrefabRef on the same entities; removing PrefabRef will prevent correct capacity initialization.
- Because the job uses ComponentLookup