From 861c55f13169f16102f9d541e7151ea95a566ed5 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Tue, 30 Apr 2024 18:11:04 +0200 Subject: [PATCH] Setup window titles --- include/3dscapture.hpp | 1 - include/capture_structs.hpp | 1 + include/frontend.hpp | 10 +++++++--- source/3dscapture.cpp | 25 +++++++++++++++++-------- source/WindowScreen.cpp | 33 +++++++++++++++++++++++++++------ source/cc3dsfs.cpp | 14 +++++++------- source/frontend.cpp | 4 ++-- 7 files changed, 61 insertions(+), 27 deletions(-) diff --git a/include/3dscapture.hpp b/include/3dscapture.hpp index a8ce720..7d6437e 100755 --- a/include/3dscapture.hpp +++ b/include/3dscapture.hpp @@ -27,7 +27,6 @@ struct CaptureData { ULONG read[NUM_CONCURRENT_DATA_BUFFERS]; CaptureReceived capture_buf[NUM_CONCURRENT_DATA_BUFFERS]; double time_in_buf[NUM_CONCURRENT_DATA_BUFFERS]; - char chosen_serial_number[SERIAL_NUMBER_SIZE]; CaptureStatus status; }; diff --git a/include/capture_structs.hpp b/include/capture_structs.hpp index 16585e1..4551ed8 100755 --- a/include/capture_structs.hpp +++ b/include/capture_structs.hpp @@ -26,6 +26,7 @@ struct PACKED CaptureReceived { #pragma pack(pop) struct CaptureStatus { + std::string serial_number; std::string error_text; bool new_error_text; volatile int curr_in = 0; diff --git a/include/frontend.hpp b/include/frontend.hpp index da8bcd7..a848162 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -58,7 +58,7 @@ public: enum ScreenType { TOP, BOTTOM, JOINT }; ScreenInfo m_info; - WindowScreen(WindowScreen::ScreenType stype, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access); + WindowScreen(WindowScreen::ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access); ~WindowScreen(); void build(); @@ -66,7 +66,7 @@ public: void poll(); void close(); void display_call(bool is_main_thread); - void display_thread(CaptureStatus* capture_status); + void display_thread(); void end(); void after_thread_join(); void draw(double frame_time, VideoOutputData* out_buf); @@ -89,12 +89,14 @@ private: bool call_blur; bool call_screen_settings_update; }; + CaptureStatus* capture_status; std::string win_title; sf::RenderWindow m_win; int m_width, m_height; int m_window_width, m_window_height; int m_prepare_load; int m_prepare_save; + bool last_connected_status; bool m_prepare_open; bool m_prepare_quit; bool font_load_success; @@ -162,6 +164,7 @@ private: int get_fullscreen_offset_y(int top_width, int top_height, int bot_width, int bot_height); void resize_window_and_out_rects(bool do_work = true); void create_window(bool re_prepare_size); + std::string title_factory(); void update_view_size(); void open(); void update_screen_settings(); @@ -169,6 +172,7 @@ private: sf::Vector2f getShownScreenSize(bool is_top, Crop &crop_kind); void crop(); void setWinSize(bool is_main_thread); + void update_connection(); }; struct FrontendData { @@ -181,5 +185,5 @@ struct FrontendData { void default_sleep(); void update_output(FrontendData* frontend_data, double frame_time = 0, VideoOutputData *out_buf = NULL); -void screen_display_thread(WindowScreen *screen, CaptureStatus* capture_status); +void screen_display_thread(WindowScreen *screen); #endif diff --git a/source/3dscapture.cpp b/source/3dscapture.cpp index ddf2cc3..93e9eae 100755 --- a/source/3dscapture.cpp +++ b/source/3dscapture.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #define BULK_OUT 0x02 #define BULK_IN 0x82 @@ -13,6 +14,8 @@ #define FIFO_CHANNEL 0 #endif +//#define DEBUG_DEVICES_PRINT_DESCRIPTION_INFOS + static void list_devices(DevicesList &devices_list) { FT_STATUS ftStatus; DWORD numDevs = 0; @@ -34,12 +37,15 @@ static void list_devices(DevicesList &devices_list) { { ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, NULL, SerialNumber, Description, &ftHandle); + #ifdef DEBUG_DEVICES_PRINT_DESCRIPTION_INFOS + std::cout << "Total: " << numDevs << " - Index: " << i << " - " << std::string(Description) << " - " << std::string(SerialNumber) << std::endl; + #endif if (!FT_FAILED(ftStatus)) { - for(int i = 0; i < sizeof(valid_descriptions) / sizeof(*valid_descriptions); i++) { - if(Description == valid_descriptions[i]) { - for(int i = 0; i < REAL_SERIAL_NUMBER_SIZE; i++) - devices_list.serialNumbers[(SERIAL_NUMBER_SIZE * devices_list.numValidDevices) + i] = SerialNumber[i]; + for(int j = 0; j < sizeof(valid_descriptions) / sizeof(*valid_descriptions); j++) { + if(Description == valid_descriptions[j]) { + for(int k = 0; k < REAL_SERIAL_NUMBER_SIZE; k++) + devices_list.serialNumbers[(SERIAL_NUMBER_SIZE * devices_list.numValidDevices) + k] = SerialNumber[k]; devices_list.serialNumbers[(SERIAL_NUMBER_SIZE * devices_list.numValidDevices) + REAL_SERIAL_NUMBER_SIZE] = 0; ++devices_list.numValidDevices; break; @@ -132,11 +138,14 @@ bool connect(bool print_failed, CaptureData* capture_data, FrontendData* fronten return false; } - for(int i = 0; i < SERIAL_NUMBER_SIZE; i++) - capture_data->chosen_serial_number[i] = devices_list.serialNumbers[(SERIAL_NUMBER_SIZE * chosen_device) + i]; + char SerialNumber[SERIAL_NUMBER_SIZE] = { 0 }; + for(int i = 0; i < REAL_SERIAL_NUMBER_SIZE; i++) + SerialNumber[i] = devices_list.serialNumbers[(SERIAL_NUMBER_SIZE * chosen_device) + i]; + SerialNumber[REAL_SERIAL_NUMBER_SIZE] = 0; delete []devices_list.serialNumbers; + capture_data->status.serial_number = "N3DSXL - " + std::string(SerialNumber); - if (FT_Create(capture_data->chosen_serial_number, FT_OPEN_BY_SERIAL_NUMBER, &capture_data->handle)) { + if (FT_Create(SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &capture_data->handle)) { if(print_failed) { capture_data->status.error_text = "Create failed"; capture_data->status.new_error_text = true; @@ -306,7 +315,7 @@ void captureCall(CaptureData* capture_data) { while(capture_data->status.running) { if (!capture_data->status.connected) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000/USB_CHECKS_PER_SECOND)); + default_sleep(); continue; } diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index 111f0b3..230aa5c 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -16,7 +16,7 @@ static int bot_screen_crop_x[] = {0, 0, 0, (BOT_WIDTH_3DS - WIDTH_DS) / 2, 0, 0, static int bot_screen_crop_y[] = {0, 0, 0, HEIGHT_3DS - HEIGHT_DS, 0, 0, 0, 0, 0, 0}; static std::string crop_names[] = {"3DS", "16:10", "Scaled DS", "Native DS", "Scaled GBA", "Native GBA", "Scaled VC GB", "VC GB", "VC SNES", "VC NES"}; -WindowScreen::WindowScreen(WindowScreen::ScreenType stype, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access) { +WindowScreen::WindowScreen(WindowScreen::ScreenType stype, CaptureStatus* capture_status, DisplayData* display_data, AudioData* audio_data, std::mutex* events_access) { this->m_stype = stype; this->events_access = events_access; this->m_prepare_save = 0; @@ -40,6 +40,8 @@ WindowScreen::WindowScreen(WindowScreen::ScreenType stype, DisplayData* display_ this->win_title += "_top"; if(this->m_stype == WindowScreen::ScreenType::BOTTOM) this->win_title += "_bot"; + this->last_connected_status = false; + this->capture_status = capture_status; } WindowScreen::~WindowScreen() { @@ -438,10 +440,10 @@ void WindowScreen::display_call(bool is_main_thread) { this->done_display = true; } -void WindowScreen::display_thread(CaptureStatus* capture_status) { - while(capture_status->running) { +void WindowScreen::display_thread() { + while(this->capture_status->running) { this->display_lock.lock(); - if(!capture_status->running) + if(!this->capture_status->running) break; this->free_ownership_of_window(false); this->is_thread_done = true; @@ -528,6 +530,15 @@ void WindowScreen::end_connection_menu() { this->display_data->curr_menu = DEFAULT_MENU_TYPE; } +void WindowScreen::update_connection() { + if(this->last_connected_status == this->capture_status->connected) + return; + this->last_connected_status = this->capture_status->connected; + if(this->m_win.isOpen()) { + this->m_win.setTitle(this->title_factory()); + } +} + void WindowScreen::print_notification(std::string text, TextKind kind) { this->notification->setText(text); this->notification->setRectangleKind(kind); @@ -686,6 +697,8 @@ bool WindowScreen::window_needs_work() { int win_height = this->m_win.getSize().y; if((win_width != width) || (win_height != height)) return true; + if(this->last_connected_status != this->capture_status->connected) + return true; return false; } @@ -708,11 +721,11 @@ void WindowScreen::window_factory(bool is_main_thread) { this->main_thread_owns_window = is_main_thread; if(!this->loaded_info.is_fullscreen) { this->update_screen_settings(); - this->m_win.create(sf::VideoMode(this->m_width, this->m_height), this->win_title); + this->m_win.create(sf::VideoMode(this->m_width, this->m_height), this->title_factory()); this->update_view_size(); } else - this->m_win.create(this->curr_desk_mode, this->win_title, sf::Style::Fullscreen); + this->m_win.create(this->curr_desk_mode, this->title_factory(), sf::Style::Fullscreen); this->update_screen_settings(); this->events_access->unlock(); this->loaded_operations.call_create = false; @@ -723,9 +736,17 @@ void WindowScreen::window_factory(bool is_main_thread) { if((is_main_thread == this->main_thread_owns_window) && (this->main_thread_owns_window == this->loaded_info.async)) { this->m_win.setActive(false); } + this->update_connection(); this->is_window_factory_done = true; } +std::string WindowScreen::title_factory() { + std::string title = this->win_title; + if(this->capture_status->connected) + title += " - " + this->capture_status->serial_number; + return title; +} + void WindowScreen::pre_texture_conversion_processing() { if(this->loaded_menu != DEFAULT_MENU_TYPE) return; diff --git a/source/cc3dsfs.cpp b/source/cc3dsfs.cpp index 04d56f9..5ce5e9a 100755 --- a/source/cc3dsfs.cpp +++ b/source/cc3dsfs.cpp @@ -53,7 +53,7 @@ void UpdateOutText(OutTextData &out_text_data, std::string full_text, std::strin } void ConnectedOutTextGenerator(OutTextData &out_text_data, CaptureData* capture_data) { - UpdateOutText(out_text_data, "Connected to " + std::string(capture_data->chosen_serial_number), "Connected", TEXT_KIND_SUCCESS); + UpdateOutText(out_text_data, "Connected to " + capture_data->status.serial_number, "Connected", TEXT_KIND_SUCCESS); } std::string LayoutNameGenerator(int index) { @@ -214,9 +214,9 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) { curr_fps_array = new double[FPS_WINDOW_SIZE]; memset(out_buf, 0, sizeof(VideoOutputData)); - 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); + WindowScreen top_screen(WindowScreen::ScreenType::TOP, &capture_data->status, &frontend_data.display_data, audio_data, &events_access); + WindowScreen bot_screen(WindowScreen::ScreenType::BOTTOM, &capture_data->status, &frontend_data.display_data, audio_data, &events_access); + WindowScreen joint_screen(WindowScreen::ScreenType::JOINT, &capture_data->status, &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; @@ -229,9 +229,9 @@ void mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data) { bot_screen.build(); joint_screen.build(); - std::thread top_thread(screen_display_thread, &top_screen, &capture_data->status); - std::thread bot_thread(screen_display_thread, &bot_screen, &capture_data->status); - std::thread joint_thread(screen_display_thread, &joint_screen, &capture_data->status); + std::thread top_thread(screen_display_thread, &top_screen); + std::thread bot_thread(screen_display_thread, &bot_screen); + std::thread joint_thread(screen_display_thread, &joint_screen); capture_data->status.connected = connect(true, capture_data, &frontend_data); if(capture_data->status.connected) diff --git a/source/frontend.cpp b/source/frontend.cpp index d7d31c7..bb05daf 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -203,6 +203,6 @@ void update_output(FrontendData* frontend_data, double frame_time, VideoOutputDa frontend_data->joint_screen->draw(frame_time, out_buf); } -void screen_display_thread(WindowScreen *screen, CaptureStatus* capture_status) { - screen->display_thread(capture_status); +void screen_display_thread(WindowScreen *screen) { + screen->display_thread(); }