Revert "Testing ugly Windows workaround"

This reverts commit 44df9ccab4.
This commit is contained in:
mathusummut
2019-01-27 19:48:26 +01:00
parent e5c53270a9
commit d2539dc784
8 changed files with 38 additions and 66 deletions

View File

@@ -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",

View File

@@ -426,58 +426,37 @@ namespace Game {
}
}
void ClientInterface::popBack() {
shared_ptr<NetworkCommand> 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<NetworkCommand>(*networkMessageCommandList.getCommand(i)));
cachedPendingCommands[networkMessageCommandList.getFrameCount()].push_back(*networkMessageCommandList.getCommand(i));
if (cachedPendingCommandCRCs.find(networkMessageCommandList.getFrameCount()) == cachedPendingCommandCRCs.end()) {
cachedPendingCommandCRCs[networkMessageCommandList.getFrameCount()].reserve(GameConstants::maxPlayers);

View File

@@ -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) {

View File

@@ -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<NetworkCommand> ptr = make_shared<NetworkCommand>(*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);
}
}
// =====================================================

View File

@@ -385,7 +385,7 @@ namespace Game {
class GameNetworkInterface : public NetworkInterface {
protected:
typedef vector<shared_ptr<NetworkCommand>> Commands;
typedef vector<NetworkCommand> 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<NetworkCommand> getPendingCommand(int i) {
return pendingCommands[i];
NetworkCommand* getPendingCommand(int i) {
return &pendingCommands[i];
}
void clearPendingCommands() {
pendingCommands.clear();

View File

@@ -1642,12 +1642,6 @@ namespace Game {
}
}
bool NetworkMessageCommandList::addCommand(const shared_ptr<NetworkCommand> 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++;

View File

@@ -543,7 +543,6 @@ namespace Game {
}
bool addCommand(const NetworkCommand* networkCommand);
bool addCommand(const shared_ptr<NetworkCommand> networkCommand);
void clear() {
data.header.commandCount = 0;

View File

@@ -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();