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

Ability to create a query view directly from World #328

Closed
LPGhatguy opened this issue Jul 2, 2023 · 5 comments
Closed

Ability to create a query view directly from World #328

LPGhatguy opened this issue Jul 2, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@LPGhatguy
Copy link

hecs has a great mechanism for random access of a query via views:

let mut query = game.world.query::<(&A, &B, &C)>();
let view = query.view();
let (a, b, c) = view.get(some_entity)?;

It'd be really handy to collapse the calls to query and view into just one call, to avoid needing to create the extra binding.

I think there are a couple good solutions to this problem:

  • A new method, World::view and a new View type that owns its contents
  • Refactoring of QueryBorrow to enable random access
@Ralith
Copy link
Owner

Ralith commented Jul 2, 2023

Refactoring of QueryBorrow to enable random access

This would involve taking the fetch field of View, which is a table with one entry per archetype, and adding it to query, populating it either up front (which adds unnecessary work to normal queries) or lazily (which adds a branch to every random access, the case that views are specifically supposed to optimize). Given those (minor) drawbacks, I think I lean slightly towards paying the modest one-time cost of introducing a new type (perhaps ViewBorrow).

Are you interested in making a PR for this?

@Ralith Ralith added enhancement New feature or request good first issue Good for newcomers labels Jul 2, 2023
@LPGhatguy
Copy link
Author

I'd be interested in working on this feature, but I'm pretty booked for a couple months. If no one else comes along and takes it by then, I can take a look!

@LPGhatguy
Copy link
Author

I created a cursed and unsafe version of this API in the hecs wrapper we have in our engine. We use views a lot, so I think it will be very nice to have.

I'm going to use it for awhile and see whether it's a very large gain. If it is, I'll take a go at implementing it properly in hecs!

@Ralith
Copy link
Owner

Ralith commented Nov 17, 2023

This would incrementally tidy up some of the code I've been writing lately too.

@Ralith
Copy link
Owner

Ralith commented Mar 27, 2024

Fixed by #367.

@Ralith Ralith closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants