2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  resource.cpp                                                          */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                         This file is part of:                          */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                             GODOT ENGINE                               */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                        https://godotengine.org                         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Permission is hereby granted, free of charge, to any person obtaining  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* a copy of this software and associated documentation files (the        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* "Software"), to deal in the Software without restriction, including    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* without limitation the rights to use, copy, modify, merge, publish,    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* distribute, sublicense, and/or sell copies of the Software, and to     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* permit persons to whom the Software is furnished to do so, subject to  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* the following conditions:                                              */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* The above copyright notice and this permission notice shall be         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* included in all copies or substantial portions of the Software.        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
									
										
										
										
											2018-01-05 00:50:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  "resource.h" 
  
						 
					
						
							
								
									
										
										
										
											2017-01-16 08:04:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 18:13:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "core/io/resource_loader.h" 
  
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "core/math/math_funcs.h" 
  
						 
					
						
							
								
									
										
										
										
											2024-07-16 10:31:39 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "core/math/random_pcg.h" 
  
						 
					
						
							
								
									
										
										
										
											2020-06-08 16:39:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "core/os/os.h" 
  
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "core/variant/container_type_validate.h" 
  
						 
					
						
							
								
									
										
										
										
											2017-08-05 19:48:29 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "scene/main/node.h"   //only so casting works
  
						 
					
						
							
								
									
										
										
										
											2018-09-11 18:13:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  Resource : : emit_changed ( )  {  
						 
					
						
							
								
									
										
										
										
											2025-02-10 11:49:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( emit_changed_state  ! =  EMIT_CHANGED_UNBLOCKED )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										emit_changed_state  =  EMIT_CHANGED_BLOCKED_PENDING_EMIT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ResourceLoader : : is_within_load ( )  & &  ! Thread : : is_main_thread ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceLoader : : resource_changed_emit ( this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-12 16:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									emit_signal ( CoreStringName ( changed ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-10 11:49:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : _block_emit_changed ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( emit_changed_state  = =  EMIT_CHANGED_UNBLOCKED )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										emit_changed_state  =  EMIT_CHANGED_BLOCKED ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : _unblock_emit_changed ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  emit  =  ( emit_changed_state  = =  EMIT_CHANGED_BLOCKED_PENDING_EMIT ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									emit_changed_state  =  EMIT_CHANGED_UNBLOCKED ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( emit )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										emit_changed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  Resource : : _resource_path_changed ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-06-27 23:21:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : set_path ( const  String  & p_path ,  bool  p_take_over )  {  
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( path_cache  = =  p_path )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( p_path . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_take_over  =  false ;  // Can't take over an empty path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MutexLock  lock ( ResourceCache : : lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! path_cache . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ResourceCache : : resources . erase ( path_cache ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										path_cache  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Ref < Resource >  existing  =  ResourceCache : : get_ref ( p_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( existing . is_valid ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( p_take_over )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												existing - > path_cache  =  String ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ResourceCache : : resources . erase ( p_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-11 16:17:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ERR_FAIL_MSG ( vformat ( " Another resource is loaded from path '%s' (possible cyclic resource inclusion). " ,  p_path ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2014-06-27 23:21:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										path_cache  =  p_path ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! path_cache . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ResourceCache : : resources [ path_cache ]  =  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_resource_path_changed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								String  Resource : : get_path ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  path_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-05 02:07:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : set_path_cache ( const  String  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									path_cache  =  p_path ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_CALL ( _set_path_cache ,  p_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-05 02:07:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 10:31:39 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  thread_local  RandomPCG  unique_id_gen  =  RandomPCG ( 0 ) ;  
						 
					
						
							
								
									
										
										
										
											2024-09-23 15:07:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : seed_scene_unique_id ( uint32_t  p_seed )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									unique_id_gen . seed ( p_seed ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  Resource : : generate_scene_unique_id ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Generate a unique enough hash, but still user-readable.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If it's not unique it does not matter because the saver will try again.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-23 15:07:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( unique_id_gen . get_seed ( )  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OS : : DateTime  dt  =  OS : : get_singleton ( ) - > get_datetime ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t  hash  =  hash_murmur3_one_32 ( OS : : get_singleton ( ) - > get_ticks_usec ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . year ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . month ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . day ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . hour ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . minute ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( dt . second ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										hash  =  hash_murmur3_one_32 ( Math : : rand ( ) ,  hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										unique_id_gen . seed ( hash ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uint32_t  random_num  =  unique_id_gen . rand ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									static  constexpr  uint32_t  characters  =  5 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									static  constexpr  uint32_t  char_count  =  ( ' z '  -  ' a ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									static  constexpr  uint32_t  base  =  char_count  +  ( ' 9 '  -  ' 0 ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									String  id ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-28 20:33:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									id . resize_uninitialized ( characters  +  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-12 11:42:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									char32_t  * ptr  =  id . ptrw ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( uint32_t  i  =  0 ;  i  <  characters ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-23 15:07:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										uint32_t  c  =  random_num  %  base ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( c  <  char_count )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-12 11:42:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ptr [ i ]  =  ( ' a '  +  c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-12 11:42:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ptr [ i ]  =  ( ' 0 '  +  ( c  -  char_count ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-23 15:07:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										random_num  / =  base ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-12 11:42:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ptr [ characters ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : set_scene_unique_id ( const  String  & p_id )  {  
						 
					
						
							
								
									
										
										
										
											2024-02-08 13:26:55 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									bool  is_valid  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  p_id . length ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! is_ascii_identifier_char ( p_id [ i ] ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											is_valid  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											scene_unique_id  =  Resource : : generate_scene_unique_id ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( ! is_valid ,  " The scene unique ID must contain only letters, numbers, and underscores. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									scene_unique_id  =  p_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-22 00:03:19 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  Resource : : get_scene_unique_id ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  scene_unique_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-22 00:03:19 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  Resource : : set_name ( const  String  & p_name )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									name  =  p_name ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-14 13:28:45 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									emit_changed ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2020-05-14 14:29:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								String  Resource : : get_name ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-27 12:43:49 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : update_configuration_warning ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( _update_configuration_warning )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										_update_configuration_warning ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  Resource : : editor_can_reload_from_file ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ;  //by default yes
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : connect_changed ( const  Callable  & p_callable ,  uint32_t  p_flags )  {  
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ResourceLoader : : is_within_load ( )  & &  ! Thread : : is_main_thread ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceLoader : : resource_changed_connect ( this ,  p_callable ,  p_flags ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-12 16:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-04 17:01:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! is_connected ( CoreStringName ( changed ) ,  p_callable )  | |  p_flags  &  CONNECT_REFERENCE_COUNTED )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										connect ( CoreStringName ( changed ) ,  p_callable ,  p_flags ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : disconnect_changed ( const  Callable  & p_callable )  {  
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ResourceLoader : : is_within_load ( )  & &  ! Thread : : is_main_thread ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceLoader : : resource_changed_disconnect ( this ,  p_callable ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-12 16:03:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-05 09:48:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-04 17:01:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( is_connected ( CoreStringName ( changed ) ,  p_callable ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										disconnect ( CoreStringName ( changed ) ,  p_callable ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : reset_state ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_CALL ( _reset_state ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Error  Resource : : copy_from ( const  Ref < Resource >  & p_resource )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( p_resource . is_null ( ) ,  ERR_INVALID_PARAMETER ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( get_class ( )  ! =  p_resource - > get_class ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  ERR_INVALID_PARAMETER ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-10 11:49:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									_block_emit_changed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									reset_state ( ) ;  // May want to reset state.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									List < PropertyInfo >  pi ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									p_resource - > get_property_list ( & pi ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-24 15:46:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  PropertyInfo  & E  :  pi )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( E . usage  &  PROPERTY_USAGE_STORAGE ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( E . name  = =  " resource_path " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ;  //do not change path
 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set ( E . name ,  p_resource - > get ( E . name ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-27 13:17:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-10 11:49:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_unblock_emit_changed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  OK ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-03-07 20:19:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : reload_from_file ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									String  path  =  get_path ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! path . is_resource_file ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Ref < Resource >  s  =  ResourceLoader : : load ( ResourceLoader : : path_remap ( path ) ,  get_class ( ) ,  ResourceFormatLoader : : CACHE_MODE_IGNORE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-25 14:13:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( s . is_null ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 14:18:45 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									copy_from ( s ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Variant  Resource : : _duplicate_recursive ( const  Variant  & p_variant ,  const  DuplicateParams  & p_params ,  uint32_t  p_usage )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Anything other than object can be simply skipped in case of a shallow copy.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! p_params . deep  & &  p_variant . get_type ( )  ! =  Variant : : OBJECT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  p_variant ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									switch  ( p_variant . get_type ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										case  Variant : : OBJECT :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  Ref < Resource >  & sr  =  p_variant ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											bool  should_duplicate  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( sr . is_valid ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ( p_usage  &  PROPERTY_USAGE_ALWAYS_DUPLICATE ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													should_duplicate  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  if  ( ( p_usage  &  PROPERTY_USAGE_NEVER_DUPLICATE ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													should_duplicate  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  if  ( p_params . local_scene )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													should_duplicate  =  sr - > is_local_to_scene ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													switch  ( p_params . subres_mode )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  RESOURCE_DEEP_DUPLICATE_NONE :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															should_duplicate  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  RESOURCE_DEEP_DUPLICATE_INTERNAL :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															should_duplicate  =  p_params . deep  & &  sr - > is_built_in ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  RESOURCE_DEEP_DUPLICATE_ALL :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															should_duplicate  =  p_params . deep ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														}  break ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														default :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															DEV_ASSERT ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( should_duplicate )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( thread_duplicate_remap_cache - > has ( sr ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  thread_duplicate_remap_cache - > get ( sr ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													const  Ref < Resource >  & dupe  =  p_params . local_scene 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															?  sr - > duplicate_for_local_scene ( p_params . local_scene ,  * thread_duplicate_remap_cache ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															:  sr - > _duplicate ( p_params ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													thread_duplicate_remap_cache - > insert ( sr ,  dupe ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													return  dupe ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  p_variant ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										case  Variant : : ARRAY :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  Array  & src  =  p_variant ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Array  dst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( src . is_typed ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												dst . set_typed ( src . get_element_type ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											dst . resize ( src . size ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( int  i  =  0 ;  i  <  src . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												dst [ i ]  =  _duplicate_recursive ( src [ i ] ,  p_params ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  dst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : DICTIONARY :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  Dictionary  & src  =  p_variant ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Dictionary  dst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( src . is_typed ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												dst . set_typed ( src . get_key_type ( ) ,  src . get_value_type ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( const  Variant  & k  :  src . get_key_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  Variant  & v  =  src [ k ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												dst . set ( 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														_duplicate_recursive ( k ,  p_params ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														_duplicate_recursive ( v ,  p_params ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  dst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_BYTE_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_INT32_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_INT64_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_FLOAT32_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_FLOAT64_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_STRING_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_VECTOR2_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_VECTOR3_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_COLOR_ARRAY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : PACKED_VECTOR4_ARRAY :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  p_variant . duplicate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										default :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  p_variant ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : _duplicate ( const  DuplicateParams  & p_params )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( p_params . local_scene  & &  p_params . subres_mode  ! =  RESOURCE_DEEP_DUPLICATE_MAX ,  Ref < Resource > ( ) ,  " Duplication for local-to-scene can't specify a deep duplicate mode. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateRemapCacheT  * remap_cache_backup  =  thread_duplicate_remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// These are for avoiding potential duplicates that can happen in custom code
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// from participating in the same duplication session (remap cache).
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define BEFORE_USER_CODE thread_duplicate_remap_cache = nullptr; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define AFTER_USER_CODE thread_duplicate_remap_cache = remap_cache_backup; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									List < PropertyInfo >  plist ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									get_property_list ( & plist ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BEFORE_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-17 16:03:09 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Ref < Resource >  r  =  Object : : cast_to < Resource > ( ClassDB : : instantiate ( get_class ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AFTER_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-18 23:45:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( r . is_null ( ) ,  Ref < Resource > ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									thread_duplicate_remap_cache - > insert ( Ref < Resource > ( this ) ,  r ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( p_params . local_scene )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r - > local_scene  =  p_params . local_scene ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Duplicate script first, so the scripted properties are considered.
 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BEFORE_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									r - > set_script ( get_script ( ) ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AFTER_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-24 15:46:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  PropertyInfo  & E  :  plist )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( E . usage  &  PROPERTY_USAGE_STORAGE ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( E . name  = =  " script " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										BEFORE_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 10:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Variant  p  =  get ( E . name ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AFTER_USER_CODE 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										p  =  _duplicate_recursive ( p ,  p_params ,  E . usage ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										BEFORE_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										r - > set ( E . name ,  p ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AFTER_USER_CODE 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-18 23:45:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  r ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# undef BEFORE_USER_CODE 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# undef AFTER_USER_CODE 
  
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : duplicate_for_local_scene ( Node  * p_for_scene ,  DuplicateRemapCacheT  & p_remap_cache )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef DEBUG_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The only possibilities for the remap cache passed being valid are these:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// a) It's the same already used as the one of the thread. That happens when this function
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//    is called within some recursion level within a duplication.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// b) There's no current thread remap cache, which means this function is acting as an entry point.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This check failing means that this function is being called as an entry point during an ongoing
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// duplication, likely due to custom instantiation or setter code. It would be an engine bug because
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// code starting or joining a duplicate session must ensure to exit it temporarily when making calls
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// that may in turn invoke such custom code.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( thread_duplicate_remap_cache  & &  & p_remap_cache  ! =  thread_duplicate_remap_cache )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_PRINT ( " Resource::duplicate_for_local_scene() called during an ongoing duplication session. This is an engine bug. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DuplicateRemapCacheT  * remap_cache_backup  =  thread_duplicate_remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									thread_duplicate_remap_cache  =  & p_remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateParams  params ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . deep  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . local_scene  =  p_for_scene ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  Ref < Resource >  & dupe  =  _duplicate ( params ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									thread_duplicate_remap_cache  =  remap_cache_backup ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  dupe ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : _find_sub_resources ( const  Variant  & p_variant ,  HashSet < Ref < Resource > >  & p_resources_found )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  ( p_variant . get_type ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : ARRAY :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Array  a  =  p_variant ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( int  i  =  0 ;  i  <  a . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												_find_sub_resources ( a [ i ] ,  p_resources_found ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : DICTIONARY :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Dictionary  d  =  p_variant ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-12 06:43:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  ( const  KeyValue < Variant ,  Variant >  & kv  :  d )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												_find_sub_resources ( kv . key ,  p_resources_found ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												_find_sub_resources ( kv . value ,  p_resources_found ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  Variant : : OBJECT :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Ref < Resource >  r  =  p_variant ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( r . is_valid ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												p_resources_found . insert ( r ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : configure_for_local_scene ( Node  * p_for_scene ,  DuplicateRemapCacheT  & p_remap_cache )  {  
						 
					
						
							
								
									
										
										
										
											2017-12-04 15:55:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									List < PropertyInfo >  plist ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									get_property_list ( & plist ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-08 19:38:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									reset_local_to_scene ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-04 15:55:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									local_scene  =  p_for_scene ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-24 15:46:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  PropertyInfo  & E  :  plist )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( E . usage  &  PROPERTY_USAGE_STORAGE ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-04 15:55:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Variant  p  =  get ( E . name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-17 21:14:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										HashSet < Ref < Resource > >  sub_resources ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										_find_sub_resources ( p ,  sub_resources ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( Ref < Resource >  sr  :  sub_resources )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( sr - > is_local_to_scene ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ! p_remap_cache . has ( sr ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													sr - > configure_for_local_scene ( p_for_scene ,  p_remap_cache ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													p_remap_cache [ sr ]  =  sr ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-04 15:55:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : duplicate ( bool  p_deep )  const  {  
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateRemapCacheT  remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  started_session  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! thread_duplicate_remap_cache )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  & remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										started_session  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateParams  params ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . deep  =  p_deep ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . subres_mode  =  RESOURCE_DEEP_DUPLICATE_INTERNAL ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  Ref < Resource >  & dupe  =  _duplicate ( params ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( started_session )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  dupe ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-01-21 14:18:57 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : duplicate_deep ( ResourceDeepDuplicateMode  p_deep_subresources_mode )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_INDEX_V ( p_deep_subresources_mode ,  RESOURCE_DEEP_DUPLICATE_MAX ,  Ref < Resource > ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateRemapCacheT  remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  started_session  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! thread_duplicate_remap_cache )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  & remap_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										started_session  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DuplicateParams  params ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . deep  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . subres_mode  =  p_deep_subresources_mode ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  Ref < Resource >  & dupe  =  _duplicate ( params ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( started_session )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  dupe ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-06-20 17:55:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : _duplicate_deep_bind ( DeepDuplicateMode  p_deep_subresources_mode )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  _duplicate_from_variant ( true ,  ( ResourceDeepDuplicateMode ) p_deep_subresources_mode ,  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  Resource : : _duplicate_from_variant ( bool  p_deep ,  ResourceDeepDuplicateMode  p_deep_subresources_mode ,  int  p_recursion_count )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// A call without deep duplication would have been early-rejected at Variant::duplicate() unless it's the root call.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DEV_ASSERT ( ! ( p_recursion_count  >  0  & &  p_deep_subresources_mode  = =  RESOURCE_DEEP_DUPLICATE_NONE ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// When duplicating from Variant, this function may be called multiple times from
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// different parts of the data structure being copied. Therefore, we need to create
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// a remap cache instance in a way that can be shared among all of the calls.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Whatever Variant, Array or Dictionary that initiated the call chain will eventually
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// claim it, when the stack unwinds up to the root call.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// One exception is that this is the root call.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_recursion_count  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( p_deep )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  duplicate_deep ( p_deep_subresources_mode ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  duplicate ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( thread_duplicate_remap_cache )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Resource : : DuplicateRemapCacheT : : Iterator  E  =  thread_duplicate_remap_cache - > find ( Ref < Resource > ( this ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( E )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  E - > value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  memnew ( DuplicateRemapCacheT ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DuplicateParams  params ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . deep  =  p_deep ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									params . subres_mode  =  p_deep_subresources_mode ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  Ref < Resource >  dupe  =  _duplicate ( params ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  dupe ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : _teardown_duplicate_from_variant ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( thread_duplicate_remap_cache )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										memdelete ( thread_duplicate_remap_cache ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										thread_duplicate_remap_cache  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-06-30 01:28:05 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : _set_path ( const  String  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									set_path ( p_path ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : _take_over_path ( const  String  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									set_path ( p_path ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								RID  Resource : : get_rid ( )  const  {  
						 
					
						
							
								
									
										
										
										
											2024-01-17 15:03:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RID  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! GDVIRTUAL_CALL ( _get_rid ,  ret ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef DISABLE_DEPRECATED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( _get_extension ( )  & &  _get_extension ( ) - > get_rid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ret  =  RID : : from_uint64 ( _get_extension ( ) - > get_rid ( _get_extension_instance ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-10 08:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 15:03:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2022-03-10 08:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 15:03:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 14:18:40 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef TOOLS_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-07 17:45:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								uint32_t  Resource : : hash_edited_version_for_preview ( )  const  {  
						 
					
						
							
								
									
										
										
										
											2022-06-18 16:20:55 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  hash  =  hash_murmur3_one_32 ( get_edited_version ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 14:18:40 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									List < PropertyInfo >  plist ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									get_property_list ( & plist ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-24 15:46:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  PropertyInfo  & E  :  plist )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-15 23:45:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( E . usage  &  PROPERTY_USAGE_STORAGE  & &  E . type  = =  Variant : : OBJECT  & &  E . hint  = =  PROPERTY_HINT_RESOURCE_TYPE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-03 01:43:50 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Ref < Resource >  res  =  get ( E . name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 14:18:40 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( res . is_valid ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-07 17:45:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hash  =  hash_murmur3_one_32 ( res - > hash_edited_version_for_preview ( ) ,  hash ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 14:18:40 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  hash ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : set_local_to_scene ( bool  p_enable )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									local_to_scene  =  p_enable ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  Resource : : is_local_to_scene ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  local_to_scene ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Node  * Resource : : get_local_scene ( )  const  {  
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( local_scene )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  local_scene ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( _get_local_scene_func )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  _get_local_scene_func ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-04-02 01:20:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  Resource : : setup_local_to_scene ( )  {  
						 
					
						
							
								
									
										
										
										
											2021-08-21 22:52:44 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									emit_signal ( SNAME ( " setup_local_to_scene_requested " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-08 14:47:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_CALL ( _setup_local_to_scene ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-08 19:38:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : reset_local_to_scene ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Restores the state as if setup_local_to_scene() hadn't been called.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-04-02 01:20:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Node  * ( * Resource : : _get_local_scene_func ) ( )  =  nullptr ;  
						 
					
						
							
								
									
										
										
										
											2021-04-27 12:43:49 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  ( * Resource : : _update_configuration_warning ) ( )  =  nullptr ;  
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 17:00:18 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : set_as_translation_remapped ( bool  p_remapped )  {  
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( remapped_list . in_list ( )  = =  p_remapped )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 17:00:18 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 17:00:18 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MutexLock  lock ( ResourceCache : : lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-28 17:00:18 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_remapped )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceLoader : : remapped_list . add ( & remapped_list ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceLoader : : remapped_list . remove ( & remapped_list ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
  
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : set_id_for_path ( const  String  & p_path ,  const  String  & p_id )  {  
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef TOOLS_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2021-12-09 03:42:46 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( p_id . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . write_lock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : resource_path_cache [ p_path ] . erase ( get_path ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . write_unlock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . write_lock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : resource_path_cache [ p_path ] [ get_path ( ) ]  =  p_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . write_unlock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  Resource : : get_id_for_path ( const  String  & p_path )  const  {  
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef TOOLS_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ResourceCache : : path_cache_lock . read_lock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ResourceCache : : resource_path_cache [ p_path ] . has ( get_path ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										String  result  =  ResourceCache : : resource_path_cache [ p_path ] [ get_path ( ) ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . read_unlock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ResourceCache : : path_cache_lock . read_unlock ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-04-11 14:35:23 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  Resource : : _bind_methods ( )  {  
						 
					
						
							
								
									
										
										
										
											2017-02-13 12:47:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_path " ,  " path " ) ,  & Resource : : _set_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " take_over_path " ,  " path " ) ,  & Resource : : _take_over_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_path " ) ,  & Resource : : get_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_path_cache " ,  " path " ) ,  & Resource : : set_path_cache ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-13 12:47:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_name " ,  " name " ) ,  & Resource : : set_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_name " ) ,  & Resource : : get_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_rid " ) ,  & Resource : : get_rid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_local_to_scene " ,  " enable " ) ,  & Resource : : set_local_to_scene ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " is_local_to_scene " ) ,  & Resource : : is_local_to_scene ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-09 13:19:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_local_scene " ) ,  & Resource : : get_local_scene ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-13 12:47:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " setup_local_to_scene " ) ,  & Resource : : setup_local_to_scene ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " reset_state " ) ,  & Resource : : reset_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_id_for_path " ,  " path " ,  " id " ) ,  & Resource : : set_id_for_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_id_for_path " ,  " path " ) ,  & Resource : : get_id_for_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " is_built_in " ) ,  & Resource : : is_built_in ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-03 21:29:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 13:26:55 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_static_method ( " Resource " ,  D_METHOD ( " generate_scene_unique_id " ) ,  & Resource : : generate_scene_unique_id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " set_scene_unique_id " ,  " id " ) ,  & Resource : : set_scene_unique_id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " get_scene_unique_id " ) ,  & Resource : : get_scene_unique_id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 16:24:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " emit_changed " ) ,  & Resource : : emit_changed ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " duplicate " ,  " deep " ) ,  & Resource : : duplicate ,  DEFVAL ( false ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-06-20 17:55:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClassDB : : bind_method ( D_METHOD ( " duplicate_deep " ,  " deep_subresources_mode " ) ,  & Resource : : _duplicate_deep_bind ,  DEFVAL ( RESOURCE_DEEP_DUPLICATE_INTERNAL ) ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												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-01-21 11:55:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// For the bindings, it's much more natural to expose this enum from the Variant realm via Resource.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-06-20 17:55:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Therefore, we can't use BIND_ENUM_CONSTANT here because we need some customization.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_integer_constant ( get_class_static ( ) ,  StringName ( " DeepDuplicateMode " ) ,  " DEEP_DUPLICATE_NONE " ,  RESOURCE_DEEP_DUPLICATE_NONE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_integer_constant ( get_class_static ( ) ,  StringName ( " DeepDuplicateMode " ) ,  " DEEP_DUPLICATE_INTERNAL " ,  RESOURCE_DEEP_DUPLICATE_INTERNAL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ClassDB : : bind_integer_constant ( get_class_static ( ) ,  StringName ( " DeepDuplicateMode " ) ,  " DEEP_DUPLICATE_ALL " ,  RESOURCE_DEEP_DUPLICATE_ALL ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Overhaul `Resource::duplicate()`
Thanks to a refactor, `Resource::duplicate_for_local_scene()` and `Resource::duplicate()` are now both users of the same, parametrized, implementation.
`Resource::duplicate()` now honors deepness in a more consistent and predictable fashion. `Resource::duplicate_deep()` is added (instead of just adding a parameter to the former, for compatibility needs).
The behavior after this change is as follows:
  - Deep (`deep=true`, formerly `subresources=true`):
    - Previously, only resources found as direct property values of the one to copy would be, recursively, duplicated.
    - Now, in addition, arrays and dictionaries are walked so the copy is truly deep, and only local subresources found across are copied.
    - Previously, subresources would be duplicated as many times as being referenced throughout the main resource.
    - Now, each subresource is only duplicated once and from that point, a referenced to that single copy is used. That's the enhanced behavior that `duplicate_for_local_scene()` already featured.
    - The behavior with respect to packed arrays is still duplication.
    - Formerly, arrays and dictionaries were recursive duplicated, with resources ignored.
    - Now, arrays and dictionaries are recursive duplicated, with resources duplicated.
    - When doing it through `duplicate_deep()`, there's a` deep_subresources_mode` parameter, with various possibilites to control if no resources are duplicated (so arrays, etc. are, but keeping referencing the originals), if only the internal ones are (resources with no non-local path, the default), or if all of them are. The default is to copy every subresource, just like `duplicate(true)`.
  - Not deep (`deep=false`, formerly `subresources=false`): <a name="resource-shallow"></a>
    - Previously, the first level of resources found as direct property values would be duplicated unconditionally. Packed arrays, arrays and dictionaries were non-recursively duplicated.
    - Now, no subresource found at any level in any form will be duplicated, but the original reference kept instead. Packed arrays, arrays and dictionaries are referenced, not duplicated at all.
    - Now, resources found as values of always-duplicate properties are duplicated, recursively or not matching what was requested for the root call.
This commit also changes what's the virtual method to override to customize the duplication (now it's the protected `_duplicate()` instead of the public `duplicate()`).
											 
										 
										
											2025-01-21 10:25:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_SIGNAL ( MethodInfo ( " changed " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-21 22:52:44 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_SIGNAL ( MethodInfo ( " setup_local_to_scene_requested " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_GROUP ( " Resource " ,  " resource_ " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-08 11:30:02 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL ,  " resource_local_to_scene " ) ,  " set_local_to_scene " ,  " is_local_to_scene " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-12 01:11:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_PROPERTY ( PropertyInfo ( Variant : : STRING ,  " resource_path " ,  PROPERTY_HINT_NONE ,  " " ,  PROPERTY_USAGE_EDITOR ) ,  " set_path " ,  " get_path " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-29 15:43:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_PROPERTY ( PropertyInfo ( Variant : : STRING ,  " resource_name " ) ,  " set_name " ,  " get_name " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 13:26:55 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ADD_PROPERTY ( PropertyInfo ( Variant : : STRING ,  " resource_scene_unique_id " ,  PROPERTY_HINT_NONE ,  " " ,  PROPERTY_USAGE_NONE ) ,  " set_scene_unique_id " ,  " get_scene_unique_id " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-10 08:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-08 14:47:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_BIND ( _setup_local_to_scene ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-17 15:03:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_BIND ( _get_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 13:26:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GDVIRTUAL_BIND ( _reset_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									GDVIRTUAL_BIND ( _set_path_cache ,  " path " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 01:04:31 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-06 21:36:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Resource : : Resource ( )  :  
						 
					
						
							
								
									
										
										
										
											2025-06-22 23:08:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										remapped_list ( this )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_define_ancestry ( AncestralClass : : RESOURCE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Resource : : ~ Resource ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-05-13 11:51:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( unlikely ( path_cache . is_empty ( ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-13 11:51:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MutexLock  lock ( ResourceCache : : lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-13 11:51:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Only unregister from the cache if this is the actual resource listed there.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// (Other resources can have the same value in `path_cache` if loaded with `CACHE_IGNORE`.)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HashMap < String ,  Resource  * > : : Iterator  E  =  ResourceCache : : resources . find ( path_cache ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( likely ( E  & &  E - > value  = =  this ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ResourceCache : : resources . remove ( E ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HashMap < String ,  Resource  * >  ResourceCache : : resources ;  
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef TOOLS_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2021-07-20 21:36:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HashMap < String ,  HashMap < String ,  String > >  ResourceCache : : resource_path_cache ;  
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Mutex  ResourceCache : : lock ;  
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef TOOLS_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2021-01-18 14:01:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RWLock  ResourceCache : : path_cache_lock ;  
						 
					
						
							
								
									
										
										
										
											2019-07-16 09:46:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  ResourceCache : : clear ( )  {  
						 
					
						
							
								
									
										
										
										
											2023-11-28 13:19:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! resources . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-08 16:39:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 13:19:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ERR_PRINT ( vformat ( " %d resources still in use at exit. " ,  resources . size ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-08 10:09:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  ( const  KeyValue < String ,  Resource  * >  & E  :  resources )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												print_line ( vformat ( " Resource still in use: %s (%s) " ,  E . key ,  E . value - > get_class ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-08 16:39:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-28 13:19:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ERR_PRINT ( vformat ( " %d resources still in use at exit (run with --verbose for details). " ,  resources . size ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-08 16:39:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-14 16:41:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									resources . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  ResourceCache : : has ( const  String  & p_path )  {  
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Resource  * * res  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MutexLock  mutex_lock ( lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										res  =  resources . getptr ( p_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( res  & &  ( * res ) - > get_reference_count ( )  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// This resource is in the process of being deleted, ignore its existence.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											( * res ) - > path_cache  =  String ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											resources . erase ( p_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2020-05-14 14:29:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Ref < Resource >  ResourceCache : : get_ref ( const  String  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Ref < Resource >  ref ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										MutexLock  mutex_lock ( lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Resource  * * res  =  resources . getptr ( p_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ref  =  Ref < Resource > ( * res ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 18:25:37 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-25 14:13:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( res  & &  ref . is_null ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// This resource is in the process of being deleted, ignore its existence
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											( * res ) - > path_cache  =  String ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											resources . erase ( p_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 00:00:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-22 13:46:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ref ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-17 07:33:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  ResourceCache : : get_cached_resources ( List < Ref < Resource > >  * p_resources )  {  
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MutexLock  mutex_lock ( lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-19 20:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LocalVector < String >  to_remove ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-08 10:09:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( KeyValue < String ,  Resource  * >  & E  :  resources )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-19 20:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Ref < Resource >  ref  =  Ref < Resource > ( E . value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-25 14:13:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ref . is_null ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-19 20:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// This resource is in the process of being deleted, ignore its existence
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											E . value - > path_cache  =  String ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											to_remove . push_back ( E . key ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_resources - > push_back ( ref ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( const  String  & E  :  to_remove )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										resources . erase ( E ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								int  ResourceCache : : get_cached_resource_count ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-08-28 11:27:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MutexLock  mutex_lock ( lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  resources . size ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 22:10:30 -03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}