From 51546db8f202c97c2737b2f4a9e8f7769cbaeb30 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 19 Aug 2024 11:57:40 +0200 Subject: [PATCH] Sync multiple children --- NetworkSync.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/NetworkSync.cpp b/NetworkSync.cpp index 54648f2..ac7b851 100644 --- a/NetworkSync.cpp +++ b/NetworkSync.cpp @@ -36,8 +36,11 @@ void NetworkSync::ReceiveNetworkId() { printf("_Received network Id %d\n", this->networkId); #endif PublishModel(roboid); - if (roboid->childCount > 0) - PublishRelativeThing(roboid->GetChild(0), true); + for (unsigned char childIx = 0; childIx < roboid->childCount; childIx++) { + Thing* child = roboid->GetChild(childIx); + if (child != nullptr) + PublishRelativeThing(child, true); + } } void NetworkSync::NewObject(InterestingThing* thing) { @@ -70,14 +73,14 @@ void NetworkSync::PublishRelativeThing(Thing* thing, bool recurse) { SendSpherical(buffer, &ix, thing->position); SendBuffer(ix); - // delay(100); PublishModel(thing); - // delay(1000); if (recurse) { - Thing* child = thing->GetChild(0); - if (child != nullptr) - PublishRelativeThing(child, true); + for (unsigned char childIx = 0; childIx < thing->childCount; childIx++) { + Thing* child = thing->GetChild(childIx); + if (child != nullptr) + PublishRelativeThing(child, true); + } } } @@ -146,9 +149,11 @@ void NetworkSync::SendPose(Roboid* roboid, bool recurse) { SendBuffer(ix); if (recurse) { - Thing* child = roboid->GetChild(0); - if (child != nullptr) - SendPose(child, true); + for (unsigned char childIx = 0; childIx < roboid->childCount; childIx++) { + Thing* child = roboid->GetChild(childIx); + if (child != nullptr) + SendPose(child, true); + } } } @@ -162,10 +167,11 @@ void NetworkSync::SendPose(Thing* thing, bool recurse) { SendBuffer(ix); if (recurse) { - // delay(10); - Thing* child = thing->GetChild(0); - if (child != nullptr) - SendPose(child, true); + for (unsigned char childIx = 0; childIx < thing->childCount; childIx++) { + Thing* child = thing->GetChild(childIx); + if (child != nullptr) + SendPose(thing->GetChild(childIx), true); + } } }