godot-module-template/core/variant
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
..
array.cpp Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
array.h Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
binder_common.h Core: Modernize C headers with C++ equivalents 2025-05-02 08:23:01 -05:00
callable.cpp Fix crash when calling get_argument_count() on invalid Callable 2025-03-04 13:32:34 +09:00
callable.h Core: Expand is_zero_constructible coverage 2025-03-17 11:45:26 -05:00
callable_bind.cpp Merge pull request #98713 from dalexeev/core-fix-callable-get-bound-arguments 2024-11-12 12:13:04 -06:00
callable_bind.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
container_type_validate.h Merge pull request #100057 from aaronp64/container_validate_obj_perf 2025-05-06 08:38:03 -05:00
dictionary.cpp Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
dictionary.h Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
method_ptrcall.h Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
native_ptr.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
SCsub SCons: Add unobtrusive type hints in SCons files 2024-09-25 09:34:35 -05:00
type_info.h Core: Add dedicated BitField template 2025-04-11 11:53:26 -05:00
typed_array.h Typed array equality operator logic updated 2025-05-13 14:41:16 -05:00
typed_dictionary.h Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
variant.cpp Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
variant.h Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
variant_call.cpp Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
variant_callable.cpp Add methods to get argument count of methods 2024-03-10 11:02:43 +01:00
variant_callable.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
variant_construct.cpp [Core] Improve error messages with vformat 2024-10-30 15:55:51 +01:00
variant_construct.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
variant_deep_duplicate.h Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
variant_destruct.cpp Apply iwyu suggestion in core. 2024-12-19 00:43:47 +08:00
variant_destruct.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
variant_internal.h Core: Natively convert enum/BitField with Variant 2025-04-05 12:35:34 -05:00
variant_op.cpp Merge pull request #90971 from billuo/string-format-rid 2025-04-14 19:39:50 -05:00
variant_op.h Use initializer list in Arrays 2025-03-26 18:38:15 +01:00
variant_parser.cpp Avoid single character String allocations when appending characters 2025-05-12 17:35:42 -04:00
variant_parser.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
variant_setget.cpp Overhaul Variant::duplicate() for resources 2025-05-26 10:06:40 +02:00
variant_setget.h Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
variant_utility.cpp Rename VariantUtilityFunctions::join() to join_string() 2025-05-12 17:51:09 -05:00
variant_utility.h Rename VariantUtilityFunctions::join() to join_string() 2025-05-12 17:51:09 -05:00