Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dedicated server support #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/ImGui/Private/ImGuiContextProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
41 changes: 29 additions & 12 deletions Source/ImGui/Private/ImGuiModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <Modules/ModuleManager.h>

#include <imgui.h>

#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;
Expand Down Expand Up @@ -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
}
}
}

Expand Down