UnrealImGui/Source/ImGui/Private/Utilities/WorldContextIndex.h
Sebastian 1a6aa98f51 Added support for session reloading and updated contexts and widgets management:
- Added to ImGui Context Proxy a name that is mapped to ini file set in ImGui context.
- ImGui Context Manager generates unique context names from world type and context index.
- Refactored ImGui Context Manager to have a cleaner separation between editor and non-editor bits.
- Fixed context update rules in ImGui Context Manager.
- Changed widgets management in ImGui Module Manager to allow automatic garbage collection after viewports are closed and manual removal when module is shutting down.
- ImGui Widgets are in full control of communication with context proxies.
- Added basic world context utilities.
- Refactored world context index utilities and replaced ambiguous 'default context index' with 'editor' and 'game' ones.
2017-09-27 21:16:54 +01:00

55 lines
1.8 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#pragma once
#include "Utilities/WorldContext.h"
// Utilities mapping worlds to indices that we use to identify ImGui contexts.
// Editor and standalone games have context index 0 while PIE worlds have indices starting from 1 for server and 2+ for
// clients.
namespace Utilities
{
// Invalid context index for parameters that cannot be resolved to a valid world.
static constexpr int32 INVALID_CONTEXT_INDEX = -1;
// Standalone context index.
static constexpr int32 STANDALONE_GAME_CONTEXT_INDEX = 0;
#if WITH_EDITOR
// Editor context index.
static constexpr int32 EDITOR_CONTEXT_INDEX = 0;
template<typename T>
FORCEINLINE int32 GetWorldContextIndex(const T& Obj)
{
const FWorldContext* WorldContext = GetWorldContext(Obj);
return WorldContext ? GetWorldContextIndex(*WorldContext) : INVALID_CONTEXT_INDEX;
}
FORCEINLINE int32 GetWorldContextIndex(const FWorldContext& WorldContext)
{
// In standalone game (WorldType = Game) we have only one context with index 0 (see GAME_CONTEXT_INDEX).
// In editor, we keep 0 for editor and use PIEInstance to index worlds. In simulation or standalone single-PIE
// sessions PIEInstance is 0, but since there is only one world we can change it without causing any conflicts.
// In single-PIE with dedicated server or multi-PIE sessions worlds have PIEInstance starting from 1 for server
// and 2+ for clients, what maps directly to our index.
return WorldContext.WorldType == EWorldType::PIE ? FMath::Max(WorldContext.PIEInstance, 1) : STANDALONE_GAME_CONTEXT_INDEX;
}
#else
template<typename T>
constexpr int32 GetWorldContextIndex(const T&)
{
// The only option is standalone game with one context.
return STANDALONE_GAME_CONTEXT_INDEX;
}
#endif // #if WITH_EDITOR
}