From b8a2cd1b064ed598b95c9b9e5601142ffbc4da3d Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 20 Nov 2021 18:57:58 -0800 Subject: [PATCH] PAD: Call one joint pad header in most of pcsx2, not two. (#4985) Add Gamepad.h Cleanup. Remove the Windows version of PAD.h as well. Update CMakeLists.txt Revert language changes. --- pcsx2/CMakeLists.txt | 5 +- pcsx2/PAD/{Linux/PAD.h => Gamepad.h} | 39 ++---------- pcsx2/PAD/Linux/Global.h | 12 ++++ pcsx2/PAD/Linux/PAD.cpp | 58 +++++++++++++---- pcsx2/PAD/Linux/keyboard.cpp | 5 +- pcsx2/PAD/Linux/linux.cpp | 93 ---------------------------- pcsx2/PAD/Windows/Global.h | 22 ++++++- pcsx2/PAD/Windows/PAD.cpp | 1 - pcsx2/PAD/Windows/PAD.h | 63 ------------------- pcsx2/PAD/Windows/PADConfig.cpp | 1 - pcsx2/SaveState.cpp | 6 +- pcsx2/Sio.cpp | 6 +- pcsx2/System/SysCoreThread.cpp | 6 +- pcsx2/gui/AppMain.cpp | 6 +- pcsx2/gui/FrameForGS.cpp | 6 +- pcsx2/gui/MainMenuClicks.cpp | 6 +- pcsx2/gui/SysState.cpp | 6 +- pcsx2/pcsx2.vcxproj | 2 +- pcsx2/pcsx2.vcxproj.filters | 6 +- 19 files changed, 103 insertions(+), 246 deletions(-) rename pcsx2/PAD/{Linux/PAD.h => Gamepad.h} (66%) delete mode 100644 pcsx2/PAD/Linux/linux.cpp delete mode 100644 pcsx2/PAD/Windows/PAD.h diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 4e2406caa8..4e788b9a87 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -492,7 +492,7 @@ if(WIN32) ) set(pcsx2PADHeaders - PAD/Windows/PAD.h + PAD/Gamepad.h PAD/Windows/PADConfig.h PAD/Windows/DeviceEnumerator.h PAD/Windows/Diagnostics.h @@ -557,12 +557,12 @@ else(WIN32) PAD/Linux/wx_dialog/GamepadConfiguration.cpp PAD/Linux/wx_dialog/JoystickConfiguration.cpp PAD/Linux/Config.cpp - PAD/Linux/linux.cpp ${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/resources_pad.cpp ) # PAD/Linux headers set(pcsx2PADHeaders + PAD/Gamepad.h PAD/Linux/bitwise.h PAD/Linux/Config.h PAD/Linux/Device.h @@ -571,7 +571,6 @@ else(WIN32) PAD/Linux/SDL/joystick.h PAD/Linux/keyboard.h PAD/Linux/KeyStatus.h - PAD/Linux/PAD.h PAD/Linux/state_management.h PAD/Linux/wx_dialog/opPanel.h PAD/Linux/wx_dialog/GamepadConfiguration.h diff --git a/pcsx2/PAD/Linux/PAD.h b/pcsx2/PAD/Gamepad.h similarity index 66% rename from pcsx2/PAD/Linux/PAD.h rename to pcsx2/PAD/Gamepad.h index 2946e153d5..cbd86dcb3a 100644 --- a/pcsx2/PAD/Linux/PAD.h +++ b/pcsx2/PAD/Gamepad.h @@ -15,49 +15,22 @@ #pragma once -#include "Global.h" -#include "Host.h" -#include "common/mt_queue.h" +#include "common/WindowInfo.h" #include "SaveState.h" - -enum PadOptions -{ - PADOPTION_FORCEFEEDBACK = 0x1, - PADOPTION_REVERSELX = 0x2, - PADOPTION_REVERSELY = 0x4, - PADOPTION_REVERSERX = 0x8, - PADOPTION_REVERSERY = 0x10, - PADOPTION_MOUSE_L = 0x20, - PADOPTION_MOUSE_R = 0x40, -}; - -struct WindowInfo; - -extern FILE* padLog; -extern void initLogging(); - -extern HostKeyEvent event; -extern MtQueue g_ev_fifo; - -s32 _PADopen(const WindowInfo& wi); -void _PADclose(); -void PADsetMode(int pad, int mode); - -void SysMessage(char* fmt, ...); +#include "Host.h" s32 PADinit(); void PADshutdown(); s32 PADopen(const WindowInfo& wi); -void PADsetLogDir(const char* dir); +void PADupdate(int pad); void PADclose(); -s32 PADsetSlot(u8 port, u8 slot); -s32 PADfreeze(FreezeAction mode, freezeData* data); u8 PADstartPoll(int pad); u8 PADpoll(u8 value); HostKeyEvent* PADkeyEvent(); -void PADupdate(int pad); void PADconfigure(); +s32 PADfreeze(FreezeAction mode, freezeData* data); +s32 PADsetSlot(u8 port, u8 slot); #if defined(__unix__) void PADWriteEvent(HostKeyEvent& evt); -#endif +#endif \ No newline at end of file diff --git a/pcsx2/PAD/Linux/Global.h b/pcsx2/PAD/Linux/Global.h index 71e4a8a52c..e94cbe8d2d 100644 --- a/pcsx2/PAD/Linux/Global.h +++ b/pcsx2/PAD/Linux/Global.h @@ -30,6 +30,7 @@ #include "common/pxStreams.h" #include "common/Console.h" +#include "common/mt_queue.h" #include "DebugTools/Debug.h" #define PADdefs @@ -95,6 +96,17 @@ static const std::array all_keys = PAD_R_LEFT // Right joystick (Left) ← }; +enum PadOptions +{ + PADOPTION_FORCEFEEDBACK = 0x1, + PADOPTION_REVERSELX = 0x2, + PADOPTION_REVERSELY = 0x4, + PADOPTION_REVERSERX = 0x8, + PADOPTION_REVERSERY = 0x10, + PADOPTION_MOUSE_L = 0x20, + PADOPTION_MOUSE_R = 0x40, +}; + static bool IsAnalogKey(int index) { return ((index >= PAD_L_UP) && (index <= PAD_R_LEFT)); diff --git a/pcsx2/PAD/Linux/PAD.cpp b/pcsx2/PAD/Linux/PAD.cpp index 093c4fa844..2bf7243bd0 100644 --- a/pcsx2/PAD/Linux/PAD.cpp +++ b/pcsx2/PAD/Linux/PAD.cpp @@ -22,7 +22,7 @@ #include "common/WindowInfo.h" #include "keyboard.h" -#include "PAD.h" +#include "../Gamepad.h" #include "state_management.h" #if defined(__unix__) || defined(__APPLE__) @@ -33,6 +33,14 @@ #include #endif +#include "gui/AppCoreThread.h" +#include "wx_dialog/dialog.h" + +#ifndef __APPLE__ +Display* GSdsp; +Window GSwin; +#endif + const u32 revision = 3; const u32 build = 0; // increase that with each version #define PAD_SAVE_STATE_VERSION ((revision << 8) | (build << 0)) @@ -122,22 +130,20 @@ s32 PADopen(const WindowInfo& wi) #if defined(__unix__) || defined(__APPLE__) EnumerateDevices(); #endif - return _PADopen(wi); -} +#ifndef __APPLE__ + if (wi.type != WindowInfo::Type::X11) + return -1; -void PADsetLogDir(const char* dir) -{ - // Get the path to the log directory. - s_padstrLogPath = (dir == NULL) ? "logs/" : dir; + GSdsp = static_cast(wi.display_connection); + GSwin = reinterpret_cast(wi.window_handle); +#endif - // Reload the log file after updated the path - CloseLogging(); - initLogging(); + return 0; } void PADclose() { - _PADclose(); + device_manager.devices.clear(); } s32 PADsetSlot(u8 port, u8 slot) @@ -292,3 +298,33 @@ void PADWriteEvent(HostKeyEvent& evt) g_ev_fifo.push(evt); } #endif + +void PADupdate(int pad) +{ +#ifndef __APPLE__ + // Gamepad inputs don't count as an activity. Therefore screensaver will + // be fired after a couple of minute. + // Emulate an user activity + static int count = 0; + count++; + if ((count & 0xFFF) == 0) + { + // 1 call every 4096 Vsync is enough + XResetScreenSaver(GSdsp); + } +#endif + + // Actually PADupdate is always call with pad == 0. So you need to update both + // pads -- Gregory + device_manager.Update(); +} + +void PADconfigure() +{ + ScopedCoreThreadPause paused_core; + PADLoadConfig(); + + DisplayDialog(); + paused_core.AllowResume(); + return; +} \ No newline at end of file diff --git a/pcsx2/PAD/Linux/keyboard.cpp b/pcsx2/PAD/Linux/keyboard.cpp index f5d1f4b588..1d20b9155e 100644 --- a/pcsx2/PAD/Linux/keyboard.cpp +++ b/pcsx2/PAD/Linux/keyboard.cpp @@ -20,7 +20,10 @@ #include "Global.h" #include "keyboard.h" -#include "PAD.h" +#include "../Gamepad.h" + +extern HostKeyEvent event; +extern MtQueue g_ev_fifo; /// g_key_status.press but with proper handling for analog buttons static void PressButton(u32 pad, u32 button) diff --git a/pcsx2/PAD/Linux/linux.cpp b/pcsx2/PAD/Linux/linux.cpp deleted file mode 100644 index 05c5be0c05..0000000000 --- a/pcsx2/PAD/Linux/linux.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#include "gui/AppCoreThread.h" -#include "common/WindowInfo.h" - -#include "Global.h" -#include "Device.h" -#include "keyboard.h" -#include "state_management.h" - -#include "wx_dialog/dialog.h" - -#ifndef __APPLE__ -Display* GSdsp; -Window GSwin; -#endif - -static void SysMessage(const char* fmt, ...) -{ - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (msg[strlen(msg) - 1] == '\n') - msg[strlen(msg) - 1] = 0; - - wxMessageDialog dialog(nullptr, msg, "Info", wxOK); - dialog.ShowModal(); -} - -s32 _PADopen(const WindowInfo& wi) -{ -#ifndef __APPLE__ - if (wi.type != WindowInfo::Type::X11) - return -1; - - GSdsp = static_cast(wi.display_connection); - GSwin = reinterpret_cast(wi.window_handle); -#endif - - return 0; -} - -void _PADclose() -{ - device_manager.devices.clear(); -} - -void PADupdate(int pad) -{ -#ifndef __APPLE__ - // Gamepad inputs don't count as an activity. Therefore screensaver will - // be fired after a couple of minute. - // Emulate an user activity - static int count = 0; - count++; - if ((count & 0xFFF) == 0 && GSdsp) - { - // 1 call every 4096 Vsync is enough - XResetScreenSaver(GSdsp); - } -#endif - - // Actually PADupdate is always call with pad == 0. So you need to update both - // pads -- Gregory - device_manager.Update(); -} - -void PADconfigure() -{ - ScopedCoreThreadPause paused_core; - PADLoadConfig(); - - DisplayDialog(); - paused_core.AllowResume(); - return; -} diff --git a/pcsx2/PAD/Windows/Global.h b/pcsx2/PAD/Windows/Global.h index ddcfcaa873..9d135108e9 100644 --- a/pcsx2/PAD/Windows/Global.h +++ b/pcsx2/PAD/Windows/Global.h @@ -15,7 +15,27 @@ #pragma once -#include "PAD.h" +#include +#include +#include +#include +#include +#include "common/pxStreams.h" +#include "common/Console.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "../Gamepad.h" + +struct HostKeyEvent; #ifdef __linux__ // Seriously why there is no standard diff --git a/pcsx2/PAD/Windows/PAD.cpp b/pcsx2/PAD/Windows/PAD.cpp index 5acb2b463b..d667b256c9 100644 --- a/pcsx2/PAD/Windows/PAD.cpp +++ b/pcsx2/PAD/Windows/PAD.cpp @@ -24,7 +24,6 @@ #include "resource_pad.h" #include "InputManager.h" #include "PADConfig.h" -#include "PAD.h" #include "Host.h" #include "DeviceEnumerator.h" diff --git a/pcsx2/PAD/Windows/PAD.h b/pcsx2/PAD/Windows/PAD.h deleted file mode 100644 index 6a5da04c0e..0000000000 --- a/pcsx2/PAD/Windows/PAD.h +++ /dev/null @@ -1,63 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include -#include -#include -#include -#include -#include "common/pxStreams.h" -#include "common/Console.h" -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "SaveState.h" - -struct HostKeyEvent; -struct WindowInfo; - -struct PadDataS -{ - unsigned char controllerType; - unsigned short buttonStatus; - unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY; - unsigned char moveX, moveY; - unsigned char reserved[91]; -}; - -void PADupdate(int pad); -void PADshutdown(); -s32 PADinit(); -s32 PADopen(const WindowInfo& wi); -void PADclose(); -u8 PADstartPoll(int pad); -u8 PADpoll(u8 value); -HostKeyEvent* PADkeyEvent(); -#ifndef PCSX2_CORE -void PADconfigure(); -#endif -s32 PADfreeze(FreezeAction mode, freezeData* data); -s32 PADsetSlot(u8 port, u8 slot); -void PADsetSettingsDir(const char* dir); diff --git a/pcsx2/PAD/Windows/PADConfig.cpp b/pcsx2/PAD/Windows/PADConfig.cpp index 5b9163b516..c43c737921 100644 --- a/pcsx2/PAD/Windows/PADConfig.cpp +++ b/pcsx2/PAD/Windows/PADConfig.cpp @@ -26,7 +26,6 @@ #include "KeyboardQueue.h" #include "WndProcEater.h" #include "DualShock3.h" -#include "PAD.h" // Needed to know if raw input is available. It requires XP or higher. #include "PADRawInput.h" diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index fac7c6188c..dd67687afe 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -36,11 +36,7 @@ #include "common/StringUtil.h" #include "SPU2/spu2.h" #include "USB/USB.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include diff --git a/pcsx2/Sio.cpp b/pcsx2/Sio.cpp index ab5dd87848..70aa0c2ab2 100644 --- a/pcsx2/Sio.cpp +++ b/pcsx2/Sio.cpp @@ -19,11 +19,7 @@ #include "Common.h" #include "Sio.h" #include "sio_internal.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #ifndef DISABLE_RECORDING # include "Recording/InputRecording.h" diff --git a/pcsx2/System/SysCoreThread.cpp b/pcsx2/System/SysCoreThread.cpp index db85d59d0f..3d89e1c2e3 100644 --- a/pcsx2/System/SysCoreThread.cpp +++ b/pcsx2/System/SysCoreThread.cpp @@ -34,11 +34,7 @@ extern WindowInfo g_gs_window_info; #include "DEV9/DEV9.h" #include "USB/USB.h" #include "MemoryCardFile.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include "DebugTools/MIPSAnalyst.h" #include "DebugTools/SymbolMap.h" diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index 6dfe310e8a..e59a0aef88 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -22,11 +22,7 @@ #include "AppSaveStates.h" #include "AppGameDatabase.h" #include "AppAccelerators.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include "ps2/BiosTools.h" diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index e327e2a733..8b3955d0b5 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -23,11 +23,7 @@ #include "GS/GS.h" #include "MainFrame.h" #include "MSWstuff.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include "gui/Dialogs/ModalPopups.h" diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index 126fe343f8..5f79546c7d 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -23,11 +23,7 @@ #include "System/SysThreads.h" #include "DEV9/DEV9.h" #include "USB/USB.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include "ConsoleLogger.h" #include "MainFrame.h" diff --git a/pcsx2/gui/SysState.cpp b/pcsx2/gui/SysState.cpp index 5391fa0980..2c6e7fd126 100644 --- a/pcsx2/gui/SysState.cpp +++ b/pcsx2/gui/SysState.cpp @@ -24,11 +24,7 @@ #include "common/pxStreams.h" #include "SPU2/spu2.h" #include "USB/USB.h" -#ifdef _WIN32 -#include "PAD/Windows/PAD.h" -#else -#include "PAD/Linux/PAD.h" -#endif +#include "PAD/Gamepad.h" #include "ConsoleLogger.h" diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 25eb4defcc..ef1d5a899c 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -772,7 +772,7 @@ - + diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index 197716de70..1c86cc2cbf 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -2481,9 +2481,6 @@ System\Ps2\PAD - - System\Ps2\PAD - System\Ps2\PAD @@ -2749,6 +2746,9 @@ AppHost + + System\Ps2\PAD +