From f01e488c7dfbdfb97aedb2c917502a57174b543c Mon Sep 17 00:00:00 2001 From: ohyzha Date: Mon, 16 Dec 2024 16:55:07 +0200 Subject: [PATCH 1/5] disable usage of multiple threads for rendering since it's broken now --- examples/ExampleApps/BillboardExampleApp.cpp | 1 - examples/ExampleApps/CubesExampleApp.cpp | 2 +- examples/ExampleApps/TextExampleApp.cpp | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/ExampleApps/BillboardExampleApp.cpp b/examples/ExampleApps/BillboardExampleApp.cpp index 2b69d6a..068f812 100644 --- a/examples/ExampleApps/BillboardExampleApp.cpp +++ b/examples/ExampleApps/BillboardExampleApp.cpp @@ -35,7 +35,6 @@ namespace OpenVulkano void Init() override { auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); - engineConfig->SetNumThreads(4); engineConfig->SetPreferFramebufferFormatSRGB(false); engineConfig->SetFpsCap(0); // monitor's refresh rate engineConfig->SetVSync(true); diff --git a/examples/ExampleApps/CubesExampleApp.cpp b/examples/ExampleApps/CubesExampleApp.cpp index 8b3909b..391f548 100644 --- a/examples/ExampleApps/CubesExampleApp.cpp +++ b/examples/ExampleApps/CubesExampleApp.cpp @@ -51,7 +51,7 @@ namespace OpenVulkano void Init() override { auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); - engineConfig->SetNumThreads(4); + //engineConfig->SetNumThreads(4); engineConfig->SetPreferFramebufferFormatSRGB(false); std::srand(1); // Fix seed for random numbers diff --git a/examples/ExampleApps/TextExampleApp.cpp b/examples/ExampleApps/TextExampleApp.cpp index 4a97377..3436a83 100644 --- a/examples/ExampleApps/TextExampleApp.cpp +++ b/examples/ExampleApps/TextExampleApp.cpp @@ -47,7 +47,6 @@ namespace OpenVulkano void Init() override { auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); - engineConfig->SetNumThreads(4); engineConfig->SetPreferFramebufferFormatSRGB(false); std::srand(1); // Fix seed for random numbers From 387522ba51dce5cbd474b7dc60f387151ed46350 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 11:45:05 +0200 Subject: [PATCH 2/5] update ftxui version --- 3rdParty/ftxui/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdParty/ftxui/CMakeLists.txt b/3rdParty/ftxui/CMakeLists.txt index 8fc318f..d485171 100644 --- a/3rdParty/ftxui/CMakeLists.txt +++ b/3rdParty/ftxui/CMakeLists.txt @@ -8,7 +8,7 @@ FetchContent_Declare( ftxui EXCLUDE_FROM_ALL GIT_REPOSITORY ${FTXUI_REPO} - GIT_TAG v5.0.0 + GIT_TAG daa421fa6ad97c8a6c9bd43f77c81862bfa52c77 GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(ftxui) \ No newline at end of file From 36c3bb36687524d3bb86d286b6787e1878e460d7 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 11:45:29 +0200 Subject: [PATCH 3/5] add CtrlC and CtrlZ events handling --- examples/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/main.cpp b/examples/main.cpp index 002e431..8ac6541 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include // for Event, Event::Custom #include #include @@ -28,9 +29,21 @@ int main(int argc, char** argv) int selectedExample = 0; ftxui::MenuOption option; auto screen = ftxui::ScreenInteractive::TerminalOutput(); + screen.ForceHandleCtrlC(true); + //screen.ForceHandleCtrlZ(true); option.on_enter = screen.ExitLoopClosure(); auto menu = ftxui::Menu(&examples, &selectedExample, option); - + + menu |= ftxui::CatchEvent( + [&](ftxui::Event event) + { + if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ) + { + screen.ExitLoopClosure()(); + exit(0); + } + return false; + }); screen.Loop(menu); if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!"); From ddded99bf73470b2a66e3fca54ae6b5eb2ab2165 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 13:07:23 +0200 Subject: [PATCH 4/5] introduce flag for emergency menu exit --- examples/main.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index 8ac6541..e0a35b7 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -33,24 +33,30 @@ int main(int argc, char** argv) //screen.ForceHandleCtrlZ(true); option.on_enter = screen.ExitLoopClosure(); auto menu = ftxui::Menu(&examples, &selectedExample, option); - + bool emergencyExit = false; menu |= ftxui::CatchEvent( [&](ftxui::Event event) { if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ) { screen.ExitLoopClosure()(); - exit(0); + emergencyExit = true; } return false; }); screen.Loop(menu); - if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!"); + if (!emergencyExit) + { + if (selectedExample >= examples.size()) + { + throw std::runtime_error("Invalid menu selection!"); + } - std::unique_ptr app( EXAMPLE_APPS[selectedExample].second() ); + std::unique_ptr app(EXAMPLE_APPS[selectedExample].second()); - GraphicsAppManager manager(app.get()); - manager.Run(); + GraphicsAppManager manager(app.get()); + manager.Run(); + } return 0; } From e9ec896feef351396a947fa3ecd8606c8c8fd156 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 13:25:25 +0200 Subject: [PATCH 5/5] refactoring --- examples/main.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index e0a35b7..f10b998 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -33,30 +33,32 @@ int main(int argc, char** argv) //screen.ForceHandleCtrlZ(true); option.on_enter = screen.ExitLoopClosure(); auto menu = ftxui::Menu(&examples, &selectedExample, option); - bool emergencyExit = false; + bool shouldExit = false; menu |= ftxui::CatchEvent( [&](ftxui::Event event) { if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ) { screen.ExitLoopClosure()(); - emergencyExit = true; + shouldExit = true; } return false; }); screen.Loop(menu); - if (!emergencyExit) + if (shouldExit) { - if (selectedExample >= examples.size()) - { - throw std::runtime_error("Invalid menu selection!"); - } - - std::unique_ptr app(EXAMPLE_APPS[selectedExample].second()); - - GraphicsAppManager manager(app.get()); - manager.Run(); + return 0; } + + if (selectedExample >= examples.size()) + { + throw std::runtime_error("Invalid menu selection!"); + } + + std::unique_ptr app(EXAMPLE_APPS[selectedExample].second()); + + GraphicsAppManager manager(app.get()); + manager.Run(); return 0; }