Commit graph

297 commits

Author SHA1 Message Date
Rémi Verschelde
801205b2c1
Merge pull request #48892 from lawnjelly/bvh_robust
BVH - thread safety option
2021-07-22 12:41:42 +02:00
PouleyKetchoupp
beeebb4c2f More accurate unsafe motion calculation
* Safe and unsafe motion are calculated by dichotomy with a limited
number of steps. It's good for performance, but on long motions that
either collide near the beginning or near the end, the result can be
very imprecise.
* Now a factor 0.25 or 0.75 is used to converge faster when this case
happens, which allows longer motions to get more accurate collision
detection.
* Makes snap collision more precise, and helps with cases where diagonal collision on the border of a platform can lead to the character being stuck.

Additional improvements to move_and_slide:
* Handle slide canceling in move_and_collide with 0 velocity instead of
not applying it.
* Better handling of snap with custom logic to cancel sliding.
* Remove small jittering when using stop on slope, by canceling the
motion completely when the resulting motion is less than margin instead
of always projecting to the up direction (in both body motion and snap).

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-07-19 08:09:17 -07:00
PouleyKetchoupp
2fbb6fff4e Fix move_and_collide causing sliding on slopes
Make sure the direction of the motion is preserved, unless the depth is
higher than the margin, which means the body needs depenetration in any
direction.

Also changed move_and_slide to avoid sliding on the first motion, in
order to avoid issues with unstable position on ground when jumping.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-07-19 08:09:16 -07:00
fabriceci
fba4c9d552 Fixing 2D moving platform logic
Fixing by applying the movement in two steps, first the platform
movement, and then the body movement. Plus, add the platform movement
when we are on_wall.
2021-07-15 11:57:58 +02:00
PouleyKetchoupp
c89476ad41 Expose body_test_motion in 3D physics server
Results are exposed through PhysicsTestMotionResult, the same way it's
done for 2D.

Also cleaned a few things in the 2D version.
2021-07-02 18:04:39 -07:00
PouleyKetchoupp
10fdd196b7 Fix and clean disabled shapes handling in godot physics servers
In 3D, disabled shapes are now not added to the broadphase anymore.
Since they are removed right away when disabled, no need to check for
disabled shapes for any query that comes from the broadphase.
Also Fixes raycast queries returning disabled shapes.

In 2D, disabled shapes where already not added to the broadphase.
Remove the same unnecessary checks as in 3D.

Overall harmonized API for disabled shapes in the physics servers and
removed duplicate method.
2021-06-22 16:48:24 -07:00
PouleyKetchoupp
c3107349a4 Ignore disabled shapes for mass property calculations 2021-06-17 17:17:05 -07:00
lawnjelly
14ce176f10 BVH - thread safety option
Added optional thread safe version through template argument and runtime switch, that wraps access with a mutex.
2021-05-25 10:47:32 +01:00
Rémi Verschelde
cca2a9d2d5
Merge pull request #38387 from Rhathe/set_iterations
[3.x] Enable setting of collision iterations in Physics2DServer
2021-05-19 19:48:08 +02:00
Rémi Verschelde
140350d767
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2021-05-05 15:02:01 +02:00
PouleyKetchoupp
0dacc681b6 Fixed unnecessary bvh tree updates when calling set_pairable
Dynamic BVH doesn't update the tree anymore when calling set_pairable
with no parameter change.

Also modified Godot Physics broadphase to create objects directly with
pairable (static) set correctly to make use of this optimization for the
BVH broadphase.

Note: Octree broadphase doesn't use this optimization because it forces
an update on move, so passing the proper AABB and static parameters on
creation would cause the tree to update twice.
2021-05-04 12:24:31 -07:00
Rémi Verschelde
b4af1eba0a
Style: Enforce use of bool literals instead of integers
Using clang-tidy's `modernize-use-bool-literals`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-bool-literals.html
2021-05-04 16:39:13 +02:00
Rémi Verschelde
a828398655
Style: Replaces uses of 0/NULL by nullptr (C++11)
Using clang-tidy's `modernize-use-nullptr`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-05-04 16:30:23 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
Rémi Verschelde
64a63e0861
Style: clang-format: Disable AllowShortCaseLabelsOnASingleLine 2021-05-04 14:45:15 +02:00
Rémi Verschelde
3d15f04668
Style: clang-format: Disable AllowShortIfStatementsOnASingleLine 2021-05-04 14:45:15 +02:00
Rémi Verschelde
32cc022267
Merge pull request #48314 from nekomatata/physics-2d-dynamic-bvh
[3.x] Support for Dynamic BVH as 2D Physics broadphase
2021-05-04 09:23:04 +02:00
PouleyKetchoupp
d8f681029f Support for Dynamic BVH as 2D Physics broadphase
List of changes:
- Modified bvh class to handle 2D and 3D as a template
- Changes in Rect2, Vector2, Vector3 interface to uniformize template
calls
- New option in Project Settings to enable BVH for 2D Physics (enabled
by default like in 3D)
2021-04-30 15:53:15 -07:00
Rémi Verschelde
594764c2ec
Revert "make 2d constraint solving more deterministic by solving in push order"
This reverts commit 266314ba26.

There seems to be some performance concerns, so reverting the cherry-pick for
now and we'll revisit later (see https://github.com/godotengine/godot/pull/44112#issuecomment-829426790).
2021-04-29 19:12:19 +02:00
Jordan Schidlowsky
266314ba26
make 2d constraint solving more deterministic by solving in push order
(cherry picked from commit 043b6c2d93)
2021-04-29 11:27:56 +02:00
Rémi Verschelde
a706fb11e5
Merge pull request #47943 from nekomatata/joint-check-body-types-3.x
[3.x] Fix errors related to joints setup with two non-dynamic bodies
2021-04-28 16:58:23 +02:00
Henry Conklin
8e4641bc88 Optimize BroadPhase2dHashGrid to not pair elements on different layers
Clean up logic in _check_motion

Closes 45824
2021-04-17 10:49:06 -04:00
PouleyKetchoupp
64b11b6126 Fix errors related to joints setup with two non-dynamic bodies 2021-04-15 17:53:15 -07:00
Marcel Admiraal
a3f4bd96c5
Ensure ConvexPolygonShape support count variable is initialised
(cherry picked from commit 0d4d8925b7)
2021-04-06 22:37:03 +02:00
Rémi Verschelde
bd9ee18fb1
Merge pull request #47679 from madmiraal/fix-47436.1-3.x
[3.x] Check for empty ConcavePolygonShape2D before checking for intersection
2021-04-06 22:36:01 +02:00
Marcel Admiraal
83da95b6e4 Check for empty ConcavePolygonShape2D before checking for intersection 2021-04-06 19:43:51 +01:00
Marcel Admiraal
ebcff3b4a6 Check ConvexPolygonShape2D point count before calcuating moment of inertia 2021-04-06 19:11:40 +01:00
Rémi Verschelde
ab4c73604d
Merge pull request #44696 from madmiraal/fix-44632-3.2
[3.x] Remove all elements from monitored_bodies and monitored_areas when processed
2021-03-26 16:34:27 +01:00
Hein-Pieter van Braam
220f24c191
Merge pull request #45618 from RandomShaper/modernize_mt_3.2
Backport of all the multi-threading modernization (3.2)
2021-02-18 20:47:24 +01:00
Pedro J. Estébanez
4485b43a57 Modernize atomics
- Based on C++11's `atomic`
- Reworked `SafeRefCount` (based on the rewrite by @hpvb)
- Replaced free atomic functions by the new `SafeNumeric<T>`
- Replaced wrong cases of `volatile` by the new `SafeFlag`
- Platform-specific implementations no longer needed

Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
2021-02-18 12:23:25 +01:00
Pedro J. Estébanez
6d89f675b1 Modernize Thread
- Based on C++11's `thread` and `thread_local`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed (except for the few cases of non-portable functions)
- Simpler for `NO_THREADS`
- Thread ids are now the same across platforms (main is 1; others follow)
2021-02-18 11:58:08 +01:00
Pedro J. Estébanez
8f6a636ae7 Modernize Semaphore
- Based on C++11's `mutex` and `condition_variable`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed
- Simpler for `NO_THREADS`
2021-02-18 11:58:08 +01:00
Pedro J. Estébanez
4ddcdc031b Modernize Mutex
- Based on C++11's `mutex`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed
- Simpler for `NO_THREADS`
- `BinaryMutex` added for special cases as the non-recursive version
- `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`.
- `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
2021-02-18 11:58:08 +01:00
PouleyKetchoupp
9cefab24e0 Fix test_body_motion recovery
This change makes test_body_motion more reliable when the kinematic body
recovers from being stuck.

- When recovery occurs, the rest information is generated, in order to
make sure collision results from test_move, move_and_collide and
move_and_slide are consistent and return a collision in case of overlap.

- The new calculation for recovery vector makes sure the recovery is
never more than the overlap depth between shapes.
This can help with cases where the kinematic body overlaps with several
shapes.
Recovery is made iteratively, without forcing a full overlap at each
step. This helps with getting proper rest information when recovery
occurs.

- One Way Collision:
When attempting motion, contact direction is checked against motion
before skipping in order to solve cases where kinematic bodies can sink
into one-way collision shapes.
Rest info now sets max contact depth in order to properly handle one-way
collision.

- Low speed motion is now handled in the rest info, by never setting
min_allowed_depth lower than motion length.
Separation is always applied with full margin, otherwise contact is lost
when low speed motion occurs right after higher speed motion.

- Similar changes are applied to 3D in order to make 2D and 3D
consistent.
2021-02-17 18:27:38 -07:00
Rémi Verschelde
152415a006
Merge pull request #43924 from madmiraal/fix-43588-3.2
[3.2] Fix cast_motion sometimes failing
2021-01-14 20:44:40 +01:00
Rémi Verschelde
49646383f1
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆

(cherry picked from commit b5334d14f7)
2021-01-13 16:17:06 +01:00
Marcel Admiraal
1061bb364e Fix multiple issues with one-way collisions
For RigidBodies, uses the collision normal determined by relative motion
to determine whether or not a one-way collision has occurred.

For KinematicBodies, performs additional checks to ensure a one-way
collision has occurred, and averages the recovery step over all collision
shapes.

Co-authored-by:    Sergej Gureev <sergej.gureev@relex.fi>
2021-01-07 09:23:17 +00:00
Marcel Admiraal
03cddd36db Remove all elements from monitored_bodies and monitored_areas when processed 2020-12-26 09:24:43 +00:00
Marcel Admiraal
2e99b5b137 Fix cast_motion sometimes failing
- Fixes Godot physics failing when the cast Shape is inside of, or
already colliding with another Shape.
- Fixes Bullet physics failing when there is no motion.
- Ensures Godot and Bullet physics behave the same.
- Updates the documentation to exclude the caveats for the failures and
differences.
2020-11-27 15:32:25 +00:00
Rémi Verschelde
fc5b106369
Merge pull request #42168 from madmiraal/fix-42108-3.2
[3.2]  Remove the unnecessary sync() and the restrictions it imposes on 3D Physics.
2020-11-16 09:33:17 +01:00
Marcel Admiraal
6c4a02479d
Fix how Line2D obtains the other object's supports
Measure the distance from the line against the rotated object, not the
rotated line, when obtaining the object's supports against a line.

(cherry picked from commit 7e44682c03)
2020-10-04 20:54:35 +02:00
Fabio Alessandrelli
6dffc1ef46
Ignore thread models when compiling with NO_THREAD
The thread model option for physics (2D) and rendering (single-unsafe,
single-safe, multithread), was causing crashes/locks when set as
multithreaded and exported for a platform that does not support threads
(namely HTML5).

This commit ensures that when threads support is not available, that
option is ignored, and the equivalent of "single-unsafe" is always used
instead.

(cherry picked from commit f3c6ac1d71)
2020-09-24 14:43:08 +02:00
Keegan Owsley
777d90d7a1
Wrap angles to (-pi, pi) in momentum calculation.
Fixes a bug that causes KinematicBody2Ds to produce too much angular
momentum when rotating beyond 180 degrees.

(cherry picked from commit e148338d42)
2020-09-24 14:43:06 +02:00
Markus Sauermann
d2636cd30f
Wake up RigidBody 2D after applying torque
(cherry picked from commit 8335f00949)
2020-09-24 14:43:05 +02:00
Marcel Admiraal
fc72c3fdf5 Remove the unnecessary sync() and the restrictions it imposes on 3D Physics. 2020-09-18 10:42:59 +01:00
Rémi Verschelde
400a780050 Revert "Allow Area2D and 3D mouse events without a collision layer"
This reverts commit 15850687a8.
2020-07-27 22:46:04 +02:00
Tomasz Chabora
15850687a8 Allow Area2D and 3D mouse events without a collision layer
Co-authored-by:    Tomasz Chabora <kobewi4e@gmail.com>
2020-07-11 11:14:12 +01:00
Marcel Admiraal
ccdfaf2491 Remove elements from monitored_bodies and monitored_areas as they are
processed before calling the callback, instead of after they have all
been processed, because the callbacks may readd them.
2020-07-04 10:08:33 +01:00
Cevantime
6206f4439d fix laxist collision detection on one way shapes
(cherry picked from commit 23f7d2c29d)
2020-07-03 15:34:30 +02:00
Marcel Admiraal
de284ea5d2 Trigger broadphase update when changing collision layer/mask, and
check for collision layer/mask changes in 2D hash grid broadphase update.
2020-06-27 18:11:21 +01:00