mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-12-01 15:35:47 +00:00
Tiny performance optimization
Keep disabled damage types vector sorted and do binary search.
This commit is contained in:
parent
78352d4402
commit
cabdf93e21
1 changed files with 7 additions and 15 deletions
|
@ -1409,22 +1409,18 @@ void Entity::moveOutOfWall()
|
||||||
|
|
||||||
void Entity::setDamageTarget(DamageType dt, bool v)
|
void Entity::setDamageTarget(DamageType dt, bool v)
|
||||||
{
|
{
|
||||||
|
DisabledDamageTypes::iterator it = std::lower_bound(disabledDamageTypes.begin(), disabledDamageTypes.end(), dt);
|
||||||
if (v)
|
if (v)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < disabledDamageTypes.size(); ++i)
|
if(it != disabledDamageTypes.end() && *it == dt)
|
||||||
{
|
disabledDamageTypes.erase(it);
|
||||||
if(disabledDamageTypes[i] == dt)
|
|
||||||
{
|
|
||||||
disabledDamageTypes[i] = disabledDamageTypes.back();
|
|
||||||
disabledDamageTypes.pop_back();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(isDamageTarget(dt))
|
if(it == disabledDamageTypes.end())
|
||||||
disabledDamageTypes.push_back(dt);
|
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)
|
bool Entity::isDamageTarget(DamageType dt)
|
||||||
{
|
{
|
||||||
const size_t sz = disabledDamageTypes.size();
|
return std::binary_search(disabledDamageTypes.begin(), disabledDamageTypes.end(), dt);
|
||||||
for(size_t i = 0; i < sz; ++i)
|
|
||||||
if(disabledDamageTypes[i] == dt)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Entity::getHealthPerc()
|
float Entity::getHealthPerc()
|
||||||
|
|
Loading…
Reference in a new issue