get rid of SGPawn::Tick, introduce SGPawn::HandVelocitySamplerFramerate, and make hand velocity sampler timer-based instead of tick-based
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "Runtime/Launch/Resources/Version.h"
|
||||
#include "TimerManager.h"
|
||||
#include "UObject/UObjectGlobals.h"
|
||||
#include "XRDeviceVisualizationComponent.h"
|
||||
|
||||
@@ -47,8 +48,9 @@
|
||||
#include "SenseGlove/Components/SGTouchComponent.h"
|
||||
#include "SenseGlove/Components/SGVirtualHandComponent.h"
|
||||
#include "SenseGlove/Components/SGWristTrackerComponent.h"
|
||||
#include "SGSettings/SGSettings.h"
|
||||
#include "SGBuildHacks/SGPlatform.h"
|
||||
#include "SGLog/SGLog.h"
|
||||
#include "SGSettings/SGSettings.h"
|
||||
|
||||
struct ASGPawn::FImpl
|
||||
{
|
||||
@@ -56,6 +58,12 @@ struct ASGPawn::FImpl
|
||||
* Static methods
|
||||
************************/
|
||||
|
||||
/************************
|
||||
* Member variables
|
||||
************************/
|
||||
|
||||
FTimerHandle HandVelocitySamplerTimer;
|
||||
|
||||
/************************
|
||||
* Owner object
|
||||
************************/
|
||||
@@ -146,6 +154,7 @@ struct ASGPawn::FImpl
|
||||
void SetRightHandGrabbedActor(AActor* Actor) const;
|
||||
|
||||
void RecordHandVelocity(FSGGrabState& GrabState, const float DeltaSeconds) const;
|
||||
void StartHandVelocitySamplerTimer();
|
||||
|
||||
void Release(FSGGrabState& GrabState) const;
|
||||
|
||||
@@ -491,6 +500,7 @@ ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer)
|
||||
RightPinkyFingertipTouchCollider->SetCollisionObjectType(ECC_Pawn);
|
||||
Pimpl->SetFingerColliderCollisionEnabled(RightPinkyFingertipTouchCollider, true);
|
||||
|
||||
HandVelocitySamplerFramerate = 60.0f;
|
||||
MaxNumberOfHandVelocitySamples = 10;
|
||||
|
||||
LeftHandGrabState = FSGGrabState{
|
||||
@@ -577,6 +587,8 @@ void ASGPawn::BeginPlay()
|
||||
|
||||
Pimpl->BindFingerGrabOverlapEvents();
|
||||
Pimpl->BindFingerTouchOverlapEvents();
|
||||
|
||||
Pimpl->StartHandVelocitySamplerTimer();
|
||||
}
|
||||
|
||||
void ASGPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
@@ -589,14 +601,6 @@ 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();
|
||||
@@ -2211,6 +2215,44 @@ 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,6 +199,9 @@ 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;
|
||||
|
||||
@@ -379,7 +382,6 @@ 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user