Commit Graph

103 Commits

Author SHA1 Message Date
342266cfd9 Overhaul Variant::duplicate() for resources
This in the scope of a duplication triggered via any type in the `Variant` realm. that is, the following: `Variant` itself, `Array` and `Dictionary`. That includes invoking `duplicate()` from scripts.

A `duplicate_deep(deep_subresources_mode)` method is added to `Variant`, `Array` and `Dictionary` (for compatibility reasons, simply adding an extra parameter was not possible). The default value for it is `RESOURCE_DEEP_DUPLICATE_NONE`, which is like calling `duplicate(true)`.

Remarks:
- The results of copying resources via those `Variant` types are exactly the same as if the copy were initiated from the `Resource` type at C++.
- In order to keep some separation between `Variant` and the higher-level animal which is `Resource`, `Variant` still contains the original code for that, so it's self-sufficient unless there's a `Resource` involved. Once the deep copy finds a `Resource` that has to be copied according to the duplication parameters, the algorithm invokes the `Resource` duplication machinery. When the stack is unwind back to a nesting level `Variant` can handle, `Variant` duplication logic keeps functioning.

While that is good from a responsibility separation standpoint, that would have a caveat: `Variant` would not be aware of the mapping between original and duplicate subresources and so wouldn't be able to keep preventing multiple duplicates.

To avoid that, this commit also introduces a wormwhole, a sharing mechanism by which `Variant` and `Resource` can collaborate in managing the lifetime of the original-to-duplicates map. The user-visible benefit is that the overduplicate prevention works as broadly as the whole `Variant` entity being copied, including all nesting levels, regardless how disconnected the data members containing resources may be across al the nesting levels. In other words, despite the aforementioned division of duties between `Variant` and `Resource` duplication logic, the duplicates map is shared among them. It's created when first finding a `Resource` and, however how deep the copy was working at that point, the map kept alive unitl the stack is unwind to the root user call, until the first step of the recursion.

Thanks to that common map of duplicates, this commit is able to fix the issue that `Resource::duplicate_for_local_scene()` used to ignore overridden duplicate logic.
2025-05-26 10:06:40 +02:00
0d267e7b1e Core: Add dedicated BitField template 2025-04-11 11:53:26 -05:00
f7e4987d0e Dictionary::get_key_list use LocalVector instead of List. 2025-04-09 02:46:24 +08:00
8a93218aab Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
f6a35e2a6e Merge pull request #86015 from kitbdev/array-initializer-list
Add list initialization to Array, Variant, and TypedArray
2025-03-19 17:46:06 -05:00
0c7d78f455 StringLikeVariantOrder: Compare in-place 2025-03-18 11:21:30 -07:00
7f6a9380a0 Merge pull request #103999 from YYF233333/unneeded_array_read_only
Remove unneeded `read_only` check for `Array` const operator
2025-03-13 08:57:22 -05:00
75bc471965 Add is_zero_constructible to denote if a type can be semi-trivially constructed with all 0 bytes.
Optimize `CowData` and `LocalVector` resize for zero constructible types.
Mark several compatible types as `is_zero_constructible`.
2025-03-12 09:49:24 +01:00
883ca56517 Remove unneeded read_only check for Array const operator. 2025-03-12 07:22:42 +08:00
324512e11c Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
91fda4ecaf Merge pull request #101055 from Ivorforce/variant-to-number-consolidate
Consolidate `Variant` int and float conversion functions to reduce duplicate logic.
2025-01-06 22:48:24 +01:00
0e72967244 Consolidate Variant int and float conversion functions to reduce duplicate logic. 2025-01-03 20:16:43 +01:00
46c23e1758 Don't set Variant::Type in destructor
When profiling Dome Keeper, I found that in physics_process a HashMap
gets cleared a lot, which ends up calling the Variant destructor.
Calling Variant::clear() dominates this operation.

By not uselessly setting the Type to NIL on destruction we save about
50% of time. This is likely because if there is a simple type in the
Variant that doesn't need destructing, but now we write when we should
just drop the Variant altogether.

Since the value of Variant::type should be unobservable after
destruction this doesn't change any outward behavior.
2024-12-25 23:40:19 +01:00
34fa0bf3ec Add move assignment and move constructor to Variant.
Add `_to_variant` helper functions to `gdvirtual.gen.inc` to work around an MSVC bug.
2024-12-15 14:38:46 +01:00
bd1a35ce9e Core: Fix JSON.{from,to}_native() issues 2024-11-29 12:43:06 +03:00
03b05cf9ac Core: Fix built-in enum constant bindings 2024-11-22 14:03:21 +03:00
89a311205f Style: Apply clang-tidy fixes
• `modernize-use-default-member-init` and `readability-redundant-member-init`
• Minor adjustments to `.clang-tidy` to improve syntax & remove redundancies
2024-11-04 12:11:06 -06:00
79f654ced5 [Core] Fix sorting of Dictionary keys
`StringName` keys were sorted as `StringName` which is unstable.
2024-10-18 08:47:05 +02:00
cee0e6667a Refactor ref-counting code and fix ref counted releasing before aquiring 2024-09-21 11:36:58 -07:00
71accb9008 Merge pull request #94679 from rune-scape/remove-unused-initialize_ref
Remove unused `initialize_ref`
2024-08-28 00:12:16 +02:00
496b7b8482 Core: Improve vformat error reporting on sprintf failure
And fix a few occurrences of formatting errors that led me to this.
2024-07-04 10:54:55 +02:00
c8b697c64c Remove unused initialize_ref 2024-07-03 13:32:50 -07:00
7599a7b719 Core: Readd Variant class initializer, fix comment 2024-05-14 12:20:40 -05:00
413c11357d Use Core/Scene stringnames consistently 2024-05-13 23:41:07 +02:00
f9b488508c Add PackedVector4Array Variant type
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
2024-05-03 00:58:27 +02:00
kit
cb17798df3 Add Array and Variant list inializer 2024-05-02 15:35:17 -04:00
c4e24d2b3b [GDScript] Correctly report invalid read-only access 2024-05-01 12:28:47 +02:00
f647888006 Make varray() variadic 2024-04-26 14:33:11 +02:00
b95e7fcecd Core: Integrate initalizer lists for Variant 2024-04-19 08:52:17 -05:00
64146cb7f3 [Core] Add iteration support to Array 2024-04-10 14:49:34 +02:00
b0cda1f85f Core: Use fixed-width integer types in Variant 2024-04-04 08:54:11 -05:00
9903e6779b Enforce template syntax typename over class 2024-03-07 22:39:09 -06:00
1a6cabc0bf Make Callable bind method const 2024-02-22 00:14:02 -06:00
3edb671b8a Use Packed*Array over Vector<T> in Variant
Also shuffles some method definitions and declarations to be more consistent with the way the Variant types are ordered across the codebase.

And removes an unnecessary JSON assign (`JSON::stringify` can now be accessed statically)
2024-02-06 12:53:19 +01:00
fa48a51183 Merge pull request #87688 from AThousandShips/what_is_this
Remove unnecessary `this->` expressions
2024-01-29 13:18:09 +01:00
15369fdb1d Remove unnecessary this-> expressions 2024-01-29 09:59:18 +01:00
8406e60522 Add InputEventKey.location to tell left from right
This adds a new enum `KeyLocation` and associated property
`InputEventKey.location`, which indicates the left/right location of key
events which may come from one of two physical keys, eg. Shift, Ctrl.

It also adds simulation of missing Shift KEYUP events for Windows.
When multiple Shifts are held down at the same time, Windows natively
only sends a KEYUP for the last one to be released.
2024-01-26 14:42:28 +01:00
96a95cb974 Add const lvalue ref to container parameters 2024-01-05 14:49:57 -03:00
2bffa3cbc5 Merge pull request #82639 from golfinq/gdscript-improve-indexing-error
GDScript: Improve error messages for invalid indexing
2024-01-04 16:38:58 +01:00
b5c6e870e8 Merge pull request #82264 from dalexeev/core-builtin-methods-as-callables
Core: Allow methods of built-in `Variant` types to be used as Callables
2024-01-02 18:05:05 +01:00
3f469ee485 Add PackedRealArray as an alias for Vector<real_t> 2023-12-18 11:37:43 -06:00
80c9533810 Rework blending method in Variant animation for Int/Array/String 2023-11-16 21:37:18 +09:00
b04263644c Core: Allow methods of built-in Variant types to be used as Callables 2023-10-25 15:53:52 +03:00
09b30be86d Add vararg call() method to C++ Callable 2023-10-05 11:35:29 +02:00
5efbed51cc GDScript: Improve error messages for invalid indexing
These errors are very common when using an invalid property name
or calling on an object of the wrong type, and the previous message
was a bit cryptic for users.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Co-authored-by: golfinq <golfinqz@gmail.com>
2023-10-02 14:23:11 -04:00
ee27254602 Support both semantic (by default) and numeric Variant hash comparison
Hash comparison for Variant continues to perform semantic/logical comparison with NaN's considered equal by default (to prevent #16114, #7354, #6947, #8081), but now optionally allows for numeric comparison that does not consider NaN's equal to support proper value comparison (for #72222)
2023-08-31 09:29:48 -07:00
5654d40367 Don't use a const reference for the enum constructor in Variant 2023-06-11 15:13:05 -05:00
a825f955ab Make sure Variant is not implicitely cast when using operator[]
Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
2023-02-13 10:50:22 +01:00
37248d7c87 Add @GlobalScope is_same(a, b) and Variant::identity_compare() 2023-01-25 10:46:21 -05:00
97610c8bfc Add property usage to array indexer
This makes the `Array` indexer show as returning `Variant` instead of `void` in the documentation.
2023-01-19 14:22:11 +01:00