engine

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 38 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine is the driver behind gram.Run: the window's loop (gogpu), one active Stage and its ECS at a time, and the unexported implementations of the contracts package game declares. Nothing here is a user's business to read; the public surface is package game.

Engine

Engine runs a game.Game in a window: every frame a tick of the active Stage and a picture of its visible scenes. It is also the game.Runtime every Stage and Scene sees. The next frame's ticks and publishing run on a goroutine of their own while a frame is drawn; the barrier between waits for them, takes the input and lays the scenes out. A stage's first frame, a switch's and, with Props.Serial or GRAM_SERIAL set, every frame tick before they are drawn. GRAM_FPS_LOG has it log the frame rate every second, GRAM_INPUT_LOG the cursor's place in the window (and whether the window has it) every second and every click as it comes, GRAM_FULLSCREEN starts it fullscreen (F11 switches, at the window's next pass — on a Mac the window's own Ctrl+Cmd+F, the system keeping F11 — and the look while riding follows the cursor's place where the window gives no deltas), GRAM_VSYNC=off unpaces it, GRAM_SHOT=<file.png> saves the frame GRAM_SHOT_FRAME (120) and quits, the world taking one step a frame till then.

Initializer, runtime and persistence

The unexported initializer is the game.Initializer a Stage's Init receives, the unexported persistence the game.Persistence over the active Stage: a save is the ECS snapshot plus every tracked value's Persisted state, matched by name on load, so a save survives plugins being added, removed or reordered.

Input

An InputAdapter captures one frame's raw input into control.InputEvents; DesktopAdapter is the window's. DefaultController runs the capture each frame and hands the events to its handler every tick; HandlerFn adapts a plain function.

Index

Constants

This section is empty.

Variables

View Source
var Termination = errors.New("gram: the game quit")

Termination is what Update returns once the game has quit.

Functions

This section is empty.

Types

type DefaultController

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

DefaultController captures input each frame and, once an EventHandler is registered via SetHandler, runs it every tick.

func NewDefaultController

func NewDefaultController(adapter InputAdapter, events *control.InputEvents) *DefaultController

func (*DefaultController) Capture

func (c *DefaultController) Capture(e *control.InputEvents)

func (*DefaultController) Init

func (c *DefaultController) Init(*goke.SysInit)

func (*DefaultController) SetHandler

func (c *DefaultController) SetHandler(handler control.EventHandler)

func (*DefaultController) Update

func (c *DefaultController) Update(_ *goke.CmdBuf, _ time.Duration)

type DesktopAdapter

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

DesktopAdapter captures the input of the engine's window (gogpu); without a window it captures nothing.

func (*DesktopAdapter) Capture

func (a *DesktopAdapter) Capture(e *control.InputEvents)

func (*DesktopAdapter) Collect added in v0.3.0

func (a *DesktopAdapter) Collect()

Collect keeps the events of the window's pass for the next Capture, which the window would forget at its next pass, and switches full screen where asked.

func (*DesktopAdapter) ToggleFullscreen added in v0.6.0

func (a *DesktopAdapter) ToggleFullscreen()

ToggleFullscreen asks for the window switched to full screen, or back, at the window's next pass.

type Engine

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

Engine drives a game.Game through its window's loop (gogpu), one active Stage and its ECS at a time.

func NewEngine

func NewEngine(g game.Game) *Engine

NewEngine builds an Engine driving g, configured by g.Props().

func (*Engine) Draw

func (e *Engine) Draw(screen *render.Image)

Draw draws the active stage's scenes shown as the barrier found them, bottom to top, onto screen.

func (*Engine) Frame added in v0.5.0

func (e *Engine) Frame() error

Frame runs a frame's Update and hands the renderer what it draws: every Publisher of the stage and of the scenes shown publishes, then swaps; not while a stage switch is pending. It returns Termination once the game has quit.

func (*Engine) Init

func (e *Engine) Init() error

Init enters the initial Stage, or the one Load asked for from its save.

func (*Engine) Issue added in v0.3.0

func (e *Engine) Issue(cmd command.Command) error

Issue gives cmd as nobody to whoever carries it out in the active Stage.

func (*Engine) Layout

func (e *Engine) Layout(outsideWidth, outsideHeight int) (int, int)

Layout is the screen's size: the Props' fixed one, or with Resizable the window's.

func (*Engine) Load added in v0.3.0

func (e *Engine) Load(stage, slot string) error

Load enters stage ("" the active one, or the starting one before Init) from its save slot. A save not there is an error, and nothing changes.

func (*Engine) Pause

func (e *Engine) Pause()

func (*Engine) Paused

func (e *Engine) Paused() bool

func (*Engine) Persistence

func (e *Engine) Persistence() game.Persistence

Persistence returns the active Stage's Save/Load/List surface.

func (*Engine) Props added in v0.3.0

func (e *Engine) Props() game.Props

Props are the game's, read once as the engine was made.

func (*Engine) Quit

func (e *Engine) Quit()

Quit ends the loop after this tick.

func (*Engine) Resume

func (e *Engine) Resume()

func (*Engine) Run

func (e *Engine) Run()

Run calls Init, then opens the window and runs the game in it, a tick and a picture a frame, until it quits.

func (*Engine) Save added in v0.3.0

func (e *Engine) Save(slot string) error

Save saves the active Stage in the save slot, "" the quicksave, where Props.Saves says.

func (*Engine) SwitchStage

func (e *Engine) SwitchStage(name string) error

SwitchStage requests a transition to the Stage called name, made at the start of the next Update.

func (*Engine) TPS

func (e *Engine) TPS() *game.TPS

TPS returns the engine's measured-ticks-per-second counter.

func (*Engine) ToggleFullscreen added in v0.3.0

func (e *Engine) ToggleFullscreen()

ToggleFullscreen switches the window to fullscreen and back, at the window's next pass.

func (*Engine) TogglePause

func (e *Engine) TogglePause()

func (*Engine) Update

func (e *Engine) Update() error

Update runs a frame's input, then its ticks. It returns Termination once the game has quit.

type HandlerFn

type HandlerFn func(events *control.InputEvents)

HandlerFn adapts a plain function to control.EventHandler.

func (HandlerFn) HandleEvents

func (f HandlerFn) HandleEvents(events *control.InputEvents)

type InputAdapter

type InputAdapter interface {
	Capture(e *control.InputEvents)
}

InputAdapter captures one frame's raw input into events.

Jump to

Keyboard shortcuts

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