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

The scene must be initialized in a certain order #1

Open
sedyh opened this issue May 13, 2022 · 0 comments
Open

The scene must be initialized in a certain order #1

sedyh opened this issue May 13, 2022 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@sedyh
Copy link
Owner

sedyh commented May 13, 2022

Problem

At the moment, scene initialization should always go in the order: components > systems > entities. Otherwise, they will not find each other.

type Game struct{}

func (g *Game) Setup(w engine.World) {
    w.AddComponents()
    w.AddSystems()
    w.AddEntities()
}

Solution

It is necessary to correct this behavior by replacing the functions of adding all parts with a builder that will automatically initialize at the very end of the scene creation.

func (w *world) AddComponents(components ...interface{}) {
	w.futureComponents = append(w.futureComponents, components...)
}
func (w *world) AddSystems(systems ...interface{}) {
	w.futureSystems = append(w.futureSystems, components...)
}
func (w *world) AddEntities(entities ...interface{}) {
	w.futureEntities = append(w.futureEntities, components...)
}
func (w *world) ChangeScene(next Scene) {
	next.Setup(w)
        w.buildScene()
}
@sedyh sedyh added bug Something isn't working good first issue Good for newcomers labels May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant