Compare commits
No commits in common. "385addff123a9afb41c8cc0878f753bebcbed409" and "8009ecd877e64aabffb65a95f1bc93a695994cef" have entirely different histories.
385addff12
...
8009ecd877
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 32241423ab2783930e1d1e5ba64a67709cf20b9b
|
Subproject commit 2059577fc2213075c0300e7390591db2c637ba4b
|
@ -7,17 +7,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#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<>
|
template<>
|
||||||
bool MessageSerializerCallbacks::component_get_json<Message::Components::ContactFrom>(MessageSerializerCallbacks& msc, const Handle h, nlohmann::json& j) {
|
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;
|
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"];
|
const std::vector<uint8_t> id = j.is_binary()?j:j["bytes"];
|
||||||
|
|
||||||
Contact3 other_c = findContactByID(msc.cr, id);
|
// TODO: id lookup table, this is very inefficent
|
||||||
if (!msc.cr.valid(other_c)) {
|
for (const auto& [c_it, id_it] : msc.cr.view<Contact::Components::ID>().each()) {
|
||||||
// create sparse contact with id only
|
if (id == id_it.data) {
|
||||||
other_c = msc.cr.create();
|
h.emplace_or_replace<Message::Components::ContactFrom>(c_it);
|
||||||
msc.cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.emplace_or_replace<Message::Components::ContactFrom>(other_c);
|
// TODO: should we really return false if the contact is unknown??
|
||||||
|
return false;
|
||||||
// TODO: should we return false if the contact is unknown??
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
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"];
|
const std::vector<uint8_t> id = j.is_binary()?j:j["bytes"];
|
||||||
|
|
||||||
Contact3 other_c = findContactByID(msc.cr, id);
|
// TODO: id lookup table, this is very inefficent
|
||||||
if (!msc.cr.valid(other_c)) {
|
for (const auto& [c_it, id_it] : msc.cr.view<Contact::Components::ID>().each()) {
|
||||||
// create sparse contact with id only
|
if (id == id_it.data) {
|
||||||
other_c = msc.cr.create();
|
h.emplace_or_replace<Message::Components::ContactTo>(c_it);
|
||||||
msc.cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
h.emplace_or_replace<Message::Components::ContactTo>(other_c);
|
|
||||||
|
|
||||||
// TODO: should we return false if the contact is unknown??
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: should we really return false if the contact is unknown??
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user