Skip to content
CVL COREUnity SDK : Zero-Allocation Client

Client Prediction, Interpolation & Presentation Smoothing (Unity SDK)

[SPECIFICATION] Presentation Smoothing & Metabolic Profiling Invariant

The CVL CORE Presentation Smoothing & Metabolic Profiling Suite governs remote entity trajectory reconstruction, hierarchical vehicle parenting, screen-space UI isolation, and zero-allocation frame auditing within the Unity client runtime. By pairing an 8-slot 133 ms historical snapshot ring buffer with speed-free dead reckoning, ghost PhysX stripping, and sub-canvas UI pooling, the presentation bridge renders a 500-entity unculled hotspot baseline at native monitor refresh rates with a verified 0 B/frame managed garbage collection footprint.


[SEC 01.0] Executive Architecture & Subsystem Topology

Section titled “[SEC 01.0] Executive Architecture & Subsystem Topology”

Because the Authoritative Spatial Micro-Kernel conflates internal 30Hz physics sweeps into a 15Hz outbound kinematic broadcast (66.6 ms packet interval) to halve network egress bandwidth, naive client rendering would produce visible transform stepping or stutter during TCP packet clumping. The CVL CORE Presentation Bridge eliminates network micro-jitter by decoupling visual proxy rendering from raw socket arrival times.

[RING BUFFER] The 133ms Historical Snapshot Ring Buffer
Section titled “[RING BUFFER] The 133ms Historical Snapshot Ring Buffer”

Every networked proxy (CVLNetworkIdentity) maintains a pre-allocated, 8-slot circular snapshot buffer that stores confirmed server transforms alongside drift-aligned timestamps:

  • Synthesized Server-Tick Clock Alignment: Rather than trusting erratic OS socket arrival times directly, each inbound OP_BROADCAST header carries the authoritative 32-bit serverTick (30Hz base timebase, 0.0333333s step). On initial packet ingestion, the identity seeds a local-to-server clock offset and gently drift-aligns subsequent packets (0.005f interpolation weight), automatically re-anchoring if tick divergence exceeds 15 ticks or 0.5 seconds.
  • Adaptive Jitter Delay Floor (133 ms): During LateUpdate(), the proxy calculates its target playback delay behind the newest confirmed snapshot using smoothed 1.0Hz OP_PING telemetry: targetDelay = Max(0.133f, (CurrentPingMs + (CurrentJitterMs * 2.0f)) * 0.001f). Maintaining a minimum 133 ms floor guarantees at least two complete 15Hz broadcast intervals remain buffered to absorb transient network jitter.
  • Elastic Playback Time-Scaling (0.92x to 1.08x): The proxy’s local render clock smoothly accelerates or decelerates relative to the ideal playback timestamp via timeScale = Clamp(1.0f + ((idealRenderTime - renderClock) * 0.5f), 0.92f, 1.08f), preventing abrupt visual time-warps while keeping the playback cursor centered inside the buffered window.
  • Left-Edge Starvation Clamping & NaN Safeguards: If the render clock falls behind or equals the oldest buffered snapshot timestamp, the proxy clamps firmly to the oldest confirmed transform; executing dead reckoning on the left edge is strictly prohibited. Furthermore, normalized blend factor calculations verify that the timestamp delta between bracketing snapshots is strictly > 0.001s to prevent division-by-zero NaN exceptions during clustered packet bursts.
[EXTRAPOLATION] Speed-Free Dead Reckoning & Kinetic Energy Bleed
Section titled “[EXTRAPOLATION] Speed-Free Dead Reckoning & Kinetic Energy Bleed”

When a remote proxy’s render clock outpaces the newest buffered snapshot during a packet stall (right-edge buffer starvation), extrapolating forward using quantized facing yaw causes proxies to veer into walls if the actor was strafing or turning. CVL CORE resolves right-edge starvation via Speed-Free Dead Reckoning:

  • Confirmed Displacement Vector Derivation: Trajectory direction is derived strictly from the normalized horizontal displacement vector between the two most recent confirmed server snapshots rather than orientation angles.
  • Half-RTT Horizon & Exponential Kinetic Bleed: The extrapolation window incorporates one-way wire transit latency (halfRttSeconds = CurrentPingMs * 0.5f * 0.001f) and caps maximum forward projection to 0.15 seconds. If the stall duration exceeds halfRttSeconds + 0.08f, horizontal speed decays exponentially (Lerp(smoothedSpeed, 0.0f, dt * 10.0f)), smoothly bleeding kinetic energy to park the proxy in place without overshooting obstacles.
  • Animator Hash Caching & Angular Deadbands: To avoid per-frame string hashing and orientation micro-tremors, CVLNetworkIdentity pre-caches Animator.StringToHash("Speed") and Animator.StringToHash("Stance"), gates SetFloat transitions behind a 0.05f velocity epsilon, and applies a 0.3-degree yaw noise floor.

[SEC 02.0] Concurrency & State Ownership / Lifecycle

Section titled “[SEC 02.0] Concurrency & State Ownership / Lifecycle”

All snapshot interpolation, hierarchical mount parenting, screen-space UI projection, and metabolic frame profiling execute deterministically on the Unity Main Thread across ordered [DefaultExecutionOrder] phases.

Architecture: 133ms Snapshot Ring Buffer & Right-Edge Kinetic Bleed Timeline
Historical Buffer Window (8-Slot Circular Ring per CVLNetworkIdentity)
===================================================================================
[Snap 0 (Oldest)] ------> [Snap 1] ------> [Snap 2] ------> [Snap 3 (Newest)]
| ^ |
| (Left-Edge Clamp: | | (Right-Edge Starvation:
| Zero Extrapolation) [Render Clock Cursor] | Speed-Free Dead Reckoning)
| |<--- >= 133ms --->| |
| Target Delay | +---> Project along (Snap2->Snap3)
| (0.92x..1.08x) | Cap <= 150ms & Bleed Speed
===================================================================================
Sub-Canvas Screen-Space Nameplate Isolation ([DefaultExecutionOrder(10 -> 200)])
+---------------------------------------------------------------------------------+
| Central Screen Space - Overlay Canvas (GraphicRaycaster Stripped) |
| |-- Pooled Nameplate [001] ---> Isolated Sub-Canvas (overrideSorting = false)|
| |-- Pooled Nameplate [002] ---> Isolated Sub-Canvas (raycastTarget = false) |
| +-- Sub-Pixel Motion Gate: (screenPos - lastPos).sqrMagnitude >= 0.0001f |
+---------------------------------------------------------------------------------+
[GHOST AUTHORITY] Remote Proxy Ghost Authority & PhysX Stripping
Section titled “[GHOST AUTHORITY] Remote Proxy Ghost Authority & PhysX Stripping”

When CVLNetworkManager pre-warms PrefabCatalog object pools at boot (InitializeProxyPools) and activates non-local entities (Setup(isLocal: false)), it strips all local physics authority to prevent PhysX broadphase contention against the 133 ms interpolation timeline:

  • Component Deactivation: On remote proxies, CVLPlayerController, CharacterController, Rigidbody, solid Collider components, Camera, and AudioListener components are immediately disabled, and Animator.applyRootMotion is forced to false.
  • Tag Preservation: The SDK disables Camera components on remote prefabs without mutating developer scene tags (Untagged vs. MainCamera), preventing interference with external camera managers.
  • Local-Only Physics.SyncTransforms() Isolation: Global C++ PhysX transform flushes (Physics.SyncTransforms()) are gated strictly behind isLocalPlayer == true during authoritative OP_SET_POS rollbacks. Executing Physics.SyncTransforms() on remote proxies during multi-entity bundle hydration or 15Hz broadcasts is prohibited.
[HIERARCHY] Hierarchical Vehicle Mount Synchronization
Section titled “[HIERARCHY] Hierarchical Vehicle Mount Synchronization”

When an entity boards or dismounts a ROLE_MOBILE_GROUNDED (Role 6) or ROLE_MOBILE_AERIAL (Role 7) vehicle (ParentNetID transition in OP_BUNDLE or OP_SET_POS), CVLNetworkIdentity.Update() synchronizes the Unity transform hierarchy:

  • Mount Binding (ParentNetID > 0): Resolves the parent vehicle identity, locates its "Passenger Socket" child Transform (enforced at edit-time by CVLPrefabValidator), parents the passenger (transform.SetParent(socket, false)), zeroes local position and rotation offsets, and snaps to the socket anchor. If IsLocalPlayer == true, the SDK automatically sets CVLEngineAPI.IsInputSuspended = true and disables the local CharacterController.
  • Dismount Restoration (ParentNetID == 0): Unparents the transform (SetParent(null, true)), hard-snaps to the confirmed world coordinate, and restores CharacterController.enabled = true and CVLEngineAPI.IsInputSuspended = false for the local operator.

[SEC 03.0] Sub-Canvas UI Isolation & The 600-Frame Metabolic Profiler

Section titled “[SEC 03.0] Sub-Canvas UI Isolation & The 600-Frame Metabolic Profiler”

Rendering 500 floating 3D world-space canvases or rebuilding a single monolithic Unity UI canvas every frame saturates the main thread with vertex-dirtying and pointer-raycast overhead. CVL CORE pairs a sub-canvas screen-space UI manager with an automated 600-frame metabolic profiler.

[UI POOLING] Zero-Allocation Screen-Space Nameplate Pooling (CVLScreenSpaceUIManager)
Section titled “[UI POOLING] Zero-Allocation Screen-Space Nameplate Pooling (CVLScreenSpaceUIManager)”

3D world-space canvases are prohibited across the SDK. CVLScreenSpaceUIManager ([DefaultExecutionOrder(10)]) and EntityNameplate ([DefaultExecutionOrder(200)]) enforce five UI optimization layers:

  1. GraphicRaycaster Stripping: The central Screen Space - Overlay canvas strips its GraphicRaycaster component entirely, and all child Graphic elements set raycastTarget = false to eliminate per-frame pointer traversal.
  2. Pre-Warmed Sub-Canvas Isolation: During Awake(), the manager pre-warms a Stack<GameObject> nameplate pool to TotalPoolCapacity. Each nameplate instance carries an isolated sub-Canvas (overrideSorting = false), isolating dirty UI batch rebuilds strictly to the individual nameplate sub-tree.
  3. Frustum & Distance Leasing (45.0m Cutoff): EntityNameplate only leases a pooled UI instance when the proxy is in front of Camera.main and within cullDistance (45.0m), returning the UI instance to the pool stack immediately when the proxy exits the view frustum.
  4. Inverse-Distance Perspective Scaling: Visible nameplates track VisualPivot.position + (Vector3.up * heightOffset) with centered pivots (X = 0.5, Y = 0.5) and scale according to scale = referenceDistance / distance, gated by a 0.005f scale epsilon.
  5. Sub-Pixel Motion Deadband: RectTransform.position updates are skipped unless squared screen-space movement satisfies (screenPos - lastScreenPos).sqrMagnitude >= 0.0001f (with screenPos.z = 0f), eliminating sub-pixel UI batch churn.
[PROFILER] The 600-Frame Client Metabolic Profiler (CVLClientProfilerReport)
Section titled “[PROFILER] The 600-Frame Client Metabolic Profiler (CVLClientProfilerReport)”

Executing at [DefaultExecutionOrder(1000)], CVLClientProfilerReport verifies that client presentation maintains 0 B/frame of managed heap growth under a 500-entity unculled hotspot load:

  • 10.0-Second Post-Login Warmup Blockout: Automatically delays recording until 10.0 seconds after active gameplay begins (warmupDelaySeconds = 10.0f) so initial Stage 2 geometry hydration and Stage 3 bundle pooling settle.
  • Native C++ IMGUI Loop Suppression: Unity’s legacy OnGUI() system allocates managed Event objects on every repaint/layout pass in the Editor. During the 600-frame audit window, the profiler invokes CVLEngineAPI.SetGuiSuppressed(true). HUD scripts (CVLDemoHUD, CVLScreenSpaceUIManager) subscribe to OnGuiSuppressionChanged and set this.enabled = false during the audit, causing Unity’s native C++ loop to skip OnGUI() invocation completely.
  • Forensic Report Generation (ClientMetabolicReport.txt): Across 600 consecutive frames (and re-triggerable manually via F4), the profiler records P50, P95, P99, and 1% Low frame times, GC.CollectionCount(0/1/2) deltas, managed heap byte deltas, and live server vitals.

[SEC 04.0] Architectural Invariants & Guardrails

Section titled “[SEC 04.0] Architectural Invariants & Guardrails”

Maintaining 0 B/frame client rendering and rock-solid visual interpolation requires strict adherence to coordinate reconstruction and UI/profiler discipline.

[GUARDRAIL] Canonical Coordinate Swizzling & 32-Bit Unsigned Bit Unpacking
Section titled “[GUARDRAIL] Canonical Coordinate Swizzling & 32-Bit Unsigned Bit Unpacking”

Because the CVL CORE server operates in a 2D/2.5D top-down Cartesian plane (X East/West, Y North/South, Z Elevation with +512.0 local zone bias and Z_AXIS_BIAS) while Unity operates in a left-handed Y-up 3D coordinate system with an inverted Z-axis, the Presentation Bridge applies canonical swizzling on ingress and egress:

  • Wire-to-Unity Reconstruction: Global server coordinates resolve via serverX = ZoneOriginX + (rawX - 512.0) and serverY = ZoneOriginY + (rawY - 512.0). These map to Unity space as unityPos.x = serverX, unityPos.y = (serverZ - zAxisBias) + playerPivotOffset, and unityPos.z = worldMaxZ - serverY, with heading reflected across 180 degrees via unityYaw = (180.0f - serverYaw) % 360.0f.
  • Explicit uint Casts & Half-Step Bucket Centering: When extracting 17-bit or 20-bit packed horizontal coordinates from OP_BROADCAST bitmasks, bitfields must be cast explicitly to 32-bit unsigned integers (uint) prior to arithmetic shifts to prevent 16-bit overflow at 65535. Reconstructed integers add a +0.5 half-step offset using 64-bit double precision scalars to center quantization buckets and eliminate directional drift.
[CHECKLIST // INVARIANTS] INTERPOLATION, PHYSX & UI PRESENTATION GUARDRAILS

1. Zero Left-Edge Extrapolation: Never run dead reckoning when renderClock <= oldestSnapshot.Timestamp; always clamp to the oldest snapshot.
2. Remote Proxy PhysX Isolation: Disable CharacterController, Rigidbody, and solid Collider components on all remote proxies; never call Physics.SyncTransforms() when isLocalPlayer == false.
3. No 3D World-Space Canvases: Always route floating UI through CVLScreenSpaceUIManager sub-canvas pools with GraphicRaycaster stripped and raycastTarget = false.
4. Suppress OnGUI During Profiling: Bind custom OnGUI debug scripts to CVLEngineAPI.OnGuiSuppressionChanged (this.enabled = !suppressed) so Editor IMGUI allocations do not pollute 600-frame metabolic audits.


[SEC 05.0] Presentation & Profiler Gate Integration

Section titled “[SEC 05.0] Presentation & Profiler Gate Integration”

The following C# integration example demonstrates subscribing to CVLEngineAPI combat flash events (OP_FLASH_DAMAGE), hooking custom debug overlays into the OnGuiSuppressionChanged profiler gate, and reading live smoothed RTT/jitter metrics that drive the 133 ms interpolation buffer:

[IMPLEMENTATION] Client Presentation & Profiler Gate Integration (CVLEngineAPI.cs)
Section titled “[IMPLEMENTATION] Client Presentation & Profiler Gate Integration (CVLEngineAPI.cs)”
EXAMPLE INTEGRATION : Assets/CVL_CORE_SDK/API/PresentationAndProfilerHook.cs
using UnityEngine;
using CVLCore.SDK;
public class PresentationAndProfilerHook : MonoBehaviour
{
private void Awake()
{
// Eliminate legacy IMGUI layout pass overhead
useGUILayout = false;
}
private void OnEnable()
{
CVLEngineAPI.OnDamageFlashed += HandleDamageFlashed;
CVLEngineAPI.OnGuiSuppressionChanged += HandleGuiSuppressionChanged;
CVLEngineAPI.OnPingUpdated += HandlePingUpdated;
}
private void OnDisable()
{
CVLEngineAPI.OnDamageFlashed -= HandleDamageFlashed;
CVLEngineAPI.OnGuiSuppressionChanged -= HandleGuiSuppressionChanged;
CVLEngineAPI.OnPingUpdated -= HandlePingUpdated;
}
private void HandleGuiSuppressionChanged(bool isSuppressed)
{
// Disables this MonoBehaviour during the 600-frame CVLClientProfilerReport audit
// so Unity's C++ loop completely skips OnGUI() invocation (0 B/frame)
this.enabled = !isSuppressed;
}
private void HandleDamageFlashed(string targetEid, short signedHpDelta)
{
// Triggered upon 4-byte OP_FLASH_DAMAGE receipt; trigger pooled hit VFX or flinch animation
Debug.Log($"Combat Presentation Flash on {targetEid}: {signedHpDelta} HP");
}
private void HandlePingUpdated(float smoothedRttMs, float smoothedJitterMs)
{
// Inspect the adaptive interpolation delay floor (>= 133ms)
float activeInterpDelaySec = Mathf.Max(0.133f, (smoothedRttMs + (smoothedJitterMs * 2.0f)) * 0.001f);
}
}
Section titled “[RELATED SPECS] Cross-Category Subsystem Links”