diff options
author | kobewi <kobewi4e@gmail.com> | 2023-09-04 17:01:33 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2024-05-11 18:53:08 +0200 |
commit | a262d2d8811a43c906a4cac55b7126ebec7699be (patch) | |
tree | 0507fff0aed8778e71a2afc0a2d4ac15184e7803 /core | |
parent | 916ea002c15e82879f3eada7c635daaecccc9e35 (diff) | |
download | redot-engine-a262d2d8811a43c906a4cac55b7126ebec7699be.tar.gz |
Add shorthand for using singleton string names
Diffstat (limited to 'core')
-rw-r--r-- | core/config/project_settings.cpp | 4 | ||||
-rw-r--r-- | core/core_string_names.cpp | 6 | ||||
-rw-r--r-- | core/core_string_names.h | 8 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 2 | ||||
-rw-r--r-- | core/io/resource.cpp | 12 | ||||
-rw-r--r-- | core/object/class_db.cpp | 2 | ||||
-rw-r--r-- | core/object/message_queue.cpp | 2 | ||||
-rw-r--r-- | core/object/object.cpp | 16 | ||||
-rw-r--r-- | core/variant/variant.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 6 |
10 files changed, 29 insertions, 31 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index a0412e91ff..a116c9c270 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -291,7 +291,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { } } } else { - if (p_name == CoreStringNames::get_singleton()->_custom_features) { + if (p_name == CoreStringName(_custom_features)) { Vector<String> custom_feature_array = String(p_value).split(","); for (int i = 0; i < custom_feature_array.size(); i++) { custom_features.insert(custom_feature_array[i]); @@ -875,7 +875,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<S if (!p_custom_features.is_empty()) { // Store how many properties are saved, add one for custom features, which must always go first. file->store_32(count + 1); - String key = CoreStringNames::get_singleton()->_custom_features; + String key = CoreStringName(_custom_features); file->store_pascal_string(key); int len; diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 21645e5efc..1ffe76495d 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -33,12 +33,10 @@ CoreStringNames *CoreStringNames::singleton = nullptr; CoreStringNames::CoreStringNames() : - _free(StaticCString::create("free")), + free_(StaticCString::create("free")), changed(StaticCString::create("changed")), - _script(StaticCString::create("script")), + script(StaticCString::create("script")), script_changed(StaticCString::create("script_changed")), - ___pdcdata(StaticCString::create("___pdcdata")), - __getvar(StaticCString::create("__getvar")), _iter_init(StaticCString::create("_iter_init")), _iter_next(StaticCString::create("_iter_next")), _iter_get(StaticCString::create("_iter_get")), diff --git a/core/core_string_names.h b/core/core_string_names.h index 1c77cef567..d7ddc39f5e 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -50,12 +50,10 @@ public: static CoreStringNames *singleton; - StringName _free; + StringName free_; // "free", conflict with C++ keyword. StringName changed; - StringName _script; + StringName script; StringName script_changed; - StringName ___pdcdata; - StringName __getvar; StringName _iter_init; StringName _iter_next; StringName _iter_get; @@ -98,4 +96,6 @@ public: StringName property_list_changed; }; +#define CoreStringName(m_name) CoreStringNames::get_singleton()->m_name + #endif // CORE_STRING_NAMES_H diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 2cdfacae17..1928f86d6a 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1696,7 +1696,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Variant value; - if (E.name == CoreStringNames::get_singleton()->_script) { + if (E.name == CoreStringName(script)) { Ref<Script> script = obj->get_script(); if (script.is_valid()) { String path = script->get_path(); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 4c3cfeaa58..24ff0e83d2 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -43,9 +43,9 @@ void Resource::emit_changed() { if (ResourceLoader::is_within_load() && !Thread::is_main_thread()) { // Let the connection happen on the main thread, later, since signals are not thread-safe. - call_deferred("emit_signal", CoreStringNames::get_singleton()->changed); + call_deferred("emit_signal", CoreStringName(changed)); } else { - emit_signal(CoreStringNames::get_singleton()->changed); + emit_signal(CoreStringName(changed)); } } @@ -172,8 +172,8 @@ void Resource::connect_changed(const Callable &p_callable, uint32_t p_flags) { callable_mp(this, &Resource::connect_changed).call_deferred(p_callable, p_flags); return; } - if (!is_connected(CoreStringNames::get_singleton()->changed, p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) { - connect(CoreStringNames::get_singleton()->changed, p_callable, p_flags); + if (!is_connected(CoreStringName(changed), p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) { + connect(CoreStringName(changed), p_callable, p_flags); } } @@ -183,8 +183,8 @@ void Resource::disconnect_changed(const Callable &p_callable) { callable_mp(this, &Resource::disconnect_changed).call_deferred(p_callable); return; } - if (is_connected(CoreStringNames::get_singleton()->changed, p_callable)) { - disconnect(CoreStringNames::get_singleton()->changed, p_callable); + if (is_connected(CoreStringName(changed), p_callable)) { + disconnect(CoreStringName(changed), p_callable); } } diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 6b84dfcee9..7ea26c3fc5 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1554,7 +1554,7 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia } // The "free()" method is special, so we assume it exists and return a Callable. - if (p_property == CoreStringNames::get_singleton()->_free) { + if (p_property == CoreStringName(free_)) { r_value = Callable(p_object, p_property); return true; } diff --git a/core/object/message_queue.cpp b/core/object/message_queue.cpp index 90536e58ff..6fab934395 100644 --- a/core/object/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -197,7 +197,7 @@ Error CallQueue::push_notification(ObjectID p_id, int p_notification) { Message *msg = memnew_placement(buffer_end, Message); msg->type = TYPE_NOTIFICATION; - msg->callable = Callable(p_id, CoreStringNames::get_singleton()->notification); //name is meaningless but callable needs it + msg->callable = Callable(p_id, CoreStringName(notification)); //name is meaningless but callable needs it //msg->target; msg->notification = p_notification; diff --git a/core/object/object.cpp b/core/object/object.cpp index 5125ab8a6e..57f8766509 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -260,7 +260,7 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } } - if (p_name == CoreStringNames::get_singleton()->_script) { + if (p_name == CoreStringName(script)) { set_script(p_value); if (r_valid) { *r_valid = true; @@ -351,7 +351,7 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { } } - if (p_name == CoreStringNames::get_singleton()->_script) { + if (p_name == CoreStringName(script)) { ret = get_script(); if (r_valid) { *r_valid = true; @@ -672,7 +672,7 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call } bool Object::has_method(const StringName &p_method) const { - if (p_method == CoreStringNames::get_singleton()->_free) { + if (p_method == CoreStringName(free_)) { return true; } @@ -698,7 +698,7 @@ int Object::_get_method_argument_count_bind(const StringName &p_method) const { } int Object::get_method_argument_count(const StringName &p_method, bool *r_is_valid) const { - if (p_method == CoreStringNames::get_singleton()->_free) { + if (p_method == CoreStringName(free_)) { if (r_is_valid) { *r_is_valid = true; } @@ -787,7 +787,7 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) { Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; - if (p_method == CoreStringNames::get_singleton()->_free) { + if (p_method == CoreStringName(free_)) { //free must be here, before anything, always ready #ifdef DEBUG_ENABLED if (p_argcount != 0) { @@ -850,7 +850,7 @@ Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_ Variant Object::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; - if (p_method == CoreStringNames::get_singleton()->_free) { + if (p_method == CoreStringName(free_)) { // Free is not const, so fail. r_error.error = Callable::CallError::CALL_ERROR_METHOD_NOT_CONST; return Variant(); @@ -979,7 +979,7 @@ void Object::set_script(const Variant &p_script) { } notify_property_list_changed(); //scripts may add variables, so refresh is desired - emit_signal(CoreStringNames::get_singleton()->script_changed); + emit_signal(CoreStringName(script_changed)); } void Object::set_script_instance(ScriptInstance *p_instance) { @@ -1654,7 +1654,7 @@ void Object::clear_internal_resource_paths() { } void Object::notify_property_list_changed() { - emit_signal(CoreStringNames::get_singleton()->property_list_changed); + emit_signal(CoreStringName(property_list_changed)); } void Object::_bind_methods() { diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 3a499a2bcd..8be00b1358 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2121,7 +2121,7 @@ Variant::operator ::RID() const { } #endif Callable::CallError ce; - Variant ret = _get_obj().obj->callp(CoreStringNames::get_singleton()->get_rid, nullptr, 0, ce); + Variant ret = _get_obj().obj->callp(CoreStringName(get_rid), nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::RID) { return ret; } diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 96c52260d9..48176163a1 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -1384,7 +1384,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { ref.push_back(r_iter); Variant vref = ref; const Variant *refp[] = { &vref }; - Variant ret = _get_obj().obj->callp(CoreStringNames::get_singleton()->_iter_init, refp, 1, ce); + Variant ret = _get_obj().obj->callp(CoreStringName(_iter_init), refp, 1, ce); if (ref.size() != 1 || ce.error != Callable::CallError::CALL_OK) { valid = false; @@ -1619,7 +1619,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { ref.push_back(r_iter); Variant vref = ref; const Variant *refp[] = { &vref }; - Variant ret = _get_obj().obj->callp(CoreStringNames::get_singleton()->_iter_next, refp, 1, ce); + Variant ret = _get_obj().obj->callp(CoreStringName(_iter_next), refp, 1, ce); if (ref.size() != 1 || ce.error != Callable::CallError::CALL_OK) { valid = false; @@ -1811,7 +1811,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { Callable::CallError ce; ce.error = Callable::CallError::CALL_OK; const Variant *refp[] = { &r_iter }; - Variant ret = _get_obj().obj->callp(CoreStringNames::get_singleton()->_iter_get, refp, 1, ce); + Variant ret = _get_obj().obj->callp(CoreStringName(_iter_get), refp, 1, ce); if (ce.error != Callable::CallError::CALL_OK) { r_valid = false; |