From 633be51e621662f5405aa9f9569ecaeff643ed9b Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Mon, 9 Feb 2026 14:55:27 +0100 Subject: [PATCH] move reusable code to its own pimpl method --- .../Components/SGVirtualHandComponent.cpp | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index c8be6d3a..b54a1f8c 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -165,6 +165,8 @@ struct USGVirtualHandComponent::FImpl void DrawDebugVirtualHand() const; void TriggerHandVisibilityChangedEvent(bool bNewVisibility) const; + + void AutoStopAllHaptics() const; }; FName USGVirtualHandComponent::FImpl::ParseVirtualHandSettingsOverridesPropertyName(const FName& PropertyName) @@ -385,12 +387,10 @@ void USGVirtualHandComponent::UninitializeComponent() { Super::UninitializeComponent(); - const USGGloveTracker* GloveTracker{USGGloveTracker::GetInstance(GetOuter())}; - USGHapticGlove* Glove{IsValid(GloveTracker) ? GloveTracker->GetGlove(IsRight()) : nullptr}; const bool bAutoStopHaptics = GetVirtualHandSettings().HapticsSettings.bAutoStopAllHapticsOnEndPlay; - if (IsValid(Glove) && Glove->IsConnected() && bAutoStopHaptics) + if (bAutoStopHaptics) { - Glove->StopHaptics(); + Pimpl->AutoStopAllHaptics(); } } @@ -405,12 +405,10 @@ void USGVirtualHandComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) { Super::EndPlay(EndPlayReason); - const USGGloveTracker* GloveTracker{USGGloveTracker::GetInstance(GetOuter())}; - USGHapticGlove* Glove{IsValid(GloveTracker) ? GloveTracker->GetGlove(IsRight()) : nullptr}; const bool bAutoStopHaptics = GetVirtualHandSettings().HapticsSettings.bAutoStopAllHapticsOnEndPlay; - if (IsValid(Glove) && Glove->IsConnected() && bAutoStopHaptics) + if (bAutoStopHaptics) { - Glove->StopHaptics(); + Pimpl->AutoStopAllHaptics(); } } @@ -889,6 +887,17 @@ void USGVirtualHandComponent::FImpl::TriggerHandVisibilityChangedEvent(const boo Owner->OnHandVisibilityChanged(bNewVisibility); } +void USGVirtualHandComponent::FImpl::AutoStopAllHaptics() const +{ + const USGGloveTracker* GloveTracker{USGGloveTracker::GetInstance(Owner->GetOuter())}; + USGHapticGlove* Glove{IsValid(GloveTracker) ? GloveTracker->GetGlove(Owner->IsRight()) : nullptr}; + const bool bAutoStopHaptics = Owner->GetVirtualHandSettings().HapticsSettings.bAutoStopAllHapticsOnEndPlay; + if (IsValid(Glove) && Glove->IsConnected() && bAutoStopHaptics) + { + Glove->StopHaptics(); + } +} + void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const { delete P;