1 package gohan 2 3 import ( 4 "errors" 5 6 "github.com/hajimehoshi/ebiten/v2" 7 ) 8 9 // System represents a system that runs continuously. 10 // 11 // Systems may specify any number of required components by adding public 12 // fields to their struct. When no required components are specified, the 13 // system will run for every active entity. 14 // 15 // While systems must implement the Update and Draw methods, the special error 16 // value ErrUnregister may be returned at any time by systems to indicate the 17 // method returning the error should not be called again. 18 // 19 // Systems do not need to implement locking to prevent race conditions between 20 // Update and Draw methods. Ebitengine calls only one of these methods at a time. 21 type System interface { 22 // Update is called once for each matching Entity each time the game state is updated. 23 Update(e Entity) error 24 25 // Draw is called once for each matching Entity each time the game is drawn to the screen. 26 Draw(e Entity, screen *ebiten.Image) error 27 } 28 29 // ErrUnregister is a special error value which may be used to unregister a 30 // system from Draw or Update events. 31 var ErrUnregister = errors.New("unregister system") 32