Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize comparisons for Object's get_argument_options #86743

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,15 +1723,17 @@ bool Engine::is_printing_error_messages() const {
return ::Engine::get_singleton()->is_printing_error_messages();
}

#ifdef TOOLS_ENABLED
void Engine::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;
if (p_idx == 0 && (pf == "has_singleton" || pf == "get_singleton" || pf == "unregister_singleton")) {
for (const String &E : get_singleton_list()) {
r_options->push_back(E.quote());
}
}
Object::get_argument_options(p_function, p_idx, r_options);
}
#endif

void Engine::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
Expand Down
2 changes: 2 additions & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ class Engine : public Object {
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

Engine() { singleton = this; }
};
Expand Down
4 changes: 3 additions & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ void Input::_bind_methods() {
ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected")));
}

#ifdef TOOLS_ENABLED
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;

if ((p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength" || pf == "get_action_raw_strength")) ||
(p_idx < 2 && pf == "get_axis") ||
Expand All @@ -201,6 +202,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
}
Object::get_argument_options(p_function, p_idx, r_options);
}
#endif

void Input::VelocityTrack::update(const Vector2 &p_delta_p, const Vector2 &p_screen_delta_p) {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
Expand Down
3 changes: 3 additions & 0 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ class Input : public Object {
public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;

#ifdef TOOLS_ENABLED
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

static Input *get_singleton();

Expand Down
13 changes: 8 additions & 5 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,15 +2086,17 @@ void ObjectDB::debug_objects(DebugFunc p_func) {
spin_lock.unlock();
}

#ifdef TOOLS_ENABLED
void Object::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
const String pf = p_function;
if (p_idx == 0) {
if (p_function == "connect" || p_function == "is_connected" || p_function == "disconnect" || p_function == "emit_signal" || p_function == "has_signal") {
if (pf == "connect" || pf == "is_connected" || pf == "disconnect" || pf == "emit_signal" || pf == "has_signal") {
List<MethodInfo> signals;
get_signal_list(&signals);
for (const MethodInfo &E : signals) {
r_options->push_back(E.name.quote());
}
} else if (p_function == "call" || p_function == "call_deferred" || p_function == "callv" || p_function == "has_method") {
} else if (pf == "call" || pf == "call_deferred" || pf == "callv" || pf == "has_method") {
List<MethodInfo> methods;
get_method_list(&methods);
for (const MethodInfo &E : methods) {
Expand All @@ -2103,21 +2105,21 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
}
r_options->push_back(E.name.quote());
}
} else if (p_function == "set" || p_function == "set_deferred" || p_function == "get") {
} else if (pf == "set" || pf == "set_deferred" || pf == "get") {
List<PropertyInfo> properties;
get_property_list(&properties);
for (const PropertyInfo &E : properties) {
if (E.usage & PROPERTY_USAGE_DEFAULT && !(E.usage & PROPERTY_USAGE_INTERNAL)) {
r_options->push_back(E.name.quote());
}
}
} else if (p_function == "set_meta" || p_function == "get_meta" || p_function == "has_meta" || p_function == "remove_meta") {
} else if (pf == "set_meta" || pf == "get_meta" || pf == "has_meta" || pf == "remove_meta") {
for (const KeyValue<StringName, Variant> &K : metadata) {
r_options->push_back(String(K.key).quote());
}
}
} else if (p_idx == 2) {
if (p_function == "connect") {
if (pf == "connect") {
// Ideally, the constants should be inferred by the parameter.
// But a parameter's PropertyInfo does not store the enum they come from, so this will do for now.
List<StringName> constants;
Expand All @@ -2128,6 +2130,7 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
}
}
}
#endif

SpinLock ObjectDB::spin_lock;
uint32_t ObjectDB::slot_count = 0;
Expand Down
3 changes: 1 addition & 2 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,6 @@ class Object {
Variant::Type get_static_property_type(const StringName &p_property, bool *r_valid = nullptr) const;
Variant::Type get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid = nullptr) const;

virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;

// Translate message (internationalization).
String tr(const StringName &p_message, const StringName &p_context = "") const;
String tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const;
Expand All @@ -969,6 +967,7 @@ class Object {
_FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; }

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
void editor_set_section_unfold(const String &p_section, bool p_unfolded);
bool editor_is_section_unfolded(const String &p_section);
const HashSet<String> &editor_get_section_folding() const { return editor_section_folding; }
Expand Down
7 changes: 5 additions & 2 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ bool EditorInterface::is_movie_maker_enabled() const {
return EditorRunBar::get_singleton()->is_movie_maker_enabled();
}

// Base.
#ifdef TOOLS_ENABLED
void EditorInterface::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;
if (p_idx == 0) {
if (pf == "set_main_screen_editor") {
for (String E : { "\"2D\"", "\"3D\"", "\"Script\"", "\"AssetLib\"" }) {
Expand All @@ -508,6 +508,9 @@ void EditorInterface::get_argument_options(const StringName &p_function, int p_i
}
Object::get_argument_options(p_function, p_idx, r_options);
}
#endif

// Base.

void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("restart_editor", "save"), &EditorInterface::restart_editor, DEFVAL(true));
Expand Down
5 changes: 3 additions & 2 deletions editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ class EditorInterface : public Object {
void set_movie_maker_enabled(bool p_enabled);
bool is_movie_maker_enabled() const;

// Base.

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

// Base.
static void create();
static void free();

Expand Down
5 changes: 4 additions & 1 deletion scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,11 @@ PackedStringArray AnimatedSprite2D::get_configuration_warnings() const {
return warnings;
}

#ifdef TOOLS_ENABLED
void AnimatedSprite2D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
const String pf = p_function;
if (p_idx == 0 && frames.is_valid()) {
if (p_function == "play" || p_function == "play_backwards" || p_function == "set_animation" || p_function == "set_autoplay") {
if (pf == "play" || pf == "play_backwards" || pf == "set_animation" || pf == "set_autoplay") {
List<StringName> al;
frames->get_animation_list(&al);
for (const StringName &name : al) {
Expand All @@ -589,6 +591,7 @@ void AnimatedSprite2D::get_argument_options(const StringName &p_function, int p_
}
Node2D::get_argument_options(p_function, p_idx, r_options);
}
#endif

#ifndef DISABLE_DEPRECATED
bool AnimatedSprite2D::_set(const StringName &p_name, const Variant &p_value) {
Expand Down
3 changes: 3 additions & 0 deletions scene/2d/animated_sprite_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ class AnimatedSprite2D : public Node2D {
bool is_flipped_v() const;

PackedStringArray get_configuration_warnings() const override;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

AnimatedSprite2D();
};
Expand Down
5 changes: 4 additions & 1 deletion scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,11 @@ PackedStringArray AnimatedSprite3D::get_configuration_warnings() const {
return warnings;
}

#ifdef TOOLS_ENABLED
void AnimatedSprite3D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
const String pf = p_function;
if (p_idx == 0 && frames.is_valid()) {
if (p_function == "play" || p_function == "play_backwards" || p_function == "set_animation" || p_function == "set_autoplay") {
if (pf == "play" || pf == "play_backwards" || pf == "set_animation" || pf == "set_autoplay") {
List<StringName> al;
frames->get_animation_list(&al);
for (const StringName &name : al) {
Expand All @@ -1450,6 +1452,7 @@ void AnimatedSprite3D::get_argument_options(const StringName &p_function, int p_
}
SpriteBase3D::get_argument_options(p_function, p_idx, r_options);
}
#endif

#ifndef DISABLE_DEPRECATED
bool AnimatedSprite3D::_set(const StringName &p_name, const Variant &p_value) {
Expand Down
3 changes: 3 additions & 0 deletions scene/3d/sprite_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ class AnimatedSprite3D : public SpriteBase3D {
virtual Rect2 get_item_rect() const override;

virtual PackedStringArray get_configuration_warnings() const override;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

AnimatedSprite3D();
};
Expand Down
6 changes: 4 additions & 2 deletions scene/animation/animation_blend_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,21 +1545,23 @@ void AnimationNodeBlendTree::_node_changed(const StringName &p_node) {
emit_signal(SNAME("node_changed"), p_node);
}

#ifdef TOOLS_ENABLED
void AnimationNodeBlendTree::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;
bool add_node_options = false;
if (p_idx == 0) {
add_node_options = (pf == "get_node" || pf == "has_node" || pf == "rename_node" || pf == "remove_node" || pf == "set_node_position" || pf == "get_node_position" || pf == "connect_node" || pf == "disconnect_node");
} else if (p_idx == 2) {
add_node_options = (pf == "connect_node" || pf == "disconnect_node");
}
if (add_node_options) {
for (KeyValue<StringName, Node> E : nodes) {
for (const KeyValue<StringName, Node> &E : nodes) {
r_options->push_back(String(E.key).quote());
}
}
AnimationRootNode::get_argument_options(p_function, p_idx, r_options);
}
#endif

void AnimationNodeBlendTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeBlendTree::add_node, DEFVAL(Vector2()));
Expand Down
2 changes: 2 additions & 0 deletions scene/animation/animation_blend_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ class AnimationNodeBlendTree : public AnimationRootNode {

virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

AnimationNodeBlendTree();
~AnimationNodeBlendTree();
Expand Down
4 changes: 3 additions & 1 deletion scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,8 +2152,9 @@ void AnimationMixer::_notification(int p_what) {
}
}

#ifdef TOOLS_ENABLED
void AnimationMixer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;
if (p_idx == 0) {
if (pf == "get_animation" || pf == "has_animation") {
List<StringName> al;
Expand All @@ -2171,6 +2172,7 @@ void AnimationMixer::get_argument_options(const StringName &p_function, int p_id
}
Node::get_argument_options(p_function, p_idx, r_options);
}
#endif

void AnimationMixer::_bind_methods() {
/* ---- Data lists ---- */
Expand Down
3 changes: 3 additions & 0 deletions scene/animation/animation_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ class AnimationMixer : public Node {
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
virtual void _validate_property(PropertyInfo &p_property) const;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

static void _bind_methods();
void _node_removed(Node *p_node);
Expand Down
6 changes: 4 additions & 2 deletions scene/animation/animation_node_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,21 +1793,23 @@ void AnimationNodeStateMachine::_animation_node_removed(const ObjectID &p_oid, c
AnimationRootNode::_animation_node_removed(p_oid, p_node);
}

#ifdef TOOLS_ENABLED
void AnimationNodeStateMachine::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
const String pf = p_function;
bool add_state_options = false;
if (p_idx == 0) {
add_state_options = (pf == "get_node" || pf == "has_node" || pf == "rename_node" || pf == "remove_node" || pf == "replace_node" || pf == "set_node_position" || pf == "get_node_position");
} else if (p_idx <= 1) {
add_state_options = (pf == "has_transition" || pf == "add_transition" || pf == "remove_transition");
}
if (add_state_options) {
for (KeyValue<StringName, State> E : states) {
for (const KeyValue<StringName, State> &E : states) {
r_options->push_back(String(E.key).quote());
}
}
AnimationRootNode::get_argument_options(p_function, p_idx, r_options);
}
#endif

void AnimationNodeStateMachine::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeStateMachine::add_node, DEFVAL(Vector2()));
Expand Down
2 changes: 2 additions & 0 deletions scene/animation/animation_node_state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class AnimationNodeStateMachine : public AnimationRootNode {

virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override;

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

AnimationNodeStateMachine();
};
Expand Down
6 changes: 4 additions & 2 deletions scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,10 @@ double AnimationPlayer::get_blend_time(const StringName &p_animation1, const Str
}
}

#ifdef TOOLS_ENABLED
void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String pf = p_function;
if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "has_animation" || p_function == "queue")) {
const String pf = p_function;
if (p_idx == 0 && (pf == "play" || pf == "play_backwards" || pf == "has_animation" || pf == "queue")) {
List<StringName> al;
get_animation_list(&al);
for (const StringName &name : al) {
Expand All @@ -736,6 +737,7 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
}
AnimationMixer::get_argument_options(p_function, p_idx, r_options);
}
#endif

void AnimationPlayer::_animation_removed(const StringName &p_name, const StringName &p_library) {
AnimationMixer::_animation_removed(p_name, p_library);
Expand Down
2 changes: 2 additions & 0 deletions scene/animation/animation_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ class AnimationPlayer : public AnimationMixer {
double get_current_animation_position() const;
double get_current_animation_length() const;

#ifdef TOOLS_ENABLED
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

virtual void advance(double p_time) override;

Expand Down
4 changes: 3 additions & 1 deletion scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ void Control::set_root_layout_direction(int p_root_dir) {
root_layout_direction = p_root_dir;
}

#ifdef TOOLS_ENABLED
void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
ERR_READ_THREAD_GUARD;
CanvasItem::get_argument_options(p_function, p_idx, r_options);

if (p_idx == 0) {
List<StringName> sn;
String pf = p_function;
const String pf = p_function;
if (pf == "add_theme_color_override" || pf == "has_theme_color" || pf == "has_theme_color_override" || pf == "get_theme_color") {
ThemeDB::get_singleton()->get_default_theme()->get_color_list(get_class(), &sn);
} else if (pf == "add_theme_style_override" || pf == "has_theme_style" || pf == "has_theme_style_override" || pf == "get_theme_style") {
Expand All @@ -228,6 +229,7 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}
}
}
#endif

PackedStringArray Control::get_configuration_warnings() const {
ERR_READ_THREAD_GUARD_V(PackedStringArray());
Expand Down
4 changes: 3 additions & 1 deletion scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ class Control : public CanvasItem {

static void set_root_layout_direction(int p_root_dir);

virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
PackedStringArray get_configuration_warnings() const override;
#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif

virtual bool is_text_field() const;

Expand Down
Loading
Loading