github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/ecs/itfc.go (about)

     1  package ecs
     2  
     3  import (
     4  	"github.com/15mga/kiwi/ds"
     5  	"github.com/15mga/kiwi/util"
     6  )
     7  
     8  type IComponent interface {
     9  	Entity() *Entity
    10  	setEntity(entity *Entity)
    11  	Type() TComponent
    12  	// Init 添加到Entity时调用
    13  	Init()
    14  	// Start Entity添加到Scene时调用
    15  	Start()
    16  	Dispose()
    17  }
    18  
    19  type ISystem interface {
    20  	Type() TSystem
    21  	Frame() *Frame
    22  	Scene() *Scene
    23  	FrameBefore() *ds.FnLink
    24  	FrameAfter() *ds.FnLink
    25  	OnBeforeStart()
    26  	OnStart(frame *Frame)
    27  	OnAfterStart()
    28  	OnStop()
    29  	OnUpdate()
    30  	PutJob(name JobName, data ...any)
    31  	DoJob(name JobName)
    32  	BindJob(name JobName, handler util.FnAnySlc)
    33  	BindPJob(name JobName, fn util.FnAnySlc)
    34  	BindPFnJob(name JobName, fn FnLinkAnySlc)
    35  	PTagComponents(tag string, fn func(IComponent)) ([]IComponent, bool)
    36  	PTagComponentsWithParams(tag string, fn func(IComponent, []any), params ...any) ([]IComponent, bool)
    37  	PTagComponentsToFnLink(tag string, fn func(IComponent, *ds.FnLink)) ([]IComponent, bool)
    38  	PTagComponentsToFnLinkWithParams(tag string, fn func(IComponent, []any, *ds.FnLink), params ...any) ([]IComponent, bool)
    39  }
    40  
    41  type IEvent interface {
    42  	Type() TEvent
    43  }
    44  
    45  type (
    46  	TJob         uint8
    47  	FnLinkAnySlc func(*ds.FnLink, []any)
    48  )
    49  
    50  const (
    51  	JobDef TJob = iota
    52  	JobP
    53  	JobPLink
    54  )