diff options
Diffstat (limited to 'core/script_language.cpp')
-rw-r--r-- | core/script_language.cpp | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/core/script_language.cpp b/core/script_language.cpp index 82cac6bc9a..38a970f3c6 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -34,6 +34,7 @@ #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" #include "core/project_settings.h" + #include <stdint.h> ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES]; @@ -45,11 +46,10 @@ bool ScriptServer::languages_finished = false; ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr; void Script::_notification(int p_what) { - if (p_what == NOTIFICATION_POSTINITIALIZE) { - - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { EngineDebugger::get_script_debugger()->set_break_language(get_language()); + } } } @@ -100,7 +100,6 @@ Dictionary Script::_get_script_constant_map() { } void Script::_bind_methods() { - ClassDB::bind_method(D_METHOD("can_instance"), &Script::can_instance); //ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create); ClassDB::bind_method(D_METHOD("instance_has", "base_object"), &Script::instance_has); @@ -125,30 +124,25 @@ void Script::_bind_methods() { } void ScriptServer::set_scripting_enabled(bool p_enabled) { - scripting_enabled = p_enabled; } bool ScriptServer::is_scripting_enabled() { - return scripting_enabled; } ScriptLanguage *ScriptServer::get_language(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, _language_count, nullptr); return _languages[p_idx]; } void ScriptServer::register_language(ScriptLanguage *p_language) { - ERR_FAIL_COND(_language_count >= MAX_LANGUAGES); _languages[_language_count++] = p_language; } void ScriptServer::unregister_language(ScriptLanguage *p_language) { - for (int i = 0; i < _language_count; i++) { if (_languages[i] == p_language) { _language_count--; @@ -161,7 +155,6 @@ void ScriptServer::unregister_language(ScriptLanguage *p_language) { } void ScriptServer::init_languages() { - { //load global classes global_classes_clear(); if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { @@ -169,8 +162,9 @@ void ScriptServer::init_languages() { for (int i = 0; i < script_classes.size(); i++) { Dictionary c = script_classes[i]; - if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) + if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) { continue; + } add_global_class(c["class"], c["base"], c["language"], c["path"]); } } @@ -182,7 +176,6 @@ void ScriptServer::init_languages() { } void ScriptServer::finish_languages() { - for (int i = 0; i < _language_count; i++) { _languages[i]->finish(); } @@ -191,24 +184,20 @@ void ScriptServer::finish_languages() { } void ScriptServer::set_reload_scripts_on_save(bool p_enable) { - reload_scripts_on_save = p_enable; } bool ScriptServer::is_reload_scripts_on_save_enabled() { - return reload_scripts_on_save; } void ScriptServer::thread_enter() { - for (int i = 0; i < _language_count; i++) { _languages[i]->thread_enter(); } } void ScriptServer::thread_exit() { - for (int i = 0; i < _language_count; i++) { _languages[i]->thread_exit(); } @@ -228,16 +217,20 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName g.base = p_base; global_classes[p_class] = g; } + void ScriptServer::remove_global_class(const StringName &p_class) { global_classes.erase(p_class); } + bool ScriptServer::is_global_class(const StringName &p_class) { return global_classes.has(p_class); } + StringName ScriptServer::get_global_class_language(const StringName &p_class) { ERR_FAIL_COND_V(!global_classes.has(p_class), StringName()); return global_classes[p_class].language; } + String ScriptServer::get_global_class_path(const String &p_class) { ERR_FAIL_COND_V(!global_classes.has(p_class), String()); return global_classes[p_class].path; @@ -247,6 +240,7 @@ StringName ScriptServer::get_global_class_base(const String &p_class) { ERR_FAIL_COND_V(!global_classes.has(p_class), String()); return global_classes[p_class].base; } + StringName ScriptServer::get_global_class_native_base(const String &p_class) { ERR_FAIL_COND_V(!global_classes.has(p_class), String()); String base = global_classes[p_class].base; @@ -255,6 +249,7 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) { } return base; } + void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) { const StringName *K = nullptr; List<StringName> classes; @@ -266,6 +261,7 @@ void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) { r_global_classes->push_back(E->get()); } } + void ScriptServer::save_global_classes() { List<StringName> gc; get_global_class_list(&gc); @@ -285,27 +281,26 @@ void ScriptServer::save_global_classes() { //////////////////// void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) { - List<PropertyInfo> pinfo; get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { Pair<StringName, Variant> p; p.first = E->get().name; - if (get(p.first, p.second)) + if (get(p.first, p.second)) { state.push_back(p); + } } } } Variant ScriptInstance::call(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -324,23 +319,25 @@ void ScriptInstance::call_multilevel_reversed(const StringName &p_method, const } void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } } Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) + if (argptr[i]->get_type() == Variant::NIL) { break; + } argc++; } @@ -359,9 +356,9 @@ void ScriptLanguage::frame() { } bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { - - if (script->is_placeholder_fallback_enabled()) + if (script->is_placeholder_fallback_enabled()) { return false; + } if (values.has(p_name)) { Variant defval; @@ -384,8 +381,8 @@ bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_v } return false; } -bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) const { +bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) const { if (values.has(p_name)) { r_ret = values[p_name]; return true; @@ -408,7 +405,6 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co } void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { - if (script->is_placeholder_fallback_enabled()) { for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { p_properties->push_back(E->get()); @@ -425,38 +421,41 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti } Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - if (values.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return values[p_name].get_type(); } if (constants.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return constants[p_name].get_type(); } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return Variant::NIL; } void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - - if (script->is_placeholder_fallback_enabled()) + if (script->is_placeholder_fallback_enabled()) { return; + } if (script.is_valid()) { script->get_script_method_list(p_list); } } -bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { - if (script->is_placeholder_fallback_enabled()) +bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { + if (script->is_placeholder_fallback_enabled()) { return false; + } if (script.is_valid()) { return script->has_method(p_method); @@ -465,17 +464,15 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { } void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values) { - Set<StringName> new_values; for (const List<PropertyInfo>::Element *E = p_properties.front(); E; E = E->next()) { - StringName n = E->get().name; new_values.insert(n); if (!values.has(n) || values[n].get_type() != E->get().type) { - - if (p_values.has(n)) + if (p_values.has(n)) { values[n] = p_values[n]; + } } } @@ -483,9 +480,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c List<StringName> to_remove; for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) { - - if (!new_values.has(E->key())) + if (!new_values.has(E->key())) { to_remove.push_back(E->key()); + } Variant defval; if (script->get_property_default_value(E->key(), defval)) { @@ -497,13 +494,11 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c } while (to_remove.size()) { - values.erase(to_remove.front()->get()); to_remove.pop_front(); } if (owner && owner->get_script_instance() == this) { - owner->_change_notify(); } //change notify @@ -513,7 +508,6 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c } void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) { - if (script->is_placeholder_fallback_enabled()) { Map<StringName, Variant>::Element *E = values.find(p_name); @@ -535,31 +529,34 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, } } - if (r_valid) + if (r_valid) { *r_valid = false; // Cannot change the value in either case + } } Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) { - if (script->is_placeholder_fallback_enabled()) { const Map<StringName, Variant>::Element *E = values.find(p_name); if (E) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return E->value(); } E = constants.find(p_name); if (E) { - if (r_valid) + if (r_valid) { *r_valid = true; + } return E->value(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return Variant(); } @@ -579,7 +576,6 @@ PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, } PlaceHolderScriptInstance::~PlaceHolderScriptInstance() { - if (script.is_valid()) { script->_placeholder_erased(this); } |