From 8c0a1a2688c9a9c75f7188cf2116d9751afcd488 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 27 Feb 2025 12:11:08 +0100 Subject: [PATCH] Fix updates from short-lived participants --- Participant.cpp | 4 ++-- RemoteParticipant.cpp | 4 ++-- RemoteParticipant.h | 2 +- Thing.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Participant.cpp b/Participant.cpp index f25e40e..71cd4a0 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -29,7 +29,7 @@ Participant::Participant(int port) { } Participant::Participant(const char* ipAddress, int port) { - this->ipAddress = ipAddress; // maybe this is not needed anymore, keeping it to "0.0.0.0" + this->ipAddress = ipAddress; // maybe this is not needed anymore, keeping it to "0.0.0.0" this->port = port; this->site = new RemoteParticipant(ipAddress, port); } @@ -286,7 +286,7 @@ void Participant::Process(RemoteParticipant* sender, PoseMsg* msg) {} void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) { // std::cout << this->name << ": process Binary [" << (int)this->networkId << "/" // << (int)msg->networkId << "]\n"; - Thing* thing = this->Get(msg->networkId, msg->thingId); + Thing* thing = sender->Get(msg->networkId, msg->thingId); if (thing != nullptr) thing->ProcessBinary(msg->bytes); else diff --git a/RemoteParticipant.cpp b/RemoteParticipant.cpp index ee24bae..252e732 100644 --- a/RemoteParticipant.cpp +++ b/RemoteParticipant.cpp @@ -33,8 +33,8 @@ Thing* RemoteParticipant::Get(unsigned char networkId, unsigned char thingId) { return nullptr; } -void RemoteParticipant::Add(Thing* thing) { - if (thing->id == 0) { +void RemoteParticipant::Add(Thing* thing, bool checkId) { + if (checkId && thing->id == 0) { // allocate a new thing ID thing->id = this->things.size() + 1; this->things.push_back(thing); diff --git a/RemoteParticipant.h b/RemoteParticipant.h index 4f7fa3a..14c4742 100644 --- a/RemoteParticipant.h +++ b/RemoteParticipant.h @@ -19,7 +19,7 @@ protected: public: Thing *Get(unsigned char networkId, unsigned char thingId); - void Add(Thing *thing); + void Add(Thing *thing, bool checkId = true); void Remove(Thing *thing); void UpdateAll(unsigned long currentTimeMs); }; diff --git a/Thing.cpp b/Thing.cpp index 12081cb..1de94d3 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -37,7 +37,7 @@ Thing::Thing(RemoteParticipant* owner, unsigned char networkId, unsigned char th this->angularVelocity = Spherical16::zero; // std::cout << "Created thing " << (int)this->networkId << "/" << (int)this->id // << "\n"; - owner->Add(this); + owner->Add(this, false); } void Thing::Terminate() {