Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HeartRateActorDummy.h
- #pragma once
- #include "CoreMinimal.h"
- #include "GameFramework/Actor.h"
- #include "HeartRateRetriever.h"
- #include "HeartRateActorDummy.generated.h"
- UCLASS()
- class ANGEL_GREYBOX_API AHeartRateActorDummy : public AActor
- {
- GENERATED_BODY()
- public:
- // Sets default values for this actor's properties
- AHeartRateActorDummy();
- virtual void BeginPlay() override;
- virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
- virtual void BeginDestroy();
- virtual void Tick(float DeltaTime) override;
- void TimerWrapper();
- float ConvertHeartRate();
- HeartRateRetriever* HRR;
- FTimerHandle MemberTimerHandle;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- int heartRate;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- int baseHeartRate;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- int upperHeartRate;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- int lowerHeartRate;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- float GameplayHeartRate;
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Game")
- int prevHeartRate;
- };
- // HeartRateActorDummy.cpp
- #include "HeartRateActorDummy.h"
- #include "UObject/ConstructorHelpers.h"
- #include <EngineGlobals.h>
- #include <Runtime/Engine/Classes/Engine/Engine.h>
- #include "TimerManager.h"
- AHeartRateActorDummy::AHeartRateActorDummy()
- : Super()
- {
- PrimaryActorTick.bStartWithTickEnabled = true;
- PrimaryActorTick.bCanEverTick = true;
- baseHeartRate = 60;
- upperHeartRate = 120;
- lowerHeartRate = 60;
- }
- void AHeartRateActorDummy::BeginPlay()
- {
- HRR = nullptr;
- HRR = new HeartRateRetriever();
- GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &AHeartRateActorDummy::TimerWrapper, 1.0f, true, 2.0f);
- }
- void AHeartRateActorDummy::EndPlay(const EEndPlayReason::Type EndPlayReason)
- {
- if (HRR)
- {
- if (HRR)
- {
- HRR->EnsureCompletion();
- delete HRR;
- HRR = nullptr;
- }
- }
- Super::EndPlay(EndPlayReason);
- }
- void AHeartRateActorDummy::BeginDestroy()
- {
- if (HRR)
- {
- HRR->EnsureCompletion();
- delete HRR;
- HRR = nullptr;
- }
- Super::BeginDestroy();
- }
- void AHeartRateActorDummy::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- void AHeartRateActorDummy::TimerWrapper()
- {
- if (HRR)
- {
- heartRate = HRR->GetHeartRate();
- // Update the heart rate bounds values if necessary
- if (heartRate > upperHeartRate)
- {
- upperHeartRate = heartRate;
- }
- else if (heartRate < lowerHeartRate)
- {
- lowerHeartRate = heartRate;
- }
- GameplayHeartRate = ConvertHeartRate();
- prevHeartRate = HRR->GetPrevHeartRate();
- }
- }
- // Function for converting heart rate into useful gameplay variable
- float AHeartRateActorDummy::ConvertHeartRate()
- {
- float tempHR = 0;
- tempHR = heartRate - baseHeartRate;
- // Make sure the heart rate is a positive value
- if (tempHR < 0)
- {
- tempHR = 0;
- }
- // Convert the heart rate into something useful for gameplay
- // Expect a value between 1 and 4
- tempHR = tempHR / 20;
- tempHR = tempHR + 1;
- return tempHR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement