Commit Graph

348 Commits

Author SHA1 Message Date
Rémi Verschelde
02e4e208ef
Fix various GCC 13 warnings
Fixes occurrences of `-Wtype-limits`, `-Wmaybe-uninitialized`,
`-Wduplicated-branches`.
2023-12-08 15:32:59 +01:00
lawnjelly
43e181a00a Single Compilation Unit build.
Adds support for simple SCU build.
This speeds up compilation by compiling multiple cpp files within a single translation unit.
2023-07-02 20:13:16 +01:00
belzecue
efb4a0a6d5 Backport from Godot 4 - Fix RigidDynamicBody gaining momentum with bounce #55313 2023-04-19 01:13:58 +08:00
Rémi Verschelde
1426cd3b3a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".

Backported from #70885.
2023-01-10 15:26:54 +01:00
lawnjelly
6a2912c856 Fix pairing crash in physics Octree
Remove section of code that should not run and was causing crash.
2022-12-20 19:25:34 +00:00
Ricardo Buring
40357471dc Fix typo bug in heightmap shape
(cherry picked from commit 55eceb5150)
2022-12-12 14:00:37 +08:00
Cory Petkovsek
d7ba3b73a9 Clarify invalid RID errors in Server free() functions. 2022-08-12 23:02:09 +08:00
Ryan Heath
4f5c268a60 Add area monitor callback error checking 2022-08-07 13:57:06 -07:00
Rémi Verschelde
d9d3861f76
Merge pull request #55764 from tinmanjuggernaut/validate_rid
[3.x] Validate RIDs before freeing
2022-08-05 22:38:49 +02:00
Rémi Verschelde
818f1eed31 Code quality: Fix header guards consistency
Adds `header_guards.sh` bash script, used in CI to validate future
changes. Can be run locally to fix invalid header guards.
2022-07-25 14:53:37 +02:00
Hugo Locurcio
46b7133967 Add a 3D suffix to relevant physics profiler categories
2D physics categories already had a 2D suffix: "Physics 2D"

(cherry picked from commit 36428305a6)
2022-06-01 00:29:46 +02:00
Cory Petkovsek
2be0738304 Visual/Physics/Navigation Servers validate RIDs with documentation update 2022-05-06 03:39:06 +08:00
lawnjelly
036bace9e9 BVH - Fix area-area collision regression
Minimal approach to fixing regression whereby static areas where not detect dynamic areas.
2022-02-26 11:36:27 +00:00
Rémi Verschelde
6ca309e058
Merge pull request #58531 from rburing/area_call_queries_fix_premature_return
[3.x] Godot Physics `AreaSW` and `Area2DSW`: fix premature return in `call_queries`
2022-02-26 09:36:14 +01:00
Ricardo Buring
89ce63a84f AreaSW and Area2DSW: fix premature return in call_queries 2022-02-25 14:41:34 +01:00
Ricardo Buring
e6f1a44b4d In final phase of test_body_motion, move and cull AABB for body once instead of for every shape 2022-02-21 15:03:09 +01:00
Rémi Verschelde
7a16bb2ee4
Fix typos with codespell
Using codespell 2.2-dev from current git.

Added `misc/scripts/codespell.sh` to make it easier to run it once in a
while and update the skip and ignore lists.

(cherry picked from commit 1bdb82c64e)
2022-02-11 09:50:59 +01:00
lawnjelly
dc14636e68 BVH templated mask checks and generic NUM_TREES
Refactors the BVH to make it more generic and customizable. Instead of hard coding the system of pairable_mask and pairable_type into the BVH, this information is no longer stored internally, and instead the BVH uses callbacks both for determining whether pairs of objects can pair with each other, and for filtering cull / intersection tests.

In addition, instead of hard coding the number of trees, the BVH now supports up to 32 trees, and each object can supply a tree collision mask to determine which trees it can collide against.

This enables the BVH to scale to either the two or 3 trees needed in physics, and the single tree used without pairing in Godot 4 render tree.
2022-01-21 10:08:29 +00:00
Rémi Verschelde
a627cdafc5
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-13 15:54:13 +01:00
PouleyKetchoupp
e11662ad77
Handle test body motion with 0 margin
Margin needs to have a high enough value for test body motion to work
properly (separate using the margin, move without then gather rest info
with the margin again).

Fixes issues with test motion returning no collision in some cases with
margin equal to 0.

(cherry picked from commit 0c354047e1)
2021-12-10 11:16:35 +01:00
lawnjelly
3d981b8265 Add option to use handles to RID
Adds an option to compile an alternative implementation for RIDs, which allows checks for erroneous usage patterns as well as providing leak tests.
2021-12-06 14:43:34 +00:00
Camille Mohr-Daurat
3970f28f67
Merge pull request #55096 from lawnjelly/bvh_expanded_leaf
BVH - add option for expanded AABBs in leaves
2021-11-22 09:37:16 -07:00
Rémi Verschelde
393c7959ef
Merge pull request #42929 from madmiraal/fix-42877-3.2 2021-11-20 10:23:06 +01:00
Marcel Admiraal
702529d63e Give each RigidBody its own DirectBodyState wrapper. 2021-11-20 08:17:04 +00:00
Marcel Admiraal
e900bac80b Add area to moved list when changing monitorable,
and only remove area from query when deleting pair if it was monitorable.
2021-11-20 06:54:36 +00:00
lawnjelly
211dc8cd2d BVH - add option for expanded AABBs in leaves
This PR adds a define BVH_EXPAND_LEAF_AABBS which is set, which stores expanded AABBs in the tree instead of exact AABBs.

This makes the logic less error prone when considering reciprocal collisions in the pairing, as all collision detect is now taking place between expanded AABB against expanded AABB, rather than expanded AABB against exact AABB.

The flip side of this is that the intersection tests will now be less exact when expanded margins are set.

All margins are now user customizable via project settings, and take account of collision pairing density to adjust the margin dynamically.
2021-11-20 06:45:12 +00:00
Rémi Verschelde
45088780be
Merge pull request #54925 from nekomatata/bvh-fix-update-3.x 2021-11-16 21:23:11 +01:00
PouleyKetchoupp
e9fdf3e61f Fix physics BVH pairing for teleported or fast moving objects
Updating the broadphase to find new collision pairs was done after
checking for collision islands, so it was working in most cases due to
the pairing margin used in the BVH, but in case of teleported objects
the narrowphase collision could be skipped.

Now it's done before checking for collision islands, so we can ensure
that broadphase pairing has been done at the same time as objects are
marked as moved so their collision can be checked properly.

This issue didn't happen in the Octree/HashGrid because they do nothing
on update and trigger pairs directly when objects move instead.
2021-11-16 12:01:57 -07:00
Julian Adamse
7e5034958e
Fix the volume calculation for cylinders
(cherry picked from commit 03903fdeec)
2021-11-15 16:09:59 +01:00
lawnjelly
062406b555 [3.x] Add Basis helper functions for transforming normals
Correct transformation of normals that works with a Basis containing non-uniform scale is difficult to get correct for those not familiar with the maths, it is also rather verbose and hard to read in calling code. This PR adds helper functions which both standardize the approach and make it clearer in calling code what is being done and why.
2021-11-15 08:43:46 +00:00
PouleyKetchoupp
b93aeec4a2 Fix errors in KinematicBody when floor is destroyed or removed
In all physics servers, body_get_direct_state() now silently returns
nullptr when the body has been already freed or is removed from space,
so the client code can detect this state and invalidate the body rid.

In 2D, there is no change in behavior (just no more errors).

In 3D, the Bullet server returned a valid direct body state when the
body was removed from the physics space, but in this case it didn't
make sense to use the information from the body state.
2021-11-09 15:15:40 -07:00
Rémi Verschelde
6b7c841e1b
Merge pull request #54111 from nekomatata/fix-rigid-body-update-collision-layer-3.x 2021-11-08 23:58:47 +01:00
Rémi Verschelde
1b65550ec7
clang-format: Various fixes to comments alignment from clang-format 13
All reviewed manually and occasionally rewritten to avoid bad auto formatting.
2021-10-28 14:50:32 +02:00
Rémi Verschelde
42d385b312
clang-format: Disable alignment of operands, too unreliable
Sets `AlignOperands` to `DontAlign`.

`clang-format` developers seem to mostly care about space-based indentation and
every other version of clang-format breaks the bad mismatch of tabs and spaces
that it seems to use for operand alignment. So it's better without, so that it
respects our two-tabs `ContinuationIndentWidth`.
2021-10-28 13:23:38 +02:00
PouleyKetchoupp
562d9cef1b Fix RigidBody collision update after changing collision layer/mask
Changing the collision layer of a sleeping body was not triggering area
updates correctly.

Bodies need to be active for collision to be checked against already
overlapping bodies and areas.

Neighbors need to be activated too in order to handle the case where a
static body is modified (it can't be activated directly but paired
bodies need to check their collision again).

In 3D, moved the call to wakeup() from the physics server to
BodySW::_shapes_changed to make it consistent with 2D and also handle
the case where shapes are modified (_shapes_changed is called in both
this case and collision layer changes).
2021-10-21 17:22:47 -07:00
PouleyKetchoupp
48144ed40e Fix physics BVH broadphase update when changing collision layer/mask
The BVH implementation is not checking collision layers on existing
pairs on move like other physics broadphases do.

This is solved by adding a new call to trigger pair callbacks again so
the physics engine can check layers again (specific to the BVH version,
other broadphase implementations just trigger a move like before).
2021-10-21 16:53:41 -07:00
Rémi Verschelde
abb1413e0f
Merge pull request #53453 from nekomatata/fix-rayshape-snap-3.x 2021-10-06 08:37:57 +02:00
PouleyKetchoupp
255febefb2 Fix Rayshape recovery in test_body_ray_separation
These changes improve Rayshape behavior for Godot Physics 2D and 3D
when using move_and_slide with and without snapping.

Kinematic margin is now applied to ray shapes when handling snapping
collision tests and separation raycasts to help getting consistent
results in slopes and flat surfaces.

Recovery is calculated without the margin and a depth of 0 is still
considered a collision to stabilize results when on flat surface.

Recovery depth takes into account the current recovery vector (just like
test_body_motion) to fix jittering issues with multiple ray shapes due
to applying too much recovery.
2021-10-05 18:24:30 -07:00
PouleyKetchoupp
9bc1b4b90e Improved logic for KinematicBody collision recovery depth
Allows more flexible collision detection with different safe margin values.

Kinematic body motion changes in 2D and 3D:
-Recovery only for depth > min contact depth to help with collision
detection consistency (rest info could be lost if recovery was too much)
-Adaptive min contact depth (based on margin) instead of space parameter
2021-10-05 17:00:55 -07:00
Daniel
57b3b5108a Added wakeup() call to velocity, force and impulse functions. 2021-09-28 19:00:10 +13:00
PouleyKetchoupp
bb6760a09f Optimize raycast with large Heightmap shape data
Port raycast accelerator from Bullet's btHeightfieldTerrainShape.
2021-09-06 15:59:47 -07:00
Camille Mohr-Daurat
095dea7b71
Merge pull request #48551 from nekomatata/concave-shape-optimization-3.x
[3.x] Optimize area detection and intersect_shape queries with concave shapes
2021-09-06 09:36:27 -07:00
LoipesMas
32965aa0ab Epsilon check for angular velocity in BodySW 2021-08-16 20:11:46 +02:00
PouleyKetchoupp
da159cd258 Fix 3D moving platform logic
Same thing that was already done in 2D, applies moving platform motion
by using a call to move_and_collide that excludes the platform itself,
instead of making it part of the body motion.

Helps with handling walls and slopes correctly when the character walks
on the moving platform.

Also made some minor adjustments to the 2D version and documentation.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-08-09 18:55:49 -07:00
Rémi Verschelde
0403cb8ad5
Merge pull request #51447 from nekomatata/fix-moving-platform-rotation-3.x
[3.x] Fix applied rotation from moving platforms in move_and_slide
2021-08-09 23:20:35 +02:00
PouleyKetchoupp
f101349225 Fix applied rotation from moving platforms in move_and_slide
When synchronizing KinematicBody motion with moving the platform using
direct body state, only the linear velocity was taken into account.

This change exposes velocity at local point in direct body state and
uses it in move_and_slide to get the proper velocity that includes
rotations.
2021-08-09 12:04:57 -07:00
lawnjelly
37f20e1d78 Fix Transform::xform(Plane) functions, add Transform unit tests
The Transform::xform and xform_inv are made safe for Planes when using non-uniform scaling.

Basic unit tests for Transform.

Optimization of calling sites to prevent loss of performance from the changes to xform(Plane).
2021-08-07 08:05:39 +01:00
PouleyKetchoupp
6fdffacb4e 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-08-04 10:41:58 -07:00
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