Commit graph

311 commits

Author SHA1 Message Date
Marcel Admiraal 2abfc0518f Check for empty ConcavePolygonShape2D before checking for intersection 2021-04-06 20:05:10 +01:00
Rémi Verschelde 2bd89ac249
Merge pull request #44695 from madmiraal/fix-44632
Remove all elements from monitored_bodies and monitored_areas when processed
2021-03-26 16:34:02 +01:00
PouleyKetchoupp c5d2404a13 Fix GodotPhysics solver with kinematic body set to report contacts
In 3D, collision is disabled between kinematic/static bodies when
contacts are generated only to report them.

In 2D, this case was already fixed but the code is cleaned to make it
easier to follow.
2021-03-11 18:06:00 -07:00
Eryk Dwornicki fb9d6fcc6d Refactor removal of constraints from bodies in 2D joints 2021-02-27 20:52:01 +01:00
Rémi Verschelde a930472319
Merge pull request #45863 from nekomatata/physics-queries-disabled-shapes
Fix physics queries not filtering out disabled collision shapes
2021-02-24 13:05:28 +01:00
Rémi Verschelde 310496a89f
Merge pull request #45617 from RandomShaper/modernize_atomics
Modernize atomics (and fix `volatile`)
2021-02-18 19:40:31 +01:00
Pedro J. Estébanez 8e128726f0 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 bool` by the new `SafeFlag`
- Platform-specific implementations no longer needed

Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
2021-02-18 17:12:46 +01:00
PouleyKetchoupp cff7a69aa0 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 19:02:59 -07:00
reduz 8b19ffd810 Make Servers truly Thread Safe
-Rendering server now uses a split RID allocate/initialize internally, this allows generating RIDs immediately but initialization to happen later on the proper thread (as rendering APIs generally requiere to call on the right thread).
-RenderingServerWrapMT is no more, multithreading is done in RenderingServerDefault.
-Some functions like texture or mesh creation, when renderer supports it, can register and return immediately (so no waiting for server API to flush, and saving staging and command buffer memory).
-3D physics server changed to be made multithread friendly.
-Added PhysicsServer3DWrapMT to use 3D physics server from multiple threads.
-Disablet Bullet (too much effort to make multithread friendly, this needs to be fixed eventually).
2021-02-10 13:21:46 -03:00
PouleyKetchoupp 50501f2843 Fix physics queries not filtering out disabled collision shapes
This change allows collide_shape, intersect_shape, cast_motion and
rest_info in both 2D and 3D to ignore disabled shapes and make them
consistent with the physics simulation.

In some other cases, _cull_aabb_for_body is used and filters shapes out
internally, but whenever a physics query uses the broadphase directly
without calling _cull_aabb_for_body, disabled shapes can be returned
and need to be filtered out.
2021-02-09 19:14:17 -07:00
Rémi Verschelde d2e1216504
Merge pull request #37547 from aaronfranke/tau
Use Math_TAU and deg2rad/etc in more places and optimize code
2021-02-01 20:55:25 +01:00
Rémi Verschelde 5525cd85c6
Merge pull request #45315 from RandomShaper/modernize_thread
Modernize Thread
2021-01-31 15:24:56 +01:00
Pedro J. Estébanez 99fe462452 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-01-29 12:02:13 +01:00
Aaron Franke cb9fc117d1
Use real_t in physics code 2021-01-28 18:15:42 -05:00
Rémi Verschelde 011d201046
Merge pull request #43923 from madmiraal/fix-43588
Fix cast_motion sometimes failing
2021-01-14 20:44:19 +01:00
Aaron Franke 1d5042c9e2
Use Math_TAU and deg2rad/rad2deg in more places and optimize code 2021-01-09 03:47:14 -05:00
Marcel Admiraal 7653b8cc1e 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:22:39 +00:00
Rémi Verschelde b5334d14f7
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 🎆
2021-01-01 20:19:21 +01:00
Rémi Verschelde 058f3fe069
Merge pull request #44149 from madmiraal/rename-tangent-orthogonal
Rename Vector2.tangent() to Vector2.orthogonal()
2020-12-28 16:00:12 +01:00
Marcel Admiraal 5b937d493f Rename empty() to is_empty() 2020-12-28 10:39:56 +00:00
Marcel Admiraal d7c3a41363 Remove all elements from monitored_bodies and monitored_areas when processed 2020-12-26 09:27:42 +00:00
Marcel Admiraal a24c38d1a8 Rename Vector2.tangent() to Vector2.orthogonal() 2020-12-06 18:16:06 +00:00
Jordan Schidlowsky 043b6c2d93 make 2d constraint solving more deterministic by solving in push order 2020-12-04 22:23:12 -06:00
Marcel Admiraal 356a2b7235 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:33:00 +00:00
Aaron Franke 02161aad5a
Remove empty lines around braces with the formatting script 2020-11-16 23:38:11 -05:00
Rémi Verschelde d7176e9040
Merge pull request #42167 from madmiraal/fix-42108
Remove the unnecessary sync() and the restrictions it imposes on 3D Physics.
2020-11-16 09:32:48 +01:00
reduz 127458ed17 Reorganized core/ directory, it was too fatty already
-Removed FuncRef, since Callable makes it obsolete
-Removed int_types.h as its obsolete in c++11+
-Changed color names code
2020-11-07 20:17:12 -03:00
Marcel Admiraal 7e44682c03 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.
2020-10-03 12:59:34 +01:00
Fabio Alessandrelli f3c6ac1d71 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.
2020-09-23 11:24:01 +02:00
Marcel Admiraal 41209efa7f Remove the unnecessary sync() and the restrictions it imposes on 3D Physics. 2020-09-18 10:43:31 +01:00
Rémi Verschelde 2d9b409103
Merge pull request #41528 from keegano/physics-fix-wrap-angle
Wrap angles to (-pi, pi) in momentum calculation.
2020-09-17 16:32:53 +02:00
TwistedTwigleg 0205eef96b Fixed 2D physics regression that causes RigidBody2D nodes to spin uncontrollably when colliding 2020-08-28 14:16:12 -04:00
Keegan Owsley e148338d42 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.
2020-08-26 08:25:28 -07:00
Markus Sauermann 8335f00949 Wake up RigidBody 2D after applying torque 2020-08-01 14:36:24 +02:00
Rémi Verschelde c845e20add Revert "Allow Area2D and 3D mouse events without a collision layer"
This reverts commit 7eebb06b55.
2020-07-27 22:45:01 +02:00
Rémi Verschelde d0cea291d2
Merge pull request #40193 from KoBeWi/dem_pikks
Allow Area2D and 3D mouse events without collision layer
2020-07-11 00:26:56 +02:00
Marcel Admiraal 26fcf2b04c Add override keywords. 2020-07-10 13:56:54 +01:00
Tomasz Chabora 7eebb06b55 Allow Area2D and 3D mouse events without a collision layer
Co-authored-by: madmiraal <madmiraal@users.noreply.github.com>
2020-07-10 13:23:20 +02:00
Marcel Admiraal 7eb0fcdb1a 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:17:57 +01:00
Cevantime 23f7d2c29d fix laxist collision detection on one way shapes 2020-07-03 11:24:15 +02:00
Rémi Verschelde 67e4082b1e
Merge pull request #37350 from aaronfranke/force-impulse
Refactor physics force and impulse code to use (force, position) order
2020-07-02 18:39:16 +02:00
Marcel Admiraal 79d3d3d17b 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:34:16 +01:00
Marcel Admiraal 62142c5416 Ensure pair callback data is set to null when it's null. 2020-06-13 14:43:25 +01:00
Marcel Admiraal a442526744 Test collision mask before creating constraint pair in Godot physics broadphase 2D and 3D. 2020-06-08 17:46:21 +01:00
Marcel Admiraal b5e31b70dc Correct misspellings of damped spring. 2020-06-04 18:07:24 +01:00
Aaron Franke ba27deef06
Refactor physics force and impulse code 2020-06-02 23:18:59 -04:00
Andrii Doroshenko (Xrayez) 69d5de632e Split Geometry singleton into Geometry2D and Geometry3D
Extra `_2d` suffixes are removed from 2D methods accoringly.
2020-05-27 14:28:34 +03:00
Rémi Verschelde ca3192d18a Style: Fix unnecessary semicolons that confused clang-format 2020-05-19 11:24:58 +02:00
Rémi Verschelde 0ee0fa42e6 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
2020-05-14 21:57:34 +02:00
Rémi Verschelde 07bc4e2f96 Style: Enforce separation line between function definitions
I couldn't find a tool that enforces it, so I went the manual route:
```
find -name "thirdparty" -prune \
  -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \
  -o -name "*.glsl" > files
perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files)
misc/scripts/fix_style.sh -c
```

This adds a newline after all `}` on the first column, unless they
are followed by `#` (typically `#endif`). This leads to having lots
of places with two lines between function/class definitions, but
clang-format then fixes it as we enforce max one line of separation.

This doesn't fix potential occurrences of function definitions which
are indented (e.g. for a helper class defined in a .cpp), but it's
better than nothing. Also can't be made to run easily on CI/hooks so
we'll have to be careful with new code.

Part of #33027.
2020-05-14 16:54:55 +02:00