2024-06-28 21:10:01 +02:00
|
|
|
#include "./participation.hpp"
|
|
|
|
|
2024-07-08 18:12:47 +02:00
|
|
|
#include "./contact_components.hpp"
|
2024-06-28 21:10:01 +02:00
|
|
|
#include "./chunk_picker.hpp"
|
|
|
|
|
2024-07-08 18:12:47 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2024-06-28 21:10:01 +02:00
|
|
|
bool addParticipation(Contact3Handle c, ObjectHandle o) {
|
|
|
|
bool was_new {false};
|
2024-07-08 18:12:47 +02:00
|
|
|
assert(static_cast<bool>(o));
|
|
|
|
assert(static_cast<bool>(c));
|
2024-06-28 21:10:01 +02:00
|
|
|
|
|
|
|
if (static_cast<bool>(o)) {
|
|
|
|
const auto [_, inserted] = o.get_or_emplace<Components::SuspectedParticipants>().participants.emplace(c);
|
|
|
|
was_new = inserted;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<bool>(c)) {
|
2024-07-08 18:12:47 +02:00
|
|
|
const auto [_, inserted] = c.get_or_emplace<Contact::Components::FT1Participation>().participating.emplace(o);
|
2024-06-28 21:10:01 +02:00
|
|
|
was_new = was_new || inserted;
|
|
|
|
}
|
|
|
|
|
2024-07-09 11:40:01 +02:00
|
|
|
//std::cout << "added " << (was_new?"new ":"") << "participant\n";
|
2024-07-08 18:12:47 +02:00
|
|
|
|
2024-06-28 21:10:01 +02:00
|
|
|
return was_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeParticipation(Contact3Handle c, ObjectHandle o) {
|
2024-07-08 18:12:47 +02:00
|
|
|
assert(static_cast<bool>(o));
|
|
|
|
assert(static_cast<bool>(c));
|
|
|
|
|
2024-06-28 21:10:01 +02:00
|
|
|
if (static_cast<bool>(o) && o.all_of<Components::SuspectedParticipants>()) {
|
|
|
|
o.get<Components::SuspectedParticipants>().participants.erase(c);
|
|
|
|
}
|
|
|
|
|
2024-07-08 18:12:47 +02:00
|
|
|
if (static_cast<bool>(c)) {
|
|
|
|
if (c.all_of<Contact::Components::FT1Participation>()) {
|
|
|
|
c.get<Contact::Components::FT1Participation>().participating.erase(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.all_of<ChunkPicker>()) {
|
|
|
|
c.get<ChunkPicker>().participating_unfinished.erase(o);
|
|
|
|
}
|
2024-06-28 21:10:01 +02:00
|
|
|
}
|
2024-07-08 18:12:47 +02:00
|
|
|
|
2024-07-09 11:40:01 +02:00
|
|
|
//std::cout << "removed participant\n";
|
2024-06-28 21:10:01 +02:00
|
|
|
}
|
|
|
|
|