attempt to see if this fixes out of synch
This commit is contained in:
parent
a0b87ba7eb
commit
29155d31c1
|
@ -390,8 +390,12 @@ void FactionThread::execute() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
|
||||||
float updateProgressValue = unit->getUpdateProgress();
|
float updateProgressValue = unit->getUpdateProgress();
|
||||||
int speed = unit->getCurrSkill()->getTotalSpeed(unit->getTotalUpgrade());
|
int speed = unit->getCurrSkill()->getTotalSpeed(unit->getTotalUpgrade());
|
||||||
|
float df = unit->getDiagonalFactor();
|
||||||
|
float hf = unit->getHeightFactor();
|
||||||
|
bool changedActiveCommand = unit->isChangedActiveCommand();
|
||||||
|
|
||||||
char szBuf[8096]="";
|
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);
|
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1859,9 +1859,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target
|
||||||
return commandType;
|
return commandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float Unit::getUpdateProgress() {
|
float Unit::getUpdateProgress() {
|
||||||
//assert(progress <= 1.f);
|
|
||||||
if(progress > 1.f) {
|
if(progress > 1.f) {
|
||||||
char szBuf[8096]="";
|
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);
|
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
|
//speed modifier
|
||||||
float diagonalFactor= 1.f;
|
float diagonalFactor = getDiagonalFactor();
|
||||||
float heightFactor= 1.f;
|
float heightFactor = getHeightFactor();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//update progresses
|
//update progresses
|
||||||
const Game *game = Renderer::getInstance().getGame();
|
const Game *game = Renderer::getInstance().getGame();
|
||||||
|
@ -1917,10 +1894,8 @@ float Unit::getUpdateProgress() {
|
||||||
throw megaglest_runtime_error("game->getWorld() == NULL");
|
throw megaglest_runtime_error("game->getWorld() == NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
//float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
newProgress = getUpdatedProgress(progress,
|
||||||
//float newProgress = progress;
|
game->getWorld()->getUpdateFps(this->getFactionIndex()),
|
||||||
//newProgress += (speed * diagonalFactor * heightFactor) / speedDenominator;
|
|
||||||
newProgress = getUpdatedProgress(progress, game->getWorld()->getUpdateFps(this->getFactionIndex()),
|
|
||||||
speed, diagonalFactor, heightFactor);
|
speed, diagonalFactor, heightFactor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1938,18 +1913,55 @@ bool Unit::needToUpdate() {
|
||||||
return return_value;
|
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<float>(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<float>(heightFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return heightFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Unit::getSpeedDenominator(int updateFPS) {
|
||||||
|
float speedDenominator = truncateDecimal<float>(speedDivider * updateFPS);
|
||||||
|
return speedDenominator;
|
||||||
|
}
|
||||||
float Unit::getUpdatedProgress(float currentProgress, int updateFPS, int speed,
|
float Unit::getUpdatedProgress(float currentProgress, int updateFPS, int speed,
|
||||||
float diagonalFactor, float heightFactor) {
|
float diagonalFactor, float heightFactor) {
|
||||||
|
|
||||||
truncateDecimal<float>(diagonalFactor);
|
float speedDenominator = getSpeedDenominator(updateFPS);
|
||||||
truncateDecimal<float>(heightFactor);
|
float newProgress = truncateDecimal<float>(currentProgress);
|
||||||
|
newProgress += truncateDecimal<float>
|
||||||
float speedDenominator = (speedDivider * updateFPS);
|
((speed * diagonalFactor * heightFactor) / speedDenominator);
|
||||||
truncateDecimal<float>(speedDenominator);
|
|
||||||
float newProgress = currentProgress;
|
|
||||||
truncateDecimal<float>(newProgress);
|
|
||||||
newProgress += ((speed * diagonalFactor * heightFactor) / speedDenominator);
|
|
||||||
truncateDecimal<float>(newProgress);
|
|
||||||
return newProgress;
|
return newProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1976,19 +1988,8 @@ bool Unit::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//speed modifier
|
//speed modifier
|
||||||
float diagonalFactor = 1.f;
|
float diagonalFactor = getDiagonalFactor();
|
||||||
float heightFactor = 1.f;
|
float heightFactor = getHeightFactor();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//update progresses
|
//update progresses
|
||||||
lastAnimProgress= animProgress;
|
lastAnimProgress= animProgress;
|
||||||
|
@ -2019,7 +2020,8 @@ bool Unit::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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;
|
animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator;
|
||||||
}
|
}
|
||||||
//update target
|
//update target
|
||||||
|
|
|
@ -725,6 +725,10 @@ public:
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
bool needToUpdate();
|
bool needToUpdate();
|
||||||
float getUpdateProgress();
|
float getUpdateProgress();
|
||||||
|
float getDiagonalFactor();
|
||||||
|
float getHeightFactor();
|
||||||
|
float getSpeedDenominator(int updateFPS);
|
||||||
|
bool isChangedActiveCommand() const { return changedActiveCommand; }
|
||||||
|
|
||||||
bool isLastStuckFrameWithinCurrentFrameTolerance();
|
bool isLastStuckFrameWithinCurrentFrameTolerance();
|
||||||
inline uint32 getLastStuckFrame() const { return lastStuckFrame; }
|
inline uint32 getLastStuckFrame() const { return lastStuckFrame; }
|
||||||
|
@ -771,6 +775,7 @@ private:
|
||||||
void morphAttackBoosts(Unit *unit);
|
void morphAttackBoosts(Unit *unit);
|
||||||
|
|
||||||
float getUpdatedProgress(float currentProgress, int updateFPS, int speed, float diagonalFactor, float heightFactor);
|
float getUpdatedProgress(float currentProgress, int updateFPS, int speed, float diagonalFactor, float heightFactor);
|
||||||
|
|
||||||
void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false);
|
void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue