-
Notifications
You must be signed in to change notification settings - Fork 41
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
Support for Custom Checksum Methods #85
Conversation
This is perhaps a more overarching change, but I was wondering if it would make sense to have traits for a type's preferred way of doing rollback and checksum. e.g. We would then have extension method We can implement it for bevys built in types. And users could implement it for their own types. Due to the orphan rule, there are still cases where we need We could also implement the trait for glam types, like #[derive(RollbackCheksum)]
struct Foo {
vel: Vec3, // we've implemented it for Vec3, no annotations needed
#[checksum(Hash)]]
baz: PeerId,
#[checksum(ignore)]
internal_computed: u32
} Just wanted to share my thoughts on it. |
3a64040
to
0705051
Compare
I do like the idea of a trait describing the checksum, but I think Rust's orphan rule and specialisation rules would get in the way of a really useful trait, beyond the current |
That's not possible i think. I have some ideas for how to do this with a minimum of boiler plate, but perhaps it's better to discuss it over an actual pr, I'm hoping i get some time to work on it in a couple of weeks. In the meantime, this pr is a step up over the current state, and would be great in the bevy 0.12 release. |
Agreed! In my opinion, we should merge #80 and this PR before doing the next release (together with ggrs). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me!
Objective
As identified by @johanhelsing (and now experienced by myself in my own project!), it is currently quite cumbersome to add checksums for 3rd party types which did not already implement
Hash
. It is entirely possible, but it requires a substantial amount of boilerplate compared to types which implementHash
. Ideally, users could provide a custom method to map!Hash
types into a checksum value.Solution
I've modified the
ComponentChecksumHashPlugin
andResourceChecksumHashPlugin
plugins to take a parameter,hasher
, which is a function describing how to hash the desired type. By default,hasher
is a function usingHash
if implemented:To add to the ergonomics, I've extended
GgrsApp
to directly accept this custom hashing method as an alternate method:Notes
I've made this branch based off of my #83 for testing purposes, but these changes could be easily ported to any alternate Bevy 0.12 upgrade branch as required.