revert offloading senseglove glove data retrieval api calls to timers and restore calls from tickcomponent functions
This commit is contained in:
@@ -42,9 +42,7 @@
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/SkeletalMesh.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "IXRTrackingSystem.h"
|
||||
#include "Templates/UnrealTypeTraits.h"
|
||||
#include "TimerManager.h"
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
|
||||
#include "SenseGlove/Animation/SGVirtualHandAnimInstance.h"
|
||||
@@ -92,13 +90,6 @@ struct USGVirtualHandComponent::FImpl
|
||||
return GetPluginVirtualHandSettings().MeshSettings.DefaultRightHandMeshPathOnly;
|
||||
}
|
||||
|
||||
FORCEINLINE static float GetXRDataRetrievalInterval()
|
||||
{
|
||||
const USGSettings* Settings{USGSettings::GetInstance()};
|
||||
ensureAlwaysMsgf(Settings, TEXT("The settings subsystem has not been initialized!"));
|
||||
return 1.0f / Settings->GetTrackingSettings().GloveTrackingSettings.DataRetrievalRefreshRate;
|
||||
}
|
||||
|
||||
/************************
|
||||
* Member variables
|
||||
************************/
|
||||
@@ -109,13 +100,14 @@ struct USGVirtualHandComponent::FImpl
|
||||
ECollisionEnabled::Type CachedCollisionEnabled;
|
||||
FCollisionResponseContainer CachedCollisionResponse;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
FXRMotionControllerData MotionControllerData;
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FXRMotionControllerState MotionControllerState;
|
||||
FXRHandTrackingState HandTrackingState;
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
FTimerHandle XRDataRetrievalTimer;
|
||||
|
||||
/************************
|
||||
* Owner object
|
||||
************************/
|
||||
@@ -158,6 +150,8 @@ struct USGVirtualHandComponent::FImpl
|
||||
void DisableCollisionResponse();
|
||||
void RestoreCollisionResponse() const;
|
||||
|
||||
void UpdateXRData();
|
||||
|
||||
void SetVisibility(const bool bInVisible);
|
||||
void UpdateVisibility();
|
||||
|
||||
@@ -172,8 +166,6 @@ struct USGVirtualHandComponent::FImpl
|
||||
void DrawDebugVirtualHand() const;
|
||||
|
||||
void TriggerHandVisibilityChangedEvent(bool bNewVisibility) const;
|
||||
|
||||
void StartXRDataRetrievalTimer();
|
||||
};
|
||||
|
||||
FName USGVirtualHandComponent::FImpl::ParseVirtualHandSettingsOverridesPropertyName(const FName& PropertyName)
|
||||
@@ -385,7 +377,7 @@ void USGVirtualHandComponent::InitializeComponent()
|
||||
Pimpl->SetDefaultMesh();
|
||||
}
|
||||
|
||||
Pimpl->StartXRDataRetrievalTimer();
|
||||
Pimpl->UpdateXRData();
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::UninitializeComponent()
|
||||
@@ -404,6 +396,8 @@ void USGVirtualHandComponent::UninitializeComponent()
|
||||
void USGVirtualHandComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
Pimpl->UpdateXRData();
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
@@ -432,6 +426,8 @@ void USGVirtualHandComponent::TickComponent(
|
||||
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
Pimpl->UpdateXRData();
|
||||
|
||||
if (Pimpl->ShouldDrawDebugVirtualHand())
|
||||
{
|
||||
Pimpl->DrawDebugVirtualHand();
|
||||
@@ -453,6 +449,8 @@ void USGVirtualHandComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, const bool
|
||||
void USGVirtualHandComponent::EditorTick(
|
||||
const float DeltaTime, const ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Pimpl->UpdateXRData();
|
||||
|
||||
if (Pimpl->ShouldDrawDebugVirtualHand())
|
||||
{
|
||||
Pimpl->DrawDebugVirtualHand();
|
||||
@@ -747,6 +745,42 @@ void USGVirtualHandComponent::FImpl::RestoreCollisionResponse() const
|
||||
Owner->SetCollisionResponseToChannels(CachedCollisionResponse);
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImpl::UpdateXRData()
|
||||
{
|
||||
const EControllerHand Hand = Owner->IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
{
|
||||
FXRMotionControllerData Data;
|
||||
Data.bValid = false;
|
||||
|
||||
|
||||
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
const bool bGotMotionControllerData =
|
||||
FSGXRTracker::GetMotionControllerData(Owner, Hand, Data);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
(void)
|
||||
bGotMotionControllerData;
|
||||
MotionControllerData = MoveTemp(Data);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
{
|
||||
FXRHandTrackingState State;
|
||||
State.bValid = false;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
Owner, EXRSpaceType::UnrealWorldSpace, Hand, State);
|
||||
|
||||
(void) bGotHandTrackingState;
|
||||
HandTrackingState = MoveTemp(State);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImpl::SetVisibility(const bool bInVisible)
|
||||
{
|
||||
Owner->SetHiddenInGame(!bInVisible, false);
|
||||
@@ -856,74 +890,6 @@ void USGVirtualHandComponent::FImpl::TriggerHandVisibilityChangedEvent(const boo
|
||||
Owner->OnHandVisibilityChanged(bNewVisibility);
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImpl::StartXRDataRetrievalTimer()
|
||||
{
|
||||
const UWorld* World{Owner->GetWorld()};
|
||||
if (!ensureAlwaysMsgf(World, TEXT("Invalid world!")))
|
||||
{
|
||||
SGLOG_ERROR("The SGVirtualHandComponent's XRDataRetrievalTimer has failed to start!");
|
||||
return;
|
||||
}
|
||||
|
||||
SGLOG("Starting SGVirtualHandComponent's XRDataRetrievalTimer...");
|
||||
|
||||
FTimerDelegate Handler;
|
||||
Handler.BindLambda([= SG_CAPTURE_THIS]()-> void
|
||||
{
|
||||
const EControllerHand Hand = Owner->IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
{
|
||||
FXRMotionControllerData Data;
|
||||
Data.bValid = false;
|
||||
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
const bool bGotMotionControllerData =
|
||||
FSGXRTracker::GetMotionControllerData(Owner, Hand, Data);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
(void) bGotMotionControllerData;
|
||||
MotionControllerData = MoveTemp(Data);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
{
|
||||
FXRHandTrackingState State;
|
||||
State.bValid = false;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
Owner, EXRSpaceType::UnrealWorldSpace, Hand, State);
|
||||
|
||||
(void) bGotHandTrackingState;
|
||||
HandTrackingState = MoveTemp(State);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
// Perform all other updates for the next tick!
|
||||
UpdateVisibility();
|
||||
});
|
||||
|
||||
const float Interval = GetXRDataRetrievalInterval();
|
||||
|
||||
FTimerManager& TimerManager = World->GetTimerManager();
|
||||
TimerManager.SetTimer(
|
||||
XRDataRetrievalTimer, Handler, Interval,
|
||||
true, -1.0f);
|
||||
|
||||
if (ensureAlwaysMsgf(TimerManager.IsTimerActive(XRDataRetrievalTimer),
|
||||
TEXT("XRDataRetrievalTimer is not active")))
|
||||
{
|
||||
SGLOG("The SGVirtualHandComponent's XRDataRetrievalTimer has been started successfully!");
|
||||
SGLOG("The SGVirtualHandComponent's XRDataRetrievalTimer interval is: ", Interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
SGLOG_ERROR("The SGVirtualHandComponent's XRDataRetrievalTimer has failed to start!");
|
||||
}
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const
|
||||
{
|
||||
delete P;
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
#include "SenseGlove/Components/SGWristTrackerComponent.h"
|
||||
|
||||
#include "IXRTrackingSystem.h"
|
||||
#include "MotionDelayBuffer.h"
|
||||
#include "TimerManager.h"
|
||||
|
||||
#include "SGBuildHacks/SGPlatform.h"
|
||||
#include "SGDebug/SGDebugGizmo.h"
|
||||
@@ -53,26 +51,20 @@ struct USGWristTrackerComponent::FImpl
|
||||
|
||||
static FName ParseWristTrackingSettingsOverridesPropertyName(const FName& PropertyName);
|
||||
|
||||
FORCEINLINE static float GetXRDataRetrievalInterval()
|
||||
{
|
||||
const USGSettings* Settings{USGSettings::GetInstance()};
|
||||
ensureAlwaysMsgf(Settings, TEXT("The settings subsystem has not been initialized!"));
|
||||
return 1.0f / Settings->GetTrackingSettings().GloveTrackingSettings.DataRetrievalRefreshRate;
|
||||
}
|
||||
|
||||
/************************
|
||||
* Member variables
|
||||
************************/
|
||||
|
||||
bool bOverridePluginSettingsPropertyAlreadyModified;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
FXRMotionControllerData MotionControllerData;
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FXRMotionControllerState MotionControllerState;
|
||||
FXRHandTrackingState HandTrackingState;
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
FTimerHandle XRDataRetrievalTimer;
|
||||
|
||||
/************************
|
||||
* Owner object
|
||||
************************/
|
||||
@@ -102,10 +94,10 @@ struct USGWristTrackerComponent::FImpl
|
||||
void OverridePluginSettingsPropertyChanged();
|
||||
|
||||
void UpdateMotionSource() const;
|
||||
void UpdateXRData();
|
||||
void UpdateWristTrackingData() const;
|
||||
void DrawDebugWristTracker() const;
|
||||
|
||||
void StartXRDataRetrievalTimer();
|
||||
void DrawDebugWristTracker() const;
|
||||
};
|
||||
|
||||
USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& ObjectInitializer)
|
||||
@@ -220,9 +212,9 @@ void USGWristTrackerComponent::InitializeComponent()
|
||||
{
|
||||
Super::InitializeComponent();
|
||||
|
||||
Pimpl->StartXRDataRetrievalTimer();
|
||||
|
||||
Pimpl->UpdateMotionSource();
|
||||
Pimpl->UpdateXRData();
|
||||
Pimpl->UpdateWristTrackingData();
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::BeginPlay()
|
||||
@@ -230,6 +222,8 @@ void USGWristTrackerComponent::BeginPlay()
|
||||
Super::BeginPlay();
|
||||
|
||||
Pimpl->UpdateMotionSource();
|
||||
Pimpl->UpdateXRData();
|
||||
Pimpl->UpdateWristTrackingData();
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::TickComponent(
|
||||
@@ -245,6 +239,9 @@ void USGWristTrackerComponent::TickComponent(
|
||||
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
Pimpl->UpdateXRData();
|
||||
Pimpl->UpdateWristTrackingData();
|
||||
|
||||
if (GetWristTrackingSettings().DebuggingSettings.bDrawDebugWristTracker)
|
||||
{
|
||||
Pimpl->DrawDebugWristTracker();
|
||||
@@ -254,8 +251,17 @@ void USGWristTrackerComponent::TickComponent(
|
||||
void USGWristTrackerComponent::EditorTick(
|
||||
const float DeltaTime, const ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Pimpl->UpdateXRData();
|
||||
Pimpl->UpdateWristTrackingData();
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
const FXRMotionControllerData& USGWristTrackerComponent::GetMotionControllerData() const
|
||||
{
|
||||
return Pimpl->MotionControllerData;
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
const FXRHandTrackingState& USGWristTrackerComponent::GetHandTrackingState() const
|
||||
{
|
||||
@@ -321,6 +327,41 @@ void USGWristTrackerComponent::FImpl::UpdateMotionSource() const
|
||||
Owner->SetTrackingMotionSource(TrackingMotionSource);
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::FImpl::UpdateXRData()
|
||||
{
|
||||
const EControllerHand Hand = Owner->IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7
|
||||
{
|
||||
FXRMotionControllerData Data;
|
||||
Data.bValid = false;
|
||||
|
||||
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
const bool bGotMotionControllerData =
|
||||
FSGXRTracker::GetMotionControllerData(Owner, Hand, Data);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
(void)
|
||||
bGotMotionControllerData;
|
||||
MotionControllerData = MoveTemp(Data);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION < 7 */
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
{
|
||||
FXRHandTrackingState State;
|
||||
State.bValid = false;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
Owner, EXRSpaceType::UnrealWorldSpace, Hand, State);
|
||||
|
||||
(void) bGotHandTrackingState;
|
||||
HandTrackingState = MoveTemp(State);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::FImpl::UpdateWristTrackingData() const
|
||||
{
|
||||
FVector NewWristLocation{Owner->GetComponentLocation()};
|
||||
@@ -363,58 +404,6 @@ void USGWristTrackerComponent::FImpl::DrawDebugWristTracker() const
|
||||
FSGDebugGizmo::Draw(World, Owner->WristLocation, Owner->WristRotation, DebuggingSettings.DebugWristTrackerSettings);
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::FImpl::StartXRDataRetrievalTimer()
|
||||
{
|
||||
const UWorld* World{Owner->GetWorld()};
|
||||
if (!ensureAlwaysMsgf(World, TEXT("Invalid world!")))
|
||||
{
|
||||
SGLOG_ERROR("The SGWristTrackerComponent's XRDataRetrievalTimer has failed to start!");
|
||||
return;
|
||||
}
|
||||
|
||||
SGLOG("Starting SGWristTrackerComponent's XRDataRetrievalTimer...");
|
||||
|
||||
FTimerDelegate Handler;
|
||||
Handler.BindLambda([= SG_CAPTURE_THIS]()-> void
|
||||
{
|
||||
const EControllerHand Hand = Owner->IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
{
|
||||
FXRHandTrackingState State;
|
||||
State.bValid = false;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
Owner, EXRSpaceType::UnrealWorldSpace, Hand, State);
|
||||
|
||||
(void) bGotHandTrackingState;
|
||||
HandTrackingState = MoveTemp(State);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
// Perform all other updates for the next tick!
|
||||
UpdateWristTrackingData();
|
||||
});
|
||||
|
||||
const float Interval = GetXRDataRetrievalInterval();
|
||||
|
||||
FTimerManager& TimerManager = World->GetTimerManager();
|
||||
TimerManager.SetTimer(
|
||||
XRDataRetrievalTimer, Handler, Interval,
|
||||
true, -1.0f);
|
||||
|
||||
if (ensureAlwaysMsgf(TimerManager.IsTimerActive(XRDataRetrievalTimer),
|
||||
TEXT("XRDataRetrievalTimer is not active")))
|
||||
{
|
||||
SGLOG("The SGWristTrackerComponent's XRDataRetrievalTimer has been started successfully!");
|
||||
SGLOG("The SGWristTrackerComponent's XRDataRetrievalTimer interval is: ", Interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
SGLOG_ERROR("The SGWristTrackerComponent's XRDataRetrievalTimer has failed to start!");
|
||||
}
|
||||
}
|
||||
|
||||
void USGWristTrackerComponent::FImplDeleter::operator()(const FImpl* P) const
|
||||
{
|
||||
delete P;
|
||||
|
||||
Reference in New Issue
Block a user