bepu / bepuphysics2

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

Determinism test expansion #42

Closed RossNordby closed 6 years ago

RossNordby commented 6 years ago

The current test (DeterminismTest) is pretty weak. It covers the universally shared bookkeeping, but fails to capture many complex types.

Probably wise to allow it to evaluate any generic demo.

ip commented 6 years ago

Hi! I'm looking for some library for deterministic collision detection for my Unity game. I found the v. 1 fork of BEPUphysics which uses fixed-point math (via FixedMath.Net) but it seems to be abandoned.

It's interesting that you're actively developing version 2 now. Do you plan to support fixed-point determinism? I'm saying fixed-point, because this is probably the only way to reliably get the same results across all platforms.

My use case is following. I want to record game replays on the client side and replaying them on client and server side for these reasons:

Deterministic lock-step approach would allow me to store lots of replays, because I would only need to store inputs. I need collision detection only (kinematic bodies).

RossNordby commented 6 years ago

Cross platform determinism is something I'd like to do, but which I can't realistically devote the necessary time to for the short-medium term at least.

This would have to come after a move towards abstracted SIMD scalars. Right now, all SIMD math is implemented on top of Vector and friends which exposes a small shared set of features. For performance and functionality, I'd like to eventually implement some form of ScalarWide type on top of the newer low level intrinsics (https://github.com/dotnet/corefx/issues/22940). With that in place, I could create a fixed point implementation of scalars behind a compilation symbol.

Fixed point would require some more work beyond that, though- all the instances of non-SIMD floats would need to be swapped out too.

All of this requires some codegen improvements in the compiler so that the abstractions would be zero overhead without spewing ifdefs everywhere. That puts a lower bound on the timeline.

ip commented 6 years ago

A simpler and easier solution might be code generation (transpiling), like they do in web development (e.g. TypeScript to JavaScript, also popular in Golang community). Entitas ECS library uses this approach as well.

RossNordby commented 6 years ago

That's an option I've considered occasionally, but it can introduce some tooling annoyances. The minimal effort and maximum usability path is just having a JIT or other compiler which is able to deal with structs (and ideally operators) with equivalent final assembly to a dedicated code generation pass.

Fortunately, this appears to be an area of focus in the CoreCLR/CoreRT and will probably be addressed before I get around to working on it anyway. Unity is a bit of an unknown, but there are even more issues there. (unless they swap to using the core runtimes wink wink nudge wiggly eyebrows come on you know you want to guys)

RossNordby commented 6 years ago

Determinism test has been expanded and a whole bunch of bugs have been fixed as of 565713e74af0b8473f5fb518e8feae584768231d.