Skip to content

Commit

Permalink
Dev (#43)
Browse files Browse the repository at this point in the history
* Bugfix #37

Fix multiple Context Hook callback added to Imgui context, after a reconnect.

* Prevent Server from saving a imgui.ini file

This could conflict with other imgui application in same folder, and the Server doesn't really need any Imgui settings saved

* Fixes for Linux build

-Invalid GPU resource release on Com Thread
-TextureId cast error
-Unneeded Windows specific include

* Fix some textureid cast error on GCC

* Socket 'Force Listen' now optional

Default is unused. Prevents having 2 running NetImgui Servers listening on same port.
Seems like the 'force listen' isn't  needed on Windows/Linux, but can still toggle it on if needed.

* Updated for Dear ImGui 1.89 support

-Small changes done to inputs

* OffsetPointer fix

Possible error for platorm using top bit in 64bits in VirtualAddress space

* Removed 'unused const' warning introduced in VisualStudio 17.4.4

Fix the CI

* Revert to wrongly submitted loader file during last Dear ImGui backend update

* Upgrade DearImgui 1.89.5

* Version 1.9 Release

* Update msbuild_vs2022_dev.yml

updated msbuild setup

* Update msbuild_vs2022_dev.yml

Update to dotnet installed (needed for sharpmake)

* Update msbuild_vs2022_dev.yml

* Update msbuild_vs2022_dev.yml

* Update msbuild_vs2022_dev.yml
  • Loading branch information
sammyfreg committed May 4, 2023
1 parent f2af650 commit 2a0bf69
Show file tree
Hide file tree
Showing 43 changed files with 6,755 additions and 4,328 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/msbuild_vs2022_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ jobs:
- uses: actions/checkout@v3

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v1.1

- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.408'

- name: Generate Solutions
working-directory: ${{env.GITHUB_WORKSPACE}}
run: ./GenerateProject.bat 1
Expand Down
4 changes: 2 additions & 2 deletions Build/GenerateCompatibilityTest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ cls
:: SETTINGS
::-----------------------------------------------------------------------------------
:: List of offical Dear ImGui (from official depot)
set VERSIONS=(v1.71 v1.72 v1.73 v1.74 v1.75 v1.76 v1.77 v1.78 v1.79, v1.80, v1.81, v1.82, v1.83, v1.84, v1.85, v1.86, v1.87, v1.88)
set VERSIONS=(v1.71 v1.72 v1.73 v1.74 v1.75 v1.76 v1.77 v1.78 v1.79, v1.80, v1.81, v1.82, v1.83, v1.84, v1.85, v1.86, v1.87, v1.88, v1.89.1, v1.89.2, v1.89.3, v1.89.4, v1.89.5)

:: List of custom Dear ImGui releases (from own depot)
set EXTRA_VERSIONS=(dock-1-76, dock-1-80)
set EXTRA_VERSIONS=(dock-1-76, dock-1-80, dock-1-89)

:: Output directory
set IMGUI_DIR=%~dp0..\_generated\imgui
Expand Down
66 changes: 46 additions & 20 deletions Code/Client/NetImgui_Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//! @Name : NetImgui
//=================================================================================================
//! @author : Sammy Fatnassi
//! @date : 2022/07/18
//! @version : v1.8.1
//! @date : 2023/05/04
//! @version : v1.9
//! @Details : For integration info : https://github.com/sammyfreg/netImgui/wiki
//=================================================================================================
#define NETIMGUI_VERSION "1.8.1 WIP"
#define NETIMGUI_VERSION_NUM 10801
#define NETIMGUI_VERSION "1.9" // Version Release 1.9
#define NETIMGUI_VERSION_NUM 10900



Expand All @@ -23,7 +23,7 @@
// ImGui.h warnings(s)
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#pragma clang diagnostic ignored "-Wreserved-identifier" // Enuma values using '__' or member starting with '_' in imgui.h
#pragma clang diagnostic ignored "-Wreserved-identifier" // Enum values using '__' or member starting with '_' in imgui.h
// NetImgui_Api.h Warning(s)
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // Not using nullptr in case this file is used in pre C++11
#elif defined(_MSC_VER)
Expand Down Expand Up @@ -69,13 +69,39 @@

#include <stdint.h>

//=================================================================================================
// Default Build settings defines values
// Assign default values when not set in user NetImgui_Config.h
//=================================================================================================

//-------------------------------------------------------------------------------------------------
// Prepended to functions signature, for dll export/import
//-------------------------------------------------------------------------------------------------
#ifndef NETIMGUI_API
#define NETIMGUI_API IMGUI_API // Use same value as defined by Dear ImGui by default
#define NETIMGUI_API IMGUI_API // Use same value as defined by Dear ImGui by default
#endif

//-------------------------------------------------------------------------------------------------
// Enable TCP socket 'reuse port' option when opening it as a 'listener'.
// Note: Can help when unable to open a socket because it wasn't properly released after a crash.
//-------------------------------------------------------------------------------------------------
#ifndef NETIMGUI_FORCE_TCP_LISTEN_BINDING
#define NETIMGUI_FORCE_TCP_LISTEN_BINDING 0 // Doesn't seem to be needed on Window/Linux
#endif

//-------------------------------------------------------------------------------------------------
// Enable Dear ImGui Callbacks support for BeginFrame/Render automatic interception.
// Note: Avoid having to replace ImGui::BeginFrame/ImGui::Render with in library user code, by
// 'NetImgui::NewFrame/NetImgui::EndFrame'. But prevent benefit of skipping frame draw
// when unneeded, that 'NetImgui::NewFrame' can provide.
// For more info, consult 'SampleNewFrame.cpp'.
// Needs Dear ImGui 1.81+
//-------------------------------------------------------------------------------------------------
#ifndef NETIMGUI_IMGUI_CALLBACK_ENABLED
#define NETIMGUI_IMGUI_CALLBACK_ENABLED (IMGUI_VERSION_NUM >= 18100) // Not supported pre Dear ImGui 1.81
#endif


namespace NetImgui
{

Expand Down Expand Up @@ -115,31 +141,31 @@ NETIMGUI_API bool Startup(void);
NETIMGUI_API void Shutdown();

//=================================================================================================
// Try to establish a connection to NetImgui server application.
// Establish a connection between the NetImgui server application and this client.
//
// Can establish connection with netImgui Server application by either reaching it directly
// Can connect with NetImgui Server application by either reaching it directly
// using 'ConnectToApp' or waiting for Server to reach us after Client called 'ConnectFromApp'.
//
// Note: Start a new communication thread using std::Thread by default, but can receive custom
// thread start function instead (Look at ClientExample 'CustomCommunicationThread').
//-------------------------------------------------------------------------------------------------
// clientName : Named that will be displayed on the Server, for this Client
// serverHost : Address of the netImgui Server application (Ex1: 127.0.0.2, Ex2: localhost)
// serverPort : PortID of the netImgui Server application to connect to
// clientName : Client name displayed in the Server's clients list
// serverHost : Address of the NetImgui Server application (Ex1: 127.0.0.2, Ex2: localhost)
// serverPort : PortID of the NetImgui Server application to connect to
// clientPort : PortID this Client should wait for connection from Server application
// threadFunction : User provided function to launch new networking thread.
// Use 'DefaultStartCommunicationThread' by default, relying on 'std::thread'.
// Use 'DefaultStartCommunicationThread' by default (relying on 'std::thread').
//=================================================================================================
NETIMGUI_API bool ConnectToApp(const char* clientName, const char* serverHost, uint32_t serverPort=kDefaultServerPort, ThreadFunctPtr threadFunction=0);
NETIMGUI_API bool ConnectFromApp(const char* clientName, uint32_t clientPort=kDefaultClientPort, ThreadFunctPtr threadFunction=0);

//=================================================================================================
// Request a disconnect from the netImguiApp server
// Request a disconnect from the NetImguiServer application
//=================================================================================================
NETIMGUI_API void Disconnect(void);

//=================================================================================================
// True if connected to netImguiApp server
// True if connected to the NetImguiServer application
//=================================================================================================
NETIMGUI_API bool IsConnected(void);

Expand All @@ -156,13 +182,13 @@ NETIMGUI_API bool IsConnectionPending(void);
NETIMGUI_API bool IsDrawing(void);

//=================================================================================================
// True when Dear ImGui is currently expecting draw commands *sent to remote netImgui app*.
// This means that we are between NewFrame() and EndFrame() of drawing for remote application
// True when we are currently drawinf on the NetImguiServer application
// Means that we are between NewFrame() and EndFrame() of drawing for remote application
//=================================================================================================
NETIMGUI_API bool IsDrawingRemote(void);

//=================================================================================================
// Send an updated texture used by imgui, to netImguiApp server
// Send an updated texture used by imgui, to the NetImguiServer application
// Note: To remove a texture, set pData to nullptr
//=================================================================================================
NETIMGUI_API void SendDataTexture(ImTextureID textureId, void* pData, uint16_t width, uint16_t height, eTexFormat format);
Expand Down Expand Up @@ -210,7 +236,7 @@ NETIMGUI_API void SetCompressionMode(eCompressionMode eMode);
NETIMGUI_API eCompressionMode GetCompressionMode();

//=================================================================================================
// Helper function to quickly create a context duplicate (sames settings/font/styles)
// Helper functions
//=================================================================================================
NETIMGUI_API uint8_t GetTexture_BitsPerPixel (eTexFormat eFormat);
NETIMGUI_API uint32_t GetTexture_BytePerLine (eTexFormat eFormat, uint32_t pixelWidth);
Expand All @@ -219,9 +245,9 @@ NETIMGUI_API uint32_t GetTexture_BytePerImage (eTexFormat eFormat, uint32_t pi

//=================================================================================================
// Optional single include compiling option
// Note: User that do not wish adding the few NetImgui cpp files to their project,
// Note: User wanting to avoid adding the few NetImgui sources files to their project,
// can instead define 'NETIMGUI_IMPLEMENTATION' *once* before including 'NetImgui_Api.h'
// and this will load the required cpp files alongside
// to pull all the needed cpp files alongside for compilation
//=================================================================================================
#if defined(NETIMGUI_IMPLEMENTATION)
#include "Private/NetImgui_Api.cpp"
Expand Down
11 changes: 8 additions & 3 deletions Code/Client/NetImgui_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#endif // NETIMGUI_ENABLED

//=================================================================================================
// Port used by connect the Server and Client together
// Default Ports used to reach the Server or the Client (listen port for incoming connection)
//=================================================================================================
namespace NetImgui
{
Expand Down Expand Up @@ -53,5 +53,10 @@ namespace NetImgui
#define NETIMGUI_POSIX_SOCKETS_ENABLED !(NETIMGUI_WINSOCKET_ENABLED)
#endif

// Disable auto interception of ImGui::NewFrame() / ImGui::Render()
//#define NETIMGUI_IMGUI_CALLBACK_ENABLED 0
//=================================================================================================
// Various build settings define
// Note: for more information, please look in 'NetImgui_Api.h' for description and default values
//=================================================================================================
//#define NETIMGUI_IMGUI_CALLBACK_ENABLED (IMGUI_VERSION_NUM >= 18100) // Not supported pre Dear ImGui 1.81
//#define NETIMGUI_FORCE_TCP_LISTEN_BINDING 0 // Doesn't seem to be needed on Window/Linux
//#define NETIMGUI_API IMGUI_API // Use same value as defined by Dear ImGui by default
32 changes: 22 additions & 10 deletions Code/Client/Private/NetImgui_Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ bool ConnectToApp(const char* clientName, const char* ServerHost, uint32_t serve
while (client.IsActive())
std::this_thread::yield();

client.ContextRestore(); // Restore context setting override, after a disconnect
client.ContextRemoveHooks(); // Remove hooks callback only when completly disconnected

StringCopy(client.mName, (clientName == nullptr || clientName[0] == 0 ? "Unnamed" : clientName));
client.mpSocketPending = Network::Connect(ServerHost, serverPort);
if (client.mpSocketPending.load() != nullptr)
Expand All @@ -70,7 +73,10 @@ bool ConnectFromApp(const char* clientName, uint32_t serverPort, ThreadFunctPtr

while (client.IsActive())
std::this_thread::yield();


client.ContextRestore(); // Restore context setting override, after a disconnect
client.ContextRemoveHooks(); // Remove hooks callback only when completly disconnected

StringCopy(client.mName, (clientName == nullptr || clientName[0] == 0 ? "Unnamed" : clientName));
client.mpSocketPending = Network::ListenStart(serverPort);
if (client.mpSocketPending.load() != nullptr)
Expand Down Expand Up @@ -192,7 +198,7 @@ bool NewFrame(bool bSupportFrameSkip)
// Regular Imgui NewFrame
else
{
// Restore context setting override, after a disconnect
// Restore context setting override, after a disconnect
client.ContextRestore();

// Remove hooks callback only when completly disconnected
Expand Down Expand Up @@ -489,7 +495,7 @@ uint32_t GetTexture_BytePerImage(eTexFormat eFormat, uint32_t pixelWidth, uint32
//Note: If adding support to BC compression format, have to take into account 4x4 size alignement
}

static inline void AddKeyEvent(const Client::ClientInfo& client, const CmdInput* pCmdInput, CmdInput::NetImguiKeys netimguiKey, ImGuiKey_ imguiKey)
static inline void AddKeyEvent(const Client::ClientInfo& client, const CmdInput* pCmdInput, CmdInput::NetImguiKeys netimguiKey, ImGuiKey imguiKey)
{
uint32_t valIndex = netimguiKey/64;
uint64_t valMask = 0x0000000000000001ull << (netimguiKey%64);
Expand All @@ -504,7 +510,7 @@ static inline void AddKeyEvent(const Client::ClientInfo& client, const CmdInput*
#endif
}

static inline void AddKeyAnalogEvent(const Client::ClientInfo& client, const CmdInput* pCmdInput, CmdInput::NetImguiKeys netimguiKey, ImGuiKey_ imguiKey)
static inline void AddKeyAnalogEvent(const Client::ClientInfo& client, const CmdInput* pCmdInput, CmdInput::NetImguiKeys netimguiKey, ImGuiKey imguiKey)
{
uint32_t valIndex = netimguiKey/64;
uint64_t valMask = 0x0000000000000001ull << (netimguiKey%64);
Expand Down Expand Up @@ -567,10 +573,13 @@ bool ProcessInputData(Client::ClientInfo& client)
AddInputDown(ImGuiKey_Y) // for text edit CTRL+Y: redo
AddInputDown(ImGuiKey_Z) // for text edit CTRL+Z: undo
#else
#if IMGUI_VERSION_NUM < 18837
#define ImGuiKey ImGuiKey_
#endif
// At the moment All Dear Imgui version share the same ImGuiKey_ enum (with a 512 value offset),
// but could change in the future, so convert from our own enum version, to Dear ImGui.
#define AddInputDown(KEYNAME) AddKeyEvent(client, pCmdInput, CmdInput::KEYNAME, ImGuiKey_::KEYNAME);
#define AddAnalogInputDown(KEYNAME) AddKeyAnalogEvent(client, pCmdInput, CmdInput::KEYNAME, ImGuiKey_::KEYNAME);
#define AddInputDown(KEYNAME) AddKeyEvent(client, pCmdInput, CmdInput::KEYNAME, ImGuiKey::KEYNAME);
#define AddAnalogInputDown(KEYNAME) AddKeyAnalogEvent(client, pCmdInput, CmdInput::KEYNAME, ImGuiKey::KEYNAME);
AddInputDown(ImGuiKey_Tab)
AddInputDown(ImGuiKey_LeftArrow)
AddInputDown(ImGuiKey_RightArrow)
Expand Down Expand Up @@ -650,6 +659,9 @@ bool ProcessInputData(Client::ClientInfo& client)

#undef AddInputDown
#undef AddAnalogInputDown
#if IMGUI_VERSION_NUM < 18837
#undef ImGuiKey
#endif

// Mouse
io.AddMouseWheelEvent(wheelX, wheelY);
Expand All @@ -661,10 +673,10 @@ bool ProcessInputData(Client::ClientInfo& client)
}
}
#endif
io.KeyShift = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ModShift);
io.KeyCtrl = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ModCtrl);
io.KeyAlt = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ModAlt);
io.KeySuper = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ModSuper);
io.KeyShift = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ReservedForModShift);
io.KeyCtrl = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ReservedForModCtrl);
io.KeyAlt = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ReservedForModAlt);
io.KeySuper = pCmdInput->IsKeyDown(CmdInput::NetImguiKeys::ImGuiKey_ReservedForModSuper);

size_t keyCount(1);
uint16_t character;
Expand Down
3 changes: 2 additions & 1 deletion Code/Client/Private/NetImgui_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ ClientInfo::ClientInfo()
: mpSocketPending(nullptr)
, mpSocketComs(nullptr)
, mpSocketListen(nullptr)
, mFontTextureID(TextureCastHelper(uint64_t(0u)))
, mFontTextureID(TextureCastFromUInt(uint64_t(0u)))
, mTexturesPendingSent(0)
, mTexturesPendingCreated(0)
{
Expand Down Expand Up @@ -382,6 +382,7 @@ void ClientInfo::ContextInitialize()

#if NETIMGUI_IMGUI_CALLBACK_ENABLED
ImGuiContextHook hookNewframe, hookEndframe;
ContextRemoveHooks();
hookNewframe.HookId = 0;
hookNewframe.Type = ImGuiContextHookType_NewFramePre;
hookNewframe.Callback = HookBeginFrame;
Expand Down
Loading

0 comments on commit 2a0bf69

Please sign in to comment.