-
Notifications
You must be signed in to change notification settings - Fork 76
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
build a map of entity iid to EntityInstance during asset load #192
Conversation
Thanks for the contribution! This is actually extremely similar to something I've been thinking about doing but haven't gotten around to - and I would prefer to implement just one of these solutions. My thought was to basically create a resource that maps entity iids to to that entity's indices in the asset. I was also thinking, in conjunction with this, there could be an #[derive(Clone, Debug, PartialEq, Eq, Hash, Deref, Component)]
pub struct EntityIid(String);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct LdtkEntityIndices {
world_index: usize,
level_index: usize,
layer_index: usize,
entity_index: usize,
}
#[derive(Clone, Debug, PartialEq, Eq, Resource)]
pub struct LdtkEntityIndex {
map: HashMap<Handle<LdtkAsset>, HashMap<EntityIid, LdtkEntityIndices>>,
}
#[derive(Clone, Debug, SystemParam)]
pub struct LdtkIndexer {
assets: Res<Assets<LdtkAsset>>,
index: Res<LdtkEntityIndex>
}
impl LdtkIndexer {
// pub methods that provide convenient access *by reference* to levels, layers and entity instances for a given entity
// some methods could be `_single()` and assume only one LdtkAsset exists since this is true for most users
} The idea is that we won't be copying a decent sized type like We could also maybe store an What are your thoughts on this - do you think it would help you lookup entities in your use case? |
The approach you've suggested makes sense to me and would enable me to do what I need to. I think as a starting point just having an Are you looking for contributions in this area? I quickly threw up these PRs yesterday to kick off some discussions as I couldn't see a Perhaps the |
Sorry for the lack of |
Having quickly implemented adding That said, with the lookup approach then |
Simply to allow easier lookup for entities, e.g. from
EntityRef
fields.It's a little brute-force and ideally the map should probably be a
HashMap<String, &EntityInstance>
to stop cloning theEntityInstance
butbevy
wasn't a fan of the lifetime - I also thought it was technically self-referencial but the compiler didn't seem upset by it.It might be worth turning them into
Handle
s but that seems a little overkill as there could be a lot inside a map and then it gives you the lookup againstAssets<Handle<EntityInstance>>
in any system that wants to use it.