|
7 | 7 | #include <godot_cpp/classes/time.hpp> |
8 | 8 | #include <godot_cpp/classes/engine.hpp> |
9 | 9 | #include <godot_cpp/variant/utility_functions.hpp> |
10 | | -#include <algorithm> |
11 | | - |
12 | | -// TODO: Remove std algorithm |
13 | 10 |
|
14 | 11 | using namespace godot; |
15 | 12 |
|
@@ -66,27 +63,26 @@ void NativeRopeServer::_bind_methods() |
66 | 63 |
|
67 | 64 | void NativeRopeServer::register_rope(Node2D* rope) |
68 | 65 | { |
69 | | - _ropes.emplace_back(rope); |
| 66 | + _ropes.push_back(rope); |
70 | 67 | _start_stop_process(); |
71 | 68 | // UtilityFunctions::print("Rope registered: " + String::num_int64(_ropes.size())); |
72 | 69 | } |
73 | 70 |
|
74 | 71 | void NativeRopeServer::unregister_rope(Node2D* rope) |
75 | 72 | { |
76 | | - if (_ropes.empty() || rope != _ropes.back()) |
77 | | - { |
78 | | - auto it = std::find(_ropes.begin(), _ropes.end(), rope); |
79 | | - if (it == _ropes.end()) |
80 | | - { |
81 | | - UtilityFunctions::push_warning("Unregistering non-registered Rope"); |
82 | | - return; |
83 | | - } |
| 73 | + const int idx = _ropes.find(rope); |
84 | 74 |
|
85 | | - // Swap and pop |
86 | | - (*it) = _ropes.back(); |
| 75 | + if (idx < 0) |
| 76 | + { |
| 77 | + UtilityFunctions::push_warning("Unregistering non-registered Rope"); |
| 78 | + return; |
87 | 79 | } |
88 | 80 |
|
89 | | - _ropes.pop_back(); |
| 81 | + // Swap and pop |
| 82 | + const int last_idx = _ropes.size() - 1; |
| 83 | + _ropes.set(idx, _ropes[last_idx]); |
| 84 | + _ropes.remove_at(last_idx); |
| 85 | + |
90 | 86 | _start_stop_process(); |
91 | 87 | // UtilityFunctions::print("Rope unregistered: " + String::num_int64(_ropes.size())); |
92 | 88 | } |
@@ -117,7 +113,7 @@ void NativeRopeServer::_start_stop_process() |
117 | 113 | } |
118 | 114 |
|
119 | 115 | _last_time = 0.f; |
120 | | - bool should_run = !_ropes.empty() && (!Engine::get_singleton()->is_editor_hint() || _update_in_editor); |
| 116 | + bool should_run = !_ropes.is_empty() && (!Engine::get_singleton()->is_editor_hint() || _update_in_editor); |
121 | 117 |
|
122 | 118 | if (should_run != _is_running) |
123 | 119 | { |
|
0 commit comments