Skip to content

Commit

Permalink
Changes to support hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyfreg committed Feb 13, 2021
1 parent a61731d commit 24f6a98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
18 changes: 4 additions & 14 deletions Code/Client/Private/NetImgui_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ void HookEndFrame(ImGuiContext*, ImGuiContextHook* hook)
}
}

void HookShutdown(ImGuiContext*, ImGuiContextHook* hook)
{
Client::ClientInfo& client = *reinterpret_cast<Client::ClientInfo*>(hook->UserData);
client.mhImguiHookShutdown = client.mhImguiHookNewframe = client.mhImguiHookEndframe = 0;
//SF to do handle this properly and on shutdown
}
#endif // NETIMGUI_IMGUI_CALLBACK_ENABLED

//=================================================================================================
Expand All @@ -312,6 +306,8 @@ ClientInfo::ClientInfo()
//=================================================================================================
ClientInfo::~ClientInfo()
{
ContextRemoveHooks();

for( auto& texture : mTextures ){
texture.Set(nullptr);
}
Expand Down Expand Up @@ -364,7 +360,7 @@ void ClientInfo::ContextInitialize()
mpContext = ImGui::GetCurrentContext();

#if NETIMGUI_IMGUI_CALLBACK_ENABLED
ImGuiContextHook hookNewframe, hookEndframe, hookShutdown;
ImGuiContextHook hookNewframe, hookEndframe;

hookNewframe.Type = ImGuiContextHookType_NewFramePre;
hookNewframe.Callback = HookBeginFrame;
Expand All @@ -375,11 +371,6 @@ void ClientInfo::ContextInitialize()
hookEndframe.Callback = HookEndFrame;
hookEndframe.UserData = this;
mhImguiHookEndframe = ImGui::AddContextHook(mpContext, &hookEndframe);

hookShutdown.Type = ImGuiContextHookType_Shutdown;
hookShutdown.Callback = HookShutdown;
hookShutdown.UserData = this;
mhImguiHookShutdown = ImGui::AddContextHook(mpContext, &hookShutdown);
#endif
}

Expand Down Expand Up @@ -457,8 +448,7 @@ void ClientInfo::ContextRemoveHooks()
{
ImGui::RemContextHook(mpContext, mhImguiHookNewframe);
ImGui::RemContextHook(mpContext, mhImguiHookEndframe);
ImGui::RemContextHook(mpContext, mhImguiHookShutdown);
mhImguiHookShutdown = mhImguiHookNewframe = mhImguiHookEndframe = 0;
mhImguiHookNewframe = mhImguiHookNewframe = 0;
}
#endif
}
Expand Down
3 changes: 1 addition & 2 deletions Code/Client/Private/NetImgui_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ struct ClientInfo
bool mbInsideNewEnd = false; // Currently inside NetImgui::NewFrame() or NetImgui::EndFrame() (prevents recusrive hook call)
bool mbValidDrawFrame = false; // If we should forward the drawdata to the server at the end of ImGui::Render()

char PADDING[7];
char PADDING[3];
ImGuiID mhImguiHookNewframe = 0;
ImGuiID mhImguiHookEndframe = 0;
ImGuiID mhImguiHookShutdown = 0;

void TextureProcessPending();
void TextureProcessRemoval();
Expand Down
8 changes: 6 additions & 2 deletions Code/Client/Private/NetImgui_Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "NetImgui_WarningReenable.h"
//=================================================================================================

#define NETIMGUI_IMGUI_CALLBACK_ENABLED ((IMGUI_VERSION_NUM >= 17905) && 0)
#define NETIMGUI_IMGUI_CALLBACK_ENABLED ((IMGUI_VERSION_NUM >= 18000) && 0)

//=================================================================================================
#include "NetImgui_WarningDisable.h"
Expand Down Expand Up @@ -60,7 +60,11 @@ class ScopedValue
: mValueRef(ValueRef)
, mValueRestore(ValueRef)
{
ValueRef = Value;
mValueRef = Value;
}
~ScopedValue()
{
mValueRef = mValueRestore;
}
protected:
TType& mValueRef;
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Sammy Fatnassi (Github: @Sammyfreg)
Copyright (c) 2021 Sammy Fatnassi (Github: @Sammyfreg)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit 24f6a98

Please sign in to comment.