make the senseglove settings a singleton with engine subsystem lifetime and fix the blueprint accessors

This commit is contained in:
Mamadou Babaei
2023-03-28 10:39:55 +02:00
parent 5a2584161b
commit ffc89daa3a
5 changed files with 64 additions and 15 deletions
@@ -35,6 +35,10 @@
#include "SGSettings/SGSettings.h"
#include "Engine/Engine.h"
#include "SGLog/SGLog.h"
struct USGSettings::FImpl
{
/************************
@@ -66,11 +70,44 @@ struct USGSettings::FImpl
************************/
};
USGSettings::USGSettings(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
USGSettings* USGSettings::GetInstance()
{
USGSettings* Instance{GEngine->GetEngineSubsystem<USGSettings>()};
return Instance;
}
void USGSettings::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}
bool USGSettings::ShouldCreateSubsystem(UObject* Outer) const
{
return true;
}
void USGSettings::Initialize(FSubsystemCollectionBase& Collection)
{
SGLOG("Initializing the SenseGlove settings singleton with the engine lifetime...");
Super::Initialize(Collection);
Pimpl = TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter);
HardwareOffset = ESGPositionalTrackingHardware::None;
SGLOG("The SenseGlove settings singleton has been successfully initialized with the engine lifetime!");
}
void USGSettings::Deinitialize()
{
SGLOG("De-initializing the SenseGlove settings singleton due to the engine lifetime expiration...");
Super::Deinitialize();
Pimpl.Release();
SGLOG("The SenseGlove settings singleton has been successfully de-initialized!");
}
USGSettings::FImpl::FImpl(USGSettings* InOwner)
@@ -78,9 +115,4 @@ USGSettings::FImpl::FImpl(USGSettings* InOwner)
{
}
USGSettings::FImpl::~FImpl() = default;
void USGSettings::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}
USGSettings::FImpl::~FImpl() = default;
@@ -35,8 +35,8 @@
#pragma once
#include "Subsystems/EngineSubsystem.h"
#include "Templates/UniquePtr.h"
#include "UObject/Object.h"
#include "UObject/ObjectMacros.h"
#include "SGTypes/SGCoreTypes.h"
@@ -44,9 +44,12 @@
#include "SGSettings.generated.h"
UCLASS(config = SenseGloveSettings)
class SENSEGLOVESETTINGS_API USGSettings : public UObject
class SENSEGLOVESETTINGS_API USGSettings : public UEngineSubsystem
{
GENERATED_UCLASS_BODY()
GENERATED_BODY()
public:
static USGSettings* GetInstance();
private:
struct FImpl;
@@ -73,4 +76,10 @@ public:
{
HardwareOffset = InHardWareOffset;
}
public:
virtual bool ShouldCreateSubsystem(UObject* Outer) const override;
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
};
@@ -53,6 +53,7 @@ public class SenseGloveSettings : ModuleRules
new string[]
{
"CoreUObject",
"Engine",
"SenseGloveLog",
"SenseGloveTypes",
}
@@ -37,6 +37,11 @@
#include "SGSettings/SGSettings.h"
USGSettings* USGSettingsKismetLibrary::GetInstance()
{
return USGSettings::GetInstance();
}
ESGPositionalTrackingHardware USGSettingsKismetLibrary::GetHardwareOffset(const USGSettings* Settings)
{
return Settings->GetHardwareOffset();
@@ -48,10 +48,12 @@ class SENSEGLOVESETTINGSKISMET_API USGSettingsKismetLibrary final : public USGBl
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Settings")
static USGSettings* GetInstance();
UFUNCTION(BlueprintPure, Category="SenseGlove | Settings")
FORCEINLINE ESGPositionalTrackingHardware GetHardwareOffset(const USGSettings* Settings);
static ESGPositionalTrackingHardware GetHardwareOffset(const USGSettings* Settings);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Settings")
FORCEINLINE void SetHardwareOffset(UPARAM(ref) USGSettings* Settings,
ESGPositionalTrackingHardware InHardWareOffset);
static void SetHardwareOffset(UPARAM(ref) USGSettings* Settings, ESGPositionalTrackingHardware InHardWareOffset);
};