Try moving poll around (might make it an option later and/or move the extra buttons polling, since it's not sfml-based)

This commit is contained in:
Lorenzooone 2024-06-05 22:43:46 +02:00
parent 13eb923286
commit 444120b0e8
4 changed files with 11 additions and 19 deletions

View File

@ -43,7 +43,7 @@ class WindowScreen {
public:
ScreenInfo m_info;
WindowScreen(ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access);
WindowScreen(ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data);
~WindowScreen();
void build();
@ -91,7 +91,6 @@ private:
double frame_time;
DisplayData* display_data;
AudioData* audio_data;
std::mutex* events_access;
std::chrono::time_point<std::chrono::high_resolution_clock> last_mouse_action_time;
std::chrono::time_point<std::chrono::high_resolution_clock> last_window_creation_time;
HeldTime touch_right_click_action;

View File

@ -11,11 +11,10 @@
#define TOP_ROUNDED_PADDING 0
#define BOTTOM_ROUNDED_PADDING 5
WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access) {
WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data) {
this->m_stype = stype;
insert_basic_crops(this->possible_crops, this->m_stype);
insert_basic_pars(this->possible_pars);
this->events_access = events_access;
this->m_prepare_save = 0;
this->m_prepare_load = 0;
this->m_prepare_open = false;
@ -315,19 +314,16 @@ bool WindowScreen::window_needs_work() {
void WindowScreen::window_factory(bool is_main_thread) {
if(this->loaded_operations.call_close) {
this->events_access->lock();
this->m_win.setActive(true);
this->main_thread_owns_window = is_main_thread;
this->m_win.close();
while(!events_queue.empty())
events_queue.pop();
this->events_access->unlock();
this->loaded_operations.call_close = false;
this->loaded_operations.call_create = false;
}
if(this->loaded_operations.call_create) {
this->notification->setShowText(false);
this->events_access->lock();
this->m_win.setActive(true);
this->main_thread_owns_window = is_main_thread;
if(!this->loaded_info.is_fullscreen) {
@ -339,7 +335,6 @@ void WindowScreen::window_factory(bool is_main_thread) {
this->m_win.create(this->curr_desk_mode, this->title_factory(), sf::Style::Fullscreen);
this->last_window_creation_time = std::chrono::high_resolution_clock::now();
this->update_screen_settings();
this->events_access->unlock();
this->loaded_operations.call_create = false;
}
if(this->m_win.isOpen()) {
@ -821,10 +816,8 @@ void WindowScreen::setWinSize(bool is_main_thread) {
int win_width = this->m_win.getSize().x;
int win_height = this->m_win.getSize().y;
if((win_width != width) || (win_height != height)) {
this->events_access->lock();
this->m_win.setActive(true);
this->main_thread_owns_window = is_main_thread;
this->m_win.setSize(sf::Vector2u(width, height));
this->events_access->unlock();
}
}

View File

@ -45,6 +45,8 @@ static double FPSArrayGetAverage(FPSArray *array) {
int available_fps = FPS_WINDOW_SIZE;
if(array->index < available_fps)
available_fps = array->index;
if(available_fps == 0)
return 0.0;
double fps_sum = 0;
for(int i = 0; i < available_fps; i++)
fps_sum += array->data[i];
@ -1408,7 +1410,6 @@ void WindowScreen::poll_window() {
FPSArrayInsertElement(&poll_fps, diff.count());
this->last_poll_time = curr_time;
sf::Event event;
this->events_access->lock();
while(this->m_win.pollEvent(event)) {
int joystickId = event.joystickConnect.joystickId;
if(event.type == sf::Event::JoystickButtonPressed)
@ -1457,7 +1458,6 @@ void WindowScreen::poll_window() {
this->reset_held_times();
this->touch_right_click_action.started = false;
}
this->events_access->unlock();
}
else {
this->reset_held_times();

View File

@ -256,7 +256,6 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
frontend_data.reload = true;
bool skip_io = false;
int num_allowed_blanks = MAX_ALLOWED_BLANKS;
std::mutex events_access;
OutTextData out_text_data;
out_text_data.consumed = true;
int ret_val = 0;
@ -264,9 +263,9 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
out_buf = new VideoOutputData;
memset(out_buf, 0, sizeof(VideoOutputData));
WindowScreen top_screen(ScreenType::TOP, &capture_data->status, &frontend_data.display_data, audio_data, &events_access);
WindowScreen bot_screen(ScreenType::BOTTOM, &capture_data->status, &frontend_data.display_data, audio_data, &events_access);
WindowScreen joint_screen(ScreenType::JOINT, &capture_data->status, &frontend_data.display_data, audio_data, &events_access);
WindowScreen top_screen(ScreenType::TOP, &capture_data->status, &frontend_data.display_data, audio_data);
WindowScreen bot_screen(ScreenType::BOTTOM, &capture_data->status, &frontend_data.display_data, audio_data);
WindowScreen joint_screen(ScreenType::JOINT, &capture_data->status, &frontend_data.display_data, audio_data);
frontend_data.top_screen = &top_screen;
frontend_data.bot_screen = &bot_screen;
frontend_data.joint_screen = &joint_screen;
@ -325,13 +324,14 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
chosen_buf = NULL;
}
top_screen.poll();
bot_screen.poll();
joint_screen.poll();
update_output(&frontend_data, last_frame_time, chosen_buf);
int load_index = 0;
int save_index = 0;
top_screen.poll();
bot_screen.poll();
joint_screen.poll();
if(top_screen.open_capture() || bot_screen.open_capture() || joint_screen.open_capture()) {
capture_data->status.connected = connect(true, capture_data, &frontend_data);