tox private impl + dht caps histo

This commit is contained in:
Green Sky 2023-11-13 16:23:49 +01:00
parent 4e4f62dd20
commit fd9d14d00c
No known key found for this signature in database
7 changed files with 104 additions and 1 deletions

View File

@ -58,6 +58,9 @@ add_executable(tomato
./tox_ui_utils.hpp
./tox_ui_utils.cpp
./tox_dht_cap_histo.hpp
./tox_dht_cap_histo.cpp
./chat_gui4.hpp
./chat_gui4.cpp
)

View File

@ -21,7 +21,8 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri
sdlrtu(renderer_),
cg(conf, rmm, cr, sdlrtu),
sw(conf),
tuiu(tc, conf)
tuiu(tc, conf),
tdch(tpi)
{
tel.subscribeAll(tc);
@ -109,12 +110,14 @@ Screen* MainScreen::poll(bool& quit) {
}
pm.tick(time_delta);
tdch.tick(time_delta);
mts.iterate();
cg.render();
sw.render();
tuiu.render();
tdch.render();
if constexpr (false) {
ImGui::ShowDemoWindow();

View File

@ -24,6 +24,7 @@
#include "./chat_gui4.hpp"
#include "./settings_window.hpp"
#include "./tox_ui_utils.hpp"
#include "./tox_dht_cap_histo.hpp"
#include <string>
#include <iostream>
@ -63,6 +64,7 @@ struct MainScreen final : public Screen {
ChatGui4 cg;
SettingsWindow sw;
ToxUIUtils tuiu;
ToxDHTCapHisto tdch;
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
~MainScreen(void);

69
src/tox_dht_cap_histo.cpp Normal file
View File

@ -0,0 +1,69 @@
#include "./tox_dht_cap_histo.hpp"
#include <imgui/imgui.h>
void ToxDHTCapHisto::tick(float time_delta) {
if (!_enabled) {
return;
}
_time_since_last_add += time_delta;
if (_time_since_last_add >= _value_add_interval) {
_time_since_last_add = 0.f; // very loose
const auto total = _tpi.toxDHTGetNumCloselist();
const auto with_cap = _tpi.toxDHTGetNumCloselistAnnounceCapable();
if (total == 0 || with_cap == 0) {
_ratios.push_back(0.f);
} else {
_ratios.push_back(float(with_cap) / float(total));
}
// TODO: limit
while (_ratios.size() > 5*60) {
_ratios.erase(_ratios.begin());
}
}
}
void ToxDHTCapHisto::render(void) {
{ // main window menubar injection
// assumes the window "tomato" was rendered already by cg
if (ImGui::Begin("tomato")) {
if (ImGui::BeginMenuBar()) {
ImGui::Separator();
if (ImGui::BeginMenu("Tox")) {
ImGui::SeparatorText("DHT diagnostics");
ImGui::Checkbox("enabled", &_enabled);
if (ImGui::MenuItem("show DHT announce capability histogram")) {
_show_window = true;
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
ImGui::End();
}
if (_show_window) {
if (ImGui::Begin("Tox DHT announce capability histogram", &_show_window)) {
if (_enabled) {
ImGui::PlotHistogram("##histogram", _ratios.data(), _ratios.size(), 0, nullptr, 0.f, 1.f, {-1, -1});
} else {
ImGui::TextUnformatted("logging disabled!");
if (ImGui::Button("enable")) {
_enabled = true;
}
}
}
ImGui::End();
}
}

22
src/tox_dht_cap_histo.hpp Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include <solanaceae/toxcore/tox_private_interface.hpp>
#include <vector>
class ToxDHTCapHisto {
ToxPrivateI& _tpi;
bool _enabled {true};
bool _show_window {false};
std::vector<float> _ratios;
const float _value_add_interval {1.f}; // every second
float _time_since_last_add {0.f};
public:
ToxDHTCapHisto(ToxPrivateI& tpi) : _tpi(tpi) {}
void tick(float time_delta);
void render(void);
};

View File

@ -1,3 +1,5 @@
#pragma once
#include <tox/tox_private.h>
#include <solanaceae/toxcore/tox_private_interface.hpp>

View File

@ -23,6 +23,8 @@ void ToxUIUtils::render(void) {
if (ImGui::BeginMenuBar()) {
ImGui::Separator();
if (ImGui::BeginMenu("Tox")) {
ImGui::SeparatorText("Friends/Groups");
if (ImGui::MenuItem("add Friend by ID")) {
_show_add_friend_window = true;
}