Game.Simulation.TouristHouseholdBehaviorSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
This system runs periodically (every 64 simulation frames according to GetUpdateInterval) to manage the state of tourist household entities. Its main responsibilities:
- Validate and clean up Target components pointing to buildings that no longer exist.
- Ensure TouristHousehold entities are tracked as lodging seekers (add LodgingSeeker) when appropriate.
- Validate and clear a TouristHousehold's hotel reference if the referenced building's Renter buffer no longer contains the household entity.
- Performs its changes using an EndFrameBarrier command buffer (parallel writer) so modifications are deferred and safe for multi-threaded jobs.
Fields
-
private EntityQuery m_TouristHouseholdGroup
This query targets TouristHousehold entities with an UpdateFrame and excludes MovingAway, Deleted and Temp. The system uses it to schedule the job over relevant entities. -
private SimulationSystem m_SimulationSystem
Cached reference to the SimulationSystem used to read the global frameIndex to compute the update frame for the job scheduling. -
private EndFrameBarrier m_EndFrameBarrier
Barrier used to create an EntityCommandBuffer (as a ParallelWriter) to add/remove components (for example add LodgingSeeker or remove Target) at a safe point after the job completes. -
private TypeHandle __TypeHandle
Generated internal container holding all Entity/Component type handles used by jobs and helper methods. It's assigned on compiler-time initialization.
Properties
- None (the class exposes no public properties).
Note: the nested job struct and nested TypeHandle contain many public/readonly fields used by the job; these are not exposed as system properties.
Constructors
public TouristHouseholdBehaviorSystem()
Default constructor (marked [Preserve] for IL2CPP/code stripping). Typical systems created by the world use this; initialization occurs in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the interval at which the system prefers to run. This system returns 64 which means it updates every 64 simulation frames (subject to scheduling logic used by SimulationUtils). -
[Preserve] protected override void OnCreate()
Initializes the system: - Acquires references to SimulationSystem and EndFrameBarrier from the World.
- Creates the m_TouristHouseholdGroup entity query (TouristHousehold + UpdateFrame, excluding MovingAway/Deleted/Temp).
-
Calls RequireForUpdate with the query so the system will only run when matching entities exist.
-
[Preserve] protected override void OnUpdate()
Computes the update frame to run on using SimulationUtils.GetUpdateFrameWithInterval and schedules TouristHouseholdTickJob (a parallel IJobChunk) over m_TouristHouseholdGroup. It fills the job data with the appropriate Entity/Component/Buffer lookups and passes a command buffer (EndFrameBarrier.CreateCommandBuffer().AsParallelWriter()). After scheduling, it adds the returned JobHandle to the EndFrameBarrier via AddJobHandleForProducer. -
protected override void OnCreateForCompiler()
Compiler-time helper to assign queries and type handles used by generated code. Internal initialization path used by the DOTS codegen. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Generated helper (currently a no-op except for a temp EntityQueryBuilder dispose); used by compiler flow to ensure queries are assigned when building with generated code.
Nested / Job-related methods (high-level descriptions)
- TouristHouseholdTickJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : void
The chunk job that implements the per-chunk logic: - Skips chunks whose UpdateFrame shared component index does not match the computed m_UpdateFrameIndex.
-
Iterates entities in the chunk; for each entity:
- If the entity has a Target component and the target entity either is Entity.Null or no longer has a Building component, the Target component is removed via the command buffer.
- If the entity is not already a LodgingSeeker, the job checks the TouristHousehold.m_Hotel reference:
- If m_Hotel is Entity.Null, or the hotel entity has no Renter buffer, clear m_Hotel.
- Otherwise check the Renter buffer to see if the household is still listed as a renter; if not, clear m_Hotel.
- Finally, adds a LodgingSeeker component to the tourist household (via command buffer) so other systems can handle lodging logic.
-
TouristHouseholdTickJob.IJobChunk.Execute wrapper
Explicit interface implementation that forwards to the strongly-typed Execute method. -
TypeHandle.__AssignHandles(ref SystemState state)
Assigns the concrete EntityTypeHandle, ComponentTypeHandle, SharedComponentTypeHandle, ComponentLookup, and BufferLookup instances used by the job. This is an internally-generated helper and is called during system initialization.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// This system already sets up its query and barrier; if you need to
// cooperate with it you can get references similarly:
var sim = World.GetOrCreateSystemManaged<SimulationSystem>();
var barrier = World.GetOrCreateSystemManaged<EndFrameBarrier>();
// Example: schedule your job to run in same rhythm (compute update frame)
uint updateFrameWithInterval = SimulationUtils.GetUpdateFrameWithInterval(
sim.frameIndex,
(uint)this.GetUpdateInterval(SystemUpdatePhase.GameSimulation),
16);
// Or, if you need to add/remove components from within a job,
// use the barrier's command buffer like this:
var ecb = barrier.CreateCommandBuffer().AsParallelWriter();
// ecb can be used inside a parallel job to add/remove components safely.
}
Notes and implementation details: - The system is built to work with Unity DOTS (Entities IJobChunk) and uses parallel chunk scheduling. - Mutations are performed via an EndFrameBarrier command buffer to defer structural changes until it is safe. - It relies on shared UpdateFrame to ensure work is distributed across frames instead of running on every frame for all entities.