From f218c2bfc9f9eb592707be18b74199a20db9abb5 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 27 Jul 2020 21:21:30 +0930 Subject: [PATCH] Project64-input: Real N64 Range --- Source/Project64-input/DirectInput.cpp | 16 +++++ Source/Project64-input/DirectInput.h | 4 +- Source/Project64-input/InputConfigUI.cpp | 8 +++ Source/Project64-input/InputSettings.cpp | 15 ++++- Source/Project64-input/InputSettingsID.h | 1 + Source/Project64-input/N64Controller.h | 1 + Source/Project64-input/OptionsUI.cpp | 61 ++++++++++++++++++ Source/Project64-input/OptionsUI.h | 6 ++ Source/Project64-input/Project64-input.rc | Bin 16904 -> 18232 bytes .../Project64-input/Project64-input.vcxproj | 2 + .../Project64-input.vcxproj.filters | 6 ++ Source/Project64-input/resource.h | Bin 8918 -> 9100 bytes 12 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 Source/Project64-input/OptionsUI.cpp create mode 100644 Source/Project64-input/OptionsUI.h diff --git a/Source/Project64-input/DirectInput.cpp b/Source/Project64-input/DirectInput.cpp index 0db5426a19..2e4fabd254 100644 --- a/Source/Project64-input/DirectInput.cpp +++ b/Source/Project64-input/DirectInput.cpp @@ -453,8 +453,24 @@ void CDirectInput::GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys) lAxisValueY += l_Value; } } + + if (Controller.RealN64Range && (lAxisValueX || lAxisValueY)) + { + long lAbsoluteX = (lAxisValueX > 0) ? lAxisValueX : -lAxisValueX; + long lAbsoluteY = (lAxisValueY > 0) ? lAxisValueY : -lAxisValueY; + + long lRangeX = lAbsoluteX > lAbsoluteY ? MAX_AXIS_VALUE : MAX_AXIS_VALUE * lAbsoluteX / lAbsoluteY; + long lRangeY = lAbsoluteX > lAbsoluteY ? MAX_AXIS_VALUE * lAbsoluteY / lAbsoluteX : MAX_AXIS_VALUE; + + double dRangeDiagonal = sqrt((double)(lRangeX * lRangeX + lRangeY * lRangeY)); + double dRel = MAX_AXIS_VALUE / dRangeDiagonal; + lAxisValueX = (long)(lAxisValueX * dRel); + lAxisValueY = (long)(lAxisValueY * dRel); + } if (lAxisValueX > MAX_AXIS_VALUE) { lAxisValueX = MAX_AXIS_VALUE; } + if (lAxisValueX < MIN_AXIS_VALUE) { lAxisValueX = MIN_AXIS_VALUE; } if (lAxisValueY > MAX_AXIS_VALUE) { lAxisValueY = MAX_AXIS_VALUE; } + if (lAxisValueY < MIN_AXIS_VALUE) { lAxisValueY = MIN_AXIS_VALUE; } Keys->X_AXIS = lAxisValueX / N64DIVIDER; Keys->Y_AXIS = lAxisValueY / N64DIVIDER; } diff --git a/Source/Project64-input/DirectInput.h b/Source/Project64-input/DirectInput.h index 14556ef4d6..4f01701f0e 100644 --- a/Source/Project64-input/DirectInput.h +++ b/Source/Project64-input/DirectInput.h @@ -15,7 +15,8 @@ class CDirectInput enum { CONFIG_THRESHOLD = 50, - MAX_AXIS_VALUE = 0x7FFF, + MIN_AXIS_VALUE = -32767, + MAX_AXIS_VALUE = 32767, RANGE_RELATIVE = 0x8000, AI_AXE_POSITIVE = 0, AI_AXE_NEGATIVE = 1, @@ -51,7 +52,6 @@ class CDirectInput void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys); void UpdateDeviceData(void); void DevicesChanged(void); - void DeviceAdded(void); private: CDirectInput(); diff --git a/Source/Project64-input/InputConfigUI.cpp b/Source/Project64-input/InputConfigUI.cpp index 4bf0744d44..2943fddee7 100644 --- a/Source/Project64-input/InputConfigUI.cpp +++ b/Source/Project64-input/InputConfigUI.cpp @@ -3,6 +3,7 @@ #include "wtl.h" #include "wtl-BitmapPicture.h" #include "wtl-ScanButton.h" +#include "OptionsUI.h" #include #include #include "resource.h" @@ -26,6 +27,7 @@ class CControllerSettings : MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic) COMMAND_HANDLER_EX(IDC_BTN_DEFAULTS, BN_CLICKED, DefaultBtnClicked) COMMAND_HANDLER_EX(IDC_BTN_SETUP, BN_CLICKED, SetupBtnClicked) + COMMAND_HANDLER_EX(IDC_BTN_OPTIONS, BN_CLICKED, OptionsBtnClicked) COMMAND_HANDLER_EX(IDC_CHK_PLUGGED_IN, BN_CLICKED, ItemChanged) NOTIFY_HANDLER_EX(IDC_TACK_RANGE, NM_RELEASEDCAPTURE, ItemChangedNotify); MESSAGE_HANDLER(WM_HSCROLL, OnScroll) @@ -45,6 +47,7 @@ class CControllerSettings : LRESULT OnScanCanceled(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); void DefaultBtnClicked(UINT Code, int id, HWND ctl); void SetupBtnClicked(UINT Code, int id, HWND ctl); + void OptionsBtnClicked(UINT Code, int id, HWND ctl); void ItemChanged(UINT Code, int id, HWND ctl); LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/); void DisplayController(void); @@ -209,6 +212,11 @@ void CControllerSettings::SetupBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl* m_ButtonUDPad.DetectKey(); } +void CControllerSettings::OptionsBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) +{ + ConfigOption(m_ControllerNumber, m_ControlInfo, m_Controller); +} + void CControllerSettings::ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); diff --git a/Source/Project64-input/InputSettings.cpp b/Source/Project64-input/InputSettings.cpp index 28b989964c..ba21eb3cdd 100644 --- a/Source/Project64-input/InputSettings.cpp +++ b/Source/Project64-input/InputSettings.cpp @@ -26,6 +26,7 @@ static char * Control0_R_ANALOG_Default = "{6F1D2B61-D5A0-11CF-BFC7-444553540000 static const uint32_t Default_DeadZone = 25; static const uint32_t Default_Range = 100; static const uint32_t Default_Plugin = PLUGIN_MEMPAK; +static const bool Default_RealN64Range = true; CInputSettings::CInputSettings() { @@ -80,14 +81,16 @@ void CInputSettings::LoadController(uint32_t ControlIndex, CONTROL & ControllerI InputSettingID PluginSettings[] = { Set_Control0_Plugin }; InputSettingID RangeSettings[] = { Set_Control0_Range }; InputSettingID DeadZoneSettings[] = { Set_Control0_Deadzone }; + InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range }; ControllerInfo.Present = ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])) ? GetSetting((short)PresentSettings[ControlIndex]) != 0 : 0; - ControllerInfo.Plugin = ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])) ? GetSetting((short)PluginSettings[ControlIndex]) : PLUGIN_NONE; - Controller.Range = (uint8_t)(ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])) ? GetSetting((short)RangeSettings[ControlIndex]) : 100); + ControllerInfo.Plugin = ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])) ? GetSetting((short)PluginSettings[ControlIndex]) : Default_Plugin; + Controller.Range = (uint8_t)(ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])) ? GetSetting((short)RangeSettings[ControlIndex]) : Default_Range); if (Controller.Range == 0) { Controller.Range = 1; } if (Controller.Range > 100) { Controller.Range = 100; } - Controller.DeadZone = (uint8_t)(ControlIndex < (sizeof(DeadZoneSettings) / sizeof(DeadZoneSettings[0])) ? GetSetting((short)DeadZoneSettings[ControlIndex]) : 5); + Controller.DeadZone = (uint8_t)(ControlIndex < (sizeof(DeadZoneSettings) / sizeof(DeadZoneSettings[0])) ? GetSetting((short)DeadZoneSettings[ControlIndex]) : Default_DeadZone); if (Controller.DeadZone > 100) { Controller.DeadZone = 100; } + Controller.RealN64Range = (ControlIndex < (sizeof(RealN64RangeSettings) / sizeof(RealN64RangeSettings[0])) ? GetSetting((short)RealN64RangeSettings[ControlIndex]) != 0 : Default_RealN64Range); } void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller) @@ -124,6 +127,7 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr InputSettingID PluginSettings[] = { Set_Control0_Plugin }; InputSettingID RangeSettings[] = { Set_Control0_Range }; InputSettingID DeadzoneSettings[] = { Set_Control0_Deadzone }; + InputSettingID RealN64RangeSettings[] = { Set_Control0_RealN64Range }; for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++) { @@ -152,6 +156,10 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr { SetSetting((short)DeadzoneSettings[ControlIndex], Controller.DeadZone); } + if (ControlIndex < (sizeof(RealN64RangeSettings) / sizeof(RealN64RangeSettings[0]))) + { + SetSetting((short)RealN64RangeSettings[ControlIndex], Controller.RealN64Range ? 1 : 0); + } FlushSettings(); } @@ -233,6 +241,7 @@ void CInputSettings::RegisterSettings(void) RegisterSetting(Set_Control0_Plugin, Data_DWORD_General, "Plugin", "Controller 1", Default_Plugin, nullptr); RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", Default_Range, nullptr); RegisterSetting(Set_Control0_Deadzone, Data_DWORD_General, "Deadzone", "Controller 1", Default_DeadZone, nullptr); + RegisterSetting(Set_Control0_RealN64Range, Data_DWORD_General, "RealN64Range", "Controller 1", Default_RealN64Range, nullptr); RegisterSetting(Set_Control0_U_DPAD, Data_String_General, "DPadUp", "Controller 1", 0, Control0_U_DPAD_Default); RegisterSetting(Set_Control0_D_DPAD, Data_String_General, "DPadDown", "Controller 1", 0, Control0_D_DPAD_Default); RegisterSetting(Set_Control0_L_DPAD, Data_String_General, "DPadLeft", "Controller 1", 0, Control0_L_DPAD_Default); diff --git a/Source/Project64-input/InputSettingsID.h b/Source/Project64-input/InputSettingsID.h index 0b678a5fc1..9625e58e87 100644 --- a/Source/Project64-input/InputSettingsID.h +++ b/Source/Project64-input/InputSettingsID.h @@ -6,6 +6,7 @@ enum InputSettingID Set_Control0_Plugin, Set_Control0_Range, Set_Control0_Deadzone, + Set_Control0_RealN64Range, Set_Control0_U_DPAD, Set_Control0_D_DPAD, Set_Control0_L_DPAD, diff --git a/Source/Project64-input/N64Controller.h b/Source/Project64-input/N64Controller.h index 6cf0b6feff..c607dfb1ea 100644 --- a/Source/Project64-input/N64Controller.h +++ b/Source/Project64-input/N64Controller.h @@ -23,4 +23,5 @@ typedef struct BUTTON R_ANALOG; uint8_t Range; uint8_t DeadZone; + bool RealN64Range; } N64CONTROLLER; diff --git a/Source/Project64-input/OptionsUI.cpp b/Source/Project64-input/OptionsUI.cpp new file mode 100644 index 0000000000..03225ad7b3 --- /dev/null +++ b/Source/Project64-input/OptionsUI.cpp @@ -0,0 +1,61 @@ +#include "OptionsUI.h" +#include "wtl.h" +#include "resource.h" +#include + +class COptionsDlg : + public CDialogImpl +{ +public: + enum { IDD = IDD_Options }; + + BEGIN_MSG_MAP(COptionsDlg) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + COMMAND_ID_HANDLER(IDOK, OnOkCmd) + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + END_MSG_MAP() + + COptionsDlg(uint32_t ControlIndex, CONTROL & ControlInfo, N64CONTROLLER & Controller) : + m_ControlIndex(ControlIndex), + m_ControlInfo(ControlInfo), + m_Controller(Controller) + { + } + + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) + { + CenterWindow(GetParent()); + SetWindowText(stdstr_f("Options - Player %d", m_ControlIndex + 1).ToUTF16().c_str()); + CButton(GetDlgItem(IDC_REAL_N64_RANGE)).SetCheck(m_Controller.RealN64Range ? BST_CHECKED : BST_UNCHECKED); + return TRUE; + } + LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) + { + bool bChanged = false; + bool RealN64Range = CButton(GetDlgItem(IDC_REAL_N64_RANGE)).GetCheck() == BST_CHECKED; + if (RealN64Range != m_Controller.RealN64Range) + { + m_Controller.RealN64Range = RealN64Range; + bChanged = true; + } + if (bChanged) + { + GetParent().SendMessage(PSM_CHANGED); + } + EndDialog(wID); + return 0; + } + LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) + { + EndDialog(wID); + return 0; + } + uint32_t m_ControlIndex; + CONTROL & m_ControlInfo; + N64CONTROLLER & m_Controller; +}; + +void ConfigOption(uint32_t ControlIndex, CONTROL & ControlInfo, N64CONTROLLER & Controller) +{ + COptionsDlg(ControlIndex, ControlInfo, Controller).DoModal(); +} diff --git a/Source/Project64-input/OptionsUI.h b/Source/Project64-input/OptionsUI.h new file mode 100644 index 0000000000..cf356f1918 --- /dev/null +++ b/Source/Project64-input/OptionsUI.h @@ -0,0 +1,6 @@ +#pragma once +#include +#include "ControllerSpec1.1.h" +#include "N64Controller.h" + +void ConfigOption(uint32_t ControlIndex, CONTROL & ControlInfo, N64CONTROLLER & Controller); \ No newline at end of file diff --git a/Source/Project64-input/Project64-input.rc b/Source/Project64-input/Project64-input.rc index 561140dc844d704fb8e043ca463f333e8d384f6a..cfc0c4d2f840dd2b7288add4e4427f3c4ca22190 100644 GIT binary patch delta 616 zcmZuv%}N4M7(F6^4q1UnRz#!GBGR1E8BK(s{A=)U8kJ}zA`wAUP`g^TXj2e(-J&;; zENIs&^cp=t`_3IIu!hT>d++z1bH2a1x%R!@`G&(x#6pRyhZfFofg_ya1n1&27@O9S zLmmmJaBpHo(ZdbmO4vdj6*xQ_C<{wj9oV$n=yI#L;@(4>nnfaPbYRij9P_lXPXyVt zcM*c}4;vrP2yyYEn0^DA_)wA)B{C~wcX?q=;%bO9Pg#k)Cy>PkzdB6!G@-dKLp)BU z3Pto;;Q$9X{$Fbf$aq!S6C##h6z_o-s9)3B}w8YGI*fiUlAKRv{!_}hyZv + @@ -76,6 +77,7 @@ + diff --git a/Source/Project64-input/Project64-input.vcxproj.filters b/Source/Project64-input/Project64-input.vcxproj.filters index 29668a8882..52932c7336 100644 --- a/Source/Project64-input/Project64-input.vcxproj.filters +++ b/Source/Project64-input/Project64-input.vcxproj.filters @@ -39,6 +39,9 @@ Source Files + + Source Files + @@ -80,6 +83,9 @@ Header Files + + Header Files + diff --git a/Source/Project64-input/resource.h b/Source/Project64-input/resource.h index ed3cd0f3039feae01e2fbb1680ff6fa1f2096d58..281f036678f6d88c7a3151b4394c36160a9f32e3 100644 GIT binary patch delta 107 zcmccS+T*_A7vtmwj4ZtV3