snapbuf

package
v0.8.2 Latest Latest
Warning

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

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

Documentation

Overview

Package snapbuf 提供固定深度的环形快照缓冲,用于延迟补偿/server rewind。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

type Ring[S any] struct {
	// contains filtered or unexported fields
}

Ring 保存最近 depth 帧的快照(S 由业务定义,如 world 副本)。

func New

func New[S any](depth int) *Ring[S]

New 创建深度为 depth 的环形缓冲(depth<=0 时取 64)。

func (*Ring[S]) At

func (r *Ring[S]) At(frame uint64) (S, bool)

At 精确查找 frame 对应的快照。

func (*Ring[S]) Latest

func (r *Ring[S]) Latest() (frame uint64, snap S, ok bool)

Latest 返回最新帧号与快照。

func (*Ring[S]) Len

func (r *Ring[S]) Len() int

Len 返回当前缓冲中的帧数(<= depth)。

func (*Ring[S]) Nearest

func (r *Ring[S]) Nearest(frame uint64) (S, uint64, bool)

Nearest 返回 <= frame 的最近快照(用于 RTT 补偿)。

func (*Ring[S]) Push

func (r *Ring[S]) Push(frame uint64, snap S)

Push 写入 frame 对应的快照;frame 应单调递增。

Jump to

Keyboard shortcuts

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