lagcomp

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lagcomp implements server-side time rewind for client hit adjudication in authoritative-action multiplayer games.

The server keeps a fixed-size ring buffer of hurtbox snapshots, one per subtick. When a client reports a hit at their perceived time, the server rewinds to the client's RTT-corrected subtick and runs the hit trace against rewound state.

This is intentionally game-specific (sits under kit/game/) — outside networked authoritative-action games there is no analogue. The ring is fixed-capacity and zero-alloc on Push/At after construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attack

type Attack struct {
	Origin    geometry.Vec3
	Direction geometry.Vec3 // unit vector
	Range     float32
	Width     float32 // capsule/swept-sphere radius; 0 for ray test
}

Attack describes a single hit attempt to adjudicate.

type HitTrace

type HitTrace[H any] func(hurtbox H, attack Attack) bool

HitTrace is the caller-supplied hit test against rewound hurtbox state.

type Ring

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

Ring is a fixed-size, allocation-free ring buffer of hurtbox snapshots. Sized for the rewind window the game needs (e.g. 30 snapshots at 60Hz = 500ms).

Not safe for concurrent access; the typical owner is the per-entity actor goroutine (see kit/actor).

func NewRing

func NewRing[H any](size int) *Ring[H]

NewRing allocates a Ring with capacity for `size` snapshots. Panics if size <= 0.

func (*Ring[H]) At

func (r *Ring[H]) At(sub SubtickIndex) (Snapshot[H], bool)

At returns the snapshot for the given subtick, or false if it has fallen out of the window.

func (*Ring[H]) Cap

func (r *Ring[H]) Cap() int

Cap returns the configured ring capacity.

func (*Ring[H]) Push

func (r *Ring[H]) Push(s Snapshot[H])

Push writes a snapshot; the oldest entry is overwritten when the ring is full. Allocation-free.

func (*Ring[H]) Rewind

func (r *Ring[H]) Rewind(rtt time.Duration, now time.Time) (SubtickIndex, bool)

Rewind picks the subtick that best represents the world `rtt` ago relative to `now`. Returns the snapshot's subtick and ok=false if the requested time is out of the window.

func (*Ring[H]) Size

func (r *Ring[H]) Size() int

Size returns the number of populated slots.

type Snapshot

type Snapshot[H any] struct {
	Subtick SubtickIndex
	At      time.Time
	Hurtbox H
}

Snapshot is one entry in the ring buffer: a snapshot of the entity's hurtbox state at a specific subtick.

type SubtickIndex

type SubtickIndex uint64

SubtickIndex is a monotonically increasing subtick counter. The caller chooses tick rate (60Hz is a common default; the ring's window depends on size × tick interval).

func Validate

func Validate[H any](r *Ring[H], rtt time.Duration, now time.Time, attack Attack, trace HitTrace[H]) (hit bool, at SubtickIndex)

Validate rewinds the ring to the snapshot best matching `rtt` ago, runs the caller's HitTrace, and reports whether it landed.

Jump to

Keyboard shortcuts

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