Revert "get rid of SGPawn::Tick, introduce SGPawn::HandVelocitySamplerFramerate, and make hand velocity sampler timer-based instead of tick-based"

This reverts commit 8dea65ed40.
This commit is contained in:
Mamadou Babaei
2025-11-18 03:19:31 +01:00
parent e97fa22a7e
commit 31df72d3d0
3 changed files with 10 additions and 57 deletions
@@ -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))
@@ -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;