From d2539dc784a553bb9cf5aff786e9372f300898c9 Mon Sep 17 00:00:00 2001 From: mathusummut Date: Sun, 27 Jan 2019 19:48:26 +0100 Subject: [PATCH] Revert "Testing ugly Windows workaround" This reverts commit 44df9ccab43ac9ae55de51a8cbdc5b4699e9b156. --- source/glest_game/game/commander.cpp | 3 +- .../glest_game/network/client_interface.cpp | 69 +++++++------------ source/glest_game/network/client_interface.h | 4 +- .../glest_game/network/network_interface.cpp | 13 ++-- source/glest_game/network/network_interface.h | 6 +- source/glest_game/network/network_message.cpp | 6 -- source/glest_game/network/network_message.h | 1 - .../glest_game/network/server_interface.cpp | 2 +- 8 files changed, 38 insertions(+), 66 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index bf20c0402..07478b2d4 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -820,7 +820,8 @@ namespace Game { for (int i = 0; i < gameNetworkInterface->getPendingCommandCount(); ++i) { - giveNetworkCommand((gameNetworkInterface->getPendingCommand(i)).get()); + giveNetworkCommand(gameNetworkInterface-> + getPendingCommand(i)); } if (SystemFlags::VERBOSE_MODE_ENABLED) printf("END process: %d network commands in frame: %d\n", diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 997544963..2a6b84a72 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -426,58 +426,37 @@ namespace Game { } } - void ClientInterface::popBack() { - shared_ptr temp = requestedCommands.back(); - requestedCommands.pop_back(); - } - - void ClientInterface::popLastCommand() { - //TODO: THIS IS AN INSANELY UGLY WORKAROUND!! FIX IT!! -#ifdef _WIN32 - __try { - popBack(); - } __except (EXCEPTION_CONTINUE_EXECUTION) { - } -#else - requestedCommands.pop_back(); -#endif - } - - void ClientInterface::sendAllCommands(NetworkMessageCommandList& networkMessageCommandList) { - //send as many commands as we can - while (requestedCommands.empty() == false) { - if (networkMessageCommandList.addCommand(requestedCommands.back())) { - popLastCommand(); - } else { - break; - } - } - } - void ClientInterface::update() { bool wasConnected = this->isConnected(); + if (gotIntro == true && + wasConnected == false) { + string playerNameStr = getHumanPlayerName(); + + Lang &lang = Lang::getInstance(); + + char szBuf1[8096] = ""; + string statusTextFormat = lang.getString("PlayerDisconnected"); + snprintf(szBuf1, 8096, statusTextFormat.c_str(), playerNameStr.c_str()); + + DisplayErrorMessage(szBuf1); + //setQuit(true); + return; + } + try { - if (gotIntro == true && - wasConnected == false) { - string playerNameStr = getHumanPlayerName(); - - Lang &lang = Lang::getInstance(); - - char szBuf1[8096] = ""; - string statusTextFormat = lang.getString("PlayerDisconnected"); - snprintf(szBuf1, 8096, statusTextFormat.c_str(), playerNameStr.c_str()); - - DisplayErrorMessage(szBuf1); - //setQuit(true); - return; - } - NetworkMessageCommandList networkMessageCommandList(currentFrameCount); for (int index = 0; index < GameConstants::maxPlayers; ++index) { networkMessageCommandList.setNetworkPlayerFactionCRC(index, this->getNetworkPlayerFactionCRC(index)); } - sendAllCommands(networkMessageCommandList); + //send as many commands as we can + while (requestedCommands.empty() == false) { + if (networkMessageCommandList.addCommand(&requestedCommands.back())) { + requestedCommands.pop_back(); + } else { + break; + } + } double lastSendElapsed = difftime((long int) time(NULL), lastNetworkCommandListSendTime); @@ -1174,7 +1153,7 @@ namespace Game { //printf("Network cmd type: %d [%d] frame: %d\n",networkMessageCommandList.getCommand(i)->getNetworkCommandType(),nctPauseResume,networkMessageCommandList.getFrameCount()); //} - cachedPendingCommands[networkMessageCommandList.getFrameCount()].push_back(make_shared(*networkMessageCommandList.getCommand(i))); + cachedPendingCommands[networkMessageCommandList.getFrameCount()].push_back(*networkMessageCommandList.getCommand(i)); if (cachedPendingCommandCRCs.find(networkMessageCommandList.getFrameCount()) == cachedPendingCommandCRCs.end()) { cachedPendingCommandCRCs[networkMessageCommandList.getFrameCount()].reserve(GameConstants::maxPlayers); diff --git a/source/glest_game/network/client_interface.h b/source/glest_game/network/client_interface.h index 43f4bfcbb..6d68b81c4 100644 --- a/source/glest_game/network/client_interface.h +++ b/source/glest_game/network/client_interface.h @@ -220,9 +220,7 @@ namespace Game { void setGameSettings(GameSettings *serverGameSettings); void broadcastGameSetup(const GameSettings *gameSettings); void broadcastGameStart(const GameSettings *gameSettings); - void sendAllCommands(NetworkMessageCommandList& networkMessageCommandList); - void popBack(); - void popLastCommand(); + void updateNetworkFrame(); virtual void saveGame(XmlNode *rootNode) { diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 2063633be..b341118c4 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -410,12 +410,13 @@ namespace Game { void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, bool insertAtStart) { assert(networkCommand != NULL); Mutex *mutex = getServerSynchAccessor(); - MutexSafeWrapper safeMutex(mutex, string(__FILE__) + "_" + intToStr(__LINE__)); - shared_ptr ptr = make_shared(*networkCommand); - if (insertAtStart == false) - requestedCommands.push_back(ptr); - else - requestedCommands.insert(requestedCommands.begin(), ptr); + if (insertAtStart == false) { + MutexSafeWrapper safeMutex(mutex, string(__FILE__) + "_" + intToStr(__LINE__)); + requestedCommands.push_back(*networkCommand); + } else { + MutexSafeWrapper safeMutex(mutex, string(__FILE__) + "_" + intToStr(__LINE__)); + requestedCommands.insert(requestedCommands.begin(), *networkCommand); + } } // ===================================================== diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index 3e93f9fe4..49d8d979c 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -385,7 +385,7 @@ namespace Game { class GameNetworkInterface : public NetworkInterface { protected: - typedef vector> Commands; + typedef vector Commands; Commands requestedCommands; //commands requested by the user Commands pendingCommands; //commands ready to be given @@ -421,8 +421,8 @@ namespace Game { int getPendingCommandCount() const { return (int) pendingCommands.size(); } - shared_ptr getPendingCommand(int i) { - return pendingCommands[i]; + NetworkCommand* getPendingCommand(int i) { + return &pendingCommands[i]; } void clearPendingCommands() { pendingCommands.clear(); diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index e4a5fae5d..d82e6af1e 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -1642,12 +1642,6 @@ namespace Game { } } - bool NetworkMessageCommandList::addCommand(const shared_ptr networkCommand) { - data.commands.push_back(*networkCommand); - data.header.commandCount++; - return true; - } - bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand) { data.commands.push_back(*networkCommand); data.header.commandCount++; diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index ed4c7e840..49a2b0088 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -543,7 +543,6 @@ namespace Game { } bool addCommand(const NetworkCommand* networkCommand); - bool addCommand(const shared_ptr networkCommand); void clear() { data.header.commandCount = 0; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index c2ff11d59..5d64e5bd1 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1664,7 +1664,7 @@ namespace Game { while (requestedCommands.empty() == false) { // First add the command to the broadcast list (for all clients) - if (networkMessageCommandList.addCommand(requestedCommands.back())) { + if (networkMessageCommandList.addCommand(&requestedCommands.back())) { // Add the command to the local server command list pendingCommands.push_back(requestedCommands.back()); requestedCommands.pop_back();