Game.Tools.GenerateWaterSourcesSystem
Assembly: Game
Namespace: Game.Tools
Type: public class
Base: GameSystemBase
Summary:
GenerateWaterSourcesSystem is an ECS system responsible for turning creation definitions that include water source definitions into actual water source entities. It queries for entities with CreationDefinition (and Updated) and any WaterSourceDefinition, then schedules a parallel IJobChunk (GenerateBrushesJob) to create water source entities using an EntityCommandBuffer provided by a ModificationBarrier. The created entities receive WaterSourceData and Transform components and, unless marked permanent, are given Temp and Hidden-related components to support temporary or selected brush behavior in the editor/tooling flow.
Fields
-
private ModificationBarrier1 m_ModificationBarrier
Used to obtain an EntityCommandBuffer (as a parallel writer) for safe structural changes from a job and to register job dependencies with the barrier so entity modifications are applied at the correct time. -
private EntityQuery m_DefinitionQuery
An EntityQuery that selects entities with CreationDefinition and Updated components and with any WaterSourceDefinition. This query is required for the system to run (RequireForUpdate is called with it). -
private EntityArchetype m_WaterSourceArchetype
Precomputed archetype for newly created water source entities. The archetype includes WaterSourceData, Transform, Temp, Created, and Updated components. -
private TypeHandle __TypeHandle
A struct used to cache ComponentTypeHandle instances for CreationDefinition and WaterSourceDefinition so the job can access component arrays efficiently. -
private struct GenerateBrushesJob
(nested)
IJobChunk implementation that iterates matching chunks, reads CreationDefinition and WaterSourceDefinition arrays, and issues commands to create water source entities and set their components using the parallel EntityCommandBuffer. -
private struct TypeHandle
(nested)
Helper struct that holds ComponentTypeHandleand ComponentTypeHandle and provides a method to assign these handles from a SystemState.
Properties
- (none declared)
This system does not expose public properties. Internally it uses the cached TypeHandle struct and system state handles.
Constructors
public GenerateWaterSourcesSystem()
Default constructor preserved for ECS and codegen. No custom initialization is done here; runtime initialization occurs in OnCreate.
Methods
-
protected override void OnCreate()
Initializes the system: obtains the ModificationBarrier1 system from the world, constructs the EntityQuery (requiring CreationDefinition and Updated, and any WaterSourceDefinition), creates the archetype for water source entities (WaterSourceData, Transform, Temp, Created, Updated), and calls RequireForUpdate with the query so the system only runs when there are matching definitions. -
protected override void OnUpdate()
Builds and schedules the GenerateBrushesJob with: - ComponentTypeHandles retrieved via InternalCompilerInterface from the cached __TypeHandle,
- the prebuilt water source archetype,
-
and an EntityCommandBuffer.ParallelWriter from the modification barrier. The job is scheduled in parallel against m_DefinitionQuery, the system's Dependency is set to the returned JobHandle, and that handle is added to the modification barrier via AddJobHandleForProducer so structural changes are synchronized.
-
private void __AssignQueries(ref SystemState state)
Method generated for compiler support; currently creates and disposes an EntityQueryBuilder(Allocator.Temp). It exists to satisfy compiler/codegen scaffolding. -
protected override void OnCreateForCompiler()
Called as part of generated/compiler-time initialization. Invokes __AssignQueries and assigns component type handles into __TypeHandle using the provided SystemState reference. -
(GenerateBrushesJob)
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
For each chunk, obtains native arrays for CreationDefinition and WaterSourceDefinition, then iterates entries to: - Create a new entity with the water source archetype,
- Set WaterSourceData from the WaterSourceDefinition values (m_ConstantDepth, m_Amount, m_Radius, m_Multiplier, m_Polluted),
- Set Transform component with position from the definition and identity rotation,
- If the CreationDefinition is not Permanent, add a Temp component to the created entity (setting flags Select/Dragging depending on CreationFlags), and add a Hidden component to the original CreationDefinition.m_Original entity. This method is invoked via the IJobChunk interface and runs in parallel for chunks.
Usage Example
// Example: create an entity that will be processed by GenerateWaterSourcesSystem.
// This would typically be done by some editor/tool that constructs CreationDefinition + WaterSourceDefinition.
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
// create an entity archetype for the definition (simplified)
var defArchetype = entityManager.CreateArchetype(
typeof(CreationDefinition),
typeof(WaterSourceDefinition),
typeof(Updated)
);
Entity defEntity = entityManager.CreateEntity(defArchetype);
// populate components (pseudo-code fields)
entityManager.SetComponentData(defEntity, new CreationDefinition {
m_Original = someOriginalEntity,
m_Flags = CreationFlags.Select // or 0, or CreationFlags.Permanent
});
entityManager.SetComponentData(defEntity, new WaterSourceDefinition {
m_Position = new float3(100f, 0f, 200f),
m_Radius = 15f,
m_Amount = 1f,
m_Multiplier = 1f,
m_ConstantDepth = false,
m_Polluted = false
});
// Mark Updated so GenerateWaterSourcesSystem will process this definition on next update
entityManager.AddComponentData(defEntity, new Updated());
Notes and implementation details: - The system leverages a ModificationBarrier1 to perform structural changes (entity creation and component addition) from a job via an EntityCommandBuffer.ParallelWriter and to correctly synchronize job dependencies. - The job reads CreationDefinition and WaterSourceDefinition as read-only ComponentTypeHandles; these handles are cached via the generated TypeHandle and assigned in OnCreateForCompiler. - Temporary behavior: if a CreationDefinition is not marked Permanent, the created water source entity gets a Temp component (with Select/Dragging flags derived from CreationFlags) and the original entity referenced by CreationDefinition.m_Original receives a Hidden component to hide the definition in the editor while the temporary is active.