Project64-input: Real N64 Range

This commit is contained in:
zilmar 2020-07-27 21:21:30 +09:30
parent 6417eaf866
commit f218c2bfc9
12 changed files with 115 additions and 5 deletions

View File

@ -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;
}

View File

@ -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 @@ public:
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
void UpdateDeviceData(void);
void DevicesChanged(void);
void DeviceAdded(void);
private:
CDirectInput();

View File

@ -3,6 +3,7 @@
#include "wtl.h"
#include "wtl-BitmapPicture.h"
#include "wtl-ScanButton.h"
#include "OptionsUI.h"
#include <Common\stdtypes.h>
#include <Common\StdString.h>
#include "resource.h"
@ -26,6 +27,7 @@ public:
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 @@ private:
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);

View File

@ -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);

View File

@ -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,

View File

@ -23,4 +23,5 @@ typedef struct
BUTTON R_ANALOG;
uint8_t Range;
uint8_t DeadZone;
bool RealN64Range;
} N64CONTROLLER;

View File

@ -0,0 +1,61 @@
#include "OptionsUI.h"
#include "wtl.h"
#include "resource.h"
#include <Common\StdString.h>
class COptionsDlg :
public CDialogImpl<COptionsDlg>
{
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();
}

View File

@ -0,0 +1,6 @@
#pragma once
#include <Common\stdtypes.h>
#include "ControllerSpec1.1.h"
#include "N64Controller.h"
void ConfigOption(uint32_t ControlIndex, CONTROL & ControlInfo, N64CONTROLLER & Controller);

View File

@ -63,6 +63,7 @@
<ClCompile Include="InputMain.cpp" />
<ClCompile Include="CProject64Input.cpp" />
<ClCompile Include="InputSettings.cpp" />
<ClCompile Include="OptionsUI.cpp" />
<ClCompile Include="wtl-BitmapPicture.cpp" />
<ClCompile Include="wtl-ScanButton.cpp" />
</ItemGroup>
@ -76,6 +77,7 @@
<ClInclude Include="InputConfigUI.h" />
<ClInclude Include="ControllerSpec1.1.h" />
<ClInclude Include="CProject64Input.h" />
<ClInclude Include="OptionsUI.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="wtl-BitmapPicture.h" />
<ClInclude Include="wtl-ScanButton.h" />

View File

@ -39,6 +39,9 @@
<ClCompile Include="DeviceNotification.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OptionsUI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ControllerSpec1.1.h">
@ -80,6 +83,9 @@
<ClInclude Include="DeviceNotification.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OptionsUI.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Version.h.in">

Binary file not shown.