From f7d1262b535a6553221583625335aa27a6f92d89 Mon Sep 17 00:00:00 2001 From: Titouan Deslandes Date: Mon, 23 Jan 2023 14:26:13 -0500 Subject: [PATCH] Added dedicated server support --- Source/ImGui/Private/ImGuiContextProxy.cpp | 4 +- Source/ImGui/Private/ImGuiModuleManager.cpp | 41 +++++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Source/ImGui/Private/ImGuiContextProxy.cpp b/Source/ImGui/Private/ImGuiContextProxy.cpp index a51d3c7a..6a8cfeea 100644 --- a/Source/ImGui/Private/ImGuiContextProxy.cpp +++ b/Source/ImGui/Private/ImGuiContextProxy.cpp @@ -172,9 +172,9 @@ void FImGuiContextProxy::DrawDebug() void FImGuiContextProxy::Tick(float DeltaSeconds) { // Making sure that we tick only once per frame. - if (LastFrameNumber < GFrameNumber) + if (LastFrameNumber < GFrameCounter) { - LastFrameNumber = GFrameNumber; + LastFrameNumber = GFrameCounter; SetAsCurrent(); diff --git a/Source/ImGui/Private/ImGuiModuleManager.cpp b/Source/ImGui/Private/ImGuiModuleManager.cpp index 63df139d..037fa857 100644 --- a/Source/ImGui/Private/ImGuiModuleManager.cpp +++ b/Source/ImGui/Private/ImGuiModuleManager.cpp @@ -9,7 +9,7 @@ #include #include - +#include "NetImgui_Api.h" // High enough z-order guarantees that ImGui output is rendered on top of the game UI. constexpr int32 IMGUI_WIDGET_Z_ORDER = 10000; @@ -76,21 +76,38 @@ FImGuiModuleManager::~FImGuiModuleManager() void FImGuiModuleManager::LoadTextures() { - checkf(FSlateApplication::IsInitialized(), TEXT("Slate should be initialized before we can create textures.")); - - if (!bTexturesLoaded) + checkf(FSlateApplication::IsInitialized() || IsRunningDedicatedServer(), TEXT("Slate should be initialized before we can create textures.")); + +if (!bTexturesLoaded) { - bTexturesLoaded = true; - - TextureManager.InitializeErrorTexture(FColor::Magenta); + if (FSlateApplication::IsInitialized()) + { + bTexturesLoaded = true; + TextureManager.InitializeErrorTexture(FColor::Magenta); - // Create an empty texture at index 0. We will use it for ImGui outputs with null texture id. - TextureManager.CreatePlainTexture(PlainTextureName, 2, 2, FColor::White); + // Create an empty texture at index 0. We will use it for ImGui outputs with null texture id. + TextureManager.CreatePlainTexture(PlainTextureName, 2, 2, FColor::White); - // Register for atlas built events, so we can rebuild textures. - ContextManager.OnFontAtlasBuilt.AddRaw(this, &FImGuiModuleManager::BuildFontAtlasTexture); + // Register for atlas built events, so we can rebuild textures. + ContextManager.OnFontAtlasBuilt.AddRaw(this, &FImGuiModuleManager::BuildFontAtlasTexture); - BuildFontAtlasTexture(); + BuildFontAtlasTexture(); + } + else if (IsRunningDedicatedServer()) + { +#if NETIMGUI_ENABLED + // On dedicated server we cannot use slate so manually build the font and create the texture for NetImgui + bTexturesLoaded = true; + ImGuiIO& Io = ImGui::GetIO(); + Io.Fonts->AddFontDefault(); + Io.Fonts->Build(); + + unsigned char* Pixels; + int Width, Height, Bpp; + Io.Fonts->GetTexDataAsAlpha8(&Pixels, &Width, &Height, &Bpp); + NetImgui::SendDataTexture(0, Pixels, Width, Height, NetImgui::eTexFormat::kTexFmtA8); +#endif //NETIMGUI_ENABLED + } } }