Commit graph

602 commits

Author SHA1 Message Date
lawnjelly
5162efbfe9 2D Fixed Timestep Interpolation
Adds support to canvas items and Camera2D.
2023-08-01 16:07:48 +01:00
fabriceci
8245fd3275
Test, refactor and fix a bug in Basis.get_axis_angle
Backport of #63428.

Co-authored-by: juanFdS <juan9794@gmail.com>
2023-06-07 13:47:47 +02:00
lawnjelly
6f8e632848 Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input.

The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
2023-05-11 09:51:44 +01:00
Aaron Franke
141783d90f
[3.x] Expose determinant in Transform2D, rename internal method 2023-04-22 13:47:47 -05:00
Rémi Verschelde
5faa423944
Math: Prevent division by zero in posmod
Fixes #43932.

Co-authored-by: David Hoppenbrouwers <david@salt-inc.org>
(cherry picked from commit f011d8ca9c)
2023-03-06 13:48:13 +01:00
lawnjelly
5639be5f4f BVH - fix lockguards for multithread mode
Due to a lack of variable name, the BVH lock guards lifetimes previously did not cover the whole function call.
2023-02-20 15:43:19 +00: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
2ef0052113 Fix array-bounds warning in BVH
Provides a workaround to prevent tripping a compiler warning.

(cherry picked from commit 91d252c697)
2022-12-04 20:00:08 +08:00
Rémi Verschelde
f9b91d8d24 Style: Ensure consistent formatting with clang-format 15 2022-09-21 13:23:17 +02:00
Marcel Admiraal
3cbc6330bb Fix Geometry::get_closest_points_between_segments() returns NaN
Also fix Geometry::get_closest_distance_between_segments() returning
incorrect values.
2022-09-01 17:51:33 +01:00
Ricardo Buring
90725964a4 Fixup BVH debugging statements 2022-07-25 18:35:14 +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
fabriceci
43e9816fb1 Fix the calculation of the angular velocity when the rotation speed is not high.
(cherry picked from commit db7c91e0ad)
2022-07-19 17:16:21 +02:00
Marcel Admiraal
b8b7c21583 Ensure AudioFrame variables l and r are always initialised
(cherry picked from commit d3f0994572)
2022-06-20 14:58:57 +02:00
Theraot
6007d7f0ed Added missing p_bidirectional to AStar2D methods
The methods disconnect_points and are_points_connected  now have an optional p_bidirectional parameter matching AStar.

(cherry picked from commit 3590cdfd34)
2022-06-16 20:49:01 +02:00
Yuri Rubinsky
d525d902c1 Fix wrapf to correct wrap values with 0.1 stepping
(cherry picked from commit 09418afbc0)
2022-06-16 10:10:48 +02:00
Rémi Verschelde
80b82e4e66 i18n: Misc fixes translation strings
Adds some translator comments to solve some questions raised on Weblate.
2022-06-08 12:56:42 +02:00
lawnjelly
ba74643594 Force unsigned behaviour for bitfield enums
Some compilers (notably MSVC) were using signed values for bitfield enums. This was causing problems where 2 bits were used to store 4 or less enum values, where they were being treated as negative numbers.

This PR explicitly requests these enums to be treated as unsigned values.
2022-06-06 16:58:21 +01:00
Rémi Verschelde
5e693b6d84 Fix warnings found by Emscripten 3.1.10
Fix `-Wunused-but-set-variable`, `-Wunqualified-std-cast-call`, and
`-Wliteral-range` warnings.

(cherry picked from commit d8935b27a9)
2022-05-16 16:38:26 +02:00
smix8
da9a88a35a Allow AStar/AStar2D zero point weight
Allow AStar/AStar2D zero point weight.

Limit was set to 1 which seemed like an arbitrary value as lower values down to zero can be useful for common gameplay navigation elements like teleports.
2022-05-06 02:33:31 +02:00
Rémi Verschelde
9e37599f36 Core: Rename math 'phi' arguments to 'angle'
(cherry picked from commit e7a58a7eb6)
2022-05-05 15:02:46 +02:00
Rémi Verschelde
445339e1b2
Merge pull request #58427 from lawnjelly/safe_vector2 2022-03-07 12:39:28 +01:00
lawnjelly
0bcda22d7c Protection for array operator for Vector2 / 3 in DEV builds
A previous PR had changed the array operator to give unbounded access. This could cause crashes where old code depended on this previous safe behaviour.

This PR adds DEV_ASSERT macros for out of bound access to DEV builds, allowing us to quickly identify bugs in calling code, without affecting performance in release or release_debug editor builds.
2022-03-07 10:34:40 +00:00
lawnjelly
d24c715678 Float literals - fix math classes to allow 32 bit calculations
Converts float literals from double format (e.g. 0.0) to float format (e.g. 0.0f) where appropriate for 32 bit calculations, and cast to (real_t) or (float) as appropriate.

This ensures that appropriate calculations will be done at 32 bits when real_t is compiled as float, rather than promoted to 64 bits.
2022-02-24 16:46:02 +00:00
lawnjelly
522bce1159 Fixed Timestep Interpolation (3D)
Adds fixed timestep interpolation to the visual server.
Switchable on and off with project setting.

This version does not add new API for set_transform etc, when nodes have the interpolated flag set they will always use interpolation.
2022-02-16 09:41:23 +00: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
Hayden
6d867b6d13
Make parser treat all exponent literals as float
(cherry picked from commit 1305ff92f7)
2022-02-11 09:50:58 +01:00
Hayden Leete
61cd26be28
Added hex and bin literal support to Expression parser
fixed formatting

(cherry picked from commit 018de19eba)
2022-02-11 09:50:58 +01:00
Bartłomiej T. Listwon
134aac5725 Fix Vector2 and Vector2i coord access via operator[] 2022-02-09 09:18:05 +01:00
lawnjelly
90bea27e82 BVH - fix leaking leaves
In the BVH leaf nodes are a combination of two objects - a node object, and a leaf object. Testing revealed that in some situations node objects could be freed without also freeing the paired leaf object. This closes this bug.
2022-02-03 08:05:57 +00:00
lawnjelly
8ea20f5fdd Add OccluderShapePolygon
Add OccluderShapePolygon, glue to Occluder and gizmos etc.
2022-02-01 11:31:06 +00: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
lawnjelly
adf14bfdde Add nodiscard to core math classes to catch c++ errors.
A common source of errors is to call functions (such as round()) expecting them to work in place, but them actually being designed only to return the processed value. Not using the return value in this case in indicative of a bug, and can be flagged as a warning by using the [[nodiscard]] attribute.
2022-01-20 17:28:31 +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
Rémi Verschelde
09884f17a3
Revert "Warn when using an AABB or Rect2 with a negative size"
This reverts commit d75e580765.

Fixes #56509.
2022-01-12 17:28:03 +01:00
Rémi Verschelde
b197de6f5f
Fix typos with codespell
Using codespell 2.1.0.

Method:
```
$ cat > ../godot-word-whitelist.txt << EOF
ang
curvelinear
dof
doubleclick
fave
findn
GIRD
leapyear
lod
merchantibility
nd
numer
ois
ony
que
readded
seeked
statics
synching
te
uint
unselect
webp
EOF

$ codespell -w -q 3 -I ../godot-word-whitelist.txt --skip="./thirdparty,*.po"
$ git diff // undo unwanted changes
```
2022-01-07 00:14:54 +01:00
Aaron Franke
d75e580765
Warn when using an AABB or Rect2 with a negative size
(cherry picked from commit 9687f6fca3)
2021-12-06 16:51:59 +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
Aaron Franke
1d8cef8236
[3.x] Backport some APIs in math structs 2021-11-27 01:19:45 -06: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
4a29f657b6
Merge pull request #55050 from lawnjelly/bvh_detect_shrinkage 2021-11-19 17:39:12 +01:00
Marcel Admiraal
4d3690eba5 Remove unimplemented methods 2021-11-18 12:47:36 +00:00
lawnjelly
9315b4fb51 BVH - fix typename compiler warning
Some versions of microsoft compiler flag a warning that they want a typename keyword in templates in more places than clang / gcc.
2021-11-18 07:42:00 +00:00
lawnjelly
ed47570266 BVH - detect shrinkage within expanded bounds
Although the expanded bounds were working in normal use, for moving and growing objects, there was one case which was not dealt with properly - significant shrinkage of exact bounds within an expanded bound.

This PR detects significant shrinkage and forces a new expanded bound to be created.
2021-11-17 09:06:10 +00: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
Rémi Verschelde
14ef65e49b
Merge pull request #54348 from akien-mga/3.x-clang-format-dont-align-operands 2021-10-28 15:43:15 +02:00
Rémi Verschelde
87c80f529f
clang-format: Enable BreakBeforeTernaryOperators
clang-format keeps breaking the way it handles break *after* ternary operators,
so I give up and go with the only style they seem to actually test.
2021-10-28 14:50:33 +02: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
ba424a22d3 Fix crash due to recheck pair process in BVH broadphase
The pair user data wasn't correctly updated in the BVH from the check
pair callback.

This could lead to crashes when the check caused logical unpairing in
physics, then actual unpairing from the broadphase occured and the
physics server tried to delete an already deleted pointer.
2021-10-26 09:17:36 -07:00