using Sandbox.Utility; namespace Sandbox; /// /// Updates interpolation for any that needs it. /// [Expose] sealed class InterpolationSystem : GameObjectSystem { HashSetEx _list { get; set; } = new(); [ConVar( "debug_interp", ConVarFlags.Protected )] static bool Debug { get; set; } public InterpolationSystem( Scene scene ) : base( scene ) { Listen( Stage.Interpolation, -1, Update, "UpdateInterpolation" ); } /// /// Add a to the interpolation list. /// internal void AddGameObject( GameObject go ) { _list.Add( go ); } /// /// Remove a from the interpolation list. /// internal void RemoveGameObject( GameObject go ) { _list.Remove( go ); } private void Update() { foreach ( var go in _list.EnumerateLocked( true ) ) { if ( go.IsValid() ) { go.Transform.Update(); if ( Debug ) { DrawDebug( go ); } } } } private void DrawDebug( GameObject go ) { using var _ = Gizmo.Scope(); var targetWorld = go.WorldTransform; var world = go.Transform.InterpolatedWorld; Gizmo.Draw.Color = Color.White; Gizmo.Draw.LineSphere( world.Position, 16f ); Gizmo.Draw.Color = Color.Cyan; Gizmo.Draw.LineSphere( targetWorld.Position, 16f ); } }