Skip to content

Game.AddMeetingSystem

Assembly:
Assembly-CSharp (typical for game code; the file is part of the game's managed code)

Namespace: Game.Events

Type: public class AddMeetingSystem

Base: GameSystemBase

Summary: System that receives "add meeting" requests for households and schedules creation of event entities for those households. Requests are queued into a NativeQueue and processed in a Burst-compiled IJob (TravelJob). The job verifies that an event prefab supports coordinated meetings, ensures a household isn't already attending an event, creates an event entity (with the prefab's archetype and a PrefabRef), fills the event's Target buffer with the household's citizens, and—when appropriate for tourist households—adds coordinated meeting data pointing to a target. The system coordinates safe structural changes via a ModificationBarrier (ModificationBarrier1) and exposes the meeting queue to writers through GetMeetingQueue/AddWriter.


Fields

  • private ModificationBarrier1 m_ModificationBarrier
    {{ YOUR_INFO }}
    Holds the modification barrier system used to produce EntityCommandBuffer instances for safe structural changes from jobs.

  • private NativeQueue<AddMeeting> m_MeetingQueue
    {{ YOUR_INFO }}
    Persistent NativeQueue used to enqueue meeting requests from other systems/jobs/threads. Allocated in OnCreate and disposed in OnDestroy.

  • private EntityQuery m_LeisureSettingsQuery
    {{ YOUR_INFO }}
    EntityQuery used to look up the singleton LeisureParametersData (used to map LeisureType to event prefabs).

  • private EntityArchetype m_JournalDataArchetype
    {{ YOUR_INFO }}
    Archetype created for AddEventJournalData / Game.Common.Event entries (created in OnCreate). Used by the system for journal/event data if needed.

  • private TriggerSystem m_TriggerSystem
    {{ YOUR_INFO }}
    Reference to the TriggerSystem from the world (cached in OnCreate). Not directly used in the shown code but prepared for potential trigger interactions.

  • private CityStatisticsSystem m_CityStatisticsSystem
    {{ YOUR_INFO }}
    Reference to CityStatisticsSystem (cached in OnCreate). Not directly used in the shown code but available to the system.

  • private JobHandle m_Deps
    {{ YOUR_INFO }}
    Aggregated JobHandle of writers/readers that interact with the meeting queue. Used to combine dependencies when scheduling the processing job and to be returned to callers via GetMeetingQueue.

  • private TypeHandle __TypeHandle
    {{ YOUR_INFO }}
    Container for component/buffer lookup handles (ComponentLookup/BufferLookup) used by the job. Populated in OnCreateForCompiler via __AssignHandles.

  • public struct AddMeeting
    {{ YOUR_INFO }}
    Data struct for items enqueued into m_MeetingQueue. Contains:

  • Entity m_Household — the household entity requesting the meeting
  • LeisureType m_Type — the leisure/event type to create for the household

  • private struct TravelJob : IJob
    {{ YOUR_INFO }}
    Burst-compiled job that dequeues AddMeeting items and creates event entities. Uses read-only buffer/component lookups, the LeisureParametersData singleton, and an EntityCommandBuffer for structural changes. Ensures households are only processed once (via a temporary NativeParallelHashSet) and handles tourist households by attaching a CoordinatedMeeting component when applicable.

  • private struct TypeHandle
    {{ YOUR_INFO }}
    Holds read-only ComponentLookup and BufferLookup fields for the components used by the job. Includes a method __AssignHandles to initialize those lookups from a SystemState.


Properties

  • (none declared)
    {{ YOUR_INFO }}
    This system does not expose public properties. Interaction is via GetMeetingQueue/GetMeetingQueue(out JobHandle) and AddWriter(JobHandle).

Constructors

  • public AddMeetingSystem()
    {{ YOUR_INFO }}
    Default parameterless constructor (preserved). Most initialization occurs in OnCreate.

Methods

  • public NativeQueue<AddMeeting> GetMeetingQueue(out JobHandle deps)
    {{ YOUR_INFO }}
    Returns the NativeQueue used for adding meetings and outputs the current dependency JobHandle (m_Deps). Callers should combine their job dependencies with AddWriter to ensure proper synchronization.

  • public void AddWriter(JobHandle reader)
    {{ YOUR_INFO }}
    Called by external writers to register their JobHandle as a dependency. This method combines the provided reader handle into m_Deps (JobHandle.CombineDependencies), so the system's processing job will wait for writers to finish.

  • protected override void OnCreate()
    {{ YOUR_INFO }}
    Initializes subsystem references and resources:

  • Caches ModificationBarrier1, TriggerSystem, CityStatisticsSystem
  • Builds m_LeisureSettingsQuery for LeisureParametersData singleton lookup
  • Creates an archetype for AddEventJournalData and Game.Common.Event
  • Allocates m_MeetingQueue as a Persistent NativeQueue
  • Calls RequireForUpdate on the leisure settings query so this system only runs when leisure parameters exist

  • protected override void OnDestroy()
    {{ YOUR_INFO }}
    Disposes the native meeting queue and calls base.OnDestroy.

  • protected override void OnUpdate()
    {{ YOUR_INFO }}
    Prepares and schedules the Burst TravelJob:

  • Fills TravelJob fields with ComponentLookup/BufferLookup instances (via InternalCompilerInterface and __TypeHandle)
  • Passes the LeisureParametersData singleton
  • Provides an EntityCommandBuffer from the ModificationBarrier for structural changes
  • Schedules the job with combined dependencies (m_Deps + base.Dependency)
  • Calls AddWriter with the scheduled dependency to register it
  • Tells the ModificationBarrier about the producer job handle (AddJobHandleForProducer)

  • protected override void OnCreateForCompiler()
    {{ YOUR_INFO }}
    Compiler-time initialization that assigns queries and type handles (calls __AssignQueries and __TypeHandle.__AssignHandles). Used by the generated/class-compiler workflow.

  • private void __AssignQueries(ref SystemState state)
    {{ YOUR_INFO }}
    Generated helper that can initialize EntityQueryBuilder queries; currently contains an empty/new EntityQueryBuilder call. Part of compiler-generated plumbing.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    {{ YOUR_INFO }}
    Initializes the ComponentLookup and BufferLookup fields stored in TypeHandle by calling state.GetComponentLookup/GetBufferLookup with isReadOnly: true.

  • private void TravelJob.Execute()
    {{ YOUR_INFO }}
    Implementation details of the job:

  • Allocates a small NativeParallelHashSet to track processed households this job invocation
  • Loops while m_MeetingQueue.TryDequeue(out AddMeeting)
  • Looks up prefab via m_LeisureParameters.GetPrefab(item.m_Type)
  • Skips if the prefab does not have a HaveCoordinatedMeetingData buffer (no coordinated meeting support)
  • For each household, checks that it is not already attending (m_AttendingEvents.HasComponent) and not yet processed in this invocation
  • Adds AttendingEvent to the household (via command buffer)
  • Creates an event entity using the prefab's event archetype (m_EventDatas[prefab].m_Archetype)
  • Sets PrefabRef on the event entity and fills TargetElement buffer with household citizens (from HouseholdCitizen buffer)
  • If the household is a tourist household without a hotel and has a Target (m_Targets[entity].m_Target != Null), sets CoordinatedMeeting on the new event entity with that target
  • Disposes the temporary NativeParallelHashSet

Notes on safety: The job uses read-only lookups and an EntityCommandBuffer to perform structural changes. The NativeQueue is consumed inside the job by TryDequeue.


Usage Example

// Example: enqueueing a meeting request from another system or job producer
public void SomeProducerMethod(AddMeetingSystem addMeetingSystem, Entity household, LeisureType type)
{
    // Get the queue and current dependency (to know which jobs must complete before the system processes)
    JobHandle deps;
    NativeQueue<AddMeetingSystem.AddMeeting> queue = addMeetingSystem.GetMeetingQueue(out deps);

    // If you are producing from a job, pass the job's handle to AddWriter so the system waits for it.
    // If producing on the main thread, you can call AddWriter with default(JobHandle).
    addMeetingSystem.AddWriter(deps);

    // Enqueue the request (safe because the queue is a thread-safe NativeQueue)
    queue.Enqueue(new AddMeetingSystem.AddMeeting
    {
        m_Household = household,
        m_Type = type
    });
}

{{ YOUR_INFO }}
Notes and tips: - Always call AddWriter with the producer JobHandle when enqueuing from a job so the system waits for that job to finish. - The system only runs if a LeisureParametersData singleton exists (RequireForUpdate sets that requirement). - The job uses a ModificationBarrier's command buffer; structural entity changes occur via ECB after the job finishes. - The TravelJob is Burst-compiled for performance; keep managed calls out of producer code paths.