Skip to content
Open
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
6 changes: 6 additions & 0 deletions core/string/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ bool NodePath::operator==(const NodePath &p_path) const {
return false;
}

if (data->hash_cache_valid && p_path.data->hash_cache_valid) {
if (data->hash_cache != p_path.data->hash_cache) {
return false;
}
}

if (data->absolute != p_path.data->absolute) {
return false;
}
Expand Down
29 changes: 18 additions & 11 deletions core/templates/a_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ class AHashMap {
return nullptr;
}

TValue &get_value_ref_or_add_default(const TKey &p_key, bool &r_was_added) {
uint32_t element_idx = 0;
uint32_t meta_idx = 0;
uint32_t hash = _hash(p_key);
bool exists = _lookup_idx_with_hash(p_key, element_idx, meta_idx, hash);

if (exists) {
r_was_added = false;
return _elements[element_idx].value;
} else {
r_was_added = true;
element_idx = _insert_element(p_key, TValue(), hash);
return _elements[element_idx].value;
}
}

bool has(const TKey &p_key) const {
uint32_t _idx = 0;
uint32_t meta_idx = 0;
Expand Down Expand Up @@ -592,17 +608,8 @@ class AHashMap {
}

TValue &operator[](const TKey &p_key) {
uint32_t element_idx = 0;
uint32_t meta_idx = 0;
uint32_t hash = _hash(p_key);
bool exists = _lookup_idx_with_hash(p_key, element_idx, meta_idx, hash);

if (exists) {
return _elements[element_idx].value;
} else {
element_idx = _insert_element(p_key, TValue(), hash);
return _elements[element_idx].value;
}
bool dummy;
return get_value_ref_or_add_default(p_key, dummy);
}

/* Insert */
Expand Down
4 changes: 2 additions & 2 deletions editor/animation/animation_blend_space_1d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
animations_to_add.clear();

LocalVector<StringName> classes;
ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
ClassDB::get_inheriters_from_class(SNAME("AnimationRootNode"), classes);
classes.sort_custom<StringName::AlphCompare>();

menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);

List<StringName> names;
LocalVector<StringName> names;
tree->get_animation_list(&names);

for (const StringName &E : names) {
Expand Down
2 changes: 1 addition & 1 deletion editor/animation/animation_blend_space_1d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {

PopupMenu *menu = nullptr;
PopupMenu *animations_menu = nullptr;
Vector<String> animations_to_add;
Vector<StringName> animations_to_add;
float add_point_pos = 0.0f;
Vector<real_t> points;

Expand Down
2 changes: 1 addition & 1 deletion editor/animation/animation_blend_space_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven

menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);

List<StringName> names;
LocalVector<StringName> names;
tree->get_animation_list(&names);
for (const StringName &E : names) {
animations_menu->add_icon_item(get_editor_theme_icon(SNAME("Animation")), E);
Expand Down
2 changes: 1 addition & 1 deletion editor/animation/animation_blend_space_2d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {

PopupMenu *menu = nullptr;
PopupMenu *animations_menu = nullptr;
Vector<String> animations_to_add;
Vector<StringName> animations_to_add;
Vector2 add_point_pos;
Vector<Vector2> points;

Expand Down
68 changes: 41 additions & 27 deletions editor/animation/animation_blend_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ void AnimationNodeBlendTreeEditor::update_graph() {
if (updating || blend_tree.is_null()) {
return;
}
if (graph_update_queued) {
return;
}
graph_update_queued = true;
// Defer to idle time, so multiple requests can be merged.
callable_mp(this, &AnimationNodeBlendTreeEditor::update_graph_immediately).call_deferred();
}

void AnimationNodeBlendTreeEditor::update_graph_immediately() {
if (updating || blend_tree.is_null()) {
return;
}

AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
if (!tree) {
Expand Down Expand Up @@ -174,8 +186,8 @@ void AnimationNodeBlendTreeEditor::update_graph() {
name->set_custom_minimum_size(Vector2(100, 0) * EDSCALE);
node->add_child(name);
node->set_slot(0, false, 0, Color(), true, read_only ? -1 : 0, get_theme_color(SceneStringName(font_color), SNAME("Label")));
name->connect(SceneStringName(text_submitted), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed).bind(agnode), CONNECT_DEFERRED);
name->connect(SceneStringName(focus_exited), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out).bind(agnode), CONNECT_DEFERRED);
name->connect(SceneStringName(text_submitted), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed).bind(agnode, E), CONNECT_DEFERRED);
name->connect(SceneStringName(focus_exited), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out).bind(agnode, E), CONNECT_DEFERRED);
name->connect(SceneStringName(text_changed), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_rename_lineedit_changed), CONNECT_DEFERRED);
base = 1;
agnode->set_deletable(true);
Expand All @@ -198,7 +210,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {
node->set_slot(base + i, true, read_only ? -1 : 0, get_theme_color(SceneStringName(font_color), SNAME("Label")), false, 0, Color());
}

List<PropertyInfo> pinfo;
LocalVector<PropertyInfo> pinfo;
agnode->get_parameter_list(&pinfo);
for (const PropertyInfo &F : pinfo) {
if (!(F.usage & PROPERTY_USAGE_EDITOR)) {
Expand All @@ -218,7 +230,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {
}
prop->set_name_split_ratio(ratio);
prop->update_property();
prop->connect("property_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_property_changed));
prop->connect(SNAME("property_changed"), callable_mp(this, &AnimationNodeBlendTreeEditor::_property_changed));

if (F.hint == PROPERTY_HINT_RESOURCE_TYPE) {
// Give the resource editor some more space to make the inside readable.
Expand All @@ -232,7 +244,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {
}
}

node->connect("dragged", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged).bind(E));
node->connect(SNAME("dragged"), callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged).bind(E));

if (AnimationTreeEditor::get_singleton()->can_edit(agnode)) {
node->add_child(memnew(HSeparator));
Expand Down Expand Up @@ -272,7 +284,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {

ProgressBar *pb = memnew(ProgressBar);

List<StringName> anims;
LocalVector<StringName> anims;
tree->get_animation_list(&anims);

for (const StringName &F : anims) {
Expand All @@ -285,25 +297,25 @@ void AnimationNodeBlendTreeEditor::update_graph() {
animations[E] = pb;
node->add_child(pb);

mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected).bind(options, E), CONNECT_DEFERRED);
mb->get_popup()->connect(SNAME("index_pressed"), callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected).bind(options, E), CONNECT_DEFERRED);
}

Ref<StyleBox> sb_panel = node->get_theme_stylebox(SceneStringName(panel), "GraphNode")->duplicate();
Ref<StyleBox> sb_panel = node->get_theme_stylebox(SceneStringName(panel), SNAME("GraphNode"))->duplicate();
if (sb_panel.is_valid()) {
sb_panel->set_content_margin(SIDE_TOP, 12 * EDSCALE);
sb_panel->set_content_margin(SIDE_BOTTOM, 12 * EDSCALE);
node->add_theme_style_override(SceneStringName(panel), sb_panel);
}

node->add_theme_constant_override("separation", 4 * EDSCALE);
node->add_theme_constant_override(SNAME("separation"), 4 * EDSCALE);
}

List<AnimationNodeBlendTree::NodeConnection> node_connections;
blend_tree->get_node_connections(&node_connections);

for (const AnimationNodeBlendTree::NodeConnection &E : node_connections) {
StringName from = E.output_node;
StringName to = E.input_node;
const StringName &from = E.output_node;
const StringName &to = E.input_node;
int to_idx = E.input_index;

graph->connect_node(from, 0, to, to_idx);
Expand All @@ -324,6 +336,8 @@ void AnimationNodeBlendTreeEditor::update_graph() {
}
}
}

graph_update_queued = false;
}

void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) {
Expand Down Expand Up @@ -795,16 +809,16 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano

updating = true;

HashSet<String> paths;
HashMap<String, RBSet<String>> types;
HashSet<NodePath> paths;
HashMap<NodePath, RBSet<String>> types;
{
List<StringName> animation_list;
LocalVector<StringName> animation_list;
tree->get_animation_list(&animation_list);

for (const StringName &E : animation_list) {
Ref<Animation> anim = tree->get_animation(E);
for (int i = 0; i < anim->get_track_count(); i++) {
String track_path = String(anim->track_get_path(i));
NodePath track_path = anim->track_get_path(i);
paths.insert(track_path);

String track_type_name;
Expand Down Expand Up @@ -835,8 +849,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano

HashMap<String, TreeItem *> parenthood;

for (const String &E : paths) {
NodePath path = E;
for (const NodePath &path : paths) {
TreeItem *ti = nullptr;
String accum;
for (int i = 0; i < path.get_name_count(); i++) {
Expand All @@ -856,8 +869,8 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
ti->set_selectable(0, false);
ti->set_editable(0, false);

if (base->has_node(accum)) {
Node *node = base->get_node(accum);
Node *node = base->get_node_or_null(accum);
if (node) {
ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node));
}

Expand All @@ -866,10 +879,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
}
}

Node *node = nullptr;
if (base->has_node(accum)) {
node = base->get_node(accum);
}
Node *node = base->get_node_or_null(accum);
if (!node) {
continue; //no node, can't edit
}
Expand Down Expand Up @@ -1007,6 +1017,10 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) {
return; // Node has been changed.
}

if (graph_update_queued) {
return;
}

String error;

error = tree->get_editor_error_message();
Expand Down Expand Up @@ -1094,7 +1108,7 @@ void AnimationNodeBlendTreeEditor::_node_changed(const StringName &p_node_name)
update_graph();
}

void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) {
void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node, const StringName p_name) {
if (blend_tree.is_null()) {
return;
}
Expand All @@ -1104,7 +1118,7 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
return;
}

String prev_name = blend_tree->get_node_name(p_node);
String prev_name = p_name;
ERR_FAIL_COND(prev_name.is_empty());
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name));
ERR_FAIL_NULL(gn);
Expand Down Expand Up @@ -1175,11 +1189,11 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima
current_node_rename_text = String();
}

void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Ref<AnimationNode> p_node) {
void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Ref<AnimationNode> p_node, const StringName p_name) {
if (current_node_rename_text.is_empty()) {
return; // The text_submitted signal triggered the graph update and freed the LineEdit.
}
_node_renamed(current_node_rename_text, p_node);
_node_renamed(current_node_rename_text, p_node, p_name);
}

void AnimationNodeBlendTreeEditor::_node_rename_lineedit_changed(const String &p_text) {
Expand Down
6 changes: 4 additions & 2 deletions editor/animation/animation_blend_tree_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
static AnimationNodeBlendTreeEditor *singleton;

void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
void _node_renamed_focus_out(Ref<AnimationNode> p_node);
void _node_renamed(const String &p_text, Ref<AnimationNode> p_node, StringName p_name);
void _node_renamed_focus_out(Ref<AnimationNode> p_node, StringName p_name);
Comment on lines +101 to +102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void _node_renamed(const String &p_text, Ref<AnimationNode> p_node, StringName p_name);
void _node_renamed_focus_out(Ref<AnimationNode> p_node, StringName p_name);
void _node_renamed(const String &p_text, Ref<AnimationNode> p_node, const StringName &p_name);
void _node_renamed_focus_out(Ref<AnimationNode> p_node, const StringName &p_name);

void _node_rename_lineedit_changed(const String &p_text);
void _node_changed(const StringName &p_node_name);

String current_node_rename_text;
bool graph_update_queued;
bool updating;

void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
Expand Down Expand Up @@ -167,6 +168,7 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
virtual void edit(const Ref<AnimationNode> &p_node) override;

void update_graph();
void update_graph_immediately();

AnimationNodeBlendTreeEditor();
};
Expand Down
6 changes: 3 additions & 3 deletions editor/animation/animation_library_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void AnimationLibraryEditor::_load_files(const PackedStringArray &p_paths) {
continue;
}

List<StringName> libs;
LocalVector<StringName> libs;
mixer->get_animation_library_list(&libs);
bool is_already_added = false;
for (const StringName &K : libs) {
Expand Down Expand Up @@ -684,7 +684,7 @@ void AnimationLibraryEditor::update_tree() {
Color ss_color = get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor));

TreeItem *root = tree->create_item();
List<StringName> libs;
LocalVector<StringName> libs;
Vector<uint64_t> collapsed_lib_ids = _load_mixer_libs_folding();

mixer->get_animation_library_list(&libs);
Expand Down Expand Up @@ -951,7 +951,7 @@ String AnimationLibraryEditor::_get_mixer_signature() const {
String signature = String();

// Get all libraries sorted for consistency
List<StringName> libs;
LocalVector<StringName> libs;
mixer->get_animation_library_list(&libs);
libs.sort_custom<StringName::AlphCompare>();

Expand Down
10 changes: 5 additions & 5 deletions editor/animation/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ void AnimationPlayerEditor::_update_animation_blend() {

blend_editor.tree->clear();

String current = animation->get_item_text(animation->get_selected());
StringName current = animation->get_item_text(animation->get_selected());

List<StringName> anims;
LocalVector<StringName> anims;
player->get_animation_list(&anims);
TreeItem *root = blend_editor.tree->create_item();
updating_blends = true;
Expand Down Expand Up @@ -1020,7 +1020,7 @@ void AnimationPlayerEditor::_update_player() {
return;
}

List<StringName> libraries;
LocalVector<StringName> libraries;
player->get_animation_library_list(&libraries);

int active_idx = -1;
Expand Down Expand Up @@ -1144,7 +1144,7 @@ void AnimationPlayerEditor::_update_name_dialog_library_dropdown() {
}
}

List<StringName> libraries;
LocalVector<StringName> libraries;
player->get_animation_library_list(&libraries);
library->clear();

Expand Down Expand Up @@ -1478,7 +1478,7 @@ void AnimationPlayerEditor::_current_animation_changed(const StringName &p_name)
}

// Determine the read-only status of the animation's library and the libraries as a whole.
List<StringName> libraries;
LocalVector<StringName> libraries;
player->get_animation_library_list(&libraries);

bool current_animation_library_is_readonly = false;
Expand Down
Loading