From 11471243ea0b8a2f56a16d274339d2c073c99f3a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 24 Sep 2013 19:35:35 +0000 Subject: [PATCH] - implement ability to toggle off verbose and normal network crc mode via ini entries: EnableNetworkGameSynchChecks EnableNetworkGameSynchMonitor --- source/glest_game/game/game.cpp | 52 ++++++++++--------- source/glest_game/game/game_settings.h | 18 ++++--- source/glest_game/global/core_data.cpp | 12 +++++ .../menu/menu_state_custom_game.cpp | 12 +++++ 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index c7101860..514c10d0 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1571,6 +1571,13 @@ void Game::init(bool initForPreviewOnly) { printf("New game has started...\n"); } + if(isFlagType1BitEnabled(gameSettings.getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { + printf("*Note: Monitoring Network CRC VERBOSE synchronization...\n"); + } + else if(isFlagType1BitEnabled(gameSettings.getFlagTypes1(),ft1_network_synch_checks) == true) { + printf("*Note: Monitoring Network CRC NORMAL synchronization...\n"); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== START GAME ==== getCurrentPixelByteCount() = %llu\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount()); if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"=============================================\n"); @@ -1702,20 +1709,19 @@ void Game::processNetworkSynchChecksIfRequired() { Faction *faction = world.getFaction(index); netIntf->setNetworkPlayerFactionCRC(index,faction->getCRC().getSum()); - if(settings != NULL && (settings->getFlagTypes1() & ft1_network_synch_checks) == ft1_network_synch_checks) { - faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); - } - else if(world.getFrameCount() % 20 == 0) { - faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); + if(settings != NULL) { + if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { + faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); + } + else if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true && + world.getFrameCount() % 20 == 0) { + faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); + } } } else { netIntf->setNetworkPlayerFactionCRC(index,0); } - - //if(world.getFrameCount() % 40 == 0) { - // printf("Frame #: %d Faction: %d CRC: %u\n",world.getFrameCount(),index,netIntf->getNetworkPlayerFactionCRC(index)); - //} } } } @@ -2985,7 +2991,9 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo if(aiInterfaces[i] == NULL && server->isClientConnected(faction->getStartLocationIndex()) == false) { - DumpCRCWorldLogIfRequired("_faction_" + intToStr(i)); + if(faction->getPersonalityType() != fpt_Observer) { + DumpCRCWorldLogIfRequired("_faction_" + intToStr(i)); + } faction->setFactionDisconnectHandled(true); @@ -4919,7 +4927,9 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) { printf("Check save world CRC to log. isNetworkGame = %d fileSuffix = %s\n",isNetworkGame,fileSuffix.c_str()); GameSettings *settings = world.getGameSettingsPtr(); - //if(settings != NULL && (settings->getFlagTypes1() & ft1_network_synch_checks) == ft1_network_synch_checks) { + if(settings != NULL && + (isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true || + isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true)) { string debugCRCWorldLogFile = Config::getInstance().getString("DebugCRCWorldLogFile","debugCRCWorld.log"); debugCRCWorldLogFile += fileSuffix; @@ -4936,13 +4946,13 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) { printf("Save to log debugCRCWorldLogFile = %s\n",debugCRCWorldLogFile.c_str()); - #if defined(WIN32) && !defined(__MINGW32__) + #if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(debugCRCWorldLogFile).c_str(), L"w"); std::ofstream logFile(fp); - #else + #else std::ofstream logFile; logFile.open(debugCRCWorldLogFile.c_str(), ios_base::out | ios_base::trunc); - #endif + #endif logFile << "World CRC debug information:" << std::endl; logFile << "============================" << std::endl; logFile << "Maximum framecount: " << world.getFaction(0)->getCRC_DetailsForWorldFrameCount() << std::endl; @@ -4961,13 +4971,13 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) { } logFile.close(); - #if defined(WIN32) && !defined(__MINGW32__) + #if defined(WIN32) && !defined(__MINGW32__) if(fp) { fclose(fp); } - #endif + #endif - //} + } } } @@ -4979,14 +4989,6 @@ void Game::exitGameState(Program *program, Stats &endStats) { //printf("game = %p\n",game); if(game) { -// NetworkManager &networkManager= NetworkManager::getInstance(); -// NetworkRole role = networkManager.getNetworkRole(); -// string suffix = "_client"; -// if(role == nrServer) { -// suffix = "_server"; -// } -// game->DumpCRCWorldLogIfRequired(suffix); - game->setEndGameTeamWinnersAndLosers(); game->endGame(); } diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 234791ef..de5cd273 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -61,14 +61,20 @@ public: // ===================================================== enum FlagTypes1 { - ft1_none = 0x00, - ft1_show_map_resources = 0x01, - ft1_allow_team_switching = 0x02, - ft1_allow_in_game_joining = 0x04, - ft1_network_synch_checks = 0x08 - //ft1_xx = 0x10, + ft1_none = 0x00, + ft1_show_map_resources = 0x01, + ft1_allow_team_switching = 0x02, + ft1_allow_in_game_joining = 0x04, + ft1_network_synch_checks_verbose = 0x08, + ft1_network_synch_checks = 0x10 + //ft1_xx = 0x20, + //ft1_xx = 0x40, }; +static bool isFlagType1BitEnabled(uint32 flagValue,FlagTypes1 type) { + return ((flagValue & type) == type); +} + enum NetworkPlayerStatusType { npst_None = 0, npst_PickSettings = 1, diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index fe825079..032724df 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1070,6 +1070,18 @@ bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *game if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) { //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + valueFlags1 |= ft1_network_synch_checks_verbose; + gameSettings->setFlagTypes1(valueFlags1); + + } + else { + valueFlags1 &= ~ft1_network_synch_checks_verbose; + gameSettings->setFlagTypes1(valueFlags1); + + } + if(Config::getInstance().getBool("EnableNetworkGameSynchMonitor","true") == true) { + //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + valueFlags1 |= ft1_network_synch_checks; gameSettings->setFlagTypes1(valueFlags1); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 6046630d..66814c57 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -3185,6 +3185,18 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) { //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + valueFlags1 |= ft1_network_synch_checks_verbose; + gameSettings->setFlagTypes1(valueFlags1); + + } + else { + valueFlags1 &= ~ft1_network_synch_checks_verbose; + gameSettings->setFlagTypes1(valueFlags1); + + } + if(Config::getInstance().getBool("EnableNetworkGameSynchMonitor","true") == true) { + //printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n"); + valueFlags1 |= ft1_network_synch_checks; gameSettings->setFlagTypes1(valueFlags1);