From 88cc8411c0d2f89df21f7ea500c732bddb0fb81c Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Thu, 13 Nov 2025 10:15:28 +0100 Subject: [PATCH] Revert "get rid of SGPawn::Tick, introduce SGPawn::HandVelocitySamplerFramerate, and make hand velocity sampler timer-based instead of tick-based" This reverts commit 8dea65ed40b1ec6ef7c3e7e32f09ecfd41453159. --- Handbook/src/appendix/changelog.md | 3 - .../SenseGlove/GameFramework/SGPawn.cpp | 60 +++---------------- .../Public/SenseGlove/GameFramework/SGPawn.h | 4 +- 3 files changed, 10 insertions(+), 57 deletions(-) diff --git a/Handbook/src/appendix/changelog.md b/Handbook/src/appendix/changelog.md index 7cf72646..e0f6eeb4 100644 --- a/Handbook/src/appendix/changelog.md +++ b/Handbook/src/appendix/changelog.md @@ -24,7 +24,6 @@ This minor release focuses on delivering performance improvements, made possible - Added third-party module `SGLogThirdPartyLibs`. - Added third-party module `SGLoguruThirdPartyLibs`. - Added third-party module `SGWjwwoodSerialThirdPartyLibs` to replace `SGSerialThirdPartyLibs` while retaining `SGSerialThirdPartyLibs` for a different purpose. See the relevant comment in the Changed section below. -- Added UPROPERTY `SGPawn::HandVelocitySamplerFramerate` to control the hand velocity sampler's timer interval. This allows getting rid of `SGPawn::Tick()` for improved performance and reliability, which also improves chopiness on low frame-rates. - Added UPROPERTY `USGTouchComponent::VibrotactileAmplitude`. - Added UPROPERTY `USGTouchComponent::VibrotactileFrequency`. - Added method `USGTouchComponent::GetVibrotactileAmplitude()`. @@ -47,7 +46,6 @@ This minor release focuses on delivering performance improvements, made possible - As a result of SenseGlove libraries >= `v2.300.0` changing it's directory structure, the `ThirdParty` folder's directory structure has been revamped. - Renamed third-party module `SGSerialThirdPartyLibs` to `SGWjwwoodSerialThirdPartyLibs` since SenseGlove libraries >= `v2.300.0` ships a new static library named `sgserial`. Thus, to avoid confusion and naming conflicts the third-party `serial` static library is now provided by the `SGWjwwoodSerialThirdPartyLibs` module and `sgserial` is provided by the `SGSerialThirdPartyLibs` module. - `FSGGloveTrackingSettings::GloveConnectivityCheckInterval` settings have been renamed to `FSGGloveTrackingSettings::DataRetrievalRefreshRate` for adoption other than glove connectivity use cases. -- The hand velocity sampler is now timer-based instead of being tick-based and the update interval is controlled via `SGPawn::HandVelocitySamplerFramerate`. - Glove data retrieval and related calculations have been moved from `USGVirtualHandComponent::TickComponent()` and `USGWristTrackerComponent::TickComponent()` into background timers, reducing the performance overhead of any SenseGlove API calls. - `USGVirtualHandComponent::GetMotionControllerData()` signature has changed. - `USGVirtualHandComponent::GetHandTrackingState()` signature has changed. @@ -65,7 +63,6 @@ This minor release focuses on delivering performance improvements, made possible - Cleaned up remnants of the long-removed Unreal Engine `5.2` from third-party module `*.Build.cs` files. - Cleaned up remnants of the long-removed Unreal Engine `5.2` from `SenseGlove.Build.cs`, `SenseGloveKismet.Build.cs`, `SenseGloveTracking.Build.cs`, files. - Cleaned up remnants of the long-removed Unreal Engine `5.2` from `SenseGloveTracking` module. -- `SGPawn::Tick()` is no longer handled in order to improve performance and reliability. The hand velocity sampler is now timer-based instead of being tick-based and the update interval is controlled via `SGPawn::HandVelocitySamplerFramerate`. - `USGVirtualHandComponent::GetMotionControllerState()` has been removed. - `USGWristTrackerComponent::GetMotionControllerState()` has been removed. - `USGVirtualHandComponentKismetLibrary::GetMotionControllerState()` has been removed. diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index c949f7df..319adc6b 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -40,7 +40,6 @@ #include "Components/SphereComponent.h" #include "Kismet/KismetMathLibrary.h" #include "Runtime/Launch/Resources/Version.h" -#include "TimerManager.h" #include "UObject/UObjectGlobals.h" #include "XRDeviceVisualizationComponent.h" @@ -48,9 +47,8 @@ #include "SenseGlove/Components/SGTouchComponent.h" #include "SenseGlove/Components/SGVirtualHandComponent.h" #include "SenseGlove/Components/SGWristTrackerComponent.h" -#include "SGBuildHacks/SGPlatform.h" -#include "SGLog/SGLog.h" #include "SGSettings/SGSettings.h" +#include "SGLog/SGLog.h" struct ASGPawn::FImpl { @@ -58,12 +56,6 @@ struct ASGPawn::FImpl * Static methods ************************/ - /************************ - * Member variables - ************************/ - - FTimerHandle HandVelocitySamplerTimer; - /************************ * Owner object ************************/ @@ -154,7 +146,6 @@ struct ASGPawn::FImpl void SetRightHandGrabbedActor(AActor* Actor) const; void RecordHandVelocity(FSGGrabState& GrabState, const float DeltaSeconds) const; - void StartHandVelocitySamplerTimer(); void Release(FSGGrabState& GrabState) const; @@ -500,7 +491,6 @@ ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer) RightPinkyFingertipTouchCollider->SetCollisionObjectType(ECC_Pawn); Pimpl->SetFingerColliderCollisionEnabled(RightPinkyFingertipTouchCollider, true); - HandVelocitySamplerFramerate = 60.0f; MaxNumberOfHandVelocitySamples = 10; LeftHandGrabState = FSGGrabState{ @@ -587,8 +577,6 @@ void ASGPawn::BeginPlay() Pimpl->BindFingerGrabOverlapEvents(); Pimpl->BindFingerTouchOverlapEvents(); - - Pimpl->StartHandVelocitySamplerTimer(); } void ASGPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) @@ -601,6 +589,14 @@ void ASGPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) Pimpl->UnbindFingerTouchOverlapEvents(); } +void ASGPawn::Tick(const float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + Pimpl->RecordHandVelocity(LeftHandGrabState, DeltaSeconds); + Pimpl->RecordHandVelocity(RightHandGrabState, DeltaSeconds); +} + void ASGPawn::PreInitializeComponents() { Super::PreInitializeComponents(); @@ -2215,44 +2211,6 @@ void ASGPawn::FImpl::RecordHandVelocity(FSGGrabState& GrabState, const float Del GrabState.PreviousHandLocation = GrabState.Hand->GetComponentLocation(); } -void ASGPawn::FImpl::StartHandVelocitySamplerTimer() -{ - const UWorld* World{Owner->GetWorld()}; - if (!ensureAlwaysMsgf(World, TEXT("Invalid world!"))) - { - SGLOG_ERROR("The SGPawn hand velocity sampler timer has failed to start!"); - return; - } - - SGLOG("Starting SGPawn's hand-velocity sampler timer..."); - - FTimerDelegate Handler; - Handler.BindLambda([= SG_CAPTURE_THIS]()-> void - { - const float DeltaSeconds = World->GetDeltaSeconds(); - RecordHandVelocity(Owner->LeftHandGrabState, DeltaSeconds); - RecordHandVelocity(Owner->RightHandGrabState, DeltaSeconds); - }); - - const float Interval = 1.0f / Owner->HandVelocitySamplerFramerate; - - FTimerManager& TimerManager = World->GetTimerManager(); - TimerManager.SetTimer( - HandVelocitySamplerTimer, Handler, Interval, - true, -1.0f); - - if (ensureAlwaysMsgf(TimerManager.IsTimerActive(HandVelocitySamplerTimer), - TEXT("HandVelocitySamplerTimer is not active"))) - { - SGLOG("The SGPawn hand velocity sampler timer has been started successfully!"); - SGLOG("The SGPawn hand velocity sampler interval is: ", Interval); - } - else - { - SGLOG_ERROR("The SGPawn hand velocity sampler timer has failed to start!"); - } -} - void ASGPawn::FImpl::Release(FSGGrabState& GrabState) const { if (!IsValid(GrabState.GrabbedActor)) diff --git a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h index 34b9b12b..0f40d592 100644 --- a/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h +++ b/Source/SenseGlove/Public/SenseGlove/GameFramework/SGPawn.h @@ -199,9 +199,6 @@ private: UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) USphereComponent* RightPinkyFingertipTouchCollider; - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) - float HandVelocitySamplerFramerate; - UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) int32 MaxNumberOfHandVelocitySamples; @@ -382,6 +379,7 @@ public: public: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + virtual void Tick(float DeltaSeconds) override; virtual void PreInitializeComponents() override; virtual void PostInitializeComponents() override;