From 9777cb81cb6dff2e481b5f9ca7a151255ef8450e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 14 Dec 2024 23:47:04 +0100 Subject: [PATCH] remote (combined) bitset have --- external/solanaceae_object_store | 2 +- src/bitset_image_loader.cpp | 102 +++++++++++++++++++++++++------ src/bitset_image_loader.hpp | 22 +++++++ src/chat_gui4.cpp | 11 ++-- src/os_comps.hpp | 15 ----- src/os_comps_id.inl | 2 - 6 files changed, 114 insertions(+), 40 deletions(-) diff --git a/external/solanaceae_object_store b/external/solanaceae_object_store index ed640ba..18d2888 160000 --- a/external/solanaceae_object_store +++ b/external/solanaceae_object_store @@ -1 +1 @@ -Subproject commit ed640ba08cf8452e202ed567cad48ad396b8e1db +Subproject commit 18d2888e3452074245375f329d90520ac250b595 diff --git a/src/bitset_image_loader.cpp b/src/bitset_image_loader.cpp index 10e0260..07bc266 100644 --- a/src/bitset_image_loader.cpp +++ b/src/bitset_image_loader.cpp @@ -16,23 +16,8 @@ namespace Message { uint64_t getTimeMS(void); } -BitsetImageLoader::BitsetImageLoader(void) { -} - -std::optional BitsetImageLoader::load(TextureUploaderI& tu, ObjectHandle o) { - if (!static_cast(o)) { - std::cerr << "BIL error: trying to load invalid object\n"; - return std::nullopt; - } - - if (!o.all_of()) { - // after completion, this is called until the texture times out - //std::cout << "BIL: no local have bitset\n"; - return std::nullopt; - } - - // TODO: const - auto& have = o.get().have; +std::optional BitsetImageLoader::haveToTexture(TextureUploaderI& tu, BitSet& have, ObjectHandle o) { + assert(have.size_bits() > 0); auto* surf = SDL_CreateSurfaceFrom( have.size_bits(), 1, @@ -83,3 +68,86 @@ std::optional BitsetImageLoader::load(TextureUploaderI& tu, Object return new_entry; } +BitsetImageLoader::BitsetImageLoader(void) { +} + +std::optional BitsetImageLoader::load(TextureUploaderI& tu, ObjectHandle o) { + if (!static_cast(o)) { + std::cerr << "BIL error: trying to load invalid object\n"; + return std::nullopt; + } + + if (!o.any_of()) { + // after completion, this is called until the texture times out + //std::cout << "BIL: no local have bitset\n"; + return std::nullopt; + } + + if (o.all_of()) { + auto& have = o.get().have; + assert(have.size_bits() > 0); + return haveToTexture(tu, have, o); + } else if (o.all_of()) { + auto& list = o.get().others; + if (list.empty()) { + std::cout << "BIL: remote set list empty\n"; + return std::nullopt; + } + const auto& first_entry = list.begin()->second; + + if (first_entry.have_all) { + _tmp_bitset = {8}; + _tmp_bitset.invert(); + std::cout << "BIL: remote first have all\n"; + } else { + _tmp_bitset = first_entry.have; + assert(_tmp_bitset.size_bits() == first_entry.have.size_bits()); + + for (auto it = list.begin()+1; it != list.end(); it++) { + if (it->second.have_all) { + _tmp_bitset = {8}; + _tmp_bitset.invert(); + std::cout << "BIL: remote have all\n"; + break; + } + + _tmp_bitset.merge(it->second.have); + } + } + + return haveToTexture(tu, _tmp_bitset, o); + } + + return std::nullopt; +} + +std::optional BitsetImageLoader::load(TextureUploaderI& tu, ObjectContactSub ocs) { + if (!static_cast(ocs.o)) { + std::cerr << "BIL error: trying to load invalid object\n"; + return std::nullopt; + } + + if (!ocs.o.all_of()) { + // after completion, this is called until the texture times out + return std::nullopt; + } + + auto& map = ocs.o.get().others; + auto it = map.find(ocs.c); + if (it == map.end()) { + // contact not found + return std::nullopt; + } + + if (it->second.have_all) { + BitSet tmp{8}; // or 1? + tmp.invert(); + return haveToTexture(tu, tmp, ocs.o); + } else if (it->second.have.size_bits() == 0) { + BitSet tmp{8}; // or 1? + return haveToTexture(tu, tmp, ocs.o); + } else { + return haveToTexture(tu, it->second.have, ocs.o); + } +} + diff --git a/src/bitset_image_loader.hpp b/src/bitset_image_loader.hpp index 66e3475..12975e3 100644 --- a/src/bitset_image_loader.hpp +++ b/src/bitset_image_loader.hpp @@ -1,14 +1,36 @@ #pragma once #include +#include +#include #include "./texture_cache.hpp" #include +struct ObjectContactSub final { + ObjectHandle o; + Contact3 c{entt::null}; +}; + +template<> +struct std::hash { + std::size_t operator()(ObjectContactSub const& ocs) const noexcept { + const std::size_t h1 = reinterpret_cast(ocs.o.registry()); + const std::size_t h2 = entt::to_integral(ocs.o.entity()); + const std::size_t h3 = entt::to_integral(ocs.c); + return (h1 << 3) ^ (h3 << 7) ^ (h2 * 11400714819323198485llu); + } +}; + class BitsetImageLoader { + BitSet _tmp_bitset; + + std::optional haveToTexture(TextureUploaderI& tu, BitSet& have, ObjectHandle o); + public: BitsetImageLoader(void); std::optional load(TextureUploaderI& tu, ObjectHandle o); + std::optional load(TextureUploaderI& tu, ObjectContactSub ocs); }; diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 1898e70..2119db4 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -1232,7 +1232,10 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f); } - if (!upload && !o.all_of() && o.all_of()) { + if ( + (!upload && !o.all_of() && o.all_of()) || + (upload && o.all_of()) + ) { ImGui::BeginGroup(); // TODO: hights are all off @@ -1266,7 +1269,6 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { ); ImGui::EndGroup(); - //} else if (upload && o.all_of()) { } else { ImGui::ProgressBar( fraction, @@ -1770,11 +1772,10 @@ void ChatGui4::sendFileList(const std::vector& list) { } bool ChatGui4::onEvent(const ObjectStore::Events::ObjectUpdate& e) { - if (!e.e.all_of()) { - return false; + if (e.e.any_of()) { + _b_tc.stale(e.e); } - _b_tc.stale(e.e); return false; } diff --git a/src/os_comps.hpp b/src/os_comps.hpp index 133e70c..078de72 100644 --- a/src/os_comps.hpp +++ b/src/os_comps.hpp @@ -8,21 +8,6 @@ namespace ObjectStore::Components { - // until i find a better name - namespace File { - - // ephemeral?, not sure saving this to disk makes sense - // tag remove have all? - struct RemoteHaveBitset { - struct Entry { - bool have_all {false}; - BitSet have; - }; - entt::dense_map others; - }; - - } // File - namespace Ephemeral { namespace File { diff --git a/src/os_comps_id.inl b/src/os_comps_id.inl index 51b54ff..c1bb9c9 100644 --- a/src/os_comps_id.inl +++ b/src/os_comps_id.inl @@ -18,8 +18,6 @@ constexpr std::string_view entt::type_name::value() noexcept { \ // cross compile(r) stable ids -DEFINE_COMP_ID(ObjComp::F::RemoteHaveBitset) - DEFINE_COMP_ID(ObjComp::Ephemeral::File::TransferStatsSeparated) #undef DEFINE_COMP_ID