1
0
mirror of synced 2024-11-12 01:20:49 +01:00

Update SDL2 and add rumble trigger support

This commit is contained in:
Aaron M 2021-02-14 12:38:22 +13:00
parent e4bf590583
commit 9916f46b8e
6 changed files with 39 additions and 8 deletions

View File

@ -11,6 +11,7 @@ struct EffectTriggers {
void(*Rumble)(double lowfrequency, double highfrequency, double length);
void(*RumbleDevice2)(double lowfrequency, double highfrequency, double length);
void(*RumbleDevice3)(double lowfrequency, double highfrequency, double length);
void(*RumbleTriggers)(double lefttrigger, double righttrigger, double length);
void(*LeftRight)(double smallstrength, double largestrength, double length);
void(*LeftRightDevice2)(double smallstrength, double largestrength, double length);
void(*Springi)(double strength);

View File

@ -23,6 +23,8 @@ DeviceGUID=
;Set to 1 if you want to enable rumble, else 0.
EnableRumble=1
ReverseRumble=0
;Set to 1 if you want to enable rumble in triggers, else 0.
EnableRumbleTriggers=1
; Set to 1 to generate log.txt, else 0. Logs will be appended and not cleared.
Logging=0
; Length of a feedback command. While a long period works fine, some games may still require shorter ones.

View File

@ -403,14 +403,14 @@ cd $(OutDir) && for /D /r %d in (.\Deploy\*) do @xcopy *.dll %d\
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
<Import Project="packages\sdl2.nuget.redist.2.0.9\build\native\sdl2.nuget.redist.targets" Condition="Exists('packages\sdl2.nuget.redist.2.0.9\build\native\sdl2.nuget.redist.targets')" />
<Import Project="packages\sdl2.nuget.2.0.9\build\native\sdl2.nuget.targets" Condition="Exists('packages\sdl2.nuget.2.0.9\build\native\sdl2.nuget.targets')" />
<Import Project="packages\sdl2.nuget.redist.2.0.14\build\native\sdl2.nuget.redist.targets" Condition="Exists('packages\sdl2.nuget.redist.2.0.14\build\native\sdl2.nuget.redist.targets')" />
<Import Project="packages\sdl2.nuget.2.0.14\build\native\sdl2.nuget.targets" Condition="Exists('packages\sdl2.nuget.2.0.14\build\native\sdl2.nuget.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\sdl2.nuget.redist.2.0.9\build\native\sdl2.nuget.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.redist.2.0.9\build\native\sdl2.nuget.redist.targets'))" />
<Error Condition="!Exists('packages\sdl2.nuget.2.0.9\build\native\sdl2.nuget.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.2.0.9\build\native\sdl2.nuget.targets'))" />
<Error Condition="!Exists('packages\sdl2.nuget.redist.2.0.14\build\native\sdl2.nuget.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.redist.2.0.14\build\native\sdl2.nuget.redist.targets'))" />
<Error Condition="!Exists('packages\sdl2.nuget.2.0.14\build\native\sdl2.nuget.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.2.0.14\build\native\sdl2.nuget.targets'))" />
</Target>
</Project>

View File

@ -13,8 +13,8 @@
<ItemGroup>
<None Include="Config\FFBPlugin.ini" />
<None Include="Includes\SDL2.dll" />
<None Include="packages.config" />
<None Include="LICENSE" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DllMain.cpp" />

View File

@ -889,6 +889,7 @@ int configMaxForce = GetPrivateProfileInt(TEXT("Settings"), TEXT("MaxForce"), 10
int enableLogging = GetPrivateProfileInt(TEXT("Settings"), TEXT("Logging"), 0, settingsFilename);
int PowerMode = GetPrivateProfileInt(TEXT("Settings"), TEXT("PowerMode"), 0, settingsFilename);
int EnableRumble = GetPrivateProfileInt(TEXT("Settings"), TEXT("EnableRumble"), 0, settingsFilename);
int EnableRumbleTriggers = GetPrivateProfileInt(TEXT("Settings"), TEXT("EnableRumbleTriggers"), 0, settingsFilename);
int ReverseRumble = GetPrivateProfileInt(TEXT("Settings"), TEXT("ReverseRumble"), 0, settingsFilename);
wchar_t* deviceGUIDString = new wchar_t[256];
int DeviceGUID = GetPrivateProfileString(TEXT("Settings"), TEXT("DeviceGUID"), NULL, deviceGUIDString, 256, settingsFilename);
@ -1017,8 +1018,9 @@ HINSTANCE Get_hInstance()
void Initialize(int device_index)
{
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
hlp.log("in initialize");
SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
SDL_JoystickEventState(SDL_ENABLE);
SDL_JoystickUpdate();
char joystick_guid[256];
@ -1934,6 +1936,26 @@ void TriggerRumbleEffectDevice3(double highfrequency, double lowfrequency, doubl
}
}
void TriggerRumbleTriggerEffect(double lefttrigger, double righttrigger, double length)
{
if (EnableRumbleTriggers == 1)
{
DWORD minForceLow = (DWORD)(lefttrigger > 0.001 ? (configMinForce / 100.0 * 65535.0) : 0);
DWORD minForceHigh = (DWORD)(righttrigger > 0.001 ? (configMinForce / 100.0 * 65535.0) : 0);
DWORD maxForce = (DWORD)(configMaxForce / 100.0 * 65535.0);
DWORD rangeLow = maxForce - minForceLow;
DWORD rangeHigh = maxForce - minForceHigh;
DWORD LeftMotor = (DWORD)(lefttrigger * rangeLow + minForceLow);
DWORD RightMotor = (DWORD)(righttrigger * rangeHigh + minForceHigh);
int RumbleTriggers = SDL_JoystickRumbleTriggers(GameController, LeftMotor, RightMotor, length);
if (RumbleTriggers == -1)
{
EnableRumbleTriggers = 0;
}
}
}
void TriggerSpringEffect(double strength)
{
TriggerSpringEffectWithDefaultOption(strength, false);
@ -2256,6 +2278,7 @@ DWORD WINAPI FFBLoop(LPVOID lpParam)
t.Rumble = &TriggerRumbleEffect;
t.RumbleDevice2 = &TriggerRumbleEffectDevice2;
t.RumbleDevice3 = &TriggerRumbleEffectDevice3;
t.RumbleTriggers = &TriggerRumbleTriggerEffect;
t.LeftRight = &TriggerLeftRightEffect;
t.LeftRightDevice2 = &TriggerLeftRightDevice2Effect;
t.Springi = &TriggerSpringEffectInfinite;
@ -3294,6 +3317,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved)
{
SDL_JoystickRumble(GameController, 0, 0, 0);
}
if (EnableRumbleTriggers == 1)
{
SDL_JoystickRumbleTriggers(GameController, 0, 0, 0);
}
}
if (GameController2)

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="sdl2.nuget" version="2.0.9" targetFramework="native" />
<package id="sdl2.nuget.redist" version="2.0.9" targetFramework="native" />
<package id="sdl2.nuget" version="2.0.14" targetFramework="native" />
<package id="sdl2.nuget.redist" version="2.0.14" targetFramework="native" />
</packages>