-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor physics force and impulse code to use (force, position) order #37350
Conversation
bc5fac5
to
fd5318a
Compare
What's the reason to remove the query with add central force/impulse? |
@AndreaCatania Because |
Well, this is not true. Add force performs more thing than just add a vector and this matters when you have to use a lot of times per each frame this function. What's the benefit that we get removing such API? |
I don't understand what you mean. This is the old code: _FORCE_INLINE_ void add_central_force(const Vector2 &p_force) {
applied_force += p_force;
}
_FORCE_INLINE_ void add_force(const Vector2 &p_offset, const Vector2 &p_force) {
applied_force += p_force;
applied_torque += p_offset.cross(p_force);
}
_FORCE_INLINE_ void add_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) {
applied_force += p_force;
if (p_position != Vector2()) {
applied_torque += p_position.cross(p_force);
}
} The new The benefit is not having two functions that do the exact same thing. |
These are not the same, otherwise would not be there. The reason is that when you don't want to add an offsetted force (most likely) you don't want to also perform: if (p_position != Vector2()) {
applied_torque += p_position.cross(p_force);
} nor send useless position vectors around. I don't think this API is unclear or confusing so I don't understand what is the real benefit. |
I don't disagree with @AndreaCatania, it might be a good idea to keep them separate. However, I think |
What about if If not, we could also keep |
e0a960d
to
977573b
Compare
977573b
to
f8a2e1d
Compare
c8d2845
to
73a787f
Compare
@AndreaCatania I removed all the controversial changes from this PR, now it's just the (force, position) etc ordering, and using the full words "force", "impulse", and "position". I'd appreciate a review. The docs are updated, so you can look at them to see the publicly-facing API changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modify all the functions were not needed but is cool to have all with the same order, Thanks.
73a787f
to
95534f1
Compare
95534f1
to
ba27dee
Compare
Thanks! |
Implements the proposal in this comment: #16863 (comment)
add_force
now uses(force, position)
andapply_impulse
now uses(impulse, position)
. This very much breaks compatibility, in a way that isn't visible in projects until runtime (the worst kind).The
position
parameter is now optional,therefore I removedadd_central_force
andapply_central_impulse
since they are now redundant (the code still has checks and optimizations).In addition to the above, I also enforced a consistent naming scheme. Previously
position
could either beoffset
orpos
, now it'sposition
everywhere, alsoimpulse
could either bej
orimpu
, now it'simpulse
everywhere.