Documentation ¶
Index ¶
- type Checkpoint
- type Game
- func (g *Game) Checkpoint() *Checkpoint
- func (g *Game) Frame() uint32
- func (g *Game) FrameDrift() int
- func (g *Game) Gen() uint32
- func (g *Game) HandleLocalInput(buttons uint8)
- func (g *Game) HandleRemoteInput(buttons uint8, frame uint32)
- func (g *Game) Init(cp *Checkpoint)
- func (g *Game) Reset()
- func (g *Game) RunFrame(startTime time.Time)
- func (g *Game) SetRTT(t time.Duration)
- func (g *Game) SleepFrames(n uint32)
- func (g *Game) Sleeping() bool
- type Message
- type MsgType
- type Netplay
- func (np *Netplay) HandleMessages()
- func (np *Netplay) RemotePing() int64
- func (np *Netplay) RunFrame(startTime time.Time)
- func (np *Netplay) SendButtons(buttons uint8)
- func (np *Netplay) SendBye()
- func (np *Netplay) SendInitialState()
- func (np *Netplay) SendPing()
- func (np *Netplay) SendReset()
- func (np *Netplay) SendResync()
- func (np *Netplay) SendWait(frames uint32)
- func (np *Netplay) ShouldExit() bool
- type Protocol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checkpoint ¶
type Game ¶
type Game struct { LocalJoy *input.Joystick RemoteJoy *input.Joystick DisasmEnabled bool // contains filtered or unexported fields }
Game is a network play state manager. It keeps track of the inputs from both players and makes sure their state is synchronized.
func (*Game) Checkpoint ¶
func (g *Game) Checkpoint() *Checkpoint
Checkpoint returns the current checkpoint where both players are in sync. The returned value should not be modified and is only valid within the current frame.
func (*Game) FrameDrift ¶
func (*Game) Gen ¶
Gen returns the current generation number. It is incremented every time the game is reset.
func (*Game) HandleLocalInput ¶
HandleLocalInput adds records and applies the input from the local player. Since the remote player is behind, it assumes that it just keeps pressing the same buttons until it catches up.
func (*Game) HandleRemoteInput ¶
HandleRemoteInput adds the input from the remote player.
func (*Game) Init ¶
func (g *Game) Init(cp *Checkpoint)
func (*Game) SleepFrames ¶
type Netplay ¶
type Netplay struct {
// contains filtered or unexported fields
}
func (*Netplay) HandleMessages ¶
func (np *Netplay) HandleMessages()
HandleMessages handles incoming messages from the remote player.
func (*Netplay) RemotePing ¶
RemotePing returns the ping time to the remote peer in milliseconds.
func (*Netplay) SendButtons ¶
SendButtons sends the local input to the remote player. Should be called every frame.
func (*Netplay) SendBye ¶
func (np *Netplay) SendBye()
SendBye sends a bye message to the remote player when the game is over.
func (*Netplay) SendInitialState ¶
func (np *Netplay) SendInitialState()
SendInitialState is used by the server to send the initial state to the client.
func (*Netplay) SendReset ¶
func (np *Netplay) SendReset()
SendReset restarts the game on both sides.
func (*Netplay) SendResync ¶
func (np *Netplay) SendResync()
func (*Netplay) ShouldExit ¶
ShouldExit indicates whether the game loop should exit.