Game.Simulation.MeetingSystem
Assembly: Game (game assembly)
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
Manages the lifecycle of CoordinatedMeeting entities (waiting, traveling, attending, done) by scheduling a Burst-compiled IJobChunk (MeetingJob) to process meeting chunks in parallel. The system reads meeting prefabs (HaveCoordinatedMeetingData, CalendarEventData, PrefabRef) and citizen/building state (Citizen, CurrentBuilding, HealthProblem, PropertyRenter, HouseholdMember, AttendingMeeting) to decide transitions, show icons, and remove/clean up meetings. It uses RandomSeed and the SimulationSystem frame index to schedule phase durations, writes structural changes through an EndFrameBarrier command buffer (parallel writer), and issues icon notifications via IconCommandSystem.
Fields
-
private EntityQuery m_MeetingGroup
Holds the query selecting CoordinatedMeeting entities with CoordinatedMeetingAttendee buffers, excluding Deleted and Temp. Used to drive which entities the job processes. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem; used to read the current simulation frame (frameIndex) for timing meeting phases and random seed usage. -
private EndFrameBarrier m_EndFrameBarrier
Barrier used to produce a parallel EntityCommandBuffer for safely enqueuing structural changes (AddComponent, RemoveComponent ) at end of frame. -
private IconCommandSystem m_IconCommandSystem
Used to create an IconCommandBuffer for showing notifications/icons (e.g., meeting start notifications) on buildings. -
private TypeHandle __TypeHandle
Generated helper that caches Entity/Component/Buffer type handles and ComponentLookup/BufferLookup instances for the job. Assigned during OnCreate/OnCreateForCompiler. -
(Nested)
private struct MeetingJob
(BurstCompile)
IJobChunk that contains all per-chunk processing logic: reads CoordinatedMeeting components and CoordinatedMeetingAttendee buffers, looks up related components/buffers (citizen state, current building, health, renters, household, meeting data on prefabs, calendar event data), uses RandomSeed and m_SimulationFrame to manage phases, and writes commands via EntityCommandBuffer. It also uses IconCommandBuffer for notification icons. -
(Nested)
private struct TypeHandle
Compiler-generated grouping of type handles and lookups. Provides __AssignHandles(ref SystemState) to initialize handles.
Properties
- None (this system exposes no public properties)
Constructors
public MeetingSystem()
Default constructor (Preserve attribute on class methods ensures this system is preserved for runtime reflection/creation). Initialization of fields is handled in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 16. The system requests to be updated every 16 simulation frames (i.e., it runs at an interval of 16 frames). -
[Preserve] protected override void OnCreate()
Initializes references to subsystem instances: - Gets or creates SimulationSystem, EndFrameBarrier, IconCommandSystem from the World.
- Builds the m_MeetingGroup EntityQuery that selects entities with CoordinatedMeeting and CoordinatedMeetingAttendee, excluding Deleted and Temp.
-
Calls RequireForUpdate(m_MeetingGroup) so the system only runs when there are matching entities.
-
[Preserve] protected override void OnUpdate()
Creates and schedules MeetingJob: - Fills jobData fields by obtaining Entity/Component/Buffer handles via InternalCompilerInterface and the __TypeHandle.
- Sets RandomSeed.Next() and m_SimulationSystem.frameIndex on the job.
- Creates an EntityCommandBuffer.ParallelWriter from m_EndFrameBarrier and an IconCommandBuffer from m_IconCommandSystem.
- Schedules the job with JobChunkExtensions.ScheduleParallel over m_MeetingGroup and attaches the returned JobHandle to base.Dependency.
-
Calls m_EndFrameBarrier.AddJobHandleForProducer(base.Dependency) to ensure the barrier waits on the job before playing back commands.
-
protected override void OnCreateForCompiler()
Compiler-time helper: ensures __AssignQueries and type handles are prepared for the generated code paths. -
private void __AssignQueries(ref SystemState state)
Compiler-generated stub called by OnCreateForCompiler (empty in this decompiled form, used during code generation/compilation). -
(MeetingJob)
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Core per-chunk logic (Burst compiled). Summary of behavior per CoordinatedMeeting entity: - Loads CoordinatedMeeting component, PrefabRef (prefab), obtains the HaveCoordinatedMeetingData buffer from the prefab, and optional CalendarEventData.
- If the meeting is not Done, fetches the meeting data for the current phase.
- Iterates attendees in the CoordinatedMeetingAttendee buffer and:
- If any attendee is not a valid citizen, is moving away (CitizenFlags.MovingAwayReachOC), or has a HealthProblem, mark the meeting Done and break (cleanup).
- If the meeting targets EventTargetType.Couple (determined from CalendarEventData), verify all attendees belong to the same household; otherwise mark Done.
- Status transitions:
- Waiting: if a target building exists (m_Target != Entity.Null) → set status to Traveling.
- Traveling: check whether all attendees' CurrentBuilding equals the target building. If they have arrived:
- Add icon notification using m_IconCommandBuffer if meeting data has a notification.
- Set status to Attending and set phase end time to current simulation frame + a random delay between haveCoordinatedMeetingData.m_Delay.x and .y.
- Attending: while current frame <= phase end time, ensure attendees remain at the meeting building and are healthy / not moving away. If anyone leaves or time expires, advance phase:
- Increment m_Phase; if m_Phase >= number of phases in the prefab buffer → set status Done.
- Otherwise clear m_Target and set status Waiting.
- Done: add Deleted tag to the CoordinatedMeeting entity via the parallel command buffer, remove AttendingMeeting component from household entities and individual attendees where present (via command buffer), and stop tracking.
- Writes back modified CoordinatedMeeting components into chunk NativeArray when changed.
- Uses CommandBuffer.ParallelWriter for structural changes and IconCommandBuffer for icons.
Notes about safety and behavior: - MeetingJob is marked BurstCompile for performance. - Uses ComponentLookup/BufferLookup with isReadOnly where appropriate, and uses an EntityCommandBuffer.ParallelWriter for structural writes to be safe in parallel execution. - The job uses RandomSeed.Next() to compute per-meeting randomized phase durations. - If an attendee is a PropertyRenter (renter entity on a building), the target building is resolved to the actual property (PropertyRenter.m_Property). - The system clears AttendingMeeting marker components when meetings complete.
Usage Example
// Create a meeting entity so MeetingSystem can process it.
// Assumes entityManager, targetBuilding, meetingPrefab, and one or more citizenEntity are available.
Entity meeting = entityManager.CreateEntity();
// Add a CoordinatedMeeting that starts in Waiting and targets a building when set later
entityManager.AddComponentData(meeting, new CoordinatedMeeting {
m_Status = MeetingStatus.Waiting,
m_Phase = 0,
m_Target = Entity.Null, // set to a building entity when participants are assigned or when the meeting starts
m_PhaseEndTime = 0u
});
// Attach the prefab reference (meetingPrefab must have HaveCoordinatedMeetingData buffer)
entityManager.AddComponentData(meeting, new PrefabRef { m_Prefab = meetingPrefab });
// Add attendees buffer and one attendee
var attendees = entityManager.AddBuffer<CoordinatedMeetingAttendee>(meeting);
attendees.Add(new CoordinatedMeetingAttendee { m_Attendee = citizenEntity });
// The MeetingSystem (running every 16 frames) will process this entity once attendees arrive at the target
// and will manage status transitions, notifications and cleanup automatically.
Additional notes for modders: - To customize meeting behavior, edit the HaveCoordinatedMeetingData buffer on the meeting prefab (per-phase delays, notification entities, etc.) or CalendarEventData (target type like Couple). - The system removes AttendingMeeting components from attendees and households when a meeting finishes; ensure other systems that rely on that component handle its removal. - Because the job runs in Burst and uses parallel ECBs, structural changes are deferred and applied by the EndFrameBarrier after the job completes.