Draft: Support deterministic body IDs when restoring state#2073
Conversation
|
Hello, I've looked at the changes and I appreciate the work you've put in this, but to be honest, I don't want to add this kind of complexity to the core Jolt library. As far as I can see the change does:
I think you can implement the same behavior in your own application:
|
|
Appreciate your time to take a look and the comments. Funnily enough, the start of the experiment was doing just that, having a monotonically increasing body id that was synchronized/reset, but with sequence id of 0, meaning it wouldn't reuse a slot. I was initially worried (and maybe a bit lazy 😉 ) about performance penalty for how sparse that would ultimately become. But I can probably move some version of the freelist into my game layer as you mentioned. Or at the very least lease slots past destruction so I know they can't be used until they're VERY stale and out of history before being reused. Again, Jorrit, thanks so much for everything you do. |
|
Having a monitonically increasing body ID is probably not a good idea if it means there will be lots of sparsity. If you create a body with a custom ID then it currently does an O(N) loop through the freelist to remove that ID from the freelist. So it's best to keep the freelist small. Ideally you track the body IDs you free and reuse the last freed body ID first. |
As a continuation from #1930
I ended up disappearing for GDC and never updated. But following that discussion I have been successful synchronizing ids and context for shape/material out of band, while sending a full staterecorder over the wire only once at the beginning of each client connection. In addition, storing one for each tick within history for reprediction. I quickly noticed that id generation was not deterministic after restoring, which inspired these changes:
I added a
EStateRecorderState::IdSequencesto save/restore body id sequence numbers and the free list order, and then an option toPhysicsSystem::RestoreStateto destroy bodies not present in the state.Together these make body ID allocation after a restore identical to the original run, which I needed for rollback/reprediction. Also adds some state recorder tests to verify.
Currently a draft because I'm also looking for a bit guidance on expected guarantees for serialization format of the state recorder. I put all of this in the new
IdSequencesso theoretically it could be backwards compatible if folks were saving previous recordings to disk. Also, maybe it makes sense to not care about deterministic body id on replay. It's not as important if you're just using it for like visual debugging or forking. So I wanted to keep it as a separate option. You can also tell I hesitated to add it to All and that it awkwardly tags onto the body logic. Happy to clean this up or drop it altogether if you prefer another approach. I'm sure it also needs extra warning/handling for filters or other partial state saves. Or the free list restore not working if you don't have the entity destruction enabled.I've been using these changes successful for a while in my prototype for the past few weeks, but it's not incredibly complex at the moment.
Ultimately I needed 2 things: