clean up and simplify the touch callback lambda
This commit is contained in:
@@ -93,12 +93,19 @@ struct ASGPlayerController::FImpl
|
|||||||
* Methods
|
* Methods
|
||||||
************************/
|
************************/
|
||||||
|
|
||||||
USGBuzzCommand* GetBuzzCommand(const AActor* ActorThumbTouching, const AActor* ActorIndexTouching,
|
USGBuzzCommand* GetBuzzCommand(
|
||||||
|
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching,
|
||||||
const AActor* ActorMiddleTouching, const AActor* ActorRingTouching,
|
const AActor* ActorMiddleTouching, const AActor* ActorRingTouching,
|
||||||
const AActor* ActorPinkyTouching) const;
|
const AActor* ActorPinkyTouching) const;
|
||||||
USGForceFeedbackCommand* GetForceFeedbackCommand(const AActor* ActorThumbTouching, const AActor* ActorIndexTouching,
|
USGForceFeedbackCommand* GetForceFeedbackCommand(
|
||||||
|
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching,
|
||||||
const AActor* ActorMiddleTouching, const AActor* ActorRingTouching,
|
const AActor* ActorMiddleTouching, const AActor* ActorRingTouching,
|
||||||
const AActor* ActorPinkyTouching) const;
|
const AActor* ActorPinkyTouching) const;
|
||||||
|
|
||||||
|
void UpdateHapticsFeedback(
|
||||||
|
const USGVirtualHandComponent* Hand,
|
||||||
|
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching, const AActor* ActorMiddleTouching,
|
||||||
|
const AActor* ActorRingTouching, const AActor* ActorPinkyTouching);
|
||||||
};
|
};
|
||||||
|
|
||||||
int32 ASGPlayerController::FImpl::GetBuzzLevel(const AActor* Actor)
|
int32 ASGPlayerController::FImpl::GetBuzzLevel(const AActor* Actor)
|
||||||
@@ -236,57 +243,9 @@ void ASGPlayerController::BeginPlay()
|
|||||||
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching, const AActor* ActorMiddleTouching,
|
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching, const AActor* ActorMiddleTouching,
|
||||||
const AActor* ActorRingTouching, const AActor* ActorPinkyTouching) -> void
|
const AActor* ActorRingTouching, const AActor* ActorPinkyTouching) -> void
|
||||||
{
|
{
|
||||||
if (!IsValid(SGPawn))
|
Pimpl->UpdateHapticsFeedback(
|
||||||
{
|
Hand,
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsValid(Hand))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
USGHapticGlove* Glove = Hand->GetConnectedGlove();
|
|
||||||
if (!IsValid(Glove))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const USGBuzzCommand* BuzzCommand{Pimpl->GetBuzzCommand(
|
|
||||||
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching)};
|
|
||||||
if (IsValid(BuzzCommand))
|
|
||||||
{
|
|
||||||
Glove->SendHaptics(BuzzCommand);
|
|
||||||
|
|
||||||
const float Duration = FImpl::GetBuzzDuration(
|
|
||||||
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching);
|
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching);
|
||||||
|
|
||||||
GetWorldTimerManager().ClearTimer(Pimpl->TouchBuzzStopTimer);
|
|
||||||
|
|
||||||
FTimerDelegate TouchBuzzStopHandler;
|
|
||||||
TouchBuzzStopHandler.BindLambda([=]()-> void
|
|
||||||
{
|
|
||||||
Glove->SendHaptics(USGBuzzCommand::Off(this));
|
|
||||||
});
|
|
||||||
|
|
||||||
GetWorldTimerManager().SetTimer(
|
|
||||||
Pimpl->TouchBuzzStopTimer, TouchBuzzStopHandler, Duration, false, -1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Glove->SendHaptics(USGBuzzCommand::Off(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
const USGForceFeedbackCommand* ForceFeedbackCommand{Pimpl->GetForceFeedbackCommand(
|
|
||||||
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching)};
|
|
||||||
if (IsValid(ForceFeedbackCommand))
|
|
||||||
{
|
|
||||||
Glove->SendHaptics(ForceFeedbackCommand);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Glove->SendHaptics(USGForceFeedbackCommand::Off(this));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,6 +317,63 @@ USGForceFeedbackCommand* ASGPlayerController::FImpl::GetForceFeedbackCommand(
|
|||||||
return ForceFeedbackCommand;
|
return ForceFeedbackCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASGPlayerController::FImpl::UpdateHapticsFeedback(
|
||||||
|
const USGVirtualHandComponent* Hand,
|
||||||
|
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching, const AActor* ActorMiddleTouching,
|
||||||
|
const AActor* ActorRingTouching, const AActor* ActorPinkyTouching)
|
||||||
|
{
|
||||||
|
if (!IsValid(Hand))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
USGHapticGlove* Glove = Hand->GetConnectedGlove();
|
||||||
|
if (!IsValid(Glove))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const USGBuzzCommand* BuzzCommand{
|
||||||
|
GetBuzzCommand(
|
||||||
|
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching)
|
||||||
|
};
|
||||||
|
if (IsValid(BuzzCommand))
|
||||||
|
{
|
||||||
|
Glove->SendHaptics(BuzzCommand);
|
||||||
|
|
||||||
|
const float Duration = FImpl::GetBuzzDuration(
|
||||||
|
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching);
|
||||||
|
|
||||||
|
Owner->GetWorldTimerManager().ClearTimer(TouchBuzzStopTimer);
|
||||||
|
|
||||||
|
FTimerDelegate TouchBuzzStopHandler;
|
||||||
|
TouchBuzzStopHandler.BindLambda([=]()-> void
|
||||||
|
{
|
||||||
|
Glove->SendHaptics(USGBuzzCommand::Off(Owner));
|
||||||
|
});
|
||||||
|
|
||||||
|
Owner->GetWorldTimerManager().SetTimer(
|
||||||
|
TouchBuzzStopTimer, TouchBuzzStopHandler, Duration, false, -1.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Glove->SendHaptics(USGBuzzCommand::Off(Owner));
|
||||||
|
}
|
||||||
|
|
||||||
|
const USGForceFeedbackCommand* ForceFeedbackCommand{
|
||||||
|
GetForceFeedbackCommand(
|
||||||
|
ActorThumbTouching, ActorIndexTouching, ActorMiddleTouching, ActorRingTouching, ActorPinkyTouching)
|
||||||
|
};
|
||||||
|
if (IsValid(ForceFeedbackCommand))
|
||||||
|
{
|
||||||
|
Glove->SendHaptics(ForceFeedbackCommand);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Glove->SendHaptics(USGForceFeedbackCommand::Off(Owner));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ASGPlayerController::FImplDeleter::operator()(const FImpl* P) const
|
void ASGPlayerController::FImplDeleter::operator()(const FImpl* P) const
|
||||||
{
|
{
|
||||||
delete P;
|
delete P;
|
||||||
|
|||||||
Reference in New Issue
Block a user