Game.Buildings.ReferencesSystem
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Buildings
Type: class
Base: GameSystemBase
Summary:
ReferencesSystem is an ECS system used by the game to maintain references between "spawn location" type entities (SpawnLocation, HangaroundLocation, ParkingLane) and their owners. It runs a Burst-compiled IJobChunk (UpdateBuildingReferencesJob) to update owner buffers of type SpawnLocationElement so owners have up-to-date lists of related spawn locations. The job also handles deletion (removing references when a spawn location has Deleted set) and respects temporary (Temp) components to only propagate references for temporary owners when appropriate. The system uses ComponentTypeHandle, ComponentLookup and BufferLookup for efficient chunk-based processing and schedules the job through JobChunkExtensions in OnUpdate.
Fields
-
private EntityQuery m_SpawnLocationQuery
{{ YOUR_INFO }}
Description: Query that matches entities which are spawn-location-like (SpawnLocation, HangaroundLocation or ParkingLane) and have an Owner and Created, or alternatively Deleted and Owner. The system RequiresForUpdate this query so it only runs when relevant entities exist. -
private TypeHandle __TypeHandle
{{ YOUR_INFO }}
Description: Internal helper struct used to cache EntityTypeHandle, ComponentTypeHandle and ComponentLookup/BufferLookup handles required by the job. These handles are assigned during OnCreateForCompiler (via __AssignHandles) to avoid repeatedly fetching them at runtime.
Properties
- None
Constructors
public ReferencesSystem()
{{ YOUR_INFO }}
Description: Default constructor (compiler-preserved). Initialization work is done in OnCreate/OnCreateForCompiler; the constructor itself is empty.
Methods
-
protected override void OnCreate()
: System.Void
{{ YOUR_INFO }}
Description: Creates the m_SpawnLocationQuery which has two parts (one matching Created+Owner and any of SpawnLocation/ HangaroundLocation/ ParkingLane; and one matching Deleted+Owner with the same any-clause). Calls RequireForUpdate(m_SpawnLocationQuery) so the system only updates when the query is non-empty. -
protected override void OnUpdate()
: System.Void
{{ YOUR_INFO }}
Description: Builds an UpdateBuildingReferencesJob instance, fills all required handles via InternalCompilerInterface wrappers around the cached __TypeHandle handles, and schedules the job with JobChunkExtensions.Schedule against m_SpawnLocationQuery, chaining to the system's dependency. -
protected override void OnCreateForCompiler()
: System.Void
{{ YOUR_INFO }}
Description: Called by the generated/compiled pipeline to prepare the system for execution: calls __AssignQueries and assigns handles in __TypeHandle by calling __AssignHandles. This sets up the internal handles required by OnUpdate. -
private void __AssignQueries(ref SystemState state)
: System.Void
{{ YOUR_INFO }}
Description: Internal helper invoked from OnCreateForCompiler; in this decompiled code it only constructs and disposes an EntityQueryBuilder (left essentially empty in the decompilation). In general this method would be part of generated query setup. -
(nested)
private struct TypeHandle.__AssignHandles(ref SystemState state)
: System.Void
{{ YOUR_INFO }}
Description: Assigns all Entity/Component/Buffer lookups and type handles used by the job: EntityTypeHandle, ComponentTypeHandle, ComponentLookup , and BufferLookup . This method centralizes handle initialization. -
(nested)
private struct UpdateBuildingReferencesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
: System.Void
{{ YOUR_INFO }}
Description: Core chunk-processing logic. For each chunk: - Retrieves arrays of Entity and Owner for the chunk.
- Determines which spawn location type the chunk represents (SpawnLocation, HangaroundLocation, or ParkingLane) by checking chunk.Has for the appropriate ComponentTypeHandle.
- If the chunk has Deleted, it iterates owners and removes the spawn location entity entry from each owner's SpawnLocationElement buffer, climbing owner chains via Owner components to remove references from parent owners too.
- Otherwise, optionally filters by Temp (only propagate if owner has Temp when spawn location is temporary), then adds the SpawnLocationElement (entity + type) to the owner's buffer using CollectionUtils.TryAddUniqueValue, and climbs owner chains to add to ancestor owners as well.
-
The job uses ComponentLookup for Owner and Temp and BufferLookup for SpawnLocationElement buffers to access and modify data.
-
(nested)
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
: System.Void
{{ YOUR_INFO }}
Description: Explicit interface implementation that forwards to the typed Execute method above. Marked for Burst compilation.
Usage Example
// Example: creating an entity that will be processed by ReferencesSystem.
// This shows how to create a spawn-location entity and an owner entity so that
// ReferencesSystem will add a SpawnLocationElement to the owner's buffer.
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// create owner entity and add a SpawnLocationElement buffer
var ownerArchetype = em.CreateArchetype(typeof(Owner), typeof(SpawnLocationElement));
var owner = em.CreateEntity(ownerArchetype);
// set owner component data (example owner id is the entity itself)
em.SetComponentData(owner, new Owner { m_Owner = owner });
// create a spawn location entity with Created and SpawnLocation components and an Owner
var spawnArchetype = em.CreateArchetype(typeof(Created), typeof(Owner), typeof(SpawnLocation));
var spawn = em.CreateEntity(spawnArchetype);
em.SetComponentData(spawn, new Owner { m_Owner = owner });
// The ReferencesSystem will run on the next update and add a SpawnLocationElement
// to the owner's SpawnLocationElement buffer pointing to 'spawn'.
Notes and tips:
- The system expects owners to have a dynamic buffer of SpawnLocationElement so make sure owner archetypes include that buffer type.
- Deleted on a spawn-location entity causes the system to remove references from owner buffers.
- Temp component is treated specially: when a spawn location is marked temporary, the job will only propagate to owners that have Temp (checked via ComponentLookup