diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/multiplayer_replicator.cpp | 8 | ||||
-rw-r--r-- | core/io/multiplayer_replicator.h | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/core/io/multiplayer_replicator.cpp b/core/io/multiplayer_replicator.cpp index 87c3cc4abc..1642aab136 100644 --- a/core/io/multiplayer_replicator.cpp +++ b/core/io/multiplayer_replicator.cpp @@ -341,8 +341,10 @@ void MultiplayerReplicator::process_sync(int p_from, const uint8_t *p_packet, in if (cfg.on_sync_receive.is_valid()) { Array objs; if (tracked_objects.has(id)) { + objs.resize(tracked_objects[id].size()); + int idx = 0; for (const ObjectID &obj_id : tracked_objects[id]) { - objs.push_back(ObjectDB::get_instance(obj_id)); + objs[idx++] = ObjectDB::get_instance(obj_id); } } PackedByteArray pba; @@ -717,8 +719,10 @@ Error MultiplayerReplicator::sync_all(const ResourceUID::ID &p_scene_id, int p_p if (cfg.on_sync_send.is_valid()) { Array objs; if (tracked_objects.has(p_scene_id)) { + objs.resize(tracked_objects[p_scene_id].size()); + int idx = 0; for (const ObjectID &obj_id : tracked_objects[p_scene_id]) { - objs.push_back(ObjectDB::get_instance(obj_id)); + objs[idx++] = ObjectDB::get_instance(obj_id); } } Variant args[3] = { p_scene_id, objs, p_peer }; diff --git a/core/io/multiplayer_replicator.h b/core/io/multiplayer_replicator.h index 6d2618d3df..2630ad7a8a 100644 --- a/core/io/multiplayer_replicator.h +++ b/core/io/multiplayer_replicator.h @@ -32,6 +32,8 @@ #define MULTIPLAYER_REPLICATOR_H #include "core/io/multiplayer_api.h" + +#include "core/templates/hash_map.h" #include "core/variant/typed_array.h" class MultiplayerReplicator : public Object { @@ -70,7 +72,7 @@ private: Vector<uint8_t> packet_cache; Map<ResourceUID::ID, SceneConfig> replications; Map<ObjectID, ResourceUID::ID> replicated_nodes; - Map<ResourceUID::ID, List<ObjectID>> tracked_objects; + HashMap<ResourceUID::ID, List<ObjectID>> tracked_objects; // Encoding Error _get_state(const List<StringName> &p_properties, const Object *p_obj, List<Variant> &r_variant); |