Skip to content

Commit 7adb986

Browse files
committed
Fix orphan strings in AnimationNodeStateMachine
1 parent cf038de commit 7adb986

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

editor/plugins/animation_state_machine_editor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ bool AnimationNodeStateMachineEditor::_create_submenu(PopupMenu *p_menu, Ref<Ani
691691

692692
if (ansm == state_machine) {
693693
end_menu->add_item(E, nodes_to_connect.size());
694-
nodes_to_connect.push_back(AnimationNodeStateMachine::END_NODE);
694+
nodes_to_connect.push_back(SceneStringName(End));
695695
continue;
696696
}
697697

@@ -1241,11 +1241,11 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() {
12411241

12421242
state_machine_draw->draw_style_box(node_style, nr.node);
12431243

1244-
if (!is_selected && AnimationNodeStateMachine::START_NODE == name) {
1244+
if (!is_selected && SceneStringName(Start) == name) {
12451245
Ref<StyleBox> start_style = _adjust_stylebox_opacity(theme_cache.node_frame_start, opacity);
12461246
state_machine_draw->draw_style_box(start_style, nr.node);
12471247
}
1248-
if (!is_selected && AnimationNodeStateMachine::END_NODE == name) {
1248+
if (!is_selected && SceneStringName(End) == name) {
12491249
Ref<StyleBox> end_style = _adjust_stylebox_opacity(theme_cache.node_frame_end, opacity);
12501250
state_machine_draw->draw_style_box(end_style, nr.node);
12511251
}
@@ -1341,7 +1341,7 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw_individual(const S
13411341
return;
13421342
}
13431343

1344-
if (p_name == AnimationNodeStateMachine::START_NODE || p_name == AnimationNodeStateMachine::END_NODE || p_name.is_empty()) {
1344+
if (p_name == SceneStringName(Start) || p_name == SceneStringName(End) || p_name.is_empty()) {
13451345
return;
13461346
}
13471347

@@ -1676,7 +1676,7 @@ void AnimationNodeStateMachineEditor::_erase_selected(const bool p_nested_action
16761676
undo_redo->create_action(TTR("Node Removed"));
16771677

16781678
for (int i = 0; i < node_rects.size(); i++) {
1679-
if (node_rects[i].node_name == AnimationNodeStateMachine::START_NODE || node_rects[i].node_name == AnimationNodeStateMachine::END_NODE) {
1679+
if (node_rects[i].node_name == SceneStringName(Start) || node_rects[i].node_name == SceneStringName(End)) {
16801680
continue;
16811681
}
16821682

@@ -1736,7 +1736,7 @@ void AnimationNodeStateMachineEditor::_update_mode() {
17361736
if (tool_select->is_pressed()) {
17371737
selection_tools_hb->show();
17381738
bool nothing_selected = selected_nodes.is_empty() && selected_transition_from == StringName() && selected_transition_to == StringName();
1739-
bool start_end_selected = selected_nodes.size() == 1 && (*selected_nodes.begin() == AnimationNodeStateMachine::START_NODE || *selected_nodes.begin() == AnimationNodeStateMachine::END_NODE);
1739+
bool start_end_selected = selected_nodes.size() == 1 && (*selected_nodes.begin() == SceneStringName(Start) || *selected_nodes.begin() == SceneStringName(End));
17401740
tool_erase->set_disabled(nothing_selected || start_end_selected || read_only);
17411741
} else {
17421742
selection_tools_hb->hide();

scene/animation/animation_node_state_machine.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
#include "animation_node_state_machine.h"
3232
#include "scene/main/window.h"
3333

34-
StringName AnimationNodeStateMachine::START_NODE;
35-
StringName AnimationNodeStateMachine::END_NODE;
36-
3734
/////////////////////////////////////////////////
3835

3936
void AnimationNodeStateMachineTransition::set_switch_mode(SwitchMode p_mode) {
@@ -229,9 +226,9 @@ void AnimationNodeStateMachinePlayback::_set_current(AnimationNodeStateMachine *
229226

230227
// Validation.
231228
if (anodesm->get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
232-
indices = anodesm->find_transition_from(AnimationNodeStateMachine::START_NODE);
229+
indices = anodesm->find_transition_from(SceneStringName(Start));
233230
int anodesm_start_size = indices.size();
234-
indices = anodesm->find_transition_to(AnimationNodeStateMachine::END_NODE);
231+
indices = anodesm->find_transition_to(SceneStringName(End));
235232
int anodesm_end_size = indices.size();
236233
if (group_start_size > 1) {
237234
WARN_PRINT_ED("There are two or more transitions to the Grouped AnimationNodeStateMachine in AnimationNodeStateMachine: " + base_path + ", which may result in unintended transitions.");
@@ -307,7 +304,7 @@ bool AnimationNodeStateMachinePlayback::is_playing() const {
307304
}
308305

309306
bool AnimationNodeStateMachinePlayback::is_end() const {
310-
return current == AnimationNodeStateMachine::END_NODE && fading_from == StringName();
307+
return current == SceneStringName(End) && fading_from == StringName();
311308
}
312309

313310
StringName AnimationNodeStateMachinePlayback::get_current_node() const {
@@ -447,7 +444,7 @@ bool AnimationNodeStateMachinePlayback::_travel_children(AnimationTree *p_tree,
447444
if (p_test_only) {
448445
child_playback = child_playback->duplicate();
449446
}
450-
child_playback->_travel_main(AnimationNodeStateMachine::END_NODE);
447+
child_playback->_travel_main(SceneStringName(End));
451448
child_found_route &= child_playback->_travel(p_tree, child_anodesm.ptr(), false, p_test_only);
452449
child_path += "/" + child_playback->get_current_node();
453450
}
@@ -490,7 +487,7 @@ bool AnimationNodeStateMachinePlayback::_travel_children(AnimationTree *p_tree,
490487

491488
void AnimationNodeStateMachinePlayback::_start(AnimationNodeStateMachine *p_state_machine) {
492489
playing = true;
493-
_set_current(p_state_machine, start_request != StringName() ? start_request : AnimationNodeStateMachine::START_NODE);
490+
_set_current(p_state_machine, start_request != StringName() ? start_request : SceneStringName(Start));
494491
teleport_request = true;
495492
stop_request = false;
496493
start_request = StringName();
@@ -507,7 +504,7 @@ String AnimationNodeStateMachinePlayback::_validate_path(AnimationNodeStateMachi
507504
String target = p_path;
508505
Ref<AnimationNodeStateMachine> anodesm = p_state_machine->find_node_by_path(target);
509506
while (anodesm.is_valid() && anodesm->get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
510-
Vector<int> indices = anodesm->find_transition_from(AnimationNodeStateMachine::START_NODE);
507+
Vector<int> indices = anodesm->find_transition_from(SceneStringName(Start));
511508
if (indices.size()) {
512509
target = target + "/" + anodesm->get_transition_to(indices[0]); // Find next state of Start.
513510
} else {
@@ -660,7 +657,7 @@ bool AnimationNodeStateMachinePlayback::_make_travel_path(AnimationTree *p_tree,
660657
if (i >= new_path.size()) {
661658
break; // Tracing has been finished, needs to break.
662659
}
663-
playback->_travel_main(AnimationNodeStateMachine::END_NODE);
660+
playback->_travel_main(SceneStringName(End));
664661
if (!playback->_travel(p_tree, anodesm.ptr(), false, p_test_only)) {
665662
found_route = false;
666663
break;
@@ -818,8 +815,8 @@ AnimationNode::NodeTimeInfo AnimationNodeStateMachinePlayback::_process(const St
818815
bool is_start_of_group = false;
819816
bool is_end_of_group = false;
820817
if (!p_state_machine->are_ends_reset() || p_state_machine->get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
821-
is_start_of_group = fading_from == AnimationNodeStateMachine::START_NODE;
822-
is_end_of_group = current == AnimationNodeStateMachine::END_NODE;
818+
is_start_of_group = fading_from == SceneStringName(Start);
819+
is_end_of_group = current == SceneStringName(End);
823820
}
824821

825822
// Calc blend amount by cross-fade.
@@ -881,7 +878,7 @@ AnimationNode::NodeTimeInfo AnimationNodeStateMachinePlayback::_process(const St
881878
}
882879

883880
// Find next and see when to transition.
884-
bool will_end = _transition_to_next_recursive(tree, p_state_machine, p_delta, p_test_only) || current == AnimationNodeStateMachine::END_NODE;
881+
bool will_end = _transition_to_next_recursive(tree, p_state_machine, p_delta, p_test_only) || current == SceneStringName(End);
885882

886883
// Predict remaining time.
887884
if (will_end || ((p_state_machine->get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_NESTED) && !p_state_machine->has_transition_from(current))) {
@@ -951,7 +948,7 @@ bool AnimationNodeStateMachinePlayback::_transition_to_next_recursive(AnimationT
951948
_set_current(p_state_machine, next.node);
952949
current_curve = next.curve;
953950

954-
if (current == AnimationNodeStateMachine::END_NODE) {
951+
if (current == SceneStringName(End)) {
955952
break;
956953
}
957954

@@ -981,7 +978,7 @@ bool AnimationNodeStateMachinePlayback::_transition_to_next_recursive(AnimationT
981978
}
982979
}
983980

984-
return next.node == AnimationNodeStateMachine::END_NODE;
981+
return next.node == SceneStringName(End);
985982
}
986983

987984
bool AnimationNodeStateMachinePlayback::_can_transition_to_next(AnimationTree *p_tree, AnimationNodeStateMachine *p_state_machine, NextInfo p_next, bool p_test_only) {
@@ -1015,7 +1012,7 @@ bool AnimationNodeStateMachinePlayback::_can_transition_to_next(AnimationTree *p
10151012
return false;
10161013
}
10171014

1018-
if (current != AnimationNodeStateMachine::START_NODE && p_next.switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END) {
1015+
if (current != SceneStringName(Start) && p_next.switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END) {
10191016
return Animation::is_less_or_equal_approx(current_nti.get_remain(p_next.break_loop_at_end), p_next.xfade);
10201017
}
10211018
return true;
@@ -1025,13 +1022,13 @@ Ref<AnimationNodeStateMachineTransition> AnimationNodeStateMachinePlayback::_che
10251022
Ref<AnimationNodeStateMachineTransition> temp_transition;
10261023
Ref<AnimationNodeStateMachinePlayback> parent_playback;
10271024
if (r_state_machine->get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
1028-
if (p_transition.from == AnimationNodeStateMachine::START_NODE) {
1025+
if (p_transition.from == SceneStringName(Start)) {
10291026
parent_playback = _get_parent_playback(p_tree);
10301027
if (parent_playback.is_valid()) {
10311028
r_bypass = true;
10321029
temp_transition = parent_playback->_get_group_start_transition();
10331030
}
1034-
} else if (p_transition.to == AnimationNodeStateMachine::END_NODE) {
1031+
} else if (p_transition.to == SceneStringName(End)) {
10351032
parent_playback = _get_parent_playback(p_tree);
10361033
if (parent_playback.is_valid()) {
10371034
temp_transition = parent_playback->_get_group_end_transition();
@@ -1518,7 +1515,7 @@ void AnimationNodeStateMachine::add_transition(const StringName &p_from, const S
15181515
return;
15191516
}
15201517

1521-
ERR_FAIL_COND(p_from == END_NODE || p_to == START_NODE);
1518+
ERR_FAIL_COND(p_from == SceneStringName(End) || p_to == SceneStringName(Start));
15221519
ERR_FAIL_COND(p_from == p_to);
15231520
ERR_FAIL_COND(!_can_connect(p_from));
15241521
ERR_FAIL_COND(!_can_connect(p_to));
@@ -1560,7 +1557,7 @@ StringName AnimationNodeStateMachine::get_transition_to(int p_transition) const
15601557
bool AnimationNodeStateMachine::is_transition_across_group(int p_transition) const {
15611558
ERR_FAIL_INDEX_V(p_transition, transitions.size(), false);
15621559
if (get_state_machine_type() == AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
1563-
if (transitions[p_transition].from == START_NODE || transitions[p_transition].to == END_NODE) {
1560+
if (transitions[p_transition].from == SceneStringName(Start) || transitions[p_transition].to == SceneStringName(End)) {
15641561
return true;
15651562
}
15661563
}
@@ -1745,14 +1742,14 @@ void AnimationNodeStateMachine::reset_state() {
17451742
State start;
17461743
start.node = s;
17471744
start.position = Vector2(200, 100);
1748-
states[START_NODE] = start;
1745+
states[SceneStringName(Start)] = start;
17491746

17501747
Ref<AnimationNodeEndState> e;
17511748
e.instantiate();
17521749
State end;
17531750
end.node = e;
17541751
end.position = Vector2(900, 100);
1755-
states[END_NODE] = end;
1752+
states[SceneStringName(End)] = end;
17561753

17571754
emit_changed();
17581755
emit_signal(SNAME("tree_changed"));
@@ -1862,20 +1859,17 @@ Vector<StringName> AnimationNodeStateMachine::get_nodes_with_transitions_to(cons
18621859
}
18631860

18641861
AnimationNodeStateMachine::AnimationNodeStateMachine() {
1865-
START_NODE = "Start";
1866-
END_NODE = "End";
1867-
18681862
Ref<AnimationNodeStartState> s;
18691863
s.instantiate();
18701864
State start;
18711865
start.node = s;
18721866
start.position = Vector2(200, 100);
1873-
states[START_NODE] = start;
1867+
states[SceneStringName(Start)] = start;
18741868

18751869
Ref<AnimationNodeEndState> e;
18761870
e.instantiate();
18771871
State end;
18781872
end.node = e;
18791873
end.position = Vector2(900, 100);
1880-
states[END_NODE] = end;
1874+
states[SceneStringName(End)] = end;
18811875
}

scene/animation/animation_node_state_machine.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ class AnimationNodeStateMachine : public AnimationRootNode {
110110
GDCLASS(AnimationNodeStateMachine, AnimationRootNode);
111111

112112
public:
113-
static StringName START_NODE;
114-
static StringName END_NODE;
115-
116113
enum StateMachineType {
117114
STATE_MACHINE_TYPE_ROOT,
118115
STATE_MACHINE_TYPE_NESTED,

scene/scene_string_names.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class SceneStringNames {
151151
const StringName text_submitted = StaticCString::create("text_submitted");
152152
const StringName value_changed = StaticCString::create("value_changed");
153153

154+
const StringName Start = StaticCString::create("Start");
155+
const StringName End = StaticCString::create("End");
156+
154157
const StringName FlatButton = StaticCString::create("FlatButton");
155158
};
156159

0 commit comments

Comments
 (0)