Game.Serialization.TrimPathsSystem
Assembly: Game
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
TrimPathsSystem is an ECS system that trims path element buffers for entities that own paths. It schedules a Burst-compiled IJobChunk (TrimPathsJob) that iterates chunks containing PathOwner components and PathElement buffers, and calls PathUtils.TrimPath on any PathOwner whose m_ElementIndex > 0. The system uses an EntityQuery that requires PathOwner and PathElement and excludes Temp and Deleted, and it wires up ComponentTypeHandle/BufferTypeHandle via a compiler helper TypeHandle struct.
Fields
-
private EntityQuery m_Query
Holds the query used by the system: selects entities with PathOwner and PathElement buffers while excluding Temp and Deleted. The query is created in OnCreate and passed to ScheduleParallel in OnUpdate. -
private TypeHandle __TypeHandle
Compiler-generated helper struct that caches ComponentTypeHandleand BufferTypeHandle . The __AssignHandles method populates these handles from a SystemState; they are used when constructing the TrimPathsJob in OnUpdate.
Properties
- This system exposes no public properties.
Constructors
public TrimPathsSystem()
Default (parameterless) constructor. Marked with [Preserve] to avoid stripping; standard construction used by the ECS/bootstrapper.
Methods
protected override void OnCreate()
Initializes the entity query:- Creates m_Query with ComponentType.ReadOnly
(), ComponentType.ReadOnly (), ComponentType.Exclude (), ComponentType.Exclude (). -
Calls RequireForUpdate(m_Query) so the system only updates when matching entities exist.
-
protected override void OnUpdate()
Creates and schedules the TrimPathsJob: - Populates jobData.m_PathOwnerType and jobData.m_PathElementType using InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle with handles from __TypeHandle.
-
Schedules the job with JobChunkExtensions.ScheduleParallel(jobData, m_Query, base.Dependency) and stores resulting JobHandle in base.Dependency.
-
protected override void OnCreateForCompiler()
Called by compiler tooling to initialize compiler-specific plumbing: -
Calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef).
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler helper that builds/initializes any query-related artifacts required for ahead-of-time compilation. In this implementation it creates and immediately disposes an EntityQueryBuilder(Allocator.Temp) (used to reproduce query metadata for the compiler). -
private struct TrimPathsJob : IJobChunk
A Burst-compiled job that operates per chunk. Important members and behavior: - Fields:
public ComponentTypeHandle<PathOwner> m_PathOwnerType
public BufferTypeHandle<PathElement> m_PathElementType
- Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask):
- Retrieves NativeArray
via chunk.GetNativeArray(ref m_PathOwnerType). - Retrieves BufferAccessor
via chunk.GetBufferAccessor(ref m_PathElementType). - Iterates entities in the chunk; for each PathOwner where pathOwner.m_ElementIndex > 0 calls PathUtils.TrimPath(bufferAccessor[i], ref pathOwner) and writes the modified PathOwner back into the nativeArray.
- Retrieves NativeArray
-
The job is marked with [BurstCompile] for performance.
-
private struct TypeHandle
Holds the cached handles used by the job. Members: public ComponentTypeHandle<PathOwner> __Game_Pathfind_PathOwner_RW_ComponentTypeHandle
public BufferTypeHandle<PathElement> __Game_Pathfind_PathElement_RW_BufferTypeHandle
- Method
public void __AssignHandles(ref SystemState state)
assigns these handles from the given SystemState via state.GetComponentTypeHandle() and state.GetBufferTypeHandle ().
Attributes used in the class: - [CompilerGenerated] on the system class (generated/augmented by compiler tooling). - [Preserve] on ctor and lifecycle methods to prevent stripping. - [BurstCompile] on the TrimPathsJob for Burst optimization.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_Query = GetEntityQuery(
ComponentType.ReadOnly<PathOwner>(),
ComponentType.ReadOnly<PathElement>(),
ComponentType.Exclude<Temp>(),
ComponentType.Exclude<Deleted>());
RequireForUpdate(m_Query);
}
Additional notes: - The system relies on PathUtils.TrimPath (from Game.Pathfind) to perform the buffer trimming logic; the TrimPathsJob simply invokes that utility per-path owner needing trimming. - This design schedules the trimming work in parallel across chunks to scale with entity count; the use of buffer accessors and component handles is done via the ECS internal/compiler interfaces to be compatible with the generated code patterns.