Game.Events.EventJournalInitializeSystem
Assembly: Game
Namespace: Game.Events
Type: class
Base: GameSystemBase
Summary: Initializes journal entries for newly created in-game events. This system queries for entities that have Event + Created + PrefabRef and that do not have Deleted/Temp, then creates an EventJournalEntry entity for each event. It attaches JournalEvent to the original event entity (pointing to the created journal entry) and, when the event prefab declares tracked data/effects, it initializes dynamic buffers on the journal entry to store those tracked values. The work is performed in a parallel IJobChunk (Burst-compiled) and uses a ModificationBarrier4 command buffer to safely create entities/components from jobs.
Fields
-
private EntityQuery m_CreatedEventQuery
Query selecting created Event entities with a PrefabRef and without Deleted/Temp. Used as the input query for the job that creates journal entries. -
private EntityArchetype m_EventJournalArchetype
Archetype describing the EventJournalEntry entity (includes EventJournalEntry, Created, PrefabRef). Used when creating journal entry entities. -
private ModificationBarrier4 m_ModificationBarrier
Barrier system used to obtain an EntityCommandBuffer.ParallelWriter so entity/component creation and modification can be scheduled from the parallel job and applied safely. -
private TypeHandle __TypeHandle
Generated struct that stores EntityTypeHandle, ComponentTypeHandles, and ComponentLookup instances required by the job. Initialized in OnCreateForCompiler. -
Nested (private) types of interest:
InitEventJournalEntriesJob
(Burst-compiled struct implementing IJobChunk)
Job that iterates chunks of created Event entities, creates journal entries, sets JournalEvent on the source event, and initializes optional EventJournalData/EventJournalCityEffect buffers based on JournalEventPrefabData on the event prefab.TypeHandle
(helper struct)
Holds handles/lookups and provides an __AssignHandles method to bind them to the SystemState.
Properties
- (none public)
This system exposes no public properties.
Constructors
public EventJournalInitializeSystem()
Default constructor. Marked with [Preserve]. Standard system construction; most initialization occurs in OnCreate.
Methods
-
protected override void OnCreate()
Creates the m_CreatedEventQuery (Event + Created + PrefabRef + JournalEvent, excluding Deleted/Temp), creates the event journal archetype (EventJournalEntry, Created, PrefabRef), acquires the ModificationBarrier4 system, and calls RequireForUpdate(m_CreatedEventQuery) so the system runs only when matching entities exist. -
protected override void OnUpdate()
Builds an InitEventJournalEntriesJob, populating it with: - EntityTypeHandle, ComponentTypeHandle
, ComponentTypeHandle (read-only), - ComponentLookup
(read-only), - the journal archetype,
-
and a parallel command buffer from m_ModificationBarrier. The job is scheduled in parallel over m_CreatedEventQuery; the system updates its dependency and registers the job handle with the modification barrier.
-
protected override void OnCreateForCompiler()
Compiler/IL generation helper that calls __AssignQueries and binds the type handles via __TypeHandle.__AssignHandles. Present to satisfy generated code patterns. -
private void __AssignQueries(ref SystemState state)
Generated placeholder that can be used to create and assign queries during code generation/compilation. Implementation here simply constructs and disposes an EntityQueryBuilder(Allocator.Temp). -
InitEventJournalEntriesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
For each event entity in the chunk: - Reads the PrefabRef (event prefab) and (if present) the Duration component.
- Creates a new journal entry entity using CreateJournalEntry.
- Sets JournalEvent on the source event to reference the created journal entity.
-
If Duration exists, also adds EventJournalPending with the start frame to the created journal entry. The job runs in parallel and uses the command buffer's ParallelWriter methods (CreateEntity, SetComponent, AddComponent, AddBuffer).
-
InitEventJournalEntriesJob.CreateJournalEntry(Entity eventEntity, Entity eventPrefab, int chunkIndex) : Entity
Creates an entity with m_JournalArchetype, sets its EventJournalEntry.m_Event and PrefabRef.m_Prefab, reads JournalEventPrefabData for the event prefab, and if the prefab data indicates tracked data/effects, adds and initializes DynamicBuffers EventJournalData and EventJournalCityEffect by calling InitDataBuffer / InitEffectBuffer. Returns the created journal entity. -
InitEventJournalEntriesJob.InitDataBuffer(DynamicBuffer
datas, int dataFlags)
Initializes EventJournalData buffer entries according to the bitflags in dataFlags. Iterates possible data types (3 types) and adds entries with m_Value = 0. -
InitEventJournalEntriesJob.InitEffectBuffer(DynamicBuffer
effects, int effectFlags)
Initializes EventJournalCityEffect buffer entries according to effectFlags. Iterates possible effect types (5 types) and adds entries with m_StartValue = 0 and m_Value = 0. -
(explicit interface impl) IJobChunk.Execute forwards to the job's Execute method.
Usage Example
// The system is registered/created by the World and runs automatically.
// Example showing how a newly created Event entity will get a journal entry:
// Create an event entity elsewhere (example)
Entity eventEntity = entityManager.CreateEntity(eventPrefabArchetype);
entityManager.AddComponentData(eventEntity, new Event { /* ... */ });
entityManager.AddComponentData(eventEntity, new Created());
entityManager.AddComponentData(eventEntity, new PrefabRef { m_Prefab = someEventPrefab });
// When EventJournalInitializeSystem runs (OnUpdate), it will:
// - create an EventJournalEntry entity linked to the eventEntity
// - set JournalEvent on the eventEntity to reference the created journal
// - add buffers EventJournalData or EventJournalCityEffect to the journal entity
// if the event prefab's JournalEventPrefabData declares tracked data/effects.
Notes: - The heavy lifting is done inside a Burst-compiled IJobChunk for performance and to allow parallel scheduling. - The system relies on JournalEventPrefabData (read via ComponentLookup) on the event prefab to determine which buffers to allocate and initialize on the journal entry.