Closed rjdgtn closed 1 year ago
Hi rjdgtn,
Thank you for asking!
By m_gravityScale
, I think you mean the b2BodyDef::gravityScale
and b2Body::m_gravityScale
member variables.
I had removed these because b2Body::m_gravityScale
was associated with an additional multiplication operation within the island solver in more performance critical code (specifically in integrating velocity as v += h * (b->m_gravityScale * gravity + b->m_invMass * b->m_force)
). By combining bodies' m_gravityScale
with world gravity and bodies' m_force
variables, the calculation of the new linear velocity (v
) effectively reduced to v += h * body.GetLinearAcceleration()
. It also reduces the memory size of world and body instances (since they need to remember less data now). Note that I removed body forces and non-persistence of these also so that a body's acceleration setting contains this all now.
The closest analogy to these original variables are the BodyDef::linearAcceleration
, Body::m_linearAcceleration
, and World:: m_gravity
member variables. So if you want a body to have an acceleration different than the world gravity, that acceleration can be set on the body (after it's creation by the world instance) by calling the Body::SetAcceleration
method or one of the free functions that also sets it. Note that world gravity only sets the body acceleration on body creation and doesn't factor in to the body's velocity calculation after that.
By the way, your question suggests that this change from the original Box2D is surprising and/or unclear. Please accept my apology for this and my thanks again to you for pointing this out.
I reviewed this project's changes document to see if I'd made any mention of this difference in there and didn't find any. I've also moved development of this project over to the new project name and space of PlayRho. I suspect PlayRho also doesn't mention this change from the original Box2D either. I have updated PlayRho's issue louis-langholtz/PlayRho#219 to help me remember to address this. I'm less sure of what to do for this Box2D however.
Would you be willing and/or interested in trying out PlayRho? I'd really love to get more people to use PlayRho and help with great questions like you've made. Also, PlayRho is open to contributions and has that process integrated in the pull requests mechanism in a way that I quite like.
Thanks for the detailed answer. I'll use SetAcceleration for change gravity influence.
1) Is current PlayRho version more stable or more optimised than your box2d fork last commit version?
2) I make pong-like game with very simple physics, but need full determinism. Your box2d fork looks 20% faster that original box2d, but using of Fixed32 for float calculations makes it 10 times slower. This is a very big price for determinism. Is there a way to improve performance?
3) I want to have two or more independent physics worlds in different threads. Do I correctly understand that this will not be a problem?
Fixed32
type is available, I've found the use of 32-bit based fixed precision seemingly not generally very usable and I don't recommend using it. My Box2D fork's implementation of Fixed32
also still uses the standard floating-point math library and the float
type to do calculations like sine, cosine, and square root. That's likely to re-introduce the platform dependence which it sounds like you want to avoid. PlayRho's implementation of the Fixed32
and Fixed64
types meanwhile was updated to not rely at all on hardware floating point support nor the standard math library. So PlayRho's implementation of the fixed types should provide better platform independence. Some of the math library routines I implemented for fixed types in PlayRho disappoint me however in their performance (log
's performance is the most disappointing). I've read that going back and forth between integer and floating-point arithmetic hardware can kill performance but then I've also read that integer division tends to be significantly slower than floating-point division. I haven't done any actual bench marking of the different implementations though to be more specific. Using a popular implementation of fixed point type is probably the better way to go in terms of performance and correctness but then none of them seem to support constexpr
/LiteralType
C++ concepts causing other problems.Hope this helps.
Thanks for the detailed answer.
#ifndef WIN32
to `#if LP64__`Yes. Sorry about this. A 128-bit integer does need to be supported on the platform for the Fixed64
implementation to deal with intermediary fixed point results, and that does preclude Fixed64
's use on many platforms.
I've opened PlayRho issue louis-langholtz/PlayRho#295 to address my desire to have an externally developed fixed point type supported by the PlayRho library. An external implementation would likely be much more widely tested too which would be appealing to me.
Alternatively, the implementation of Fixed64
could be worked on to at least optionally use two 64-bit integers (instead of the 128-bit integer) and I've opened PlayRho issue louis-langholtz/realnumb#1 for that. It's not clear that Fixed64
would be performant enough though.
Ok. Thanks
Why you remove m_gravityScale? What is your analog?