- performance improvements for units using the stop command when units are idle
This commit is contained in:
parent
ab7dc1d007
commit
47a81f8b44
|
@ -36,6 +36,7 @@ using namespace Shared::Util;
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
const int UnitPathBasic::maxBlockCount= GameConstants::updateFps / 2;
|
const int UnitPathBasic::maxBlockCount= GameConstants::updateFps / 2;
|
||||||
|
const int updateUnitForStopCommandFrameCount = 80;
|
||||||
|
|
||||||
UnitPathBasic::UnitPathBasic() {
|
UnitPathBasic::UnitPathBasic() {
|
||||||
this->blockCount = 0;
|
this->blockCount = 0;
|
||||||
|
@ -211,6 +212,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||||
throw runtime_error("#2 Invalid path position = " + pos.getString());
|
throw runtime_error("#2 Invalid path position = " + pos.getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->lastStopCommandCheckFrame = 0;
|
||||||
this->unitPath = unitpath;
|
this->unitPath = unitpath;
|
||||||
this->unitPath->setMap(map);
|
this->unitPath->setMap(map);
|
||||||
this->pos=pos;
|
this->pos=pos;
|
||||||
|
@ -1143,12 +1145,25 @@ bool Unit::needToUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//update progresses
|
//update progresses
|
||||||
float newProgress = progress;
|
|
||||||
const Game *game = Renderer::getInstance().getGame();
|
const Game *game = Renderer::getInstance().getGame();
|
||||||
newProgress += (speed * diagonalFactor * heightFactor) / (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
||||||
|
float newProgress = progress;
|
||||||
|
newProgress += (speed * diagonalFactor * heightFactor) / speedDenominator;
|
||||||
|
|
||||||
if(newProgress >= 1.f) {
|
if(newProgress >= 1.f) {
|
||||||
return_value = true;
|
return_value = true;
|
||||||
|
|
||||||
|
if(currSkill->getClass() != scDie) {
|
||||||
|
if(currSkill->getClass() == scStop) {
|
||||||
|
return_value = false;
|
||||||
|
uint32 framesSinceLastCheck = (game->getWorld()->getFrameCount() - this->getLastStopCommandCheckFrame());
|
||||||
|
if(this->getLastStopCommandCheckFrame() <= 0 ||
|
||||||
|
framesSinceLastCheck >= updateUnitForStopCommandFrameCount) {
|
||||||
|
return_value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return return_value;
|
return return_value;
|
||||||
|
@ -1190,8 +1205,11 @@ bool Unit::update() {
|
||||||
//update progresses
|
//update progresses
|
||||||
lastAnimProgress= animProgress;
|
lastAnimProgress= animProgress;
|
||||||
const Game *game = Renderer::getInstance().getGame();
|
const Game *game = Renderer::getInstance().getGame();
|
||||||
progress += (speed * diagonalFactor * heightFactor) / (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
|
||||||
animProgress += (currSkill->getAnimSpeed() * heightFactor) / (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex()));
|
||||||
|
progress += (speed * diagonalFactor * heightFactor) / speedDenominator;
|
||||||
|
|
||||||
|
animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator;
|
||||||
|
|
||||||
//update target
|
//update target
|
||||||
updateTarget();
|
updateTarget();
|
||||||
|
@ -1226,6 +1244,7 @@ bool Unit::update() {
|
||||||
(*it)->setPos(getCurrVector());
|
(*it)->setPos(getCurrVector());
|
||||||
(*it)->setRotation(getRotation());
|
(*it)->setRotation(getRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
//checks
|
//checks
|
||||||
if(animProgress > 1.f) {
|
if(animProgress > 1.f) {
|
||||||
animProgress = currSkill->getClass() == scDie? 1.f: 0.f;
|
animProgress = currSkill->getClass() == scDie? 1.f: 0.f;
|
||||||
|
@ -1238,6 +1257,18 @@ bool Unit::update() {
|
||||||
if(currSkill->getClass() != scDie) {
|
if(currSkill->getClass() != scDie) {
|
||||||
progress = 0.f;
|
progress = 0.f;
|
||||||
return_value = true;
|
return_value = true;
|
||||||
|
if(currSkill->getClass() == scStop) {
|
||||||
|
return_value = false;
|
||||||
|
uint32 framesSinceLastCheck = (game->getWorld()->getFrameCount() - this->getLastStopCommandCheckFrame());
|
||||||
|
if(this->getLastStopCommandCheckFrame() <= 0 ||
|
||||||
|
framesSinceLastCheck >= updateUnitForStopCommandFrameCount) {
|
||||||
|
this->setLastStopCommandCheckFrame(game->getWorld()->getFrameCount());
|
||||||
|
return_value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if(return_value == true) {
|
||||||
|
// printf("\n\n\n@@@@@@@@@@@@@@@ Unit [%s - %d] current skill [%s]\n",this->getFullName().c_str(),this->getId(),currSkill->getName().c_str());
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
progress= 1.f;
|
progress= 1.f;
|
||||||
|
|
|
@ -331,6 +331,7 @@ private:
|
||||||
static Game *game;
|
static Game *game;
|
||||||
|
|
||||||
bool ignoreCheckCommand;
|
bool ignoreCheckCommand;
|
||||||
|
uint32 lastStopCommandCheckFrame;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||||
|
@ -345,7 +346,7 @@ public:
|
||||||
Field getCurrField() const {return currField;}
|
Field getCurrField() const {return currField;}
|
||||||
int getLoadCount() const {return loadCount;}
|
int getLoadCount() const {return loadCount;}
|
||||||
float getLastAnimProgress() const {return lastAnimProgress;}
|
float getLastAnimProgress() const {return lastAnimProgress;}
|
||||||
float getProgress() const {return progress;}
|
//float getProgress() const {return progress;}
|
||||||
float getAnimProgress() const {return animProgress;}
|
float getAnimProgress() const {return animProgress;}
|
||||||
float getHightlight() const {return highlight;}
|
float getHightlight() const {return highlight;}
|
||||||
int getProgress2() const {return progress2;}
|
int getProgress2() const {return progress2;}
|
||||||
|
@ -496,6 +497,9 @@ public:
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
bool needToUpdate();
|
bool needToUpdate();
|
||||||
|
|
||||||
|
uint32 getLastStopCommandCheckFrame() const {return lastStopCommandCheckFrame; }
|
||||||
|
void setLastStopCommandCheckFrame(uint32 value) { lastStopCommandCheckFrame = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float computeHeight(const Vec2i &pos) const;
|
float computeHeight(const Vec2i &pos) const;
|
||||||
void updateTarget();
|
void updateTarget();
|
||||||
|
|
|
@ -269,15 +269,17 @@ void UnitUpdater::updateUnitCommand(Unit *unit, int frameIndex) {
|
||||||
if(unit->anyCommand() == false && unit->isOperative()) {
|
if(unit->anyCommand() == false && unit->isOperative()) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//const SkillType *currSkill= unit->getCurrSkill();
|
if(unit->getType()->hasSkillClass(scAttack) || unit->getType()->hasCommandClass(ccMove)) {
|
||||||
//if(currSkill == NULL || currSkill->getClass() != scStop) {
|
//printf("\n\n\n$$$$$$$$$ Unit [%s - %d] unitFrame [%d] WorldFrame [%d]\n",unit->getFullName().c_str(),unit->getId(),unit->getLastStopCommandCheckFrame(),world->getFrameCount());
|
||||||
|
if(unit->getType()->hasSkillClass(scStop)) {
|
||||||
unit->setCurrSkill(scStop);
|
unit->setCurrSkill(scStop);
|
||||||
|
}
|
||||||
|
|
||||||
if(unit->getType()->hasCommandClass(ccStop)) {
|
if(unit->getType()->hasCommandClass(ccStop)) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
@ -344,6 +346,9 @@ void UnitUpdater::updateStop(Unit *unit, int frameIndex) {
|
||||||
|
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// printf("\n\n\n################ Unit [%s - %d] unitFrame [%d] WorldFrame [%d]\n",unit->getFullName().c_str(),unit->getId(),unit->getLastStopCommandCheckFrame(),world->getFrameCount());
|
||||||
|
// }
|
||||||
|
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,6 +426,7 @@ void World::update(){
|
||||||
//tick
|
//tick
|
||||||
bool needToTick = canTickWorld();
|
bool needToTick = canTickWorld();
|
||||||
if(needToTick == true) {
|
if(needToTick == true) {
|
||||||
|
//printf("=========== World is about to be updated, current frameCount = %d\n",frameCount);
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue