UnrealImGui/Source/ImGui/Private/ImGuiDelegatesContainer.cpp
Sebastian a76f4bc451 Improved hot-reload stability and support for reloading after recompiling outside of the editor:
- Hot-reloading from inside of the editor and after recompiling from the outside should be equally supported and work together.
- Improved robustness of the delegates redirections. There should be no lost delegates when reloading (either after in-editor or outside recompilation).
- Refactored code to use the same redirection template for context and delegates container.
2020-07-31 10:24:53 +01:00

62 lines
1.8 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#include "ImGuiDelegatesContainer.h"
#include "ImGuiModule.h"
#include "Utilities/RedirectingHandle.h"
#include "Utilities/WorldContextIndex.h"
// Redirecting handle which will automatically bind to another one, if a different instance of the module is loaded.
struct FImGuiDelegatesContainerHandle : Utilities::TRedirectingHandle<FImGuiDelegatesContainer>
{
FImGuiDelegatesContainerHandle(FImGuiDelegatesContainer& InDefaultContainer)
: Utilities::TRedirectingHandle<FImGuiDelegatesContainer>(InDefaultContainer)
{
if (FImGuiModule* Module = FModuleManager::GetModulePtr<FImGuiModule>("ImGui"))
{
SetParent(&Module->GetDelegatesContainerHandle());
}
}
};
static FImGuiDelegatesContainer DelegatesContainer;
static FImGuiDelegatesContainerHandle DelegatesHandle(DelegatesContainer);
FImGuiDelegatesContainer& FImGuiDelegatesContainer::Get()
{
return GetHandle().Get();
}
FImGuiDelegatesContainerHandle& FImGuiDelegatesContainer::GetHandle()
{
return DelegatesHandle;
}
void FImGuiDelegatesContainer::MoveContainer(FImGuiDelegatesContainerHandle& OtherContainerHandle)
{
// Only move data if pointer points to default instance, otherwise our data has already been moved and we only
// keep pointer to a more recent version.
if (GetHandle().IsDefault())
{
OtherContainerHandle.Get() = MoveTemp(GetHandle().Get());
GetHandle().Get().Clear();
}
// Update pointer to the most recent version.
GetHandle().SetParent(&OtherContainerHandle);
}
int32 FImGuiDelegatesContainer::GetContextIndex(UWorld* World)
{
return Utilities::GetWorldContextIndex(*World);
}
void FImGuiDelegatesContainer::Clear()
{
WorldEarlyDebugDelegates.Empty();
WorldDebugDelegates.Empty();
MultiContextEarlyDebugDelegate.Clear();
MultiContextDebugDelegate.Clear();
}