SkyPortal-plugin/Source/SkyPortal/Public/SkyPortalRunner.h

85 lines
2.2 KiB
C
Raw Normal View History

2024-09-24 22:17:52 +00:00
#pragma once
2024-09-25 15:33:25 +00:00
#include "Core.h"
2024-09-24 22:17:52 +00:00
#include "HAL/Runnable.h"
#include "SkyPortalFigure.h"
2024-09-25 15:33:25 +00:00
#include "SkyPortalRunner.generated.h"
2024-09-24 22:17:52 +00:00
USTRUCT(BlueprintType)
struct FPortalStatusData
{
2024-09-25 15:33:25 +00:00
GENERATED_BODY()
2024-09-24 22:17:52 +00:00
// Array of statuses
UPROPERTY(BlueprintReadOnly, EditFixedSize, Category = "SkyPortal|Figure", meta = (EditFixedOrder))
TArray<EFigureStatus> StatusArray;
// timestamp.
// only one byte long. This means that after the value 0xFF, it overflows back to 0x00.
// Since these are so far apart, it can be assumed that 0x00 is newer than anything in the range 0xF0 - 0xFF.
UPROPERTY(BlueprintReadOnly, Category = "SkyPortal|Figure")
uint8 Counter;
// Should always be true
UPROPERTY(BlueprintReadOnly, Category = "SkyPortal|Figure")
bool bIsReady;
explicit FPortalStatusData(uint8 ArraySize = 16, EFigureStatus DefaultStatus = EFigureStatus::NOT_PRESENT) :
Counter(0), // Utilisation correcte de l'initialisation directe
bIsReady(true) // Utilisation correcte de l'initialisation directe
{
// Initialisation du tableau StatusArray avec 16 <20>l<EFBFBD>ments par d<>faut
StatusArray.Init(DefaultStatus, ArraySize);
}
// Overload the == operator
bool operator==(const FPortalStatusData& Other) const
{
if (bIsReady == Other.bIsReady && Counter == Other.Counter) {
if (StatusArray == Other.StatusArray) {
return true;
}
}
return false;
}
// Overload the != operator
bool operator!=(const FPortalStatusData& Other) const
{
return !(*this == Other);
}
};
class FPortalStatusChecker : public FRunnable {
public:
2024-09-25 15:33:25 +00:00
/* Constructor : pass the subsystem and desired check interval(in seconds)
*
* @param InSubsystem Should always be the SkyPortalSubsystem
*/
FPortalStatusChecker(UEngineSubsystem* InSubsystem, float InCheckInterval);
2024-09-24 22:17:52 +00:00
// FRunnable interface
virtual bool Init() override;
virtual uint32 Run() override;
virtual void Stop() override;
virtual void Exit() override;
2024-09-25 11:47:11 +00:00
2024-09-24 22:17:52 +00:00
private:
// Pointer to the subsystem that contains PortalStatus()
2024-09-25 15:33:25 +00:00
UEngineSubsystem* SkyPortalSubsystemRef;
2024-09-24 22:17:52 +00:00
// Time interval (in seconds) for status checking
float CheckInterval;
// Thread control variables
FThreadSafeBool bShouldRun;
// Helper function to check portal status
void CheckPortalStatus();
};