session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 4 Imported by: 0

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

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 FrameSink

type FrameSink func(frame.Snapshot)

FrameSink receives the render snapshot produced after each stepped tick.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session advances a world deterministically and delivers snapshots.

func New

func New(cfg Config) *Session

New builds a Session around an already-constructed world.

func (*Session) OrdersForTick

func (s *Session) OrdersForTick(tick uint64) []order.Order

OrdersForTick returns the orders scheduled for a given tick, for command frame assembly.

func (*Session) PendingTicks

func (s *Session) PendingTicks() []uint64

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

func (s *Session) ScheduleAt(tick uint64, o order.Order)

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

func (s *Session) SetFrameSink(sink FrameSink)

SetFrameSink installs the callback invoked with each tick's snapshot.

func (*Session) Step

func (s *Session) Step() frame.Snapshot

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.

func (*Session) Submit

func (s *Session) Submit(o order.Order) uint64

Submit schedules a local order for execution InputDelay ticks in the future. Offline this is effectively "next tick"; in multiplayer the authoritative server reassigns the execution tick before broadcasting.

func (*Session) World

func (s *Session) World() *sim.World

World exposes the underlying world for snapshotting and inspection.

Jump to

Keyboard shortcuts

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