Class LagCompensationRegistry
Server-side registry of CharacterPositionHistory, and the scoped rewind that resolves a hit against where characters were rather than where they are.
public static class LagCompensationRegistry
- Inheritance
-
LagCompensationRegistry
- Inherited Members
Remarks
How to use it. Wrap a spatial query in a using block. The scope displaces every eligible character in the scene, keeps them displaced for the body, and puts them back on dispose — including when the body throws, which is the whole reason it is a scope rather than a pair of calls.
using (LagCompensationRegistry.Rewind(scene, target, caster))
{
hitCount = physicsScene.OverlapSphere(center, radius, hits, mask, QueryTriggerInteraction.UseGlobal);
}
Scene-scoped on purpose. Characters are indexed by scene handle because each scene runs its own UnityEngine.PhysicsScene. Rewinding every character on the server for a query that can only hit one scene would be both wasteful and wrong.
The caster is never rewound. A shooter aims from where it is now, not where it was, so displacing it would move the origin of its own query.
Methods
RegisteredIn(Scene)
Number of characters registered in a scene. For diagnostics and tests.
public static int RegisteredIn(Scene scene)
Parameters
sceneScene
Returns
Rewind(Scene, RewindTarget, ICharacter)
Displaces every character in scene to where it was at
tick, until the returned scope is disposed.
public static LagCompensationRegistry.RewindScope Rewind(Scene scene, RewindTarget target, ICharacter exclude = null)
Parameters
sceneSceneScene whose characters should be rewound.
targetRewindTargetexcludeICharacterCharacter to leave in place — normally the caster.