Deterministic fixed-point port, open source
Posted: Sun Feb 11, 2018 12:24 pm
EDIT: Source code is now available at https://github.com/sam-vdp/bepuphysics1int
Hi everyone,
like test44x I was looking for a deterministic fixed-point physics engine and have started porting BEPUv1 to use integer math. I followed the instructions from the previous thread quite closely and the port seems to work so far. I intend to make this open-source ASAP, but I have some stylistic questions I would like to discuss first.
Also, Norbo, thank you so much for your work on BEPUphysics. Going through the entire codebase with search and replace really makes you appreciate the effort that went into it
Questions
1. EntityStateChange
In EntityStateWriteBuffer there is a struct EntityStateChange that has some FieldOffset annotations for Windows builds. These broke the build after using the fixed-point type instead of float, I assume because Vector3 and Quaternion doubled in size? I don't quite understand what the annotations do, particularly the overlapping offset for the first two fields. For now I have removed them and it seems like nothing broke. What would be the proper fix there, though?
2. Fixed-point library
I am using https://github.com/asik/FixedMath.Net for the fixed-point operations. I have slightly modified the source and will probably add some performance tweaks later. Which begs the question, where to put the modified source?
3. Numerical constants in BEPU
There are a good number of float and int constants in the BEPU source and the question is how to translate those to the Fix64 type. Right now I am using a bit of a mixed approach:
4. Fixed-point Pow() function?
FixedMath.Net doesn't have Pow(), do you have a recommendation for a good algorithm?
I want to clean up the code a bit, add some tests for performance and determinism, but I expect I'll put the code on github some time next week.
Thank you all for your and in advance for your help.
Cheers,
Bart
Hi everyone,
like test44x I was looking for a deterministic fixed-point physics engine and have started porting BEPUv1 to use integer math. I followed the instructions from the previous thread quite closely and the port seems to work so far. I intend to make this open-source ASAP, but I have some stylistic questions I would like to discuss first.
Also, Norbo, thank you so much for your work on BEPUphysics. Going through the entire codebase with search and replace really makes you appreciate the effort that went into it
Questions
1. EntityStateChange
In EntityStateWriteBuffer there is a struct EntityStateChange that has some FieldOffset annotations for Windows builds. These broke the build after using the fixed-point type instead of float, I assume because Vector3 and Quaternion doubled in size? I don't quite understand what the annotations do, particularly the overlapping offset for the first two fields. For now I have removed them and it seems like nothing broke. What would be the proper fix there, though?
2. Fixed-point library
I am using https://github.com/asik/FixedMath.Net for the fixed-point operations. I have slightly modified the source and will probably add some performance tweaks later. Which begs the question, where to put the modified source?
- Fork on github and maintain separately - makes building BEPU more of a hassle
- Add FixedMath project to BEPU solution - requires user to a another reference to their project
- Add FixedMath source into BEPUutilities project
3. Numerical constants in BEPU
There are a good number of float and int constants in the BEPU source and the question is how to translate those to the Fix64 type. Right now I am using a bit of a mixed approach:
- I've added an implicit cast from int to Fix64. All float instances in the source without a fractional part (like 1f) were replaced with their int counterparts.
- I've added an implicit cast from decimal to Fix64 and replaced float values with decimal for all initializers.
- For float constants used inside the code (stuff like x > 0.1f) I have added static constants in a helper class, to avoid the cost of converting from decimal to Fix64 inline.
4. Fixed-point Pow() function?
FixedMath.Net doesn't have Pow(), do you have a recommendation for a good algorithm?
I want to clean up the code a bit, add some tests for performance and determinism, but I expect I'll put the code on github some time next week.
Thank you all for your and in advance for your help.
Cheers,
Bart