Documentation
¶
Index ¶
- func ListSaves(basePath string) ([]string, error)
- func RegComp[C any](game *Game) goke.CompID
- type Game
- func (g *Game) Draw(screen *ebiten.Image)
- func (g *Game) ECS() *goke.ECS
- func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int)
- func (g *Game) Load(basePath, label string, space *gokg.Space, onLoaded func(count int), ...) error
- func (g *Game) Loop(plan func(ctx goke.RunCtx, d time.Duration))
- func (g *Game) Pause()
- func (g *Game) Paused() bool
- func (g *Game) RegSys(factory func() goke.System) goke.Runnable
- func (g *Game) RenderSequence(rendererFactories ...func() render.Renderer)
- func (g *Game) Resume()
- func (g *Game) Run()
- func (g *Game) Save(basePath, label string) error
- func (g *Game) SetEventHandler(handler control.EventHandler)
- func (g *Game) Setup(providers ...goke.SetupProvider)
- func (g *Game) Step() time.Duration
- func (g *Game) TogglePause()
- func (g *Game) Update() error
- func (g *Game) UseModule(m goke.Module)
- type GameProps
- type Resettable
- type Resources
- func (r *Resources[S, T]) GetGameProps() *GameProps
- func (r *Resources[S, T]) GetInputEvents() *control.InputEvents
- func (r *Resources[S, T]) GetSpaceConfig() spatial.Config
- func (r *Resources[S, T]) LoadState(rd io.Reader) error
- func (r *Resources[S, T]) Reset()
- func (r *Resources[S, T]) SaveState(w io.Writer) error
- func (r *Resources[S, T]) State() *S
- func (r *Resources[S, T]) TPS() *int
- func (r *Resources[S, T]) Telemetry() *T
- type TimeTracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
func (*Game) Load ¶
func (g *Game) Load(basePath, label string, space *gokg.Space, onLoaded func(count int), providers ...any) error
Load restores a snapshot written by Save (same basePath and label) into this (must be freshly constructed) Game: State, the ECS snapshot, and — since space (the gokg spatial index) isn't part of the ECS snapshot — a rebuild of space from every loaded entity's kinematics.Position, deferred to the same Setup phase RenderSequence/UseModule/Setup use. onLoaded, if not nil, is called once that rebuild completes, with the loaded entity count (e.g. to set a telemetry field) — nil if you don't need it. providers supplies component tokens the same way ProvidedComps does (e.g. your physics module); render.Appearance is always included.
func (*Game) RenderSequence ¶
func (*Game) Save ¶
Save pauses the ECS and writes one file — State (see Resources.SaveState; a zero-length marker if S doesn't implement encoding.BinaryMarshaler) followed by the ECS snapshot — to saveFilePath(basePath, label). label selects which save this is: "" for the quicksave slot, anything else for a named save (see ListSaves to discover named saves already on disk). Resumes before returning either way.
func (*Game) SetEventHandler ¶
func (g *Game) SetEventHandler(handler control.EventHandler)
func (*Game) Setup ¶
func (g *Game) Setup(providers ...goke.SetupProvider)
Setup defers each provider's SetupSystems to the same one-time ecs.Setup call RenderSequence/UseModule feed — in call order, mirroring ecs.Setup's own name and one-time-seeding spirit at the Game level.
func (*Game) TogglePause ¶
func (g *Game) TogglePause()
type Resettable ¶
type Resettable interface{ Reset() }
Resettable lets Telemetry hook into each stats interval — if T implements it, Reset is called right after TPS is refreshed.
type Resources ¶
type Resources[S, T any] struct { // contains filtered or unexported fields }
Resources bundles what Game needs (GameProps, input, world config, and built-in TPS/EntityCount telemetry) with two game-owned shapes: S for control state, T for display telemetry.
func NewResources ¶
func (*Resources[S, T]) GetGameProps ¶
func (*Resources[S, T]) GetInputEvents ¶
func (r *Resources[S, T]) GetInputEvents() *control.InputEvents
func (*Resources[S, T]) GetSpaceConfig ¶
func (*Resources[S, T]) LoadState ¶
LoadState restores State from rd, written by SaveState — a no-op (beyond consuming the length prefix, to leave rd positioned right after State for any data that follows) if S doesn't implement encoding.BinaryUnmarshaler.
func (*Resources[S, T]) SaveState ¶
SaveState writes a uint32 length prefix followed by State to w — the prefix is 0 if S doesn't implement encoding.BinaryMarshaler, so games with nothing worth persisting beyond the ECS snapshot don't need to do anything special. Length-prefixed (rather than reading w to EOF) so SaveState/LoadState can share a stream with data written after them, e.g. Game.Save appending an ECS snapshot to the same file.
type TimeTracker ¶
type TimeTracker struct {
// contains filtered or unexported fields
}
TimeTracker is responsible for the fixed physics step (Fixed Time Step) and statistics.
func NewTimeTracker ¶
func NewTimeTracker() *TimeTracker
func (*TimeTracker) CalculateSteps ¶
func (t *TimeTracker) CalculateSteps(physicsStep time.Duration, maxSteps int) int
CalculateSteps calculates how many physics ticks should be performed in the current frame.
func (*TimeTracker) ProcessStatsInterval ¶
func (t *TimeTracker) ProcessStatsInterval() bool