diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index da3df81d..b5e7464b 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -390,8 +390,12 @@ void FactionThread::execute() { if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { float updateProgressValue = unit->getUpdateProgress(); int speed = unit->getCurrSkill()->getTotalSpeed(unit->getTotalUpgrade()); + float df = unit->getDiagonalFactor(); + float hf = unit->getHeightFactor(); + bool changedActiveCommand = unit->isChangedActiveCommand(); + char szBuf[8096]=""; - snprintf(szBuf,8096,"unit->needToUpdate() returned: %d updateProgressValue: %f speed = %d",update,updateProgressValue,speed); + snprintf(szBuf,8096,"unit->needToUpdate() returned: %d updateProgressValue: %f speed: %d changedActiveCommand: %d df: %f hf: %f",update,updateProgressValue,speed,changedActiveCommand,df,hf); unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 2ef0f1ab..07ca4019 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1859,9 +1859,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target return commandType; } - float Unit::getUpdateProgress() { - //assert(progress <= 1.f); if(progress > 1.f) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: progress > 1.f, progress = [%f]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,progress); @@ -1884,29 +1882,8 @@ float Unit::getUpdateProgress() { } //speed modifier - float diagonalFactor= 1.f; - float heightFactor= 1.f; - if(currSkill->getClass() == scMove) { - //if moving in diagonal move slower - Vec2i dest= pos - lastPos; - if(abs(dest.x) + abs(dest.y) == 2) { - diagonalFactor = 0.71f; - } - - //if moving to an higher cell move slower else move faster - Cell *unitCell = map->getCell(pos); - if(unitCell == NULL) { - throw megaglest_runtime_error("unitCell == NULL"); - } - - Cell *targetCell = map->getCell(targetPos); - if(targetCell == NULL) { - throw megaglest_runtime_error("targetCell == NULL"); - } - - float heightDiff= unitCell->getHeight() - targetCell->getHeight(); - heightFactor= clamp(1.f + heightDiff / 5.f, 0.2f, 5.f); - } + float diagonalFactor = getDiagonalFactor(); + float heightFactor = getHeightFactor(); //update progresses const Game *game = Renderer::getInstance().getGame(); @@ -1917,10 +1894,8 @@ float Unit::getUpdateProgress() { throw megaglest_runtime_error("game->getWorld() == NULL"); } - //float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); - //float newProgress = progress; - //newProgress += (speed * diagonalFactor * heightFactor) / speedDenominator; - newProgress = getUpdatedProgress(progress, game->getWorld()->getUpdateFps(this->getFactionIndex()), + newProgress = getUpdatedProgress(progress, + game->getWorld()->getUpdateFps(this->getFactionIndex()), speed, diagonalFactor, heightFactor); } @@ -1938,18 +1913,55 @@ bool Unit::needToUpdate() { return return_value; } +float Unit::getDiagonalFactor() { + //speed modifier + float diagonalFactor= 1.f; + if(currSkill->getClass() == scMove) { + //if moving in diagonal move slower + Vec2i dest= pos - lastPos; + if(abs(dest.x) + abs(dest.y) == 2) { + diagonalFactor = 0.71f; + diagonalFactor = truncateDecimal(diagonalFactor); + } + } + + return diagonalFactor; +} + +float Unit::getHeightFactor() { + //speed modifier + float heightFactor= 1.f; + if(currSkill->getClass() == scMove) { + //if moving to an higher cell move slower else move faster + Cell *unitCell = map->getCell(pos); + if(unitCell == NULL) { + throw megaglest_runtime_error("unitCell == NULL"); + } + + Cell *targetCell = map->getCell(targetPos); + if(targetCell == NULL) { + throw megaglest_runtime_error("targetCell == NULL"); + } + + float heightDiff= unitCell->getHeight() - targetCell->getHeight(); + heightFactor= clamp(1.f + heightDiff / 5.f, 0.2f, 5.f); + heightFactor = truncateDecimal(heightFactor); + } + + return heightFactor; +} + +float Unit::getSpeedDenominator(int updateFPS) { + float speedDenominator = truncateDecimal(speedDivider * updateFPS); + return speedDenominator; +} float Unit::getUpdatedProgress(float currentProgress, int updateFPS, int speed, float diagonalFactor, float heightFactor) { - truncateDecimal(diagonalFactor); - truncateDecimal(heightFactor); - - float speedDenominator = (speedDivider * updateFPS); - truncateDecimal(speedDenominator); - float newProgress = currentProgress; - truncateDecimal(newProgress); - newProgress += ((speed * diagonalFactor * heightFactor) / speedDenominator); - truncateDecimal(newProgress); + float speedDenominator = getSpeedDenominator(updateFPS); + float newProgress = truncateDecimal(currentProgress); + newProgress += truncateDecimal + ((speed * diagonalFactor * heightFactor) / speedDenominator); return newProgress; } @@ -1976,19 +1988,8 @@ bool Unit::update() { } //speed modifier - float diagonalFactor = 1.f; - float heightFactor = 1.f; - if(currSkill->getClass() == scMove) { - //if moving in diagonal move slower - Vec2i dest = pos - lastPos; - if(abs(dest.x) + abs(dest.y) == 2) { - diagonalFactor = 0.71f; - } - - //if moving to an higher cell move slower else move faster - float heightDiff = map->getCell(pos)->getHeight() - map->getCell(targetPos)->getHeight(); - heightFactor = clamp(1.f + heightDiff / 5.f, 0.2f, 5.f); - } + float diagonalFactor = getDiagonalFactor(); + float heightFactor = getHeightFactor(); //update progresses lastAnimProgress= animProgress; @@ -2019,7 +2020,8 @@ bool Unit::update() { } } else { - float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); + //float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); + float speedDenominator = getSpeedDenominator(game->getWorld()->getUpdateFps(this->getFactionIndex())); animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator; } //update target diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 86efb65c..89ad023a 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -725,6 +725,10 @@ public: std::string toString() const; bool needToUpdate(); float getUpdateProgress(); + float getDiagonalFactor(); + float getHeightFactor(); + float getSpeedDenominator(int updateFPS); + bool isChangedActiveCommand() const { return changedActiveCommand; } bool isLastStuckFrameWithinCurrentFrameTolerance(); inline uint32 getLastStuckFrame() const { return lastStuckFrame; } @@ -771,6 +775,7 @@ private: void morphAttackBoosts(Unit *unit); float getUpdatedProgress(float currentProgress, int updateFPS, int speed, float diagonalFactor, float heightFactor); + void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false); };