From 14c70966b0ef771d1be9734b95cecd8be317780b Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 2 Jul 2011 21:44:29 +0000 Subject: [PATCH] - bugfix for hpanim on bebuilt, to interplotate out the last reset frames --- source/g3d_viewer/main.cpp | 21 ++++++++++++--------- source/glest_game/graphics/renderer.cpp | 4 ++-- source/glest_game/type_instances/unit.cpp | 21 +++++++++++++++++++-- source/glest_game/type_instances/unit.h | 1 + 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index e03e09fa..a72f69e1 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -526,6 +526,9 @@ void MainWindow::onPaint(wxPaintEvent &event) { //printf("anim [%f] particleLoopStart [%d]\n",anim,particleLoopStart); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); + renderer->renderTheModel(model, anim); int updateLoops = particleLoopStart; @@ -628,7 +631,7 @@ void MainWindow::onMouseWheelDown(wxMouseEvent &event) { zoom*= 1.1f; zoom= clamp(zoom, 0.1f, 10.0f); - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); onPaint(paintEvent); @@ -645,7 +648,7 @@ void MainWindow::onMouseWheelUp(wxMouseEvent &event) { zoom*= 0.90909f; zoom= clamp(zoom, 0.1f, 10.0f); - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); onPaint(paintEvent); @@ -667,7 +670,7 @@ void MainWindow::onMouseMove(wxMouseEvent &event){ rotX+= clamp(lastX-x, -10, 10); rotY+= clamp(lastY-y, -10, 10); - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); onPaint(paintEvent); @@ -676,7 +679,7 @@ void MainWindow::onMouseMove(wxMouseEvent &event){ zoom*= 1.0f+(lastX-x+lastY-y)/100.0f; zoom= clamp(zoom, 0.1f, 10.0f); - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); onPaint(paintEvent); @@ -1136,7 +1139,7 @@ void MainWindow::loadModel(string path) { model= tmpModel; statusbarText = getModelInfo(); - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); if(timer) timer->Start(100); titlestring = extractFileFromDirectoryPath(modelPath) + " - "+ titlestring; @@ -1486,7 +1489,7 @@ void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){ speed = 0; } - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); } catch(std::runtime_error e) { @@ -1502,7 +1505,7 @@ void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){ speed = 1; } - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 ) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 ) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); } catch(std::runtime_error e) { @@ -1703,7 +1706,7 @@ void MainWindow::onKeyDown(wxKeyEvent &e) { speed = 1.0; } - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); } @@ -1712,7 +1715,7 @@ void MainWindow::onKeyDown(wxKeyEvent &e) { if(speed < 0) { speed = 0; } - string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); + string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); } else if (e.GetKeyCode() == 'W') { diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index f3428958..24680b96 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -3020,7 +3020,7 @@ void Renderer::renderUnits(const int renderFps) { //render Model *model= unit->getCurrentModelPtr(); - model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive()); + model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive() && !unit->isBeingBuiltWithAnimHpBound()); modelRenderer->render(model); triangleCount+= model->getTriangleCount(); @@ -4658,7 +4658,7 @@ void Renderer::renderUnitsFast(bool renderingShadows) { //render Model *model= unit->getCurrentModelPtr(); - model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive()); + model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive() && !unit->isBeingBuiltWithAnimHpBound()); modelRenderer->render(model); glPopMatrix(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 7062edd2..25c51bd1 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -528,6 +528,23 @@ bool Unit::isOperative() const{ return isAlive() && isBuilt(); } +bool Unit::isBeingBuiltWithAnimHpBound() const{ + if(currSkill == NULL) { + char szBuf[4096]=""; + sprintf(szBuf,"In [%s::%s Line: %d] ERROR: currSkill == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str()); + throw runtime_error(szBuf); + } + + bool result = false; + if(currSkill->getClass() == scBeBuilt) { + const BeBuiltSkillType *bbst = dynamic_cast(currSkill); + if(bbst != NULL) { + result = bbst->getAnimHpBound(); + } + } + return result; +} + bool Unit::isBeingBuilt() const{ if(currSkill == NULL) { char szBuf[4096]=""; @@ -1250,7 +1267,7 @@ bool Unit::update() { float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); progress += (speed * diagonalFactor * heightFactor) / speedDenominator; - if(currSkill->getClass() == scBeBuilt && static_cast(currSkill)->getAnimHpBound()==true ){ + if(isBeingBuiltWithAnimHpBound() == true) { animProgress=this->getHpRatio(); } else{ @@ -1811,7 +1828,7 @@ string Unit::getDesc() const { str += lang.get("MaxUnitCount")+ ": " + intToStr(faction->getCountForMaxUnitCount(type)) + "/" + intToStr(type->getMaxUnitCount()); } - str += "\n"+lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade)); + str += "\n"+lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade)) + " [" + floatToStr(getHpRatio()) + "] [" + floatToStr(animProgress) + "]"; if(type->getHpRegeneration()!=0){ str+= " (" + lang.get("Regeneration") + ": " + intToStr(type->getHpRegeneration()) + ")"; } diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 42144b5b..177d9e44 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -439,6 +439,7 @@ public: bool isOperative() const; bool isBeingBuilt() const; bool isBuilt() const; + bool isBeingBuiltWithAnimHpBound() const; bool isPutrefacting() const; bool isAlly(const Unit *unit) const; bool isDamaged() const;