Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World System "auto-register" #54

Open
merlindorin opened this issue Mar 9, 2022 · 1 comment
Open

World System "auto-register" #54

merlindorin opened this issue Mar 9, 2022 · 1 comment

Comments

@merlindorin
Copy link

merlindorin commented Mar 9, 2022

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

@Noofbiz
Copy link
Member

Noofbiz commented May 4, 2022

Yeah, one thing I don't like about the add by interface method is how bad that looks. The good news is that go 1.18 is adding generics, which will provide a way to do all the add by interface stuff without all the current complexity. I'll probably end up doing something like AddGenericSystem(s System) that will hopefully end up replacing all that with just a single line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants