ensure dead units clean up
This commit is contained in:
parent
85ab3c76cc
commit
fe151abcc5
|
@ -1327,14 +1327,14 @@ Vec3f Unit::getCurrVector() const{
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
|
return getCurrVectorFlat() + Vec3f(0.f, truncateDecimal<float>(type->getHeight()/2.f), 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3f Unit::getCurrVectorFlat() const{
|
Vec3f Unit::getCurrVectorFlat() const{
|
||||||
return getVectorFlat(lastPos, pos);
|
return getVectorFlat(lastPos, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Unit::getProgessAsFloat() const {
|
float Unit::getProgressAsFloat() const {
|
||||||
float result = (static_cast<float>(progress) / 100.f);
|
float result = (static_cast<float>(progress) / 100.f);
|
||||||
result = truncateDecimal<float>(result);
|
result = truncateDecimal<float>(result);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1347,17 +1347,17 @@ Vec3f Unit::getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) c
|
||||||
float y2= computeHeight(curPosValue);
|
float y2= computeHeight(curPosValue);
|
||||||
|
|
||||||
if(currSkill->getClass() == scMove) {
|
if(currSkill->getClass() == scMove) {
|
||||||
v.x= lastPosValue.x + getProgessAsFloat() * (curPosValue.x - lastPosValue.x);
|
v.x= truncateDecimal<float>(lastPosValue.x + getProgressAsFloat() * (curPosValue.x - lastPosValue.x));
|
||||||
v.z= lastPosValue.y + getProgessAsFloat() * (curPosValue.y - lastPosValue.y);
|
v.z= truncateDecimal<float>(lastPosValue.y + getProgressAsFloat() * (curPosValue.y - lastPosValue.y));
|
||||||
v.y= y1 + getProgessAsFloat() * (y2-y1);
|
v.y= truncateDecimal<float>(y1 + getProgressAsFloat() * (y2-y1));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
v.x= static_cast<float>(curPosValue.x);
|
v.x= static_cast<float>(curPosValue.x);
|
||||||
v.z= static_cast<float>(curPosValue.y);
|
v.z= static_cast<float>(curPosValue.y);
|
||||||
v.y= y2;
|
v.y= y2;
|
||||||
}
|
}
|
||||||
v.x += type->getSize() / 2.f - 0.5f;
|
v.x += truncateDecimal<float>(type->getSize() / 2.f - 0.5f);
|
||||||
v.z += type->getSize() / 2.f - 0.5f;
|
v.z += truncateDecimal<float>(type->getSize() / 2.f - 0.5f);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -1900,24 +1900,19 @@ bool Unit::needToUpdate() {
|
||||||
|
|
||||||
int Unit::getDiagonalFactor() {
|
int Unit::getDiagonalFactor() {
|
||||||
//speed modifier
|
//speed modifier
|
||||||
//float diagonalFactor= 1.f;
|
|
||||||
int diagonalFactor= 100;
|
int diagonalFactor= 100;
|
||||||
if(currSkill->getClass() == scMove) {
|
if(currSkill->getClass() == scMove) {
|
||||||
//if moving in diagonal move slower
|
//if moving in diagonal move slower
|
||||||
Vec2i dest= pos - lastPos;
|
Vec2i dest= pos - lastPos;
|
||||||
if(abs(dest.x) + abs(dest.y) == 2) {
|
if(abs(dest.x) + abs(dest.y) == 2) {
|
||||||
diagonalFactor = 71;
|
diagonalFactor = 71;
|
||||||
//diagonalFactor = truncateDecimal<float>(diagonalFactor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return diagonalFactor;
|
return diagonalFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Unit::getHeightFactor() {
|
int Unit::getHeightFactor() {
|
||||||
//speed modifier
|
int heightFactor = 100;
|
||||||
//float heightFactor= 1.f;
|
|
||||||
float heightFactor= 100;
|
|
||||||
if(currSkill->getClass() == scMove) {
|
if(currSkill->getClass() == scMove) {
|
||||||
//if moving to an higher cell move slower else move faster
|
//if moving to an higher cell move slower else move faster
|
||||||
Cell *unitCell = map->getCell(pos);
|
Cell *unitCell = map->getCell(pos);
|
||||||
|
@ -1930,9 +1925,6 @@ int Unit::getHeightFactor() {
|
||||||
throw megaglest_runtime_error("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);
|
|
||||||
int heightDiff= ((unitCell->getHeight() * 100.f) - (targetCell->getHeight() * 100.f));
|
int heightDiff= ((unitCell->getHeight() * 100.f) - (targetCell->getHeight() * 100.f));
|
||||||
heightFactor= clamp(100 + heightDiff / 500, 20, 500);
|
heightFactor= clamp(100 + heightDiff / 500, 20, 500);
|
||||||
}
|
}
|
||||||
|
@ -1941,19 +1933,21 @@ int Unit::getHeightFactor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Unit::getSpeedDenominator(int updateFPS) {
|
int Unit::getSpeedDenominator(int updateFPS) {
|
||||||
//float speedDenominator = truncateDecimal<float>(speedDivider * updateFPS);
|
|
||||||
int speedDenominator = (speedDivider * updateFPS) * 100;
|
int speedDenominator = (speedDivider * updateFPS) * 100;
|
||||||
return speedDenominator;
|
return speedDenominator;
|
||||||
}
|
}
|
||||||
int Unit::getUpdatedProgress(int currentProgress, int updateFPS, int speed,
|
int Unit::getUpdatedProgress(int currentProgress, int updateFPS, int speed,
|
||||||
int diagonalFactor, int heightFactor) {
|
int diagonalFactor, int heightFactor) {
|
||||||
|
|
||||||
//float speedDenominator = getSpeedDenominator(updateFPS);
|
|
||||||
int speedDenominator = getSpeedDenominator(updateFPS);
|
int speedDenominator = getSpeedDenominator(updateFPS);
|
||||||
//float newProgress = truncateDecimal<float>(currentProgress);
|
|
||||||
int newProgress = currentProgress;
|
int newProgress = currentProgress;
|
||||||
//newProgress += truncateDecimal<float> ((speed * diagonalFactor * heightFactor) / speedDenominator);
|
int progressIncrease = ((speed * diagonalFactor * heightFactor) / speedDenominator);
|
||||||
newProgress += ((speed * diagonalFactor * heightFactor) / speedDenominator);
|
// Ensure we increment at least a value of 1 of the action will be stuck infinitely
|
||||||
|
if(speed > 0 && diagonalFactor > 0 && heightFactor > 0 && progressIncrease == 0) {
|
||||||
|
progressIncrease = 1;
|
||||||
|
}
|
||||||
|
newProgress += progressIncrease;
|
||||||
|
|
||||||
return newProgress;
|
return newProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1987,9 +1981,8 @@ bool Unit::update() {
|
||||||
lastAnimProgress= animProgress;
|
lastAnimProgress= animProgress;
|
||||||
const Game *game = Renderer::getInstance().getGame();
|
const Game *game = Renderer::getInstance().getGame();
|
||||||
|
|
||||||
//float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
progress = getUpdatedProgress(progress,
|
||||||
//progress += (speed * diagonalFactor * heightFactor) / speedDenominator;
|
game->getWorld()->getUpdateFps(this->getFactionIndex()),
|
||||||
progress = getUpdatedProgress(progress, game->getWorld()->getUpdateFps(this->getFactionIndex()),
|
|
||||||
speed, diagonalFactor, heightFactor);
|
speed, diagonalFactor, heightFactor);
|
||||||
|
|
||||||
//printf("Test progress = %d for unit [%d - %s]\n",progress,id,getType()->getName().c_str());
|
//printf("Test progress = %d for unit [%d - %s]\n",progress,id,getType()->getName().c_str());
|
||||||
|
@ -2008,17 +2001,17 @@ bool Unit::update() {
|
||||||
if(currSkill->getClass() == scMorph) {
|
if(currSkill->getClass() == scMorph) {
|
||||||
targetProgress = this->getProgressRatio();
|
targetProgress = this->getProgressRatio();
|
||||||
}
|
}
|
||||||
if(animProgress<targetProgress){
|
if(animProgress < targetProgress) {
|
||||||
float diff = targetProgress - animProgress;
|
float diff = targetProgress - animProgress;
|
||||||
animProgress=animProgress + diff / (GameConstants::updateFps);
|
animProgress = animProgress + diff / (GameConstants::updateFps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
float speedDenominator = static_cast<float>(speedDivider) *
|
||||||
int speedDenominator = getSpeedDenominator(game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
game->getWorld()->getUpdateFps(this->getFactionIndex());
|
||||||
animProgress += (currSkill->getAnimSpeed() *
|
animProgress += (currSkill->getAnimSpeed() *
|
||||||
(truncateDecimal<float>(static_cast<float>(heightFactor) / 100.f))) /
|
(truncateDecimal<float>(static_cast<float>(heightFactor) / 100.f))) /
|
||||||
(truncateDecimal<float>(static_cast<float>(speedDenominator) / 100.f));
|
(truncateDecimal<float>(speedDenominator));
|
||||||
}
|
}
|
||||||
//update target
|
//update target
|
||||||
updateTarget();
|
updateTarget();
|
||||||
|
@ -2026,15 +2019,15 @@ bool Unit::update() {
|
||||||
//rotation
|
//rotation
|
||||||
if(currSkill->getClass() != scStop) {
|
if(currSkill->getClass() != scStop) {
|
||||||
const int rotFactor= 2;
|
const int rotFactor= 2;
|
||||||
if(getProgessAsFloat() < 1.f / rotFactor) {
|
if(getProgressAsFloat() < 1.f / rotFactor) {
|
||||||
if(type->getFirstStOfClass(scMove)){
|
if(type->getFirstStOfClass(scMove)){
|
||||||
if(abs((int)(lastRotation-targetRotation)) < 180)
|
if(abs((int)(lastRotation-targetRotation)) < 180)
|
||||||
rotation= lastRotation + (targetRotation - lastRotation) *
|
rotation= lastRotation + (targetRotation - lastRotation) *
|
||||||
getProgessAsFloat() * rotFactor;
|
getProgressAsFloat() * rotFactor;
|
||||||
else {
|
else {
|
||||||
float rotationTerm = targetRotation > lastRotation ? -360.f: +360.f;
|
float rotationTerm = targetRotation > lastRotation ? -360.f: +360.f;
|
||||||
rotation = lastRotation + (targetRotation - lastRotation + rotationTerm) *
|
rotation = lastRotation + (targetRotation - lastRotation + rotationTerm) *
|
||||||
getProgessAsFloat() * rotFactor;
|
getProgressAsFloat() * rotFactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -725,7 +725,7 @@ public:
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
bool needToUpdate();
|
bool needToUpdate();
|
||||||
float getProgessAsFloat() const;
|
float getProgressAsFloat() const;
|
||||||
int getUpdateProgress();
|
int getUpdateProgress();
|
||||||
int getDiagonalFactor();
|
int getDiagonalFactor();
|
||||||
int getHeightFactor();
|
int getHeightFactor();
|
||||||
|
|
Loading…
Reference in New Issue