inputclock

package
v0.9.2 Latest Latest
Warning

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

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

Documentation

Overview

Package inputclock 记录客户端帧与服务器帧映射,并估算 RTT(延迟补偿入口)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock 维护 per-player 帧映射与 RTT 估算。

func New

func New(opts ...Option) *Clock

New 创建 Clock。

func (*Clock) CompensatedFrame

func (c *Clock) CompensatedFrame(player string, clientFrame uint64, tick time.Duration) (uint64, bool)

CompensatedFrame 返回用于 lag compensation 的目标服务器帧(serverFrame - rewind)。

func (*Clock) RTT

func (c *Clock) RTT(player string) time.Duration

RTT 返回 player 的 RTT 估算(无样本时为 0)。

func (*Clock) Record

func (c *Clock) Record(s Sample)

Record 记录一条输入样本;若同一 (player, clientFrame) 已存在则覆盖。

func (*Clock) RewindFrames

func (c *Clock) RewindFrames(player string, tick time.Duration) uint64

RewindFrames 按 tick 间隔估算 RTT 对应的 rewind 帧数(至少 1)。

func (*Clock) ServerFrame

func (c *Clock) ServerFrame(player string, clientFrame uint64) (uint64, bool)

ServerFrame 返回 clientFrame 对应的服务器帧。

func (*Clock) UpdateRTT

func (c *Clock) UpdateRTT(player string, rtt time.Duration)

UpdateRTT 用 ping 往返时间更新 player 的 RTT 估算(指数移动平均)。

type Option

type Option func(*Clock)

Option 配置 Clock。

func WithNow

func WithNow(fn func() time.Time) Option

WithNow 注入时钟(测试用)。

type Sample

type Sample struct {
	Player      string
	ClientFrame uint64
	ServerFrame uint64
	ReceivedAt  time.Time
}

Sample 是一条输入的时间戳样本。

Jump to

Keyboard shortcuts

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