From 2cbb14acda02b2a50224fda082d5ae33b131b1bd Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sun, 9 Jun 2024 19:48:56 +0200 Subject: [PATCH] Improve performance gain of "Fast Poll", and rename it to better explain it --- README.md | 2 +- include/frontend.hpp | 4 +- source/Menus/VideoMenu.cpp | 2 +- source/WindowScreen_Menu.cpp | 96 +++++++++++++++++++----------------- source/cc3dsfs.cpp | 20 +++++--- 5 files changed, 68 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 527a9c2..7bf0d29 100755 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ The name of profiles can be changed by altering the __name__ field in its file. - USB Hubs can be the cause of connection issues. If you're having problems, try checking whether the 3DS connects fine or not without any other devices connected. - Fullscreen mode on MacOS may mistake the screen for being bigger than what it really is. Changing the resolution to the proper one of the screen in the _Resolution Settings_ under Video Settings will fix the issue. - Current font in use: OFL Sorts Mill Goudy TT -- Enabling/Disabling Fast Poll may slightly boost the FPS of the software, at the cost of an extremely slight decrease in frame latency. Disabled by default (as when the FPS are greater than the CC's, it doesn't do anything). +- Enabling Slow Poll may slightly boost the FPS of the software, at the cost of an extremely slight decrease in frame latency, and slower reaction times of the software to key presses. Disabled by default (as when the FPS are greater than the CC's, it's not reccomended). - When compiling on a Raspberry Pi, to enable usage of GPIO, use: ``` cmake -B build -DRASPBERRY_PI_COMPILATION=TRUE ; cmake --build build --config Release diff --git a/include/frontend.hpp b/include/frontend.hpp index a3dcbb2..9899341 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -56,7 +56,7 @@ public: void build(); void reload(); - void poll(); + void poll(bool do_everything = true); void close(); void display_call(bool is_main_thread); void display_thread(); @@ -216,7 +216,7 @@ private: void bottom_pos_change(int new_bottom_pos); bool query_reset_request(); void reset_held_times(); - void poll_window(); + void poll_window(bool do_everything); bool common_poll(SFEvent &event_data); bool main_poll(SFEvent &event_data); bool no_menu_poll(SFEvent &event_data); diff --git a/source/Menus/VideoMenu.cpp b/source/Menus/VideoMenu.cpp index 26afe15..e876148 100755 --- a/source/Menus/VideoMenu.cpp +++ b/source/Menus/VideoMenu.cpp @@ -151,7 +151,7 @@ static const VideoMenuOptionInfo bottom_one_rotation_option = { .out_action = VIDEO_MENU_BOTTOM_ROTATION_DEC}; static const VideoMenuOptionInfo fast_poll_option = { -.base_name = "Disable Fast Poll", .false_name = "Enable Fast Poll", +.base_name = "Disable Slow Poll", .false_name = "Enable Slow Poll", .active_fullscreen = true, .active_windowed_screen = true, .active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true, .is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION, diff --git a/source/WindowScreen_Menu.cpp b/source/WindowScreen_Menu.cpp index 781520a..17bcc44 100755 --- a/source/WindowScreen_Menu.cpp +++ b/source/WindowScreen_Menu.cpp @@ -134,7 +134,7 @@ void WindowScreen::blur_change() { void WindowScreen::fast_poll_change() { this->display_data->fast_poll = !this->display_data->fast_poll; - this->print_notification_on_off("Fast Poll", this->display_data->fast_poll); + this->print_notification_on_off("Slow Poll", this->display_data->fast_poll); } void WindowScreen::padding_change() { @@ -972,7 +972,7 @@ bool WindowScreen::main_poll(SFEvent &event_data) { return consumed; } -void WindowScreen::poll() { +void WindowScreen::poll(bool do_everything) { if(this->close_capture()) return; if((this->m_info.is_fullscreen || this->display_data->mono_app_mode) && this->m_info.show_mouse) { @@ -981,7 +981,7 @@ void WindowScreen::poll() { if(diff.count() > this->mouse_timeout) this->m_info.show_mouse = false; } - this->poll_window(); + this->poll_window(do_everything); bool done = false; while(!events_queue.empty()) { if(done) @@ -1638,55 +1638,59 @@ void WindowScreen::reset_held_times() { check_held_reset(false, this->touch_action); } -void WindowScreen::poll_window() { +void WindowScreen::poll_window(bool do_everything) { if(this->m_win.isOpen()) { - auto curr_time = std::chrono::high_resolution_clock::now(); - const std::chrono::duration diff = curr_time - this->last_poll_time; - FPSArrayInsertElement(&poll_fps, diff.count()); - this->last_poll_time = curr_time; - sf::Event event; - while(this->m_win.pollEvent(event)) { - int joystickId = event.joystickConnect.joystickId; - if(event.type == sf::Event::JoystickButtonPressed) - joystickId = event.joystickButton.joystickId; - else if(event.type == sf::Event::JoystickMoved) - joystickId = event.joystickMove.joystickId; - int mouse_x = event.mouseButton.x; - int mouse_y = event.mouseButton.y; - if(event.type == sf::Event::MouseMoved) { - mouse_x = event.mouseMove.x; - mouse_y = event.mouseMove.y; + if(do_everything) { + auto curr_time = std::chrono::high_resolution_clock::now(); + const std::chrono::duration diff = curr_time - this->last_poll_time; + FPSArrayInsertElement(&poll_fps, diff.count()); + this->last_poll_time = curr_time; + sf::Event event; + while(this->m_win.pollEvent(event)) { + int joystickId = event.joystickConnect.joystickId; + if(event.type == sf::Event::JoystickButtonPressed) + joystickId = event.joystickButton.joystickId; + else if(event.type == sf::Event::JoystickMoved) + joystickId = event.joystickMove.joystickId; + int mouse_x = event.mouseButton.x; + int mouse_y = event.mouseButton.y; + if(event.type == sf::Event::MouseMoved) { + mouse_x = event.mouseMove.x; + mouse_y = event.mouseMove.y; + } + events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, 0.0, event.mouseButton.button, mouse_x, mouse_y, false, false); } - events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, 0.0, event.mouseButton.button, mouse_x, mouse_y, false, false); } if(this->m_win.hasFocus()) { - check_held_reset(sf::Mouse::isButtonPressed(sf::Mouse::Right), this->right_click_action); - bool found = false; - for(int i = 0; i < sf::Joystick::Count; i++) { - if(!sf::Joystick::isConnected(i)) - continue; - if(sf::Joystick::getButtonCount(i) <= 0) - continue; - found = true; - check_held_reset(sf::Joystick::isButtonPressed(i, 0), this->controller_button_action); - break; - } - if(!found) - check_held_reset(false, this->controller_button_action); - bool touch_active = sf::Touch::isDown(0); - check_held_reset(touch_active, this->touch_action); - check_held_reset(touch_active, this->touch_right_click_action); - if(touch_active) { - sf::Vector2i touch_pos = sf::Touch::getPosition(0, this->m_win); - auto curr_time = std::chrono::high_resolution_clock::now(); - const std::chrono::duration diff = curr_time - this->touch_right_click_action.start_time; - if(diff.count() > this->touch_long_press_timer) { - events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Right, touch_pos.x, touch_pos.y, false, false); - this->touch_right_click_action.start_time = std::chrono::high_resolution_clock::now(); + if(do_everything) { + check_held_reset(sf::Mouse::isButtonPressed(sf::Mouse::Right), this->right_click_action); + bool found = false; + for(int i = 0; i < sf::Joystick::Count; i++) { + if(!sf::Joystick::isConnected(i)) + continue; + if(sf::Joystick::getButtonCount(i) <= 0) + continue; + found = true; + check_held_reset(sf::Joystick::isButtonPressed(i, 0), this->controller_button_action); + break; } - events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Left, touch_pos.x, touch_pos.y, false, false); + if(!found) + check_held_reset(false, this->controller_button_action); + bool touch_active = sf::Touch::isDown(0); + check_held_reset(touch_active, this->touch_action); + check_held_reset(touch_active, this->touch_right_click_action); + if(touch_active) { + sf::Vector2i touch_pos = sf::Touch::getPosition(0, this->m_win); + auto curr_time = std::chrono::high_resolution_clock::now(); + const std::chrono::duration diff = curr_time - this->touch_right_click_action.start_time; + if(diff.count() > this->touch_long_press_timer) { + events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Right, touch_pos.x, touch_pos.y, false, false); + this->touch_right_click_action.start_time = std::chrono::high_resolution_clock::now(); + } + events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Left, touch_pos.x, touch_pos.y, false, false); + } + joystick_axis_poll(this->events_queue); } - joystick_axis_poll(this->events_queue); extra_buttons_poll(this->events_queue); } else { diff --git a/source/cc3dsfs.cpp b/source/cc3dsfs.cpp index fe76daf..894a6a9 100755 --- a/source/cc3dsfs.cpp +++ b/source/cc3dsfs.cpp @@ -258,11 +258,11 @@ static void soundCall(AudioData *audio_data, CaptureData* capture_data) { audio.stop(); } -static void poll_all_windows(FrontendData *frontend_data, bool &polled) { +static void poll_all_windows(FrontendData *frontend_data, bool do_everything, bool &polled) { if(!polled) { - frontend_data->top_screen->poll(); - frontend_data->bot_screen->poll(); - frontend_data->joint_screen->poll(); + frontend_data->top_screen->poll(do_everything); + frontend_data->bot_screen->poll(do_everything); + frontend_data->joint_screen->poll(do_everything); polled = true; } } @@ -289,6 +289,7 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data, ExtraButtonShortcuts extra_button_shortcuts; out_text_data.consumed = true; int ret_val = 0; + int poll_timeout = 0; out_buf = new VideoOutputData; memset(out_buf, 0, sizeof(VideoOutputData)); @@ -320,6 +321,13 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data, while(capture_data->status.running) { bool polled = false; + bool poll_everything = true; + if(poll_timeout > 0) { + poll_everything = false; + poll_timeout--; + } + else if(frontend_data.display_data.fast_poll) + poll_timeout = 6; VideoOutputData *chosen_buf = out_buf; bool blank_out = false; if(capture_data->status.connected) { @@ -356,12 +364,12 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data, } if(frontend_data.display_data.fast_poll) - poll_all_windows(&frontend_data, polled); + poll_all_windows(&frontend_data, poll_everything, polled); update_output(&frontend_data, last_frame_time, chosen_buf); if(!frontend_data.display_data.fast_poll) - poll_all_windows(&frontend_data, polled); + poll_all_windows(&frontend_data, poll_everything, polled); int load_index = 0; int save_index = 0;