2017-08-28 19:29:07 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
#include "Utilities/WorldContext.h"
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Utilities mapping worlds to indices that we use to identify ImGui contexts.
|
|
|
|
|
|
|
|
namespace Utilities
|
|
|
|
{
|
|
|
|
// Invalid context index for parameters that cannot be resolved to a valid world.
|
2020-09-15 19:48:35 +00:00
|
|
|
static constexpr int32 INVALID_CONTEXT_INDEX = -10;
|
2017-08-28 19:29:07 +00:00
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
// Standalone context index.
|
2020-09-15 19:48:35 +00:00
|
|
|
static constexpr int32 STANDALONE_GAME_CONTEXT_INDEX = -2;
|
2017-09-27 20:16:54 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
#if WITH_EDITOR
|
|
|
|
|
2020-09-15 19:48:35 +00:00
|
|
|
// Editor context index. We are lacking flexibility here, so we might need to change it somehow.
|
|
|
|
static constexpr int32 EDITOR_CONTEXT_INDEX = -1;
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
FORCEINLINE int32 GetWorldContextIndex(const FWorldContext& WorldContext)
|
|
|
|
{
|
2017-10-28 21:25:44 +00:00
|
|
|
switch (WorldContext.WorldType)
|
|
|
|
{
|
|
|
|
case EWorldType::PIE:
|
2020-09-15 19:48:35 +00:00
|
|
|
return WorldContext.PIEInstance;
|
2017-10-28 21:25:44 +00:00
|
|
|
case EWorldType::Game:
|
|
|
|
return STANDALONE_GAME_CONTEXT_INDEX;
|
|
|
|
case EWorldType::Editor:
|
|
|
|
return EDITOR_CONTEXT_INDEX;
|
|
|
|
default:
|
|
|
|
return INVALID_CONTEXT_INDEX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 13:33:38 +00:00
|
|
|
template<typename T>
|
|
|
|
FORCEINLINE int32 GetWorldContextIndex(const T& Obj)
|
|
|
|
{
|
|
|
|
const FWorldContext* WorldContext = GetWorldContext(Obj);
|
|
|
|
return WorldContext ? GetWorldContextIndex(*WorldContext) : INVALID_CONTEXT_INDEX;
|
|
|
|
}
|
|
|
|
|
2019-03-11 19:19:32 +00:00
|
|
|
FORCEINLINE int32 GetWorldContextIndex(const UWorld& World)
|
2017-10-28 21:25:44 +00:00
|
|
|
{
|
|
|
|
return (World.WorldType == EWorldType::Editor) ? EDITOR_CONTEXT_INDEX : GetWorldContextIndex(World.GetGameInstance());
|
2017-08-28 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 19:19:11 +00:00
|
|
|
FORCEINLINE int32 GetWorldContextIndex(const UWorld* World)
|
|
|
|
{
|
|
|
|
return World ? GetWorldContextIndex(*World) : INVALID_CONTEXT_INDEX;
|
|
|
|
}
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
constexpr int32 GetWorldContextIndex(const T&)
|
|
|
|
{
|
|
|
|
// The only option is standalone game with one context.
|
2017-09-27 20:16:54 +00:00
|
|
|
return STANDALONE_GAME_CONTEXT_INDEX;
|
2017-08-28 19:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #if WITH_EDITOR
|
|
|
|
}
|