From e495b402181c8e413f4ed2517c59e12320156a43 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Thu, 15 Jun 2023 17:36:55 +0200 Subject: [PATCH] refactor the newly added motion source settings and off-load them from the wrist tracker to the settings system, though this causes crashes still --- .../Components/SGWristTrackerComponent.cpp | 21 ++++++---- .../Components/SGWristTrackerComponent.h | 39 +------------------ .../SGWristTrackerComponentKismetLibrary.cpp | 24 ------------ .../SGWristTrackerComponentKismetLibrary.h | 16 -------- .../SenseGloveKismet.Build.cs | 1 - .../Private/SGSettings/SGSettings.cpp | 7 ++++ .../SGSettings/SGWristTrackingSettings.cpp | 6 +++ .../SGSettings/SGWristTrackingSettings.h | 17 ++++++++ .../SenseGloveSettings.Build.cs | 1 + 9 files changed, 47 insertions(+), 85 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp index 98f301af..364b68b0 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp @@ -106,11 +106,6 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj SetReceivesDecals(false); SetCanEverAffectNavigation(false); - LeftHandMotionSource = EControllerHand::Left; - RightHandMotionSource = EControllerHand::Right; - - SetRight(true); - bOverridePluginWristTrackingSettings = false; WristTrackingSettings = FSGWristTrackingSettings( ESGPositionalTrackingHardware::None, @@ -118,6 +113,8 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj FVector::ZeroVector, FRotator::ZeroRotator, FRotator::ZeroRotator, + EControllerHand::Left, + EControllerHand::Right, false, FSGDebugGizmoSettings( 4.0f, 1.0f, @@ -132,6 +129,8 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj Glove = nullptr; WristLocation = FVector::ZeroVector; WristRotation = FRotator::ZeroRotator; + + SetRight(true); } const FSGWristTrackingSettings& USGWristTrackerComponent::GetWristTrackingSettings() const @@ -141,7 +140,13 @@ const FSGWristTrackingSettings& USGWristTrackerComponent::GetWristTrackingSettin return WristTrackingSettings; } - return USGSettings::GetInstance()->GetWristTrackingSettings(); + const USGSettings* Settings{USGSettings::GetInstance()}; + if (!ensureAlwaysMsgf(Settings, TEXT("The settings subsystem has not been initialized!"))) + { + return WristTrackingSettings; + } + + return Settings->GetWristTrackingSettings(); } void USGWristTrackerComponent::SetWristTrackingSettings(const FSGWristTrackingSettings& InWristTrackingSettings) @@ -155,7 +160,9 @@ void USGWristTrackerComponent::SetWristTrackingSettings(const FSGWristTrackingSe void USGWristTrackerComponent::SetRight(const bool bRight) { - SetTrackingSource(bRight ? GetRightHandMotionSource() : GetLeftHandMotionSource()); + SetTrackingSource(bRight + ? GetWristTrackingSettings().LeftHandMotionSource + : GetWristTrackingSettings().RightHandMotionSource); } #if WITH_EDITOR diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h index c2b18744..3b6768bc 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h @@ -36,7 +36,6 @@ #pragma once #include "GameFramework/Actor.h" -#include "InputCoreTypes.h" #include "Math/Rotator.h" #include "Math/Vector.h" #include "MotionControllerComponent.h" @@ -95,20 +94,6 @@ private: FImplDeleter PimplDeleter; private: - /** - * Determines which motion source to use. - * For Oculus this is usually Left, and for VIVE usually LeftFoot. - */ - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - EControllerHand LeftHandMotionSource; - - /** - * Determines which motion source to use. - * For Oculus this is usually Right, and for VIVE usually RightFoot. - */ - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - EControllerHand RightHandMotionSource; - /** * Determines whether to override the plugin's wrist tracking settings or not. */ @@ -136,26 +121,6 @@ private: FRotator WristRotation; public: - FORCEINLINE EControllerHand GetLeftHandMotionSource() const - { - return LeftHandMotionSource; - } - - void SetLeftHandMotionSource(const EControllerHand InLeftHandMotionSource) - { - LeftHandMotionSource = InLeftHandMotionSource; - } - - FORCEINLINE EControllerHand GetRightHandMotionSource() const - { - return RightHandMotionSource; - } - - void SetRightHandMotionSource(const EControllerHand InRightHandMotionSource) - { - RightHandMotionSource = InRightHandMotionSource; - } - FORCEINLINE bool OverridesPluginWristTrackingSettings() const { return !!bOverridePluginWristTrackingSettings; @@ -171,12 +136,12 @@ public: FORCEINLINE bool IsLeft() const { - return GetTrackingSource() == GetLeftHandMotionSource(); + return GetTrackingSource() == GetWristTrackingSettings().LeftHandMotionSource; } FORCEINLINE bool IsRight() const { - return GetTrackingSource() == GetRightHandMotionSource(); + return GetTrackingSource() == GetWristTrackingSettings().RightHandMotionSource; } void SetRight(const bool bRight); diff --git a/Source/SenseGloveKismet/Private/SGKismet/SGWristTrackerComponentKismetLibrary.cpp b/Source/SenseGloveKismet/Private/SGKismet/SGWristTrackerComponentKismetLibrary.cpp index c0e5981b..31d8b1f2 100644 --- a/Source/SenseGloveKismet/Private/SGKismet/SGWristTrackerComponentKismetLibrary.cpp +++ b/Source/SenseGloveKismet/Private/SGKismet/SGWristTrackerComponentKismetLibrary.cpp @@ -37,30 +37,6 @@ #include "SenseGlove/Components/SGWristTrackerComponent.h" -EControllerHand UWristTrackerComponentKismetLibrary::GetLeftHandMotionSource( - const USGWristTrackerComponent* WristTrackerComponent) -{ - return WristTrackerComponent->GetLeftHandMotionSource(); -} - -void UWristTrackerComponentKismetLibrary::SetLeftHandMotionSource( - USGWristTrackerComponent* WristTrackerComponent, const EControllerHand InLeftHandMotionSource) -{ - WristTrackerComponent->SetLeftHandMotionSource(InLeftHandMotionSource); -} - -EControllerHand UWristTrackerComponentKismetLibrary::GetRightHandMotionSource( - const USGWristTrackerComponent* WristTrackerComponent) -{ - return WristTrackerComponent->GetRightHandMotionSource(); -} - -void UWristTrackerComponentKismetLibrary::SetRightHandMotionSource( - USGWristTrackerComponent* WristTrackerComponent, const EControllerHand InRightHandMotionSource) -{ - WristTrackerComponent->SetRightHandMotionSource(InRightHandMotionSource); -} - bool UWristTrackerComponentKismetLibrary::OverridesPluginWristTrackingSettings( const USGWristTrackerComponent* WristTrackerComponent) { diff --git a/Source/SenseGloveKismet/Public/SGKismet/SGWristTrackerComponentKismetLibrary.h b/Source/SenseGloveKismet/Public/SGKismet/SGWristTrackerComponentKismetLibrary.h index cb4bd755..2f373eb6 100644 --- a/Source/SenseGloveKismet/Public/SGKismet/SGWristTrackerComponentKismetLibrary.h +++ b/Source/SenseGloveKismet/Public/SGKismet/SGWristTrackerComponentKismetLibrary.h @@ -37,8 +37,6 @@ #pragma once -#include "InputCoreTypes.h" - #include "SGKismet/SGBlueprintFunctionLibrary.h" #include "SGSettings/SGWristTrackingSettings.h" @@ -55,20 +53,6 @@ class SENSEGLOVEKISMET_API UWristTrackerComponentKismetLibrary final : public US GENERATED_BODY() public: - UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component") - static EControllerHand GetLeftHandMotionSource(const USGWristTrackerComponent* WristTrackerComponent); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component") - static void SetLeftHandMotionSource(UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent, - EControllerHand InLeftHandMotionSource); - - UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component") - static EControllerHand GetRightHandMotionSource(const USGWristTrackerComponent* WristTrackerComponent); - - UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component") - static void SetRightHandMotionSource(UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent, - EControllerHand InRightHandMotionSource); - UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Wrist Tracker Component") static bool OverridesPluginWristTrackingSettings(const USGWristTrackerComponent* WristTrackerComponent); diff --git a/Source/SenseGloveKismet/SenseGloveKismet.Build.cs b/Source/SenseGloveKismet/SenseGloveKismet.Build.cs index 3ebf5125..440cdee7 100644 --- a/Source/SenseGloveKismet/SenseGloveKismet.Build.cs +++ b/Source/SenseGloveKismet/SenseGloveKismet.Build.cs @@ -55,7 +55,6 @@ public class SenseGloveKismet : ModuleRules "CoreUObject", "Engine", "HeadMountedDisplay", - "InputCore", "SenseGlove", "SenseGloveCore", "SenseGloveLog", diff --git a/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp b/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp index 2d090bb2..376f19e2 100644 --- a/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp +++ b/Source/SenseGloveSettings/Private/SGSettings/SGSettings.cpp @@ -65,6 +65,11 @@ struct USGSettings::FImpl USGSettings* USGSettings::GetInstance() { + if (!ensureAlwaysMsgf(GEngine, TEXT("The engine has not been initialized!"))) + { + return nullptr; + } + USGSettings* Instance{GEngine->GetEngineSubsystem()}; return Instance; } @@ -78,6 +83,8 @@ USGSettings::USGSettings() FVector::ZeroVector, FRotator::ZeroRotator, FRotator::ZeroRotator, + EControllerHand::Left, + EControllerHand::Right, false, FSGDebugGizmoSettings( 4.0f, 1.0f, diff --git a/Source/SenseGloveSettings/Private/SGSettings/SGWristTrackingSettings.cpp b/Source/SenseGloveSettings/Private/SGSettings/SGWristTrackingSettings.cpp index 4ad402e4..af340bbe 100644 --- a/Source/SenseGloveSettings/Private/SGSettings/SGWristTrackingSettings.cpp +++ b/Source/SenseGloveSettings/Private/SGSettings/SGWristTrackingSettings.cpp @@ -41,6 +41,8 @@ FSGWristTrackingSettings::FSGWristTrackingSettings() TrackingHardwareLocationOffsetRightHand(FVector::ZeroVector), TrackingHardwareRotationOffsetLeftHand(FRotator::ZeroRotator), TrackingHardwareRotationOffsetRightHand(FRotator::ZeroRotator), + LeftHandMotionSource(EControllerHand::Left), + RightHandMotionSource(EControllerHand::Right), bDrawWristTrackerDebugGizmo(false), WristTrackerDebugGizmoSettings(FSGDebugGizmoSettings()) { @@ -52,6 +54,8 @@ FSGWristTrackingSettings::FSGWristTrackingSettings( const FVector& InTrackingHardwareLocationOffsetRightHand, const FRotator& InTrackingHardwareRotationOffsetLeftHand, const FRotator& InTrackingHardwareRotationOffsetRightHand, + const EControllerHand InLeftHandMotionSource, + const EControllerHand InRightHandMotionSource, const bool bInDrawWristTrackerDebugGizmo, const FSGDebugGizmoSettings& InWristTrackerDebugGizmoSettings) : TrackingHardware(InTrackingHardware), @@ -59,6 +63,8 @@ FSGWristTrackingSettings::FSGWristTrackingSettings( TrackingHardwareLocationOffsetRightHand(InTrackingHardwareLocationOffsetRightHand), TrackingHardwareRotationOffsetLeftHand(InTrackingHardwareRotationOffsetLeftHand), TrackingHardwareRotationOffsetRightHand(InTrackingHardwareRotationOffsetRightHand), + LeftHandMotionSource(InLeftHandMotionSource), + RightHandMotionSource(InRightHandMotionSource), bDrawWristTrackerDebugGizmo(bInDrawWristTrackerDebugGizmo), WristTrackerDebugGizmoSettings(InWristTrackerDebugGizmoSettings) { diff --git a/Source/SenseGloveSettings/Public/SGSettings/SGWristTrackingSettings.h b/Source/SenseGloveSettings/Public/SGSettings/SGWristTrackingSettings.h index b539b048..617e39db 100644 --- a/Source/SenseGloveSettings/Public/SGSettings/SGWristTrackingSettings.h +++ b/Source/SenseGloveSettings/Public/SGSettings/SGWristTrackingSettings.h @@ -35,6 +35,7 @@ #pragma once +#include "InputCoreTypes.h" #include "UObject/ObjectMacros.h" #include "SGSettings/SGDebugGizmoSettings.h" @@ -82,6 +83,20 @@ public: meta=(EditCondition="TrackingHardware == ESGPositionalTrackingHardware::Custom", EditConditionHides)) FRotator TrackingHardwareRotationOffsetRightHand; + /** + * Determines which motion source to use. + * For Oculus this is usually Left, and for VIVE usually LeftFoot. + */ + UPROPERTY(Config, EditDefaultsOnly, Category="Wrist Tracking") + EControllerHand LeftHandMotionSource; + + /** + * Determines which motion source to use. + * For Oculus this is usually Right, and for VIVE usually RightFoot. + */ + UPROPERTY(Config, EditDefaultsOnly, Category="Wrist Tracking") + EControllerHand RightHandMotionSource; + /** * If enabled, draws debug Wrist trackers where possible. */ @@ -104,6 +119,8 @@ public: const FVector& InTrackingHardwareLocationOffsetRightHand, const FRotator& InTrackingHardwareRotationOffsetLeftHand, const FRotator& InTrackingHardwareRotationOffsetRightHand, + EControllerHand InLeftHandMotionSource, + EControllerHand InRightHandMotionSource, bool bInDrawWristTrackerDebugGizmo, const FSGDebugGizmoSettings& InWristTrackerDebugGizmoSettings); }; \ No newline at end of file diff --git a/Source/SenseGloveSettings/SenseGloveSettings.Build.cs b/Source/SenseGloveSettings/SenseGloveSettings.Build.cs index b432fa06..683b75e2 100644 --- a/Source/SenseGloveSettings/SenseGloveSettings.Build.cs +++ b/Source/SenseGloveSettings/SenseGloveSettings.Build.cs @@ -54,6 +54,7 @@ public class SenseGloveSettings : ModuleRules { "CoreUObject", "Engine", + "InputCore", "SenseGloveCore", "SenseGloveLog", "SenseGloveTypes",