statesync-interpolate

command
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

statesync-interpolate — Actor + DeltaSync + 渲染插值组合演示

展示三大核心能力的组合:

职责
Actor Pipeline pkg/game/match 单 goroutine 串行化,业务无锁
Delta Sync pkg/game/replicate 只发脏数据的增量同步(AOI + DirtySet)
Visual Delay Buffer pkg/game/interpolate 客户端渲染延迟缓冲 + 帧间插值

原理

服务器(20Hz)                          客户端(60fps)
┌──────────┐   Subscribe/WebSocket    ┌──────────────────────┐
│ match    │ ─────────────────────→   │ interpolate.Buffer   │
│ .Match   │   每 50ms 一帧世界快照    │   ↓                  │
└──────────┘                          │ TimeLine.RenderTime()│
                                      │   ↓                  │
                                      │ Buffer.Bracket(t)    │
                                      │   ↓                  │
                                      │ InterpolateFrame()   │
                                      │   = 60fps 丝滑渲染   │
                                      └──────────────────────┘

客户端始终渲染"过去 100ms"的世界状态。收到服务器帧后存入 Buffer,渲染循环从 Buffer 找前后两帧做线性插值。代价是固定 100ms 延迟,换来完全吸收网络抖动。

运行

go run ./examples/statesync-interpolate

输出示例:

服务器: 20Hz tick | 客户端: 60fps render | 渲染延迟: 100ms

┌─────────────────────────┬───────────┬────────────────┬──────────────┐
│ 玩家                    │ 渲染帧数  │ 帧间平滑度(σ)  │ 结论         │
├─────────────────────────┼───────────┼────────────────┼──────────────┤
│ alice(稳定网络)          │     170   │       0.14     │ ✅ 丝滑       │
│ bob(普通网络)            │     170   │       0.13     │ ✅ 丝滑       │
│ carol(高抖动)            │     170   │       0.13     │ ✅ 丝滑       │
└─────────────────────────┴───────────┴────────────────┴──────────────┘

即使 carol 的网络抖动高达 50ms,通过 100ms 渲染缓冲仍然完全平滑。

Documentation

Overview

statesync-interpolate demo:展示 match(Actor) + replicate(DeltaSync) + interpolate(VisualDelay) 的组合。

服务器:20Hz 权威仿真(match.Match 的 Actor 模型),每 tick 生成世界快照并广播。 客户端:收到快照后存入 interpolate.Buffer,渲染循环以 60fps 从 Buffer 中取前后两帧做线性插值,始终落后服务器 100ms(吸收网络抖动)。

本 demo 进程内同时模拟服务器和 3 个"客户端",每个客户端:

  1. 收服务器快照 → Push 到 Buffer
  2. 模拟 60fps 渲染循环 → TimeLine.RenderTime() + Buffer.Bracket() + InterpolateFrame()
  3. 统计:帧间平滑度(位移方差)

运行:go run ./examples/statesync-interpolate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL