Cleaned unused delegates code:

- Removed code allowing to register game delegates outside of the delegates container.
- Removed unused multi-context delegate that is not part of the container.
This commit is contained in:
Sebastian 2020-06-28 18:13:29 +01:00
parent 5d5bd8a284
commit c7d36a802b
5 changed files with 10 additions and 73 deletions

View File

@ -152,7 +152,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetEditorContextData()
if (UNLIKELY(!Data)) if (UNLIKELY(!Data))
{ {
Data = &Contexts.Emplace(Utilities::EDITOR_CONTEXT_INDEX, FContextData{ GetEditorContextName(), Utilities::EDITOR_CONTEXT_INDEX, OnDrawMultiContext, FontAtlas, DPIScale, -1 }); Data = &Contexts.Emplace(Utilities::EDITOR_CONTEXT_INDEX, FContextData{ GetEditorContextName(), Utilities::EDITOR_CONTEXT_INDEX, FontAtlas, DPIScale, -1 });
OnContextProxyCreated.Broadcast(Utilities::EDITOR_CONTEXT_INDEX, *Data->ContextProxy); OnContextProxyCreated.Broadcast(Utilities::EDITOR_CONTEXT_INDEX, *Data->ContextProxy);
} }
@ -167,7 +167,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetStandaloneWorldCont
if (UNLIKELY(!Data)) if (UNLIKELY(!Data))
{ {
Data = &Contexts.Emplace(Utilities::STANDALONE_GAME_CONTEXT_INDEX, FContextData{ GetWorldContextName(), Utilities::STANDALONE_GAME_CONTEXT_INDEX, OnDrawMultiContext, FontAtlas, DPIScale }); Data = &Contexts.Emplace(Utilities::STANDALONE_GAME_CONTEXT_INDEX, FContextData{ GetWorldContextName(), Utilities::STANDALONE_GAME_CONTEXT_INDEX, FontAtlas, DPIScale });
OnContextProxyCreated.Broadcast(Utilities::STANDALONE_GAME_CONTEXT_INDEX, *Data->ContextProxy); OnContextProxyCreated.Broadcast(Utilities::STANDALONE_GAME_CONTEXT_INDEX, *Data->ContextProxy);
} }
@ -209,7 +209,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetWorldContextData(co
#if WITH_EDITOR #if WITH_EDITOR
if (UNLIKELY(!Data)) if (UNLIKELY(!Data))
{ {
Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, OnDrawMultiContext, FontAtlas, DPIScale, WorldContext->PIEInstance }); Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, FontAtlas, DPIScale, WorldContext->PIEInstance });
OnContextProxyCreated.Broadcast(Index, *Data->ContextProxy); OnContextProxyCreated.Broadcast(Index, *Data->ContextProxy);
} }
else else
@ -220,7 +220,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetWorldContextData(co
#else #else
if (UNLIKELY(!Data)) if (UNLIKELY(!Data))
{ {
Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, OnDrawMultiContext, FontAtlas, DPIScale }); Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, FontAtlas, DPIScale });
OnContextProxyCreated.Broadcast(Index, *Data->ContextProxy); OnContextProxyCreated.Broadcast(Index, *Data->ContextProxy);
} }
#endif #endif

View File

@ -58,10 +58,6 @@ public:
return Data ? Data->ContextProxy.Get() : nullptr; return Data ? Data->ContextProxy.Get() : nullptr;
} }
// Delegate called for all contexts in manager, right after calling context specific draw event. Allows listeners
// draw the same content to multiple contexts.
FSimpleMulticastDelegate OnDrawMultiContext;
// Delegate called when a new context proxy is created. // Delegate called when a new context proxy is created.
FContextProxyCreatedDelegate OnContextProxyCreated; FContextProxyCreatedDelegate OnContextProxyCreated;
@ -74,9 +70,9 @@ private:
struct FContextData struct FContextData
{ {
FContextData(const FString& ContextName, int32 ContextIndex, FSimpleMulticastDelegate& SharedDrawEvent, ImFontAtlas& FontAtlas, float DPIScale, int32 InPIEInstance = -1) FContextData(const FString& ContextName, int32 ContextIndex, ImFontAtlas& FontAtlas, float DPIScale, int32 InPIEInstance = -1)
: PIEInstance(InPIEInstance) : PIEInstance(InPIEInstance)
, ContextProxy(new FImGuiContextProxy(ContextName, ContextIndex, &SharedDrawEvent, &FontAtlas, DPIScale)) , ContextProxy(new FImGuiContextProxy(ContextName, ContextIndex, &FontAtlas, DPIScale))
{ {
} }

View File

@ -73,10 +73,9 @@ namespace
}; };
} }
FImGuiContextProxy::FImGuiContextProxy(const FString& InName, int32 InContextIndex, FSimpleMulticastDelegate* InSharedDrawEvent, ImFontAtlas* InFontAtlas, float InDPIScale) FImGuiContextProxy::FImGuiContextProxy(const FString& InName, int32 InContextIndex, ImFontAtlas* InFontAtlas, float InDPIScale)
: Name(InName) : Name(InName)
, ContextIndex(InContextIndex) , ContextIndex(InContextIndex)
, SharedDrawEvent(InSharedDrawEvent)
, IniFilename(TCHAR_TO_ANSI(*GetIniFile(InName))) , IniFilename(TCHAR_TO_ANSI(*GetIniFile(InName)))
{ {
// Create context. // Create context.
@ -295,11 +294,6 @@ void FImGuiContextProxy::BroadcastWorldDebug()
void FImGuiContextProxy::BroadcastMultiContextDebug() void FImGuiContextProxy::BroadcastMultiContextDebug()
{ {
if (SharedDrawEvent && SharedDrawEvent->IsBound())
{
SharedDrawEvent->Broadcast();
}
FSimpleMulticastDelegate& MultiContextDebugEvent = FImGuiDelegatesContainer::Get().OnMultiContextDebug(); FSimpleMulticastDelegate& MultiContextDebugEvent = FImGuiDelegatesContainer::Get().OnMultiContextDebug();
if (MultiContextDebugEvent.IsBound()) if (MultiContextDebugEvent.IsBound())
{ {

View File

@ -19,7 +19,7 @@ class FImGuiContextProxy
{ {
public: public:
FImGuiContextProxy(const FString& Name, int32 InContextIndex, FSimpleMulticastDelegate* InSharedDrawEvent, ImFontAtlas* InFontAtlas, float InDPIScale); FImGuiContextProxy(const FString& Name, int32 InContextIndex, ImFontAtlas* InFontAtlas, float InDPIScale);
~FImGuiContextProxy(); ~FImGuiContextProxy();
FImGuiContextProxy(const FImGuiContextProxy&) = delete; FImGuiContextProxy(const FImGuiContextProxy&) = delete;
@ -68,7 +68,8 @@ public:
// Cursor type desired by this context (updated once per frame during context update). // Cursor type desired by this context (updated once per frame during context update).
EMouseCursor::Type GetMouseCursor() const { return MouseCursor; } EMouseCursor::Type GetMouseCursor() const { return MouseCursor; }
// Delegate called right before ending the frame to allows listeners draw their controls. // Internal draw event used to draw module's examples and debug widgets. Unlike the delegates container, it is not
// passed when the module is reloaded, so all objects that are unloaded with the module should register here.
FSimpleMulticastDelegate& OnDraw() { return DrawEvent; } FSimpleMulticastDelegate& OnDraw() { return DrawEvent; }
// Call early debug events to allow listeners draw their debug widgets. // Call early debug events to allow listeners draw their debug widgets.
@ -116,7 +117,6 @@ private:
uint32 LastFrameNumber = 0; uint32 LastFrameNumber = 0;
FSimpleMulticastDelegate DrawEvent; FSimpleMulticastDelegate DrawEvent;
FSimpleMulticastDelegate* SharedDrawEvent = nullptr;
std::string IniFilename; std::string IniFilename;
}; };

View File

@ -15,8 +15,6 @@
#include <Interfaces/IPluginManager.h> #include <Interfaces/IPluginManager.h>
#define IMGUI_REDIRECT_OBSOLETE_DELEGATES 1
#define LOCTEXT_NAMESPACE "FImGuiModule" #define LOCTEXT_NAMESPACE "FImGuiModule"
@ -44,62 +42,24 @@ static FImGuiEditor* ImGuiEditor = nullptr;
#if WITH_EDITOR #if WITH_EDITOR
FImGuiDelegateHandle FImGuiModule::AddEditorImGuiDelegate(const FImGuiDelegate& Delegate) FImGuiDelegateHandle FImGuiModule::AddEditorImGuiDelegate(const FImGuiDelegate& Delegate)
{ {
#if IMGUI_REDIRECT_OBSOLETE_DELEGATES
return { FImGuiDelegatesContainer::Get().OnWorldDebug(Utilities::EDITOR_CONTEXT_INDEX).Add(Delegate), return { FImGuiDelegatesContainer::Get().OnWorldDebug(Utilities::EDITOR_CONTEXT_INDEX).Add(Delegate),
EDelegateCategory::Default, Utilities::EDITOR_CONTEXT_INDEX }; EDelegateCategory::Default, Utilities::EDITOR_CONTEXT_INDEX };
#else
checkf(ImGuiModuleManager, TEXT("Null pointer to internal module implementation. Is module available?"));
return { ImGuiModuleManager->GetContextManager().GetEditorContextProxy().OnDraw().Add(Delegate),
EDelegateCategory::Default, Utilities::EDITOR_CONTEXT_INDEX };
#endif // IMGUI_REDIRECT_OBSOLETE_DELEGATES
} }
#endif #endif
FImGuiDelegateHandle FImGuiModule::AddWorldImGuiDelegate(const FImGuiDelegate& Delegate) FImGuiDelegateHandle FImGuiModule::AddWorldImGuiDelegate(const FImGuiDelegate& Delegate)
{ {
#if IMGUI_REDIRECT_OBSOLETE_DELEGATES
const int32 ContextIndex = Utilities::GetWorldContextIndex((UWorld*)GWorld); const int32 ContextIndex = Utilities::GetWorldContextIndex((UWorld*)GWorld);
return { FImGuiDelegatesContainer::Get().OnWorldDebug(ContextIndex).Add(Delegate), EDelegateCategory::Default, ContextIndex }; return { FImGuiDelegatesContainer::Get().OnWorldDebug(ContextIndex).Add(Delegate), EDelegateCategory::Default, ContextIndex };
#else
checkf(ImGuiModuleManager, TEXT("Null pointer to internal module implementation. Is module available?"));
#if WITH_EDITOR
checkf(GEngine, TEXT("Null GEngine. AddWorldImGuiDelegate should be only called with GEngine initialized."));
const FWorldContext* WorldContext = Utilities::GetWorldContext(GEngine->GameViewport);
if (!WorldContext)
{
WorldContext = Utilities::GetWorldContextFromNetMode(ENetMode::NM_DedicatedServer);
}
checkf(WorldContext, TEXT("Couldn't find current world. AddWorldImGuiDelegate should be only called from a valid world."));
int32 Index;
FImGuiContextProxy& Proxy = ImGuiModuleManager->GetContextManager().GetWorldContextProxy(*WorldContext->World(), Index);
#else
const int32 Index = Utilities::STANDALONE_GAME_CONTEXT_INDEX;
FImGuiContextProxy& Proxy = ImGuiModuleManager->GetContextManager().GetWorldContextProxy();
#endif
return{ Proxy.OnDraw().Add(Delegate), EDelegateCategory::Default, Index };
#endif // IMGUI_REDIRECT_OBSOLETE_DELEGATES
} }
FImGuiDelegateHandle FImGuiModule::AddMultiContextImGuiDelegate(const FImGuiDelegate& Delegate) FImGuiDelegateHandle FImGuiModule::AddMultiContextImGuiDelegate(const FImGuiDelegate& Delegate)
{ {
#if IMGUI_REDIRECT_OBSOLETE_DELEGATES
return { FImGuiDelegatesContainer::Get().OnMultiContextDebug().Add(Delegate), EDelegateCategory::MultiContext }; return { FImGuiDelegatesContainer::Get().OnMultiContextDebug().Add(Delegate), EDelegateCategory::MultiContext };
#else
checkf(ImGuiModuleManager, TEXT("Null pointer to internal module implementation. Is module available?"));
return { ImGuiModuleManager->GetContextManager().OnDrawMultiContext.Add(Delegate), EDelegateCategory::MultiContext };
#endif
} }
void FImGuiModule::RemoveImGuiDelegate(const FImGuiDelegateHandle& Handle) void FImGuiModule::RemoveImGuiDelegate(const FImGuiDelegateHandle& Handle)
{ {
#if IMGUI_REDIRECT_OBSOLETE_DELEGATES
if (Handle.Category == EDelegateCategory::MultiContext) if (Handle.Category == EDelegateCategory::MultiContext)
{ {
FImGuiDelegatesContainer::Get().OnMultiContextDebug().Remove(Handle.Handle); FImGuiDelegatesContainer::Get().OnMultiContextDebug().Remove(Handle.Handle);
@ -108,19 +68,6 @@ void FImGuiModule::RemoveImGuiDelegate(const FImGuiDelegateHandle& Handle)
{ {
FImGuiDelegatesContainer::Get().OnWorldDebug(Handle.Index).Remove(Handle.Handle); FImGuiDelegatesContainer::Get().OnWorldDebug(Handle.Index).Remove(Handle.Handle);
} }
#else
if (ImGuiModuleManager)
{
if (Handle.Category == EDelegateCategory::MultiContext)
{
ImGuiModuleManager->GetContextManager().OnDrawMultiContext.Remove(Handle.Handle);
}
else if (auto* Proxy = ImGuiModuleManager->GetContextManager().GetContextProxy(Handle.Index))
{
Proxy->OnDraw().Remove(Handle.Handle);
}
}
#endif
} }
#endif // IMGUI_WITH_OBSOLETE_DELEGATES #endif // IMGUI_WITH_OBSOLETE_DELEGATES