attempt to fix the model render not properly timed

This commit is contained in:
Mark Vejvoda 2013-05-31 07:09:25 +00:00
parent a0506e3486
commit 6cc8f6ac75
4 changed files with 29 additions and 28 deletions

View File

@ -5141,7 +5141,7 @@ void Renderer::renderUnits(const int renderFps) {
//dead alpha
const SkillType *st= unit->getCurrSkill();
if(st->getClass() == scDie && static_cast<const DieSkillType*>(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);

View File

@ -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<int>(diff * 100.f) / (GameConstants::updateFps);
}
}
else {
float speedDenominator = static_cast<float>(speedDivider) *
int speedDenominator = speedDivider *
game->getWorld()->getUpdateFps(this->getFactionIndex());
animProgress += (currSkill->getAnimSpeed() *
(truncateDecimal<float>(static_cast<float>(heightFactor) / 100.f))) /
(truncateDecimal<float>(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<float>(pst->getStartTime()) <= truncateDecimal<float>(animProgress)) {
if(truncateDecimal<float>(pst->getStartTime()) <= truncateDecimal<float>(getAnimProgressAsFloat())) {
//printf("STARTING queued particle system type [%s] [%f] [%f] [%f] [%f]\n",pst->getType().c_str(),truncateDecimal<float>(pst->getStartTime()),truncateDecimal<float>(pst->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress));
UnitParticleSystem *ups = new UnitParticleSystem(200);
@ -2329,8 +2327,8 @@ void Unit::updateTimedParticles() {
if(truncateDecimal<float>(ps->getStartTime()) != 0.0 || truncateDecimal<float>(ps->getEndTime()) != 1.0) {
//printf("Checking for end particle system #%d [%d] [%f] [%f] [%f] [%f]\n",i,ps->shape,truncateDecimal<float>(ps->getStartTime()),truncateDecimal<float>(ps->getEndTime()),truncateDecimal<float>(animProgress),truncateDecimal<float>(lastAnimProgress));
if(truncateDecimal<float>(animProgress) >= 0.99 ||
truncateDecimal<float>(animProgress) >= truncateDecimal<float>(ps->getEndTime())) {
if(truncateDecimal<float>(getAnimProgressAsFloat()) >= 0.99 ||
truncateDecimal<float>(getAnimProgressAsFloat()) >= truncateDecimal<float>(ps->getEndTime())) {
//printf("ENDING particle system [%d]\n",ps->shape);
ps->fade();

View File

@ -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<float>(lastAnimProgress) / 100.f;}
inline float getAnimProgressAsFloat() const {return static_cast<float>(animProgress) / 100.f;}
inline float getHightlight() const {return highlight;}
inline int getProgress2() const {return progress2;}
inline int getFactionIndex() const {

View File

@ -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<const AttackSkillType*>(unit->getCurrSkill());
float attackStartTime= ast->getAttackStartTime();
if(attackStartTime>=unit->getLastAnimProgress() && attackStartTime<unit->getAnimProgress()){
if(attackStartTime>=unit->getLastAnimProgressAsFloat() && attackStartTime<unit->getAnimProgressAsFloat()){
startAttackParticleSystem(unit);
}
}