From cd2177fc1e63098707c09331d81d9ef2bc803781 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 23 May 2013 00:33:30 +0000 Subject: [PATCH] attempt to see if this fixes long standing out of synch bugs --- source/glest_game/type_instances/faction.cpp | 5 + source/glest_game/type_instances/unit.cpp | 121 +++++++++++-------- source/glest_game/type_instances/unit.h | 1 + 3 files changed, 74 insertions(+), 53 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 7b30ab50..205a54ad 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -369,6 +369,11 @@ void FactionThread::execute() { //update = true; if(update == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"unit->needToUpdate() returned: %d",update); + unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); + } int64 elapsed2 = 0; if(minorDebugPerformance) elapsed2 = chrono.getMillis(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 9ba92df4..c1935c17 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1917,9 +1917,11 @@ bool Unit::needToUpdate() { throw megaglest_runtime_error("game->getWorld() == NULL"); } - float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); - float newProgress = progress; - newProgress += (speed * diagonalFactor * heightFactor) / speedDenominator; + //float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); + //float newProgress = progress; + //newProgress += (speed * diagonalFactor * heightFactor) / speedDenominator; + float newProgress = getUpdatedProgress(progress, game->getWorld()->getUpdateFps(this->getFactionIndex()), + speed, diagonalFactor, heightFactor); if(newProgress >= 1.f) { return_value = true; @@ -1928,55 +1930,14 @@ bool Unit::needToUpdate() { return return_value; } -void Unit::updateTimedParticles() { - //!!! - // Start new particle systems based on start time - if(queuedUnitParticleSystemTypes.empty() == false) { - for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { - UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; - if(pst != NULL) { - if(truncateDecimal(pst->getStartTime()) <= truncateDecimal(animProgress)) { - //printf("STARTING queued particle system type [%s] [%f] [%f] [%f] [%f]\n",pst->getType().c_str(),truncateDecimal(pst->getStartTime()),truncateDecimal(pst->getEndTime()),truncateDecimal(animProgress),truncateDecimal(lastAnimProgress)); +float Unit::getUpdatedProgress(float currentProgress, int updateFPS, int speed, + float diagonalFactor, float heightFactor) { - UnitParticleSystem *ups = new UnitParticleSystem(200); - pst->setValues(ups); - ups->setPos(getCurrVector()); - if(getFaction()->getTexture()) { - ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); - } - unitParticleSystems.push_back(ups); - Renderer::getInstance().manageParticleSystem(ups, rsGame); - - queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i); - } - } - else { - queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i); - } - } - } - - // End existing systems based on end time - if(unitParticleSystems.empty() == false) { - for(int i = unitParticleSystems.size() - 1; i >= 0; i--) { - UnitParticleSystem *ps = unitParticleSystems[i]; - if(ps != NULL) { - if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { - if(truncateDecimal(ps->getStartTime()) != 0.0 || truncateDecimal(ps->getEndTime()) != 1.0) { - //printf("Checking for end particle system #%d [%d] [%f] [%f] [%f] [%f]\n",i,ps->shape,truncateDecimal(ps->getStartTime()),truncateDecimal(ps->getEndTime()),truncateDecimal(animProgress),truncateDecimal(lastAnimProgress)); - - if(truncateDecimal(animProgress) >= 0.99 || - truncateDecimal(animProgress) >= truncateDecimal(ps->getEndTime())) { - //printf("ENDING particle system [%d]\n",ps->shape); - - ps->fade(); - unitParticleSystems.erase(unitParticleSystems.begin() + i); - } - } - } - } - } - } + float speedDenominator = (speedDivider * updateFPS); + float newProgress = currentProgress; + newProgress += ((speed * diagonalFactor * heightFactor) / speedDenominator); + truncateDecimal(newProgress); + return newProgress; } bool Unit::update() { @@ -2020,8 +1981,10 @@ bool Unit::update() { lastAnimProgress= animProgress; const Game *game = Renderer::getInstance().getGame(); - float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); - progress += (speed * diagonalFactor * heightFactor) / speedDenominator; + //float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); + //progress += (speed * diagonalFactor * heightFactor) / speedDenominator; + progress = getUpdatedProgress(progress, game->getWorld()->getUpdateFps(this->getFactionIndex()), + speed, diagonalFactor, heightFactor); if(isAnimProgressBound() == true) { float targetProgress=0; @@ -2043,6 +2006,7 @@ bool Unit::update() { } } else { + float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator; } //update target @@ -2282,6 +2246,57 @@ bool Unit::update() { return return_value; } +void Unit::updateTimedParticles() { + //!!! + // Start new particle systems based on start time + if(queuedUnitParticleSystemTypes.empty() == false) { + for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { + UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; + if(pst != NULL) { + if(truncateDecimal(pst->getStartTime()) <= truncateDecimal(animProgress)) { + //printf("STARTING queued particle system type [%s] [%f] [%f] [%f] [%f]\n",pst->getType().c_str(),truncateDecimal(pst->getStartTime()),truncateDecimal(pst->getEndTime()),truncateDecimal(animProgress),truncateDecimal(lastAnimProgress)); + + UnitParticleSystem *ups = new UnitParticleSystem(200); + pst->setValues(ups); + ups->setPos(getCurrVector()); + if(getFaction()->getTexture()) { + ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); + } + unitParticleSystems.push_back(ups); + Renderer::getInstance().manageParticleSystem(ups, rsGame); + + queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i); + } + } + else { + queuedUnitParticleSystemTypes.erase(queuedUnitParticleSystemTypes.begin() + i); + } + } + } + + // End existing systems based on end time + if(unitParticleSystems.empty() == false) { + for(int i = unitParticleSystems.size() - 1; i >= 0; i--) { + UnitParticleSystem *ps = unitParticleSystems[i]; + if(ps != NULL) { + if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { + if(truncateDecimal(ps->getStartTime()) != 0.0 || truncateDecimal(ps->getEndTime()) != 1.0) { + //printf("Checking for end particle system #%d [%d] [%f] [%f] [%f] [%f]\n",i,ps->shape,truncateDecimal(ps->getStartTime()),truncateDecimal(ps->getEndTime()),truncateDecimal(animProgress),truncateDecimal(lastAnimProgress)); + + if(truncateDecimal(animProgress) >= 0.99 || + truncateDecimal(animProgress) >= truncateDecimal(ps->getEndTime())) { + //printf("ENDING particle system [%d]\n",ps->shape); + + ps->fade(); + unitParticleSystems.erase(unitParticleSystems.begin() + i); + } + } + } + } + } + } +} + bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const { bool result = false; for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index a3f9f88c..8185f666 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -769,6 +769,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); };