Fix updates from short-lived participants

This commit is contained in:
Pascal Serrarens 2025-02-27 12:11:08 +01:00
parent c7650f1be1
commit 8c0a1a2688
4 changed files with 6 additions and 6 deletions

View File

@ -29,7 +29,7 @@ Participant::Participant(int port) {
} }
Participant::Participant(const char* ipAddress, 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->port = port;
this->site = new RemoteParticipant(ipAddress, 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) { void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) {
// std::cout << this->name << ": process Binary [" << (int)this->networkId << "/" // std::cout << this->name << ": process Binary [" << (int)this->networkId << "/"
// << (int)msg->networkId << "]\n"; // << (int)msg->networkId << "]\n";
Thing* thing = this->Get(msg->networkId, msg->thingId); Thing* thing = sender->Get(msg->networkId, msg->thingId);
if (thing != nullptr) if (thing != nullptr)
thing->ProcessBinary(msg->bytes); thing->ProcessBinary(msg->bytes);
else else

View File

@ -33,8 +33,8 @@ Thing* RemoteParticipant::Get(unsigned char networkId, unsigned char thingId) {
return nullptr; return nullptr;
} }
void RemoteParticipant::Add(Thing* thing) { void RemoteParticipant::Add(Thing* thing, bool checkId) {
if (thing->id == 0) { if (checkId && thing->id == 0) {
// allocate a new thing ID // allocate a new thing ID
thing->id = this->things.size() + 1; thing->id = this->things.size() + 1;
this->things.push_back(thing); this->things.push_back(thing);

View File

@ -19,7 +19,7 @@ protected:
public: public:
Thing *Get(unsigned char networkId, unsigned char thingId); Thing *Get(unsigned char networkId, unsigned char thingId);
void Add(Thing *thing); void Add(Thing *thing, bool checkId = true);
void Remove(Thing *thing); void Remove(Thing *thing);
void UpdateAll(unsigned long currentTimeMs); void UpdateAll(unsigned long currentTimeMs);
}; };

View File

@ -37,7 +37,7 @@ Thing::Thing(RemoteParticipant* owner, unsigned char networkId, unsigned char th
this->angularVelocity = Spherical16::zero; this->angularVelocity = Spherical16::zero;
// std::cout << "Created thing " << (int)this->networkId << "/" << (int)this->id // std::cout << "Created thing " << (int)this->networkId << "/" << (int)this->id
// << "\n"; // << "\n";
owner->Add(this); owner->Add(this, false);
} }
void Thing::Terminate() { void Thing::Terminate() {