migrate the static getworld to sgengineutils
This commit is contained in:
@@ -35,15 +35,9 @@
|
||||
|
||||
#include "SGTracking/SGGloveTracker.h"
|
||||
|
||||
#if WITH_EDITOR
|
||||
#include "Editor.h"
|
||||
#endif /* WITH_EDITOR */
|
||||
#include "Engine/Engine.h"
|
||||
#include "Engine/TimerHandle.h"
|
||||
#include "Engine/World.h"
|
||||
#if WITH_EDITOR
|
||||
#include "Subsystems/UnrealEditorSubsystem.h"
|
||||
#endif /* WITH_EDITOR */
|
||||
#include "TimerManager.h"
|
||||
|
||||
#include "SGBackend/SGBackend.h"
|
||||
@@ -52,6 +46,7 @@
|
||||
#include "SGLog/SGLog.h"
|
||||
#include "SGSettings/SGSettings.h"
|
||||
#include "SGSettings/SGTrackingSettings.h"
|
||||
#include "SGUtils/SGEngineUtils.h"
|
||||
|
||||
struct USGGloveTracker::FImpl
|
||||
{
|
||||
@@ -59,8 +54,6 @@ struct USGGloveTracker::FImpl
|
||||
* Static methods
|
||||
************************/
|
||||
|
||||
static UWorld* GetWorld();
|
||||
|
||||
FORCEINLINE static float GetGloveConnectivityCheckInterval()
|
||||
{
|
||||
const USGSettings* Settings{USGSettings::GetInstance()};
|
||||
@@ -101,90 +94,9 @@ struct USGGloveTracker::FImpl
|
||||
void UpdateGloves() const;
|
||||
};
|
||||
|
||||
UWorld* USGGloveTracker::FImpl::GetWorld()
|
||||
{
|
||||
UWorld* World{nullptr};
|
||||
|
||||
#if WITH_EDITOR
|
||||
if (GIsEditor)
|
||||
{
|
||||
if (IsValid(GEditor))
|
||||
{
|
||||
const bool bIsPIE = GPlayInEditorID != -1;
|
||||
if (!bIsPIE)
|
||||
{
|
||||
const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(1)};
|
||||
if (WorldContext)
|
||||
{
|
||||
World = WorldContext->World();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(GPlayInEditorID)};
|
||||
if (WorldContext)
|
||||
{
|
||||
World = WorldContext->World();
|
||||
}
|
||||
}
|
||||
|
||||
/// NOTE
|
||||
// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
|
||||
// "You are not on the main thread."
|
||||
// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid
|
||||
// EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
|
||||
// The Editor is currently in a play mode.
|
||||
if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld))
|
||||
{
|
||||
UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()};
|
||||
if (IsValid(UnrealEditorSubsystem))
|
||||
{
|
||||
/// NOTE
|
||||
// This is exactly UnrealEditorSubsystem->GetEditorWorld() without all the annoying warnings that
|
||||
// pollutes the logs. It's safe since we've already done all the checks.
|
||||
World = GEditor->GetEditorWorldContext(false).World();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsValid(World) && IsValid(GEngine))
|
||||
{
|
||||
const UGameViewportClient* Viewport{GEngine->GameViewport};
|
||||
if (IsValid(Viewport))
|
||||
{
|
||||
World = Viewport->GetWorld();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsValid(GEngine))
|
||||
{
|
||||
World = GEngine->GetCurrentPlayWorld(nullptr);
|
||||
}
|
||||
}
|
||||
#else /* WITH_EDITOR */
|
||||
if (IsValid(GEngine))
|
||||
{
|
||||
World = GEngine->GetCurrentPlayWorld(nullptr);
|
||||
}
|
||||
#endif /* WITH_EDITOR */
|
||||
|
||||
if (!IsValid(World) && IsValid(GEngine))
|
||||
{
|
||||
UEngineSubsystem* EngineSubsystem{GEngine->GetEngineSubsystem<UEngineSubsystem>()};
|
||||
if (IsValid(EngineSubsystem))
|
||||
{
|
||||
World = EngineSubsystem->GetWorld();
|
||||
}
|
||||
}
|
||||
|
||||
return World;
|
||||
}
|
||||
|
||||
USGGloveTracker* USGGloveTracker::GetInstance()
|
||||
{
|
||||
UWorld* World{FImpl::GetWorld()};
|
||||
UWorld* World{FSGEngineUtils::GetWorld()};
|
||||
USGGloveTracker* Instance{IsValid(World) ? World->GetSubsystem<USGGloveTracker>() : nullptr};
|
||||
return Instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user