zdandoh / ecs

Golang ECS library using go generate
MIT License
5 stars 0 forks source link

Relationships #5

Open delaneyj opened 8 months ago

delaneyj commented 8 months ago

Flecs relationships are crazy powerful.

https://www.flecs.dev/flecs/md_docs_2Relationships.html

Would be interested in how to generate version of this.

zdandoh commented 8 months ago

Certainly seems like a cool feature, but I'm not really sure how I'd implement this in a performant manner. Any ideas?

delaneyj commented 8 months ago

So the way flecs works it all IDs are 8 bytes.
For entity & components IDs you have [index 32][generation 16] But for relationships its [fromIndex 32][toIndex 32] that allows one->many.
If that was a pair of bitsets you could do fast queries on all toIndex for a given fromIndex.

https://ajmmertens.medium.com/building-games-in-ecs-with-entity-relationships-657275ba2c6c

zdandoh commented 8 months ago

Can you explain in more depth, it seems like you'd get non-sequential entity ids the way you're proposing

zdandoh commented 8 months ago

Ah, I found https://ajmmertens.medium.com/doing-a-lot-with-a-little-ecs-identifiers-25a72bd2647 The tl;dr is that yes, your storage must be able to handle non-sequential ids.

zdandoh commented 8 months ago

I added some experimental support for relationships. The current implementation is pretty heavy since it relies on allocating at runtime, but I think it's still a nice to have. Take a look at TestRelationship if you're interested in the details. It's got some nice syntactic sugar and conditional codegen depending on whether the relationship has associated data.