FishNet
FishNet copied to clipboard
feat: make rollback jobified
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
RollbackManagernow owns aRollbackCollectionwhich 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
TransformAccessArrayandIJobParallelForTransform:_colliderRollbacksTAA: one entry perColliderRollbackroot._rollingCollidersTAA: flattened list of all rolling collider transforms across allColliderRollbackinstances.
- Snapshot history is stored as a ring buffer per rolling collider:
_rollingCollidersSnapshotsis a flattened ring[rollingColliderIdx * MaxSnapshots + frame]._rollingCollidersWriteIndicesstores 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:IncrementGroupsFramesJob(IJobParallelFor) – increments available history frames per group (saturates atMaxSnapshots) if not rolled back.PopulateColliderRollbackSnapshotsJob(IJobParallelForTransform) – captures TRS snapshot for eachColliderRollbackroot.PopulateRollingColliderSnapshotsJob(IJobParallelForTransform) – writes rolling collider TRS into the per-collider ring buffer.
Rollback execution (jobified)
- Rollback all (per scene/time):
ApplyRollbackJobruns over_rollingCollidersTAAand applies the correct snapshot (lerp/exact) for each rolling collider. - Rollback by ray request:
ApplyRollbackRaycastJobruns over_rollingCollidersTAAand 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:ComputeDeferredRollbackSumsJob(IJobParallelFor, one iteration per group) – iterates all requests (typically small) and computes per-groupsumDecimalFrameandhitCountfor requests whose rays hit the group OBB.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) andRollbackManager.DeferredRollbackOrder. - Added
RollbackManager.OnRollbackDeferredevent andRequestRollbackDeferred(...)+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