From ee271467d09b8ab4326c579342f720620f139531 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 2 Jun 2013 05:57:51 +0000 Subject: [PATCH] attempt to fix join game out of synch (and added more logging to track further if needed) --- source/glest_game/game/game.cpp | 1 + source/glest_game/type_instances/faction.cpp | 27 ++++++++++---------- source/glest_game/type_instances/unit.cpp | 11 ++++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index cb3ae38e..b7606d43 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5691,6 +5691,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches } bool localEcho = lang.isLanguageLocal(languageList[i]); server->sendTextMessage(szMsg,-1, localEcho,languageList[i]); + sleep(1); haveClientConnectedButNoReady = true; } diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 88de5507..5fceca9a 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -392,20 +392,19 @@ void FactionThread::execute() { if(minorDebugPerformance && (chrono.getMillis() - elapsed2) >= 1) printf("Faction [%d - %s] #2-unit threaded updates on frame: %d for [%d] unit # %d, unitCount = %d, took [%lld] msecs\n",faction->getStartLocationIndex(),faction->getType()->getName().c_str(),currentTriggeredFrameIndex,faction->getUnitPathfindingListCount(),j,unitCount,(long long int)chrono.getMillis() - elapsed2); } -// else { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { -// int updateProgressValue = unit->getUpdateProgress(); -// int speed = unit->getCurrSkill()->getTotalSpeed(unit->getTotalUpgrade()); -// int df = unit->getDiagonalFactor(); -// int hf = unit->getHeightFactor(); -// bool changedActiveCommand = unit->isChangedActiveCommand(); -// -// char szBuf[8096]=""; -// snprintf(szBuf,8096,"unit->needToUpdate() returned: %d updateProgressValue: %d speed: %d changedActiveCommand: %d df: %d hf: %d",update,updateProgressValue,speed,changedActiveCommand,df,hf); -// unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); -// } -// -// } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { + int updateProgressValue = unit->getUpdateProgress(); + int speed = unit->getCurrSkill()->getTotalSpeed(unit->getTotalUpgrade()); + int df = unit->getDiagonalFactor(); + int hf = unit->getHeightFactor(); + bool changedActiveCommand = unit->isChangedActiveCommand(); + + char szBuf[8096]=""; + snprintf(szBuf,8096,"unit->needToUpdate() returned: %d updateProgressValue: %d speed: %d changedActiveCommand: %d df: %d hf: %d",update,updateProgressValue,speed,changedActiveCommand,df,hf); + unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); + } + } } if(minorDebugPerformance && chrono.getMillis() >= 1) printf("Faction [%d - %s] threaded updates on frame: %d for [%d] units took [%lld] msecs\n",faction->getStartLocationIndex(),faction->getType()->getName().c_str(),currentTriggeredFrameIndex,faction->getUnitPathfindingListCount(),(long long int)chrono.getMillis()); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 806a4a98..62a2e47f 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1965,7 +1965,8 @@ int Unit::getHeightFactor() { throw megaglest_runtime_error("targetCell == NULL"); } - int heightDiff= ((unitCell->getHeight() * 100.f) - (targetCell->getHeight() * 100.f)); + int heightDiff= (truncateDecimal(unitCell->getHeight() * 100.f,2) - + truncateDecimal(targetCell->getHeight() * 100.f,2)); heightFactor= clamp(100 + heightDiff / 500, 20, 500); } @@ -4032,8 +4033,8 @@ std::string Unit::toString() const { result += " deadCount = " + intToStr(this->deadCount); result += " progress = " + intToStr(this->progress); result += "\n"; - result += " lastAnimProgress = " + floatToStr(this->lastAnimProgress,16); - result += " animProgress = " + floatToStr(this->animProgress,16); + result += " lastAnimProgress = " + intToStr(this->lastAnimProgress); + result += " animProgress = " + intToStr(this->animProgress); result += " highlight = " + floatToStr(this->highlight,16); result += " progress2 = " + intToStr(this->progress2); result += " kills = " + intToStr(this->kills); @@ -4131,9 +4132,9 @@ void Unit::saveGame(XmlNode *rootNode) { // float progress; //between 0 and 1 unitNode->addAttribute("progress",intToStr(progress), mapTagReplacements); // float lastAnimProgress; //between 0 and 1 - unitNode->addAttribute("lastAnimProgress",floatToStr(lastAnimProgress,16), mapTagReplacements); + unitNode->addAttribute("lastAnimProgress",intToStr(lastAnimProgress), mapTagReplacements); // float animProgress; //between 0 and 1 - unitNode->addAttribute("animProgress",floatToStr(animProgress,16), mapTagReplacements); + unitNode->addAttribute("animProgress",intToStr(animProgress), mapTagReplacements); // float highlight; unitNode->addAttribute("highlight",floatToStr(highlight,16), mapTagReplacements); // int progress2;