gohan/system.go

32 lines
1.1 KiB
Go

package gohan
import (
"errors"
"github.com/hajimehoshi/ebiten/v2"
)
// System represents a system that runs continuously.
//
// Systems may specify any number of required components by adding public
// fields to their struct. When no required components are specified, the
// system will run for every active entity.
//
// While systems must implement the Update and Draw methods, the special error
// value ErrUnregister may be returned at any time by systems to indicate the
// method returning the error should not be called again.
//
// Systems do not need to implement locking to prevent race conditions between
// Update and Draw methods. Ebitengine calls only one of these methods at a time.
type System interface {
// Update is called once for each matching Entity each time the game state is updated.
Update(e Entity) error
// Draw is called once for each matching Entity each time the game is drawn to the screen.
Draw(e Entity, screen *ebiten.Image) error
}
// ErrUnregister is a special error value which may be used to unregister a
// system from Draw or Update events.
var ErrUnregister = errors.New("unregister system")