Compare commits

..

No commits in common. "385addff123a9afb41c8cc0878f753bebcbed409" and "8009ecd877e64aabffb65a95f1bc93a695994cef" have entirely different histories.

2 changed files with 17 additions and 30 deletions

@ -1 +1 @@
Subproject commit 32241423ab2783930e1d1e5ba64a67709cf20b9b
Subproject commit 2059577fc2213075c0300e7390591db2c637ba4b

View File

@ -7,17 +7,6 @@
#include <iostream>
static Contact3 findContactByID(Contact3Registry& cr, const std::vector<uint8_t>& id) {
// TODO: id lookup table, this is very inefficent
for (const auto& [c_it, id_it] : cr.view<Contact::Components::ID>().each()) {
if (id == id_it.data) {
return c_it;
}
}
return entt::null;
}
template<>
bool MessageSerializerCallbacks::component_get_json<Message::Components::ContactFrom>(MessageSerializerCallbacks& msc, const Handle h, nlohmann::json& j) {
const Contact3 c = h.get<Message::Components::ContactFrom>().c;
@ -49,17 +38,16 @@ bool MessageSerializerCallbacks::component_emplace_or_replace_json<Message::Comp
const std::vector<uint8_t> id = j.is_binary()?j:j["bytes"];
Contact3 other_c = findContactByID(msc.cr, id);
if (!msc.cr.valid(other_c)) {
// create sparse contact with id only
other_c = msc.cr.create();
msc.cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
// TODO: id lookup table, this is very inefficent
for (const auto& [c_it, id_it] : msc.cr.view<Contact::Components::ID>().each()) {
if (id == id_it.data) {
h.emplace_or_replace<Message::Components::ContactFrom>(c_it);
return true;
}
}
h.emplace_or_replace<Message::Components::ContactFrom>(other_c);
// TODO: should we return false if the contact is unknown??
return true;
// TODO: should we really return false if the contact is unknown??
return false;
}
template<>
@ -93,15 +81,14 @@ bool MessageSerializerCallbacks::component_emplace_or_replace_json<Message::Comp
const std::vector<uint8_t> id = j.is_binary()?j:j["bytes"];
Contact3 other_c = findContactByID(msc.cr, id);
if (!msc.cr.valid(other_c)) {
// create sparse contact with id only
other_c = msc.cr.create();
msc.cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
// TODO: id lookup table, this is very inefficent
for (const auto& [c_it, id_it] : msc.cr.view<Contact::Components::ID>().each()) {
if (id == id_it.data) {
h.emplace_or_replace<Message::Components::ContactTo>(c_it);
return true;
}
}
h.emplace_or_replace<Message::Components::ContactTo>(other_c);
// TODO: should we return false if the contact is unknown??
return true;
// TODO: should we really return false if the contact is unknown??
return false;
}