mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-07-18 16:43:28 -05:00
Prepare infrastructure for multi-device selection
This commit is contained in:
parent
17dddfef20
commit
89b9ceb2a9
|
|
@ -4,6 +4,7 @@
|
|||
#include "utils.hpp"
|
||||
#include "hw_defs.hpp"
|
||||
#include "capture_structs.hpp"
|
||||
#include "frontend.hpp"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FTD3XX_STATIC
|
||||
|
|
@ -33,6 +34,6 @@ struct CaptureData {
|
|||
CaptureStatus status;
|
||||
};
|
||||
|
||||
bool connect(bool print_failed, CaptureData* capture_data);
|
||||
bool connect(bool print_failed, CaptureData* capture_data, FrontendData* frontend_data);
|
||||
void captureCall(CaptureData* capture_data);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -167,6 +167,8 @@ private:
|
|||
DisplayData* display_data;
|
||||
AudioData* audio_data;
|
||||
std::mutex* events_access;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> last_mouse_action_time;
|
||||
const float mouse_timeout = 5.0f;
|
||||
|
||||
sf::Texture in_tex;
|
||||
|
||||
|
|
@ -231,6 +233,14 @@ private:
|
|||
void setWinSize(bool is_main_thread);
|
||||
};
|
||||
|
||||
void update_output(WindowScreen &top_screen, WindowScreen &bot_screen, WindowScreen &joint_screen, bool &reload, bool split, double frame_time, VideoOutputData *out_buf);
|
||||
struct FrontendData {
|
||||
WindowScreen *top_screen;
|
||||
WindowScreen *bot_screen;
|
||||
WindowScreen *joint_screen;
|
||||
DisplayData display_data;
|
||||
bool reload;
|
||||
};
|
||||
|
||||
void update_output(FrontendData* frontend_data, double frame_time = 0, VideoOutputData *out_buf = NULL);
|
||||
void screen_display_thread(WindowScreen *screen, CaptureStatus* capture_status);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ static void list_devices(DevicesList &devices_list) {
|
|||
}
|
||||
}
|
||||
|
||||
static int choose_device(DevicesList &devices_list) {
|
||||
static int choose_device(DevicesList &devices_list, FrontendData* frontend_data) {
|
||||
if(devices_list.numValidDevices == 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
|
@ -61,7 +61,7 @@ static void preemptive_close_connection(CaptureData* capture_data) {
|
|||
FT_Close(capture_data->handle);
|
||||
}
|
||||
|
||||
bool connect(bool print_failed, CaptureData* capture_data) {
|
||||
bool connect(bool print_failed, CaptureData* capture_data, FrontendData* frontend_data) {
|
||||
capture_data->status.new_error_text = false;
|
||||
if (capture_data->status.connected) {
|
||||
capture_data->status.close_success = false;
|
||||
|
|
@ -89,7 +89,7 @@ bool connect(bool print_failed, CaptureData* capture_data) {
|
|||
return false;
|
||||
}
|
||||
|
||||
int chosen_device = choose_device(devices_list);
|
||||
int chosen_device = choose_device(devices_list, frontend_data);
|
||||
if(chosen_device == -1) {
|
||||
if(print_failed) {
|
||||
capture_data->status.error_text = "No device was selected";
|
||||
|
|
|
|||
|
|
@ -79,6 +79,12 @@ void WindowScreen::reload() {
|
|||
|
||||
void WindowScreen::poll() {
|
||||
double old_scaling = 0.0;
|
||||
if(this->m_info.is_fullscreen && this->m_info.show_mouse) {
|
||||
auto curr_time = std::chrono::high_resolution_clock::now();
|
||||
const std::chrono::duration<double> diff = curr_time - this->last_mouse_action_time;
|
||||
if(diff.count() > this->mouse_timeout)
|
||||
this->m_info.show_mouse = false;
|
||||
}
|
||||
this->poll_window();
|
||||
while(!events_queue.empty()) {
|
||||
SFEvent event_data = events_queue.front();
|
||||
|
|
@ -305,6 +311,24 @@ void WindowScreen::poll() {
|
|||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case sf::Event::MouseMoved:
|
||||
if(this->m_info.is_fullscreen) {
|
||||
this->m_info.show_mouse = true;
|
||||
this->last_mouse_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
break;
|
||||
case sf::Event::MouseButtonPressed:
|
||||
if(this->m_info.is_fullscreen) {
|
||||
this->m_info.show_mouse = true;
|
||||
this->last_mouse_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
break;
|
||||
case sf::Event::MouseButtonReleased:
|
||||
if(this->m_info.is_fullscreen) {
|
||||
this->m_info.show_mouse = true;
|
||||
this->last_mouse_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
break;
|
||||
case sf::Event::JoystickButtonPressed:
|
||||
break;
|
||||
|
|
@ -379,7 +403,10 @@ void WindowScreen::draw(double frame_time, VideoOutputData* out_buf) {
|
|||
loaded_operations = future_operations;
|
||||
if(this->m_win.isOpen() || this->loaded_operations.call_create) {
|
||||
WindowScreen::reset_operations(future_operations);
|
||||
memcpy(this->saved_buf, out_buf, sizeof(VideoOutputData));
|
||||
if(out_buf != NULL)
|
||||
memcpy(this->saved_buf, out_buf, sizeof(VideoOutputData));
|
||||
else
|
||||
memset(this->saved_buf, 0, sizeof(VideoOutputData));
|
||||
loaded_info = m_info;
|
||||
this->notification->setTextFactor(this->loaded_info.menu_scaling_factor);
|
||||
this->notification->prepareRenderText();
|
||||
|
|
|
|||
|
|
@ -189,13 +189,12 @@ void soundCall(AudioData *audio_data, CaptureData* capture_data) {
|
|||
|
||||
void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
||||
VideoOutputData *out_buf;
|
||||
VideoOutputData *null_buf;
|
||||
double *curr_fps_array;
|
||||
int num_elements_fps_array = 0;
|
||||
int curr_out, prev_out = NUM_CONCURRENT_DATA_BUFFERS - 1;
|
||||
DisplayData display_data;
|
||||
display_data.split = false;
|
||||
bool reload = true;
|
||||
FrontendData frontend_data;
|
||||
frontend_data.display_data.split = false;
|
||||
frontend_data.reload = true;
|
||||
bool skip_io = false;
|
||||
int num_allowed_blanks = MAX_ALLOWED_BLANKS;
|
||||
double last_frame_time = 0;
|
||||
|
|
@ -213,17 +212,18 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
std::string layout_path = cfg_dir + "/presets/";
|
||||
|
||||
out_buf = new VideoOutputData;
|
||||
null_buf = new VideoOutputData;
|
||||
curr_fps_array = new double[FPS_WINDOW_SIZE];
|
||||
memset(out_buf, 0, sizeof(VideoOutputData));
|
||||
memset(null_buf, 0, sizeof(VideoOutputData));
|
||||
|
||||
WindowScreen top_screen(WindowScreen::ScreenType::TOP, &display_data, audio_data, &events_access);
|
||||
WindowScreen bot_screen(WindowScreen::ScreenType::BOTTOM, &display_data, audio_data, &events_access);
|
||||
WindowScreen joint_screen(WindowScreen::ScreenType::JOINT, &display_data, audio_data, &events_access);
|
||||
WindowScreen top_screen(WindowScreen::ScreenType::TOP, &frontend_data.display_data, audio_data, &events_access);
|
||||
WindowScreen bot_screen(WindowScreen::ScreenType::BOTTOM, &frontend_data.display_data, audio_data, &events_access);
|
||||
WindowScreen joint_screen(WindowScreen::ScreenType::JOINT, &frontend_data.display_data, audio_data, &events_access);
|
||||
frontend_data.top_screen = &top_screen;
|
||||
frontend_data.bot_screen = &bot_screen;
|
||||
frontend_data.joint_screen = &joint_screen;
|
||||
|
||||
if(!skip_io) {
|
||||
load(base_path, base_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, display_data, audio_data, out_text_data);
|
||||
load(base_path, base_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, frontend_data.display_data, audio_data, out_text_data);
|
||||
}
|
||||
|
||||
top_screen.build();
|
||||
|
|
@ -234,7 +234,7 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
std::thread bot_thread(screen_display_thread, &bot_screen, &capture_data->status);
|
||||
std::thread joint_thread(screen_display_thread, &joint_screen, &capture_data->status);
|
||||
|
||||
capture_data->status.connected = connect(true, capture_data);
|
||||
capture_data->status.connected = connect(true, capture_data, &frontend_data);
|
||||
if(capture_data->status.connected)
|
||||
ConnectedOutTextGenerator(out_text_data, capture_data);
|
||||
|
||||
|
|
@ -259,7 +259,7 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
}
|
||||
}
|
||||
|
||||
update_output(top_screen, bot_screen, joint_screen, reload, display_data.split, frame_time, out_buf);
|
||||
update_output(&frontend_data, frame_time, out_buf);
|
||||
last_frame_time = frame_time;
|
||||
|
||||
curr_fps_array[num_elements_fps_array % FPS_WINDOW_SIZE] = 1.0 / frame_time;
|
||||
|
|
@ -271,9 +271,9 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
VideoOutputData *chosen_buf = out_buf;
|
||||
if(capture_data->status.cooldown_curr_in) {
|
||||
last_frame_time = 0;
|
||||
chosen_buf = null_buf;
|
||||
chosen_buf = NULL;
|
||||
}
|
||||
update_output(top_screen, bot_screen, joint_screen, reload, display_data.split, last_frame_time, chosen_buf);
|
||||
update_output(&frontend_data, last_frame_time, chosen_buf);
|
||||
}
|
||||
|
||||
prev_out = curr_out;
|
||||
|
|
@ -294,7 +294,7 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
fps_sum += curr_fps_array[i];
|
||||
|
||||
if(!capture_data->status.connected)
|
||||
update_output(top_screen, bot_screen, joint_screen, reload, display_data.split, 0, null_buf);
|
||||
update_output(&frontend_data);
|
||||
|
||||
int load_index = 0;
|
||||
int save_index = 0;
|
||||
|
|
@ -303,7 +303,7 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
joint_screen.poll();
|
||||
|
||||
if(top_screen.open_capture() || bot_screen.open_capture() || joint_screen.open_capture()) {
|
||||
capture_data->status.connected = connect(true, capture_data);
|
||||
capture_data->status.connected = connect(true, capture_data, &frontend_data);
|
||||
if(capture_data->status.connected)
|
||||
ConnectedOutTextGenerator(out_text_data, capture_data);
|
||||
}
|
||||
|
|
@ -315,17 +315,17 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
if((load_index = top_screen.load_data()) || (load_index = bot_screen.load_data()) || (load_index = joint_screen.load_data())) {
|
||||
if (!skip_io) {
|
||||
std::string layout_name = LayoutNameGenerator(load_index);
|
||||
bool op_success = load(layout_path, layout_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, display_data, audio_data, out_text_data);
|
||||
bool op_success = load(layout_path, layout_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, frontend_data.display_data, audio_data, out_text_data);
|
||||
if(op_success)
|
||||
UpdateOutText(out_text_data, "Layout loaded from: " + layout_path + layout_name, "Layout " + std::to_string(load_index) + " loaded", TEXT_KIND_SUCCESS);
|
||||
reload = true;
|
||||
frontend_data.reload = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((save_index = top_screen.save_data()) || (save_index = bot_screen.save_data()) || (save_index = joint_screen.save_data())) {
|
||||
if (!skip_io) {
|
||||
std::string layout_name = LayoutNameGenerator(save_index);
|
||||
bool op_success = save(layout_path, layout_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, display_data, audio_data, out_text_data);
|
||||
bool op_success = save(layout_path, layout_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, frontend_data.display_data, audio_data, out_text_data);
|
||||
if(op_success)
|
||||
UpdateOutText(out_text_data, "Layout saved to: " + layout_path + layout_name, "Layout " + std::to_string(save_index) + " saved", TEXT_KIND_SUCCESS);
|
||||
}
|
||||
|
|
@ -362,7 +362,7 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
joint_screen.after_thread_join();
|
||||
|
||||
if (!skip_io) {
|
||||
save(base_path, base_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, display_data, audio_data, out_text_data);
|
||||
save(base_path, base_name, top_screen.m_info, bot_screen.m_info, joint_screen.m_info, frontend_data.display_data, audio_data, out_text_data);
|
||||
}
|
||||
|
||||
if(!out_text_data.consumed) {
|
||||
|
|
@ -371,7 +371,6 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) {
|
|||
}
|
||||
|
||||
delete out_buf;
|
||||
delete null_buf;
|
||||
delete []curr_fps_array;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,20 +139,20 @@ std::string save_screen_info(std::string base, const ScreenInfo &info) {
|
|||
return out;
|
||||
}
|
||||
|
||||
void update_output(WindowScreen &top_screen, WindowScreen &bot_screen, WindowScreen &joint_screen, bool &reload, bool split, double frame_time, VideoOutputData *out_buf) {
|
||||
if(reload) {
|
||||
top_screen.reload();
|
||||
bot_screen.reload();
|
||||
joint_screen.reload();
|
||||
reload = false;
|
||||
void update_output(FrontendData* frontend_data, double frame_time, VideoOutputData *out_buf) {
|
||||
if(frontend_data->reload) {
|
||||
frontend_data->top_screen->reload();
|
||||
frontend_data->bot_screen->reload();
|
||||
frontend_data->joint_screen->reload();
|
||||
frontend_data->reload = false;
|
||||
}
|
||||
// Make sure the window is closed before showing split/non-split
|
||||
if(split)
|
||||
joint_screen.draw(frame_time, out_buf);
|
||||
top_screen.draw(frame_time, out_buf);
|
||||
bot_screen.draw(frame_time, out_buf);
|
||||
if(!split)
|
||||
joint_screen.draw(frame_time, out_buf);
|
||||
if(frontend_data->display_data.split)
|
||||
frontend_data->joint_screen->draw(frame_time, out_buf);
|
||||
frontend_data->top_screen->draw(frame_time, out_buf);
|
||||
frontend_data->bot_screen->draw(frame_time, out_buf);
|
||||
if(!frontend_data->display_data.split)
|
||||
frontend_data->joint_screen->draw(frame_time, out_buf);
|
||||
}
|
||||
|
||||
void screen_display_thread(WindowScreen *screen, CaptureStatus* capture_status) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user