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

Add the ability to interpret the same buffer with different Voxel traits #4

Merged
merged 1 commit into from Feb 13, 2022

Conversation

dcz-self
Copy link
Contributor

Fixes #3 .

I don't really like it a lot, with the references' lifetimes messing up the newtypes. At least in practice when voxels mostly impllement Copy, this only means a lifetimed From is needed (see example).

@dcz-self dcz-self mentioned this pull request Jan 18, 2022
Copy link
Contributor

@BGR360 BGR360 left a comment

Choose a reason for hiding this comment

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

Just passing by

Comment on lines 23 to 24
name = "reinterpret"
path = "reinterpret/main.rs"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use a more descriptive name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you propose?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm... maybe multiple_views. Or mirror the name of the function and call it with_cast.

src/lib.rs Outdated
Comment on lines 100 to 108
fn is_empty(&self) -> bool {
self.0.is_empty()
}
fn is_opaque(&self) -> bool {
self.0.is_opaque()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add #[inline] hints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know much about inlining, so I'll leave that decision to someone else.

Copy link
Owner

Choose a reason for hiding this comment

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

General guidance is here: https://nnethercote.github.io/perf-book/inlining.html

My policy has been to #[inline] very short functions that might get called in a tight loop. It's just a suggestion to the compiler, and the compiler might decide it's a bad idea to inline a particular function, and I'm OK trusting the compiler's decision in most cases.

Copy link
Owner

Choose a reason for hiding this comment

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

So I think inlining these trait methods makes sense. Pushing and popping a stack frame in either of these functions would be bad for performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/simple.rs Outdated
@@ -17,6 +18,31 @@ pub fn visible_block_faces<T, S>(
) where
T: Voxel,
S: Shape<u32, 3>,
{
visible_block_faces_with_cast::<_, IdentityVoxel<T>, _>(
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure "cast" is the proper term for this. Maybe _with_voxel_view or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Owner

@bonsairobo bonsairobo left a comment

Choose a reason for hiding this comment

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

I'm not sure it's necessary to have such a large example for this feature. Maybe just a doc test showing a very simple call to visible_block_faces_...

@bonsairobo
Copy link
Owner

I would merge the first patch, but I don't think we need a new example (with bevy and all) for this. Feel free to add a doc test for the new function though.

@dcz-self
Copy link
Contributor Author

Rebased. I skipped the doctest, however.

@bonsairobo bonsairobo merged commit ad3e172 into bonsairobo:main Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Voxel trait inflexible
3 participants