Compare commits
12 Commits
60c941417c
...
7613065b4c
Author | SHA1 | Date | |
---|---|---|---|
7613065b4c | |||
be8ceb861c | |||
da0f59a3f5 | |||
000254320e | |||
2fac7206d2 | |||
e8234f2a4a | |||
a0ba0b39d8 | |||
845967cf12 | |||
92b58cbfa9 | |||
5a0651eaf0 | |||
14fcaf1d7e | |||
5a0252d8d0 |
30
.github/workflows/cd.yml
vendored
30
.github/workflows/cd.yml
vendored
@ -10,6 +10,36 @@ env:
|
|||||||
BUILD_TYPE: Release
|
BUILD_TYPE: Release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
linux-ubuntu:
|
||||||
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: sudo apt update && sudo apt -y install libsodium-dev
|
||||||
|
|
||||||
|
- name: Configure CMake
|
||||||
|
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ${{ github.event.repository.name }}-ubuntu20.04-x86_64
|
||||||
|
# TODO: do propper packing
|
||||||
|
path: |
|
||||||
|
${{github.workspace}}/build/bin/
|
||||||
|
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
2
external/solanaceae_plugin
vendored
2
external/solanaceae_plugin
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 96bab0200f5b13671756abe7e3132ed78aaa2a40
|
Subproject commit 5ae3f07c3ac16c3255ed5b7792c17545c7667ac3
|
2
external/solanaceae_toxcore
vendored
2
external/solanaceae_toxcore
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 54084b5a53e1617ff9b0c225880b0f1d60fe65ea
|
Subproject commit 08b3d69c159ca93aaaf38b6ee06507aa0eefd403
|
@ -51,7 +51,7 @@ ChatGui4::ChatGui4(
|
|||||||
) : _conf(conf), _rmm(rmm), _cr(cr), _tal(_cr), _contact_tc(_tal, tu), _msg_tc(_mil, tu), _sip(tu) {
|
) : _conf(conf), _rmm(rmm), _cr(cr), _tal(_cr), _contact_tc(_tal, tu), _msg_tc(_mil, tu), _sip(tu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatGui4::render(void) {
|
void ChatGui4::render(float time_delta) {
|
||||||
if (!_cr.storage<Contact::Components::TagAvatarInvalidate>().empty()) { // handle force-reloads for avatars
|
if (!_cr.storage<Contact::Components::TagAvatarInvalidate>().empty()) { // handle force-reloads for avatars
|
||||||
std::vector<Contact3> to_purge;
|
std::vector<Contact3> to_purge;
|
||||||
_cr.view<Contact::Components::TagAvatarInvalidate>().each([&to_purge](const Contact3 c) {
|
_cr.view<Contact::Components::TagAvatarInvalidate>().each([&to_purge](const Contact3 c) {
|
||||||
@ -66,7 +66,7 @@ void ChatGui4::render(void) {
|
|||||||
_msg_tc.update();
|
_msg_tc.update();
|
||||||
|
|
||||||
_fss.render();
|
_fss.render();
|
||||||
_sip.render();
|
_sip.render(time_delta);
|
||||||
|
|
||||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
ImGui::SetNextWindowPos(viewport->WorkPos);
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||||
|
@ -46,7 +46,7 @@ class ChatGui4 {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void render(void);
|
void render(float time_delta);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool any_unread {false};
|
bool any_unread {false};
|
||||||
|
94
src/main.cpp
94
src/main.cpp
@ -21,7 +21,8 @@ int main(int argc, char** argv) {
|
|||||||
std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n";
|
std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto last_time = std::chrono::steady_clock::now();
|
auto last_time_render = std::chrono::steady_clock::now();
|
||||||
|
auto last_time_tick = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
// actual setup
|
// actual setup
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
@ -68,9 +69,22 @@ int main(int argc, char** argv) {
|
|||||||
bool quit = false;
|
bool quit = false;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
auto new_time = std::chrono::steady_clock::now();
|
auto new_time = std::chrono::steady_clock::now();
|
||||||
//const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
|
||||||
last_time = new_time;
|
|
||||||
|
|
||||||
|
const float time_delta_tick = std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time_tick).count();
|
||||||
|
const float time_delta_render = std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time_render).count();
|
||||||
|
|
||||||
|
bool tick = time_delta_tick >= screen->nextTick();
|
||||||
|
bool render = time_delta_render >= screen->nextRender();
|
||||||
|
|
||||||
|
if (tick) {
|
||||||
|
Screen* ret_screen = screen->tick(time_delta_tick, quit);
|
||||||
|
if (ret_screen != nullptr) {
|
||||||
|
screen.reset(ret_screen);
|
||||||
|
}
|
||||||
|
last_time_tick = new_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do events outside of tick/render, so they can influence reported intervals
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_EVENT_QUIT) {
|
if (event.type == SDL_EVENT_QUIT) {
|
||||||
@ -88,21 +102,18 @@ int main(int argc, char** argv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//float fps_target = 60.f;
|
// can do both in the same loop
|
||||||
//if (SDL_GetWindowFlags(window.get()) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) {
|
if (render) {
|
||||||
//fps_target = 30.f;
|
|
||||||
//}
|
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer3_NewFrame();
|
ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
//ImGui::ShowDemoWindow();
|
{ // render
|
||||||
|
Screen* ret_screen = screen->render(time_delta_render, quit);
|
||||||
Screen* ret_screen = screen->poll(quit);
|
|
||||||
if (ret_screen != nullptr) {
|
if (ret_screen != nullptr) {
|
||||||
screen.reset(ret_screen);
|
screen.reset(ret_screen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
||||||
@ -112,10 +123,63 @@ int main(int argc, char** argv) {
|
|||||||
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());
|
||||||
|
|
||||||
std::this_thread::sleep_for( // time left to get to 60fps
|
last_time_render = new_time;
|
||||||
std::chrono::duration<float, std::chrono::seconds::period>(0.0166f) // 60fps frame duration
|
}
|
||||||
- std::chrono::duration<float, std::chrono::seconds::period>(std::chrono::steady_clock::now() - new_time) // time used for rendering
|
|
||||||
);
|
//// TODO: seperate out render and tick
|
||||||
|
//const float time_to_next_loop = std::min<float>(screen->nextRender(), screen->nextTick());
|
||||||
|
|
||||||
|
//std::this_thread::sleep_for( // time left to get to 60fps
|
||||||
|
//std::chrono::duration<float, std::chrono::seconds::period>(time_to_next_loop)
|
||||||
|
//- std::chrono::duration<float, std::chrono::seconds::period>(std::chrono::steady_clock::now() - new_time) // time used for rendering
|
||||||
|
//);
|
||||||
|
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
if (render || tick) {
|
||||||
|
// why is windows like this
|
||||||
|
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms
|
||||||
|
SDL_Delay(1); // yield for 1ms
|
||||||
|
} else {
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// pretty hacky and spins if close to next update
|
||||||
|
// if next loop >= 1ms away, wait 1ms
|
||||||
|
if (time_delta_tick+0.001f < screen->nextTick() && time_delta_render+0.001f < screen->nextRender()) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// dynamic sleep, sleeps the reminder till next update
|
||||||
|
//std::this_thread::sleep_for(std::chrono::duration<float, std::chrono::seconds::period>(
|
||||||
|
//std::min<float>(
|
||||||
|
//screen->nextTick() - time_delta_tick,
|
||||||
|
//screen->nextRender() - time_delta_render
|
||||||
|
//)
|
||||||
|
//));
|
||||||
|
|
||||||
|
const float min_delay = std::min<float>(
|
||||||
|
screen->nextTick() - time_delta_tick,
|
||||||
|
screen->nextRender() - time_delta_render
|
||||||
|
) * 1000.f;
|
||||||
|
|
||||||
|
if (min_delay > 0.f) {
|
||||||
|
SDL_Delay(uint32_t(min_delay));
|
||||||
|
}
|
||||||
|
|
||||||
|
// better in theory, but consumes more cpu on linux for some reason
|
||||||
|
//SDL_WaitEventTimeout(nullptr, int32_t(
|
||||||
|
//std::min<float>(
|
||||||
|
//screen->nextTick() - time_delta_tick,
|
||||||
|
//screen->nextRender() - time_delta_render
|
||||||
|
//) * 1000.f
|
||||||
|
//));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// why is windows like this
|
||||||
|
//std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms
|
||||||
|
SDL_Delay(1); // yield for 1ms
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -75,23 +75,78 @@ bool MainScreen::handleEvent(SDL_Event& e) {
|
|||||||
if (e.type == SDL_EVENT_DROP_FILE) {
|
if (e.type == SDL_EVENT_DROP_FILE) {
|
||||||
std::cout << "DROP FILE: " << e.drop.file << "\n";
|
std::cout << "DROP FILE: " << e.drop.file << "\n";
|
||||||
cg.sendFilePath(e.drop.file);
|
cg.sendFilePath(e.drop.file);
|
||||||
|
_render_interval = 1.f/60.f; // TODO: magic
|
||||||
|
_time_since_event = 0.f;
|
||||||
return true; // TODO: forward return succ from sendFilePath()
|
return true; // TODO: forward return succ from sendFilePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
e.type == SDL_EVENT_WINDOW_MINIMIZED ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_HIDDEN ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_OCCLUDED // does this trigger on partial occlusion?
|
||||||
|
) {
|
||||||
|
auto* window = SDL_GetWindowFromID(e.window.windowID);
|
||||||
|
auto* event_renderer = SDL_GetRenderer(window);
|
||||||
|
if (event_renderer != nullptr && event_renderer == renderer) {
|
||||||
|
// our window is now obstructed
|
||||||
|
if (_window_hidden_ts < e.window.timestamp) {
|
||||||
|
_window_hidden_ts = e.window.timestamp;
|
||||||
|
_window_hidden = true;
|
||||||
|
//std::cout << "TOMAT: window hidden " << e.window.timestamp << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true; // forward?
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
e.type == SDL_EVENT_WINDOW_SHOWN ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_RESTORED ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_EXPOSED
|
||||||
|
) {
|
||||||
|
auto* window = SDL_GetWindowFromID(e.window.windowID);
|
||||||
|
auto* event_renderer = SDL_GetRenderer(window);
|
||||||
|
if (event_renderer != nullptr && event_renderer == renderer) {
|
||||||
|
if (_window_hidden_ts <= e.window.timestamp) {
|
||||||
|
_window_hidden_ts = e.window.timestamp;
|
||||||
|
|
||||||
|
if (_window_hidden) {
|
||||||
|
// if window was previously hidden, we shorten the wait for the next frame
|
||||||
|
_render_interval = 1.f/60.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
_window_hidden = false;
|
||||||
|
//std::cout << "TOMAT: window shown " << e.window.timestamp << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_render_interval = 1.f/60.f; // TODO: magic
|
||||||
|
_time_since_event = 0.f;
|
||||||
|
return true; // forward?
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
_fps_perf_mode <= 1 && (
|
||||||
|
// those are all the events imgui polls
|
||||||
|
e.type == SDL_EVENT_MOUSE_MOTION ||
|
||||||
|
e.type == SDL_EVENT_MOUSE_WHEEL ||
|
||||||
|
e.type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
|
||||||
|
e.type == SDL_EVENT_MOUSE_BUTTON_UP ||
|
||||||
|
e.type == SDL_EVENT_TEXT_INPUT ||
|
||||||
|
e.type == SDL_EVENT_KEY_DOWN ||
|
||||||
|
e.type == SDL_EVENT_KEY_UP ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_MOUSE_ENTER ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_MOUSE_LEAVE ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_FOCUS_GAINED ||
|
||||||
|
e.type == SDL_EVENT_WINDOW_FOCUS_LOST
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
_render_interval = 1.f/60.f; // TODO: magic
|
||||||
|
_time_since_event = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen* MainScreen::poll(bool& quit) {
|
Screen* MainScreen::render(float time_delta, bool&) {
|
||||||
auto new_time = std::chrono::high_resolution_clock::now();
|
|
||||||
const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
|
||||||
last_time = new_time;
|
|
||||||
|
|
||||||
quit = !tc.iterate();
|
|
||||||
|
|
||||||
tcm.iterate(time_delta);
|
|
||||||
|
|
||||||
tam.iterate();
|
|
||||||
|
|
||||||
// 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.
|
||||||
@ -109,48 +164,87 @@ Screen* MainScreen::poll(bool& quit) {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
pm.tick(time_delta);
|
const float pm_interval = pm.render(time_delta); // render
|
||||||
tdch.tick(time_delta);
|
|
||||||
|
|
||||||
mts.iterate();
|
cg.render(time_delta); // render
|
||||||
|
sw.render(); // render
|
||||||
|
tuiu.render(); // render
|
||||||
|
tdch.render(); // render
|
||||||
|
|
||||||
|
{ // main window menubar injection
|
||||||
|
if (ImGui::Begin("tomato")) {
|
||||||
|
if (ImGui::BeginMenuBar()) {
|
||||||
|
// ImGui::Separator(); // why do we not need this????
|
||||||
|
if (ImGui::BeginMenu("Performance")) {
|
||||||
|
{ // fps
|
||||||
|
const auto targets = "normal\0reduced\0powersave\0";
|
||||||
|
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
|
||||||
|
ImGui::Combo("fps mode", &_fps_perf_mode, targets, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // compute
|
||||||
|
const auto targets = "normal\0powersave\0";
|
||||||
|
ImGui::SetNextItemWidth(ImGui::GetFontSize()*10);
|
||||||
|
ImGui::Combo("compute mode", &_compute_perf_mode, targets, 4);
|
||||||
|
ImGui::SetItemTooltip("Limiting compute can slow down things like filetransfers!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
ImGui::EndMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
cg.render();
|
|
||||||
sw.render();
|
|
||||||
tuiu.render();
|
|
||||||
tdch.render();
|
|
||||||
|
|
||||||
if constexpr (false) {
|
if constexpr (false) {
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
if (
|
||||||
{ // texture tests
|
_fps_perf_mode > 1 // TODO: magic
|
||||||
const size_t width = 8;
|
) {
|
||||||
const size_t height = 8;
|
// powersave forces 250ms
|
||||||
#define W 0xff, 0xff, 0xff, 0xff
|
_render_interval = 1.f/4.f;
|
||||||
#define B 0x00, 0x00, 0x00, 0xff
|
} else if (
|
||||||
#define P 0xff, 0x00, 0xff, 0xff
|
_time_since_event > 1.f && ( // 1sec cool down
|
||||||
static uint8_t raw_pixel[width*height*4] {
|
_fps_perf_mode == 1 || // TODO: magic
|
||||||
P, W, W, W, W, W, W, P,
|
_window_hidden
|
||||||
W, W, W, W, W, W, W, W,
|
)
|
||||||
W, W, W, W, W, W, W, W,
|
) {
|
||||||
W, W, W, B, B, W, W, W,
|
_render_interval = std::min<float>(1.f/4.f, pm_interval);
|
||||||
W, W, W, B, B, W, W, W,
|
} else {
|
||||||
W, W, W, W, W, W, W, W,
|
_render_interval = std::min<float>(1.f/60.f, pm_interval);
|
||||||
W, W, W, W, W, W, W, W,
|
|
||||||
P, W, W, W, W, W, W, P,
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint64_t texture = sdlrtu.uploadRGBA(raw_pixel, width, height);
|
|
||||||
|
|
||||||
if (ImGui::Begin("test texture")) {
|
|
||||||
ImGui::Text("test texture windoajsdf");
|
|
||||||
|
|
||||||
ImGui::Image(reinterpret_cast<void*>(texture), {width*10, height*10});
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
|
||||||
}
|
_time_since_event += time_delta;
|
||||||
#endif
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
||||||
|
quit = !tc.iterate(); // compute
|
||||||
|
|
||||||
|
tcm.iterate(time_delta); // compute
|
||||||
|
|
||||||
|
tam.iterate(); // compute
|
||||||
|
|
||||||
|
const float pm_interval = pm.tick(time_delta); // compute
|
||||||
|
|
||||||
|
tdch.tick(time_delta); // compute
|
||||||
|
|
||||||
|
mts.iterate(); // compute
|
||||||
|
|
||||||
|
_min_tick_interval = std::max<float>(
|
||||||
|
std::min<float>(
|
||||||
|
tc.toxIterationInterval()/1000.f,
|
||||||
|
pm_interval
|
||||||
|
//0.03f // HACK: 30ms upper bound, should be the same as tox but will change
|
||||||
|
),
|
||||||
|
(_compute_perf_mode == 0 ? 0.001f : 0.1f) // in powersave fix the lowerbound to 100ms
|
||||||
|
);
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,6 @@ extern "C" {
|
|||||||
struct MainScreen final : public Screen {
|
struct MainScreen final : public Screen {
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point last_time = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
SimpleConfigModel conf;
|
SimpleConfigModel conf;
|
||||||
Contact3Registry cr;
|
Contact3Registry cr;
|
||||||
RegistryMessageModel rmm;
|
RegistryMessageModel rmm;
|
||||||
@ -66,6 +64,10 @@ struct MainScreen final : public Screen {
|
|||||||
ToxUIUtils tuiu;
|
ToxUIUtils tuiu;
|
||||||
ToxDHTCapHisto tdch;
|
ToxDHTCapHisto tdch;
|
||||||
|
|
||||||
|
bool _window_hidden {false};
|
||||||
|
bool _window_hidden_ts {0};
|
||||||
|
float _time_since_event {0.f};
|
||||||
|
|
||||||
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
||||||
~MainScreen(void);
|
~MainScreen(void);
|
||||||
|
|
||||||
@ -73,6 +75,18 @@ struct MainScreen final : public Screen {
|
|||||||
|
|
||||||
// return nullptr if not next
|
// return nullptr if not next
|
||||||
// sets bool quit to true if exit
|
// sets bool quit to true if exit
|
||||||
Screen* poll(bool&) override;
|
Screen* render(float time_delta, bool&) override;
|
||||||
|
Screen* tick(float time_delta, bool&) override;
|
||||||
|
|
||||||
|
// 0 - normal
|
||||||
|
// 1 - power save
|
||||||
|
int _fps_perf_mode {0};
|
||||||
|
int _compute_perf_mode {0};
|
||||||
|
|
||||||
|
float _render_interval {1.f/60.f};
|
||||||
|
float _min_tick_interval {0.f};
|
||||||
|
|
||||||
|
float nextRender(void) override { return _render_interval; }
|
||||||
|
float nextTick(void) override { return _min_tick_interval; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,14 +2,21 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
// all time values are in seconds
|
||||||
struct Screen {
|
struct Screen {
|
||||||
virtual ~Screen(void) = default;
|
virtual ~Screen(void) = default;
|
||||||
|
|
||||||
// return true if handled
|
// return true if handled
|
||||||
virtual bool handleEvent(SDL_Event& e) { return false; }
|
virtual bool handleEvent(SDL_Event&) { return false; }
|
||||||
|
|
||||||
// return nullptr if not next
|
// return nullptr if not next
|
||||||
// sets bool quit to true if exit
|
// sets bool quit to true if exit
|
||||||
virtual Screen* poll(bool& quit) = 0;
|
// both render and tick get called in the selfreported intervals
|
||||||
|
virtual Screen* render(float time_delta, bool& quit) = 0; // pure since this is a graphical app
|
||||||
|
virtual Screen* tick(float time_delta, bool& quit) = 0;
|
||||||
|
|
||||||
|
// TODO: const?
|
||||||
|
virtual float nextRender(void) { return 1.f/60.f; }
|
||||||
|
virtual float nextTick(void) { return 0.03f; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ void SendImagePopup::sendMemory(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendImagePopup::render(void) {
|
void SendImagePopup::render(float time_delta) {
|
||||||
if (_open_popup) {
|
if (_open_popup) {
|
||||||
_open_popup = false;
|
_open_popup = false;
|
||||||
ImGui::OpenPopup("send image##SendImagePopup");
|
ImGui::OpenPopup("send image##SendImagePopup");
|
||||||
@ -171,7 +171,7 @@ void SendImagePopup::render(void) {
|
|||||||
|
|
||||||
preview_image.doAnimation(getNowMS());
|
preview_image.doAnimation(getNowMS());
|
||||||
|
|
||||||
time += 1.f/60.f; // TODO: actual delay
|
time += time_delta;
|
||||||
time = fmod(time, 1.f); // fract()
|
time = fmod(time, 1.f); // fract()
|
||||||
|
|
||||||
//ImGui::Text("send file....\n......");
|
//ImGui::Text("send file....\n......");
|
||||||
|
@ -71,6 +71,6 @@ struct SendImagePopup {
|
|||||||
// from file_path
|
// from file_path
|
||||||
|
|
||||||
// call this each frame
|
// call this each frame
|
||||||
void render(void);
|
void render(float time_delta);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) {
|
StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen* StartScreen::poll(bool&) {
|
Screen* StartScreen::render(float, bool&) {
|
||||||
|
|
||||||
// TODO: imgui tox profile selector?
|
// TODO: imgui tox profile selector?
|
||||||
|
|
||||||
@ -137,3 +137,7 @@ Screen* StartScreen::poll(bool&) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Screen* StartScreen::tick(float, bool&) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ struct StartScreen final : public Screen {
|
|||||||
|
|
||||||
// return nullptr if not next
|
// return nullptr if not next
|
||||||
// sets bool quit to true if exit
|
// sets bool quit to true if exit
|
||||||
Screen* poll(bool&) override;
|
Screen* render(float, bool&) override;
|
||||||
|
Screen* tick(float, bool&) override;
|
||||||
|
|
||||||
|
// use default nextRender and nextTick
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user