summaryrefslogtreecommitdiff
path: root/scene/multiplayer
diff options
context:
space:
mode:
Diffstat (limited to 'scene/multiplayer')
-rw-r--r--scene/multiplayer/multiplayer_spawner.cpp6
-rw-r--r--scene/multiplayer/scene_cache_interface.cpp6
-rw-r--r--scene/multiplayer/scene_replication_interface.cpp5
-rw-r--r--scene/multiplayer/scene_replication_state.cpp20
-rw-r--r--scene/multiplayer/scene_replication_state.h4
5 files changed, 17 insertions, 24 deletions
diff --git a/scene/multiplayer/multiplayer_spawner.cpp b/scene/multiplayer/multiplayer_spawner.cpp
index 25ab27f3e7..a9b9ffa989 100644
--- a/scene/multiplayer/multiplayer_spawner.cpp
+++ b/scene/multiplayer/multiplayer_spawner.cpp
@@ -91,9 +91,9 @@ void MultiplayerSpawner::_notification(int p_what) {
case NOTIFICATION_EXIT_TREE: {
_update_spawn_node();
- const ObjectID *oid = nullptr;
- while ((oid = tracked_nodes.next(oid))) {
- Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid));
+
+ for (const KeyValue<ObjectID, SpawnInfo> &E : tracked_nodes) {
+ Node *node = Object::cast_to<Node>(ObjectDB::get_instance(E.key));
ERR_CONTINUE(!node);
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &MultiplayerSpawner::_node_exit));
// This is unlikely, but might still crash the engine.
diff --git a/scene/multiplayer/scene_cache_interface.cpp b/scene/multiplayer/scene_cache_interface.cpp
index f05dc5a2da..a933758946 100644
--- a/scene/multiplayer/scene_cache_interface.cpp
+++ b/scene/multiplayer/scene_cache_interface.cpp
@@ -50,10 +50,8 @@ void SceneCacheInterface::on_peer_change(int p_id, bool p_connected) {
path_get_cache.erase(p_id);
// Cleanup sent cache.
// Some refactoring is needed to make this faster and do paths GC.
- List<NodePath> keys;
- path_send_cache.get_key_list(&keys);
- for (const NodePath &E : keys) {
- PathSentCache *psc = path_send_cache.getptr(E);
+ for (const KeyValue<NodePath, PathSentCache> &E : path_send_cache) {
+ PathSentCache *psc = path_send_cache.getptr(E.key);
psc->confirmed_peers.erase(p_id);
}
}
diff --git a/scene/multiplayer/scene_replication_interface.cpp b/scene/multiplayer/scene_replication_interface.cpp
index 2952512462..63259bcd39 100644
--- a/scene/multiplayer/scene_replication_interface.cpp
+++ b/scene/multiplayer/scene_replication_interface.cpp
@@ -49,9 +49,8 @@ void SceneReplicationInterface::make_default() {
void SceneReplicationInterface::_free_remotes(int p_id) {
const HashMap<uint32_t, ObjectID> remotes = rep_state->peer_get_remotes(p_id);
- const uint32_t *k = nullptr;
- while ((k = remotes.next(k))) {
- Node *node = rep_state->get_node(remotes.get(*k));
+ for (const KeyValue<uint32_t, ObjectID> &E : remotes) {
+ Node *node = rep_state->get_node(E.value);
ERR_CONTINUE(!node);
node->queue_delete();
}
diff --git a/scene/multiplayer/scene_replication_state.cpp b/scene/multiplayer/scene_replication_state.cpp
index b8dadeff24..9a9b08b67b 100644
--- a/scene/multiplayer/scene_replication_state.cpp
+++ b/scene/multiplayer/scene_replication_state.cpp
@@ -55,9 +55,8 @@ void SceneReplicationState::_untrack(const ObjectID &p_id) {
}
// If we spawned or synced it, we need to remove it from any peer it was sent to.
if (net_id || peer == 0) {
- const int *k = nullptr;
- while ((k = peers_info.next(k))) {
- peers_info.get(*k).known_nodes.erase(p_id);
+ for (KeyValue<int, PeerInfo> &E : peers_info) {
+ E.value.known_nodes.erase(p_id);
}
}
}
@@ -134,9 +133,8 @@ void SceneReplicationState::reset() {
peers_info.clear();
known_peers.clear();
// Tracked nodes are cleared on deletion, here we only reset the ids so they can be later re-assigned.
- const ObjectID *oid = nullptr;
- while ((oid = tracked_nodes.next(oid))) {
- TrackedNode &tobj = tracked_nodes[*oid];
+ for (KeyValue<ObjectID, TrackedNode> &E : tracked_nodes) {
+ TrackedNode &tobj = E.value;
tobj.net_id = 0;
tobj.remote_peer = 0;
tobj.last_sync = 0;
@@ -195,9 +193,8 @@ Error SceneReplicationState::peer_add_node(int p_peer, const ObjectID &p_id) {
ERR_FAIL_COND_V(!peers_info.has(p_peer), ERR_INVALID_PARAMETER);
peers_info[p_peer].known_nodes.insert(p_id);
} else {
- const int *pid = nullptr;
- while ((pid = peers_info.next(pid))) {
- peers_info.get(*pid).known_nodes.insert(p_id);
+ for (KeyValue<int, PeerInfo> &E : peers_info) {
+ E.value.known_nodes.insert(p_id);
}
}
return OK;
@@ -208,9 +205,8 @@ Error SceneReplicationState::peer_del_node(int p_peer, const ObjectID &p_id) {
ERR_FAIL_COND_V(!peers_info.has(p_peer), ERR_INVALID_PARAMETER);
peers_info[p_peer].known_nodes.erase(p_id);
} else {
- const int *pid = nullptr;
- while ((pid = peers_info.next(pid))) {
- peers_info.get(*pid).known_nodes.erase(p_id);
+ for (KeyValue<int, PeerInfo> &E : peers_info) {
+ E.value.known_nodes.erase(p_id);
}
}
return OK;
diff --git a/scene/multiplayer/scene_replication_state.h b/scene/multiplayer/scene_replication_state.h
index 18e4d9fa39..6ac9265b67 100644
--- a/scene/multiplayer/scene_replication_state.h
+++ b/scene/multiplayer/scene_replication_state.h
@@ -81,8 +81,8 @@ private:
public:
const Set<int> get_peers() const { return known_peers; }
- const Set<ObjectID> get_spawned_nodes() const { return spawned_nodes; }
- const Set<ObjectID> get_path_only_nodes() const { return path_only_nodes; }
+ const Set<ObjectID> &get_spawned_nodes() const { return spawned_nodes; }
+ const Set<ObjectID> &get_path_only_nodes() const { return path_only_nodes; }
MultiplayerSynchronizer *get_synchronizer(const ObjectID &p_id) { return tracked_nodes.has(p_id) ? tracked_nodes[p_id].get_synchronizer() : nullptr; }
MultiplayerSpawner *get_spawner(const ObjectID &p_id) { return tracked_nodes.has(p_id) ? tracked_nodes[p_id].get_spawner() : nullptr; }