Files
UnrealEngineUWP/Engine/Source/Runtime/HeadMountedDisplay/Private/XRMotionControllerBase.cpp
robert manuszewski d1443992e1 Deprecating ANY_PACKAGE.
This change consists of multiple changes:

Core:
- Deprecation of ANY_PACKAGE macro. Added ANY_PACKAGE_DEPRECATED macro which can still be used for backwards compatibility purposes (only used in CoreUObject)
- Deprecation of StaticFindObjectFast* functions that take bAnyPackage parameter
- Added UStruct::GetStructPathName function that returns FTopLevelAssetPath representing the path name (package + object FName, super quick compared to UObject::GetPathName) + wrapper UClass::GetClassPathName to make it look better when used with UClasses
- Added (Static)FindFirstObject* functions that find a first object given its Name (no Outer). These functions are used in places I consider valid to do global UObject (UClass) lookups like parsing command line parameters / checking for unique object names
- Added static UClass::TryFindType function which serves a similar purpose as FindFirstObject however it's going to throw a warning (with a callstack / maybe ensure in the future?) if short class name is provided. This function is used  in places that used to use short class names but now should have been converted to use path names to catch any potential regressions and or edge cases I missed.
- Added static UClass::TryConvertShortNameToPathName utility function
- Added static UClass::TryFixShortClassNameExportPath utility function
- Object text export paths will now also include class path (Texture2D'/Game/Textures/Grass.Grass' -> /Script/Engine.Texture2D'/Game/Textures/Grass.Grass')
- All places that manually generated object export paths for objects will now use FObjectPropertyBase::GetExportPath
- Added a new startup test that checks for short type names in UClass/FProperty MetaData values

AssetRegistry:
- Deprecated any member variables (FAssetData / FARFilter) or functions that use FNames to represent class names and replaced them with FTopLevelAssetPath
- Added new member variables and new function overloads that use FTopLevelAssetPath to represent class names
- This also applies to a few other modules' APIs to match AssetRegistry changes

Everything else:
- Updated code that used ANY_PACKAGE (depending on the use case) to use FindObject(nullptr, PathToObject), UClass::TryFindType (used when path name is expected, warns if it's a short name) or FindFirstObject (usually for finding types based on user input but there's been a few legitimate use cases not related to user input)
- Updated code that used AssetRegistry API to use FTopLevelAssetPaths and USomeClass::StaticClass()->GetClassPathName() instead of GetFName()
- Updated meta data and hardcoded FindObject(ANY_PACKAGE, "EEnumNameOrClassName") calls to use path names

#jira UE-99463
#rb many.people
[FYI] Marcus.Wassmer
#preflight 629248ec2256738f75de9b32

#codereviewnumbers 20320742, 20320791, 20320799, 20320756, 20320809, 20320830, 20320840, 20320846, 20320851, 20320863, 20320780, 20320765, 20320876, 20320786

#ROBOMERGE-OWNER: robert.manuszewski
#ROBOMERGE-AUTHOR: robert.manuszewski
#ROBOMERGE-SOURCE: CL 20430220 via CL 20433854 via CL 20435474 via CL 20435484
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v949-20362246)

[CL 20448496 by robert manuszewski in ue5-main branch]
2022-06-01 03:46:59 -04:00

163 lines
9.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "XRMotionControllerBase.h"
#include "UObject/UObjectGlobals.h" // for FindObject<>
#include "UObject/Class.h" // for UEnum
#include "InputCoreTypes.h" // for EControllerHand
FName FXRMotionControllerBase::LeftHandSourceId(TEXT("Left"));
FName FXRMotionControllerBase::RightHandSourceId(TEXT("Right"));
FName FXRMotionControllerBase::HMDSourceId(TEXT("HMD"));
namespace XRMotionControllerBase_Impl
{
static const FName LegacySources[] = {
{ FXRMotionControllerBase::LeftHandSourceId, }, // EControllerHand::Left
{ FXRMotionControllerBase::RightHandSourceId }, // EControllerHand::Right
{ TEXT("AnyHand") }, // EControllerHand::AnyHand
{ TEXT("Pad") }, // EControllerHand::Pad
{ TEXT("ExternalCamera") }, // EControllerHand::ExternalCamera
{ TEXT("Gun") }, // EControllerHand::Gun
{ TEXT("Special_1") }, // EControllerHand::Special_1
{ TEXT("Special_2") }, // EControllerHand::Special_2
{ TEXT("Special_3") }, // EControllerHand::Special_3
{ TEXT("Special_4") }, // EControllerHand::Special_4
{ TEXT("Special_5") }, // EControllerHand::Special_5
{ TEXT("Special_6") }, // EControllerHand::Special_6
{ TEXT("Special_7") }, // EControllerHand::Special_7
{ TEXT("Special_8") }, // EControllerHand::Special_8
{ TEXT("Special_9") }, // EControllerHand::Special_9
{ TEXT("Special_10") }, // EControllerHand::Special_10
{ TEXT("Special_11") } // EControllerHand::Special_11
};
}
bool FXRMotionControllerBase::GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource, FRotator& OutOrientation, FVector& OutPosition, float WorldToMetersScale) const
{
bool bSucess = false;
if (ControllerIndex != INDEX_NONE)
{
EControllerHand DeviceHand;
if (GetHandEnumForSourceName(MotionSource, DeviceHand))
{
if (DeviceHand == EControllerHand::AnyHand)
{
bSucess = GetControllerOrientationAndPosition(ControllerIndex, EControllerHand::Left, OutOrientation, OutPosition, WorldToMetersScale);
if (!bSucess)
{
bSucess = GetControllerOrientationAndPosition(ControllerIndex, EControllerHand::Right, OutOrientation, OutPosition, WorldToMetersScale);
}
}
else
{
bSucess = GetControllerOrientationAndPosition(ControllerIndex, DeviceHand, OutOrientation, OutPosition, WorldToMetersScale);
}
}
}
return bSucess;
}
bool FXRMotionControllerBase::GetControllerOrientationAndPositionForTime(const int32 ControllerIndex, const FName MotionSource, FTimespan Time, bool& OutTimeWasUsed, FRotator& OutOrientation, FVector& OutPosition, bool& OutbProvidedLinearVelocity, FVector& OutLinearVelocity, bool& OutbProvidedAngularVelocity, FVector& OutAngularVelocityRadPerSec, bool& OutbProvidedLinearAcceleration, FVector& OutLinearAcceleration, float WorldToMetersScale) const
{
// Default implementation simply ignores the Timespan, no additional accuracy is provided by this call, velocities are not provided.
OutTimeWasUsed = false;
OutbProvidedLinearVelocity = false;
OutbProvidedAngularVelocity = false;
OutbProvidedLinearAcceleration = false;
return GetControllerOrientationAndPosition(ControllerIndex, MotionSource, OutOrientation, OutPosition, WorldToMetersScale);
}
ETrackingStatus FXRMotionControllerBase::GetControllerTrackingStatus(const int32 ControllerIndex, const FName MotionSource) const
{
if (ControllerIndex != INDEX_NONE)
{
EControllerHand DeviceHand;
if (GetHandEnumForSourceName(MotionSource, DeviceHand))
{
if (DeviceHand == EControllerHand::AnyHand)
{
FRotator ThrowawayOrientation;
FVector ThrowawayPosition;
// we've moved explicit handling of the 'AnyHand' source into this class from UMotionControllerComponent,
// to maintain behavior we use the return value of GetControllerOrientationAndPosition() to determine which hand's
// status we should check
if (GetControllerOrientationAndPosition(ControllerIndex, EControllerHand::Left, ThrowawayOrientation, ThrowawayPosition, 100.f))
{
return GetControllerTrackingStatus(ControllerIndex, EControllerHand::Left);
}
return GetControllerTrackingStatus(ControllerIndex, EControllerHand::Right);
}
return GetControllerTrackingStatus(ControllerIndex, DeviceHand);
}
}
return ETrackingStatus::NotTracked;
}
void FXRMotionControllerBase::EnumerateSources(TArray<FMotionControllerSource>& SourcesOut) const
{
const int32 LegaceSourcesCount = UE_ARRAY_COUNT(XRMotionControllerBase_Impl::LegacySources);
for (int32 Index = 0; Index < LegaceSourcesCount; ++Index)
{
SourcesOut.Add(XRMotionControllerBase_Impl::LegacySources[Index]);
}
}
bool FXRMotionControllerBase::GetHandEnumForSourceName(const FName Source, EControllerHand& OutHand)
{
static TMap<FName, EControllerHand> MotionSourceToEControllerHandMap;
if (MotionSourceToEControllerHandMap.Num() == 0)
{
// Motion source names that map to legacy EControllerHand values
MotionSourceToEControllerHandMap.Add(FXRMotionControllerBase::LeftHandSourceId, EControllerHand::Left);
MotionSourceToEControllerHandMap.Add(FXRMotionControllerBase::RightHandSourceId, EControllerHand::Right);
MotionSourceToEControllerHandMap.Add(TEXT("AnyHand"), EControllerHand::AnyHand);
MotionSourceToEControllerHandMap.Add(TEXT("Pad"), EControllerHand::Pad);
MotionSourceToEControllerHandMap.Add(TEXT("ExternalCamera"), EControllerHand::ExternalCamera);
MotionSourceToEControllerHandMap.Add(TEXT("Gun"), EControllerHand::Gun);
MotionSourceToEControllerHandMap.Add(TEXT("Special_1"), EControllerHand::Special_1);
MotionSourceToEControllerHandMap.Add(TEXT("Special_2"), EControllerHand::Special_2);
MotionSourceToEControllerHandMap.Add(TEXT("Special_3"), EControllerHand::Special_3);
MotionSourceToEControllerHandMap.Add(TEXT("Special_4"), EControllerHand::Special_4);
MotionSourceToEControllerHandMap.Add(TEXT("Special_5"), EControllerHand::Special_5);
MotionSourceToEControllerHandMap.Add(TEXT("Special_6"), EControllerHand::Special_6);
MotionSourceToEControllerHandMap.Add(TEXT("Special_7"), EControllerHand::Special_7);
MotionSourceToEControllerHandMap.Add(TEXT("Special_8"), EControllerHand::Special_8);
MotionSourceToEControllerHandMap.Add(TEXT("Special_9"), EControllerHand::Special_9);
MotionSourceToEControllerHandMap.Add(TEXT("Special_10"), EControllerHand::Special_10);
MotionSourceToEControllerHandMap.Add(TEXT("Special_11"), EControllerHand::Special_11);
// EControllerHand enum names mapped to EControllerHand enum values
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Left"), EControllerHand::Left);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Right"), EControllerHand::Right);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::AnyHand"), EControllerHand::AnyHand);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Pad"), EControllerHand::Pad);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::ExternalCamera"), EControllerHand::ExternalCamera);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Gun"), EControllerHand::Gun);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_1"), EControllerHand::Special_1);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_2"), EControllerHand::Special_2);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_3"), EControllerHand::Special_3);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_4"), EControllerHand::Special_4);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_5"), EControllerHand::Special_5);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_6"), EControllerHand::Special_6);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_7"), EControllerHand::Special_7);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_8"), EControllerHand::Special_8);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_9"), EControllerHand::Special_9);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_10"), EControllerHand::Special_10);
MotionSourceToEControllerHandMap.Add(TEXT("EControllerHand::Special_11"), EControllerHand::Special_11);
// Newer source names that can usefully map to legacy EControllerHand values
MotionSourceToEControllerHandMap.Add(TEXT("LeftGrip"), EControllerHand::Left);
MotionSourceToEControllerHandMap.Add(TEXT("RightGrip"), EControllerHand::Right);
MotionSourceToEControllerHandMap.Add(TEXT("LeftAim"), EControllerHand::Left);
MotionSourceToEControllerHandMap.Add(TEXT("RightAim"), EControllerHand::Right);
}
EControllerHand* FoundEnum = MotionSourceToEControllerHandMap.Find(Source);
if (FoundEnum != nullptr)
{
OutHand = *FoundEnum;
return true;
}
else
{
return false;
}
}