From a262d2d8811a43c906a4cac55b7126ebec7699be Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 4 Sep 2023 17:01:33 +0200 Subject: [PATCH] Add shorthand for using singleton string names --- core/config/project_settings.cpp | 4 +- core/core_string_names.cpp | 6 +- core/core_string_names.h | 8 +- core/io/marshalls.cpp | 2 +- core/io/resource.cpp | 12 +-- core/object/class_db.cpp | 2 +- core/object/message_queue.cpp | 2 +- core/object/object.cpp | 16 ++-- core/variant/variant.cpp | 2 +- core/variant/variant_setget.cpp | 6 +- editor/action_map_editor.cpp | 4 +- editor/animation_track_editor.cpp | 20 ++--- editor/editor_properties.cpp | 2 +- .../animation_player_editor_plugin.cpp | 10 +-- .../animation_state_machine_editor.cpp | 2 +- .../plugins/animation_tree_editor_plugin.cpp | 2 +- .../collision_shape_2d_editor_plugin.cpp | 4 +- .../mesh_instance_3d_editor_plugin.cpp | 10 +-- editor/plugins/script_editor_plugin.cpp | 4 +- editor/plugins/skeleton_3d_editor_plugin.cpp | 20 ++--- .../tiles/tile_set_atlas_source_editor.cpp | 14 ++-- ...le_set_scenes_collection_source_editor.cpp | 6 +- modules/gdscript/gdscript.cpp | 6 +- modules/gdscript/gdscript_analyzer.cpp | 4 +- modules/gdscript/gdscript_compiler.cpp | 2 +- modules/gdscript/gdscript_vm.cpp | 10 +-- .../gridmap/editor/grid_map_editor_plugin.cpp | 4 +- modules/gridmap/grid_map.cpp | 4 +- modules/multiplayer/multiplayer_spawner.cpp | 4 +- modules/multiplayer/scene_cache_interface.cpp | 4 +- .../scene_replication_interface.cpp | 8 +- scene/2d/animated_sprite_2d.cpp | 14 ++-- scene/2d/audio_stream_player_2d.cpp | 4 +- scene/2d/cpu_particles_2d.cpp | 2 +- scene/2d/gpu_particles_2d.cpp | 2 +- scene/2d/mesh_instance_2d.cpp | 2 +- scene/2d/multimesh_instance_2d.cpp | 2 +- scene/2d/physics/area_2d.cpp | 74 +++++++++--------- scene/2d/physics/collision_object_2d.cpp | 10 +-- scene/2d/physics/joints/joint_2d.cpp | 8 +- scene/2d/physics/rigid_body_2d.cpp | 30 +++---- scene/2d/sprite_2d.cpp | 4 +- scene/2d/tile_map.cpp | 10 +-- scene/2d/tile_map_layer.cpp | 40 +++++----- scene/2d/touch_screen_button.cpp | 8 +- scene/2d/visible_on_screen_notifier_2d.cpp | 4 +- scene/3d/cpu_particles_3d.cpp | 2 +- scene/3d/gpu_particles_3d.cpp | 2 +- scene/3d/node_3d.cpp | 14 ++-- scene/3d/physics/area_3d.cpp | 78 ++++++++++--------- scene/3d/physics/area_3d.h | 4 +- scene/3d/physics/collision_object_3d.cpp | 6 +- scene/3d/physics/joints/joint_3d.cpp | 8 +- scene/3d/physics/rigid_body_3d.cpp | 30 +++---- scene/3d/skeleton_3d.cpp | 8 +- scene/3d/sprite_3d.cpp | 22 +++--- scene/3d/visible_on_screen_notifier_3d.cpp | 4 +- scene/3d/visual_instance_3d.cpp | 8 +- scene/animation/animation_blend_tree.cpp | 16 ++-- scene/animation/animation_mixer.cpp | 20 ++--- scene/animation/animation_player.cpp | 8 +- scene/animation/animation_tree.cpp | 6 +- scene/audio/audio_stream_player_internal.cpp | 4 +- scene/gui/container.cpp | 4 +- scene/gui/control.cpp | 22 +++--- scene/gui/nine_patch_rect.cpp | 2 +- scene/gui/video_stream_player.cpp | 4 +- scene/main/canvas_item.cpp | 12 +-- scene/main/node.cpp | 16 ++-- scene/main/shader_globals_override.cpp | 12 +-- scene/main/window.cpp | 12 +-- scene/resources/packed_scene.cpp | 2 +- scene/resources/sprite_frames.cpp | 2 +- scene/scene_string_names.cpp | 2 +- scene/scene_string_names.h | 4 +- servers/audio_server.cpp | 6 +- tests/core/object/test_object.h | 4 +- 77 files changed, 382 insertions(+), 380 deletions(-) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index a0412e91ff4..a116c9c2705 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 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 RBMapstore_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 21645e5efc0..1ffe76495d8 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 1c77cef567e..d7ddc39f5e1 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 2cdfacae175..1928f86d6a8 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