1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

Tiny performance optimization

Keep disabled damage types vector sorted and do binary search.
This commit is contained in:
fgenesis 2017-07-12 04:12:06 +02:00
parent 78352d4402
commit cabdf93e21

View file

@ -1409,22 +1409,18 @@ void Entity::moveOutOfWall()
void Entity::setDamageTarget(DamageType dt, bool v)
{
DisabledDamageTypes::iterator it = std::lower_bound(disabledDamageTypes.begin(), disabledDamageTypes.end(), dt);
if (v)
{
for(size_t i = 0; i < disabledDamageTypes.size(); ++i)
{
if(disabledDamageTypes[i] == dt)
{
disabledDamageTypes[i] = disabledDamageTypes.back();
disabledDamageTypes.pop_back();
break;
}
}
if(it != disabledDamageTypes.end() && *it == dt)
disabledDamageTypes.erase(it);
}
else
{
if(isDamageTarget(dt))
if(it == disabledDamageTypes.end())
disabledDamageTypes.push_back(dt);
else if(*it != dt)
disabledDamageTypes.insert(it, dt);
}
}
@ -1455,11 +1451,7 @@ void Entity::setAllDamageTargets(bool v)
bool Entity::isDamageTarget(DamageType dt)
{
const size_t sz = disabledDamageTypes.size();
for(size_t i = 0; i < sz; ++i)
if(disabledDamageTypes[i] == dt)
return false;
return true;
return std::binary_search(disabledDamageTypes.begin(), disabledDamageTypes.end(), dt);
}
float Entity::getHealthPerc()