Skip to content

Game.Tools.ApplyNetSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Tools

Type: class

Base: GameSystemBase

Summary:
ApplyNetSystem is a game system used by the net/building editing tool pipeline to "apply" temporary network edits (Temp components) to persistent network entities in the simulation. It coordinates three Burst jobs to: - Patch temporary references so edges/nodes/lane references point to the correct (possibly replaced) originals, - Fix up connected-edge buffers so they only reference valid connections, - Handle creation, update and deletion of entities marked as Temp (creating Created/Updated/Deleted/Applied components and transferring component data as required).

It uses a ToolOutputBarrier to produce an EntityCommandBuffer for entity changes, and queries the EconomyParameterData and simulation frame to compute Recent modification costs.


Fields

  • private ToolOutputBarrier m_ToolOutputBarrier
    Holds the ToolOutputBarrier system used to obtain an EntityCommandBuffer. The command buffer is used to enqueue structural/component changes produced by the system's jobs.

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem; used to read the current simulation frame index (m_SimulationSystem.frameIndex) when creating Recent modification records.

  • private EntityQuery m_TempQuery
    EntityQuery that matches entities containing the Temp component and any of Node/Edge/Lane/Aggregate. This query selects the temporary network entities that need to be applied.

  • private EntityQuery m_EconomyParameterQuery
    EntityQuery used to read the singleton EconomyParameterData required to calculate refunds / modification costs during apply.

  • private ComponentTypeSet m_ApplyCreatedTypes
    ComponentTypeSet used when marking newly created entities as Applied/Created/Updated (added to the entity via the command buffer).

  • private ComponentTypeSet m_ApplyUpdatedTypes
    ComponentTypeSet used to mark entities that were updated (Applied + Updated).

  • private ComponentTypeSet m_ApplyDeletedTypes
    ComponentTypeSet used to mark entities that were deleted (Applied + Deleted).

  • private TypeHandle __TypeHandle
    Generated helper structure that holds ComponentTypeHandle / ComponentLookup / BufferLookup instances used by the job structs. It has a method to assign handles from the SystemState.

Properties

  • None

Constructors

  • public ApplyNetSystem()
    Default constructor. The system relies on OnCreate to initialize queries and component type sets. Marked with [Preserve] attribute on OnCreate, OnUpdate and constructor to ensure it is kept by IL stripping.

Methods

  • protected override void OnCreate()
    Initializes the system: acquires ToolOutputBarrier and SimulationSystem, constructs m_TempQuery and m_EconomyParameterQuery, initializes the ComponentTypeSet instances for apply-created/updated/deleted types, and calls RequireForUpdate for the temp and economy queries so the system only runs when needed.

  • protected override void OnUpdate()
    Main scheduling method. Prepares three job data structs:

  • PatchTempReferencesJob — patch temporary entity references for start/end nodes, connected node/edge buffers, and subnets/owners.
  • FixConnectedEdgesJob — remove stale connected edges that no longer point to the expected node.
  • HandleTempEntitiesJob — the core apply logic which will create, update or delete real entities from Temp data. This job uses a ParallelWriter EntityCommandBuffer from the ToolOutputBarrier and sets components such as Created/Updated/Deleted/Applied and transfers component/ buffer data between temp and original entities. It schedules the jobs over m_TempQuery (chunk jobs), combines dependencies and registers the producer handle with the ToolOutputBarrier.

  • protected override void OnCreateForCompiler()
    Compiler/template helper used to assign queries and calls the TypeHandle assignment helper. (Generated/used by the DOTS compiler pipeline.)

  • private void __AssignQueries(ref SystemState state)
    Generated helper invoked during compiler-time OnCreateForCompiler. In this decompiled file it creates an EntityQueryBuilder and disposes it (placeholder for query assignment).

  • private struct TypeHandle
    Generated struct containing all required type handles, lookups and buffer lookups. Use __AssignHandles(ref SystemState) to obtain ComponentTypeHandle / ComponentLookup / BufferLookup instances from a SystemState. This is used by OnUpdate to populate job fields.

Nested job structs (inner types) — brief summaries:

  • PatchTempReferencesJob : IJobChunk (BurstCompile)
    Patches temp references for edges/nodes:
  • For edge chunks it patches Edge.m_Start and Edge.m_End to map temporary node entities to their originals where appropriate.
  • Updates ConnectedNode/ConnectedEdge buffers so they reference the correct (original) entities when temps are replaced/combined or when originals are moved.
  • Fixes SubNet buffer membership when owners are remapped. This job reads Temp, Node and Edge components and uses BufferLookup/ComponentLookup instances to mutate buffers/components as needed.

  • FixConnectedEdgesJob : IJobChunk (BurstCompile)
    Cleans up ConnectedEdge buffers on original nodes by removing connected-edge entries that no longer refer to an edge containing that node (when the edge's start/end no longer equals the node). It iterates ConnectedEdge buffers and removes stale entries when necessary.

  • HandleTempEntitiesJob : IJobChunk (BurstCompile)
    Per-chunk job that performs create/update/delete semantics for temp entities:

  • If Temp.Flags contains Delete => marks original (if any) and temp entity as Deleted.
  • If Replace flag is set => marks original as Deleted (if present), then creates the new entity (adds Created/Applied/Updated as appropriate).
  • If temp has m_Original => perform an Update: copy/set components and buffers from the temp entity to the original entity according to availability and per-component logic (helpers UpdateComponent/UpdateBuffer). Manages special per-component logic (e.g., Road component's flags are merged, Recent modification costs are computed with EconomyParameterData, and some components are toggled only if the prefab is enabled).
  • Otherwise, Create the entity: remove Temp component and add Created/Applied/Updated markers and Recent if cost > 0. It uses m_CommandBuffer (EntityCommandBuffer.ParallelWriter) to enqueue structural and component changes, and uses m_SimulationSystem.frameIndex and EconomyParameterData to compute Recent modification amounts.

Helper methods inside HandleTempEntitiesJob: - Delete(chunkIndex, entity, temp) — enqueue Deleted component on original (if exists) and on the temp entity. - UpdateComponent(...) — generic logic for copying/adding/removing a component from temp to original according to whether entity/original have the component and whether updateValue is requested. - UpdateBuffer(...) — similar to UpdateComponent but for buffer components; copies buffer contents or removes the buffer on original if necessary; returns whether an old buffer existed. - Update(chunkIndex, entity, temp) — marks original as recently modified (Recent) and adds ApplyUpdatedTypes to original, then marks the temp as Deleted. - Create(chunkIndex, entity, temp) — removes Temp component from the entity, adds Recent if cost>0, and marks it with ApplyCreatedTypes.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolOutputBarrier = base.World.GetOrCreateSystemManaged<ToolOutputBarrier>();
    m_SimulationSystem = base.World.GetOrCreateSystemManaged<SimulationSystem>();
    m_TempQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[1] { ComponentType.ReadOnly<Temp>() },
        Any = new ComponentType[4]
        {
            ComponentType.ReadOnly<Node>(),
            ComponentType.ReadOnly<Edge>(),
            ComponentType.ReadOnly<Lane>(),
            ComponentType.ReadOnly<Aggregate>()
        }
    });
    m_ApplyCreatedTypes = new ComponentTypeSet(ComponentType.ReadWrite<Applied>(), ComponentType.ReadWrite<Created>(), ComponentType.ReadWrite<Updated>());
    m_ApplyUpdatedTypes = new ComponentTypeSet(ComponentType.ReadWrite<Applied>(), ComponentType.ReadWrite<Updated>());
    m_ApplyDeletedTypes = new ComponentTypeSet(ComponentType.ReadWrite<Applied>(), ComponentType.ReadWrite<Deleted>());
    m_EconomyParameterQuery = GetEntityQuery(ComponentType.ReadOnly<EconomyParameterData>());
    RequireForUpdate(m_TempQuery);
    RequireForUpdate(m_EconomyParameterQuery);
}

Notes / Tips for Modders: - ApplyNetSystem relies on Temp components that editing tools produce. To customize tool apply behavior, consider producing Temp entities with the expected component sets (Temp + Node/Edge/Lane + PrefabRef etc.). - The system uses an EntityCommandBuffer produced by ToolOutputBarrier; scheduled jobs will enqueue structural changes that are applied later by the barrier. If you need synchronous changes, ensure ordering with the barrier or run code at the appropriate sync point. - Recent cost/refund calculations use EconomyParameterData and NetUtils.GetRefundAmount; changes to refund logic affect how Recent.m_ModificationCost is computed. - Many operations are handled via generated TypeHandle and ComponentLookup/BufferLookup; when writing your own chunk jobs, follow the same pattern to get handles from the SystemState using GetComponentTypeHandle / GetComponentLookup / GetBufferLookup.

If you want, I can also produce a short diagram showing the job flow and what components/buffers each job touches, or extract the exact list of component types used by the TypeHandle for reference.