-
Notifications
You must be signed in to change notification settings - Fork 220
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
Saveload overhaul #337
Saveload overhaul #337
Conversation
This is the error I'm getting:
|
@torkleyy the problem is in "de.rs" line 129 |
OMG this is such a stupid mistake... Thanks for your help! |
The error message is confusing. I've spotted it by chance. |
src/saveload/de.rs
Outdated
struct DeserializeEntity<'a: 'b, 'b, 's, E, M: Marker, S: 's> { | ||
allocator: &'b mut M::Allocator, | ||
entities: &'b EntitiesRes, | ||
storages: &'s mut S, |
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.
Do you really need different lifetime here?
src/saveload/de.rs
Outdated
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { | ||
write!(formatter, "Sequence of serialized entities") | ||
} | ||
/// Error may occur during serialization or deserialization of component |
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.
during deserialization.
@Xaeroxe is going to continue this PR, so here's what I planned: It turned out that the current code doesn't really allow multiple allocators and has some weird interaction with the marker component storage. Therefore, I've been thinking that it would make sense to put the entity -> marker and marker -> entity mapping both into the allocator (also see these messages on Gitter). You'll likely be using a That's all I remember so far, please feel free to ask if something doesn't make sense. |
Currently looking into simplifying the marker type by stripping away what I feel may be metadata not appropriate to store here. Some examples:
I've removed the |
@Xaeroxe I was also confused by this at the beginning, but @omni-viral said that it can be useful for e.g. a generational id or something. I'm not quite sure about it. |
This metadata may be useful in the right contexts, I just don't think this is the right place to be trying to store and generate it. It should be handled by something with a more clear picture of what exactly it's trying to track. Typically the user, with their own data structures. |
I'm also in favor of simplifying it, I just left it as is because @omni-viral told me so. Let's wait for them to respond. |
I'm all for simplifying. But would it be possible to implement otherwise? |
Can you clarify what you're referring to when you say "it"? |
Network synchronization that checks for sequence id and rejects if entity in packet comes with less sequence id then one already in the world. |
Oh, yes that will definitely be possible. That kind of meta data could be stored in another component that the network system itself queries and writes to. It can exist completely separate from the marker system. |
Ok. And how deserializer would know how to deal with it? |
I don't believe it's the deserializer's job to perform that kind of filtering. It should be handled in the network layer. |
Actually it's not deserializer. It's loader. |
I'm finally getting back to this. I see your point now @omni-viral . If a marker's type is meant to be a semantic detail that controls how the underlying identifier is used during loading I'm no longer sure what we gain from making these not components @torkleyy . Can you please provide a use case where we needed a single marker type to have multiple storages? |
Rebased, review comments addressed, example fixed, formatted with rustfmt 0.3.4-nightly. I think this is ready for review. |
@@ -161,8 +161,7 @@ impl Errors { | |||
#[derive(Derivative)] | |||
#[derivative(Default(bound = ""))] | |||
pub struct Merge<F> { | |||
#[derivative(Default(value = "PhantomData"))] | |||
future_type: PhantomData<F>, | |||
#[derivative(Default(value = "PhantomData"))] future_type: PhantomData<F>, |
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.
Oh, is this some new rustfmt setting again?
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.
Is this attribute necessary at all?
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.
Yes, otherwise F
would have to implement Default
.
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.
No. PhantomData implements default for any type parameter.
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.
It does now but I think it was a rather recent fix which I don't want to rely on yet.
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.
It does at least since 1.0.0
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.
Ahhh, the attribute on PhantomData
isn't required, but we need derivative
here.
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.
LGTM. @Xaeroxe Please squash the commits.
I think it's good as-is, so feel free to merge @WaDelma |
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!
&mut ser, | ||
).unwrap_or_else(|e| eprintln!("Error: {}", e)); | ||
// TODO: Specs should return an error which combines serialization | ||
// and component errors. |
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.
Is this TODO to be left to future PR?
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.
Yes
examples/saveload.rs
Outdated
ReadStorage<'a, U64Marker>, | ||
); | ||
|
||
fn run(&mut self, (ents, pos, vel, markers): Self::SystemData) { |
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.
s/vel/mass/
examples/serialize.rs
Outdated
@@ -48,7 +48,7 @@ fn main() { | |||
let entity_list: Vec<_> = (&*data.entities).join().collect(); | |||
|
|||
// Remove all components | |||
for (entity, _) in (&*data.entities, &data.comp.check()).join() { | |||
for (entity, _) in (&*data.entities, data.comp.mask().clone()).join() { |
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.
Can't you use drain
here?
src/saveload/marker.rs
Outdated
/// Allocator for this `Marker` | ||
type Allocator: MarkerAllocator<Self>; | ||
|
||
/// Get this marker internal id | ||
/// Get this marker internal id. | ||
/// This value may never change. |
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.
As the update method says that changes in return value doesn't cause UB, I think the wording should be relaxed.
Maybe something like: "The value of this method should be constant".
src/saveload/marker.rs
Outdated
fn mark<'m>(&mut self, entity: Entity, storage: &'m mut WriteStorage<M>) -> (&'m M, bool) { | ||
let mut new = false; | ||
|
||
let marker = storage.entry(entity).unwrap().or_insert_with(|| { |
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.
What is with this unwrap
here? Is it expected to not panic? I would change it to expect
that contains explanation.
src/saveload/ser.rs
Outdated
serseq.serialize_element(&EntityData::<M, Self::Data> { | ||
marker: marker.clone(), | ||
components: self.serialize_entity(entity, &ids) | ||
.map_err(ser::Error::custom)?, // TODO: revise |
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.
What does the TODO here mean? If it's still relevant, it should be made more informative.
})?; | ||
} | ||
} | ||
to_serialize = add; |
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.
This code is bit hard to decipher, but I don't know how to improve it.
Also you could reuse to_serialize
and only do two allocations, but I don't know if it's worth it.
src/saveload/storages.rs
Outdated
|
||
// fn join(&'b mut self) -> Self::Join { | ||
// self | ||
// } |
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.
Remove commented code
src/saveload/storages.rs
Outdated
|
||
// fn join(&'c mut self) -> Self::Join { | ||
// &mut **self | ||
// } |
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.
Remove commented code
Not sure why I'm doing this everywhere then.. I'll check later.
|
I had an issue with saveload that crashed on deserialize with |
@LinearZoetrope What kind of crash was that? I never experienced any crashes, so can't say if I fixed them. |
I'll have to retest, but if I recall correctly, it was claiming anything stored in NullStorage wasn't present when deserializing. |
@LinearZoetrope I'll check it and add a test to ensure it's working. |
@torkleyy I believe this is ready to be merged. |
Ok I've just rebased this, it should be ready to merge. Recommend one more review prior to merging, as the rebase kind of aggressively preferred to keep code from this PR where there were conflicts. |
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.
LGTM, but would like another pair of eyes to go over it.
@@ -1,4 +1,4 @@ | |||
#![deny(missing_docs)] | |||
#![warn(missing_docs)] |
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.
So there are missing documentations?
type Data: Serialize; | ||
|
||
/// Serialize the components of a single entiy using a entity -> marker mapping. | ||
fn serialize_entity<F>(&self, entity: Entity, ids: F) -> Result<Self::Data, E> |
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.
s/entiy/entity/
Errors for missing docs make it rather hard to experiment with new features.
|
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.
Thanks!
bors r+
337: Saveload overhaul r=torkleyy a=torkleyy ## TODO * [x] Commit messages need to be improved * [x] There is some weird lifetime error that I don't really understand ## Motivation for this PR * Rename some items to make the code easier to understand * Remove a couple of unnecessary bounds * Allow passing references of storages (previously you could not reuse the `WriteStorage`) --- Fixes #138 Fixes #282 <!-- 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/337) <!-- Reviewable:end --> Co-authored-by: torkleyy <torkleyy@gmail.com> Co-authored-by: Jacob Kiesel <kieseljake@gmail.com>
Build succeeded |
TODO
Motivation for this PR
WriteStorage
)Fixes #138
Fixes #282
This change is