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

Adds way of getting components of specific entity #299

Merged
merged 5 commits into from
Dec 22, 2017

Conversation

WaDelma
Copy link
Member

@WaDelma WaDelma commented Nov 14, 2017

After randomly browsing through rhusics I noticed piece of code and thought about API that would make it cleaner/more efficient and this is the result.

The code in question after this PR:

let (left_shape, left_pose, left_next_pose) =
    (&shapes, &poses, &next_poses).join().get(left_entity, &entities).unwrap();

let (right_shape, right_pose, right_next_pose) =
    (&shapes, &poses, &next_poses).join().get(right_entity, &entities).unwrap();

Depends on amethyst/hibitset#20


This change is Reviewable

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niice!

src/join.rs Outdated
impl<J: Join> JoinIter<J> {
/// Allows getting joined values for specific entity.
pub fn get(&mut self, e: Entity) -> Option<J::Type> {
if self.keys.contains(e.id()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it again, maybe we should have a note saying you need to check if the entity is alive prior to doing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's something I missed but spotted in your code later @Aceeri :P Somehow I'm more picky on Gitter I guess ^^

@WaDelma I think it would be preferable to just use Index as parameter instead of Entity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would Index be preferred? Only thing that uses it is UnprotectedStorage which is not something normal library user would touch and all user facing API uses Entity.

So the problem with dead entities is that if the index is reused it would get that one instead of returning None? I would change it to check the liveliness then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change it to check the liveliness then.

But that would require to pass Entities.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entities or World depending where it's being called.

I just don't know if it's good idea to leave this for the user to check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the entities from the world.

If it's a good idea, not sure, but it's better than using an entity without upholding the imposed guarantee.

src/join.rs Outdated
if self.keys.contains(e.id()) {
Some(unsafe { J::get(&mut self.values, e.id()) })
pub fn get(&mut self, entity: Entity, entities: &Entities) -> Option<J::Type> {
if self.keys.contains(entity.id()) && entities.is_alive(entity) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we at least also provide an _unchecked variant?

@torkleyy
Copy link
Member

torkleyy commented Dec 6, 2017

Also, please resolve the Cargo.toml conflict.

@WaDelma
Copy link
Member Author

WaDelma commented Dec 6, 2017

What I should change Cargo.toml to? The change to hibitset that this needs hasn't landed yet.

@torkleyy
Copy link
Member

Reviewed 1 of 3 files at r4.
Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions.


src/join.rs, line 256 at r4 (raw file):

    /// 
    /// This method doesn't check if the entity is alive, so it should only be used if it actually is.
    pub fn get_unchecked(&mut self, entity: Entity) -> Option<J::Type> {

Logically this still gets the joined value for a given index, not an entity. Please change the parameter type and the documentation accordingly.


Comments from Reviewable

@torkleyy
Copy link
Member

:lgtm: Thank you, I didn't see that you added another commit. Sorry for the delay!

bors r+


Reviewed 2 of 3 files at r4.
Review status: 2 of 3 files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

bors bot added a commit that referenced this pull request Dec 22, 2017
299: Adds way of getting components of specific entity r=torkleyy a=WaDelma

After randomly browsing through [rhusics](https://github.com/Rhuagh/rhusics) I noticed [piece of code](https://github.com/Rhuagh/rhusics/blob/259ff9e4ea61e98919472ea9ac77005177301c1d/src/ecs/collide/systems/spatial_collision.rs#L178) and thought about API that would make it cleaner/more efficient and this is the result.

The code in question after this PR:
```rust
let (left_shape, left_pose, left_next_pose) =
    (&shapes, &poses, &next_poses).join().get(left_entity).uwnrap();

let (right_shape, right_pose, right_next_pose) =
    (&shapes, &poses, &next_poses).join().get(right_entity).uwnrap();
```

Depends on amethyst/hibitset#20

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/slide-rs/specs/299)
<!-- Reviewable:end -->
@torkleyy
Copy link
Member

Reviewed 1 of 1 files at r5.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@bors
Copy link
Contributor

bors bot commented Dec 22, 2017

Build succeeded

@bors bors bot merged commit 41c7ed5 into amethyst:master Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants