Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.3.0 #61

Merged
merged 18 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/actions/version/action.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: version

runs:
using: "composite"
using: 'composite'
steps:
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
with:
versionSpec: '5.x'
includePrerelease: true
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.15
with:
useConfigFile: true
- name: Inject Version
run: |
$json = Get-Content 'JoystickPlugin.uplugin' -raw | ConvertFrom-Json
$json.VersionName = "${{ steps.gitversion.outputs.semVer }}"
$json | ConvertTo-Json -depth 32 | Set-Content 'JoystickPlugin.uplugin'
shell: powershell
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'
includePrerelease: true
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true
- name: Inject Version
run: |
$json = Get-Content 'JoystickPlugin.uplugin' -raw | ConvertFrom-Json
$json.VersionName = "${{ steps.gitversion.outputs.semVer }}"
$json | ConvertTo-Json -depth 32 | Set-Content 'JoystickPlugin.uplugin'
shell: powershell
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ jobs:
fetch-depth: 0
- name: Setup Versioning
uses: ./.github/actions/version
- name: Package Plugin - 5.0
- name: Package Plugin - 5.1
uses: ./.github/actions/package
with:
engineVersion: '5.0'
engineVersion: '5.1'
releaseVersion: ${{ steps.gitversion.outputs.semVer }}
epicGamesDirectory: ${{ secrets.EPIC_GAMES_DIRECTORY }}
launcherDirectory: ${{ secrets.LAUNCHER_DIRECTORY }}
- name: Package Plugin - 5.1
- name: Package Plugin - 5.2
uses: ./.github/actions/package
with:
engineVersion: '5.1'
engineVersion: '5.2'
releaseVersion: ${{ steps.gitversion.outputs.semVer }}
epicGamesDirectory: ${{ secrets.EPIC_GAMES_DIRECTORY }}
launcherDirectory: ${{ secrets.LAUNCHER_DIRECTORY }}
- name: Package Plugin - 5.2
- name: Package Plugin - 5.3
uses: ./.github/actions/package
with:
engineVersion: '5.2'
engineVersion: '5.3'
releaseVersion: ${{ steps.gitversion.outputs.semVer }}
epicGamesDirectory: ${{ secrets.EPIC_GAMES_DIRECTORY }}
launcherDirectory: ${{ secrets.LAUNCHER_DIRECTORY }}
Expand Down
8 changes: 4 additions & 4 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mode: Mainline
major-version-bump-message: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)"
minor-version-bump-message: "^(feat)(\\([\\w\\s]*\\))?:"
patch-version-bump-message: "^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?:"
major-version-bump-message: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)"
minor-version-bump-message: "^(feat)(\\([\\w\\s-]*\\))?:"
patch-version-bump-message: "^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:"
continuous-delivery-fallback-tag: ''
branches:
develop:
Expand All @@ -16,4 +16,4 @@ branches:
tag: rc
main:
tag: ''
increment: Minor
increment: Minor
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Please ensure you backup your project before upgrading!

This plugin aims to provide a simple plug and play system for Joysticks and Steering Wheels (with Forced Feedback capabilities) for Unreal Engine 4/5.

### Features

* Native Unreal Input Loop :joystick:
* Event Driven Structure :mailbox_with_mail:
* Assign Controller to a player :video_game:
* Haptic/Force Feedback :collision:
* Sensor Data (Gyro/Accelerometer) :dancer:
* LED Control :rotating_light:

### How is this any different to the existing plugins? :thinking:

This plugin has been rebuilt (almost entirely) from it's forked version.
Expand Down
88 changes: 58 additions & 30 deletions Source/JoystickPlugin/Private/JoystickInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include "GameFramework/InputSettings.h"
#include "GenericPlatform/IInputInterface.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Engine/Engine.h"

const static FName JoystickCategory = "Joystick";

FJoystickInputDevice::FJoystickInputDevice(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler) : MessageHandler(InMessageHandler)
{
{
EKeys::AddMenuCategoryDisplayInfo(JoystickCategory, FText::FromString("Joystick"), TEXT("GraphEditor.PadEvent_16x"));
}

Expand Down Expand Up @@ -95,7 +96,7 @@ void FJoystickInputDevice::InitialiseAxis(const FJoystickInstanceId& InstanceId,
if (!EKeys::GetKeyDetails(AxisKey).IsValid())
{
EKeys::AddKey(AxisKeyDetails);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Axis %s (%s) %i"), *AxisKeyName, *AxisDisplayName, InstanceId);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Axis %s (%s) %d"), *AxisKeyName, *AxisDisplayName, InstanceId);
}

const FKey& MappedKey = AxisKeyDetails.GetKey();
Expand Down Expand Up @@ -127,7 +128,7 @@ void FJoystickInputDevice::InitialiseButtons(const FJoystickInstanceId& Instance
if (!EKeys::GetKeyDetails(ButtonKey).IsValid())
{
EKeys::AddKey(ButtonKeyDetails);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Button %s (%s) %i"), *ButtonKeyName, *ButtonDisplayName, InstanceId);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Button %s (%s) %d"), *ButtonKeyName, *ButtonDisplayName, InstanceId);
}

const FKey& MappedKey = ButtonKeyDetails.GetKey();
Expand Down Expand Up @@ -168,7 +169,7 @@ void FJoystickInputDevice::InitialiseHats(const FJoystickInstanceId& InstanceId,
if (!EKeys::GetKeyDetails(HatKey).IsValid())
{
EKeys::AddKey(HatKeyDetails);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Hat %s (%s) %i"), *HatKeyName, *HatDisplayName, InstanceId);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Hat %s (%s) %d"), *HatKeyName, *HatDisplayName, InstanceId);
}

const FKey& MappedKey = HatKeyDetails.GetKey();
Expand Down Expand Up @@ -208,7 +209,7 @@ void FJoystickInputDevice::InitialiseBalls(const FJoystickInstanceId& InstanceId
if (!EKeys::GetKeyDetails(BallKey).IsValid())
{
EKeys::AddKey(BallKeyDetails);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Ball %s (%s) %i"), *BallKeyName, *BallDisplayName, InstanceId);
FJoystickLogManager::Get()->LogDebug(TEXT("Added Ball %s (%s) %d"), *BallKeyName, *BallDisplayName, InstanceId);
}

const FKey& MappedKey = BallKeyDetails.GetKey();
Expand Down Expand Up @@ -250,7 +251,8 @@ void FJoystickInputDevice::JoystickPluggedIn(const FDeviceInfoSDL& Device)
}
else
{
BaseKeyName = FString::Printf(TEXT("Joystick_%s_%d"), *Device.SafeDeviceName, Device.InternalDeviceIndex);
const FString DeviceName = Device.SafeDeviceName.Replace(TEXT(" "), TEXT("_"));
BaseKeyName = FString::Printf(TEXT("Joystick_%s_%d"), *DeviceName, Device.InternalDeviceIndex);
BaseDisplayName = FString::Printf(TEXT("%s %d"), *Device.ProductName, Device.InternalDeviceIndex);
}
}
Expand All @@ -273,7 +275,7 @@ void FJoystickInputDevice::JoystickPluggedIn(const FDeviceInfoSDL& Device)

UpdateAxisProperties();

FJoystickLogManager::Get()->LogInformation(TEXT("Device Ready: %s (%i) - Instance Id: %i"), *Device.DeviceName, Device.InternalDeviceIndex, Device.InstanceId);
FJoystickLogManager::Get()->LogInformation(TEXT("Device Ready: %s (%d) - Instance Id: %d"), *Device.DeviceName, Device.InternalDeviceIndex, Device.InstanceId);
}

void FJoystickInputDevice::JoystickUnplugged(const FJoystickInstanceId& InstanceId) const
Expand Down Expand Up @@ -301,8 +303,7 @@ void FJoystickInputDevice::JoystickButton(const FJoystickInstanceId& InstanceId,
}

FButtonData& State = DeviceData.Buttons[Button];
State.PreviousButtonState = State.ButtonState;
State.ButtonState = Pressed;
State.Update(Pressed);

FJoystickLogManager::Get()->LogDebug(TEXT("Event JoystickButton Device=%d Button=%d State=%d"), InstanceId, Button, Pressed);
}
Expand All @@ -321,8 +322,7 @@ void FJoystickInputDevice::JoystickAxis(const FJoystickInstanceId& InstanceId, c
}

FAxisData& State = DeviceData.Axes[Axis];
State.PreviousValue = State.Value;
State.Value = Value;
State.Update(Value);
}

void FJoystickInputDevice::JoystickHat(const FJoystickInstanceId& InstanceId, const int Hat, const EJoystickPointOfViewDirection Value)
Expand All @@ -339,11 +339,10 @@ void FJoystickInputDevice::JoystickHat(const FJoystickInstanceId& InstanceId, co
}

FHatData& State = DeviceData.Hats[Hat];
State.PreviousDirection = State.Direction;
State.Direction = Value;
State.Update(Value);
}

void FJoystickInputDevice::JoystickBall(const FJoystickInstanceId& InstanceId, const int Ball, const FVector2D Value)
void FJoystickInputDevice::JoystickBall(const FJoystickInstanceId& InstanceId, const int Ball, const FVector2D& Value)
{
if (!JoystickDeviceState.Contains(InstanceId))
{
Expand All @@ -357,8 +356,29 @@ void FJoystickInputDevice::JoystickBall(const FJoystickInstanceId& InstanceId, c
}

FBallData& State = DeviceData.Balls[Ball];
State.PreviousDirection = State.Direction;
State.Direction = Value;
State.Update(Value);
}

void FJoystickInputDevice::JoystickGyro(const FJoystickInstanceId& InstanceId, const int Timestamp, const FVector& Value)
{
if (!JoystickDeviceState.Contains(InstanceId))
{
return;
}

FJoystickDeviceState& DeviceData = JoystickDeviceState[InstanceId];
DeviceData.Motion.UpdateGyro(Value, Timestamp);
}

void FJoystickInputDevice::JoystickAccelerometer(const FJoystickInstanceId& InstanceId, const int Timestamp, const FVector& Value)
{
if (!JoystickDeviceState.Contains(InstanceId))
{
return;
}

FJoystickDeviceState& DeviceData = JoystickDeviceState[InstanceId];
DeviceData.Motion.UpdateAccelerometer(Value, Timestamp);
}

FJoystickDeviceState* FJoystickInputDevice::GetDeviceData(const FJoystickInstanceId& InstanceId)
Expand Down Expand Up @@ -402,9 +422,10 @@ void FJoystickInputDevice::SendControllerEvents()
const int PlayerId = DeviceInfo.PlayerId;
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
IPlatformInputDeviceMapper& DeviceMapper = IPlatformInputDeviceMapper::Get();
FPlatformUserId PlatformUser = FGenericPlatformMisc::GetPlatformUserForUserIndex(DeviceInfo.PlayerId);
FInputDeviceId InputDevice = INPUTDEVICEID_NONE;
DeviceMapper.RemapControllerIdToPlatformUserAndDevice(PlayerId, OUT PlatformUser, OUT InputDevice);
DeviceMapper.AllocateNewInputDeviceId();
FPlatformUserId PlatformUser = FGenericPlatformMisc::GetPlatformUserForUserIndex(PlayerId);
FInputDeviceId InputDeviceId = FInputDeviceId::CreateFromInternalId(InstanceId);
DeviceMapper.RemapControllerIdToPlatformUserAndDevice(PlayerId, OUT PlatformUser, OUT InputDeviceId);
#endif

FInputDeviceScope InputScope(this, JoystickInputInterfaceName, InstanceId, DeviceInfo.DeviceName);
Expand All @@ -418,7 +439,7 @@ void FJoystickInputDevice::SendControllerEvents()
if (AxisKey.IsValid())
{
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnControllerAnalog(AxisKey.GetFName(), PlatformUser, InputDevice, CurrentState.Axes[AxisIndex].GetValue());
MessageHandler->OnControllerAnalog(AxisKey.GetFName(), PlatformUser, InputDeviceId, CurrentState.Axes[AxisIndex].GetValue());
#else
MessageHandler->OnControllerAnalog(AxisKey.GetFName(), PlayerId, CurrentState.Axes[AxisIndex].GetValue());
#endif
Expand All @@ -435,10 +456,10 @@ void FJoystickInputDevice::SendControllerEvents()
const FKey& YHatKey = DeviceHatKeys[1][InstanceId][HatIndex];
if (XHatKey.IsValid() && YHatKey.IsValid())
{
const FVector2D& POVAxis = UJoystickFunctionLibrary::POVAxis(CurrentState.Hats[HatIndex].Direction);
const FVector2D& POVAxis = UJoystickFunctionLibrary::POVAxis(CurrentState.Hats[HatIndex].GetValue());
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnControllerAnalog(XHatKey.GetFName(), PlatformUser, InputDevice, POVAxis.X);
MessageHandler->OnControllerAnalog(YHatKey.GetFName(), PlatformUser, InputDevice, POVAxis.Y);
MessageHandler->OnControllerAnalog(XHatKey.GetFName(), PlatformUser, InputDeviceId, POVAxis.X);
MessageHandler->OnControllerAnalog(YHatKey.GetFName(), PlatformUser, InputDeviceId, POVAxis.Y);
#else
MessageHandler->OnControllerAnalog(XHatKey.GetFName(), PlayerId, POVAxis.X);
MessageHandler->OnControllerAnalog(YHatKey.GetFName(), PlayerId, POVAxis.Y);
Expand All @@ -456,10 +477,10 @@ void FJoystickInputDevice::SendControllerEvents()
const FKey& YBallKey = DeviceBallKeys[1][InstanceId][BallIndex];
if (XBallKey.IsValid() && YBallKey.IsValid())
{
const FVector2D& BallAxis = CurrentState.Balls[BallIndex].Direction;
const FVector2D& BallAxis = CurrentState.Balls[BallIndex].GetValue();
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnControllerAnalog(XBallKey.GetFName(), PlatformUser, InputDevice, BallAxis.X);
MessageHandler->OnControllerAnalog(YBallKey.GetFName(), PlatformUser, InputDevice, BallAxis.Y);
MessageHandler->OnControllerAnalog(XBallKey.GetFName(), PlatformUser, InputDeviceId, BallAxis.X);
MessageHandler->OnControllerAnalog(YBallKey.GetFName(), PlatformUser, InputDeviceId, BallAxis.Y);
#else
MessageHandler->OnControllerAnalog(XBallKey.GetFName(), PlayerId, BallAxis.X);
MessageHandler->OnControllerAnalog(YBallKey.GetFName(), PlayerId, BallAxis.Y);
Expand All @@ -477,20 +498,20 @@ void FJoystickInputDevice::SendControllerEvents()
if (ButtonKey.IsValid())
{
FButtonData& ButtonData = JoystickDeviceState[InstanceId].Buttons[ButtonIndex];
if (ButtonData.ButtonState != ButtonData.PreviousButtonState)
if (ButtonData.GetValue() != ButtonData.GetPreviousValue())
{
if (ButtonData.ButtonState)
if (ButtonData.GetValue())
{
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnControllerButtonPressed(ButtonKey.GetFName(), PlatformUser, InputDevice, false);
MessageHandler->OnControllerButtonPressed(ButtonKey.GetFName(), PlatformUser, InputDeviceId, false);
#else
MessageHandler->OnControllerButtonPressed(ButtonKey.GetFName(), PlayerId, false);
#endif
}
else
{
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnControllerButtonReleased(ButtonKey.GetFName(), PlatformUser, InputDevice, false);
MessageHandler->OnControllerButtonReleased(ButtonKey.GetFName(), PlatformUser, InputDeviceId, false);
#else
MessageHandler->OnControllerButtonReleased(ButtonKey.GetFName(), PlayerId, false);
#endif
Expand All @@ -501,6 +522,13 @@ void FJoystickInputDevice::SendControllerEvents()
}
}
}

// Gyro
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
MessageHandler->OnMotionDetected(FVector::ZeroVector, CurrentState.Motion.Gyro, FVector::ZeroVector, CurrentState.Motion.Accelerometer, PlatformUser, InputDeviceId);
#else
MessageHandler->OnMotionDetected(FVector::ZeroVector, CurrentState.Motion.Gyro, FVector::ZeroVector, CurrentState.Motion.Accelerometer, PlayerId);
#endif
}

JoystickSubsystem->Update();
Expand Down
1 change: 1 addition & 0 deletions Source/JoystickPlugin/Private/JoystickInputSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "JoystickInputSettings.h"
#include "JoystickInputDevice.h"
#include "JoystickSubsystem.h"
#include "Engine/Engine.h"

UJoystickInputSettings::UJoystickInputSettings()
{
Expand Down
Loading
Loading