diff options
Diffstat (limited to 'modules/gdnative/nativescript/nativescript.cpp')
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 214 |
1 files changed, 120 insertions, 94 deletions
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index bf458c15ee..06b9534fce 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -111,6 +111,13 @@ void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) #endif +bool NativeScript::inherits_script(const Ref<Script> &p_script) const { +#ifndef _MSC_VER +#warning inheritance needs to be implemented in NativeScript +#endif + return false; +} + void NativeScript::set_class_name(String p_class_name) { class_name = p_class_name; } @@ -162,7 +169,6 @@ String NativeScript::get_script_class_icon_path() const { } bool NativeScript::can_instance() const { - NativeScriptDesc *script_data = get_script_desc(); #ifdef TOOLS_ENABLED @@ -178,8 +184,9 @@ bool NativeScript::can_instance() const { Ref<Script> NativeScript::get_base_script() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return Ref<Script>(); + } NativeScript *script = (NativeScript *)NSL->create_script(); Ref<NativeScript> ns = Ref<NativeScript>(script); @@ -193,14 +200,14 @@ Ref<Script> NativeScript::get_base_script() const { StringName NativeScript::get_instance_base_type() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return ""; + } return script_data->base_native_type; } ScriptInstance *NativeScript::instance_create(Object *p_this) { - NativeScriptDesc *script_data = get_script_desc(); if (!script_data) { @@ -267,8 +274,9 @@ bool NativeScript::has_method(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - if (script_data->methods.has(p_method)) + if (script_data->methods.has(p_method)) { return true; + } script_data = script_data->base_data; } @@ -278,14 +286,16 @@ bool NativeScript::has_method(const StringName &p_method) const { MethodInfo NativeScript::get_method_info(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return MethodInfo(); + } while (script_data) { Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method); - if (M) + if (M) { return M->get().info; + } script_data = script_data->base_data; } @@ -299,8 +309,9 @@ bool NativeScript::is_valid() const { bool NativeScript::is_tool() const { NativeScriptDesc *script_data = get_script_desc(); - if (script_data) + if (script_data) { return script_data->is_tool; + } return false; } @@ -313,8 +324,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - if (script_data->signals_.has(p_signal)) + if (script_data->signals_.has(p_signal)) { return true; + } script_data = script_data->base_data; } return false; @@ -323,13 +335,13 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const { void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return; + } Set<MethodInfo> signals_; while (script_data) { - for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) { signals_.insert(S->get().signal); } @@ -350,8 +362,9 @@ bool NativeScript::get_property_default_value(const StringName &p_property, Vari P = script_data->properties.find(p_property); script_data = script_data->base_data; } - if (!P) + if (!P) { return false; + } r_value = P.get().default_value; return true; @@ -363,13 +376,13 @@ void NativeScript::update_exports() { void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return; + } Set<MethodInfo> methods; while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { methods.insert(E->get().info); } @@ -401,13 +414,11 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { } Vector<ScriptNetData> NativeScript::get_rpc_methods() const { - Vector<ScriptNetData> v; NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -427,7 +438,6 @@ uint16_t NativeScript::get_rpc_method_id(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); if (E) { return E->get().rpc_method_id; @@ -445,7 +455,6 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { return E->key(); @@ -459,13 +468,11 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { switch (E->get().rpc_mode) { @@ -496,11 +503,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode(const StringName &p_method) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); if (E) { switch (E->get().rpc_mode) { @@ -535,7 +540,6 @@ Vector<ScriptNetData> NativeScript::get_rset_properties() const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -554,7 +558,6 @@ uint16_t NativeScript::get_rset_property_id(const StringName &p_variable) const NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable); if (E) { return E.get().rset_property_id; @@ -572,7 +575,6 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { return E.key(); @@ -586,13 +588,11 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { switch (E.get().rset_mode) { @@ -623,11 +623,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode(const StringName &p_variable) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable); if (E) { switch (E.get().rset_mode) { @@ -670,7 +668,6 @@ String NativeScript::get_method_documentation(const StringName &p_method) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *method = script_data->methods.find(p_method); if (method) { @@ -689,7 +686,6 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); while (script_data) { - Map<StringName, NativeScriptDesc::Signal>::Element *signal = script_data->signals_.find(p_signal_name); if (signal) { @@ -708,7 +704,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = script_data->properties.find(p_path); if (property) { @@ -722,7 +717,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (lib_path.empty() || class_name.empty() || library.is_null()) { r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; return Variant(); @@ -833,6 +827,7 @@ bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) } return false; } + bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { NativeScriptDesc *script_data = GET_SCRIPT_DESC(); @@ -877,10 +872,8 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list"); if (E) { - godot_variant result; result = E->get().method.method((godot_object *)owner, E->get().method.method_data, @@ -929,11 +922,9 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c } Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); if (P) { *r_is_valid = true; @@ -954,7 +945,6 @@ bool NativeScriptInstance::has_method(const StringName &p_method) const { } Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { @@ -1010,17 +1000,20 @@ String NativeScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -1120,11 +1113,11 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, } NativeScriptInstance::~NativeScriptInstance() { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); - if (!script_data) + if (!script_data) { return; + } script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); @@ -1138,16 +1131,13 @@ NativeScriptInstance::~NativeScriptInstance() { NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { - Map<String, Ref<GDNative>> erase_and_unload; for (Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.front(); L; L = L->next()) { - String lib_path = L->key(); Map<StringName, NativeScriptDesc> classes = L->get(); if (p_reload) { - Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); Ref<GDNative> gdn; @@ -1177,28 +1167,32 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { } for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { - // free property stuff first for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { - if (P.get().getter.free_func) + if (P.get().getter.free_func) { P.get().getter.free_func(P.get().getter.method_data); + } - if (P.get().setter.free_func) + if (P.get().setter.free_func) { P.get().setter.free_func(P.get().setter.method_data); + } } // free method stuff for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { - if (M->get().method.free_func) + if (M->get().method.free_func) { M->get().method.free_func(M->get().method.method_data); + } } // free constructor/destructor - if (C->get().create_func.free_func) + if (C->get().create_func.free_func) { C->get().create_func.free_func(C->get().create_func.method_data); + } - if (C->get().destroy_func.free_func) + if (C->get().destroy_func.free_func) { C->get().destroy_func.free_func(C->get().destroy_func.method_data); + } } erase_and_unload.insert(lib_path, gdn); @@ -1246,13 +1240,10 @@ NativeScriptLanguage::NativeScriptLanguage() { } NativeScriptLanguage::~NativeScriptLanguage() { - for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> lib = L->get(); // only shut down valid libs, duh! if (lib.is_valid()) { - // If it's a singleton-library then the gdnative module // manages the destruction at engine shutdown, not NativeScript. if (!lib->get_library()->is_singleton()) { @@ -1278,7 +1269,6 @@ void _add_reload_node() { } void NativeScriptLanguage::init() { - #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) List<String> args = OS::get_singleton()->get_cmdline_args(); @@ -1297,22 +1287,29 @@ void NativeScriptLanguage::init() { EditorNode::add_init_callback(&_add_reload_node); #endif } + String NativeScriptLanguage::get_type() const { return "NativeScript"; } + String NativeScriptLanguage::get_extension() const { return "gdns"; } + Error NativeScriptLanguage::execute_file(const String &p_path) { return OK; // Qué? } + void NativeScriptLanguage::finish() { _unload_stuff(); } + void NativeScriptLanguage::get_reserved_words(List<String> *p_words) const { } + void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { } + void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { } @@ -1321,6 +1318,7 @@ Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const s->set_class_name(p_class_name); return Ref<NativeScript>(s); } + bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { return true; } @@ -1329,20 +1327,26 @@ Script *NativeScriptLanguage::create_script() const { NativeScript *script = memnew(NativeScript); return script; } + bool NativeScriptLanguage::has_named_classes() const { return true; } + bool NativeScriptLanguage::supports_builtin_mode() const { return true; } + int NativeScriptLanguage::find_function(const String &p_function, const String &p_code) const { return -1; } + String NativeScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { return ""; } + void NativeScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { } + void NativeScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { } @@ -1350,27 +1354,36 @@ void NativeScriptLanguage::add_global_constant(const StringName &p_variable, con String NativeScriptLanguage::debug_get_error() const { return ""; } + int NativeScriptLanguage::debug_get_stack_level_count() const { return -1; } + int NativeScriptLanguage::debug_get_stack_level_line(int p_level) const { return -1; } + String NativeScriptLanguage::debug_get_stack_level_function(int p_level) const { return ""; } + String NativeScriptLanguage::debug_get_stack_level_source(int p_level) const { return ""; } + void NativeScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { } + void NativeScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { } + void NativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { } + String NativeScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { return ""; } + // Debugging stuff end. void NativeScriptLanguage::reload_all_scripts() { @@ -1378,6 +1391,7 @@ void NativeScriptLanguage::reload_all_scripts() { void NativeScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { } + void NativeScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("gdns"); } @@ -1412,8 +1426,9 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } p_info_arr[current].call_count = d->get().call_count; p_info_arr[current].self_time = d->get().self_time; @@ -1435,8 +1450,9 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } if (d->get().last_frame_call_count) { p_info_arr[current].call_count = d->get().last_frame_call_count; @@ -1482,8 +1498,7 @@ void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p #endif } -int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) { - +int NativeScriptLanguage::register_binding_functions(godot_nativescript_instance_binding_functions p_binding_functions) { // find index int idx = -1; @@ -1514,14 +1529,16 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) { Vector<void *> &binding_data = *E->get(); - if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) + if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) { binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]); + } } binding_functions.write[p_idx].first = false; - if (binding_functions[p_idx].second.free_func) + if (binding_functions[p_idx].second.free_func) { binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data); + } } void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { @@ -1531,8 +1548,9 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); - if (!binding_data) + if (!binding_data) { return nullptr; // should never happen. + } if (binding_data->size() <= p_idx) { // okay, add new elements here. @@ -1546,7 +1564,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } if (!(*binding_data)[p_idx]) { - const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name()); // no binding data yet, soooooo alloc new one \o/ @@ -1557,7 +1574,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { - Vector<void *> *binding_data = new Vector<void *>; binding_data->resize(binding_functions.size()); @@ -1572,15 +1588,16 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { - - if (!p_data) + if (!p_data) { return; + } Vector<void *> &binding_data = *(Vector<void *> *)p_data; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } if (binding_functions[i].first && binding_functions[i].second.free_instance_binding_data) { binding_functions[i].second.free_instance_binding_data(binding_functions[i].second.data, binding_data[i]); @@ -1593,20 +1610,22 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) { } void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); - if (!data) + if (!data) { return; + } Vector<void *> &binding_data = *(Vector<void *> *)data; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } - if (!binding_functions[i].first) + if (!binding_functions[i].first) { continue; + } if (binding_functions[i].second.refcount_incremented_instance_binding) { binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object); @@ -1615,22 +1634,24 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec } bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); - if (!data) + if (!data) { return true; + } Vector<void *> &binding_data = *(Vector<void *> *)data; bool can_die = true; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } - if (!binding_functions[i].first) + if (!binding_functions[i].first) { continue; + } if (binding_functions[i].second.refcount_decremented_instance_binding) { can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object); @@ -1651,13 +1672,15 @@ void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_nam } const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const { - if (!global_type_tags.has(p_idx)) + if (!global_type_tags.has(p_idx)) { return nullptr; + } const HashMap<StringName, const void *> &tags = global_type_tags[p_idx]; - if (!tags.has(p_class_name)) + if (!tags.has(p_class_name)) { return nullptr; + } const void *tag = tags.get(p_class_name); @@ -1693,8 +1716,9 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>()); - if (!library_script_users.has(lib_path)) + if (!library_script_users.has(lib_path)) { library_script_users.insert(lib_path, Set<NativeScript *>()); + } void *proc_ptr; @@ -1734,13 +1758,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here for (Map<String, Ref<GDNative>>::Element *L = library_gdnatives.front(); L; L = L->next()) { - if (L->get().is_null()) { continue; } if (L->get()->is_initialized()) { - void *proc_ptr; Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); @@ -1805,16 +1827,20 @@ String NativeScriptLanguage::get_global_class_name(const String &p_path, String if (!p_path.empty()) { Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript"); if (script.is_valid()) { - if (r_base_type) + if (r_base_type) { *r_base_type = script->get_instance_base_type(); - if (r_icon_path) + } + if (r_icon_path) { *r_icon_path = script->get_script_class_icon_path(); + } return script->get_script_class_name(); } - if (r_base_type) + if (r_base_type) { *r_base_type = String(); - if (r_icon_path) + } + if (r_icon_path) { *r_icon_path = String(); + } } return String(); } @@ -1828,14 +1854,13 @@ void NativeReloadNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_WM_FOCUS_OUT: { - - if (unloaded) + if (unloaded) { break; + } MutexLock lock(NSL->mutex); NSL->_unload_stuff(true); for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); if (gdn.is_null()) { @@ -1863,14 +1888,13 @@ void NativeReloadNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_IN: { - - if (!unloaded) + if (!unloaded) { break; + } MutexLock lock(NSL->mutex); Set<StringName> libs_to_remove; for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); if (gdn.is_null()) { @@ -1908,8 +1932,9 @@ void NativeReloadNode::_notification(int p_what) { for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) { NativeScript *script = S->get(); - if (script->placeholders.size() == 0) + if (script->placeholders.size() == 0) { continue; + } for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { script->_update_placeholder(P->get()); @@ -1931,7 +1956,7 @@ void NativeReloadNode::_notification(int p_what) { #endif } -RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error); } @@ -1945,8 +1970,9 @@ bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "gdns") + if (el == "gdns") { return "NativeScript"; + } return ""; } |