Android build settings + metaxr
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// @lint-ignore-every LICENSELINT
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
namespace UnrealBuildTool.Rules
|
||||
{
|
||||
public class OculusXRAsyncRequest : ModuleRules
|
||||
{
|
||||
public OculusXRAsyncRequest(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
bUseUnity = true;
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
});
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
});
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
"Runtime/Engine/Classes/Components",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// @lint-ignore-every LICENSELINT
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "OculusXRAsyncRequestModule.h"
|
||||
|
||||
#if OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogOculusXRAsyncRequest);
|
||||
|
||||
#define LOCTEXT_NAMESPACE "OculusXRAsyncRequest"
|
||||
|
||||
void FOculusXRAsyncRequestModule::StartupModule()
|
||||
{
|
||||
}
|
||||
|
||||
void FOculusXRAsyncRequestModule::ShutdownModule()
|
||||
{
|
||||
}
|
||||
|
||||
#endif // OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS
|
||||
|
||||
IMPLEMENT_MODULE(FOculusXRAsyncRequestModule, OculusXRAsyncRequest)
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,32 @@
|
||||
// @lint-ignore-every LICENSELINT
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IOculusXRAsyncRequestModule.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogOculusXRAsyncRequest, Log, All);
|
||||
|
||||
#define LOCTEXT_NAMESPACE "OculusXRAsyncRequest"
|
||||
|
||||
#if OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS
|
||||
|
||||
class FOculusXRAsyncRequestModule : public IOculusXRAsyncRequestModule
|
||||
{
|
||||
public:
|
||||
virtual ~FOculusXRAsyncRequestModule() = default;
|
||||
|
||||
// IModuleInterface interface
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
|
||||
#else // OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS
|
||||
|
||||
class FOculusXRAsyncRequestModule : public FDefaultModuleImpl
|
||||
{
|
||||
};
|
||||
|
||||
#endif // OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#include "OculusXRAsyncRequestSubsystem.h"
|
||||
#include "OculusXRAsyncRequestSystem.h"
|
||||
#include <Engine/World.h>
|
||||
#include <Engine/GameInstance.h>
|
||||
|
||||
#if WITH_EDITOR
|
||||
#include <Engine/Engine.h>
|
||||
#endif
|
||||
|
||||
UOculusXRAsyncRequestSubsystem* UOculusXRAsyncRequestSubsystem::GetSubsystem()
|
||||
{
|
||||
if (GWorld != nullptr)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
if (GIsEditor)
|
||||
{
|
||||
for (const FWorldContext& Context : GEngine->GetWorldContexts())
|
||||
{
|
||||
if (Context.WorldType == EWorldType::PIE)
|
||||
{
|
||||
return Context.World()->GetGameInstance()->GetSubsystem<UOculusXRAsyncRequestSubsystem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
return GWorld->GetGameInstance()->GetSubsystem<UOculusXRAsyncRequestSubsystem>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OculusXR::FAsyncRequestSystem* UOculusXRAsyncRequestSubsystem::GetRequestSystem()
|
||||
{
|
||||
return (GetSubsystem()->RequestSystem).Get();
|
||||
}
|
||||
|
||||
void UOculusXRAsyncRequestSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
RequestSystem = MakeShared<OculusXR::FAsyncRequestSystem>();
|
||||
}
|
||||
|
||||
void UOculusXRAsyncRequestSubsystem::Deinitialize()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Subsystems/GameInstanceSubsystem.h"
|
||||
#include "OculusXRAsyncRequestSubsystem.generated.h"
|
||||
|
||||
namespace OculusXR
|
||||
{
|
||||
class FAsyncRequestSystem;
|
||||
}
|
||||
|
||||
UCLASS()
|
||||
class OCULUSXRASYNCREQUEST_API UOculusXRAsyncRequestSubsystem : public UGameInstanceSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
static UOculusXRAsyncRequestSubsystem* GetSubsystem();
|
||||
static OculusXR::FAsyncRequestSystem* GetRequestSystem();
|
||||
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
virtual void Deinitialize() override;
|
||||
|
||||
private:
|
||||
TSharedPtr<OculusXR::FAsyncRequestSystem> RequestSystem;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#include "OculusXRAsyncRequestSystem.h"
|
||||
#include "OculusXRAsyncRequestSubsystem.h"
|
||||
|
||||
namespace OculusXR
|
||||
{
|
||||
FAsyncRequestSystem::FAsyncRequestSystem()
|
||||
: EventIdCounter(0)
|
||||
{
|
||||
}
|
||||
|
||||
FAsyncRequestBase::EventId FAsyncRequestSystem::GenerateEventId()
|
||||
{
|
||||
return FAsyncRequestBase::EventId(++(GetInstance().EventIdCounter));
|
||||
}
|
||||
|
||||
FAsyncRequestSystem& FAsyncRequestSystem::GetInstance()
|
||||
{
|
||||
return *UOculusXRAsyncRequestSubsystem::GetRequestSystem();
|
||||
}
|
||||
} // namespace OculusXR
|
||||
@@ -0,0 +1,37 @@
|
||||
// @lint-ignore-every LICENSELINT
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
#define OCULUS_ASYNC_REQUEST_SUPPORTED_PLATFORMS (PLATFORM_WINDOWS && WINVER > 0x0502) || (PLATFORM_ANDROID_ARM || PLATFORM_ANDROID_ARM64 || PLATFORM_ANDROID_X64)
|
||||
|
||||
/**
|
||||
* The public interface to this module. In most cases, this interface is only public to sibling modules
|
||||
* within this plugin.
|
||||
*/
|
||||
class IOculusXRAsyncRequestModule : 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 inline IOculusXRAsyncRequestModule& Get()
|
||||
{
|
||||
return FModuleManager::LoadModuleChecked<IOculusXRAsyncRequestModule>("OculusXRAsyncRequest");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 inline bool IsAvailable()
|
||||
{
|
||||
return FModuleManager::Get().IsModuleLoaded("OculusXRAsyncRequest");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OculusXRAsyncRequestBase.h"
|
||||
#include "OculusXRAsyncRequestSystem.h"
|
||||
#include "IOculusXRAsyncRequestModule.h"
|
||||
|
||||
namespace OculusXR
|
||||
{
|
||||
// Templated event type that is derived from to create new requests types
|
||||
template <typename TDerived, typename TResultEnum, typename TValueType, typename TResultSuccess = FAsyncResultDefaultSuccess<TResultEnum>>
|
||||
struct FAsyncRequest : public FAsyncRequestBase
|
||||
{
|
||||
public:
|
||||
typedef TValueType FResultValueType;
|
||||
typedef FAsyncResult<TResultEnum, TValueType, TResultSuccess> FResultType;
|
||||
DECLARE_DELEGATE_OneParam(FCompleteDelegate, const FResultType&);
|
||||
|
||||
FAsyncRequest()
|
||||
: RequestResult(FResultType::FromEmpty())
|
||||
, bIsComplete(false)
|
||||
, bHasStarted(false)
|
||||
{
|
||||
SetEventId(FAsyncRequestSystem::GenerateEventId());
|
||||
}
|
||||
|
||||
virtual ~FAsyncRequest() {}
|
||||
|
||||
// Call this to start the request
|
||||
void Execute()
|
||||
{
|
||||
// Validate we aren't starting the request more than once
|
||||
check(!bHasStarted);
|
||||
bHasStarted = true;
|
||||
|
||||
// Start the async work
|
||||
OnInitRequest();
|
||||
|
||||
// Check initial result
|
||||
if (!TResultSuccess()(InitialResultStatus))
|
||||
{
|
||||
// Request failed so fire complete now and remove it from the request system
|
||||
// Once it goes out of scope in the calling code the shared ptr will be destroyed
|
||||
FAsyncRequestSystem::CompleteRequest<TDerived>(GetEventId(), FResultType::FromError(InitialResultStatus));
|
||||
return;
|
||||
}
|
||||
|
||||
FAsyncRequestSystem::SetRequestId<TDerived>(GetEventId(), GetRequestId());
|
||||
}
|
||||
|
||||
// Bind a callback to the completion of the event
|
||||
void BindOnComplete(const FCompleteDelegate& Function) { OnComplete = Function; }
|
||||
|
||||
bool IsComplete() const { return bIsComplete; }
|
||||
const FResultType& GetResult() const
|
||||
{
|
||||
// Result type isn't valid unless we have completed
|
||||
check(bIsComplete);
|
||||
return RequestResult;
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class FAsyncRequestSystem;
|
||||
|
||||
void RequestCompleted(const FResultType& InResult)
|
||||
{
|
||||
bIsComplete = true;
|
||||
RequestResult = InResult;
|
||||
OnComplete.ExecuteIfBound(InResult);
|
||||
OnCompleteRequest(InResult);
|
||||
}
|
||||
|
||||
// Called by the derived request to specify the result code that came from starting the async work.
|
||||
void SetInitialResult(TResultEnum ResultStatus)
|
||||
{
|
||||
InitialResultStatus = ResultStatus;
|
||||
}
|
||||
|
||||
// Overload to do request initialization, call OVRP functions, etc..
|
||||
virtual void OnInitRequest() {}
|
||||
|
||||
// Overload this request to clean up any remaining data if needed
|
||||
virtual void OnCompleteRequest(const FResultType& Result) {}
|
||||
|
||||
private:
|
||||
FCompleteDelegate OnComplete;
|
||||
TResultEnum InitialResultStatus;
|
||||
FResultType RequestResult;
|
||||
bool bIsComplete;
|
||||
bool bHasStarted;
|
||||
};
|
||||
} // namespace OculusXR
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Templates/TypeHash.h>
|
||||
|
||||
namespace OculusXR
|
||||
{
|
||||
constexpr uint64_t INVALID_TASK_REQUEST_ID = 0;
|
||||
|
||||
template <typename TResultEnum>
|
||||
struct FAsyncResultDefaultSuccess
|
||||
{
|
||||
bool operator()(TResultEnum Val) { return Val == TResultEnum::Success; }
|
||||
};
|
||||
|
||||
template <typename TResultEnum, typename TValueType, typename TSuccess = FAsyncResultDefaultSuccess<TResultEnum>>
|
||||
struct FAsyncResult
|
||||
{
|
||||
public:
|
||||
~FAsyncResult() {}
|
||||
|
||||
static FAsyncResult FromEmpty()
|
||||
{
|
||||
return FAsyncResult();
|
||||
}
|
||||
|
||||
static FAsyncResult FromResult(TResultEnum Status, const TValueType& Value)
|
||||
{
|
||||
return FAsyncResult(Status, Value);
|
||||
}
|
||||
|
||||
static FAsyncResult FromError(TResultEnum Status)
|
||||
{
|
||||
return FAsyncResult(Status, {});
|
||||
}
|
||||
|
||||
TResultEnum GetStatus() const { return Status; }
|
||||
bool IsSuccess() const { return TSuccess()(Status); }
|
||||
const TValueType& GetValue() const
|
||||
{
|
||||
check(IsSuccess());
|
||||
return Value;
|
||||
}
|
||||
|
||||
private:
|
||||
FAsyncResult() {}
|
||||
|
||||
FAsyncResult(TResultEnum InStatus, const TValueType& InValue)
|
||||
{
|
||||
Status = InStatus;
|
||||
Value = InValue;
|
||||
}
|
||||
|
||||
TResultEnum Status;
|
||||
TValueType Value;
|
||||
};
|
||||
|
||||
// Base event class that the internal task system uses to reference task data
|
||||
struct FAsyncRequestBase
|
||||
{
|
||||
public:
|
||||
FAsyncRequestBase()
|
||||
: InternalEventId(EventId(0))
|
||||
, InternalRequestId(RequestId(INVALID_TASK_REQUEST_ID))
|
||||
{
|
||||
// The derived
|
||||
}
|
||||
|
||||
struct EventId
|
||||
{
|
||||
EventId(uint64_t InId) { Id = InId; }
|
||||
|
||||
uint64_t Id;
|
||||
|
||||
bool operator==(const EventId& Rhs) const { return Id == Rhs.Id; }
|
||||
bool operator!=(const EventId& Rhs) const { return !operator==(Rhs); }
|
||||
friend uint32_t GetTypeHash(const EventId& X) { return GetTypeHash(X.Id); }
|
||||
};
|
||||
|
||||
struct RequestId
|
||||
{
|
||||
RequestId(uint64_t InId) { Id = InId; }
|
||||
|
||||
uint64_t Id;
|
||||
|
||||
bool operator==(const RequestId& Rhs) const { return Id == Rhs.Id; }
|
||||
bool operator!=(const RequestId& Rhs) const { return !operator==(Rhs); }
|
||||
friend uint32_t GetTypeHash(const RequestId& X) { return GetTypeHash(X.Id); }
|
||||
};
|
||||
|
||||
virtual ~FAsyncRequestBase() {}
|
||||
|
||||
EventId GetEventId() const { return InternalEventId; }
|
||||
RequestId GetRequestId() const { return InternalRequestId; }
|
||||
|
||||
protected:
|
||||
void SetEventId(EventId InEventId) { InternalEventId = InEventId; }
|
||||
void SetRequestId(RequestId InRequestId) { InternalRequestId = InRequestId; }
|
||||
|
||||
private:
|
||||
EventId InternalEventId; // Unique identifier, set regardless of the request ID value
|
||||
RequestId InternalRequestId; // Request id returned from successfully starting an async xr method
|
||||
};
|
||||
} // namespace OculusXR
|
||||
@@ -0,0 +1,94 @@
|
||||
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "OculusXRAsyncRequestBase.h"
|
||||
#include <Templates/SharedPointer.h>
|
||||
#include <atomic>
|
||||
|
||||
namespace OculusXR
|
||||
{
|
||||
class FAsyncRequestSystem
|
||||
{
|
||||
public:
|
||||
FAsyncRequestSystem();
|
||||
|
||||
static OCULUSXRASYNCREQUEST_API FAsyncRequestBase::EventId GenerateEventId();
|
||||
|
||||
template <typename RequestType, typename... TArgs>
|
||||
static TSharedPtr<RequestType> CreateRequest(TArgs&&... Args)
|
||||
{
|
||||
auto request = MakeShared<RequestType>(std::forward<TArgs>(Args)...);
|
||||
GetInstance().Requests.Add(request->GetEventId(), request);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
static void RemoveRequest(FAsyncRequestBase::EventId Id)
|
||||
{
|
||||
auto& systemInstance = GetInstance();
|
||||
auto foundPtr = systemInstance.Requests.Find(Id);
|
||||
if (foundPtr)
|
||||
{
|
||||
systemInstance.RequestIdToEventIdMap.Remove((*foundPtr)->GetRequestId());
|
||||
systemInstance.Requests.Remove(Id);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename RequestType>
|
||||
static TSharedPtr<RequestType> GetRequest(FAsyncRequestBase::EventId Id)
|
||||
{
|
||||
auto foundRequestPtr = GetInstance().Requests.Find(Id);
|
||||
if (foundRequestPtr != nullptr)
|
||||
{
|
||||
return StaticCastSharedPtr<RequestType>(*foundRequestPtr);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename RequestType>
|
||||
static TSharedPtr<RequestType> GetRequest(FAsyncRequestBase::RequestId Id)
|
||||
{
|
||||
auto& systemInstance = GetInstance();
|
||||
|
||||
auto foundEventId = systemInstance.RequestIdToEventIdMap.Find(Id);
|
||||
if (foundEventId != nullptr)
|
||||
{
|
||||
auto foundRequestPtr = systemInstance.Requests.Find(*foundEventId);
|
||||
if (foundRequestPtr)
|
||||
{
|
||||
return StaticCastSharedPtr<RequestType>(*foundRequestPtr);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename RequestType>
|
||||
static void SetRequestId(FAsyncRequestBase::EventId EventId, FAsyncRequestBase::RequestId RequestId)
|
||||
{
|
||||
GetInstance().RequestIdToEventIdMap.Add(RequestId, EventId);
|
||||
}
|
||||
|
||||
template <typename RequestType>
|
||||
static void CompleteRequest(FAsyncRequestBase::EventId EventId, const typename RequestType::FResultType& Result)
|
||||
{
|
||||
auto& systemInstance = GetInstance();
|
||||
|
||||
auto request = systemInstance.GetRequest<RequestType>(EventId);
|
||||
if (request.IsValid())
|
||||
{
|
||||
request->RequestCompleted(Result);
|
||||
systemInstance.RemoveRequest(EventId);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static OCULUSXRASYNCREQUEST_API FAsyncRequestSystem& GetInstance();
|
||||
|
||||
TMap<FAsyncRequestBase::EventId, TSharedPtr<FAsyncRequestBase>> Requests;
|
||||
TMap<FAsyncRequestBase::RequestId, FAsyncRequestBase::EventId> RequestIdToEventIdMap;
|
||||
std::atomic<uint64_t> EventIdCounter;
|
||||
};
|
||||
} // namespace OculusXR
|
||||
Reference in New Issue
Block a user