From b9e6e343423b2fb3f991852247a22acf60ba64b0 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Fri, 13 Sep 2024 17:32:20 +0200 Subject: [PATCH] Convert to SFML3 --- .gitignore | 2 +- CMakeLists.txt | 25 +--- README.md | 9 +- include/ExtraButtons.hpp | 2 +- include/Menus/OptionSelectionMenu.hpp | 2 +- include/Menus/RelativePositionMenu.hpp | 2 +- include/audio.hpp | 7 +- include/conversions.hpp | 3 +- include/event_structs.hpp | 43 +++++++ include/frontend.hpp | 1 + include/sfml_gfx_structs.hpp | 31 ----- include/utils.hpp | 1 + other licenses/openal_soft.txt | 67 ---------- source/ExtraButtons.cpp | 16 +-- source/Menus/OptionSelectionMenu.cpp | 32 ++--- source/Menus/RelativePositionMenu.cpp | 32 ++--- source/Menus/ResolutionMenu.cpp | 8 +- source/TextRectangle.cpp | 26 ++-- source/WindowScreen.cpp | 102 +++++++-------- source/WindowScreen_Menu.cpp | 171 +++++++++++++------------ source/audio.cpp | 31 ++--- source/audio_data.cpp | 14 +- source/cc3dsfs.cpp | 38 +++--- source/conversions.cpp | 2 +- source/frontend.cpp | 8 +- source/utils.cpp | 9 ++ 26 files changed, 311 insertions(+), 373 deletions(-) create mode 100644 include/event_structs.hpp delete mode 100644 other licenses/openal_soft.txt diff --git a/.gitignore b/.gitignore index ebdd3c5..9c1fc05 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Byte-compiled / optimized / DLL files *.o -openal32.dll +*.dll cc3dsfs cc3dsfs.exe *.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 99d06d0..b0428ff 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build archs for Mac OS X" FORCE) -set(CMAKE_OSX_DEPLOYMENT_TARGET "11" CACHE STRING "Minimum OS X deployment version") -project(cc3dsfs VERSION 1.0.0 LANGUAGES CXX) +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version") +set(TARGET_LANGUAGES CXX C) +project(cc3dsfs VERSION 1.0.0 LANGUAGES ${TARGET_LANGUAGES}) include(ExternalProject) set(WINDOWS_ARM64 0) @@ -57,7 +58,7 @@ endif() include(FetchContent) FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git - GIT_TAG 2.6.x) + GIT_TAG master) FetchContent_Declare(libusb1 GIT_REPOSITORY https://github.com/libusb/libusb-cmake.git @@ -308,7 +309,7 @@ set(OUTPUT_NAME cc3dsfs) add_executable(${OUTPUT_NAME} source/cc3dsfs.cpp source/utils.cpp source/audio_data.cpp source/audio.cpp source/frontend.cpp source/TextRectangle.cpp source/WindowScreen.cpp source/WindowScreen_Menu.cpp source/3dscapture_ftd3.cpp source/dscapture_ftd2.cpp source/usb_ds_3ds_capture.cpp source/devicecapture.cpp source/conversions.cpp source/ExtraButtons.cpp source/Menus/ConnectionMenu.cpp source/Menus/OptionSelectionMenu.cpp source/Menus/MainMenu.cpp source/Menus/VideoMenu.cpp source/Menus/CropMenu.cpp source/Menus/PARMenu.cpp source/Menus/RotationMenu.cpp source/Menus/OffsetMenu.cpp source/Menus/AudioMenu.cpp source/Menus/BFIMenu.cpp source/Menus/RelativePositionMenu.cpp source/Menus/ResolutionMenu.cpp source/Menus/FileConfigMenu.cpp source/Menus/ExtraSettingsMenu.cpp source/Menus/StatusMenu.cpp source/Menus/LicenseMenu.cpp source/WindowCommands.cpp source/Menus/ShortcutMenu.cpp source/Menus/ActionSelectionMenu.cpp source/Menus/ScalingRatioMenu.cpp source/usb_is_nitro.cpp source/usb_is_nitro_capture.cpp source/usb_generic.cpp source/Menus/ISNitroMenu.cpp ${TOOLS_DATA_DIR}/font_ttf.cpp) add_dependencies(${OUTPUT_NAME} FTD3XX_BUILD_PROJECT FTD2XX_BUILD_PROJECT) -target_link_libraries(${OUTPUT_NAME} PRIVATE sfml-graphics sfml-audio sfml-window sfml-system usb-1.0 ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER}/${FTD3XX_LIB} ${ftd2xx_BINARY_DIR}/${FTD2XX_SUBFOLDER}/${FTD2XX_LIB} ${EXTRA_LIBRARIES}) +target_link_libraries(${OUTPUT_NAME} PRIVATE SFML::Graphics SFML::Audio SFML::Window SFML::System usb-1.0 ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER}/${FTD3XX_LIB} ${ftd2xx_BINARY_DIR}/${FTD2XX_SUBFOLDER}/${FTD2XX_LIB} ${EXTRA_LIBRARIES}) target_link_directories(${OUTPUT_NAME} PRIVATE ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER} ${ftd2xx_BINARY_DIR}/${FTD2XX_SUBFOLDER}) target_include_directories(${OUTPUT_NAME} PRIVATE ${ftd3xx_BINARY_DIR}/${FTD3XX_SUBFOLDER} ${ftd2xx_BINARY_DIR}/${FTD2XX_SUBFOLDER} ${TOOLS_DATA_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/Menus) target_compile_features(${OUTPUT_NAME} PRIVATE cxx_std_20) @@ -322,21 +323,6 @@ add_custom_command( ) if(WIN32) - if(WINDOWS_ARM64) - add_custom_command( - TARGET ${OUTPUT_NAME} - COMMENT "Copy OpenAL DLL" - PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${sfml_SOURCE_DIR}/extlibs/bin/ARM64/openal32.dll ${CMAKE_SOURCE_DIR} - VERBATIM - ) - else() - add_custom_command( - TARGET ${OUTPUT_NAME} - COMMENT "Copy OpenAL DLL" - PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${sfml_SOURCE_DIR}/extlibs/bin/$,x64,x86>/openal32.dll ${CMAKE_SOURCE_DIR} - VERBATIM - ) - endif() if(WINDOWS_FTD3XX_USE_SHARED_LIB) add_custom_command( TARGET ${OUTPUT_NAME} @@ -370,7 +356,6 @@ endif() install(FILES LICENSE README.md DESTINATION .) install(DIRECTORY "other licenses" DESTINATION .) if(WIN32) - install(FILES openal32.dll DESTINATION .) if(WINDOWS_FTD3XX_USE_SHARED_LIB) install(FILES ${FTD3XX_DLL} DESTINATION .) endif() diff --git a/README.md b/README.md index b7b9441..1eff3e7 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ sudo apt install \ libxrandr-dev \ libxcursor-dev \ libudev-dev \ - libopenal-dev \ libflac-dev \ libvorbis-dev \ libgl1-mesa-dev \ @@ -115,7 +114,7 @@ _Note: Currently only tested using a PS5 controller._ - __R key__: Toggles extra padding on/off. It can be used to account for windows with rounded corners. - __2/3 key__: Cycles through the available Pixel Aspect Ratios (PAR) for the top/bottom screen. Useful for VC games and for Chrono Trigger DS. - __M key__: Toggles Audio mute on/off. -- __,/. key__: Decrements/Increments the volume by 5 units. 0 is the minimum. 100 is the maximum. +- __,/. key__: Decrements/Increments the volume by 5 units. 0 is the minimum. 200 is the maximum. - __N key__: Restarts the audio output. Useful if the audio stops working after changing OS settings. - __F1 - F4 keys__: Loads from layouts 1 through 4 respectively. To access more profiles, the GUI must be used. - __F5 - F8 keys__: Saves to layouts 1 through 4 respectively. To access more profiles, the GUI must be used. @@ -136,7 +135,6 @@ On Linux and MacOS, the profiles can be found at the "${HOME}/.config/cc3dsfs" f On Windows, the profiles can be found in the ".config/cc3dsfs" folder inside the directory in which the program runs from. ## Notes -- On Ubuntu 24.04, you may need to install libopenal1 in order for this software to work. - On Linux, you may need to include the udev USB access rules. You can use the .rules files available in the repository's usb\_rules directory, or define your own. - At startup, the audio may be unstable. It should fix itself, if you give it enough time. - If, at first, the connection to the 3DS/DS fails, reconnect the 3DS/DS and then try again. If that also doesn't work, try restarting the program. If that also doesn't work, try restarting the computer. @@ -145,8 +143,3 @@ On Windows, the profiles can be found in the ".config/cc3dsfs" folder inside the - 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). - On MacOS, you may get a notice about Apple being unable to check for malware, or the developer being unknown. To open the program regardless of that, while holding the Command key, right click the application, then select the "Open" option. - Certain TVs/Monitors may add some audio delay for the purpose of video/lip syncing. If you're experiencing too much audio delay when using this software, try checking in the TV/Monitor settings whether you can reduce that added delay. One of the names used for that setting is "Lip Sync", or something along that line. -- For the best audio latency and quality, it may be needed to change OpenAL's sound settings. Their location is OS-specific. On linux, you may also be able to use the "alsoft-config" command. In particular, the following parameters may help: -``` -frequency = 96000 -periods = 2 -``` diff --git a/include/ExtraButtons.hpp b/include/ExtraButtons.hpp index d69d432..962d708 100755 --- a/include/ExtraButtons.hpp +++ b/include/ExtraButtons.hpp @@ -2,7 +2,7 @@ #define __EXTRABUTTONS_HPP #include -#include "sfml_gfx_structs.hpp" +#include "event_structs.hpp" #ifdef RASPI #include #endif diff --git a/include/Menus/OptionSelectionMenu.hpp b/include/Menus/OptionSelectionMenu.hpp index 2d0ccf9..41b38bb 100755 --- a/include/Menus/OptionSelectionMenu.hpp +++ b/include/Menus/OptionSelectionMenu.hpp @@ -5,7 +5,7 @@ #include #include "TextRectangle.hpp" -#include "sfml_gfx_structs.hpp" +#include "event_structs.hpp" #define BACK_X_OUTPUT_OPTION -1 diff --git a/include/Menus/RelativePositionMenu.hpp b/include/Menus/RelativePositionMenu.hpp index fa7387c..ca69910 100755 --- a/include/Menus/RelativePositionMenu.hpp +++ b/include/Menus/RelativePositionMenu.hpp @@ -5,8 +5,8 @@ #include #include "TextRectangle.hpp" -#include "sfml_gfx_structs.hpp" #include "display_structs.hpp" +#include "event_structs.hpp" #define BACK_X_OUTPUT_OPTION -1 diff --git a/include/audio.hpp b/include/audio.hpp index 2bfc216..0f5690e 100755 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -7,9 +7,9 @@ #include "utils.hpp" struct Sample { - Sample(sf::Int16 *bytes, std::size_t size, float time); + Sample(std::int16_t *bytes, std::size_t size, float time); - sf::Int16 *bytes; + std::int16_t *bytes; std::size_t size; float time; }; @@ -25,13 +25,14 @@ public: void update_volume(); void start_audio(); void stop_audio(); + bool hasTooMuchTimeElapsed(); private: AudioData *audio_data; int final_volume = -1; bool terminate; int num_consecutive_fast_seek; - sf::Int16 *buffer; + std::int16_t *buffer; std::chrono::time_point clock_time_start; bool onGetData(sf::SoundStream::Chunk &data) override; diff --git a/include/conversions.hpp b/include/conversions.hpp index 370f143..5f6b217 100755 --- a/include/conversions.hpp +++ b/include/conversions.hpp @@ -1,10 +1,9 @@ #ifndef __CONVERSIONS_HPP #define __CONVERSIONS_HPP -#include #include "capture_structs.hpp" #include "display_structs.hpp" void convertVideoToOutput(int index, VideoOutputData *p_out, CaptureData* capture_data); -void convertAudioToOutput(int index, sf::Int16 *p_out, uint64_t n_samples, const bool is_big_endian, CaptureData* capture_data); +void convertAudioToOutput(int index, std::int16_t *p_out, uint64_t n_samples, const bool is_big_endian, CaptureData* capture_data); #endif diff --git a/include/event_structs.hpp b/include/event_structs.hpp new file mode 100644 index 0000000..f21299f --- /dev/null +++ b/include/event_structs.hpp @@ -0,0 +1,43 @@ +#ifndef __EVENT_STRUCTS_HPP +#define __EVENT_STRUCTS_HPP + +#include +#include + +enum JoystickDirection {JOY_DIR_NONE, JOY_DIR_UP, JOY_DIR_DOWN, JOY_DIR_LEFT, JOY_DIR_RIGHT}; +enum JoystickAction {JOY_ACTION_NONE, JOY_ACTION_CONFIRM, JOY_ACTION_NEGATE, JOY_ACTION_MENU}; + +enum EventType {EVENT_NONE, EVENT_JOYSTICK_BTN_PRESSED, EVENT_JOYSTICK_BTN_RELEASED, EVENT_JOYSTICK_MOVED, EVENT_MOUSE_BTN_PRESSED, EVENT_MOUSE_MOVED, EVENT_KEY_PRESSED, EVENT_TEXT_ENTERED, EVENT_CLOSED, EVENT_KEY_RELEASED, EVENT_MOUSE_BTN_RELEASED}; + +struct SFEvent { + SFEvent(bool pressed, sf::Keyboard::Key code, bool poweroff_cmd = false, bool is_extra = false) : type(pressed ? EVENT_KEY_PRESSED : EVENT_KEY_RELEASED), code(code), poweroff_cmd(poweroff_cmd), is_extra(is_extra) {} + SFEvent(uint32_t unicode) : type(EVENT_TEXT_ENTERED), unicode(unicode) {} + SFEvent(bool pressed, uint32_t joystickId, uint32_t joy_button) : type(pressed ? EVENT_JOYSTICK_BTN_PRESSED : EVENT_MOUSE_BTN_RELEASED), joystickId(joystickId), joy_button(joy_button) {} + SFEvent(uint32_t joystickId, sf::Joystick::Axis axis, float position) : type(EVENT_JOYSTICK_MOVED), joystickId(joystickId), axis(axis), position(position) {} + SFEvent(bool pressed, sf::Mouse::Button mouse_button, sf::Vector2i mouse_position) : type(pressed ? EVENT_MOUSE_BTN_PRESSED : EVENT_MOUSE_BTN_RELEASED), mouse_button(mouse_button), mouse_x(mouse_position.x), mouse_y(mouse_position.y) {} + SFEvent(sf::Vector2i mouse_position) : type(EVENT_MOUSE_MOVED), mouse_x(mouse_position.x), mouse_y(mouse_position.y) {} + SFEvent(EventType type) : type(type) {} + + EventType type; + sf::Keyboard::Key code; + uint32_t unicode; + uint32_t joystickId; + uint32_t joy_button; + sf::Joystick::Axis axis; + float position; + sf::Mouse::Button mouse_button; + int mouse_x; + int mouse_y; + bool poweroff_cmd; + bool is_extra; +}; + +void joystick_axis_poll(std::queue &events_queue); +JoystickDirection get_joystick_direction(uint32_t joystickId, sf::Joystick::Axis axis, float position); +JoystickAction get_joystick_action(uint32_t joystickId, uint32_t joy_button); +void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id, bool use_pud_up); +void end_extra_buttons_poll(); +void extra_buttons_poll(std::queue &events_queue); +std::string get_extra_button_name(sf::Keyboard::Key corresponding_key); + +#endif diff --git a/include/frontend.hpp b/include/frontend.hpp index eba7bd6..ba1ded5 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -33,6 +33,7 @@ #include "ISNitroMenu.hpp" #include "display_structs.hpp" #include "WindowCommands.hpp" +#include "event_structs.hpp" struct HeldTime { std::chrono::time_point start_time; diff --git a/include/sfml_gfx_structs.hpp b/include/sfml_gfx_structs.hpp index 05917a6..e93ea1a 100755 --- a/include/sfml_gfx_structs.hpp +++ b/include/sfml_gfx_structs.hpp @@ -1,40 +1,9 @@ #ifndef __SFML_GFX_STRUCTS_HPP #define __SFML_GFX_STRUCTS_HPP -#include -#include - -enum JoystickDirection {JOY_DIR_NONE, JOY_DIR_UP, JOY_DIR_DOWN, JOY_DIR_LEFT, JOY_DIR_RIGHT}; -enum JoystickAction {JOY_ACTION_NONE, JOY_ACTION_CONFIRM, JOY_ACTION_NEGATE, JOY_ACTION_MENU}; - struct out_rect_data { sf::RectangleShape out_rect; sf::RenderTexture out_tex; }; -struct SFEvent { - SFEvent(sf::Event::EventType type, sf::Keyboard::Key code, uint32_t unicode, uint32_t joystickId, uint32_t joy_button, sf::Joystick::Axis axis, float position, sf::Mouse::Button mouse_button, int mouse_x, int mouse_y, bool poweroff_cmd, bool is_extra) : type(type), code(code), unicode(unicode), joystickId(joystickId), joy_button(joy_button), axis(axis), position(position), mouse_button(mouse_button), mouse_x(mouse_x), mouse_y(mouse_y), poweroff_cmd(poweroff_cmd), is_extra(is_extra) {} - - sf::Event::EventType type; - sf::Keyboard::Key code; - uint32_t unicode; - uint32_t joystickId; - uint32_t joy_button; - sf::Joystick::Axis axis; - float position; - sf::Mouse::Button mouse_button; - int mouse_x; - int mouse_y; - bool poweroff_cmd; - bool is_extra; -}; - -void joystick_axis_poll(std::queue &events_queue); -JoystickDirection get_joystick_direction(uint32_t joystickId, sf::Joystick::Axis axis, float position); -JoystickAction get_joystick_action(uint32_t joystickId, uint32_t joy_button); -void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id, bool use_pud_up); -void end_extra_buttons_poll(); -void extra_buttons_poll(std::queue &events_queue); -std::string get_extra_button_name(sf::Keyboard::Key corresponding_key); - #endif diff --git a/include/utils.hpp b/include/utils.hpp index adfc2d9..d7d18a3 100755 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -34,6 +34,7 @@ uint32_t to_be(uint32_t value); uint16_t to_le(uint16_t value); uint16_t to_be(uint16_t value); std::string get_float_str_decimals(float value, int decimals); +void init_threads(void); class ConsumerMutex { public: diff --git a/other licenses/openal_soft.txt b/other licenses/openal_soft.txt deleted file mode 100644 index 68f8662..0000000 --- a/other licenses/openal_soft.txt +++ /dev/null @@ -1,67 +0,0 @@ - -GNU LESSER GENERAL PUBLIC LICENSE - -Version 3, 29 June 2007 - -Copyright © 2007 Free Software Foundation, Inc. - -Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - -This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. -0. Additional Definitions. - -As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License. - -“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. - -An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. - -A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”. - -The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. - -The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. -1. Exception to Section 3 of the GNU GPL. - -You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. -2. Conveying Modified Versions. - -If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: - - a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or - b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. - -3. Object Code Incorporating Material from Library Header Files. - -The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. - b) Accompany the object code with a copy of the GNU GPL and this license document. - -4. Combined Works. - -You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: - - a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. - b) Accompany the Combined Work with a copy of the GNU GPL and this license document. - c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. - d) Do one of the following: - 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. - 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. - e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) - -5. Combined Libraries. - -You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. - b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. - -6. Revised Versions of the GNU Lesser General Public License. - -The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. - -If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. - diff --git a/source/ExtraButtons.cpp b/source/ExtraButtons.cpp index 65b70a9..8bef949 100755 --- a/source/ExtraButtons.cpp +++ b/source/ExtraButtons.cpp @@ -71,10 +71,10 @@ bool ExtraButton::is_valid() { void ExtraButton::poll(std::queue &events_queue) { if(!this->is_valid()) return; - sf::Event::EventType event_kind = sf::Event::KeyReleased; + bool pressed = false; if(this->is_pressed()) - event_kind = sf::Event::KeyPressed; - if(event_kind == sf::Event::KeyPressed) { + pressed = true; + if(pressed) { auto curr_time = std::chrono::high_resolution_clock::now(); const std::chrono::duration diff = curr_time - this->last_press_time; float press_frequency_limit = this->first_re_press_time; @@ -95,7 +95,7 @@ void ExtraButton::poll(std::queue &events_queue) { } else this->started = false; - events_queue.emplace(event_kind, this->corresponding_key, 0, 0, 0, sf::Joystick::Axis::X, 0, sf::Mouse::Left, 0, 0, this->is_power, true); + events_queue.emplace(pressed, this->corresponding_key, this->is_power, true); } std::string get_extra_button_name(sf::Keyboard::Key corresponding_key) { @@ -106,10 +106,10 @@ std::string get_extra_button_name(sf::Keyboard::Key corresponding_key) { } void init_extra_buttons_poll(int page_up_id, int page_down_id, int enter_id, int power_id, bool use_pud_up) { - pi_page_up.initialize(page_up_id, sf::Keyboard::PageUp, false, 0.5, 0.03, use_pud_up, "Select"); - pi_page_down.initialize(page_down_id, sf::Keyboard::PageDown, false, 0.5, 0.03, use_pud_up, "Menu"); - pi_enter.initialize(enter_id, sf::Keyboard::Enter, false, 0.5, 0.075, use_pud_up, "Enter"); - pi_power.initialize(power_id, sf::Keyboard::Escape, true, 30.0, 30.0, use_pud_up, "Power"); + pi_page_up.initialize(page_up_id, sf::Keyboard::Key::PageUp, false, 0.5, 0.03, use_pud_up, "Select"); + pi_page_down.initialize(page_down_id, sf::Keyboard::Key::PageDown, false, 0.5, 0.03, use_pud_up, "Menu"); + pi_enter.initialize(enter_id, sf::Keyboard::Key::Enter, false, 0.5, 0.075, use_pud_up, "Enter"); + pi_power.initialize(power_id, sf::Keyboard::Key::Escape, true, 30.0, 30.0, use_pud_up, "Power"); } void end_extra_buttons_poll() { diff --git a/source/Menus/OptionSelectionMenu.cpp b/source/Menus/OptionSelectionMenu.cpp index 96a0315..e0dd483 100755 --- a/source/Menus/OptionSelectionMenu.cpp +++ b/source/Menus/OptionSelectionMenu.cpp @@ -17,7 +17,7 @@ void OptionSelectionMenu::initialize(bool font_load_success, sf::Font &text_font this->class_setup(); this->after_class_setup_connected_values(); this->menu_rectangle.setFillColor(this->menu_color); - this->menu_rectangle.setPosition(1, 1); + this->menu_rectangle.setPosition({1, 1}); this->labels = new TextRectangle*[this->num_elements_displayed_per_screen]; this->selectable_labels = new bool[this->num_elements_displayed_per_screen]; this->future_enabled_labels = new bool[this->num_elements_displayed_per_screen]; @@ -382,7 +382,7 @@ void OptionSelectionMenu::right_code() { bool OptionSelectionMenu::poll(SFEvent &event_data) { bool consumed = true; switch (event_data.type) { - case sf::Event::TextEntered: + case EVENT_TEXT_ENTERED: switch (event_data.unicode) { default: consumed = false; @@ -391,27 +391,27 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) { break; - case sf::Event::KeyPressed: + case EVENT_KEY_PRESSED: switch (event_data.code) { - case sf::Keyboard::Up: + case sf::Keyboard::Key::Up: this->up_code(false); break; - case sf::Keyboard::Down: + case sf::Keyboard::Key::Down: this->down_code(false); break; - case sf::Keyboard::PageUp: + case sf::Keyboard::Key::PageUp: this->up_code(true); break; - case sf::Keyboard::PageDown: + case sf::Keyboard::Key::PageDown: this->down_code(true); break; - case sf::Keyboard::Left: + case sf::Keyboard::Key::Left: this->left_code(); break; - case sf::Keyboard::Right: + case sf::Keyboard::Key::Right: this->right_code(); break; - case sf::Keyboard::Enter: + case sf::Keyboard::Key::Enter: this->option_selection_handling(); break; default: @@ -420,7 +420,7 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) { } break; - case sf::Event::MouseMoved: + case EVENT_MOUSE_MOVED: this->future_data.option_selected = -1; for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { if(!(this->selectable_labels[i] && this->future_enabled_labels[i])) @@ -432,7 +432,7 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) { } } break; - case sf::Event::MouseButtonPressed: + case EVENT_MOUSE_BTN_PRESSED: this->future_data.option_selected = -1; for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { if(!(this->selectable_labels[i] && this->future_enabled_labels[i])) @@ -444,10 +444,10 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) { } if(this->future_data.option_selected == -1) break; - if(event_data.mouse_button == sf::Mouse::Left) + if(event_data.mouse_button == sf::Mouse::Button::Left) this->option_selection_handling(); break; - case sf::Event::JoystickButtonPressed: + case EVENT_JOYSTICK_BTN_PRESSED: switch(get_joystick_action(event_data.joystickId, event_data.joy_button)) { case JOY_ACTION_CONFIRM: this->option_selection_handling(); @@ -460,7 +460,7 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) { break; } break; - case sf::Event::JoystickMoved: + case EVENT_JOYSTICK_MOVED: switch(get_joystick_direction(event_data.joystickId, event_data.axis, event_data.position)) { case JOY_DIR_UP: this->up_code(false); @@ -491,7 +491,7 @@ void OptionSelectionMenu::draw(float scaling_factor, sf::RenderTarget &window) { if((this->loaded_data.menu_width != rect_size.x) || (this->loaded_data.menu_height != rect_size.y)) { this->menu_rectangle.setSize(sf::Vector2f(this->loaded_data.menu_width, this->loaded_data.menu_height)); } - this->menu_rectangle.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y); + this->menu_rectangle.setPosition({(float)this->loaded_data.pos_x, (float)this->loaded_data.pos_y}); window.draw(this->menu_rectangle); for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { if(this->loaded_enabled_labels[i]) diff --git a/source/Menus/RelativePositionMenu.cpp b/source/Menus/RelativePositionMenu.cpp index c183ab0..fec56fe 100755 --- a/source/Menus/RelativePositionMenu.cpp +++ b/source/Menus/RelativePositionMenu.cpp @@ -60,7 +60,7 @@ RelativePositionMenu::RelativePositionMenu(bool font_load_success, sf::Font &tex this->class_setup(); this->after_class_setup_connected_values(); this->menu_rectangle.setFillColor(this->menu_color); - this->menu_rectangle.setPosition(1, 1); + this->menu_rectangle.setPosition({1, 1}); this->labels = new TextRectangle*[this->num_elements_displayed_per_screen]; this->selectable_labels = new bool[this->num_elements_displayed_per_screen]; for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { @@ -289,7 +289,7 @@ void RelativePositionMenu::right_code() { bool RelativePositionMenu::poll(SFEvent &event_data) { bool consumed = true; switch (event_data.type) { - case sf::Event::TextEntered: + case EVENT_TEXT_ENTERED: switch (event_data.unicode) { default: consumed = false; @@ -298,27 +298,27 @@ bool RelativePositionMenu::poll(SFEvent &event_data) { break; - case sf::Event::KeyPressed: + case EVENT_KEY_PRESSED: switch (event_data.code) { - case sf::Keyboard::Up: + case sf::Keyboard::Key::Up: this->up_code(false); break; - case sf::Keyboard::Down: + case sf::Keyboard::Key::Down: this->down_code(false); break; - case sf::Keyboard::PageUp: + case sf::Keyboard::Key::PageUp: this->up_code(true); break; - case sf::Keyboard::PageDown: + case sf::Keyboard::Key::PageDown: this->down_code(true); break; - case sf::Keyboard::Left: + case sf::Keyboard::Key::Left: this->left_code(); break; - case sf::Keyboard::Right: + case sf::Keyboard::Key::Right: this->right_code(); break; - case sf::Keyboard::Enter: + case sf::Keyboard::Key::Enter: this->option_selection_handling(); break; default: @@ -327,7 +327,7 @@ bool RelativePositionMenu::poll(SFEvent &event_data) { } break; - case sf::Event::MouseMoved: + case EVENT_MOUSE_MOVED: this->future_data.option_selected = -1; for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { if(!this->selectable_labels[i]) @@ -339,7 +339,7 @@ bool RelativePositionMenu::poll(SFEvent &event_data) { } } break; - case sf::Event::MouseButtonPressed: + case EVENT_MOUSE_BTN_PRESSED: this->future_data.option_selected = -1; for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { if(!this->selectable_labels[i]) @@ -351,10 +351,10 @@ bool RelativePositionMenu::poll(SFEvent &event_data) { } if(this->future_data.option_selected == -1) break; - if(event_data.mouse_button == sf::Mouse::Left) + if(event_data.mouse_button == sf::Mouse::Button::Left) this->option_selection_handling(); break; - case sf::Event::JoystickButtonPressed: + case EVENT_JOYSTICK_BTN_PRESSED: switch(get_joystick_action(event_data.joystickId, event_data.joy_button)) { case JOY_ACTION_CONFIRM: this->option_selection_handling(); @@ -367,7 +367,7 @@ bool RelativePositionMenu::poll(SFEvent &event_data) { break; } break; - case sf::Event::JoystickMoved: + case EVENT_JOYSTICK_MOVED: switch(get_joystick_direction(event_data.joystickId, event_data.axis, event_data.position)) { case JOY_DIR_UP: this->up_code(false); @@ -398,7 +398,7 @@ void RelativePositionMenu::draw(float scaling_factor, sf::RenderTarget &window) if((this->loaded_data.menu_width != rect_size.x) || (this->loaded_data.menu_height != rect_size.y)) { this->menu_rectangle.setSize(sf::Vector2f(this->loaded_data.menu_width, this->loaded_data.menu_height)); } - this->menu_rectangle.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y); + this->menu_rectangle.setPosition({(float)this->loaded_data.pos_x, (float)this->loaded_data.pos_y}); window.draw(this->menu_rectangle); for(int i = 0; i < this->num_elements_displayed_per_screen; i++) { this->labels[i]->draw(window); diff --git a/source/Menus/ResolutionMenu.cpp b/source/Menus/ResolutionMenu.cpp index 6704aad..b9a0f3a 100755 --- a/source/Menus/ResolutionMenu.cpp +++ b/source/Menus/ResolutionMenu.cpp @@ -50,10 +50,10 @@ sf::VideoMode ResolutionMenu::get_resolution(int index) { std::string ResolutionMenu::get_string_option(int index, int action) { sf::VideoMode mode = this->get_resolution(index); - if((mode.width == 0) && (mode.height == 0)) { - return "System Preference (" + std::to_string(this->desktop_resolution.width) + " x " + std::to_string(this->desktop_resolution.height) + ")"; + if((mode.size.x == 0) && (mode.size.y == 0)) { + return "System Preference (" + std::to_string(this->desktop_resolution.size.x) + " x " + std::to_string(this->desktop_resolution.size.y) + ")"; } - return std::to_string(mode.width) + " x " + std::to_string(mode.height); + return std::to_string(mode.size.x) + " x " + std::to_string(mode.size.y); } void ResolutionMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, int fullscreen_mode_width, int fullscreen_mode_height) { @@ -67,7 +67,7 @@ void ResolutionMenu::prepare(float menu_scaling_factor, int view_size_x, int vie continue; int mode_index = start + i; sf::VideoMode mode = this->get_resolution(mode_index); - if((mode.width == fullscreen_mode_width) && (mode.height == fullscreen_mode_height)) + if((mode.size.x == fullscreen_mode_width) && (mode.size.y == fullscreen_mode_height)) this->labels[index]->setText("<" + this->get_string_option(mode_index, DEFAULT_ACTION) + ">"); else this->labels[index]->setText(this->get_string_option(mode_index, DEFAULT_ACTION)); diff --git a/source/TextRectangle.cpp b/source/TextRectangle.cpp index b6b8fcd..048f55a 100755 --- a/source/TextRectangle.cpp +++ b/source/TextRectangle.cpp @@ -1,6 +1,6 @@ #include "TextRectangle.hpp" -TextRectangle::TextRectangle(bool font_load_success, sf::Font &text_font) { +TextRectangle::TextRectangle(bool font_load_success, sf::Font &text_font) : actual_text(text_font) { this->font_load_success = font_load_success; this->setSize(1, 1); this->setRealSize(1, 1, false); @@ -101,7 +101,7 @@ void TextRectangle::draw(sf::RenderTarget &window) { this->updateText(window.getView().getSize().x); } if(font_load_success && this->loaded_data.show_text && (!this->is_done_showing_text)) { - this->text_rect.out_rect.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y); + this->text_rect.out_rect.setPosition({(float)this->loaded_data.pos_x, (float)this->loaded_data.pos_y}); if(this->loaded_data.is_timed) { float time_seconds[3]; this->updateSlides(time_seconds); @@ -124,7 +124,7 @@ void TextRectangle::draw(sf::RenderTarget &window) { rect_curr_height = -this->loaded_data.height + ((int)(factor * this->loaded_data.height)); else if(this->time_phase == 2) rect_curr_height = ((int)(factor * this->loaded_data.height)) * -1; - this->text_rect.out_rect.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y + rect_curr_height); + this->text_rect.out_rect.setPosition({(float)this->loaded_data.pos_x, (float)this->loaded_data.pos_y + rect_curr_height}); if(factor >= 1) { this->time_phase++; @@ -175,7 +175,7 @@ void TextRectangle::setTextWithLineWrapping(int x_limit) { curr_text += this->loaded_data.printed_text[i]; this->actual_text.setString(curr_text); sf::FloatRect globalBounds = this->actual_text.getGlobalBounds(); - int bounds_width = globalBounds.width + (globalBounds.left * 2); + int bounds_width = globalBounds.size.x + (globalBounds.position.x * 2); if(line_started && (bounds_width > x_limit)) { curr_text = new_text + "\n"; for(int i = pos; i < space_pos; i++) @@ -196,8 +196,8 @@ void TextRectangle::setRealSize(int width, int height, bool check_previous) { return; } this->text_rect.out_rect.setSize(sf::Vector2f(this->loaded_data.width, this->loaded_data.height)); - this->text_rect.out_tex.create(this->loaded_data.width, this->loaded_data.height); - this->text_rect.out_rect.setTextureRect(sf::IntRect(0, 0, this->loaded_data.width, this->loaded_data.height)); + (void)this->text_rect.out_tex.resize({(unsigned int)this->loaded_data.width, (unsigned int)this->loaded_data.height}); + this->text_rect.out_rect.setTextureRect(sf::IntRect({0, 0}, {this->loaded_data.width, this->loaded_data.height})); } void TextRectangle::updateText(int x_limit) { @@ -207,29 +207,29 @@ void TextRectangle::updateText(int x_limit) { this->actual_text.setFillColor(sf::Color::White); // set the text style //this->actual_text.setStyle(sf::Text::Bold); - this->actual_text.setPosition(0, 0); + this->actual_text.setPosition({0, 0}); this->setTextWithLineWrapping(x_limit); sf::FloatRect globalBounds; if(this->loaded_data.proportional_box) { globalBounds = this->actual_text.getGlobalBounds(); int new_width = this->loaded_data.width; int new_height = this->loaded_data.height; - int bounds_width = globalBounds.width + (globalBounds.left * 2); - int bounds_height = globalBounds.height + (globalBounds.top * 2); + int bounds_width = globalBounds.size.x + (globalBounds.position.x * 2); + int bounds_height = globalBounds.size.y + (globalBounds.position.y * 2); if(new_width < bounds_width) new_width = bounds_width; if(new_height < bounds_height) new_height = bounds_height; this->setRealSize(new_width, new_height); - this->actual_text.setPosition((int)(5 * (((float)this->loaded_data.font_pixel_height) / BASE_PIXEL_FONT_HEIGHT)), 0); + this->actual_text.setPosition({(float)((int)(5 * (((float)this->loaded_data.font_pixel_height) / BASE_PIXEL_FONT_HEIGHT))), 0}); globalBounds = this->actual_text.getGlobalBounds(); - this->setRealSize(globalBounds.width + (globalBounds.left * 2), globalBounds.height + (globalBounds.top * 2)); + this->setRealSize(globalBounds.size.x + (globalBounds.position.x * 2), globalBounds.size.y + (globalBounds.position.y * 2)); } else { this->setRealSize(this->loaded_data.width, this->loaded_data.height); - this->actual_text.setPosition(0, 0); + this->actual_text.setPosition({0, 0}); globalBounds = this->actual_text.getGlobalBounds(); - this->actual_text.setPosition((int)((this->loaded_data.width - (globalBounds.width + (globalBounds.left * 2))) / 2), (int)((this->loaded_data.height - (globalBounds.height + (globalBounds.top * 2))) / 2)); + this->actual_text.setPosition({(float)((int)((this->loaded_data.width - (globalBounds.size.x + (globalBounds.position.x * 2))) / 2)), (float)((int)((this->loaded_data.height - (globalBounds.size.y + (globalBounds.position.y * 2))) / 2))}); } switch(this->loaded_data.kind) { case TEXT_KIND_NORMAL: diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index fb891c3..62c6963 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -39,13 +39,13 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp this->m_prepare_quit = false; this->ret_val = 0; reset_screen_info(this->m_info); - this->font_load_success = this->text_font.loadFromMemory(font_ttf, font_ttf_len); + this->font_load_success = this->text_font.openFromMemory(font_ttf, font_ttf_len); this->notification = new TextRectangle(this->font_load_success, this->text_font); this->init_menus(); FPSArrayInit(&this->in_fps); FPSArrayInit(&this->draw_fps); FPSArrayInit(&this->poll_fps); - this->in_tex.create(MAX_IN_VIDEO_WIDTH, MAX_IN_VIDEO_HEIGHT); + (void)this->in_tex.resize({MAX_IN_VIDEO_WIDTH, MAX_IN_VIDEO_HEIGHT}); this->m_in_rect_top.setTexture(&this->in_tex); this->m_in_rect_bot.setTexture(&this->in_tex); this->display_data = display_data; @@ -71,8 +71,8 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp this->m_info.is_fullscreen = true; if(!loaded_shaders) { base_shader = new sf::Shader(); - base_shader->loadFromMemory(no_effect_fragment_shader, sf::Shader::Fragment); - loaded_shaders = true; + if(base_shader->loadFromMemory(no_effect_fragment_shader, sf::Shader::Type::Fragment)) + loaded_shaders = true; } n_shader_refs += 1; this->in_top_shader = base_shader; @@ -98,22 +98,22 @@ WindowScreen::~WindowScreen() { } void WindowScreen::build() { - sf::Vector2f top_screen_size = sf::Vector2f(TOP_WIDTH_3DS, HEIGHT_3DS); - sf::Vector2f bot_screen_size = sf::Vector2f(BOT_WIDTH_3DS, HEIGHT_3DS); + sf::Vector2f top_screen_size = {(float)TOP_WIDTH_3DS, (float)HEIGHT_3DS}; + sf::Vector2f bot_screen_size = {(float)BOT_WIDTH_3DS, (float)HEIGHT_3DS}; int width = TOP_WIDTH_3DS; if(this->m_stype == ScreenType::BOTTOM) width = BOT_WIDTH_3DS; - this->m_out_rect_top.out_tex.create(top_screen_size.x, top_screen_size.y); + (void)this->m_out_rect_top.out_tex.resize({(unsigned int)top_screen_size.x, (unsigned int)top_screen_size.y}); this->m_out_rect_top.out_rect.setSize(top_screen_size); this->m_out_rect_top.out_rect.setTexture(&this->m_out_rect_top.out_tex.getTexture()); - this->m_out_rect_bot.out_tex.create(bot_screen_size.x, bot_screen_size.y); + (void)this->m_out_rect_bot.out_tex.resize({(unsigned int)bot_screen_size.x, (unsigned int)bot_screen_size.y}); this->m_out_rect_bot.out_rect.setSize(bot_screen_size); this->m_out_rect_bot.out_rect.setTexture(&this->m_out_rect_bot.out_tex.getTexture()); - this->m_view.setRotation(0); + this->m_view.setRotation(sf::degrees(0)); this->reload(); } @@ -141,7 +141,7 @@ void WindowScreen::display_call(bool is_main_thread) { if(this->m_win.isOpen()) { if(this->main_thread_owns_window != is_main_thread) { this->draw_lock->lock(); - this->m_win.setActive(true); + (void)this->m_win.setActive(true); this->main_thread_owns_window = is_main_thread; this->draw_lock->unlock(); } @@ -163,7 +163,7 @@ void WindowScreen::display_thread() { } if(!this->main_thread_owns_window) { this->draw_lock->lock(); - this->m_win.setActive(false); + (void)this->m_win.setActive(false); this->draw_lock->unlock(); } this->done_display = true; @@ -172,7 +172,7 @@ void WindowScreen::display_thread() { void WindowScreen::end() { if(this->main_thread_owns_window) { this->draw_lock->lock(); - this->m_win.setActive(false); + (void)this->m_win.setActive(false); this->draw_lock->unlock(); } this->display_lock.unlock(); @@ -181,7 +181,7 @@ void WindowScreen::end() { void WindowScreen::after_thread_join() { if(this->m_win.isOpen()) { this->draw_lock->lock(); - this->m_win.setActive(true); + (void)this->m_win.setActive(true); this->m_win.close(); this->draw_lock->unlock(); } @@ -274,7 +274,7 @@ void WindowScreen::free_ownership_of_window(bool is_main_thread) { if(is_main_thread == this->main_thread_owns_window) { if((this->scheduled_work_on_window) || (is_main_thread == this->loaded_info.async)) { this->draw_lock->lock(); - this->m_win.setActive(false); + (void)this->m_win.setActive(false); this->draw_lock->unlock(); } } @@ -292,13 +292,13 @@ void WindowScreen::resize_in_rect(sf::RectangleShape &in_rect, int start_x, int std::swap(target_width, target_height); } - in_rect.setTextureRect(sf::IntRect(target_x, target_y, target_width, target_height)); + in_rect.setTextureRect(sf::IntRect({target_x, target_y}, {target_width, target_height})); - in_rect.setSize(sf::Vector2f(target_width, target_height)); - in_rect.setOrigin(target_width / 2, target_height / 2); + in_rect.setSize({(float)target_width, (float)target_height}); + in_rect.setOrigin({target_width / 2.0f, target_height / 2.0f}); - in_rect.setRotation(target_rotation); - in_rect.setPosition(width / 2, height / 2); + in_rect.setRotation(sf::degrees(target_rotation)); + in_rect.setPosition({width / 2.0f, height / 2.0f}); } int WindowScreen::get_screen_corner_modifier_x(int rotation, int width) { @@ -372,7 +372,7 @@ bool WindowScreen::window_needs_work() { void WindowScreen::window_factory(bool is_main_thread) { if(this->loaded_operations.call_close) { this->draw_lock->lock(); - this->m_win.setActive(true); + (void)this->m_win.setActive(true); this->main_thread_owns_window = is_main_thread; this->m_win.close(); while(!events_queue.empty()) @@ -383,7 +383,7 @@ void WindowScreen::window_factory(bool is_main_thread) { } if(this->loaded_operations.call_create) { this->draw_lock->lock(); - this->m_win.setActive(true); + (void)this->m_win.setActive(true); this->main_thread_owns_window = is_main_thread; bool previously_open = this->m_win.isOpen(); sf::Vector2i prev_pos = sf::Vector2i(0, 0); @@ -392,14 +392,14 @@ void WindowScreen::window_factory(bool is_main_thread) { if(!this->loaded_info.is_fullscreen) { this->update_screen_settings(); if(this->loaded_info.have_titlebar) - this->m_win.create(sf::VideoMode(this->m_width, this->m_height), this->title_factory()); + this->m_win.create(sf::VideoMode({(unsigned int)this->m_width, (unsigned int)this->m_height}), this->title_factory()); else - this->m_win.create(sf::VideoMode(this->m_width, this->m_height), this->title_factory(), sf::Style::None); + this->m_win.create(sf::VideoMode({(unsigned int)this->m_width, (unsigned int)this->m_height}), this->title_factory(), sf::Style::None); this->update_view_size(); } else { if(!this->loaded_info.failed_fullscreen) - this->m_win.create(this->curr_desk_mode, this->title_factory(), sf::Style::Fullscreen); + this->m_win.create(this->curr_desk_mode, this->title_factory(), sf::Style::Default, sf::State::Fullscreen); else if(this->loaded_info.have_titlebar) this->m_win.create(this->curr_desk_mode, this->title_factory()); else @@ -417,7 +417,7 @@ 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->draw_lock->lock(); - this->m_win.setActive(false); + (void)this->m_win.setActive(false); this->draw_lock->unlock(); } this->update_connection(); @@ -617,8 +617,8 @@ void WindowScreen::set_position_screens(sf::Vector2f &curr_top_screen_size, sf:: } if(do_work) { float scale_issue_fix_offset = -0.005; - this->m_out_rect_top.out_rect.setPosition(top_screen_x + scale_issue_fix_offset + offset_x + get_screen_corner_modifier_x(this->loaded_info.top_rotation, top_screen_width), top_screen_y + offset_y + get_screen_corner_modifier_y(this->loaded_info.top_rotation, top_screen_height) + scale_issue_fix_offset); - this->m_out_rect_bot.out_rect.setPosition(bot_screen_x + scale_issue_fix_offset + offset_x + get_screen_corner_modifier_x(this->loaded_info.bot_rotation, bot_screen_width), bot_screen_y + offset_y + get_screen_corner_modifier_y(this->loaded_info.bot_rotation, bot_screen_height) + scale_issue_fix_offset); + this->m_out_rect_top.out_rect.setPosition({top_screen_x + scale_issue_fix_offset + offset_x + get_screen_corner_modifier_x(this->loaded_info.top_rotation, top_screen_width), top_screen_y + offset_y + get_screen_corner_modifier_y(this->loaded_info.top_rotation, top_screen_height) + scale_issue_fix_offset}); + this->m_out_rect_bot.out_rect.setPosition({bot_screen_x + scale_issue_fix_offset + offset_x + get_screen_corner_modifier_x(this->loaded_info.bot_rotation, bot_screen_width), bot_screen_y + offset_y + get_screen_corner_modifier_y(this->loaded_info.bot_rotation, bot_screen_height) + scale_issue_fix_offset}); } int top_end_x = top_screen_x + offset_x + top_screen_width; @@ -639,8 +639,8 @@ float WindowScreen::get_max_float_screen_multiplier(ResizingScreenData *own_scre if((other_rotation / 10) % 2) std::swap(width_limit, height_limit); - int desk_height = curr_desk_mode.height; - int desk_width = curr_desk_mode.width; + int desk_height = curr_desk_mode.size.y; + int desk_width = curr_desk_mode.size.x; int height_max = desk_height; int width_max = desk_width; switch(this->m_info.bottom_pos) { @@ -800,8 +800,8 @@ void WindowScreen::non_integer_scale_screens(ResizingScreenData *top_screen_resi if((bot_screen_resize_data->rotation / 10) % 2) std::swap(min_bot_screen_width, min_bot_screen_height); - int free_width = curr_desk_mode.width - (min_bot_screen_width + min_top_screen_width); - int free_height = curr_desk_mode.height - (min_bot_screen_height + min_top_screen_height); + int free_width = curr_desk_mode.size.x - (min_bot_screen_width + min_top_screen_width); + int free_height = curr_desk_mode.size.y - (min_bot_screen_height + min_top_screen_height); switch(this->m_info.non_integer_mode) { case SMALLER_PRIORITY: @@ -880,7 +880,7 @@ int WindowScreen::get_fullscreen_offset_x(int top_width, int top_height, int bot default: return 0; } - return (curr_desk_mode.width - offset_contribute) * this->loaded_info.total_offset_x; + return (curr_desk_mode.size.x - offset_contribute) * this->loaded_info.total_offset_x; } int WindowScreen::get_fullscreen_offset_y(int top_width, int top_height, int bot_width, int bot_height) { @@ -904,7 +904,7 @@ int WindowScreen::get_fullscreen_offset_y(int top_width, int top_height, int bot default: return 0; } - return (curr_desk_mode.height - offset_contribute) * this->loaded_info.total_offset_y; + return (curr_desk_mode.size.y - offset_contribute) * this->loaded_info.total_offset_y; } void WindowScreen::resize_window_and_out_rects(bool do_work) { @@ -940,16 +940,16 @@ void WindowScreen::resize_window_and_out_rects(bool do_work) { if(this->loaded_info.is_fullscreen) { offset_x = get_fullscreen_offset_x(top_width, top_height, bot_width, bot_height); offset_y = get_fullscreen_offset_y(top_width, top_height, bot_width, bot_height); - max_x = curr_desk_mode.width; - max_y = curr_desk_mode.height; + max_x = curr_desk_mode.size.x; + max_y = curr_desk_mode.size.y; } - sf::Vector2f new_top_screen_size = sf::Vector2f(top_width, top_height); - sf::Vector2f new_bot_screen_size = sf::Vector2f(bot_width, bot_height); + sf::Vector2f new_top_screen_size = {(float)top_width, (float)top_height}; + sf::Vector2f new_bot_screen_size = {(float)bot_width, (float)bot_height}; if(do_work) { this->m_out_rect_top.out_rect.setSize(new_top_screen_size); - this->m_out_rect_top.out_rect.setTextureRect(sf::IntRect(0, 0, top_screen_size.x, top_screen_size.y)); + this->m_out_rect_top.out_rect.setTextureRect(sf::IntRect({0, 0}, {(int)top_screen_size.x, (int)top_screen_size.y})); this->m_out_rect_bot.out_rect.setSize(new_bot_screen_size); - this->m_out_rect_bot.out_rect.setTextureRect(sf::IntRect(0, 0, bot_screen_size.x, bot_screen_size.y)); + this->m_out_rect_bot.out_rect.setTextureRect(sf::IntRect({0, 0}, {(int)bot_screen_size.x, (int)bot_screen_size.y})); } this->set_position_screens(new_top_screen_size, new_bot_screen_size, offset_x, offset_y, max_x, max_y, do_work); if((!this->loaded_info.is_fullscreen) && this->loaded_info.rounded_corners_fix) { @@ -968,7 +968,7 @@ void WindowScreen::create_window(bool re_prepare_size, bool reset_text) { else { bool success = false; if((this->m_info.fullscreen_mode_width > 0) && (this->m_info.fullscreen_mode_height > 0) && (this->m_info.fullscreen_mode_bpp > 0)) { - sf::VideoMode mode_created = sf::VideoMode(this->m_info.fullscreen_mode_width, this->m_info.fullscreen_mode_height, this->m_info.fullscreen_mode_bpp); + sf::VideoMode mode_created = sf::VideoMode({(unsigned int)this->m_info.fullscreen_mode_width, (unsigned int)this->m_info.fullscreen_mode_height}, this->m_info.fullscreen_mode_bpp); if(mode_created.isValid()) { this->curr_desk_mode = mode_created; success = true; @@ -980,11 +980,11 @@ void WindowScreen::create_window(bool re_prepare_size, bool reset_text) { } #ifdef __APPLE__ if(!success) { - this->curr_desk_mode = sf::VideoMode(2 * FALLBACK_FS_RESOLUTION_WIDTH, 2 * FALLBACK_FS_RESOLUTION_HEIGHT, FALLBACK_FS_RESOLUTION_BPP); + this->curr_desk_mode = sf::VideoMode({2 * FALLBACK_FS_RESOLUTION_WIDTH, 2 * FALLBACK_FS_RESOLUTION_HEIGHT}, FALLBACK_FS_RESOLUTION_BPP); success = this->curr_desk_mode.isValid(); } if(!success) { - this->curr_desk_mode = sf::VideoMode(FALLBACK_FS_RESOLUTION_WIDTH, FALLBACK_FS_RESOLUTION_HEIGHT, FALLBACK_FS_RESOLUTION_BPP); + this->curr_desk_mode = sf::VideoMode({FALLBACK_FS_RESOLUTION_WIDTH, FALLBACK_FS_RESOLUTION_HEIGHT}, FALLBACK_FS_RESOLUTION_BPP); success = this->curr_desk_mode.isValid(); } #endif @@ -1001,11 +1001,11 @@ void WindowScreen::create_window(bool re_prepare_size, bool reset_text) { this->m_info.fullscreen_mode_height = FALLBACK_FS_RESOLUTION_HEIGHT; this->m_info.fullscreen_mode_bpp = FALLBACK_FS_RESOLUTION_BPP; } - this->curr_desk_mode = sf::VideoMode(this->m_info.fullscreen_mode_width, this->m_info.fullscreen_mode_height, this->m_info.fullscreen_mode_bpp); + this->curr_desk_mode = sf::VideoMode({(unsigned int)this->m_info.fullscreen_mode_width, (unsigned int)this->m_info.fullscreen_mode_height}, this->m_info.fullscreen_mode_bpp); this->m_info.failed_fullscreen = true; } - this->m_window_width = curr_desk_mode.width; - this->m_window_height = curr_desk_mode.height; + this->m_window_width = curr_desk_mode.size.x; + this->m_window_height = curr_desk_mode.size.y; this->m_info.show_mouse = false; } if(re_prepare_size) @@ -1019,7 +1019,7 @@ void WindowScreen::update_view_size() { this->m_window_width = this->m_width; this->m_window_height = this->m_height; } - this->m_view.reset(sf::FloatRect(0, 0, this->m_window_width, this->m_window_height)); + this->m_view = sf::View(sf::FloatRect({0, 0}, {(float)this->m_window_width, (float)this->m_window_height})); this->m_win.setView(this->m_view); } @@ -1033,8 +1033,8 @@ void WindowScreen::update_screen_settings() { } void WindowScreen::rotate() { - this->m_out_rect_top.out_rect.setRotation(this->loaded_info.top_rotation); - this->m_out_rect_bot.out_rect.setRotation(this->loaded_info.bot_rotation); + this->m_out_rect_top.out_rect.setRotation(sf::degrees(this->loaded_info.top_rotation)); + this->m_out_rect_bot.out_rect.setRotation(sf::degrees(this->loaded_info.bot_rotation)); this->loaded_operations.call_screen_settings_update = true; } @@ -1068,7 +1068,7 @@ sf::Vector2f WindowScreen::getShownScreenSize(bool is_top, ScreenInfo* info) { width = (*crops)[*crop_kind]->bot_width; height = (*crops)[*crop_kind]->bot_height; } - return sf::Vector2f(width, height); + return {(float)width, (float)height}; } void WindowScreen::crop() { @@ -1094,9 +1094,9 @@ void WindowScreen::setWinSize(bool is_main_thread) { int win_height = this->m_win.getSize().y; if((win_width != width) || (win_height != height)) { this->draw_lock->lock(); - this->m_win.setActive(true); + (void)this->m_win.setActive(true); this->main_thread_owns_window = is_main_thread; - this->m_win.setSize(sf::Vector2u(width, height)); + this->m_win.setSize({(unsigned int)width, (unsigned int)height}); this->draw_lock->unlock(); } } diff --git a/source/WindowScreen_Menu.cpp b/source/WindowScreen_Menu.cpp index 7e7f1e2..1c851eb 100755 --- a/source/WindowScreen_Menu.cpp +++ b/source/WindowScreen_Menu.cpp @@ -2,20 +2,20 @@ #define FPS_WINDOW_SIZE 64 -static const sf::VideoMode default_fs_mode_4_5k_macos = sf::VideoMode(4480, 2520); -static const sf::VideoMode default_fs_mode_4k_macos = sf::VideoMode(4096, 2304); -static const sf::VideoMode default_fs_mode_4k = sf::VideoMode(3840, 2160); -static const sf::VideoMode default_fs_mode_1440p = sf::VideoMode(2560, 1440); -static const sf::VideoMode default_fs_mode_4_5k_half_macos = sf::VideoMode(2240, 1260); -static const sf::VideoMode default_fs_mode_4k_half_macos = sf::VideoMode(2048, 1152); -static const sf::VideoMode default_fs_mode_1080p = sf::VideoMode(1920, 1080); -static const sf::VideoMode default_fs_mode_1050p = sf::VideoMode(1680, 1050); -static const sf::VideoMode default_fs_mode_900p = sf::VideoMode(1600, 900); -static const sf::VideoMode default_fs_mode_720p = sf::VideoMode(1280, 720); -static const sf::VideoMode default_fs_mode_600p = sf::VideoMode(800, 600); -static const sf::VideoMode default_fs_mode_480p = sf::VideoMode(720, 480); -static const sf::VideoMode default_fs_mode_240p = sf::VideoMode(400, 240); -static const sf::VideoMode default_fs_mode_240p_2 = sf::VideoMode(320, 240); +static const sf::VideoMode default_fs_mode_4_5k_macos = sf::VideoMode({4480, 2520}); +static const sf::VideoMode default_fs_mode_4k_macos = sf::VideoMode({4096, 2304}); +static const sf::VideoMode default_fs_mode_4k = sf::VideoMode({3840, 2160}); +static const sf::VideoMode default_fs_mode_1440p = sf::VideoMode({2560, 1440}); +static const sf::VideoMode default_fs_mode_4_5k_half_macos = sf::VideoMode({2240, 1260}); +static const sf::VideoMode default_fs_mode_4k_half_macos = sf::VideoMode({2048, 1152}); +static const sf::VideoMode default_fs_mode_1080p = sf::VideoMode({1920, 1080}); +static const sf::VideoMode default_fs_mode_1050p = sf::VideoMode({1680, 1050}); +static const sf::VideoMode default_fs_mode_900p = sf::VideoMode({1600, 900}); +static const sf::VideoMode default_fs_mode_720p = sf::VideoMode({1280, 720}); +static const sf::VideoMode default_fs_mode_600p = sf::VideoMode({800, 600}); +static const sf::VideoMode default_fs_mode_480p = sf::VideoMode({720, 480}); +static const sf::VideoMode default_fs_mode_240p = sf::VideoMode({400, 240}); +static const sf::VideoMode default_fs_mode_240p_2 = sf::VideoMode({320, 240}); static const sf::VideoMode* default_fs_modes[] = { &default_fs_mode_4_5k_macos, @@ -53,7 +53,7 @@ static float check_held_diff(std::chrono::time_pointset_close(0); break; - case sf::Event::TextEntered: + case EVENT_TEXT_ENTERED: switch(event_data.unicode) { case 's': this->execute_cmd(WINDOW_COMMAND_SPLIT); @@ -540,19 +540,19 @@ bool WindowScreen::common_poll(SFEvent &event_data) { break; - case sf::Event::KeyPressed: + case EVENT_KEY_PRESSED: switch(event_data.code) { - case sf::Keyboard::Escape: + case sf::Keyboard::Key::Escape: this->set_close(0); break; - case sf::Keyboard::Enter: + case sf::Keyboard::Key::Enter: if(event_data.is_extra) check_held_reset(true, this->extra_enter_action); else check_held_reset(true, this->enter_action); consumed = false; break; - case sf::Keyboard::PageDown: + case sf::Keyboard::Key::PageDown: if(event_data.is_extra) check_held_reset(true, this->extra_pgdown_action); else @@ -565,16 +565,16 @@ bool WindowScreen::common_poll(SFEvent &event_data) { } break; - case sf::Event::KeyReleased: + case EVENT_KEY_RELEASED: switch(event_data.code) { - case sf::Keyboard::Enter: + case sf::Keyboard::Key::Enter: if(event_data.is_extra) check_held_reset(false, this->extra_enter_action); else check_held_reset(false, this->enter_action); consumed = false; break; - case sf::Keyboard::PageDown: + case sf::Keyboard::Key::PageDown: if(event_data.is_extra) check_held_reset(false, this->extra_pgdown_action); else @@ -587,25 +587,25 @@ bool WindowScreen::common_poll(SFEvent &event_data) { } break; - case sf::Event::MouseMoved: + case EVENT_MOUSE_MOVED: this->m_info.show_mouse = true; this->last_mouse_action_time = std::chrono::high_resolution_clock::now(); consumed = false; break; - case sf::Event::MouseButtonPressed: + case EVENT_MOUSE_BTN_PRESSED: this->m_info.show_mouse = true; this->last_mouse_action_time = std::chrono::high_resolution_clock::now(); consumed = false; break; - case sf::Event::MouseButtonReleased: + case EVENT_MOUSE_BTN_RELEASED: this->m_info.show_mouse = true; this->last_mouse_action_time = std::chrono::high_resolution_clock::now(); consumed = false; break; - case sf::Event::JoystickButtonPressed: + case EVENT_JOYSTICK_BTN_PRESSED: consumed = false; break; - case sf::Event::JoystickMoved: + case EVENT_JOYSTICK_MOVED: consumed = false; break; default: @@ -788,7 +788,7 @@ void WindowScreen::setup_resolution_menu(bool reset_data) { this->possible_resolutions.clear(); std::vector modes = sf::VideoMode::getFullscreenModes(); if(modes.size() > 0) { - this->possible_resolutions.push_back(sf::VideoMode(0, 0, 0)); + this->possible_resolutions.push_back(sf::VideoMode({0, 0}, 0)); this->possible_resolutions.push_back(modes[0]); for(int i = 1; i < modes.size(); ++i) if(modes[0].bitsPerPixel == modes[i].bitsPerPixel) @@ -848,14 +848,14 @@ void WindowScreen::setup_shortcuts_menu(bool reset_data) { this->possible_buttons_names.clear(); this->possible_buttons_ptrs.clear(); this->possible_buttons_extras.clear(); - if(get_extra_button_name(sf::Keyboard::Enter) != "") { + if(get_extra_button_name(sf::Keyboard::Key::Enter) != "") { this->possible_buttons_ptrs.push_back(&extra_button_shortcuts->enter_shortcut); - this->possible_buttons_names.push_back(get_extra_button_name(sf::Keyboard::Enter) + " Button: " + extra_button_shortcuts->enter_shortcut->name); + this->possible_buttons_names.push_back(get_extra_button_name(sf::Keyboard::Key::Enter) + " Button: " + extra_button_shortcuts->enter_shortcut->name); this->possible_buttons_extras.push_back(true); } - if(get_extra_button_name(sf::Keyboard::PageUp) != "") { + if(get_extra_button_name(sf::Keyboard::Key::PageUp) != "") { this->possible_buttons_ptrs.push_back(&extra_button_shortcuts->page_up_shortcut); - this->possible_buttons_names.push_back(get_extra_button_name(sf::Keyboard::PageUp) + " Button: " + extra_button_shortcuts->page_up_shortcut->name); + this->possible_buttons_names.push_back(get_extra_button_name(sf::Keyboard::Key::PageUp) + " Button: " + extra_button_shortcuts->page_up_shortcut->name); this->possible_buttons_extras.push_back(true); } this->shortcut_menu->insert_data(this->possible_buttons_names); @@ -933,16 +933,16 @@ void WindowScreen::update_save_menu() { bool WindowScreen::no_menu_poll(SFEvent &event_data) { bool consumed = true; switch(event_data.type) { - case sf::Event::TextEntered: + case EVENT_TEXT_ENTERED: switch(event_data.unicode) { default: consumed = false; break; } break; - case sf::Event::KeyPressed: + case EVENT_KEY_PRESSED: switch(event_data.code) { - case sf::Keyboard::Enter: + case sf::Keyboard::Key::Enter: if(event_data.is_extra) { consumed = this->can_execute_cmd(extra_button_shortcuts->enter_shortcut, true, false); if(consumed) @@ -951,13 +951,13 @@ bool WindowScreen::no_menu_poll(SFEvent &event_data) { else this->setup_main_menu(); break; - case sf::Keyboard::PageDown: + case sf::Keyboard::Key::PageDown: if(event_data.is_extra) this->setup_main_menu(); else consumed = false; break; - case sf::Keyboard::PageUp: + case sf::Keyboard::Key::PageUp: if(event_data.is_extra){ consumed = this->can_execute_cmd(extra_button_shortcuts->page_up_shortcut, true, false); if(consumed) @@ -971,19 +971,19 @@ bool WindowScreen::no_menu_poll(SFEvent &event_data) { break; } break; - case sf::Event::MouseMoved: + case EVENT_MOUSE_MOVED: consumed = false; break; - case sf::Event::MouseButtonPressed: - if(event_data.mouse_button == sf::Mouse::Right) + case EVENT_MOUSE_BTN_PRESSED: + if(event_data.mouse_button == sf::Mouse::Button::Right) this->setup_main_menu(); else consumed = false; break; - case sf::Event::MouseButtonReleased: + case EVENT_MOUSE_BTN_RELEASED: consumed = false; break; - case sf::Event::JoystickButtonPressed: + case EVENT_JOYSTICK_BTN_PRESSED: switch(get_joystick_action(event_data.joystickId, event_data.joy_button)) { case JOY_ACTION_MENU: this->setup_main_menu(); @@ -993,7 +993,7 @@ bool WindowScreen::no_menu_poll(SFEvent &event_data) { break; } break; - case sf::Event::JoystickMoved: + case EVENT_JOYSTICK_MOVED: consumed = false; break; default: @@ -1006,7 +1006,7 @@ bool WindowScreen::no_menu_poll(SFEvent &event_data) { bool WindowScreen::main_poll(SFEvent &event_data) { bool consumed = true; switch(event_data.type) { - case sf::Event::TextEntered: + case EVENT_TEXT_ENTERED: switch(event_data.unicode) { case 'c': this->execute_cmd(WINDOW_COMMAND_CROP); @@ -1111,20 +1111,20 @@ bool WindowScreen::main_poll(SFEvent &event_data) { break; - case sf::Event::KeyPressed: + case EVENT_KEY_PRESSED: switch(event_data.code) { - case sf::Keyboard::F1: - case sf::Keyboard::F2: - case sf::Keyboard::F3: - case sf::Keyboard::F4: - this->execute_cmd(static_cast(WINDOW_COMMAND_LOAD_PROFILE_1 + (event_data.code - sf::Keyboard::F1))); + case sf::Keyboard::Key::F1: + case sf::Keyboard::Key::F2: + case sf::Keyboard::Key::F3: + case sf::Keyboard::Key::F4: + this->execute_cmd(static_cast(WINDOW_COMMAND_LOAD_PROFILE_1 + ((int)event_data.code - (int)sf::Keyboard::Key::F1))); break; - case sf::Keyboard::F5: - case sf::Keyboard::F6: - case sf::Keyboard::F7: - case sf::Keyboard::F8: - this->execute_cmd(static_cast(WINDOW_COMMAND_SAVE_PROFILE_1 + (event_data.code - sf::Keyboard::F5))); + case sf::Keyboard::Key::F5: + case sf::Keyboard::Key::F6: + case sf::Keyboard::Key::F7: + case sf::Keyboard::Key::F8: + this->execute_cmd(static_cast(WINDOW_COMMAND_SAVE_PROFILE_1 + ((int)event_data.code - (int)sf::Keyboard::Key::F5))); break; default: consumed = false; @@ -1132,19 +1132,19 @@ bool WindowScreen::main_poll(SFEvent &event_data) { } break; - case sf::Event::MouseMoved: + case EVENT_MOUSE_MOVED: consumed = false; break; - case sf::Event::MouseButtonPressed: + case EVENT_MOUSE_BTN_PRESSED: consumed = false; break; - case sf::Event::MouseButtonReleased: + case EVENT_MOUSE_BTN_RELEASED: consumed = false; break; - case sf::Event::JoystickButtonPressed: + case EVENT_JOYSTICK_BTN_PRESSED: consumed = false; break; - case sf::Event::JoystickMoved: + case EVENT_JOYSTICK_MOVED: consumed = false; break; default: @@ -1170,7 +1170,7 @@ void WindowScreen::poll(bool do_everything) { break; SFEvent event_data = events_queue.front(); events_queue.pop(); - if((event_data.type == sf::Event::KeyPressed) && event_data.poweroff_cmd) { + if((event_data.type == EVENT_KEY_PRESSED) && event_data.poweroff_cmd) { this->set_close(1); done = true; continue; @@ -1657,8 +1657,8 @@ void WindowScreen::poll(bool do_everything) { case RESOLUTION_MENU_NO_ACTION: break; default: - this->m_info.fullscreen_mode_width = possible_resolutions[this->resolution_menu->selected_index].width; - this->m_info.fullscreen_mode_height = possible_resolutions[this->resolution_menu->selected_index].height; + this->m_info.fullscreen_mode_width = possible_resolutions[this->resolution_menu->selected_index].size.x; + this->m_info.fullscreen_mode_height = possible_resolutions[this->resolution_menu->selected_index].size.y; this->m_info.fullscreen_mode_bpp = possible_resolutions[this->resolution_menu->selected_index].bitsPerPixel; this->create_window(true); break; @@ -1924,25 +1924,32 @@ void WindowScreen::poll_window(bool do_everything) { 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); + while(const std::optional event = this->m_win.pollEvent()) { + if(event->is()) + events_queue.emplace(EVENT_CLOSED); + else if(const auto* keyPressed = event->getIf()) + events_queue.emplace(true, keyPressed->code); + else if(const auto* keyReleased = event->getIf()) + events_queue.emplace(false, keyReleased->code); + else if(const auto* textEntered = event->getIf()) + events_queue.emplace(textEntered->unicode); + else if(const auto* joystick_press = event->getIf()) + events_queue.emplace(true, joystick_press->joystickId, joystick_press->button); + else if(const auto* joystick_release = event->getIf()) + events_queue.emplace(false, joystick_release->joystickId, joystick_release->button); + else if(const auto* joystick_movement = event->getIf()) + events_queue.emplace(joystick_movement->joystickId, joystick_movement->axis, joystick_movement->position); + else if(const auto* mouse_pressed = event->getIf()) + events_queue.emplace(true, mouse_pressed->button, mouse_pressed->position); + else if(const auto* mouse_released = event->getIf()) + events_queue.emplace(false, mouse_released->button, mouse_released->position); + else if(const auto* mouse_movement = event->getIf()) + events_queue.emplace(mouse_movement->position); } } if(this->m_win.hasFocus()) { if(do_everything) { - check_held_reset(sf::Mouse::isButtonPressed(sf::Mouse::Right), this->right_click_action); + check_held_reset(sf::Mouse::isButtonPressed(sf::Mouse::Button::Right), this->right_click_action); bool found = false; for(int i = 0; i < sf::Joystick::Count; i++) { if(!sf::Joystick::isConnected(i)) @@ -1963,10 +1970,10 @@ void WindowScreen::poll_window(bool do_everything) { 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); + events_queue.emplace(true, sf::Mouse::Button::Right, touch_pos); 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); + events_queue.emplace(true, sf::Mouse::Button::Left, touch_pos); } joystick_axis_poll(this->events_queue); } diff --git a/source/audio.cpp b/source/audio.cpp index ceeec25..03812d5 100755 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -17,16 +17,16 @@ static int greatest_diff = 0; #endif -Sample::Sample(sf::Int16 *bytes, std::size_t size, float time) : bytes(bytes), size(size), time(time) {} +Sample::Sample(std::int16_t *bytes, std::size_t size, float time) : bytes(bytes), size(size), time(time) {} //============================================================================ Audio::Audio(AudioData *audio_data) { this->audio_data = audio_data; // Consume old events - this->buffer = new sf::Int16[MAX_SAMPLES_IN * (MAX_MAX_AUDIO_LATENCY + 1)]; + this->buffer = new std::int16_t[MAX_SAMPLES_IN * (MAX_MAX_AUDIO_LATENCY + 1)]; this->audio_data->check_audio_restart_request(); - sf::SoundStream::initialize(AUDIO_CHANNELS, SAMPLE_RATE_BASE); + sf::SoundStream::initialize(AUDIO_CHANNELS, SAMPLE_RATE_BASE, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight}); this->setPitch(1.0 / SAMPLE_RATE_DIVISOR); start_audio(); setVolume(0); @@ -56,20 +56,16 @@ void Audio::stop_audio() { samples_wait.unlock(); } +bool Audio::hasTooMuchTimeElapsed() { + auto curr_time = std::chrono::high_resolution_clock::now(); + const std::chrono::duration diff = curr_time - this->clock_time_start; + return (diff.count() > 1.0); +} + bool Audio::onGetData(sf::SoundStream::Chunk &data) { if(terminate) return false; - // Do all of this to understand if the audio has errored out and - // if it should be restarted... - auto curr_time = std::chrono::high_resolution_clock::now(); - const std::chrono::duration diff = curr_time - this->clock_time_start; - if(diff.count() < 0.0005) - num_consecutive_fast_seek++; - else - num_consecutive_fast_seek = 0; - if(num_consecutive_fast_seek > AUDIO_FAILURE_THRESHOLD) - restart = true; if(this->audio_data->check_audio_restart_request()) restart = true; @@ -85,7 +81,7 @@ bool Audio::onGetData(sf::SoundStream::Chunk &data) { return false; loaded_samples = samples.size(); } - data.samples = (const sf::Int16*)buffer; + data.samples = (const std::int16_t*)buffer; while(loaded_samples > this->audio_data->get_max_audio_latency()) { samples.pop(); @@ -95,9 +91,9 @@ bool Audio::onGetData(sf::SoundStream::Chunk &data) { data.sampleCount = 0; for(int i = 0; i < loaded_samples; i++) { - const sf::Int16 *data_samples = samples.front().bytes; + const std::int16_t *data_samples = samples.front().bytes; int count = samples.front().size; - memcpy(buffer + data.sampleCount, data_samples, count * sizeof(sf::Int16)); + memcpy(buffer + data.sampleCount, data_samples, count * sizeof(std::int16_t)); // Unused, but could be useful info //double real_sample_rate = (1.0 / samples.front().time) * count / 2; data.sampleCount += count; @@ -132,8 +128,7 @@ bool Audio::onGetData(sf::SoundStream::Chunk &data) { #endif // Basically, look into how low the time between calls of the function is - curr_time = std::chrono::high_resolution_clock::now(); - clock_time_start = curr_time; + clock_time_start = std::chrono::high_resolution_clock::now(); return true; } diff --git a/source/audio_data.cpp b/source/audio_data.cpp index f6e2136..dc91cb8 100755 --- a/source/audio_data.cpp +++ b/source/audio_data.cpp @@ -1,7 +1,7 @@ #include "audio_data.hpp" void AudioData::reset() { - this->volume = 50; + this->volume = 100; this->mute = false; this->max_audio_latency = 2; this->output_type = AUDIO_OUTPUT_STEREO; @@ -108,8 +108,8 @@ int AudioData::get_final_volume() { int read_volume = this->volume; if(read_volume < 0) read_volume = 0; - if(read_volume > 100) - read_volume = 100; + if(read_volume > 200) + read_volume = 200; return read_volume; } @@ -117,8 +117,8 @@ int AudioData::get_real_volume() { int read_volume = this->volume; if(read_volume < 0) read_volume = 0; - if(read_volume > 100) - read_volume = 100; + if(read_volume > 200) + read_volume = 200; return read_volume; } @@ -174,8 +174,8 @@ void AudioData::set_audio_output_type(int new_value) { void AudioData::set_audio_volume(int new_volume) { if(new_volume < 0) new_volume = 0; - if(new_volume > 100) - new_volume = 100; + if(new_volume > 200) + new_volume = 200; this->volume = new_volume; } diff --git a/source/cc3dsfs.cpp b/source/cc3dsfs.cpp index 0780aff..08603e2 100755 --- a/source/cc3dsfs.cpp +++ b/source/cc3dsfs.cpp @@ -1,8 +1,5 @@ #include #include -#if defined (__linux__) && defined(XLIB_BASED) -#include -#endif #if (!defined(_MSC_VER)) || (_MSC_VER > 1916) #include @@ -214,8 +211,18 @@ static void save_layout_file(int save_index, FrontendData *frontend_data, AudioD } } +static void executeSoundRestart(Audio &audio, AudioData* audio_data, bool do_restart) { + if(do_restart) { + audio.stop(); + audio.~Audio(); + ::new(&audio) Audio(audio_data); + } + audio.start_audio(); + audio.play(); +} + static void soundCall(AudioData *audio_data, CaptureData* capture_data) { - sf::Int16 (*out_buf)[MAX_SAMPLES_IN] = new sf::Int16[NUM_CONCURRENT_AUDIO_BUFFERS][MAX_SAMPLES_IN]; + std::int16_t (*out_buf)[MAX_SAMPLES_IN] = new std::int16_t[NUM_CONCURRENT_AUDIO_BUFFERS][MAX_SAMPLES_IN]; Audio audio(audio_data); int curr_out, prev_out = NUM_CONCURRENT_DATA_BUFFERS - 1, audio_buf_counter = 0; const bool endianness = is_big_endian(); @@ -240,21 +247,18 @@ static void soundCall(AudioData *audio_data, CaptureData* capture_data) { } } prev_out = curr_out; - + loaded_samples = audio.samples.size(); - if(audio.getStatus() != sf::SoundStream::Playing) { + if(audio.getStatus() != sf::SoundStream::Status::Playing) { audio.stop_audio(); - if(loaded_samples > 0) { - if(audio.restart) { - audio.stop(); - audio.~Audio(); - ::new(&audio) Audio(audio_data); - } - audio.start_audio(); - audio.play(); - } + if(loaded_samples > 0) + executeSoundRestart(audio, audio_data, audio.restart); } else { + if(loaded_samples > 0) { + if(audio.hasTooMuchTimeElapsed()) + executeSoundRestart(audio, audio_data, true); + } audio.update_volume(); } } @@ -481,9 +485,7 @@ static bool parse_int_arg(int &index, int argc, char **argv, int &target, std::s } int main(int argc, char **argv) { - #if defined(__linux__) && defined(XLIB_BASED) - XInitThreads(); - #endif + init_threads(); bool mono_app = false; int page_up_id = -1; int page_down_id = -1; diff --git a/source/conversions.cpp b/source/conversions.cpp index 3798f82..d66ee24 100755 --- a/source/conversions.cpp +++ b/source/conversions.cpp @@ -27,7 +27,7 @@ void convertVideoToOutput(int index, VideoOutputData *p_out, CaptureData* captur #endif } -void convertAudioToOutput(int index, sf::Int16 *p_out, uint64_t n_samples, const bool is_big_endian, CaptureData* capture_data) { +void convertAudioToOutput(int index, std::int16_t *p_out, uint64_t n_samples, const bool is_big_endian, CaptureData* capture_data) { if(!capture_data->status.device.has_audio) return; CaptureReceived *p_in = &capture_data->capture_buf[index]; diff --git a/source/frontend.cpp b/source/frontend.cpp index 565283a..766e84d 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -642,9 +642,9 @@ void joystick_axis_poll(std::queue &events_queue) { if(!sf::Joystick::isConnected(i)) continue; for(int j = 0; j < sf::Joystick::AxisCount; j++) { - sf::Joystick::Axis axis = sf::Joystick::Axis(sf::Joystick::Axis::X + j); + sf::Joystick::Axis axis = sf::Joystick::Axis((int)sf::Joystick::Axis::X + j); if(sf::Joystick::hasAxis(i, axis)) - events_queue.emplace(sf::Event::JoystickMoved, sf::Keyboard::Backspace, 0, i, 0, axis, sf::Joystick::getAxisPosition(i, axis), sf::Mouse::Left, 0, 0, false, false); + events_queue.emplace(i, axis, sf::Joystick::getAxisPosition(i, axis)); } } } @@ -709,9 +709,9 @@ float get_par_mult_factor(float width, float height, float max_width, float max_ JoystickDirection get_joystick_direction(uint32_t joystickId, sf::Joystick::Axis axis, float position) { bool is_horizontal = false; - if((axis == sf::Joystick::Z) || (axis == sf::Joystick::R)) + if((axis == sf::Joystick::Axis::Z) || (axis == sf::Joystick::Axis::R)) return JOY_DIR_NONE; - if((axis == sf::Joystick::X) || (axis == sf::Joystick::U) || (axis == sf::Joystick::PovX)) + if((axis == sf::Joystick::Axis::X) || (axis == sf::Joystick::Axis::U) || (axis == sf::Joystick::Axis::PovX)) is_horizontal = true; int direction = 0; if(position >= 90.0) diff --git a/source/utils.cpp b/source/utils.cpp index 60ee412..ee8a081 100755 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,5 +1,8 @@ #include "utils.hpp" +#if defined (__linux__) && defined(XLIB_BASED) +#include +#endif #include #include #include @@ -61,6 +64,12 @@ uint16_t to_be(uint16_t value) { return value; } +void init_threads(void) { + #if defined(__linux__) && defined(XLIB_BASED) + XInitThreads(); + #endif +} + std::string get_version_string(bool get_letter) { std::string version_str = std::to_string(APP_VERSION_MAJOR) + "." + std::to_string(APP_VERSION_MINOR) + "." + std::to_string(APP_VERSION_REVISION); if(get_letter)