Skip to content

Game.Simulation.WatercraftMoveSystem

Assembly:
Assembly-CSharp (inferred)

Namespace:
Game.Simulation

Type:
class

Base:
GameSystemBase

Summary:
System responsible for moving/positioning watercraft (ships) each simulation tick. It queries entities with Watercraft, WatercraftNavigation and transform-related components, then schedules a Burst-compiled IJobChunk (UpdateTransformDataJob) that computes per-boat velocities, angular velocities and new transforms based on navigation targets, prefab geometry and sampled water surface/terrain heights. The system reads water surface and terrain height data via WaterSystem and TerrainSystem and writes Transform, Moving and TransformFrame buffers. The job updates a rolling transform-frame buffer index driven by the simulation frame index.


Fields

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem used to obtain the current frame index and coordinate job timing with the main simulation.

  • private TerrainSystem m_TerrainSystem
    Reference to the TerrainSystem used to obtain CPU-accessible terrain height data for water/boat sampling.

  • private WaterSystem m_WaterSystem
    Reference to the WaterSystem used to obtain the current water surface data (waves, height) necessary to position watercraft on the water.

  • private EntityQuery m_WatercraftQuery
    EntityQuery that matches watercraft entities. Built to include components: Watercraft, WatercraftNavigation, UpdateFrame and read/write Transform, Moving and TransformFrame buffers; excludes Deleted, Temp and TripSource.

  • private TypeHandle __TypeHandle
    Container of ComponentTypeHandle/ComponentLookup/BufferTypeHandle used to cache handles for the UpdateTransformDataJob. Assigned in OnCreateForCompiler/__AssignHandles.

Nested Types

  • public struct UpdateTransformDataJob : IJobChunk
    Burst-compiled IJobChunk that performs the majority of per-entity movement logic. Reads navigation, current lane, prefab references and lookup data (ObjectGeometryData, WatercraftData) plus terrain/water data; writes Moving, Transform and TransformFrame buffers. It:
  • Computes ship pivot offsets from prefab geometry to determine turning pivots.
  • Blends between navigation target direction and current velocity, applying turning limits from WatercraftData.
  • Resets rotation/angle in special lane states (ResetSpeed/Connection).
  • Samples water heights at four corner offsets (based on prefab bounds) and computes a smoothed position.y and rotation based on sampled surface normal.
  • Writes a mid-point TransformFrame into a TransformFrame buffer at the index derived from SimulationSystem.frameIndex.

Important fields: - m_TransformFrameIndex (uint, read-only): index into TransformFrame circular buffer (0..3). - m_NavigationType, m_CurrentLaneType, m_PrefabRefType (ComponentTypeHandle, read-only): component handles for chunk access. - m_PrefabGeometryData, m_PrefabWatercraftData (ComponentLookup, read-only): lookups for prefab-specific geometry and movement parameters. - m_TerrainHeightData, m_WaterSurfaceData (by-value data): used for SampleWater computations. - m_MovingType, m_TransformType, m_TransformFrameType (handles): write handles for Moving, Transform and TransformFrame buffer.

Key methods: - Execute(ArchetypeChunk, int, bool, v128): main chunk processing loop that updates all watercraft in the chunk. - SampleWater(ref float3 position, ref quaternion rotation, ObjectGeometryData prefabGeometryData): samples water and terrain at four corners around the craft, clamps heights against hull, computes averaged position.y and an orientation aligned to the water surface.

  • private struct TypeHandle
    Small helper struct that stores ComponentTypeHandle/ComponentLookup/BufferTypeHandle instances and provides __AssignHandles(ref SystemState) to populate them from the SystemState. Used to prepare handles for the job.

Properties

None (no public properties exposed by this system).

Constructors

  • public WatercraftMoveSystem()
    Default constructor preserves the system. Initialization of systems and queries is done in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase) : System.Int32
    Returns the update interval for this system. Implementation returns 16 (system ticks), meaning the system runs every 16 simulation ticks.

  • public override int GetUpdateOffset(SystemUpdatePhase phase) : System.Int32
    Returns the update offset for this system. Implementation returns 8, used together with interval to stagger execution across phases/frames.

  • [Preserve] protected override void OnCreate() : System.Void
    Called when the system is created. Obtains references to SimulationSystem, TerrainSystem and WaterSystem via World.GetOrCreateSystemManaged<...>() and builds the m_WatercraftQuery with the appropriate included/excluded component types. Calls RequireForUpdate(m_WatercraftQuery) so the system only runs when matching entities exist.

  • [Preserve] protected override void OnUpdate() : System.Void
    Creates and schedules UpdateTransformDataJob:

  • Computes m_TransformFrameIndex = m_SimulationSystem.frameIndex / 16 % 4 to determine which transform frame slot to write.
  • Fills job handles and lookups using InternalCompilerInterface.GetComponentTypeHandle / GetComponentLookup and obtains terrain/water data from TerrainSystem/GetHeightData and WaterSystem/GetSurfaceData (the latter returns a JobHandle dependency).
  • Schedules the job with JobChunkExtensions.ScheduleParallel and combines dependencies. Registers CPU readers with TerrainSystem.AddCPUHeightReader and WaterSystem.AddSurfaceReader to track asynchronous reads.

  • private void __AssignQueries(ref SystemState state) : System.Void
    Method used during compilation pipeline to assign any additional queries; currently contains a no-op builder but is invoked from OnCreateForCompiler.

  • protected override void OnCreateForCompiler() : System.Void
    Compiler-time initialization helper: calls __AssignQueries and __TypeHandle.__AssignHandles to prime the TypeHandle for the job.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    (Internal helper used by OnCreateForCompiler; present for generated/compiled pipeline support.)

Usage Example

// Get or create the system from the game's World and read its update interval
var world = World.DefaultGameObjectInjectionWorld;
var watercraftMoveSystem = world.GetOrCreateSystemManaged<Game.Simulation.WatercraftMoveSystem>();
int interval = watercraftMoveSystem.GetUpdateInterval(SystemUpdatePhase.Simulation);

// NOTE: The system schedules its own Burst job to update watercraft transforms.
// To observe or modify behavior you typically:
// - Add/modify WatercraftNavigation or WatercraftCurrentLane components on entities
// - Adjust prefab WatercraftData/ObjectGeometryData assets used by PrefabRef
// - Or create a separate system that runs before/after to inject data.