Skip to content

Commit e56ce98

Browse files
committed
Exposes a function to check if the object is simulated or not.
1 parent 15a056a commit e56ce98

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

godot4/gd_scene_synchronizer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,20 @@ int GdSceneSynchronizer::get_peer_latency(int p_peer) const {
614614
return scene_synchronizer.get_peer_latency(p_peer);
615615
}
616616

617+
bool GdSceneSynchronizer::client_is_object_simulating(Node *p_node) const {
618+
return client_is_object_simulating(scene_synchronizer.find_object_local_id(scene_synchronizer.to_handle(p_node)));
619+
}
620+
621+
bool GdSceneSynchronizer::client_is_object_simulating(NS::ObjectLocalId p_id) const {
622+
return scene_synchronizer.client_is_simulated_object(p_id);
623+
}
624+
625+
bool GdSceneSynchronizer::client_is_object_simulating(NS::ObjectNetId p_id) const {
626+
const NS::ObjectData *od = scene_synchronizer.get_object_data(p_id);
627+
ENSURE_V(od, false);
628+
return client_is_object_simulating(od->get_net_id());
629+
}
630+
617631
Array GdSceneSynchronizer::local_controller_get_controlled_nodes() const {
618632
Array a;
619633

godot4/gd_scene_synchronizer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ class GdSceneSynchronizer : public Node, public NS::SynchronizerManager {
142142

143143
int get_peer_latency(int p_peer) const;
144144

145+
bool client_is_object_simulating(Node *p_node) const;
146+
bool client_is_object_simulating(NS::ObjectLocalId p_id) const;
147+
bool client_is_object_simulating(NS::ObjectNetId p_id) const;
148+
145149
/// Creates a realtime sync group containing a list of nodes.
146150
/// The Peers listening to this group will receive the updates only
147151
/// from the nodes within this group.

scene_synchronizer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,13 @@ const std::vector<ObjectNetId> *SceneSynchronizerBase::client_get_simulated_obje
13291329
return &(static_cast<ClientSynchronizer *>(synchronizer)->simulated_objects);
13301330
}
13311331

1332+
bool SceneSynchronizerBase::client_is_simulated_object(ObjectLocalId p_id) const {
1333+
ENSURE_V_MSG(is_client(), false, "This function CAN be used only on the client.");
1334+
const ObjectData *od = get_object_data(p_id, true);
1335+
ENSURE_V(od, false);
1336+
return od->realtime_sync_enabled_on_client;
1337+
}
1338+
13321339
void SceneSynchronizerBase::drop_object_data(NS::ObjectData &p_object_data) {
13331340
synchronizer_manager->on_drop_object_data(p_object_data);
13341341

scene_synchronizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ class SceneSynchronizerBase {
499499
void change_events_flush();
500500

501501
const std::vector<ObjectNetId> *client_get_simulated_objects() const;
502+
bool client_is_simulated_object(ObjectLocalId p_id) const;
502503

503504
public: // ------------------------------------------------------------ INTERNAL
504505
void update_objects_relevancy();

0 commit comments

Comments
 (0)