Customize entity ID selection #7898
Unanswered
klausenfeld
asked this question in
Q&A
Replies: 2 comments
-
Well, @cart, I would really like to read your messages on discord. However, discord hates my mail server and I will not give it my phone number for validation since it will just become further material for its hatred. I only have one phone number ... |
Beta Was this translation helpful? Give feedback.
0 replies
-
This idea doesn't work because bevy generally wants to keep entity metadata in a vector, indexed by the entity index. Maybe I can add a translation table between my coordinates and the entity indices. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to manually partition the entity ID space. I don't really care about generations for many of my entities. If I despawn an entity of ID X and re-create it later, I'm OK with re-using the same ID and reviving all references to it (which won't exist). Most importantly, I want to encode spacial coordinates into some of the ID space. I have a tiled map which should have an entity for each tile that's currently alive. If I could map spacial coordinates directly into the entity ID space, I could easily find neighbors to a given tile, without storing and managing explicit references.
Furthermore I have several sets of entities which I want to iterate in a stable order. That can be achieved by building a linked list on top of the entities using components, but that looks silly to me. I could just partition off a bit of ID space and choose consecutive IDs from that.
In more concrete terms, I want IDs that consist of maybe 4 bits of descriptor to encode the entity "category", and then either 28 or 60 bits of actual ID, depending on whether I want to use generations for those particular IDs or not. The 60 bits could be split into 20/20/20 for x/y/z on entities of category "tile". That should be enough for a long time. There will be a category "everything else". 15 special categories should be enough.
Now there is Entity::from_bits() and Commands::get_or_spawn(). These would probably be good enough for what I want. Both come with big bold warnings, though. Even Entity::from_raw() is apparently frowned upon and that would only give me 32 bits of ID space.
So, is this idea abhorrently evil? Is there a better way to achieve what I want?
Beta Was this translation helpful? Give feedback.
All reactions