Skip to content

Conversation

@belplaton
Copy link
Contributor

P.S. The source files have been sent in a private message.

Collider Rollback: execution refactor (single-thread → jobified + deferred)

This PR changes the execution model of collider rollback to a jobified pipeline and adds a deferred rollback path which is executed on a chosen tick phase.

What changed

  • RollbackManager now owns a RollbackCollection which stores rollback state in job-friendly native containers and drives snapshot/rollback/return via jobs.
  • Snapshot generation is driven from TimeManager:
    • OnPostTick: always creates snapshots.
    • OnPreTick / OnTick / OnPostTick: optionally executes deferred rollback depending on _deferredRollbackOrder (PreTick, Tick, PostTick).

Multithreading approach used

  • Transforms are processed through TransformAccessArray and IJobParallelForTransform:
    • _colliderRollbacksTAA: one entry per ColliderRollback root.
    • _rollingCollidersTAA: flattened list of all rolling collider transforms across all ColliderRollback instances.
  • Snapshot history is stored as a ring buffer per rolling collider:
    • _rollingCollidersSnapshots is a flattened ring [rollingColliderIdx * MaxSnapshots + frame].
    • _rollingCollidersWriteIndices stores per-rolling write pointers.
  • A group-level rolled-back mask is maintained (_colliderRollbacksRolledBackMask) to:
    • Freeze snapshot capture for rolled-back groups.
    • Avoid repeated rollback application for the same group in a single pass.

Snapshot pipeline (job chain)

  • CreateSnapshots() schedules and completes:
    1. IncrementGroupsFramesJob (IJobParallelFor) – increments available history frames per group (saturates at MaxSnapshots) if not rolled back.
    2. PopulateColliderRollbackSnapshotsJob (IJobParallelForTransform) – captures TRS snapshot for each ColliderRollback root.
    3. PopulateRollingColliderSnapshotsJob (IJobParallelForTransform) – writes rolling collider TRS into the per-collider ring buffer.

Rollback execution (jobified)

  • Rollback all (per scene/time): ApplyRollbackJob runs over _rollingCollidersTAA and applies the correct snapshot (lerp/exact) for each rolling collider.
  • Rollback by ray request: ApplyRollbackRaycastJob runs over _rollingCollidersTAA and filters targets by:
    • Scene handle (optional)
    • Requested RollbackPhysicsType
    • Ray vs OBB test computed in the job (no physics queries)
    • On hit, applies rollback for the rolling collider and marks the group as rolled back.

Deferred rollback execution (jobified, two-stage)

  • Requests are appended to a write buffer (_writeRequests), then processed in batches by swapping buffers ((_readRequests, _writeRequests) = ...) to avoid mutation during processing.
  • RollbackDeferred() schedules and completes:
    1. ComputeDeferredRollbackSumsJob (IJobParallelFor, one iteration per group) – iterates all requests (typically small) and computes per-group sumDecimalFrame and hitCount for requests whose rays hit the group OBB.
    2. ApplyDeferredRollbackJob (IJobParallelForTransform) – applies rollback to rolling colliders using the per-group averaged decimal frame (sum / count).

Return execution (jobified)

  • ReturnRollbackAllJob (IJobParallelForTransform) restores each rolling collider to the most recent snapshot and clears the group rolled-back mask.

Data / API changes

  • Added RollbackManager.RollbackRequest (stores scene handle, ray data, rollback time, physics type) and RollbackManager.DeferredRollbackOrder.
  • Added RollbackManager.OnRollbackDeferred event and RequestRollbackDeferred(...) + RollbackDeferred() methods.
  • Bounding box filtering is now handled via per-group BoundingBoxData (OBB parameters) and math ray tests inside jobs (instead of relying on a bounding-box layer check).

Files

  • Added: Assets/FishNet/Runtime/Plugins/ColliderRollback/Scripts/RollbackCollection.cs
  • Added: Assets/FishNet/Runtime/Plugins/ColliderRollback/Scripts/ColliderSnapshot.cs
  • Added/expanded: Assets/FishNet/Runtime/Plugins/ColliderRollback/Scripts/RollbackManager.Types.cs (jobs + OBB/raycast helpers)
  • Updated: Assets/FishNet/Runtime/Plugins/ColliderRollback/Scripts/RollbackManager.cs, ColliderRollback.cs, ColliderRollbackEditor.cs
  • Removed: Assets/FishNet/Runtime/Plugins/ColliderRollback/Scripts/ColliderRollback.Types.cs

The source files have been sent in a private message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant