Skip to content

Game.Rendering.EventInterpolateSystem

Assembly:
Game

Namespace:
Game.Rendering

Type:
class

Base:
GameSystemBase

Summary:
EventInterpolateSystem is a Unity ECS system used by the game to interpolate transform data for event "hotspots" (e.g. WeatherPhenomenon). It reads per-entity HotspotFrame buffers (past/future samples) and writes an InterpolatedTransform component using a cubic Bezier interpolation based on the current rendering frame index/time. The system schedules a Burst-compiled IJobChunk (UpdateTransformDataJob) to perform the interpolation in parallel for matching entities. It depends on RenderingSystem.frameIndex and frameTime and uses an EntityQuery filtering WeatherPhenomenon + HotspotFrame + InterpolatedTransform (excludes Deleted and Temp).


Fields

  • private RenderingSystem m_RenderingSystem
    Used to access runtime rendering information (frameIndex and frameTime). Acquired in OnCreate via base.World.GetOrCreateSystemManaged().

  • private EntityQuery m_EventQuery
    The EntityQuery that selects entities to process. It includes ReadOnly, ReadOnly (buffer), ReadWrite and excludes Deleted and Temp. The query is used to schedule the UpdateTransformDataJob.

  • private TypeHandle __TypeHandle
    A private helper struct instance that stores BufferTypeHandle and ComponentTypeHandle used when scheduling and running the job. __TypeHandle.__AssignHandles(ref state) initializes the handles from the SystemState.

Properties

  • None (no public properties exposed by this system).

Constructors

  • public EventInterpolateSystem()
    Default constructor marked with [Preserve]. It performs no custom work; initialization occurs in OnCreate/OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains the RenderingSystem reference, creates the EntityQuery (m_EventQuery) selecting WeatherPhenomenon/HotspotFrame/InterpolatedTransform and excludes Deleted/Temp, and calls RequireForUpdate(m_EventQuery) so the system only runs when matching entities exist.

  • protected override void OnUpdate()
    Creates and configures an UpdateTransformDataJob instance with values from m_RenderingSystem and type handles (via InternalCompilerInterface.GetBufferTypeHandle / GetComponentTypeHandle), then schedules it with JobChunkExtensions.ScheduleParallel using m_EventQuery and the current dependency. The scheduled job performs the per-chunk interpolation work.

  • protected override void OnCreateForCompiler()
    Called by compiler-friendly initialization: assigns queries and initializes type handles by calling __AssignQueries and __TypeHandle.__AssignHandles using base.CheckedStateRef.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    A small helper used during compiler initialization; in this compiled form it constructs and immediately disposes an EntityQueryBuilder(Allocator.Temp). In source terms this ensures query-related initialization paths are emitted for the system.

  • private struct TypeHandle
    Nested struct holding:

  • BufferTypeHandle<HotspotFrame> __Game_Events_HotspotFrame_RO_BufferTypeHandle (read-only)
  • ComponentTypeHandle<InterpolatedTransform> __Game_Rendering_InterpolatedTransform_RW_ComponentTypeHandle (read/write) It has a method __AssignHandles(ref SystemState state) that gets the appropriate handles from the provided SystemState.

  • private struct UpdateTransformDataJob : IJobChunk (Burst-compiled)
    Job fields:

  • [ReadOnly] public uint m_FrameIndex — current rendering frame index
  • [ReadOnly] public float m_FrameTime — current frame fractional time
  • [ReadOnly] public BufferTypeHandle<HotspotFrame> m_HotspotFrameType — buffer handle to read HotspotFrame samples
  • public ComponentTypeHandle<InterpolatedTransform> m_InterpolatedTransformType — component handle to write InterpolatedTransform

Execute(in ArchetypeChunk chunk, ...) behavior: - Computes indices into a 4-sample circular buffer based on m_FrameIndex (uses a fixed lookback of 32 frames and assumes 16-frame sample stride). - Computes normalized t in [0,1] from frame remainder and frameTime. - For each entity in the chunk: - Reads the HotspotFrame samples at two indices (current and next) from the DynamicBuffer. - Constructs a cubic Bezier (Bezier4x3) using positions and velocities (positions are offset by velocity * (4f/45f) to form control points). - Computes the interpolated position via MathUtils.Position(curve, t). - Sets rotation to quaternion.identity (no rotation interpolation here). - Writes the InterpolatedTransform back to the chunk's component array. - The job implements IJobChunk.Execute and forwards to the strongly-typed Execute method. It is marked with [BurstCompile].

Notes about interpolation logic: - The job assumes HotspotFrame buffer has at least 4 samples and that frames are sampled every 16 frames. - It uses a small time offset multiplier (4f/45f) to generate cubic control points from positions and velocities. - The result is a smoothly interpolated position across frames; rotation is left as identity.

Usage Example

[Preserve]
protected override void OnUpdate()
{
    // Prepare job data from rendering system and cached type handles
    UpdateTransformDataJob jobData = new UpdateTransformDataJob
    {
        m_FrameIndex = m_RenderingSystem.frameIndex,
        m_FrameTime = m_RenderingSystem.frameTime,
        m_HotspotFrameType = InternalCompilerInterface.GetBufferTypeHandle(
            ref __TypeHandle.__Game_Events_HotspotFrame_RO_BufferTypeHandle, ref base.CheckedStateRef),
        m_InterpolatedTransformType = InternalCompilerInterface.GetComponentTypeHandle(
            ref __TypeHandle.__Game_Rendering_InterpolatedTransform_RW_ComponentTypeHandle, ref base.CheckedStateRef)
    };

    // Schedule the chunk job to run in parallel over m_EventQuery
    base.Dependency = JobChunkExtensions.ScheduleParallel(jobData, m_EventQuery, base.Dependency);
}

{{ Additional notes: - This system is designed for the game's rendering/update loop: it relies on RenderingSystem to provide frame timing information. - If you extend or modify HotspotFrame or InterpolatedTransform, keep the buffer layout and expected sample count/indices in mind. - The BurstCompile attribute and use of IJobChunk require that types used in the job are blittable and supported by Burst. }}