more mad attempts to squeeze better performance

This commit is contained in:
Mark Vejvoda
2013-06-12 17:49:12 +00:00
parent 1d7b138ac3
commit adce76d68f
3 changed files with 22 additions and 18 deletions

View File

@@ -744,7 +744,7 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
return; return;
} }
float distToUnit=-1; double distToUnit=-1;
std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL); std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
unitBeingAttacked(result, unit, asct->getAttackSkillType(), &distToUnit); unitBeingAttacked(result, unit, asct->getAttackSkillType(), &distToUnit);
if(result.first == true) { if(result.first == true) {
@@ -780,10 +780,10 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && 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(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
} }
void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast, float *currentDistToUnit) { void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast, double *currentDistToUnit) {
//std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL); //std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
float distToUnit = -1; double distToUnit = -1;
if(currentDistToUnit != NULL) { if(currentDistToUnit != NULL) {
distToUnit = *currentDistToUnit; distToUnit = *currentDistToUnit;
} }
@@ -818,7 +818,7 @@ void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *
std::pair<bool,Unit *> UnitUpdater::unitBeingAttacked(const Unit *unit) { std::pair<bool,Unit *> UnitUpdater::unitBeingAttacked(const Unit *unit) {
std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL); std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
float distToUnit = -1; double distToUnit = -1;
for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) {
const SkillType *st = unit->getType()->getSkillType(i); const SkillType *st = unit->getType()->getSkillType(i);
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(st); const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(st);
@@ -2291,7 +2291,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
} }
} }
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance) { void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, double distance) {
if(attacker == NULL) { if(attacker == NULL) {
throw megaglest_runtime_error("attacker == NULL"); throw megaglest_runtime_error("attacker == NULL");
} }
@@ -2303,10 +2303,10 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
} }
//get vars //get vars
float damage = ast->getTotalAttackStrength(attacker->getTotalUpgrade()); double damage = ast->getTotalAttackStrength(attacker->getTotalUpgrade());
int var = ast->getAttackVar(); int var = ast->getAttackVar();
int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade()); int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade());
float damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType()); double damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
//compute damage //compute damage
//damage += random.randRange(-var, var); //damage += random.randRange(-var, var);
@@ -2534,6 +2534,7 @@ void UnitUpdater::findEnemiesForCell(const Vec2i pos, int size, int sightRange,
bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
const AttackSkillType *ast,bool evalMode) { const AttackSkillType *ast,bool evalMode) {
vector<Unit*> enemies; vector<Unit*> enemies;
enemies.reserve(100);
bool result=false; bool result=false;
//we check command target //we check command target
const Unit *commandTarget = NULL; const Unit *commandTarget = NULL;
@@ -2581,10 +2582,10 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
} }
//attack enemies that can attack first //attack enemies that can attack first
float distToUnit= -1; double distToUnit= -1;
Unit* enemySeen= NULL; Unit* enemySeen= NULL;
float distToStandingUnit= -1; double distToStandingUnit= -1;
Unit* attackingEnemySeen= NULL; Unit* attackingEnemySeen= NULL;
ControlType controlType= unit->getFaction()->getControlType(); ControlType controlType= unit->getFaction()->getControlType();
bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra; bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra;
@@ -2601,9 +2602,11 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
enemySeen = enemy; enemySeen = enemy;
result = true; result = true;
} }
float currentDist=unit->getCenteredPos().dist(enemy->getCenteredPos());
// Attackers get first priority // Attackers get first priority
if(enemy->getType()->hasSkillClass(scAttack) == true) { if(enemy->getType()->hasSkillClass(scAttack) == true) {
double currentDist = unit->getCenteredPos().dist(enemy->getCenteredPos());
// Select closest attacking unit // Select closest attacking unit
if(distToUnit < 0 || currentDist< distToUnit) { if(distToUnit < 0 || currentDist< distToUnit) {
distToUnit = currentDist; distToUnit = currentDist;
@@ -2653,8 +2656,8 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos(); Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos();
// find nearest Attack and cleanup old dates // find nearest Attack and cleanup old dates
AttackWarningData *nearest = NULL; AttackWarningData *nearest = NULL;
float currentDistance = 0.f; double currentDistance = 0.f;
float nearestDistance = 0.f; double nearestDistance = 0.f;
MutexSafeWrapper safeMutex(&mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex(&mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__));
for(int i = attackWarnings.size() - 1; i >= 0; --i) { for(int i = attackWarnings.size() - 1; i >= 0; --i) {
@@ -2726,6 +2729,7 @@ vector<Unit*> UnitUpdater::enemyUnitsOnRange(const Unit *unit,const AttackSkillT
range = ast->getTotalAttackRange(unit->getTotalUpgrade()); range = ast->getTotalAttackRange(unit->getTotalUpgrade());
} }
vector<Unit*> enemies; vector<Unit*> enemies;
enemies.reserve(100);
//we check command target //we check command target
const Unit *commandTarget = NULL; const Unit *commandTarget = NULL;
// if(unit->anyCommand()) { // if(unit->anyCommand()) {

View File

@@ -124,7 +124,7 @@ public:
inline unsigned int getAttackWarningCount() const { return attackWarnings.size(); } inline unsigned int getAttackWarningCount() const { return attackWarnings.size(); }
std::pair<bool,Unit *> unitBeingAttacked(const Unit *unit); std::pair<bool,Unit *> unitBeingAttacked(const Unit *unit);
void unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast,float *currentDistToUnit=NULL); void unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast,double *currentDistToUnit=NULL);
vector<Unit*> enemyUnitsOnRange(const Unit *unit,const AttackSkillType *ast); vector<Unit*> enemyUnitsOnRange(const Unit *unit,const AttackSkillType *ast);
void findEnemiesForCell(const Vec2i pos, int size, int sightRange, const Faction *faction, vector<Unit*> &enemies, bool attackersOnly) const; void findEnemiesForCell(const Vec2i pos, int size, int sightRange, const Faction *faction, vector<Unit*> &enemies, bool attackersOnly) const;
@@ -142,7 +142,7 @@ private:
//attack //attack
void hit(Unit *attacker); void hit(Unit *attacker);
void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField); void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField);
void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance); void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, double distance);
void startAttackParticleSystem(Unit *unit); void startAttackParticleSystem(Unit *unit);
//misc //misc

View File

@@ -204,7 +204,7 @@ public:
return x*v.x+y*v.y; return x*v.x+y*v.y;
} }
inline float dist(const Vec2<T> &v) const{ inline double dist(const Vec2<T> &v) const{
return Vec2<T>(v-*this).length(); return Vec2<T>(v-*this).length();
} }
@@ -231,7 +231,7 @@ public:
y/= m; y/= m;
} }
inline Vec2<T> rotate(float rad) { inline Vec2<T> rotate(double rad) {
// const float // const float
//#ifdef USE_STREFLOP //#ifdef USE_STREFLOP
// c = streflop::cosf(rad), // c = streflop::cosf(rad),
@@ -246,7 +246,7 @@ public:
return Vec2<T>(x*c-y*s,x*s+y*c); return Vec2<T>(x*c-y*s,x*s+y*c);
} }
inline Vec2<T> rotateAround(float rad,const Vec2<T>& pt){ inline Vec2<T> rotateAround(double rad,const Vec2<T>& pt){
return pt+(*this-pt).rotate(rad); return pt+(*this-pt).rotate(rad);
} }
@@ -447,7 +447,7 @@ public:
return x*v.x + y*v.y + z*v.z; return x*v.x + y*v.y + z*v.z;
} }
inline float dist(const Vec3<T> &v) const{ inline double dist(const Vec3<T> &v) const{
return Vec3<T>(v-*this).length(); return Vec3<T>(v-*this).length();
} }