diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 6f81e294..4bc17843 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5141,7 +5141,7 @@ void Renderer::renderUnits(const int renderFps) { //dead alpha const SkillType *st= unit->getCurrSkill(); if(st->getClass() == scDie && static_cast(st)->getFade()) { - float alpha= 1.0f-unit->getAnimProgress(); + float alpha= 1.0f - unit->getAnimProgressAsFloat(); glDisable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Vec4f(1.0f, 1.0f, 1.0f, alpha).ptr()); } @@ -5155,7 +5155,7 @@ void Renderer::renderUnits(const int renderFps) { //printf("Rendering model [%d - %s]\n[%s]\nCamera [%s]\nDistance: %f\n",unit->getId(),unit->getType()->getName().c_str(),unit->getCurrVector().getString().c_str(),this->gameCamera->getPos().getString().c_str(),this->gameCamera->getPos().dist(unit->getCurrVector())); //if(this->gameCamera->getPos().dist(unit->getCurrVector()) <= SKIP_INTERPOLATION_DISTANCE) { - model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive() && !unit->isAnimProgressBound()); + model->updateInterpolationData(unit->getAnimProgressAsFloat(), unit->isAlive() && !unit->isAnimProgressBound()); //} modelRenderer->render(model); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 8f2a4887..d81ea694 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -471,8 +471,8 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, lastPos= pos; progress= 0; - lastAnimProgress= 0; - animProgress= 0; + this->lastAnimProgress= 0; + this->animProgress= 0; progress2= 0; kills= 0; enemyKills = 0; @@ -1041,8 +1041,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) { changedActiveCommand = false; if( currSkill->getClass() != this->currSkill->getClass() || currSkill->getName() != this->currSkill->getName()) { - animProgress= 0; - lastAnimProgress= 0; + this->animProgress= 0; + this->lastAnimProgress= 0; queuedUnitParticleSystemTypes.clear(); while(unitParticleSystems.empty() == false) { @@ -1301,7 +1301,7 @@ Model *Unit::getCurrentModelPtr() { } int currentModelIndexForCurrSkillType = lastModelIndexForCurrSkillType; - Model *result = currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount); + Model *result = currSkill->getAnimation(getAnimProgressAsFloat(),this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount); if(currentModelIndexForCurrSkillType != lastModelIndexForCurrSkillType) { animationRandomCycleCount++; if(currSkill != NULL && animationRandomCycleCount >= currSkill->getAnimationCount()) { @@ -1319,7 +1319,7 @@ const Model *Unit::getCurrentModel() { } int currentModelIndexForCurrSkillType = lastModelIndexForCurrSkillType; - const Model *result = currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount); + const Model *result = currSkill->getAnimation(getAnimProgressAsFloat(),this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount); if(currentModelIndexForCurrSkillType != lastModelIndexForCurrSkillType) { animationRandomCycleCount++; if(currSkill != NULL && animationRandomCycleCount >= currSkill->getAnimationCount()) { @@ -2018,7 +2018,7 @@ bool Unit::update() { int heightFactor = getHeightFactor(); //update progresses - lastAnimProgress= animProgress; + this->lastAnimProgress= this->animProgress; const Game *game = Renderer::getInstance().getGame(); progress = getUpdatedProgress(progress, @@ -2041,17 +2041,15 @@ bool Unit::update() { if(currSkill->getClass() == scMorph) { targetProgress = this->getProgressRatio(); } - if(animProgress < targetProgress) { - float diff = targetProgress - animProgress; - animProgress = animProgress + diff / (GameConstants::updateFps); + if(getAnimProgressAsFloat() < targetProgress) { + float diff = targetProgress - getAnimProgressAsFloat(); + this->animProgress = this->animProgress + static_cast(diff * 100.f) / (GameConstants::updateFps); } } else { - float speedDenominator = static_cast(speedDivider) * + int speedDenominator = speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()); - animProgress += (currSkill->getAnimSpeed() * - (truncateDecimal(static_cast(heightFactor) / 100.f))) / - (truncateDecimal(speedDenominator)); + this->animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator; } //update target updateTarget(); @@ -2129,9 +2127,9 @@ bool Unit::update() { } //checks - if(animProgress > 1.f) { + if(this->animProgress > 100) { bool canCycle = currSkill->CanCycleNextRandomAnimation(&animationRandomCycleCount); - animProgress = currSkill->getClass() == scDie? 1.f: 0.f; + this->animProgress = currSkill->getClass() == scDie ? 100 : 0; if(canCycle == true) { this->lastModelIndexForCurrSkillType = -1; } @@ -2299,7 +2297,7 @@ void Unit::updateTimedParticles() { for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; if(pst != NULL) { - if(truncateDecimal(pst->getStartTime()) <= truncateDecimal(animProgress)) { + if(truncateDecimal(pst->getStartTime()) <= truncateDecimal(getAnimProgressAsFloat())) { //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); @@ -2329,8 +2327,8 @@ void Unit::updateTimedParticles() { 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())) { + if(truncateDecimal(getAnimProgressAsFloat()) >= 0.99 || + truncateDecimal(getAnimProgressAsFloat()) >= truncateDecimal(ps->getEndTime())) { //printf("ENDING particle system [%d]\n",ps->shape); ps->fade(); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index b48e577f..7a20032c 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -348,8 +348,8 @@ private: int deadCount; //float progress; //between 0 and 1 int progress; //between 0 and 1 - float lastAnimProgress; //between 0 and 1 - float animProgress; //between 0 and 1 + int lastAnimProgress; //between 0 and 1 + int animProgress; //between 0 and 1 float highlight; int progress2; int kills; @@ -503,9 +503,12 @@ public: inline int getId() const {return id;} inline Field getCurrField() const {return currField;} inline int getLoadCount() const {return loadCount;} - inline float getLastAnimProgress() const {return lastAnimProgress;} - //float getProgress() const {return progress;} - inline float getAnimProgress() const {return animProgress;} + + //inline int getLastAnimProgress() const {return lastAnimProgress;} + //inline int getAnimProgress() const {return animProgress;} + inline float getLastAnimProgressAsFloat() const {return static_cast(lastAnimProgress) / 100.f;} + inline float getAnimProgressAsFloat() const {return static_cast(animProgress) / 100.f;} + inline float getHightlight() const {return highlight;} inline int getProgress2() const {return progress2;} inline int getFactionIndex() const { diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 0e2fac75..e47a4aa5 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -120,7 +120,7 @@ bool UnitUpdater::updateUnit(Unit *unit) { const SkillType *currSkill= unit->getCurrSkill(); if(currSkill->getSound() != NULL) { float soundStartTime= currSkill->getSoundStartTime(); - if(soundStartTime >= unit->getLastAnimProgress() && soundStartTime < unit->getAnimProgress()) { + if(soundStartTime >= unit->getLastAnimProgressAsFloat() && soundStartTime < unit->getAnimProgressAsFloat()) { if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) { soundRenderer.playFx(currSkill->getSound(), unit->getCurrVector(), gameCamera->getPos()); @@ -138,7 +138,7 @@ bool UnitUpdater::updateUnit(Unit *unit) { if(unit->getCurrSkill()->getClass() == scAttack) { const AttackSkillType *ast= static_cast(unit->getCurrSkill()); float attackStartTime= ast->getAttackStartTime(); - if(attackStartTime>=unit->getLastAnimProgress() && attackStartTimegetAnimProgress()){ + if(attackStartTime>=unit->getLastAnimProgressAsFloat() && attackStartTimegetAnimProgressAsFloat()){ startAttackParticleSystem(unit); } }