Commit graph

106 commits

Author SHA1 Message Date
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
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
reduz
8b7c7f5a75 Add a new HashMap implementation
Adds a new, cleaned up, HashMap implementation.

* Uses Robin Hood Hashing (https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing).
* Keeps elements in a double linked list for simpler, ordered, iteration.
* Allows keeping iterators for later use in removal (Unlike Map<>, it does not do much
  for performance vs keeping the key, but helps replace old code).
* Uses a more modern C++ iterator API, deprecates the old one.
* Supports custom allocator (in case there is a wish to use a paged one).

This class aims to unify all the associative template usage and replace it by this one:
* Map<> (whereas key order does not matter, which is 99% of cases)
* HashMap<>
* OrderedHashMap<>
* OAHashMap<>
2022-05-12 11:21:29 +02:00
Haoyu Qiu
380a53f02f Add search methods for packed arrays
* count()
* find()
* rfind()
2022-05-07 20:16:11 +08:00
AndreaCatania
4066349488 Add mutable OAHashMap::lookup_ptr function to fix mutability. 2022-04-22 09:20:15 +02:00
Rémi Verschelde
c3cf4d4974
Merge pull request #60078 from Pineapple/cowdata-get-data
Remove get_data() from CowData
2022-04-12 14:27:48 +02:00
Bartłomiej T. Listwon
6dfcfecd3d Remove get_data() from CowData 2022-04-09 21:25:31 +02:00
Mark Riedesel
4f3769fd75 add SafeList destructor which calls maybe_cleanup() to prevent mem leak 2022-04-08 09:50:49 -04: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
mashumafi
9c2bfeb2fb Const Ref Callable for custom sort/search 2022-03-27 22:10:36 -04:00
kobewi
39d429e497 Change some math macros to constexpr
Changes `MAX`, `MIN`, `ABS`, `CLAMP` and `SIGN`.
2022-03-09 16:24:32 +01:00
reduz
b0ca03b0a2 Add a UniformSet cache
* Changed syntax usage for RD::Uniform to create faster with a single RID
* Converted render pass setup to use this in clustered renderer to test.

This is the first step into creating a proper uniform set cache system to simplify large parts of the codebase.
2022-03-06 13:03:33 +01: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
Haoyu Qiu
3057b19daa Make VMap::find_nearest return -1 when empty 2022-02-16 16:12:30 +08:00
reduz
74adf0bf2e Remove RID_Owner.get_rid_by_index
* Implementing this function efficiently is not really possible.
* Replaced by an option to get all RIDs into a buffer for performance.
2022-02-05 11:59:34 +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
Anilforextra
fc27636999 Vectors: Use clear() and has().
Use clear() instead of resize(0).

Use has() instead of "find(p_val) != -1".
2022-02-02 00:11:09 +05:45
Rémi Verschelde
9912492e93
Merge pull request #56668 from akien-mga/array-slice-nicer-bound-checks 2022-01-18 13:22:35 +01:00
Rémi Verschelde
585231a172
Merge pull request #56492 from akien-mga/remove-author-docstrings 2022-01-12 15:24:17 +01:00
Rémi Verschelde
c6cefb1b79
Array: Relax slice bound checks to properly handle negative indices
The same is done for `Vector` (and thus `Packed*Array`).

`begin` and `end` can now take any value and will be clamped to
`[-size(), size()]`. Negative values are a shorthand for indexing the array
from the last element upward.

`end` is given a default `INT_MAX` value (which will be clamped to `size()`)
so that the `end` parameter can be omitted to go from `begin` to the max size
of the array.

This makes `slice` works similarly to numpy's and JavaScript's.
2022-01-10 22:42:03 +01:00
Haoyu Qiu
af67e4c291 Fix crash on importing FBX file 2022-01-10 18:24:31 +08:00
Haoyu Qiu
c0d3bdc0ca Add list initialization support for Vector & LocalVector 2022-01-05 20:42:09 +08:00
Rémi Verschelde
ba2bdc478b
Style: Remove inconsistently used @author docstrings
Each file in Godot has had multiple contributors who co-authored it over the
years, and the information of who was the original person to create that file
is not very relevant, especially when used so inconsistently.

`git blame` is a much better way to know who initially authored or later
modified a given chunk of code, and most IDEs now have good integration to
show this information.
2022-01-04 20:42:50 +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
Rémi Verschelde
46d384060e
Merge pull request #35901 from nathanfranke/pool-byte-array-subarray-exclusive 2021-12-07 14:00:59 +01:00
Rémi Verschelde
7da392bcc5
Don't return reference on copy assignment operators
We prefer to prevent using chained assignment (`T a = b = c = T();`) as this
can lead to confusing code and subtle bugs.

According to https://en.wikipedia.org/wiki/Assignment_operator_(C%2B%2B), C++
allows any arbitrary return type, so this is standard compliant.

This could be re-assessed if/when we have an actual need for a behavior more
akin to that of the C++ STL, for now this PR simply changes a handful of
cases which were inconsistent with the rest of the codebase (`void` return
type was already the most common case prior to this commit).
2021-11-30 16:26:29 +01:00
Nathan Franke
dd30253cdc
PackedByteArray, Array slice end exclusive, rename subarray to slice 2021-11-26 22:13:12 -06:00
Lightning_A
e078f970db Rename remove() to remove_at() when removing by index 2021-11-23 18:58:57 -07:00
Rémi Verschelde
fc9de5ba7f
Merge pull request #54499 from Faless/threads/4.x_work_pool_default 2021-11-19 09:39:21 +01:00
Rémi Verschelde
e87687a6d0
Merge pull request #54486 from ibrahn/thread-work-pool-lazier 2021-11-08 13:39:39 +01:00
Fabio Alessandrelli
4ed1d977fc [OS] Add ThreadWorkPool default size to OS.
Some platforms (*cough* web *cough*) have hard limits on the number of
threads that can be spawned.

Currently, ThreadPoolWork (mostly used in rendering/physics servers)
will spawn as many threads as CPUs available causing exception on
machines with high CPU count.

This commit adds a new overridable method to OS that returns the default
thread pool size (still the CPU count by default), and overrides it for
the JavaScript platform so it always allocate only one thread.

We can likely improve the whole ThreadPoolWork in the future to always
allocate X amount of threads, and assign jobs to them on the fly, but
that will require some more architectural changes.
2021-11-02 04:16:00 +01:00
Ibrahn Sahir
151d2e34ca ThreadWorkPool no longer starts worker threads if given zero work. 2021-11-01 19:19:25 +00:00
Emmanuel Leblond
f9ba2efe1e
Modify Dictionary::operator== to do real key/value comparison with recursive support (and add unittests) 2021-10-30 13:11:01 +02:00
Rémi Verschelde
3a6be64c12
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 15:43:36 +02:00
Pedro J. Estébanez
f80e4e4f4c Fix HashMap element copy leaving hash as zero 2021-10-13 17:25:31 +02:00
Rémi Verschelde
6f1d2133bb
Merge pull request #52495 from kdiduk/issue-52491-fix-value-conversion-in-hashfuncs-header
#52491 Cosmetic: fix type cast so that it matches return value type
2021-10-12 22:38:39 +02:00
Pedro J. Estébanez
73697d4de6 Avoid the need for copy assignment in HashMap key/data types 2021-10-08 20:06:07 +02:00
Kirill Diduk
1f38b00242 #52491 Cosmetic: fix type cast and add comment with the algorithm source 2021-10-05 21:40:33 +02:00
Rémi Verschelde
b32f84d473
Merge pull request #52850 from mashumafi/vector-bsearch 2021-10-01 07:52:51 +02:00
mashumafi
214bbfbefe Implement bsearch for Vector and Packed*Array 2021-09-30 23:57:26 +00:00
Hugo Locurcio
ba65730cbf
Rename RID's getornull() to get_or_null() 2021-09-29 23:58:02 +02:00
Hugo Locurcio
6def32d643
Replace #pragma once by traditional include guards for consistency
`#pragma once` was used in a few files, yet we settled on using
traditional include guards instead.

The PooledList template comment was also moved to allow editors
such as Visual Studio Code to display the comment when hovering
PooledList.

`app.h` was renamed to `app_uwp.h` to be less generic for the
include guard.
2021-09-24 02:33:15 +02:00
Grigoris Pavlakis
abef2b7194 Fix placement new on zero-sized region warning on GCC 11.1
On latest (11.1 as of this commit) GCC, the following warning is
continuously issued during build:
warning: placement new constructing an object of type
'SafeNumeric<unsigned int>' and size '4' in a region of type
'uint32_t*' {aka 'unsigned int*'} and size '0' [-Wplacement-new=]

This happens because on 98ceb60eb4 the new operator override used
was dropped and replaced with standard placement new. GCC sees the
subtraction from the pointer and complains as it thinks that the
SafeNumeric is placed outside an allocation, not knowing that the
address requested is already inside one.

After suggestions, the false positive is silenced, with no other
changes.
2021-09-15 00:07:21 +03:00
Ellen Poe
f5d9c7b487 Replace stb_vorbis with libogg+libvorbis 2021-09-09 19:39:04 -07:00
Hugo Locurcio
ac7541c1b1
Merge pull request #52026 from Calinou/constiterator-fix-const
Fix ConstIterator to allow `for` range loops on Packed*Array
2021-09-01 14:25:01 +02:00
Juan Linietsky
6dab6e4136
Revert " Improve collision generation usability in the new 3D scene import workflow." 2021-08-30 11:30:36 -03:00
Camille Mohr-Daurat
b60a51f023
Merge pull request #51985 from AndreaCatania/coll
Improve collision generation usability in the new 3D scene import workflow.
2021-08-30 07:25:51 -07:00
Ellen Poe
460e0ce314 Add a SafeList data structure for future audio server usage. 2021-08-27 10:26:18 -07:00