Compare commits
6 Commits
dc081ae
...
tracypatch
Author | SHA1 | Date | |
---|---|---|---|
f784f91798 | |||
bde0f2c7c3 | |||
83bbac2cd1 | |||
d5dede5a61 | |||
719400068a | |||
aaf8c6adc1 |
2
external/CMakeLists.txt
vendored
2
external/CMakeLists.txt
vendored
@ -1,5 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
||||||
|
|
||||||
|
add_subdirectory(./tracy)
|
||||||
|
|
||||||
add_subdirectory(./entt)
|
add_subdirectory(./entt)
|
||||||
|
|
||||||
add_subdirectory(./solanaceae_util)
|
add_subdirectory(./solanaceae_util)
|
||||||
|
2
external/solanaceae_message3
vendored
2
external/solanaceae_message3
vendored
Submodule external/solanaceae_message3 updated: e6f4f18f00...7c28b232a4
5
external/toxcore/CMakeLists.txt
vendored
5
external/toxcore/CMakeLists.txt
vendored
@ -171,9 +171,10 @@ configure_file(
|
|||||||
target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore")
|
target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore")
|
||||||
target_include_directories(toxcore PUBLIC "${TOX_DIR}")
|
target_include_directories(toxcore PUBLIC "${TOX_DIR}")
|
||||||
|
|
||||||
target_compile_definitions(toxcore PUBLIC USE_IPV6=1)
|
#target_compile_definitions(toxcore PUBLIC USE_IPV6=1)
|
||||||
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG)
|
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG)
|
||||||
target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO)
|
#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO)
|
||||||
|
target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE)
|
||||||
|
|
||||||
find_package(unofficial-sodium CONFIG QUIET)
|
find_package(unofficial-sodium CONFIG QUIET)
|
||||||
find_package(sodium QUIET)
|
find_package(sodium QUIET)
|
||||||
|
12
external/tracy/CMakeLists.txt
vendored
Normal file
12
external/tracy/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
if (NOT TARGET TracyClient)
|
||||||
|
FetchContent_Declare(tracy
|
||||||
|
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
||||||
|
GIT_TAG v0.10
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(tracy)
|
||||||
|
endif()
|
||||||
|
|
15
flake.nix
15
flake.nix
@ -12,6 +12,14 @@
|
|||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
|
||||||
|
# get deps (move to lockfile or something)
|
||||||
|
# TODO: use system provided instead
|
||||||
|
tracy-src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "wolfpld"; repo = "tracy";
|
||||||
|
rev = "v0.10";
|
||||||
|
hash = "sha256-DN1ExvQ5wcIUyhMAfiakFbZkDsx+5l8VMtYGvSdboPA=";
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
packages.default = pkgs.stdenv.mkDerivation {
|
packages.default = pkgs.stdenv.mkDerivation {
|
||||||
pname = "tomato";
|
pname = "tomato";
|
||||||
@ -56,8 +64,11 @@
|
|||||||
] ++ self.packages.${system}.default.dlopenBuildInputs;
|
] ++ self.packages.${system}.default.dlopenBuildInputs;
|
||||||
|
|
||||||
cmakeFlags = [
|
cmakeFlags = [
|
||||||
"TOMATO_ASAN=1"
|
"-DTOMATO_ASAN=OFF"
|
||||||
"CMAKE_BUILD_TYPE=RelWithDebInfo"
|
"-DCMAKE_BUILD_TYPE=RelWithDebInfo"
|
||||||
|
|
||||||
|
"-DTRACY_ENABLE=ON"
|
||||||
|
"-DFETCHCONTENT_SOURCE_DIR_TRACY=${tracy-src}"
|
||||||
];
|
];
|
||||||
|
|
||||||
# TODO: replace with install command
|
# TODO: replace with install command
|
||||||
|
@ -82,6 +82,8 @@ target_link_libraries(tomato PUBLIC
|
|||||||
solanaceae_tox_contacts
|
solanaceae_tox_contacts
|
||||||
solanaceae_tox_messages
|
solanaceae_tox_messages
|
||||||
|
|
||||||
|
TracyClient
|
||||||
|
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
|
|
||||||
imgui
|
imgui
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "./file_selector.hpp"
|
#include "./file_selector.hpp"
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
#include <solanaceae/tox_messages/components.hpp>
|
#include <solanaceae/tox_messages/components.hpp>
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
@ -35,6 +37,16 @@ namespace Components {
|
|||||||
float fade {1.f};
|
float fade {1.f};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ConvertedTimeCache {
|
||||||
|
// calling localtime is expensive af
|
||||||
|
int tm_year {0};
|
||||||
|
int tm_yday {0};
|
||||||
|
int tm_mon {0};
|
||||||
|
int tm_mday {0};
|
||||||
|
int tm_hour {0};
|
||||||
|
int tm_min {0};
|
||||||
|
};
|
||||||
|
|
||||||
} // Components
|
} // Components
|
||||||
|
|
||||||
static constexpr float lerp(float a, float b, float t) {
|
static constexpr float lerp(float a, float b, float t) {
|
||||||
@ -139,6 +151,7 @@ ChatGui4::~ChatGui4(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float ChatGui4::render(float time_delta) {
|
float ChatGui4::render(float time_delta) {
|
||||||
|
ZoneScoped;
|
||||||
_fss.render();
|
_fss.render();
|
||||||
_sip.render(time_delta);
|
_sip.render(time_delta);
|
||||||
|
|
||||||
@ -324,9 +337,11 @@ float ChatGui4::render(float time_delta) {
|
|||||||
//tmp_view.use<Message::Components::Timestamp>();
|
//tmp_view.use<Message::Components::Timestamp>();
|
||||||
//tmp_view.each([&](const Message3 e, Message::Components::ContactFrom& c_from, Message::Components::ContactTo& c_to, Message::Components::Timestamp ts
|
//tmp_view.each([&](const Message3 e, Message::Components::ContactFrom& c_from, Message::Components::ContactTo& c_to, Message::Components::Timestamp ts
|
||||||
//) {
|
//) {
|
||||||
uint64_t prev_ts {0};
|
//uint64_t prev_ts {0};
|
||||||
|
Components::ConvertedTimeCache prev_time {};
|
||||||
auto tmp_view = msg_reg.view<Message::Components::Timestamp>();
|
auto tmp_view = msg_reg.view<Message::Components::Timestamp>();
|
||||||
for (auto view_it = tmp_view.rbegin(), view_last = tmp_view.rend(); view_it != view_last; view_it++) {
|
for (auto view_it = tmp_view.rbegin(), view_last = tmp_view.rend(); view_it != view_last; view_it++) {
|
||||||
|
ZoneScoped;
|
||||||
const Message3 e = *view_it;
|
const Message3 e = *view_it;
|
||||||
|
|
||||||
// manually filter ("reverse" iteration <.<)
|
// manually filter ("reverse" iteration <.<)
|
||||||
@ -342,15 +357,12 @@ float ChatGui4::render(float time_delta) {
|
|||||||
// TODO: why?
|
// TODO: why?
|
||||||
ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
|
ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
|
||||||
|
|
||||||
{ // check if date changed
|
if (msg_reg.all_of<Components::ConvertedTimeCache>(e)) { // check if date changed
|
||||||
// TODO: find defined ways of casting to time_t
|
// TODO: move conversion up?
|
||||||
std::time_t prev = prev_ts / 1000;
|
const auto& next_time = msg_reg.get<Components::ConvertedTimeCache>(e);
|
||||||
std::time_t next = ts.ts / 1000;
|
|
||||||
std::tm prev_tm = *std::localtime(&prev);
|
|
||||||
std::tm next_tm = *std::localtime(&next);
|
|
||||||
if (
|
if (
|
||||||
prev_tm.tm_yday != next_tm.tm_yday ||
|
prev_time.tm_yday != next_time.tm_yday ||
|
||||||
prev_tm.tm_year != next_tm.tm_year // making sure
|
prev_time.tm_year != next_time.tm_year // making sure
|
||||||
) {
|
) {
|
||||||
// name
|
// name
|
||||||
if (ImGui::TableNextColumn()) {
|
if (ImGui::TableNextColumn()) {
|
||||||
@ -359,14 +371,14 @@ float ChatGui4::render(float time_delta) {
|
|||||||
// msg
|
// msg
|
||||||
if (ImGui::TableNextColumn()) {
|
if (ImGui::TableNextColumn()) {
|
||||||
ImGui::TextDisabled("DATE CHANGED from %d.%d.%d to %d.%d.%d",
|
ImGui::TextDisabled("DATE CHANGED from %d.%d.%d to %d.%d.%d",
|
||||||
1900+prev_tm.tm_year, 1+prev_tm.tm_mon, prev_tm.tm_mday,
|
1900+prev_time.tm_year, 1+prev_time.tm_mon, prev_time.tm_mday,
|
||||||
1900+next_tm.tm_year, 1+next_tm.tm_mon, next_tm.tm_mday
|
1900+next_time.tm_year, 1+next_time.tm_mon, next_time.tm_mday
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
|
ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_ts = ts.ts;
|
prev_time = next_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -519,12 +531,24 @@ float ChatGui4::render(float time_delta) {
|
|||||||
|
|
||||||
// ts
|
// ts
|
||||||
if (ImGui::TableNextColumn()) {
|
if (ImGui::TableNextColumn()) {
|
||||||
|
if (!msg_reg.all_of<Components::ConvertedTimeCache>(e)) {
|
||||||
auto time = std::chrono::system_clock::to_time_t(
|
auto time = std::chrono::system_clock::to_time_t(
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>{std::chrono::milliseconds{ts.ts}}
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>{std::chrono::milliseconds{ts.ts}}
|
||||||
);
|
);
|
||||||
auto localtime = std::localtime(&time);
|
auto localtime = std::localtime(&time);
|
||||||
|
msg_reg.emplace<Components::ConvertedTimeCache>(
|
||||||
|
e,
|
||||||
|
localtime->tm_year,
|
||||||
|
localtime->tm_yday,
|
||||||
|
localtime->tm_mon,
|
||||||
|
localtime->tm_mday,
|
||||||
|
localtime->tm_hour,
|
||||||
|
localtime->tm_min
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const auto& ctc = msg_reg.get<Components::ConvertedTimeCache>(e);
|
||||||
|
|
||||||
ImGui::Text("%.2d:%.2d", localtime->tm_hour, localtime->tm_min);
|
ImGui::Text("%.2d:%.2d", ctc.tm_hour, ctc.tm_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extra
|
// extra
|
||||||
@ -657,6 +681,7 @@ void ChatGui4::sendFilePath(const char* file_path) {
|
|||||||
|
|
||||||
// has MessageText
|
// has MessageText
|
||||||
void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
||||||
|
ZoneScoped;
|
||||||
const auto& msgtext = reg.get<Message::Components::MessageText>(e).text;
|
const auto& msgtext = reg.get<Message::Components::MessageText>(e).text;
|
||||||
|
|
||||||
// TODO: set word wrap
|
// TODO: set word wrap
|
||||||
@ -699,6 +724,7 @@ void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
||||||
|
ZoneScoped;
|
||||||
if (
|
if (
|
||||||
!_show_chat_avatar_tf
|
!_show_chat_avatar_tf
|
||||||
&& (
|
&& (
|
||||||
@ -958,6 +984,7 @@ void ChatGui4::renderMessageExtra(Message3Registry& reg, const Message3 e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChatGui4::renderContactList(void) {
|
void ChatGui4::renderContactList(void) {
|
||||||
|
ZoneScoped;
|
||||||
if (ImGui::BeginChild("contacts", {TEXT_BASE_WIDTH*35, 0})) {
|
if (ImGui::BeginChild("contacts", {TEXT_BASE_WIDTH*35, 0})) {
|
||||||
//for (const auto& c : _cm.getBigContacts()) {
|
//for (const auto& c : _cm.getBigContacts()) {
|
||||||
for (const auto& c : _cr.view<Contact::Components::TagBig>()) {
|
for (const auto& c : _cr.view<Contact::Components::TagBig>()) {
|
||||||
@ -1118,6 +1145,7 @@ bool ChatGui4::renderSubContactListContact(const Contact3 c, const bool selected
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChatGui4::pasteFile(const char* mime_type) {
|
void ChatGui4::pasteFile(const char* mime_type) {
|
||||||
|
ZoneScoped;
|
||||||
size_t data_size = 0;
|
size_t data_size = 0;
|
||||||
void* data = SDL_GetClipboardData(mime_type, &data_size);
|
void* data = SDL_GetClipboardData(mime_type, &data_size);
|
||||||
|
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -1,6 +1,8 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include <imgui/backends/imgui_impl_sdl3.h>
|
#include <imgui/backends/imgui_impl_sdl3.h>
|
||||||
#include <imgui/backends/imgui_impl_sdlrenderer3.h>
|
#include <imgui/backends/imgui_impl_sdlrenderer3.h>
|
||||||
@ -10,7 +12,6 @@
|
|||||||
#include "./start_screen.hpp"
|
#include "./start_screen.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <future>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -29,8 +30,6 @@ int main(int argc, char** argv) {
|
|||||||
std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
|
std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// me just messing with RAII cleanup
|
|
||||||
auto sdl_scope = std::async(std::launch::deferred, &SDL_Quit);
|
|
||||||
|
|
||||||
// more RAII
|
// more RAII
|
||||||
std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window {
|
std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window {
|
||||||
@ -86,15 +85,14 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
|
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
|
||||||
auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown);
|
|
||||||
ImGui_ImplSDLRenderer3_Init(renderer.get());
|
ImGui_ImplSDLRenderer3_Init(renderer.get());
|
||||||
auto imgui_sdlrenderer_scope = std::async(std::launch::deferred, &ImGui_ImplSDLRenderer3_Shutdown);
|
|
||||||
|
|
||||||
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
|
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
|
||||||
|
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
|
ZoneScopedN("tomato::mainloop");
|
||||||
auto new_time = std::chrono::steady_clock::now();
|
auto new_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
const float time_delta_tick = std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time_tick).count();
|
const float time_delta_tick = std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time_tick).count();
|
||||||
@ -104,7 +102,10 @@ int main(int argc, char** argv) {
|
|||||||
bool render = time_delta_render >= screen->nextRender();
|
bool render = time_delta_render >= screen->nextRender();
|
||||||
|
|
||||||
if (tick) {
|
if (tick) {
|
||||||
|
ZoneScopedN("tomato::tick");
|
||||||
|
FrameMarkStart("tomato::tick");
|
||||||
Screen* ret_screen = screen->tick(time_delta_tick, quit);
|
Screen* ret_screen = screen->tick(time_delta_tick, quit);
|
||||||
|
FrameMarkEnd("tomato::tick");
|
||||||
if (ret_screen != nullptr) {
|
if (ret_screen != nullptr) {
|
||||||
screen.reset(ret_screen);
|
screen.reset(ret_screen);
|
||||||
}
|
}
|
||||||
@ -131,6 +132,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
// can do both in the same loop
|
// can do both in the same loop
|
||||||
if (render) {
|
if (render) {
|
||||||
|
ZoneScopedN("tomato::render");
|
||||||
|
FrameMarkStart("tomato::render");
|
||||||
ImGui_ImplSDLRenderer3_NewFrame();
|
ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
@ -146,9 +149,11 @@ int main(int argc, char** argv) {
|
|||||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
SDL_RenderPresent(renderer.get());
|
SDL_RenderPresent(renderer.get());
|
||||||
|
FrameMark;
|
||||||
// clearing after present is (should) more performant, but first frame is a mess
|
// clearing after present is (should) more performant, but first frame is a mess
|
||||||
SDL_SetRenderDrawColor(renderer.get(), 0x10, 0x10, 0x10, SDL_ALPHA_OPAQUE);
|
SDL_SetRenderDrawColor(renderer.get(), 0x10, 0x10, 0x10, SDL_ALPHA_OPAQUE);
|
||||||
SDL_RenderClear(renderer.get());
|
SDL_RenderClear(renderer.get());
|
||||||
|
FrameMarkEnd("tomato::render");
|
||||||
|
|
||||||
last_time_render = new_time;
|
last_time_render = new_time;
|
||||||
}
|
}
|
||||||
@ -213,6 +218,19 @@ int main(int argc, char** argv) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: use scope for the unique ptrs
|
||||||
|
|
||||||
|
screen.reset();
|
||||||
|
|
||||||
|
ImGui_ImplSDLRenderer3_Shutdown();
|
||||||
|
ImGui_ImplSDL3_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
renderer.reset();
|
||||||
|
window.reset();
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "./main_screen.hpp"
|
#include "./main_screen.hpp"
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
@ -155,6 +157,7 @@ bool MainScreen::handleEvent(SDL_Event& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Screen* MainScreen::render(float time_delta, bool&) {
|
Screen* MainScreen::render(float time_delta, bool&) {
|
||||||
|
ZoneScoped;
|
||||||
// HACK: render the tomato main window first, with proper flags set.
|
// HACK: render the tomato main window first, with proper flags set.
|
||||||
// flags need to be set the first time begin() is called.
|
// flags need to be set the first time begin() is called.
|
||||||
// and plugins are run before the main cg is run.
|
// and plugins are run before the main cg is run.
|
||||||
@ -215,9 +218,24 @@ Screen* MainScreen::render(float time_delta, bool&) {
|
|||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
if (ImGui::BeginMenu("Settings")) {
|
if (ImGui::BeginMenu("Settings")) {
|
||||||
if (ImGui::MenuItem("ImGui Style Editor")) {
|
ImGui::SeparatorText("ImGui");
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Style Editor")) {
|
||||||
_show_tool_style_editor = true;
|
_show_tool_style_editor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Metrics")) {
|
||||||
|
_show_tool_metrics = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Debug Log")) {
|
||||||
|
_show_tool_debug_log = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("ID Stack Tool")) {
|
||||||
|
_show_tool_id_stack = true;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
@ -234,6 +252,18 @@ Screen* MainScreen::render(float time_delta, bool&) {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_show_tool_metrics) {
|
||||||
|
ImGui::ShowMetricsWindow(&_show_tool_metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_show_tool_debug_log) {
|
||||||
|
ImGui::ShowDebugLogWindow(&_show_tool_debug_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_show_tool_id_stack) {
|
||||||
|
ImGui::ShowIDStackToolWindow(&_show_tool_id_stack);
|
||||||
|
}
|
||||||
|
|
||||||
if constexpr (false) {
|
if constexpr (false) {
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
}
|
}
|
||||||
@ -376,7 +406,8 @@ Screen* MainScreen::render(float time_delta, bool&) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
||||||
quit = !tc.iterate(); // compute
|
ZoneScoped;
|
||||||
|
quit = !tc.iterate(time_delta); // compute
|
||||||
|
|
||||||
tcm.iterate(time_delta); // compute
|
tcm.iterate(time_delta); // compute
|
||||||
|
|
||||||
|
@ -76,6 +76,9 @@ struct MainScreen final : public Screen {
|
|||||||
ToxDHTCapHisto tdch;
|
ToxDHTCapHisto tdch;
|
||||||
|
|
||||||
bool _show_tool_style_editor {false};
|
bool _show_tool_style_editor {false};
|
||||||
|
bool _show_tool_metrics {false};
|
||||||
|
bool _show_tool_debug_log {false};
|
||||||
|
bool _show_tool_id_stack {false};
|
||||||
|
|
||||||
bool _window_hidden {false};
|
bool _window_hidden {false};
|
||||||
uint64_t _window_hidden_ts {0};
|
uint64_t _window_hidden_ts {0};
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
#include "./tox_client.hpp"
|
#include "./tox_client.hpp"
|
||||||
#include "toxcore/tox.h"
|
#include "toxcore/tox.h"
|
||||||
|
|
||||||
|
// experimental
|
||||||
|
#include <cstdint>
|
||||||
|
#include <toxcore/tox_private.h>
|
||||||
|
#include <toxcore/mem.h>
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
// meh, change this
|
// meh, change this
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
@ -68,6 +75,52 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// experimental tracy alloc tracking
|
||||||
|
static Tox_System g_mysystem = tox_default_system();
|
||||||
|
static const Memory* g_systemmemory = os_memory();
|
||||||
|
static Memory_Funcs g_mymemoryfuncs {
|
||||||
|
+[](void* obj, uint32_t size) {
|
||||||
|
auto ret = g_systemmemory->funcs->malloc(g_systemmemory->obj, size);
|
||||||
|
TracyAllocNS(ret, size, 32, "tox");
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
+[](void* obj, uint32_t nmemb, uint32_t size) {
|
||||||
|
auto ret = g_systemmemory->funcs->calloc(g_systemmemory->obj, nmemb, size);
|
||||||
|
TracyAllocNS(ret, nmemb*size, 32, "tox");
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
+[](void* obj, void* ptr, uint32_t size) {
|
||||||
|
TracyFreeNS(ptr, 32, "tox");
|
||||||
|
auto ret = g_systemmemory->funcs->realloc(g_systemmemory->obj, ptr, size);
|
||||||
|
TracyAllocNS(ret, size, 32, "tox");
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
+[](void* obj, void* ptr) {
|
||||||
|
TracyFreeNS(ptr, 32, "tox");
|
||||||
|
g_systemmemory->funcs->free(g_systemmemory->obj, ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
static Memory g_mymemory {
|
||||||
|
&g_mymemoryfuncs,
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
g_mysystem.mem = &g_mymemory;
|
||||||
|
|
||||||
|
tox_options_set_operating_system(options, &g_mysystem);
|
||||||
|
|
||||||
|
|
||||||
|
tox_options_set_log_callback(options, +[](Tox*, Tox_Log_Level level, const char*, uint32_t, const char*, const char* message, void*) {
|
||||||
|
std::string tmp_str;
|
||||||
|
tmp_str += "[";
|
||||||
|
tmp_str += tox_log_level_to_string(level);
|
||||||
|
tmp_str += "] ";
|
||||||
|
tmp_str += message;
|
||||||
|
TracyMessageS(tmp_str.c_str(), tmp_str.size(), 32);
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
tox_options_set_experimental_groups_persistence(options, true);
|
tox_options_set_experimental_groups_persistence(options, true);
|
||||||
|
|
||||||
TOX_ERR_NEW err_new;
|
TOX_ERR_NEW err_new;
|
||||||
@ -121,10 +174,14 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ToxClient::~ToxClient(void) {
|
ToxClient::~ToxClient(void) {
|
||||||
|
if (_tox_profile_dirty) {
|
||||||
|
saveToxProfile();
|
||||||
|
}
|
||||||
tox_kill(_tox);
|
tox_kill(_tox);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ToxClient::iterate(void) {
|
bool ToxClient::iterate(float time_delta) {
|
||||||
|
ZoneScoped;
|
||||||
Tox_Err_Events_Iterate err_e_it = TOX_ERR_EVENTS_ITERATE_OK;
|
Tox_Err_Events_Iterate err_e_it = TOX_ERR_EVENTS_ITERATE_OK;
|
||||||
auto* events = tox_events_iterate(_tox, false, &err_e_it);
|
auto* events = tox_events_iterate(_tox, false, &err_e_it);
|
||||||
if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) {
|
if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) {
|
||||||
@ -136,7 +193,8 @@ bool ToxClient::iterate(void) {
|
|||||||
|
|
||||||
tox_events_free(events);
|
tox_events_free(events);
|
||||||
|
|
||||||
if (_tox_profile_dirty) {
|
_save_heat -= time_delta;
|
||||||
|
if (_tox_profile_dirty && _save_heat <= 0.f) {
|
||||||
saveToxProfile();
|
saveToxProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,5 +238,6 @@ void ToxClient::saveToxProfile(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_tox_profile_dirty = false;
|
_tox_profile_dirty = false;
|
||||||
|
_save_heat = 10.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
|||||||
std::string _tox_profile_path;
|
std::string _tox_profile_path;
|
||||||
std::string _tox_profile_password;
|
std::string _tox_profile_password;
|
||||||
bool _tox_profile_dirty {true}; // set in callbacks
|
bool _tox_profile_dirty {true}; // set in callbacks
|
||||||
|
float _save_heat {0.f};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//ToxClient(/*const CommandLine& cl*/);
|
//ToxClient(/*const CommandLine& cl*/);
|
||||||
@ -34,7 +35,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
|||||||
void setDirty(void) { _tox_profile_dirty = true; }
|
void setDirty(void) { _tox_profile_dirty = true; }
|
||||||
|
|
||||||
// returns false when we shoul stop the program
|
// returns false when we shoul stop the program
|
||||||
bool iterate(void);
|
bool iterate(float time_delta);
|
||||||
void stop(void); // let it know it should exit
|
void stop(void); // let it know it should exit
|
||||||
|
|
||||||
void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }
|
void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }
|
||||||
|
Reference in New Issue
Block a user