Skip to content

Commit e3d1a26

Browse files
committed
Remove C++ stdlib references
1 parent f555281 commit e3d1a26

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

src/NativeRopeServer.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include <godot_cpp/classes/time.hpp>
88
#include <godot_cpp/classes/engine.hpp>
99
#include <godot_cpp/variant/utility_functions.hpp>
10-
#include <algorithm>
11-
12-
// TODO: Remove std algorithm
1310

1411
using namespace godot;
1512

@@ -66,27 +63,26 @@ void NativeRopeServer::_bind_methods()
6663

6764
void NativeRopeServer::register_rope(Node2D* rope)
6865
{
69-
_ropes.emplace_back(rope);
66+
_ropes.push_back(rope);
7067
_start_stop_process();
7168
// UtilityFunctions::print("Rope registered: " + String::num_int64(_ropes.size()));
7269
}
7370

7471
void NativeRopeServer::unregister_rope(Node2D* rope)
7572
{
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);
8474

85-
// Swap and pop
86-
(*it) = _ropes.back();
75+
if (idx < 0)
76+
{
77+
UtilityFunctions::push_warning("Unregistering non-registered Rope");
78+
return;
8779
}
8880

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+
9086
_start_stop_process();
9187
// UtilityFunctions::print("Rope unregistered: " + String::num_int64(_ropes.size()));
9288
}
@@ -117,7 +113,7 @@ void NativeRopeServer::_start_stop_process()
117113
}
118114

119115
_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);
121117

122118
if (should_run != _is_running)
123119
{

src/NativeRopeServer.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include <godot_cpp/classes/node2d.hpp>
55
#include <godot_cpp/classes/scene_tree.hpp>
6-
#include <vector>
7-
// TODO: Remove std::vector
6+
#include "godot_cpp/templates/vector.hpp"
87

98
namespace godot
109
{
@@ -38,7 +37,7 @@ namespace godot
3837
private:
3938
static NativeRopeServer* _singleton;
4039
SceneTree* _tree;
41-
std::vector<Node2D*> _ropes;
40+
Vector<Node2D*> _ropes;
4241
float _last_time;
4342
bool _update_in_editor;
4443
bool _is_running;

0 commit comments

Comments
 (0)