Game.ServiceCoverageSystem
Assembly: Game
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
ServiceCoverageSystem is an ECS system that ensures every entity with a ServiceCoverage dynamic buffer has a fixed minimum capacity/length (9). It schedules a Burst-compiled IJobChunk (ServiceCoverageJob) to run in parallel over matching chunks, expanding buffers and appending default ServiceCoverage entries where required. The system uses a BufferTypeHandle for ServiceCoverage and an EntityQuery that requires entities with ServiceCoverage to exist before the system runs. This is intended to keep ServiceCoverage buffers consistent for net/service logic in Cities: Skylines 2 modding contexts.
Fields
-
private Unity.Entities.EntityQuery m_Query
Query used to find entities that contain the ServiceCoverage buffer. The system calls RequireForUpdate(m_Query) so it only runs while such entities exist. -
private TypeHandle __TypeHandle
Internal struct instance that stores the BufferTypeHandleused by the job. The TypeHandle struct exposes a method __AssignHandles(ref SystemState) that obtains the buffer handle from the SystemState. -
(nested)
private struct TypeHandle
Contains: public BufferTypeHandle<ServiceCoverage> __Game_Net_ServiceCoverage_RW_BufferTypeHandle
— the actual handle for reading/writing the ServiceCoverage buffer.-
public void __AssignHandles(ref SystemState state)
— obtains the BufferTypeHandlefrom the state (called during OnCreateForCompiler). -
(nested)
private struct ServiceCoverageJob : IJobChunk
The Burst-compiled job executed against matching chunks. It holds: public BufferTypeHandle<ServiceCoverage> m_CoverageType
— the handle used to get buffer accessors in the job.
The job iterates chunk entities and:
- Gets a BufferAccessor
Properties
- None (no public properties are declared on this class).
Constructors
public ServiceCoverageSystem()
Default constructor. Marked with [Preserve] attribute in the source to avoid IL stripping. Nothing else is initialized here; initialization occurs in OnCreate/OnCreateForCompiler.
Methods
[Preserve] protected override void OnCreate()
- Calls base.OnCreate().
- Creates an EntityQuery for ComponentType.ReadOnly
() and stores it in m_Query. -
Calls RequireForUpdate(m_Query) so the system only updates while such entities exist.
-
[Preserve] protected override void OnUpdate()
- Prepares a ServiceCoverageJob instance and fills its m_CoverageType by calling InternalCompilerInterface.GetBufferTypeHandle with the saved TypeHandle and the system's CheckedStateRef.
-
Schedules the job in parallel with JobChunkExtensions.ScheduleParallel(jobData, m_Query, base.Dependency) and assigns the returned JobHandle back to base.Dependency.
-
protected override void OnCreateForCompiler()
- Called by compiled code paths to set up query handles for the generated/IL2CPP compiler usage.
-
Calls __AssignQueries(ref base.CheckedStateRef) then __TypeHandle.__AssignHandles(ref base.CheckedStateRef).
-
private void __AssignQueries(ref SystemState state)
-
Internal method used during compilation-time initialization. In source it constructs and disposes an EntityQueryBuilder(Allocator.Temp) (placeholder for generated query assignment).
-
(in TypeHandle)
[MethodImpl(MethodImplOptions.AggressiveInlining)] public void __AssignHandles(ref SystemState state)
-
Obtains a BufferTypeHandle
from the provided SystemState: state.GetBufferTypeHandle<ServiceCoverage(). -
(in ServiceCoverageJob)
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
-
Core job logic described above: ensure each entity's ServiceCoverage buffer has capacity/length at least 9 and append default elements to reach that size.
-
(in ServiceCoverageJob) explicit interface wrapper for
IJobChunk.Execute(...)
that forwards to the job's Execute method.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Set up the query so the system executes only when entities have ServiceCoverage buffers
m_Query = GetEntityQuery(ComponentType.ReadOnly<ServiceCoverage>());
RequireForUpdate(m_Query);
}
Additional notes for modders: - The ServiceCoverage type referenced by the buffer is in Game.Net namespace; the system uses the buffer handle to modify dynamic buffers from a job. If you change the intended buffer size, update the constant (9) in the ServiceCoverageJob accordingly. - The job is Burst-compiled and scheduled in parallel, so avoid side effects in ServiceCoverage constructors or reliance on managed resources inside the job. Use only blittable types in the ServiceCoverage struct for safe Burst execution. - The [Preserve] attributes prevent stripping of methods/constructors by build optimizers — keep them when backporting or modifying the system to maintain runtime behavior. - If you need to mutate ServiceCoverage buffers from other systems, be mindful of dependencies (base.Dependency) to avoid race conditions with this parallel job.