Documentation
¶
Overview ¶
Package game is what a game implements and what it is handed back: the Game the engine drives, its [Stage]s and their [Scene]s, and the Initializer, Runtime and Persistence a Stage or Scene works through. Everything a third party writes against lives here, in the open; only the engine that drives it is internal.
Game ¶
A Game supplies its Props (the window, a Description for the game's own menu, TargetTPS the engine's fixed step) and its Stages by Name, plus which starts active. New is the Game of props and stages a game keeping nothing else of its own needs, the first stage starting unless Defined.Starting names another; a game wanting more writes its own.
Stage ¶
A Stage is one self-contained context the game can be in, with its own plugins and its own goke ECS, both built fresh when the Stage is entered. Init installs plugins through the Initializer; Spawn seeds the initial state of a Stage entered afresh, Loaded is told in its place when it was entered from a save; Update advances the simulation one tick. A Stage handles no input: that is a Scene's. A game seldom writes a Stage by hand: package game/stage defines one a section at a time.
Saving and loading ¶
Saving and loading are the engine's, asked for by commands it carries out: Save the active Stage in a slot, Load a Stage from its save, from any Stage (a menu's Continue), Enter a Stage afresh, Quit. They are given like any command: a key's binding, a ui button, a rule's Order, Runtime.Issue. A save is the Stage's, a file a slot in Props.Saves; a Stage entered from one is built anew and its world loaded in place of Spawn.
Scene, Scenes and Composition ¶
A Scene is one thing a Stage can show: Drawers, bottom to top, render.Renderers drawn on the screen (the world among them through a ui.Image of a render.Feed); HandleEvents, this tick's input, run only while the Scene is active; and Focusable, whether it can ever be active. Scenes, built by NewStack, is the Stage's registry of them by Name. Its Composition is the live state: which Scenes are visible, in what order, and Active, the topmost focusable one, so a non-focusable HUD can sit on top and never steal input. Composition is Serializable; a Stage hands it to Initializer.Track so visibility and order survive a save.
Initializer ¶
Initializer is what Init receives: Use installs a plugin, Track registers any other Serializable for saves, UseWorld builds this Stage's world plugin from a world.Config, and TPS is the engine's measured tick counter. It embeds plugin.Installer, so a Stage may wire ECS modules and systems of its own the way a plugin does.
A Stage hands its rules to nobody: a rule is a role's (world.Roles), a role is played by a kind, a cell or a plugin, and once Init returns the engine gives the rules of every role played to the plugin in use that catches their moment. A rule no plugin in use catches fails Init with an error wrapping host.ErrUnhosted, naming the rule.
Runtime ¶
Runtime is engine-level control, one undivided interface: the pause, Quit, SwitchStage, Save, Load, Issue, Persistence, TPS and ToggleFullscreen. The same value reaches a Stage and every Scene's HandleEvents.
Persistence ¶
Persistence is Save, Load and List over the active Stage's ECS and every tracked value, under a base path and a label ("" is the quicksave). Load restores what the snapshot holds and leaves anything absent unchanged.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Composition ¶
type Composition interface {
// Show makes name visible, on top.
Show(name string)
// Hide makes name no longer visible.
Hide(name string)
// BringToFront moves an already-visible name to the top.
BringToFront(name string)
// Order returns the currently visible names, bottom-to-top.
Order() []string
// Active returns the topmost focusable Scene's name, or "" if none is.
Active() string
plugin.Serializable
}
Composition tracks which Scenes in a Stack are visible, in what order, and which is active.
type Defined ¶ added in v0.3.0
type Defined struct {
// contains filtered or unexported fields
}
Defined is a game of props and stages and nothing else of its own: what New makes.
type Enter ¶ added in v0.3.0
type Enter struct{ Stage string }
Enter is the command to enter Stage afresh.
type Game ¶
type Game interface {
// Props configures the window, tick rate, and world for the engine.
Props() Props
// Stages returns every Stage by Name(), and which one starts active.
Stages() (stages map[string]Stage, initial string)
}
Game is implemented by the user — Engine drives it.
type Initializer ¶
type Initializer interface {
plugin.Installer
Use(p plugin.Plugin) error
// UseWorld builds and installs this Stage's world.Plugin from cfg; a second call panics.
UseWorld(cfg world.Config) *world.Plugin
// Track saves and loads s alongside the game's Plugins. Tracked after a Load, s gets the
// state the save holds for it at once.
Track(s plugin.Serializable) error
// TPS returns the engine's measured-ticks-per-second counter.
TPS() *TPS
}
Initializer is what a Stage gets during Init to install plugins and configure the ECS.
type Laying ¶ added in v0.5.0
type Laying interface {
Lay(w, h int)
}
Laying is a scene's drawer laid out before its frame is drawn: on the frame's barrier, where nothing ticks or draws, over a screen w by h pixels.
type Load ¶ added in v0.3.0
type Load struct{ Stage, Slot string }
Load is the command to enter Stage ("" the active one) from its save Slot ("" the quicksave), its world loaded instead of spawned.
type Persistence ¶
type Persistence interface {
// List returns every save found for basePath, "" (quicksave) first.
List(basePath string) ([]string, error)
// Save writes resources, every tracked Serializable and the ECS snapshot under basePath/label.
Save(basePath, label string, resources ...any) error
// Load restores a snapshot written by Save, leaving anything absent from it unchanged.
Load(basePath, label string, resources ...any) error
}
Persistence saves, loads and lists the saves of the active Stage's ECS and resources.
type Props ¶
type Props struct {
Title string // the window's: short
// Description is what the game is and how it is played, for a menu of the game's own; the
// engine shows it nowhere.
Description string
TargetTPS int
ScreenWidth, ScreenHeight int
// Resizable lets the player resize the window, the screen then being the window. Off, the
// screen stays ScreenWidth x ScreenHeight and a larger window scales it whole.
Resizable bool
// Saves is the directory the game keeps its saves in, a file a Stage and slot; empty, the one
// the game runs in.
Saves string
// Workers is how many goroutines share the work a plugin splits, the game's own among them: 0
// as many as there are CPUs, one left to the drawing where the ticks run while a frame is
// drawn; 1 none.
Workers int
// Serial has every frame ticked before it is drawn, as GRAM_SERIAL does whatever it says. Off,
// the next frame is ticked while a frame is drawn, the input shown a frame later.
Serial bool
}
Props configures the window and the tick rate, read once as the engine starts.
type Runtime ¶
type Runtime interface {
Paused() bool
Pause()
Resume()
TogglePause()
Quit()
// SwitchStage transitions to the Stage with the given Name().
SwitchStage(name string) error
// Save saves the active Stage in the save slot, "" the quicksave, where Props.Saves says.
Save(slot string) error
// Load enters stage ("" the active one) from its save slot, its world loaded instead of
// spawned. A save not there is an error, and nothing changes.
Load(stage, slot string) error
// Issue gives cmd as nobody to whoever carries it out in the active Stage, the way a key does.
Issue(cmd command.Command) error
Persistence() Persistence
TPS() *TPS
// ToggleFullscreen switches the window to fullscreen and back.
ToggleFullscreen()
// Props are the game's, as it started.
Props() Props
}
Runtime gives a Stage or Scene engine-level control: pause, stage switching, save/load.
type Save ¶ added in v0.3.0
type Save struct{ Slot string }
Save is the command to save the active Stage in the save Slot, "" the quicksave.
type Scene ¶
type Scene interface {
// Name uniquely identifies this scene.
Name() string
// Drawers returns what draws this scene, bottom to top: render.Renderers drawn on the screen,
// the world among them through a ui.Image of a render.Feed. It is called once, as the Stage is
// entered.
Drawers() []render.Renderer
// HandleEvents handles this tick's input, while this scene is active.
HandleEvents(events *control.InputEvents, runtime Runtime, composition Composition)
// Focusable reports whether this scene can ever become active.
Focusable() bool
}
Scene groups the renderers and input handling for one thing a Stage can show.
type Scenes ¶
type Scenes interface {
// Get resolves name to the Scene registered under it.
Get(name string) (Scene, bool)
// All returns every registered Scene.
All() []Scene
// Composition reports which Scenes are visible, in what order, and which is active.
Composition() Composition
}
Scenes is the immutable registry of every Scene a Stage can show, keyed by Name().
type Scenic ¶ added in v0.3.0
type Scenic interface {
Scenes() []Scene
}
Scenic is a plugin with scenes of its own, which a Stage defined in sections keeps in its stack hidden until something shows them.
type Stage ¶
type Stage interface {
// Name uniquely identifies this stage.
Name() string
// Init runs once, when this Stage becomes active.
Init(ctx Initializer) error
// Spawn runs once, when the Stage is entered afresh, seeding each plugin's initial state.
Spawn() error
// Loaded runs in place of Spawn when the Stage was entered from a save (Load), its world
// loaded.
Loaded() error
// Update advances this stage's simulation by d, once per tick.
Update(ctx goke.RunCtx, d time.Duration)
// Stack lists every Scene this stage can show, and owns their live Composition.
Stack() Scenes
}
Stage is one self-contained context a Game can be in, with its own plugins and ECS.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package stage defines a game.Stage a section at a time, always in the same order: a chain begun with New and ended with Update, each link one part of the game and nothing else.
|
Package stage defines a game.Stage a section at a time, always in the same order: a chain begun with New and ended with Update, each link one part of the game and nothing else. |