2021-11-19 04:13:28 +00:00
|
|
|
package gohan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
)
|
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
// System represents a system that runs continuously.
|
2021-11-19 04:13:28 +00:00
|
|
|
//
|
2022-02-10 20:21:03 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2022-02-01 04:07:55 +00:00
|
|
|
// 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
|
2022-06-13 09:45:51 +00:00
|
|
|
// Update and Draw methods. Ebitengine calls only one of these methods at a time.
|
2021-11-19 04:13:28 +00:00
|
|
|
type System interface {
|
2021-12-08 03:20:36 +00:00
|
|
|
// Update is called once for each matching Entity each time the game state is updated.
|
2022-06-11 00:44:51 +00:00
|
|
|
Update(e Entity) error
|
2021-11-19 04:13:28 +00:00
|
|
|
|
2021-12-08 03:20:36 +00:00
|
|
|
// Draw is called once for each matching Entity each time the game is drawn to the screen.
|
2022-06-11 00:44:51 +00:00
|
|
|
Draw(e Entity, screen *ebiten.Image) error
|
2021-11-19 04:13:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:21:03 +00:00
|
|
|
// ErrUnregister is a special error value which may be used to unregister a
|
|
|
|
// system from Draw or Update events.
|
2022-02-01 04:07:55 +00:00
|
|
|
var ErrUnregister = errors.New("unregister system")
|