@@ -99,31 +99,42 @@ void Resource::set_path_cache(const String &p_path) {
9999 GDVIRTUAL_CALL (_set_path_cache, p_path);
100100}
101101
102+ static thread_local RandomPCG unique_id_gen (0 , RandomPCG::DEFAULT_INC);
103+
104+ void Resource::seed_scene_unique_id (uint32_t p_seed) {
105+ unique_id_gen.seed (p_seed);
106+ }
107+
102108String Resource::generate_scene_unique_id () {
103109 // Generate a unique enough hash, but still user-readable.
104110 // If it's not unique it does not matter because the saver will try again.
105- OS::DateTime dt = OS::get_singleton ()->get_datetime ();
106- uint32_t hash = hash_murmur3_one_32 (OS::get_singleton ()->get_ticks_usec ());
107- hash = hash_murmur3_one_32 (dt.year , hash);
108- hash = hash_murmur3_one_32 (dt.month , hash);
109- hash = hash_murmur3_one_32 (dt.day , hash);
110- hash = hash_murmur3_one_32 (dt.hour , hash);
111- hash = hash_murmur3_one_32 (dt.minute , hash);
112- hash = hash_murmur3_one_32 (dt.second , hash);
113- hash = hash_murmur3_one_32 (Math::rand (), hash);
111+ if (unique_id_gen.get_seed () == 0 ) {
112+ OS::DateTime dt = OS::get_singleton ()->get_datetime ();
113+ uint32_t hash = hash_murmur3_one_32 (OS::get_singleton ()->get_ticks_usec ());
114+ hash = hash_murmur3_one_32 (dt.year , hash);
115+ hash = hash_murmur3_one_32 (dt.month , hash);
116+ hash = hash_murmur3_one_32 (dt.day , hash);
117+ hash = hash_murmur3_one_32 (dt.hour , hash);
118+ hash = hash_murmur3_one_32 (dt.minute , hash);
119+ hash = hash_murmur3_one_32 (dt.second , hash);
120+ hash = hash_murmur3_one_32 (Math::rand (), hash);
121+ unique_id_gen.seed (hash);
122+ }
123+
124+ uint32_t random_num = unique_id_gen.rand ();
114125
115126 static constexpr uint32_t characters = 5 ;
116127 static constexpr uint32_t char_count = (' z' - ' a' );
117128 static constexpr uint32_t base = char_count + (' 9' - ' 0' );
118129 String id;
119130 for (uint32_t i = 0 ; i < characters; i++) {
120- uint32_t c = hash % base;
131+ uint32_t c = random_num % base;
121132 if (c < char_count) {
122133 id += String::chr (' a' + c);
123134 } else {
124135 id += String::chr (' 0' + (c - char_count));
125136 }
126- hash /= base;
137+ random_num /= base;
127138 }
128139
129140 return id;
0 commit comments