yohamta / donburi

Just another ECS library for Go/Ebitengine
https://pkg.go.dev/github.com/yohamta/donburi
Other
232 stars 21 forks source link

Query entities ordered by entity id #139

Open etareduction opened 2 weeks ago

etareduction commented 2 weeks ago

I'm using donburi.Entity type (entity ids) to reference entities in components. Having an ability to order entities by their id would be useful to join two entity sets.

yohamta commented 2 weeks ago

Hi, I am not sure if I fully understand the idea. Could you please elaborate a bit more about what makes joining two entity sets necessary?

etareduction commented 2 weeks ago

Hi, I am not sure if I fully understand the idea. Could you please elaborate a bit more about what makes joining two entity sets necessary?

I like to build my ECS systems in a relational manner. My current project involves multiple expandable sets of entity archetypes like resource, storage and ship/island. All of the entities have to reference each other in some way, and some of my systems have to work on multiple of them at once (to work with storages i have to retrieve referenced resources). That's why I'm trying to figure out performant implementation of relational joins for donburi entities.

etareduction commented 1 week ago

I've skimmed through the implementation and saw that calling World.Entry() with entity id is basically free. I guess that covers most of my needs.

yohamta commented 1 week ago

Thank you for the detailed explanation. I think one solution could be to add a component to handle relationships. Implementing components for 1:N and N:N relationships could provide the functionality needed to manage entity references. What do you think?

etareduction commented 1 week ago

Thank you for the detailed explanation. I think one solution could be to add a component to handle relationships. Implementing components for 1:N and N:N relationships could provide the functionality needed to manage entity references. What do you think?

Making a relation component like that is not a problem for me:

type Owner struct {
    Entity donburi.Entity
}

What seems missing is some helper functions for querying such relational data. Bevy engine probably has an API like that if I remember correctly, maybe i could find and link it here later.

If implementing generic relation components in donburi (if that's what you meant) would help making an API for querying joined entity sets then I'm all for it.

yohamta commented 4 days ago

Thank you for the suggestion. Integrating a built-in relationship component with Query is indeed a great idea. Currently, we only support features/hierarchy. Developing a relationship feature similar to Bevy is certainly worth considering.