Commit graph

109 commits

Author SHA1 Message Date
Mounir Tohami
9ff5325642 Refactor Array iterators to be trivially copyable. 2025-10-02 14:30:55 +03:00
Lukas Tenbrink
406b22d2d5 Delete VariantGetInternalPtr and VariantImplicitConvert.
Replace uses with `VariantInternalAccessor`.
2025-09-19 00:20:07 +02:00
Lukas Tenbrink
f81287d765 Introduce VariantImplicitConvert<> template for types that can be implicitly converted to and from Variant.
De-duplicate a lot of `VariantGetInternalPtr`, `VariantInternalAccessor`, `VariantInitializer` and `VariantDefaultInitializer`.
2025-09-19 00:20:07 +02:00
Thaddeus Crews
d90d8afa5a
Merge pull request #108118 from YYF233333/varray_and_vformat
Simplify `varray`
2025-09-18 12:42:25 -05:00
Lukas Tenbrink
a916325e6a Use Span for String.sprintf, to accelerate vformat not needing to allocate an Array. 2025-09-18 19:29:04 +02:00
Yufeng Ying
8f36c97a49 Optimize varray. 2025-09-16 15:01:26 +08:00
Pedro J. Estébanez
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
Thaddeus Crews
0d267e7b1e
Core: Add dedicated BitField template 2025-04-11 11:53:26 -05:00
Yufeng Ying
f7e4987d0e Dictionary::get_key_list use LocalVector instead of List. 2025-04-09 02:46:24 +08:00
Thaddeus Crews
8a93218aab
Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
Thaddeus Crews
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
rune-scape
0c7d78f455 StringLikeVariantOrder: Compare in-place 2025-03-18 11:21:30 -07:00
Thaddeus Crews
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
Lukas Tenbrink
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
Yufeng Ying
883ca56517 Remove unneeded read_only check for Array const operator. 2025-03-12 07:22:42 +08:00
Thaddeus Crews
324512e11c
Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
Rémi Verschelde
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
Lukas Tenbrink
0e72967244 Consolidate Variant int and float conversion functions to reduce duplicate logic. 2025-01-03 20:16:43 +01:00
HP van Braam
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
Lukas Tenbrink
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
Danil Alexeev
bd1a35ce9e
Core: Fix JSON.{from,to}_native() issues 2024-11-29 12:43:06 +03:00
Danil Alexeev
03b05cf9ac
Core: Fix built-in enum constant bindings 2024-11-22 14:03:21 +03:00
Thaddeus Crews
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
A Thousand Ships
79f654ced5
[Core] Fix sorting of Dictionary keys
`StringName` keys were sorted as `StringName` which is unstable.
2024-10-18 08:47:05 +02:00
rune-scape
cee0e6667a Refactor ref-counting code and fix ref counted releasing before aquiring 2024-09-21 11:36:58 -07:00
Rémi Verschelde
71accb9008
Merge pull request #94679 from rune-scape/remove-unused-initialize_ref
Remove unused `initialize_ref`
2024-08-28 00:12:16 +02:00
Rémi Verschelde
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
rune-scape
c8b697c64c Remove unused initialize_ref 2024-07-03 13:32:50 -07:00
Thaddeus Crews
7599a7b719
Core: Readd Variant class initializer, fix comment 2024-05-14 12:20:40 -05:00
kobewi
413c11357d Use Core/Scene stringnames consistently 2024-05-13 23:41:07 +02:00
K. S. Ernest (iFire) Lee
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
A Thousand Ships
c4e24d2b3b
[GDScript] Correctly report invalid read-only access 2024-05-01 12:28:47 +02:00
kobewi
f647888006 Make varray() variadic 2024-04-26 14:33:11 +02:00
Thaddeus Crews
b95e7fcecd
Core: Integrate initalizer lists for Variant 2024-04-19 08:52:17 -05:00
A Thousand Ships
64146cb7f3
[Core] Add iteration support to Array 2024-04-10 14:49:34 +02:00
Thaddeus Crews
b0cda1f85f
Core: Use fixed-width integer types in Variant 2024-04-04 08:54:11 -05:00
Thaddeus Crews
9903e6779b
Enforce template syntax typename over class 2024-03-07 22:39:09 -06:00
Aaron Franke
1a6cabc0bf
Make Callable bind method const 2024-02-22 00:14:02 -06:00
Micky
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
Rémi Verschelde
fa48a51183
Merge pull request #87688 from AThousandShips/what_is_this
Remove unnecessary `this->` expressions
2024-01-29 13:18:09 +01:00
A Thousand Ships
15369fdb1d
Remove unnecessary this-> expressions 2024-01-29 09:59:18 +01:00
Mel Collins
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
Muller-Castro
96a95cb974 Add const lvalue ref to container parameters 2024-01-05 14:49:57 -03:00
Rémi Verschelde
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
Rémi Verschelde
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
Aaron Franke
3f469ee485
Add PackedRealArray as an alias for Vector<real_t> 2023-12-18 11:37:43 -06:00
Silc Lizard (Tokage) Renew
80c9533810 Rework blending method in Variant animation for Int/Array/String 2023-11-16 21:37:18 +09:00
Danil Alexeev
b04263644c
Core: Allow methods of built-in Variant types to be used as Callables 2023-10-25 15:53:52 +03:00
kobewi
09b30be86d Add vararg call() method to C++ Callable 2023-10-05 11:35:29 +02:00