MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / reload_scripts

Method reload_scripts

modules/gdscript/gdscript.cpp:2581–2717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2579}
2580
2581void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload) {
2582#ifdef DEBUG_ENABLED
2583
2584 List<Ref<GDScript>> scripts;
2585 {
2586 MutexLock lock(mutex);
2587
2588 SelfList<GDScript> *elem = script_list.first();
2589 while (elem) {
2590 // Scripts will reload all subclasses, so only reload root scripts.
2591 if (elem->self()->is_root_script() && !elem->self()->get_path().is_empty()) {
2592 scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
2593 }
2594 elem = elem->next();
2595 }
2596 }
2597
2598 //when someone asks you why dynamically typed languages are easier to write....
2599
2600 HashMap<Ref<GDScript>, HashMap<ObjectID, List<Pair<StringName, Variant>>>> to_reload;
2601
2602 //as scripts are going to be reloaded, must proceed without locking here
2603
2604 scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order
2605
2606 for (Ref<GDScript> &scr : scripts) {
2607 bool reload = p_scripts.has(scr) || to_reload.has(scr->get_base());
2608
2609 if (!reload) {
2610 continue;
2611 }
2612
2613 to_reload.insert(scr, HashMap<ObjectID, List<Pair<StringName, Variant>>>());
2614
2615 if (!p_soft_reload) {
2616 //save state and remove script from instances
2617 HashMap<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[scr];
2618
2619 while (scr->instances.front()) {
2620 Object *obj = scr->instances.front()->get();
2621 //save instance info
2622 List<Pair<StringName, Variant>> state;
2623 if (obj->get_script_instance()) {
2624 obj->get_script_instance()->get_property_state(state);
2625 map[obj->get_instance_id()] = state;
2626 obj->set_script(Variant());
2627 }
2628 }
2629
2630 //same thing for placeholders
2631#ifdef TOOLS_ENABLED
2632
2633 while (scr->placeholders.size()) {
2634 Object *obj = (*scr->placeholders.begin())->get_owner();
2635
2636 //save instance info
2637 if (obj->get_script_instance()) {
2638 map.insert(obj->get_instance_id(), List<Pair<StringName, Variant>>());

Callers 2

reload_scriptMethod · 0.45
poll_eventsMethod · 0.45

Calls 15

firstMethod · 0.80
is_root_scriptMethod · 0.80
selfMethod · 0.80
get_script_instanceMethod · 0.80
get_property_stateMethod · 0.80
is_built_inMethod · 0.80
get_sliceMethod · 0.80
get_sub_resourceMethod · 0.80
sizeMethod · 0.65
VariantClass · 0.50
is_emptyMethod · 0.45
get_pathMethod · 0.45

Tested by

no test coverage detected