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

Serialization #1

Closed
AlexEne opened this issue Jun 6, 2020 · 4 comments
Closed

Serialization #1

AlexEne opened this issue Jun 6, 2020 · 4 comments

Comments

@AlexEne
Copy link

AlexEne commented Jun 6, 2020

First, thanks for doing this, It's a super useful crate.

What are your thoughts on having serialization/deserialization as part of goggles (maybe behind a feature flag) ?
It may go against the original design of having something that's as simple as possible.

Right now, it's possible to provide serialization / deserialization through serde's trick of implementing it for external types, but that's a bit of a hack as it involves relying on the internal structure of certain data types and duplicating it in another crate for the purpose of implementing the serialization.
https://serde.rs/remote-derive.html

I know you mentioned on reddit that you also have a minimal-ECS that's implemented on top of goggles, maybe that's a better place to integrate with serde.

@kyren
Copy link
Owner

kyren commented Jun 6, 2020

I would be okay with implementing Serialize / Deserialize for specific types, but in my opinion a full serialization of a world with entities is just out of scope. I've implemented a serialization system in a pretty complex project that uses goggles, and naively trying to serialize every resource and every entity and every component breaks down really quickly. specs' serialization system was too simplistic and it was one of several parts of specs that I ended up just ignoring.

Now that I think about it, I'm not even sure there are any types in goggles where implementing Serialize / Deserialize is even a good idea. Maybe I'm not thinking of something, what are you using remote-derive to serialize?

@AlexEne
Copy link
Author

AlexEne commented Jun 6, 2020

So for me it's the Entity type. Right now I just forked this and added #[derive(Serialzie, Deserialize)] to it. I don't think there are many places besides that.

I am in the process of porting from my custom, messy, ECS to goggles so other things might pop-up, but until now it's just the Entity,

@kyren
Copy link
Owner

kyren commented Jun 6, 2020

I was thinking it might have been Entity. You definitely don't want to serialize Entity at least without also serializing the entity Allocator, and if you do that you usually end up serializing some unique ID per entity and then just re-creating Entity on load. AFAICT that's what the specs serialization system does as well (Marker and MarkerAllocator). If you only serialize / deserialize Entity, then you will end up allocating conflicting entities after a load. An Entity is an allocation of an index for some specific Allocator that exists in memory, that's why there's not a way to just create an Entity from an index and a generation.

I'm sure there are different entity allocation strategies that might be more amenable to direct serialization, and if so, you can still use the rest of goggles and make your own World and Entity types.

@AlexEne
Copy link
Author

AlexEne commented Jun 6, 2020

You're right :).

@AlexEne AlexEne closed this as completed Jun 6, 2020
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

No branches or pull requests

2 participants