Documentation
¶
Overview ¶
Package inputsys connects an input.Router to an ecs World: InputSystem updates the router once per tick and publishes it as a resource, and TouchControlsExtract draws the virtual touch controls. game.Engine adds both; wire them by hand when using the low-level packages.
Index ¶
Constants ¶
const TouchLayer int16 = 32766
TouchLayer is the layer the virtual touch controls are drawn on: above the game, below debug shapes.
Variables ¶
This section is empty.
Functions ¶
func RegisterLoaders ¶
RegisterLoaders makes bindings files ("input/bindings.json") loadable on srv, validated against acts. The placeholder is empty bindings, so a handle that is loading or failed binds nothing. It panics with "input: RegisterLoaders: nil Actions" or "input: RegisterLoaders: Actions not frozen", and like asset.Register if it runs twice on srv.
Types ¶
type BindingsHandle ¶
BindingsHandle refers to compiled input.Bindings loaded through the asset system. It is 8 bytes, comparable and pointer-free; the zero value means "none". No component holds one, so it lives here rather than in gfx.
func LoadBindings ¶
func LoadBindings(sc *asset.Scope, key string) BindingsHandle
LoadBindings returns the handle for a bindings file and adds a hold for sc. It never blocks and panics like asset.Load.
func LoadBindingsSync ¶
func LoadBindingsSync(sc *asset.Scope, key string) (BindingsHandle, error)
LoadBindingsSync is LoadBindings followed by loading until the file is ready or failed, like asset.LoadSync. It blocks.
type BindingsStore ¶
type BindingsStore struct {
// contains filtered or unexported fields
}
BindingsStore resolves BindingsHandle values. It is a small value; copy it freely.
func BindingsStoreOf ¶
func BindingsStoreOf(srv *asset.Server) BindingsStore
BindingsStoreOf returns the bindings store of srv. It panics like asset.StoreOf if RegisterLoaders has not run on srv.
func (BindingsStore) Err ¶
func (s BindingsStore) Err(h BindingsHandle) error
Err returns why the file failed to load, or nil.
func (BindingsStore) Get ¶
func (s BindingsStore) Get(h BindingsHandle) *input.Bindings
Get returns the bindings, or the empty placeholder; see asset.Store.Get for the pointer validity rule.
func (BindingsStore) Lookup ¶
func (s BindingsStore) Lookup(h BindingsHandle) (*input.Bindings, asset.State)
Lookup is Get plus the load state.
func (BindingsStore) Ready ¶
func (s BindingsStore) Ready(h BindingsHandle) bool
Ready reports whether h refers to loaded bindings.
func (BindingsStore) Version ¶
func (s BindingsStore) Version(h BindingsHandle) uint32
Version changes whenever the asset is committed again (first load, and hot reload once the asset system has it).
type InputSystem ¶
type InputSystem struct {
// OnError receives the load error of the watched bindings. nil logs it.
OnError func(error)
// contains filtered or unexported fields
}
InputSystem runs input.Router.Update once per tick. Add it first in the input stage, so every later system in the tick reads the same action state.
Init publishes the World resources *input.Router and *input.Events (the Router's events, reused every tick).
With InputSystem.Watch it also follows a bindings asset: whenever the asset is committed (first load, and reloads), the router gets the new default bindings before the tick's Update. A file that fails to load is reported once through OnError and the router keeps its bindings.
func New ¶
func New(r *input.Router) *InputSystem
New returns the system for r. Panics with "input: " if r is nil.
func (*InputSystem) Init ¶
func (s *InputSystem) Init(ctx *system.Context)
Init implements system.Initializer.
func (*InputSystem) Router ¶
func (s *InputSystem) Router() *input.Router
Router returns the router the system updates.
func (*InputSystem) Watch ¶
func (s *InputSystem) Watch(srv *asset.Server, h BindingsHandle)
Watch makes the system apply the bindings asset h whenever it becomes ready or is committed again. srv must have the input loaders (RegisterLoaders); Watch panics like BindingsStoreOf otherwise. A second call replaces the watched handle.
type TouchControlsExtract ¶
type TouchControlsExtract struct {
// Color and PressedColor are the outline colors. Zero means a
// translucent white and opaque white.
Color, PressedColor gfx.Color
// AlwaysShow draws the controls whatever the active device.
AlwaysShow bool
// contains filtered or unexported fields
}
TouchControlsExtract draws the touch regions of the player that owns the touch screen as screen-space outlines: rectangles and circles, a stick as its base plus a knob. It draws nothing while that player's active device is not the touch screen, so the controls appear on the first touch and disappear when a keyboard or pad is used, unless AlwaysShow is set.
Add it to the render stage after extract.ResetQueue. It needs the *render.Queue resource and the *input.Router resource that InputSystem.Init publishes, so it must be initialized after it.
func NewTouchControlsExtract ¶
func NewTouchControlsExtract() *TouchControlsExtract
NewTouchControlsExtract returns the system.
func (*TouchControlsExtract) Init ¶
func (s *TouchControlsExtract) Init(ctx *system.Context)
Init implements system.Initializer.
func (*TouchControlsExtract) Run ¶
func (s *TouchControlsExtract) Run(*system.Context)
Run implements system.Runner.