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 ¶
- Variables
- type DefaultController
- type DesktopAdapter
- type Engine
- func (e *Engine) Draw(screen *render.Image)
- func (e *Engine) Frame() error
- func (e *Engine) Init() error
- func (e *Engine) Issue(cmd command.Command) error
- func (e *Engine) Layout(outsideWidth, outsideHeight int) (int, int)
- func (e *Engine) Load(stage, slot string) error
- func (e *Engine) Pause()
- func (e *Engine) Paused() bool
- func (e *Engine) Persistence() game.Persistence
- func (e *Engine) Props() game.Props
- func (e *Engine) Quit()
- func (e *Engine) Resume()
- func (e *Engine) Run()
- func (e *Engine) Save(slot string) error
- func (e *Engine) SwitchStage(name string) error
- func (e *Engine) TPS() *game.TPS
- func (e *Engine) ToggleFullscreen()
- func (e *Engine) TogglePause()
- func (e *Engine) Update() error
- type HandlerFn
- type InputAdapter
Constants ¶
This section is empty.
Variables ¶
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)
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 (*Engine) Draw ¶
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
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) Issue ¶ added in v0.3.0
Issue gives cmd as nobody to whoever carries it out in the active Stage.
func (*Engine) Layout ¶
Layout is the screen's size: the Props' fixed one, or with Resizable the window's.
func (*Engine) Load ¶ added in v0.3.0
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) Persistence ¶
func (e *Engine) Persistence() game.Persistence
Persistence returns the active Stage's Save/Load/List surface.
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
Save saves the active Stage in the save slot, "" the quicksave, where Props.Saves says.
func (*Engine) SwitchStage ¶
SwitchStage requests a transition to the Stage called name, made at the start of the next Update.
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()
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.