Documentation
¶
Overview ¶
Package session is the transport-agnostic driver that wraps a simulation world and turns submitted orders into stepped ticks and render snapshots. It is the single piece both deployment targets share: the native server runs a Session as the authority and ships its command stream over a websocket; the wasm client runs the same Session locally for offline play and for predicting ahead of the server. Because the Session has no I/O of its own, the two builds differ only in the thin transport wrappers that feed and drain it.
Index ¶
- type Config
- type FrameSink
- type Session
- func (s *Session) OrdersForTick(tick uint64) []order.Order
- func (s *Session) PendingTicks() []uint64
- func (s *Session) Restore(tick uint64, units []sim.RestoredUnit, projectiles []sim.RestoredProjectile)
- func (s *Session) ScheduleAt(tick uint64, o order.Order)
- func (s *Session) SetFrameSink(sink FrameSink)
- func (s *Session) Step() frame.Snapshot
- func (s *Session) Submit(o order.Order) uint64
- func (s *Session) World() *sim.World
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
World *sim.World
// Runtime is the optional COB script VM advanced each tick.
Runtime sim.Runtime
// InputDelay is how many ticks ahead a Submit()ed order is scheduled, the
// window that hides network latency. Zero is correct for single-player
// offline play.
InputDelay uint64
}
Config configures a Session.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session advances a world deterministically and delivers snapshots.
func (*Session) OrdersForTick ¶
OrdersForTick returns the orders scheduled for a given tick, for command frame assembly.
func (*Session) PendingTicks ¶
PendingTicks returns the sorted ticks that have scheduled orders, used by the server to assemble command frames.
func (*Session) Restore ¶
func (s *Session) Restore(tick uint64, units []sim.RestoredUnit, projectiles []sim.RestoredProjectile)
Restore reinitializes the world from an authoritative snapshot and discards any locally scheduled orders, so a late-joining client resyncs to the server's current tick before applying the command frames that follow. The in-flight projectiles are restored alongside the units so the joiner's sky matches the authority's and any shot still en route lands identically.
func (*Session) ScheduleAt ¶
ScheduleAt queues an order to execute exactly at the given tick. The server uses this when it assigns execution ticks; clients use it when they receive a command frame. Orders within a tick keep submission order.
func (*Session) SetFrameSink ¶
SetFrameSink installs the callback invoked with each tick's snapshot.
func (*Session) Step ¶
Step advances the simulation by exactly one tick: it applies every order scheduled for the upcoming tick (in submission order), steps the world, and delivers the resulting snapshot. It returns the snapshot for callers that prefer a pull model over the sink.