Skip to content

Game.Prefabs.ProcessingRequirementSystem

Assembly:
Namespace: Game.Prefabs

Type: class (public, CompilerGenerated)

Base: GameSystemBase

Summary:
ProcessingRequirementSystem scans entities with ProcessingRequirementData, UnlockRequirementData and the Locked tag and determines whether a processing-related unlock requirement has been satisfied based on resources produced by processing companies. It schedules a Burst-compiled IJobChunk (ProcessingRequirementJob) that reads a produced-resources NativeArray provided by ProcessingCompanySystem, updates UnlockRequirementData.m_Progress, and emits an Unlock event (an entity with Event and Unlock components) via an EndFrameBarrier command buffer when the required production threshold is reached. The system runs on a coarse interval (GetUpdateInterval returns 128) and properly chains job dependencies with the ProcessingCompanySystem and the EndFrameBarrier.


Fields

  • private EndFrameBarrier m_EndFrameBarrier
    Holds a reference to the EndFrameBarrier system used to create a parallel command buffer and to register the job handle as a producer. Commands to spawn Unlock events are enqueued through this barrier so they execute at the end of the frame.

  • private ProcessingCompanySystem m_ProcessingCompanySystem
    Reference to the ProcessingCompanySystem which supplies a NativeArray of produced resources. The system requests the produced resources array from this system and uses its returned dependency when scheduling the processing job.

  • private EntityQuery m_RequirementQuery
    An EntityQuery selecting entities that have ProcessingRequirementData (read-only), UnlockRequirementData (read/write), and the Locked tag. This query is used to schedule the IJobChunk across matching chunks.

  • private EntityArchetype m_UnlockEventArchetype
    An archetype created to represent the Unlock event entity (contains Event and Unlock components). The job creates entities of this archetype to signal unlocks.

  • private TypeHandle __TypeHandle
    Compiler-generated struct that stores EntityTypeHandle and ComponentTypeHandle instances used in the job. Its __AssignHandles method assigns handles from a SystemState reference.

Properties

  • This type does not expose any public properties.

Constructors

  • public ProcessingRequirementSystem()
    Default constructor (CompilerGenerated). The system initialization (OnCreate) is where required systems, query and archetypes are set up.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 128. Indicates the system's coarse update interval (used by the framework to reduce how frequently the system is invoked).

  • [Preserve] protected override void OnCreate()
    Initializes the system:

  • Acquires the EndFrameBarrier and ProcessingCompanySystem instances from the World.
  • Builds an EntityQuery for processing requirements (ProcessingRequirementData read-only, UnlockRequirementData read/write, Locked read-only).
  • Creates an archetype for Unlock events (Event + Unlock).
  • Calls RequireForUpdate with the query so the system runs only when matching entities exist.

  • [Preserve] protected override void OnUpdate()
    Sets up and schedules the ProcessingRequirementJob:

  • Obtains the produced resources NativeArray from ProcessingCompanySystem and the associated dependency.
  • Constructs a ProcessingRequirementJob with:
    • m_ProducedResources (NativeArray)
    • m_UnlockEventArchetype (to create unlock event entities)
    • m_CommandBuffer (EndFrameBarrier's parallel command buffer)
    • entity and component type handles from __TypeHandle via InternalCompilerInterface
  • Schedules the job in parallel over m_RequirementQuery, combining dependencies.
  • Registers the returned job handle with ProcessingCompanySystem as a reader and with the EndFrameBarrier as a producer.
  • Sets base.Dependency to the scheduled job handle.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper that currently builds and disposes a temporary EntityQueryBuilder; used by the compiler-generated OnCreateForCompiler flow.

  • protected override void OnCreateForCompiler()
    Compiler-generated method that calls __AssignQueries and assigns handles in __TypeHandle. Used in builds where the compiler orchestrates handle assignment.

Nested / Job logic (summary): - ProcessingRequirementJob (private struct, BurstCompile, implements IJobChunk) - Fields: - m_ProducedResources (ReadOnly NativeArray) — produced resources per resource index. - m_UnlockEventArchetype (ReadOnly EntityArchetype) — archetype for created Unlock events. - m_CommandBuffer (EntityCommandBuffer.ParallelWriter) — used to create event entities and set their Unlock component. - m_EntityType (ReadOnly EntityTypeHandle) - m_ProcessingRequirementType (ComponentTypeHandle, ReadOnly) - m_UnlockRequirementType (ComponentTypeHandle, ReadWrite) - Execute(...) iterates entities in the chunk, reads ProcessingRequirementData and UnlockRequirementData, calls ShouldUnlock to determine if the required produced amount is reached, updates unlockRequirement.m_Progress accordingly, and creates an Unlock event entity via the parallel command buffer when the requirement is met. The Unlock component contains the source entity as payload. - ShouldUnlock(...) obtains the produced amount for the resource type (0 if Resource.NoResource else uses EconomyUtils.GetResourceIndex), compares with m_MinimumProducedAmount, sets unlockRequirement.m_Progress to either the minimum or the produced amount, and returns true if the requirement is satisfied.

Notes about concurrency and burst: - The job is Burst-compiled and scheduled as IJobChunk.ScheduleParallel using the EntityQuery; it uses EntityCommandBuffer.ParallelWriter to safely create entities from worker threads. It also respects chunk enabled masks when iterating enabled entities.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();
    m_ProcessingCompanySystem = base.World.GetOrCreateSystemManaged<ProcessingCompanySystem>();
    m_RequirementQuery = GetEntityQuery(ComponentType.ReadOnly<ProcessingRequirementData>(), ComponentType.ReadWrite<UnlockRequirementData>(), ComponentType.ReadOnly<Locked>());
    m_UnlockEventArchetype = base.EntityManager.CreateArchetype(ComponentType.ReadWrite<Event>(), ComponentType.ReadWrite<Unlock>());
    RequireForUpdate(m_RequirementQuery);
}