Improve performance gain of "Fast Poll", and rename it to better explain it

This commit is contained in:
Lorenzooone
2024-06-09 19:48:56 +02:00
parent 21dc761796
commit 2cbb14acda
5 changed files with 68 additions and 56 deletions

View File

@@ -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,

View File

@@ -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<double> 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<double> 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<double> 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<double> 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 {

View File

@@ -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;