[MP] Optimize internal SceneReplicationConfig access
Use direct pointer addressing to avoid unnecessary refs/unrefs
This commit is contained in:
parent
311a27281f
commit
5df7577a05
4 changed files with 15 additions and 10 deletions
|
@ -239,8 +239,8 @@ void MultiplayerDebugger::RPCProfiler::tick(double p_frame_time, double p_proces
|
|||
MultiplayerDebugger::SyncInfo::SyncInfo(MultiplayerSynchronizer *p_sync) {
|
||||
ERR_FAIL_NULL(p_sync);
|
||||
synchronizer = p_sync->get_instance_id();
|
||||
if (p_sync->get_replication_config().is_valid()) {
|
||||
config = p_sync->get_replication_config()->get_instance_id();
|
||||
if (p_sync->get_replication_config_ptr()) {
|
||||
config = p_sync->get_replication_config_ptr()->get_instance_id();
|
||||
}
|
||||
if (p_sync->get_root_node()) {
|
||||
root_node = p_sync->get_root_node()->get_instance_id();
|
||||
|
|
|
@ -441,6 +441,10 @@ List<NodePath> MultiplayerSynchronizer::get_delta_properties(uint64_t p_indexes)
|
|||
return out;
|
||||
}
|
||||
|
||||
SceneReplicationConfig *MultiplayerSynchronizer::get_replication_config_ptr() const {
|
||||
return replication_config.ptr();
|
||||
}
|
||||
|
||||
MultiplayerSynchronizer::MultiplayerSynchronizer() {
|
||||
// Publicly visible by default.
|
||||
peer_visibility.insert(0);
|
||||
|
|
|
@ -118,6 +118,7 @@ public:
|
|||
|
||||
List<Variant> get_delta_state(uint64_t p_cur_usec, uint64_t p_last_usec, uint64_t &r_indexes);
|
||||
List<NodePath> get_delta_properties(uint64_t p_indexes);
|
||||
SceneReplicationConfig *get_replication_config_ptr() const;
|
||||
|
||||
MultiplayerSynchronizer();
|
||||
};
|
||||
|
|
|
@ -252,9 +252,9 @@ Error SceneReplicationInterface::on_replication_start(Object *p_obj, Variant p_c
|
|||
|
||||
// Try to apply spawn state (before ready).
|
||||
if (pending_buffer_size > 0) {
|
||||
ERR_FAIL_COND_V(!node || sync->get_replication_config().is_null(), ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(!node || !sync->get_replication_config_ptr(), ERR_UNCONFIGURED);
|
||||
int consumed = 0;
|
||||
const List<NodePath> props = sync->get_replication_config()->get_spawn_properties();
|
||||
const List<NodePath> props = sync->get_replication_config_ptr()->get_spawn_properties();
|
||||
Vector<Variant> vars;
|
||||
vars.resize(props.size());
|
||||
Error err = MultiplayerAPI::decode_and_decompress_variants(vars, pending_buffer, pending_buffer_size, consumed);
|
||||
|
@ -498,8 +498,8 @@ Error SceneReplicationInterface::_make_spawn_packet(Node *p_node, MultiplayerSpa
|
|||
continue;
|
||||
}
|
||||
ERR_CONTINUE(!sync);
|
||||
ERR_FAIL_COND_V(sync->get_replication_config().is_null(), ERR_BUG);
|
||||
for (const NodePath &prop : sync->get_replication_config()->get_spawn_properties()) {
|
||||
ERR_FAIL_NULL_V(sync->get_replication_config_ptr(), ERR_BUG);
|
||||
for (const NodePath &prop : sync->get_replication_config_ptr()->get_spawn_properties()) {
|
||||
state_props.push_back(prop);
|
||||
}
|
||||
// Ensure the synchronizer has an ID.
|
||||
|
@ -714,7 +714,7 @@ void SceneReplicationInterface::_send_delta(int p_peer, const HashSet<ObjectID>
|
|||
int ofs = 1;
|
||||
for (const ObjectID &oid : p_synchronizers) {
|
||||
MultiplayerSynchronizer *sync = get_id_as<MultiplayerSynchronizer>(oid);
|
||||
ERR_CONTINUE(!sync || !sync->get_replication_config().is_valid() || !_has_authority(sync));
|
||||
ERR_CONTINUE(!sync || !sync->get_replication_config_ptr() || !_has_authority(sync));
|
||||
uint32_t net_id;
|
||||
if (!_verify_synchronizer(p_peer, sync, net_id)) {
|
||||
continue;
|
||||
|
@ -809,7 +809,7 @@ void SceneReplicationInterface::_send_sync(int p_peer, const HashSet<ObjectID> p
|
|||
// This is a lazy implementation, we could optimize much more here with by grouping by replication config.
|
||||
for (const ObjectID &oid : p_synchronizers) {
|
||||
MultiplayerSynchronizer *sync = get_id_as<MultiplayerSynchronizer>(oid);
|
||||
ERR_CONTINUE(!sync || !sync->get_replication_config().is_valid() || !_has_authority(sync));
|
||||
ERR_CONTINUE(!sync || !sync->get_replication_config_ptr() || !_has_authority(sync));
|
||||
if (!sync->update_outbound_sync_time(p_usec)) {
|
||||
continue; // nothing to sync.
|
||||
}
|
||||
|
@ -824,7 +824,7 @@ void SceneReplicationInterface::_send_sync(int p_peer, const HashSet<ObjectID> p
|
|||
int size;
|
||||
Vector<Variant> vars;
|
||||
Vector<const Variant *> varp;
|
||||
const List<NodePath> props = sync->get_replication_config()->get_sync_properties();
|
||||
const List<NodePath> props = sync->get_replication_config_ptr()->get_sync_properties();
|
||||
Error err = MultiplayerSynchronizer::get_state(props, node, vars, varp);
|
||||
ERR_CONTINUE_MSG(err != OK, "Unable to retrieve sync state.");
|
||||
err = MultiplayerAPI::encode_and_compress_variants(varp.ptrw(), varp.size(), nullptr, size);
|
||||
|
@ -883,7 +883,7 @@ Error SceneReplicationInterface::on_sync_receive(int p_from, const uint8_t *p_bu
|
|||
ofs += size;
|
||||
continue;
|
||||
}
|
||||
const List<NodePath> props = sync->get_replication_config()->get_sync_properties();
|
||||
const List<NodePath> props = sync->get_replication_config_ptr()->get_sync_properties();
|
||||
Vector<Variant> vars;
|
||||
vars.resize(props.size());
|
||||
int consumed;
|
||||
|
|
Loading…
Reference in a new issue