diff --git a/Code/Sample/Common/main.cpp b/Code/Sample/Common/main.cpp index da2997c..d1d5831 100644 --- a/Code/Sample/Common/main.cpp +++ b/Code/Sample/Common/main.cpp @@ -237,8 +237,10 @@ int main(int, char**) } //========================================================================================= - g_pSwapChain->Present(1, 0); // Present with vsync - //g_pSwapChain->Present(0, 0); // Present without vsync + // Present + HRESULT hr = g_pSwapChain->Present(1, 0); // Present with vsync + //HRESULT hr = g_pSwapChain->Present(0, 0); // Present without vsync + g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED); } // Cleanup diff --git a/Code/Sample/SampleDualUI/SampleDualUI.cpp b/Code/Sample/SampleDualUI/SampleDualUI.cpp index bd11f8f..6ed6820 100644 --- a/Code/Sample/SampleDualUI/SampleDualUI.cpp +++ b/Code/Sample/SampleDualUI/SampleDualUI.cpp @@ -81,9 +81,14 @@ bool SampleDualUI::Startup() //================================================================================================= void SampleDualUI::Shutdown() { + ImGui::SetCurrentContext(mpContextExtra); + ImGui::GetIO().BackendRendererUserData = nullptr; + ImGui::GetIO().BackendPlatformUserData = nullptr; + ImGui::GetIO().BackendLanguageUserData = nullptr; ImGui::DestroyContext(mpContextExtra); + ImGui::SetCurrentContext(mpContextMain); - mpContextMain = nullptr; + mpContextMain = nullptr; mpContextExtra = nullptr; Base::Shutdown(); } diff --git a/Code/ServerApp/Source/NetImguiServer_Config.h b/Code/ServerApp/Source/NetImguiServer_Config.h index 0712246..5b1575e 100644 --- a/Code/ServerApp/Source/NetImguiServer_Config.h +++ b/Code/ServerApp/Source/NetImguiServer_Config.h @@ -38,6 +38,7 @@ class Client enum class eStatus : uint8_t { Disconnected, // No connection detected on client + Connecting, // This server is connecting to client Connected, // This server is connect to client Available, // Client already taken, but this server can take over ErrorBusy, // Client already taken @@ -62,6 +63,8 @@ class Client inline bool IsReadOnly()const { return mReadOnly; }; inline bool IsTransient()const { return mConfigType == eConfigType::Transient; }; inline bool IsConnected()const { return mStatus == eStatus::Connected; } + inline bool IsAvailable()const { return mStatus != eStatus::Connected && mStatus != eStatus::Connecting;} + // Add/Edit/Remove config static void SetConfig(const Client& config); //!< Add or replace a client configuration info static void DelConfig(uint32_t configID); //!< Remove a client configuration diff --git a/Code/ServerApp/Source/NetImguiServer_Network.cpp b/Code/ServerApp/Source/NetImguiServer_Network.cpp index d82a0dd..c1e9cbf 100644 --- a/Code/ServerApp/Source/NetImguiServer_Network.cpp +++ b/Code/ServerApp/Source/NetImguiServer_Network.cpp @@ -251,7 +251,7 @@ bool Communications_InitializeClient(NetImgui::Internal::Network::SocketInfo* pC { bool bAvailable = (cmdVersionRcv.mFlags & static_cast(NetImgui::Internal::CmdVersion::eFlags::IsUnavailable)) == 0; NetImguiServer::Config::Client::SetProperty_Status(pClient->mClientConfigID, bAvailable ? NetImguiServer::Config::Client::eStatus::Available - : NetImguiServer::Config::Client::eStatus::ErrorBusy); + : NetImguiServer::Config::Client::eStatus::ErrorBusy); return false; } @@ -272,6 +272,7 @@ bool Communications_InitializeClient(NetImgui::Internal::Network::SocketInfo* pC return true; } } + NetImguiServer::Config::Client::SetProperty_Status(pClient->mClientConfigID, NetImguiServer::Config::Client::eStatus::Disconnected); return false; } @@ -285,9 +286,12 @@ void NetworkConnectionNew(NetImgui::Internal::Network::SocketInfo* pClientSocket if (pNewClient == nullptr) { zErrorMsg = "Too many connection on server already"; } - - if (zErrorMsg == nullptr && !gbShutdown && Communications_InitializeClient(pClientSocket, pNewClient, ConnectForce) == false) { - zErrorMsg = "Initialization failed. Wrong communication version?"; + else + { + NetImguiServer::Config::Client::SetProperty_Status(pNewClient->mClientConfigID, NetImguiServer::Config::Client::eStatus::Connecting); + if (zErrorMsg == nullptr && !gbShutdown && Communications_InitializeClient(pClientSocket, pNewClient, ConnectForce) == false) { + zErrorMsg = "Initialization failed. Wrong communication version?"; + } } if (zErrorMsg == nullptr && !gbShutdown){ @@ -296,6 +300,7 @@ void NetworkConnectionNew(NetImgui::Internal::Network::SocketInfo* pClientSocket } else{ NetImgui::Internal::Network::Disconnect(pClientSocket); + NetImguiServer::Config::Client::SetProperty_Status(pNewClient->mClientConfigID, NetImguiServer::Config::Client::eStatus::Disconnected); if (!gbShutdown) { if (pNewClient){ pNewClient->mbIsFree = true; @@ -376,7 +381,7 @@ void NetworkConnectRequest_Send() if( NetImguiServer::Config::Client::GetConfigByIndex(configIdx, clientConfig) ) { ConnectForce = clientConfig.mConnectForce; - if( (clientConfig.mConnectAuto || clientConfig.mConnectRequest || clientConfig.mConnectForce) && !clientConfig.IsConnected() && clientConfig.mHostPort != NetImguiServer::Config::Server::sPort) + if( (clientConfig.mConnectAuto || clientConfig.mConnectRequest || clientConfig.mConnectForce) && clientConfig.IsAvailable() && clientConfig.mHostPort != NetImguiServer::Config::Server::sPort) { NetImguiServer::Config::Client::SetProperty_ConnectRequest(clientConfig.mRuntimeID, false, false); // Reset the Connection request, we are processing it NetImguiServer::Config::Client::SetProperty_Status(clientConfig.mRuntimeID, NetImguiServer::Config::Client::eStatus::Disconnected); @@ -387,7 +392,7 @@ void NetworkConnectRequest_Send() // Connection successful, find an available client slot if( pClientSocket ) - { + { uint32_t freeIndex = RemoteClient::Client::GetFreeIndex(); if( freeIndex != RemoteClient::Client::kInvalidClient ) { @@ -402,6 +407,11 @@ void NetworkConnectRequest_Send() NetImguiServer::App::HAL_GetSocketInfo(pClientSocket, newClient.mConnectHost, sizeof(newClient.mConnectHost), newClient.mConnectPort); NetworkConnectionNew(pClientSocket, &newClient, ConnectForce); } + else + { + NetImgui::Internal::Network::Disconnect(pClientSocket); + NetImguiServer::Config::Client::SetProperty_Status(clientConfigID, NetImguiServer::Config::Client::eStatus::Disconnected); + } } std::this_thread::sleep_for(std::chrono::milliseconds(500)); // There's already a wait time in Connect attempt, so no need to sleep for too long here }