Documentation
¶
Overview ¶
Package statesync provides authoritative rooms and a transport-independent game API.
Index ¶
- Constants
- Variables
- func ClientTLS(certPEM []byte, serverName string) (*tls.Config, error)
- func LocalCertificate() (tls.Certificate, []byte, error)
- func ServerTLS(cert tls.Certificate) *tls.Config
- func WriteLocalCertificate(certFile, keyFile string) error
- type Change
- type Client
- func (c *Client) Action(ctx context.Context, id uint64, data []byte) ([]byte, error)
- func (c *Client) Authoritative() View
- func (c *Client) Bytes() (sent, received uint64)
- func (c *Client) Close()
- func (c *Client) Disconnect()
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) LastActionID() uint64
- func (c *Client) Player() uint32
- func (c *Client) ResumeGracePeriod() time.Duration
- func (c *Client) ResumeToken() ResumeToken
- func (c *Client) Resync() error
- func (c *Client) ResyncCount() uint64
- func (c *Client) Sample(id uint32, now time.Time) ([]byte, bool)
- func (c *Client) SetInterpolationDelay(delay time.Duration) error
- func (c *Client) SubmitInput(data []byte) error
- func (c *Client) TickRate() int
- type Config
- type Entity
- type Game
- type Input
- type Metrics
- type Model
- type PlayerInput
- type ResumeToken
- type Room
- type Server
- type View
Constants ¶
const ( ProtocolVersion byte = 2 ALPN = "statesync/2" MaxState = 512 MaxInput = 64 MaxAction = 512 MaxEntities = 256 MaxFrame = 256 * 1024 HistorySize = 128 )
Variables ¶
var ErrBusy = errors.New("statesync: queue full")
var ErrClosed = errors.New("statesync: closed")
var ErrProtocol = errors.New("statesync: invalid protocol")
var ErrResumeRejected = errors.New("statesync: resume rejected")
var ErrSessionReplaced = errors.New("statesync: session replaced")
Functions ¶
func LocalCertificate ¶
func LocalCertificate() (tls.Certificate, []byte, error)
LocalCertificate generates a short-lived localhost certificate for demos/tests. The client explicitly trusts this certificate; verification is never disabled.
func WriteLocalCertificate ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func DialResume ¶
func (*Client) Action ¶
Action uses a caller-supplied monotonically increasing request ID. Retrying the same ID and payload in this session returns the previous result.
func (*Client) Authoritative ¶
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
Disconnect closes transport but allows the session to be resumed.
func (*Client) LastActionID ¶
func (*Client) ResumeGracePeriod ¶
func (*Client) ResumeToken ¶
func (c *Client) ResumeToken() ResumeToken
func (*Client) ResyncCount ¶
func (*Client) Sample ¶
Sample returns predicted local state or a delayed interpolated remote state.
func (*Client) SetInterpolationDelay ¶
func (*Client) SubmitInput ¶
SubmitInput predicts exactly one fixed simulation step. Call at TickRate. The server independently caps processing to one input per player per tick.
type Config ¶
type Config struct {
TickRate int
SnapshotRate int
MaxPlayers int
DatagramSize int
ResumeGracePeriod time.Duration
}
func DefaultConfig ¶
func DefaultConfig() Config
type Entity ¶
type Entity struct {
ID uint32
Generation uint32
Owner uint32
Dynamic bool
Ack uint64 // Filled by the server; all inputs <= Ack have been resolved.
State []byte
}
State is an immutable, game-encoded value once returned to the framework.
type Game ¶
type Game interface {
Join(player uint32) ([]Change, error)
Leave(player uint32) []Change
ValidateInput(data []byte) error
Step(dt float32, inputs []PlayerInput) []Change
Action(player uint32, data []byte) ([]Change, []byte, error)
Entities() []Entity
}
After the initial Entities call, Game methods execute on the room's owning goroutine. Returned slices must not subsequently be modified by the game. Join/Action errors must leave game state unchanged.
type Model ¶
type Model interface {
ValidateInput([]byte) error
ValidateState([]byte) error
Predict(state, input []byte, dt float32) ([]byte, error)
Interpolate(a, b []byte, fraction float32) []byte
}
Model supplies the same movement rules and codec to the reference client. Implementations must return owned byte slices and must not modify arguments.
type PlayerInput ¶
type ResumeToken ¶
type ResumeToken [32]byte
ResumeToken is a bearer credential; never include its bytes in logs.
func (ResumeToken) GoString ¶
func (ResumeToken) GoString() string
func (ResumeToken) String ¶
func (ResumeToken) String() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package arena is the explicitly encoded 2D example game.
|
Package arena is the explicitly encoded 2D example game. |
|
cmd
|
|
|
check
command
Command check validates real QUIC rooms, headless clients and bounded UDP impairment.
|
Command check validates real QUIC rooms, headless clients and bounded UDP impairment. |
|
client
command
|
|
|
server
command
|
|
|
internal
|
|
|
nettest
Package nettest provides a bounded, seeded UDP impairment proxy.
|
Package nettest provides a bounded, seeded UDP impairment proxy. |