Native Linux compile working and works on steam deck

This commit is contained in:
Jordon Brooks 2024-06-06 21:11:12 +01:00
parent e5cca6b23f
commit 6ba25c1b0d
Signed by: jordon
GPG key ID: DBD9758CD53E786A
8 changed files with 137 additions and 52 deletions

View file

@ -5,6 +5,21 @@
#include "HarmonyLinkLib.h" #include "HarmonyLinkLib.h"
bool UHarmonyLinkLibrary::bIsWineCached = false;
bool UHarmonyLinkLibrary::bIsLinuxCached = false;
bool UHarmonyLinkLibrary::bIsSteamDeckCached = false;
bool UHarmonyLinkLibrary::bCPUInfoCached = false;
bool UHarmonyLinkLibrary::bDeviceInfoCached = false;
bool UHarmonyLinkLibrary::bOSInfoCached = false;
bool UHarmonyLinkLibrary::bIsWine = false;
bool UHarmonyLinkLibrary::bIsLinux = false;
bool UHarmonyLinkLibrary::bIsSteamDeck = false;
FCPUInfo UHarmonyLinkLibrary::CachedCPUInfo = FCPUInfo();
FDevice UHarmonyLinkLibrary::CachedDeviceInfo = FDevice();
FOSVerInfo UHarmonyLinkLibrary::CachedOSInfo = FOSVerInfo();
UHarmonyLinkLibrary::UHarmonyLinkLibrary() UHarmonyLinkLibrary::UHarmonyLinkLibrary()
{ {
if (!HarmonyLinkLib::HL_Init()) if (!HarmonyLinkLib::HL_Init())
@ -16,34 +31,65 @@ UHarmonyLinkLibrary::UHarmonyLinkLibrary()
UE_LOG(LogHarmonyLink, Log, TEXT("HarmonyLinkLib Initialised!")); UE_LOG(LogHarmonyLink, Log, TEXT("HarmonyLinkLib Initialised!"));
} }
bool UHarmonyLinkLibrary::IsWine() bool UHarmonyLinkLibrary::IsWine(bool bForce)
{ {
return HarmonyLinkLib::get_is_wine(); if (!bIsWineCached || bForce)
{
bIsWine = HarmonyLinkLib::get_is_wine();
bIsWineCached = true;
}
return bIsWine;
} }
bool UHarmonyLinkLibrary::IsLinux() bool UHarmonyLinkLibrary::IsLinux(bool bForce)
{ {
return HarmonyLinkLib::get_is_linux(); if (!bIsLinuxCached || bForce)
{
bIsLinux = HarmonyLinkLib::get_is_linux();
bIsLinuxCached = true;
}
return bIsLinux;
} }
bool UHarmonyLinkLibrary::IsSteamDeck() bool UHarmonyLinkLibrary::IsSteamDeck(bool bForce)
{ {
return GetDeviceInfo().Device == EDevice::STEAM_DECK; if (!bIsSteamDeckCached || bForce)
{
bIsSteamDeck = GetDeviceInfo().Device == EDevice::STEAM_DECK;
bIsSteamDeckCached = true;
}
return bIsSteamDeck;
} }
FCPUInfo UHarmonyLinkLibrary::GetCPUInfo() FCPUInfo UHarmonyLinkLibrary::GetCPUInfo(bool bForce)
{ {
return FCPUInfo(HarmonyLinkLib::get_cpu_info()); if (!bCPUInfoCached || bForce)
{
CachedCPUInfo = FCPUInfo(HarmonyLinkLib::get_cpu_info());
bCPUInfoCached = true;
}
return CachedCPUInfo;
} }
FDevice UHarmonyLinkLibrary::GetDeviceInfo() FDevice UHarmonyLinkLibrary::GetDeviceInfo(bool bForce)
{ {
return FDevice(HarmonyLinkLib::get_device_info()); if (!bDeviceInfoCached || bForce)
{
CachedDeviceInfo = FDevice(HarmonyLinkLib::get_device_info());
bDeviceInfoCached = true;
}
return CachedDeviceInfo;
} }
FOSVerInfo UHarmonyLinkLibrary::GetOSInfo() FOSVerInfo UHarmonyLinkLibrary::GetOSInfo(bool bForce)
{ {
return FOSVerInfo(HarmonyLinkLib::get_os_version()); if (!bOSInfoCached || bForce)
{
CachedOSInfo = FOSVerInfo(HarmonyLinkLib::get_os_version());
bOSInfoCached = true;
}
return CachedOSInfo;
} }
FBattery UHarmonyLinkLibrary::GetBatteryStatus() FBattery UHarmonyLinkLibrary::GetBatteryStatus()

View file

@ -7,6 +7,7 @@
#include "HarmonyLinkLibrary.h" #include "HarmonyLinkLibrary.h"
#include "GameFramework/GameUserSettings.h" #include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "HarmonyLinkLib.h"
UHarmonyLinkGraphics* UHarmonyLinkGraphics::_INSTANCE = nullptr; UHarmonyLinkGraphics* UHarmonyLinkGraphics::_INSTANCE = nullptr;
int32 UHarmonyLinkGraphics::_TickRate = 1; int32 UHarmonyLinkGraphics::_TickRate = 1;
@ -72,8 +73,8 @@ UHarmonyLinkGraphics::UHarmonyLinkGraphics()
AddToRoot(); AddToRoot();
FWorldDelegates::OnPostWorldInitialization.AddUObject(this, &UHarmonyLinkGraphics::OnPostWorldInitialization); FWorldDelegates::OnPostWorldInitialization.AddStatic(&UHarmonyLinkGraphics::OnPostWorldInitialization);
FWorldDelegates::OnPreWorldFinishDestroy.AddUObject(this, &UHarmonyLinkGraphics::OnWorldEnd); FWorldDelegates::OnPreWorldFinishDestroy.AddStatic(&UHarmonyLinkGraphics::OnWorldEnd);
Init(); Init();
} }
@ -82,6 +83,7 @@ UHarmonyLinkGraphics::~UHarmonyLinkGraphics()
{ {
UE_LOG(LogHarmonyLink, Verbose, TEXT("~UHarmonyLinkGraphics called.")); UE_LOG(LogHarmonyLink, Verbose, TEXT("~UHarmonyLinkGraphics called."));
FWorldDelegates::OnPostWorldInitialization.RemoveAll(this); FWorldDelegates::OnPostWorldInitialization.RemoveAll(this);
FWorldDelegates::OnPreWorldFinishDestroy.RemoveAll(this);
} }
void UHarmonyLinkGraphics::LoadConfig(const bool bForceReload) void UHarmonyLinkGraphics::LoadConfig(const bool bForceReload)
@ -352,14 +354,28 @@ void UHarmonyLinkGraphics::DestroySettings()
void UHarmonyLinkGraphics::Init() void UHarmonyLinkGraphics::Init()
{ {
UE_LOG(LogHarmonyLink, Log, TEXT("Init called.")); UE_LOG(LogHarmonyLink, Log, TEXT("Init called."));
if (!HarmonyLinkLib::HL_Init())
{
UE_LOG(LogHarmonyLink, Fatal, TEXT("Failed to initialise HarmonyLinkLib!"));
return;
}
LoadConfig(); LoadConfig();
const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus(); const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus();
if (BatteryStatus.HasBattery) if (BatteryStatus.HasBattery)
{
if (BatteryStatus.IsACConnected)
{ {
ApplyProfileInternal(EProfile::BATTERY); ApplyProfileInternal(EProfile::BATTERY);
} }
else
{
ApplyProfileInternal(EProfile::CHARGING);
}
}
} }
void UHarmonyLinkGraphics::Intermal_SaveConfig(const bool bDefaultConfig) const void UHarmonyLinkGraphics::Intermal_SaveConfig(const bool bDefaultConfig) const
@ -584,7 +600,7 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
if (World->IsGameWorld()) if (World->IsGameWorld())
{ {
if (IsValid(_INSTANCE)) if (IsValid(GetSettings()))
{ {
FTimerManager* TimerManager = &World->GetTimerManager(); FTimerManager* TimerManager = &World->GetTimerManager();
if (!TimerManager) if (!TimerManager)
@ -598,7 +614,7 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
World->GetTimerManager().SetTimer(_TickTimerHandle, [TimerManager] World->GetTimerManager().SetTimer(_TickTimerHandle, [TimerManager]
{ {
if (!_INSTANCE) if (!GetSettings())
{ {
UE_LOG(LogHarmonyLink, Error, TEXT("'This' is destroyed, Clearing timer.")) UE_LOG(LogHarmonyLink, Error, TEXT("'This' is destroyed, Clearing timer."))
if (TimerManager) if (TimerManager)
@ -607,7 +623,7 @@ void UHarmonyLinkGraphics::OnPostWorldInitialization(UWorld* World, UWorld::Init
} }
return; return;
} }
_INSTANCE->Tick(); GetSettings()->Tick();
}, _TickRate, true); }, _TickRate, true);
} }
else else

View file

@ -25,29 +25,45 @@ public:
// Checks if the game is running under Wine. // Checks if the game is running under Wine.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static bool IsWine(); static bool IsWine(bool bForce = false);
// Checks if the operating system is Linux. // Checks if the operating system is Linux.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static bool IsLinux(); static bool IsLinux(bool bForce = false);
// Checks if the game is running on a Steam Deck. // Checks if the game is running on a Steam Deck.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static bool IsSteamDeck(); static bool IsSteamDeck(bool bForce = false);
// Retrieves information about the CPU of the current device. // Retrieves information about the CPU of the current device.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static FCPUInfo GetCPUInfo(); static FCPUInfo GetCPUInfo(bool bForce = false);
// Retrieves information about the current device. // Retrieves information about the current device.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static FDevice GetDeviceInfo(); static FDevice GetDeviceInfo(bool bForce = false);
// Retrieves information about the operating system of the current device. // Retrieves information about the operating system of the current device.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static FOSVerInfo GetOSInfo(); static FOSVerInfo GetOSInfo(bool bForce = false);
// Retrieves the current battery status of the device. // Retrieves the current battery status of the device.
UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink") UFUNCTION(BlueprintCallable, BlueprintPure, Category="HarmonyLink")
static FBattery GetBatteryStatus(); static FBattery GetBatteryStatus();
private:
static bool bIsWineCached;
static bool bIsWine;
static bool bIsLinuxCached;
static bool bIsLinux;
static bool bIsSteamDeckCached;
static bool bIsSteamDeck;
static bool bCPUInfoCached;
static bool bDeviceInfoCached;
static bool bOSInfoCached;
static FCPUInfo CachedCPUInfo;
static FDevice CachedDeviceInfo;
static FOSVerInfo CachedOSInfo;
}; };

View file

@ -6,7 +6,7 @@
#include "Enums/Profile.h" #include "Enums/Profile.h"
#include "Structs/SettingsProfile.h" #include "Structs/SettingsProfile.h"
#include "UObject/Object.h" #include "Kismet/BlueprintFunctionLibrary.h"
#include "HarmonyLinkGraphics.generated.h" #include "HarmonyLinkGraphics.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnProfileChanged, EProfile, Profile); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnProfileChanged, EProfile, Profile);
@ -17,7 +17,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnBatteryLevelChanged, int32, Batte
* *
*/ */
UCLASS(Blueprintable, config="HarmonyLink") UCLASS(Blueprintable, config="HarmonyLink")
class HARMONYLINK_API UHarmonyLinkGraphics : public UObject class HARMONYLINK_API UHarmonyLinkGraphics : public UBlueprintFunctionLibrary
{ {
GENERATED_BODY() GENERATED_BODY()
@ -390,7 +390,7 @@ private:
* *
* @note Uses UE_LOG for logging errors and informational messages. * @note Uses UE_LOG for logging errors and informational messages.
*/ */
void OnPostWorldInitialization(UWorld* World, UWorld::InitializationValues IVS); static void OnPostWorldInitialization(UWorld* World, UWorld::InitializationValues IVS);
/** /**
* @brief Handles actions to be performed when the world ends. * @brief Handles actions to be performed when the world ends.
@ -406,7 +406,7 @@ private:
* *
* @note Uses UE_LOG for logging errors and informational messages. * @note Uses UE_LOG for logging errors and informational messages.
*/ */
void OnWorldEnd(UWorld* World); static void OnWorldEnd(UWorld* World);
/** /**
* @brief Resets the singleton instance of the UHarmonyLinkGraphics settings. * @brief Resets the singleton instance of the UHarmonyLinkGraphics settings.

View file

@ -43,26 +43,30 @@ public class HarmonyLinkLib : ModuleRules
} }
else if (Target.Platform == UnrealTargetPlatform.Linux) else if (Target.Platform == UnrealTargetPlatform.Linux)
{ {
PublicDefinitions.Add("HARMONYLINKLIB_SHARED=1"); PublicDefinitions.Add("HARMONYLINKLIB_STATIC=1");
//Console.WriteLine("Building Linux"); //Console.WriteLine("Building Linux");
PublicDefinitions.Add("BUILD_LINUX=1"); PublicDefinitions.Add("BUILD_LINUX=1");
string libPath = Path.Combine(ModuleDirectory, "bin", platformString, "libHarmonyLinkLibShared.so"); string dllPath = Path.Combine(ModuleDirectory, "lib", platformString, "libHarmonyLinkLibStatic_clang++.a");
//string dllTargetPath = "$(TargetOutputDir)/libHarmonyLinkLibShared.so";
//Console.WriteLine("Library Path: " + libPath); //Console.WriteLine("Library Path: " + libPath);
PublicAdditionalLibraries.Add(libPath); PublicAdditionalLibraries.Add(dllPath);
// Add the C++ standard library explicitly // Ensure the proper linking of standard C++ libraries
//string toolchainLibPath = "E:/UnrealToolChains/v22_clang-16.0.6-centos7/x86_64-unknown-linux-gnu/lib"; //PublicSystemLibraries.Add("stdc++");
//PublicSystemLibraryPaths.Add(toolchainLibPath); //PublicSystemLibraries.Add("c++abi");
RuntimeDependencies.Add(libPath); //PublicSystemLibraries.Add("m"); // Math library
} //PublicSystemLibraries.Add("pthread"); // POSIX threads library
// I shall include this if anyone wishes to provide Mac binaries of HarmonyLink but these are not included by default as I don't own one.
else if (Target.Platform == UnrealTargetPlatform.Mac) // Add the C++ standard library explicitly if needed
{ PublicSystemLibraries.Add("c++");
PublicDefinitions.Add("HARMONYLINKLIB_SHARED=1");
PublicDefinitions.Add("BUILD_MACOS=1"); // Ensure linking with libc and other necessary libraries
string dynlibPath = Path.Combine(ModuleDirectory, "lib", platformString, "libHarmonyLinkLibStatic.a"); //PublicSystemLibraries.Add("dl"); // Dynamic linking loader
//Console.WriteLine("Dynamic Library Path: " + dynlibPath); //PublicSystemLibraries.Add("rt"); // Real-time library
RuntimeDependencies.Add(dynlibPath);
// Add any other libraries that might be needed
//PublicSystemLibraries.Add("gcc_s"); // GCC support library
//PublicSystemLibraries.Add("gcc"); // GCC compiler support library
} }
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.