Serialize/deserialize world state? #544
Replies: 7 comments 41 replies
-
Hello! Thank you for considering PlayRho for this! Sounds like you have two questions:
Here's some info on these questions: Regarding serialization and deserialization: Assuming you want to be able to copy state across restarting the program or the computer, the short answer is that's not already supported. Longer... As you found, PlayRho fully supports value semantics of actions like copying and equality-checking. So if all you want is to be able to rollback at any point in an application's lifetime, that should work just by saving the copies in memory. If you want to make a copy that you can reload after stopping the program however, then that state needs to be stored somehow across that restart. Assuming like a full shutdown, that of course pushes matters to using a persistent storage mechanism and it sounds like that's the realm you're wanting support in. PlayRho doesn't have code already to do this. Is there a particular format like XML or JSON that you'd prefer to serialize/deserialize from/to? If I put aside other projects, I could whip up code for a standard format probably in like a week. Not sure I can put the other ones aside though. In any case, I'd probably do it as a separate GitHub repo/project that depends on PlayRho and an external open source library that supported that format. It shouldn't need internal access to Regarding determinism of PlayRho: PlayRho is just as deterministic as Box2D. And, like Box2D, has the exception of floating point math across different hardware. PlayRho, unlike Box2D, was designed to support using a fixed-point type however for its
I have code for such a fixed-point type and library, but it's not production quality. I'd made it originally just to test out what it'd take to have the Improving realnumb to the point I'd call it "production ready", would probably take me around 3+ weeks, and that wouldn't address its slower speed. To my knowledge, there's not another implementation of a fixed-point type & library that fully satisfies both of these requirements. If you can find one however, that'd probably be your better option. |
Beta Was this translation helpful? Give feedback.
-
Makes sense to me as well. I had been thinking of serializing to an ASCII format, like JSON as I'd mentioned. But serializing to a binary format like byte arrays seems more sensible for performance.
Yes. The master branch code is where the active development head is and I intend to make a 2.0 release from it. I think it's ready, or close to it. I'd like to get some more testers of it before making that however.
You may have thought more about this by now than I have. For a full state transfer, I'd start by looking at the state that the world instance holds. That'd be in the implementation code in I'm not sure that all the necessary state can be accessed via public member functions and non-member functions. But I'm of the opinion that it should be. Anything missing that way I'd be more inclined to address in the master branch. Some of the world state is cached state which shouldn't need to be serialized. I'm of the opinion that the state that's important for serialization would be the same state that'd be important for determining equality and vice versa. I'm also of the opinion that the master branch code for this - see bool operator==(const AabbTreeWorld& lhs, const AabbTreeWorld& rhs) noexcept - is better in this regard.
I love For a Rust-like traits interface, I'm of the opinion that what I call "polymorphic value types", are more ideal. And shapes are accessed via Incidentally, I have been thinking about the
Hmm... hadn't thought about it this way before. The compositor has been an experiment with compile-time shapes for reducing memory overhead for common shapes. I think it'd make more sense though if PlayRho merged the
I'm not sure. I guess that'd depend mostly on what you mean. I don't have objection to your doing what's most convenient for you. If you're asking whether there's any technical issue with like contributing back such work if it's done with the same git repo of code (instead of as a separate repo that was dependent on the library component), you may already know the answer to that better than I at this point. I think ultimately I'd need to see the code for what you mean to speak more articulately to this. That sounds like it might be a bit of a catch-22 or chicken and egg problem though. |
Beta Was this translation helpful? Give feedback.
-
That's what I've done too. See Testbed/Framework/Main.cpp for example. |
Beta Was this translation helpful? Give feedback.
-
I agree. Yes. I'd prefer to see code like shown at cppreference.com for std::visit: std::visit(overloaded{
[](auto arg) { std::cout << arg << ' '; },
[](double arg) { std::cout << std::fixed << arg << ' '; },
[](const std::string& arg) { std::cout << std::quoted(arg) << ' '; }
}, v); With the right template magic, I wonder if something like I did look into using Perhaps the answer at code review for this could provide guidance on how to do this. As perhaps something of a hack, I suppose a map type could be used. That'd give us more like the syntax we want. It also wouldn't be a linear search. Though performance wise, I'd guess it'd be a loss to using if-else-statements. |
Beta Was this translation helpful? Give feedback.
-
As for recreating Incidentally, have you tried serializing/deserializing without doing so for the |
Beta Was this translation helpful? Give feedback.
-
I've created a "Support serialization/deserialization" project for this for me to help track changes for this.
Copying worlds is supported and tested, but recreating them from their components per anything like serialization and deserialization is another matter I'm realizing. I don't know of a reason why it would not be technically feasible to get this to work however. Moreover, I'd really like to get this working and unit test proven. |
Beta Was this translation helpful? Give feedback.
-
@louis-langholtz Hello again, thanks for asking! Yes, I don't think I've seen any other issues so it seems to be working! We are currently working on developing our multiplayer game with this technology. I'll write you back when it's published :) |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I'm working on a Rollback Netcode engine and I'm currently looking for a physics engine for a test game that has the capability to completely serialize its state so that it can be stored and restored if needed at any time.
I was previously looking at Box2D but quickly found that making a 100% accurate copy of the World was impossible, so I found this engine instead! It's amazing that the world can be so easily cloned, good work on this! However, for my application to work I need to be able to store the copies as a flat byte array and then be able to parse them back to a World object. This is because the Rollback engine is designed to be generalizable to any game state while also needing to be able to send the entire state over the internet.
My question is therefore: is this something that by chance is already supported by PlayRho, or, if it isn't currently supported, would it be technically feasible to implement it?
Another thing I'm wondering regards the determinism of the engine. I've read the Box2D is deterministic with the exception of floating point errors on different architectures. Is there an option in PlayRho to use fixed-point math only?
Very thankful for any help I can get with this, and happy to explain further what I'm working on.
// Alex
Beta Was this translation helpful? Give feedback.
All reactions