Commit graph

262 commits

Author SHA1 Message Date
Juan Linietsky
71d2e38cb5 Optimize Convex Collision
Implements the Gauss Mapping optimization to SAT convex collision test.

* Described [here](https://ubm-twvideo01.s3.amazonaws.com/o1/vault/gdc2013/slides/822403Gregorius_Dirk_TheSeparatingAxisTest.pdf) by Dirk Gregorius.
* Requires adding of face information to edges in MeshData
* Took the chance to convert MeshData to LocalVector for performance.
2022-10-13 19:07:53 +02:00
bruvzg
0103af1ddd
Fix MSVC warnings, rename shadowed variables, fix uninitialized values, change warnings=all to use /W4. 2022-10-07 11:32:33 +03:00
Rémi Verschelde
5b6ccf2fd2 Merge pull request #66720 from qarmin/unintialized_memory
Remove usage of unitialized variables
2022-10-05 11:42:47 +02:00
Rafał Mikrut
2233624152 Remove usage of unitialized variables 2022-10-01 21:09:22 +02:00
Haoyu Qiu
8320e12ac1 Fix crash when executing PhysicsServer2D.joint_clear 2022-09-30 10:36:05 +08:00
Rémi Verschelde
6b5880b765 Merge pull request #66568 from rburing/cylinder_support_is_dead
`GodotCylinderShape3D::get_supports`: delete dead code
2022-09-28 23:52:28 +02:00
Ricardo Buring
215c5458f5 GodotCylinderShape3D::get_supports: delete dead code 2022-09-28 21:37:37 +02:00
Rémi Verschelde
85fe6ecc32 Fix MSVC warnings C4701 and C4703: Potentially uninitialized variable used 2022-09-28 17:05:34 +02:00
Rémi Verschelde
49fcf4ffad Style: Cleanup header guards for consistency
Fix file names for {Static,Lightmap}RaycasterEmbree.
2022-09-26 13:51:17 +02:00
Mansur Isaev
efd4dc20a3 Add area_get_collision_layer and area_get_collision_mask 2022-09-25 14:34:35 +04:00
Rémi Verschelde
28e1dc6162 Merge pull request #65828 from rburing/body_state_sync_callable
make `body_set_state_sync_callback` take a `Callable`
2022-09-21 11:05:41 +02:00
fabriceci
7a15ccfa7b Warn users when collisions are not supported 2022-09-19 16:51:41 +02:00
Ricardo Buring
ff4e72a0bc PhysicsServer2D and PhysicsServer3D: make body_set_state_sync_callback take a Callable
Prefer Callable to a C-style callback. This is helpful for GDExtension.
2022-09-15 15:09:23 +02:00
Jonathan Nicholl
15d057c521 Add is_zero_approx methods to Vector2, 3, and 4 2022-09-02 00:29:50 -04:00
Ricardo Buring
da37540d97 Fix collision solving between world boundary and motion shape 2022-08-27 19:51:14 +02:00
Rémi Verschelde
f9f2446972
Merge pull request #64367 from Mickeon/rename-var-to-str
Rename `str2var` to `str_to_var` and similar
2022-08-26 23:04:06 +02:00
Micky
59e11934d8 Rename str2var to str_to_var and similar
Affects the Math class, a good chunk of the audio code, and a lot of other miscellaneous classes, too.

- `var2str` -> `var_to_str`
- `str2var` -> `str_to_var`
- `bytes2var` -> `bytes_to_var`
- `bytes2var_with_objects` -> `bytes_to_var_with_objects`
- `var2bytes` -> `var_to_bytes`
- `var2bytes_with_objects` -> `var_to_bytes_with_objects`
- `linear2db` -> `linear_to_db`
- `db2linear` -> `db_to_linear`
- `deg2rad` -> `deg_to_rad`
- `rad2deg` -> `rad_to_deg`

- `dict2inst` -> `dict_to_inst`
- `inst2dict` -> `inst_to_dict`
2022-08-26 14:58:22 +02:00
fabriceci
f8cc88fab3 Restore RigidBody2/3D, SoftBody names in physics 2022-08-26 12:26:25 +02:00
Silc Renew
b31115cdc1 Add collision weight to PhysicsBody for penetrations must be avoided
Co-authored-by: Juan Linietsky <reduzio@gmail.com>
2022-08-18 08:10:31 +09:00
Silc Renew
7331295523 add get_depth() to KinematicCollision3D as same of 2D 2022-08-10 10:33:58 +09:00
Ryan Heath
9d4e5a466e Add area monitor callback error checking 2022-08-07 13:47:03 -07:00
Juan Linietsky
d4433ae6d3 Remove Signal connect binds
Remove the optional argument p_binds from `Object::connect` since it was deprecated by Callable.bind().
Changed all uses of it to Callable.bind()
2022-07-29 16:26:13 +02:00
Juan Linietsky
c7255388e1 Remove ThreadWorkPool, replace by WorkerThreadPool
The former needs to be allocated once per usage. The later is shared for all threads, which is more efficient.
It can also be better debugged.
2022-07-25 15:39:50 +02:00
Rémi Verschelde
90019676b0 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 11:17:40 +02:00
reduz
141c375581 Clean up Hash Functions
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in #61934
* Clean up usage of murmur3
* Fixed usages of binary murmur3 on floats (this is invalid)
* Changed DJB2 to use xor (which seems to be better)
2022-06-20 12:54:19 +02:00
Hugo Locurcio
36428305a6
Add a 3D suffix to relevant physics profiler categories
2D physics categories already had a 2D suffix: "Physics 2D"
2022-05-28 00:54:53 +02:00
Nathan Franke
77c8f271e7
use ERR_FAIL_INDEX when preferred 2022-05-25 13:36:45 -05:00
reduz
45af29da80 Add a new HashSet template
* Intended to replace RBSet in most cases.
* Optimized for iteration speed
2022-05-20 22:40:38 +02:00
Aaron Record
900c676b02 Use range iterators for RBSet in most cases 2022-05-19 12:09:16 +02:00
Ricardo Buring
f072aa69a9 Add motion parameter to toggle whether recovery is reported as a collision
This makes the intent explicit in each use case.
2022-05-18 16:40:29 +02:00
reduz
746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +02:00
Aaron Franke
fa7a7795f0
Rename Basis get_axis to get_column, remove redundant methods 2022-05-03 09:37:47 -05:00
Rémi Verschelde
c273ddc3ee Style: Partially apply clang-tidy's cppcoreguidelines-pro-type-member-init
Didn't commit all the changes where it wants to initialize a struct
with `{}`. Should be reviewed in a separate PR.

Option `IgnoreArrays` enabled for now to be conservative, can be
disabled to see if it proposes more useful changes.

Also fixed manually a handful of other missing initializations / moved
some from constructors.
2022-05-02 16:28:25 +02:00
bruvzg
f851c4aa33
Fix some issues found by cppcheck. 2022-04-06 14:34:37 +03:00
Rémi Verschelde
f8ab79e68a Zero initialize all pointer class and struct members
This prevents the pitfall of UB when checking if they have been
assigned something valid by comparing to nullptr.
2022-04-04 19:49:50 +02:00
lawnjelly
109d08c84a Add protective checks for invalid handle use in BVH
Adds DEV_ASSERTS that will halt at runtime if the BVH is misused with invalid IDs, and adds ERR_FAIL macros to prevent calling with invalid IDs.

Any such misuse is a bug in the physics, but this should flag any errors quickly.
2022-03-23 09:19:26 +00:00
Ricardo Buring
3d4be5d4c2 Raycasts hitting from inside: return collision point in global coordinates 2022-03-20 10:31:03 +01:00
reduz
8b547331be Create GDExtension clases for PhysicsServer3D
* Allows creating a GDExtension based 3D Physics Server (for Bullet, PhysX, etc. support)
* Some changes on native struct binding for PhysicsServer

This allows a 3D Physics server created entirely from GDExtension. Once it works, the idea is to port the 2D one to it.
2022-03-15 18:39:31 +01:00
lawnjelly
f199d2c33c [4.x] BVH - Fix area-area collision regression
Minimal approach to fixing regression whereby static areas where not detect dynamic areas.
2022-03-06 14:03:19 +00:00
Rémi Verschelde
0d1e3893d9
Merge pull request #57630 from lawnjelly/bvh4_templated_checks
[4.x] BVH - Sync BVH with 3.x
2022-03-04 23:29:38 +01:00
Ricardo Buring
d525ea2614 In final phase of test_body_motion, move and cull AABB for body once, instead of for every shape 2022-02-18 19:45:25 +01:00
Rémi Verschelde
b8b4580448
Style: Cleanup single-line blocks, semicolons, dead code
Remove currently unused implementation of TextureBasisU, could be re-added
later on if needed and ported.
2022-02-16 14:06:29 +01:00
lawnjelly
f8eaab5b47 BVH - Sync BVH with 3.x
Templated mask checks and generic NUM_TREES
Fix leaking leaves
2022-02-04 16:51:21 +00:00
TechnoPorg
02c002ff28 Fix triangular area calculation
It's a triangle, so the area should be halved.

Co-authored-by: Jeffrey Cochran <koenigcochran@gmail.com>
2022-01-27 09:57:15 -07:00
Omar Polo
bd448e5535 Rename or refactor macros to avoid leading underscores
These are not used consistently and some can conflict with
system-specific defines.  While here, also delete some unused macros.
2022-01-20 20:29:15 +01:00
Rémi Verschelde
fe52458154
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
Camille Mohr-Daurat
f1ca14cc8d
Merge pull request #55736 from nekomatata/physics-apply-forces
Improve RigidDynamicBody force and torque API
2021-12-10 17:16:28 -07:00
Camille Mohr-Daurat
c6fe431a02
Merge pull request #55773 from nekomatata/fix-raycast-ccd
Fix rigid body ray cast CCD in 2D and 3D Godot Physics
2021-12-10 17:16:02 -07:00
PouleyKetchoupp
30a608b7b9 Fix rigid body ray cast CCD in 2D and 3D Godot Physics
For 2D:
Raycast CCD now works the same as in 3D, it changes the body's velocity
to place it at the impact position instead of generating a contact point
that causes a wrong push back.

For both 2D and 3D:
The raycast CCD process reads and modifies body velocities, so it needs
to be moved to pre_solve() instead of setup() to be processed linearly
on the main thread, otherwise multithreading can cause some CCD results
to be randomly lost when multiple collisions occur.
2021-12-10 16:25:14 -07:00
PouleyKetchoupp
940f3fde5c Improve RigidDynamicBody force and torque API
Makes the API for forces and impulses more flexible, easier to
understand and harmonized between 2D and 3D.

Rigid bodies now have 3 sets of methods for forces and impulses:
-apply_impulse() for impulses (one-shot and time independent)
-apply_force() for forces (time dependent) applied for the current step
-add_constant_force() for forces that keeps being applied each step

Also updated the documentation to clarify the different methods and
parameters in rigid body nodes, body direct state and physics servers.
2021-12-10 15:55:40 -07:00