Skip to content

Commit

Permalink
Add LinuxArm64 Support (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycajunrice authored Sep 13, 2024
1 parent e3f10a6 commit 12ac2f9
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 17 deletions.
Binary file added Content/Assets/WebTexture_M.uasset
Binary file not shown.
Binary file added Content/Assets/WebTexture_T.uasset
Binary file not shown.
Binary file added Content/Assets/WebTexture_TM.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Additionally, you need to add `bCompileCEF3 = true;` to your build target
| Platform | x64 | arm64 |
|----------|:---:|:-----:|
| Windows |||
| Linux || |
| Linux || |
| Mac |||
| IOS |||
| TVOS |||
Expand Down
3 changes: 3 additions & 0 deletions Scripts/BuildPlugin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
CD /D ..
ue4 package -NoHostPlatform -TargetPlatforms=Win64+Android+Linux+LinuxArm64
2 changes: 2 additions & 0 deletions Scripts/build-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
ue4 package -NoHostPlatform -TargetPlatforms=IOS+Mac+TVOS+VisionOS
3 changes: 3 additions & 0 deletions Source/ThirdParty/LinuxArm64/libthirdweb.a
Git LFS file not shown
36 changes: 36 additions & 0 deletions Source/Thirdweb/Private/ThirdwebAssetManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024 Thirdweb. All Rights Reserved.

#include "ThirdwebAssetManager.h"

#if WITH_EDITOR || PLATFORM_ANDROID || PLATFORM_IOS
#include "WebBrowserTexture.h"

#include "Materials/Material.h"
#endif

UThirdwebAssetManager::UThirdwebAssetManager()
{
DefaultMaterial = FString(TEXT("/Thirdweb/Assets/WebTexture_M.WebTexture_M"));
DefaultTranslucentMaterial = FString(TEXT("/Thirdweb/Assets/WebTexture_TM.WebTexture_TM"));

#if WITH_EDITOR || PLATFORM_ANDROID || PLATFORM_IOS
// Add a hard reference to UWebBrowserTexture, without this the WebBrowserTexture DLL never gets loaded on Windows.
UWebBrowserTexture::StaticClass();
#endif
}

void UThirdwebAssetManager::LoadDefaultMaterials()
{
DefaultMaterial.LoadSynchronous();
DefaultTranslucentMaterial.LoadSynchronous();
}

UMaterial* UThirdwebAssetManager::GetDefaultMaterial()
{
return DefaultMaterial.Get();
}

UMaterial* UThirdwebAssetManager::GetDefaultTranslucentMaterial()
{
return DefaultTranslucentMaterial.Get();
}
42 changes: 40 additions & 2 deletions Source/Thirdweb/Private/ThirdwebModule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
// Copyright (c) 2024 Thirdweb. All Rights Reserved.

#include "Modules/ModuleManager.h"
#include "ThirdwebModule.h"

#include "IWebBrowserSingleton.h"
#include "ThirdwebAssetManager.h"
#include "WebBrowserModule.h"

#include "Materials/Material.h"

class FThirdwebModule : public IThirdwebModule
{
public:
virtual void StartupModule() override
{
if (ThirdwebAssetManager == nullptr)
{
ThirdwebAssetManager = NewObject<UThirdwebAssetManager>((UObject*)GetTransientPackage(), NAME_None, RF_Transient | RF_Public);
ThirdwebAssetManager->LoadDefaultMaterials();

IWebBrowserModule::Get(); // force the module to load
if (IWebBrowserModule::IsAvailable() && IWebBrowserModule::Get().IsWebModuleAvailable())
{
IWebBrowserSingleton* WebBrowserSingleton = IWebBrowserModule::Get().GetSingleton();
if (WebBrowserSingleton)
{
WebBrowserSingleton->SetDefaultMaterial(ThirdwebAssetManager->GetDefaultMaterial());
WebBrowserSingleton->SetDefaultTranslucentMaterial(ThirdwebAssetManager->GetDefaultTranslucentMaterial());
}
}
}
}

virtual void ShutdownModule() override
{
}

private:
UThirdwebAssetManager* ThirdwebAssetManager = nullptr;
};

IMPLEMENT_MODULE(FThirdwebModule, Thirdweb);

IMPLEMENT_MODULE(FDefaultModuleImpl, Thirdweb)
38 changes: 38 additions & 0 deletions Source/Thirdweb/Public/ThirdwebAssetManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2024 Thirdweb. All Rights Reserved.

#pragma once

#include "Materials/Material.h"

#include "UObject/SoftObjectPtr.h"

#include "ThirdwebAssetManager.generated.h"

class UMaterial;
/**
* @class UThirdwebAssetManager
* @brief Manages and handles loading, unloading, and accessing game assets.
*
* The UThirdwebAssetManager class is responsible for the efficient management
* of game assets such as textures, models, sound files, and other resources.
* It provides functions to load and unload assets, handles asset reference
* counting, and ensures that assets are loaded only once. This helps in
* optimizing game performance by minimizing redundant loading and memory usage.
*/
UCLASS()
class THIRDWEB_API UThirdwebAssetManager : public UObject
{
GENERATED_BODY()
public:
UThirdwebAssetManager();

void LoadDefaultMaterials();

UMaterial* GetDefaultMaterial();
UMaterial* GetDefaultTranslucentMaterial();

protected:
UPROPERTY()
TSoftObjectPtr<UMaterial> DefaultMaterial;
TSoftObjectPtr<UMaterial> DefaultTranslucentMaterial;
};
24 changes: 24 additions & 0 deletions Source/Thirdweb/Public/ThirdwebModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024 Thirdweb. All Rights Reserved.

#pragma once

#include "Modules/ModuleManager.h"

class IThirdwebModule : public IModuleInterface
{
public:
/**
* Singleton-like access to this module's interface. This is just for convenience!
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
*
* @return Returns singleton instance, loading the module on demand if needed
*/
static IThirdwebModule& Get() { return FModuleManager::LoadModuleChecked<IThirdwebModule>("Thirdweb"); }

/**
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true.
*
* @return True if the module is loaded and ready to use
*/
static bool IsAvailable() { return FModuleManager::Get().IsModuleLoaded("Thirdweb"); }
};
35 changes: 29 additions & 6 deletions Source/Thirdweb/Thirdweb.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ public class Thirdweb : ModuleRules
;

private bool IsApple => Target.Platform.IsInGroup(UnrealPlatformGroup.Apple);

private bool IsAndroid => Target.Platform.Equals(UnrealTargetPlatform.Android);

private bool IsMobile => IsIOSIsh || Target.Platform.Equals(UnrealTargetPlatform.Android);
private bool IsMobile => IsIOSIsh || IsAndroid;

private string LibExt =>
IsWin64 ? ".lib" : Target.Architectures.Contains(UnrealArch.IOSSimulator) ? ".sim.a" : ".a";

private string LibDir => Path.Combine(Path.Combine(ModuleDirectory, "..", "ThirdParty"),
IsIOSIsh ? "IOS" : Target.Platform.ToString());


public Thirdweb(ReadOnlyTargetRules target) : base(target)
{
PrivateDependencyModuleNames.AddRange(new string[] { "Boost" });
PrivateDependencyModuleNames.AddRange(new [] { "Boost" });
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

#if UE_5_3_OR_LATER
Expand All @@ -36,8 +37,21 @@ public Thirdweb(ReadOnlyTargetRules target) : base(target)

#if UE_5_0_OR_LATER
PublicDefinitions.Add("WITH_CEF=1");
PublicDependencyModuleNames.Add("WebBrowserWidget");
PrivateDependencyModuleNames.Add("WebBrowser");

// Copied from WebBrowserWidget
if (target.bBuildEditor || IsAndroid || IsIOSIsh)
{
// WebBrowserTexture required for cooking Android
PrivateIncludePathModuleNames.AddRange(new [] { "WebBrowserTexture" });
PrivateDependencyModuleNames.AddRange(new [] { "WebBrowserTexture" });

if (IsAndroid)
{
var PluginPath = Utils.MakePathRelativeTo(ModuleDirectory, target.RelativeEnginePath);
AdditionalPropertiesForReceipt.Add("AndroidPlugin", Path.Combine(PluginPath, "Thirdweb_UPL.xml"));
}
}
#else
PublicDefinitions.Add("WITH_CEF=0");
#endif
Expand Down Expand Up @@ -69,7 +83,7 @@ public Thirdweb(ReadOnlyTargetRules target) : base(target)
{
PrivateDependencyModuleNames.Add("Launch");
}

PublicDependencyModuleNames.AddRange(new[]
{
// Standard deps
Expand All @@ -88,5 +102,14 @@ public Thirdweb(ReadOnlyTargetRules target) : base(target)
"Slate",
"SlateCore"
});

// Copied from WebBrowserWidget
if (target.bBuildEditor)
{
// @TODO: UnrealEd Needed for the triangulation code used for sprites (but only in editor mode)
// @TOOD: Try to move the code dependent on the triangulation code to the editor-only module
PrivateIncludePathModuleNames.AddRange(new [] { "UnrealEd" });
PrivateDependencyModuleNames.AddRange(new [] { "EditorFramework", "UnrealEd" });
}
}
}
}
31 changes: 31 additions & 0 deletions Source/Thirdweb/Thirdweb_UPL.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:android="http://schemas.android.com/apk/res/android">
<init>
<log text="Thirdweb Plugin Init"/>
<setBoolFromPropertyContains result="bPackageForOculusQuest" ini="Engine" section="/Script/AndroidRuntimeSettings.AndroidRuntimeSettings" property="PackageForOculusMobile" contains="Quest"/>
<setBoolFromPropertyContains result="bPackageForOculusQuest2" ini="Engine" section="/Script/AndroidRuntimeSettings.AndroidRuntimeSettings" property="PackageForOculusMobile" contains="Quest2"/>
<setBoolFromPropertyContains result="bPackageForOculusQuestPro" ini="Engine" section="/Script/AndroidRuntimeSettings.AndroidRuntimeSettings" property="PackageForOculusMobile" contains="QuestPro"/>

<setBoolOr result="bPackageForOculusMobile"
arg1="$B(bPackageForOculusQuest)" arg2="$B(bPackageForOculusQuest2)"/>
<setBoolOr result="bPackageForOculusMobile"
arg1="$B(bPackageForOculusMobile)" arg2="$B(bPackageForOculusQuestPro)"/>

<if condition="bPackageForOculusMobile">
<true>
<log text="Adding com.oculus.always_draw_view_root for Oculus devices to manifest for hardware acceleration."/>
</true>
</if>
</init>

<androidManifestUpdates>
<if condition="bPackageForOculusMobile">
<true>
<addElements tag="application">
<meta-data android:name="com.oculus.always_draw_view_root" android:value="true"/>
</addElements>
</true>
</if>
</androidManifestUpdates>

</root>
12 changes: 4 additions & 8 deletions Thirdweb.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 3,
"VersionName": "1.2.0",
"Version": 130,
"VersionName": "1.3.0",
"FriendlyName": "Thirdweb",
"Description": "Unreal Integration of Thirdweb Wallets",
"Category": "Thirdweb",
Expand All @@ -23,16 +23,12 @@
"Win64",
"Mac",
"Linux",
"LinuxArm64",
"Android",
"IOS",
"TVOS",
"VisionOS"
]
}
],
"Plugins": [
{
"Name": "WebBrowserWidget",
"Enabled": true
}
]
}

0 comments on commit 12ac2f9

Please sign in to comment.