rollback

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	State  MatchState
	Signal *scnet.Signal
	Game   *scnet.Game
}

func NewConn

func NewConn(ctx context.Context, playerNumber scnet.Perspective, versionSuffix string) (*Conn, error)

func (*Conn) UpdateState

func (c *Conn) UpdateState() bool

type Context

type Context struct {
	LocalInputs  InputFrames
	RemoteInputs InputFrames
	Known        State
	Predicted    State

	Drop    uint8
	Dropped bool
	// contains filtered or unexported fields
}

func (*Context) Desync

func (c *Context) Desync() (ahead, behind int64)

func (*Context) Sync

func (c *Context) Sync(g *scnet.Game, ictx *input.Context) error

type InputBuf

type InputBuf struct {
	StartFrame uint64
	Length     uint64
	FrameAdv   int64
	Packed     []byte
	Bits       uint8 // number of bits remaining in final byte of packed buffer
}

func (*InputBuf) Append

func (b *InputBuf) Append(prev *InputFrame, ictx *input.Context)

func (*InputBuf) AppendFrame

func (b *InputBuf) AppendFrame(prev, frame InputFrame)

func (*InputBuf) Decode

func (b *InputBuf) Decode(frames *InputFrames) error

func (*InputBuf) MarshalBinary

func (b *InputBuf) MarshalBinary() ([]byte, error)

func (*InputBuf) Skip

func (b *InputBuf) Skip(frames uint64) *InputBuf

func (*InputBuf) UnmarshalBinary

func (b *InputBuf) UnmarshalBinary(buf []byte) error

type InputFrame

type InputFrame uint16

InputFrame is an array of held buttons for a frame.

func (InputFrame) Held added in v0.3.15

func (f InputFrame) Held(btn input.Button) bool

type InputFrames

type InputFrames []InputFrame

InputFrames is a slice of InputFrame. The index in the slice corresponds to the frame number.

func (InputFrames) Predict

func (f InputFrames) Predict(num uint64) InputFrame

Predict returns the predicted input for a specified frame number. If the frame is known, the actual input is returned. Otherwise, the last known input is returned.

type MatchState

type MatchState int
const (
	StateMatchmakingWait MatchState = iota
	StateMatchmakingConnecting
	StateMatchReady
	StateConnectionFailed
)

MatchState constants.

type State

type State interface {
	// Frame returns the current frame number.
	Frame() uint64

	// Update advances the frame number by 1 and processes the game's logic.
	// There should be no externally visible effects of this function call.
	Update(p1, p2 InputFrame)

	// Clone makes a copy of the State.
	Clone() State

	// OnRollback is called when a rollback occurs. The game should reset
	// all externally visible state. (eg. sound effects)
	OnRollback()

	// OnFrame is called after Update if the changes to the state should be
	// made externally visible.
	OnFrame()
}

Jump to

Keyboard shortcuts

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