Data structure optimizations as per review.
This commit is contained in:
parent
b05cb0fd7d
commit
2d2855cd53
2 changed files with 9 additions and 3 deletions
|
@ -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 };
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue