bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 262 forks source link

Consider simulation state snapshotting #64

Open RossNordby opened 5 years ago

RossNordby commented 5 years ago

While it's fairly easy to capture the current pose and velocity of bodies, it's more difficult to capture every bit of internal state. Directly dumping out a complete and ordered set of constraints, bodies, narrow phase mapping data, accumulated impulses, inactive data, and (shallow?) shape information could be helpful for precisely reconstructing simulation state.

Mainly useful for locally deterministic rewind/replay. Marginal benefit over 'top level' snapshots that don't include stuff like accumulated impulses and activity state is fairly small, but not zero.

Primary benefit might just be as documentation showing what kind of state exists and how to capture it at all.

Post-release feature; value/effort ratio isn't great.

RossNordby commented 4 years ago

A potentially more important use case for this that I forgot to mention: debugging. Being able to take periodic snapshots around a failure and then restart the simulation to get a locally deterministic reproduction could be very handy. Such a snapshot could be serialized and reproduced in a separate debug visualization application, making it much easier for me to find problems in user reports. Moving to a different computer wouldn't guarantee determinism due to potential floating point differences, but most types of bugs would still reproduce.

damian-666 commented 1 year ago

I just saw this preprint paper come out from this legend, Jos Stam.
though you might find it relevant / interesting. if it can be applied, would let u reverse the sim, and also to support maybe the multiplayer deterministic senario and maybe large spaces. its still not unconditionally stable ( meaning no maximum timestep to avoid explosive errors) like his semi-Langangian implicit fluid solver, nor fully conservative ( if there is dissipation it will lose energy unnaturally but usually thats unnoticed for a game) but very interesting, if not revolutionary. if you integrate this fixed point/ floating point hybrid method, without massive overhaul. this might give you or your users other possibilities to find optima and converge solvers by reversing the sim, rather than ducking out...

https://www.researchgate.net/publication/362089884_An_Exact_Bitwise_Reversible_Integrator

Alan-FGR commented 1 year ago

While determinism is probably useful, maybe for multiplayer authoritative state synchronization (i.e. overriding client state from time to time) you can use just the pose and velocity. I'm not sure however if you would kill the other states in the client and somehow rebuild that before kicking off the simulation step.

damian-666 commented 1 year ago

thats is sadly how they do it. you shoot a guy an then hes bleedign but you might see then hes suddenly Undead because he moved and the server corrected the clients. ... i dont do multplayer becasue the speed of light makes interactive physics physically impossible on a globl network. wiht 4 controllers in one ro ok or on internet in one city its barely possible to have interactive rates . even if the clients were deterministic ist not possilble because of ping rates. and network congestion.. At the spead of light ideal, This is just relativity theory.. ( or fact) 0.1337 seconds is how long light needs to go around the earth. 1/8 sec. or for interactive physics i found 120 hz is good enough. 8 hz one way isnt even close.

Alan-FGR commented 1 year ago

Lunch break here so this is a real quick reply: @damian-666 I've had to check those numbers tbh, I was assuming the speed of light would be the smallest part of the latency compared to relays and such, but you're right, 134ms is the base minimum which is pretty bad. On top of that ofc you have delays for routing and even fiber afaik has a relatively high IOR at >1.5 meaning the base minimum on fiber would be 200ms, add real world variables to that and you're definitely talking about <4hz. For authoritative correction that is definitely too much for fast paced games like your typical shooter.