Maintaining the same object id:s after deserialization #576
Replies: 1 comment 5 replies
-
Yep. It seemed algorithmically like that'd be faster than alternatives I'd thought of.
Yep. I believe this would provide a way to get back to the same object IDs after deserialization.
With the potential for a significant number of contacts being created and destroyed per step, I suspect this could noticeably slow down the world step function. And only help for cases where deserialization with the same resulting object IDs was more important than speed, and only serve to provide another way to get back to the same object IDs. I wonder how hard it would be to write the code for recreating the same IDs as suggested. |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm opening this as a discussion since I'm not sure if this is solvable with the current version of PlayRho or not.
The problem is, after serialization and deserialization of the world, I want to make sure all objects that are recreated reclaim the same id:s as the previous objects.
This is no issue if objects are only created, since they can simply be recreated in the same order, from beginning to end, and the new objects will get the same id. Where it gets complicated for me is if objects are destroyed, because then they will be marked as "free" and subsequent newly created objects will reclaim their id:s.
I found I could work around this by recreating all the objects first in the same order as they existed in the buffer. Then, looping through the list again and calling
Destroy
on the ones that were destroyed so that they are marked as free.The only issue I have now is that I want subsequent created bodies in the new world to get the same ids as if I had created them in the old world I serialized from. Looking at the code for the
ObjectPool
, it appears that new object will reclaim the id of the last destroyed object:based on that it calls
m_free.back()
. This means I would have to destroy the objects in the deserialized world in exactly the same order as they were destroyed in the world I serialized from.One way to maintain the determinism could be to make the
m_free
list a sorted list, so that perhaps always the smallest free id is picked for the new object. Or expose them_free
list so this information can be passed through serialization, so that free objects can then be destroyed in the same order.Is this something you have thought about already when doing your tests? @louis-langholtz
Beta Was this translation helpful? Give feedback.
All reactions