5 #include <CoreMinimal.h>
8 #include <Components/ActorComponent.h>
11 #include "LovenseTypes.h"
13 #include "LovenseToyAnimationControlComponent.generated.h"
19 void LovenseGetAnimationData(TArray<class UAnimSequence*>& outAnimations, TArray<float>& outTimes);
20 void CalculatePlayRate(
float deltaTime, FRandomStream& random,
float& playRate);
21 void Tick(
float deltaTime);
23 TArray<class USkeletalMeshComponent> skeletalMeshComponents;
24 TArray<class UAnimSequence*> animations;
25 float currentAnimationTime;
27 FRandomStream randomStream;
28 float currentPlayRate;
30 float currentPlayRateTarget;
33 void Class::LovenseGetAnimationData(TArray<class UAnimSequence*>& outAnimations, TArray<float>& outTimes) {
34 outAnimations.Empty(this->skeletalMeshComponents.Num());
37 for (int32 i = 0; i < this->skeletalMeshComponents.Num(); ++i) {
39 outAnimations.Add(this->animations[i]);
45 FRandomStream random = this->randomStream;
46 float playRate = this->currentPlayRate;
49 float toyDelaySeconds = static_cast<float>(toyDelay) / 1000.0f;
51 float animationTime = this->currentAnimationTime + toyDelaySeconds;
52 float time = this->currentTime;
53 float playRateTarget = this->currentPlayRateTarget;
56 while (outTimes.Num() < 51) {
58 outTimes.Add(animationTime);
60 animationTime += 0.1f * playRate;
62 this->CalculatePlayRate(0.1f, random, time, playRateTarget, playRate);
66 void Class::CalculatePlayRate(
float deltaTime, FRandomStream& random,
float& time,
float& playRateTarget,
float& playRate) {
74 playRateTarget = random.FRand();
77 playRate = FMath::FInterpTo(playRate, playRateTarget, deltaTime, 1.0f);
80 void Class::Tick(
float deltaTime) {
82 this->CalculatePlayRate(deltaTime, this->randomStream, this->currentTime, this->currentPlayRateTarget, this->currentPlayRate);
97 DECLARE_DYNAMIC_DELEGATE_TwoParams(FLovenseGetAnimationData, TArray<class UAnimSequence*>&, outAnimations, TArray<float>&, outTimes);
161 UCLASS(ClassGroup =
"Lovense", Meta = (BlueprintSpawnableComponent))
174 UFUNCTION(BlueprintCallable, Category =
"Lovense")
175 virtual void Initialize(
176 const TArray<USkeletalMeshComponent*>& inSkeletalMeshComponents,
177 const TArray<FName>& inBoneNames,
178 const FLovenseGetAnimationData& inGetAnimationDataDelegate
185 UFUNCTION(BlueprintCallable, Category =
"Lovense")
186 virtual void StartBehaviour();
195 UFUNCTION(BlueprintCallable, Category =
"Lovense")
196 virtual void StartTransition();
203 UFUNCTION(BlueprintCallable, Category =
"Lovense")
204 virtual void SetEnabled(
bool value);
207 UFUNCTION(BlueprintPure, Category =
"Lovense")
208 FORCEINLINE
bool IsEnabled() {
return this->bIsEnabled; }
214 UFUNCTION(BlueprintCallable, Category =
"Lovense")
215 virtual
void OnGamePaused();
221 UFUNCTION(BlueprintCallable, Category = "Lovense")
222 virtual
void OnGameUnpaused();
228 virtual
void TickComponent(
float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
229 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
236 FORCEINLINE
float GetMaxRecordedVelocityDecaySpeed() {
return this->maxRecordedVelocityDecaySpeed; }
298 FORCEINLINE
const TArray<FName>&
GetBoneNames() {
return this->boneNames; }
330 virtual
void OnPatternGenerationTimerFinished();
337 virtual
void RealtimeEvaluationUpdate(
float deltaTime);
343 virtual
bool GeneratePattern(const TArray<class UAnimSequence*>& animations, const TArray<
float>& times,
FLovensePattern& outPattern);
351 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Realtime Evaluation")
352 double maxAverageVelocity;
358 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Realtime Evaluation")
359 float maxRecordedVelocityDecaySpeed;
365 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Realtime Evaluation")
366 float maxRecordedVelocityDecayMinimum;
372 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Realtime Evaluation")
373 float maxToySpeedInterpolationSpeed;
380 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Realtime Evaluation", Meta = (ClampMin = "1", ClampMax = "20", UIMin = "1", UIMax = "20"))
381 float maxToySpeedTargetDuringTransition;
389 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lovense|Pattern Generation")
390 FVector2D patternToySpeedInputRange;
396 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense")
397 TArray<TObjectPtr<USkeletalMeshComponent>> skeletalMeshComponents;
404 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense")
405 TArray<FName> boneNames;
412 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense|Realtime Evaluation")
413 double maxRecordedVelocity;
420 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense|Realtime Evaluation")
421 float currentMaxToySpeed;
428 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense|Realtime Evaluation")
429 float maxToySpeedTarget;
436 UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "Lovense|Realtime Evaluation")
437 bool bRotateClockwise;
448 FTimerHandle patternGenerationTimerHandle;
455 FLovenseGetAnimationData getAnimationDataDelegate;