-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Hi,
thanks for all your work, having a lot of fun here using ecs & engo :)
One of the most boring, mistakable, and kind of dirty stuff is the registering process of a system.
Usually, we go to a code like that:
rsys := &common.RenderSystem{}
var r *common.Renderable
var notr *common.NotRenderable
w.AddSystemInterface(rsys, r, notr)
I would like to add a method to World in order to simplify this process (before, just an idea, can PR a complete work):
// didn't check the code, just the idea
type SomeSystem() {}
func(*SomeSystem) Add(basic *ecs.BasicEntity, space *common.SpaceComponent, component *BulletComponent) {}
func(*SomeSystem) Remove(basic ecs.BasicEntity) {}
func(s *SomeSystem) AutoRegister(w *ecs.World) {
var able *SomeSystemAble
var notAble *NotSomeSystemAble
w.AddSystemInterface(s, able, notAble)
}
type Registerable interface {
AutoRegister(w *ecs.World)
}
func (w *ecs.World) AutoRegisterSystem(r Registerable) *ecs.World {
r.AutoRegister(w)
}
func (w *ecs.World) AutoRegisterSystem(r Registerable) *ecs.World {
w.append(w.toBeRegistered, r)
}
world.AutoRegisterSystem(&SomeSystem{})The idea is to delegate the registration process to the system... this can be done in multiple ways like above. Another interesting way can be done by using directly the method "AutoRegister" on the system but I think it's better to define an interface and delegate the registration to World.
This is what I currently do (with a decorator but the idea is here).
Feedback appreciated
Metadata
Metadata
Assignees
Labels
No labels