1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

hacks to optimize a few bonus requests

This commit is contained in:
Andrii Danylchenko
2020-06-28 16:19:27 +03:00
parent cc75b859d4
commit d782ee39df
6 changed files with 200 additions and 141 deletions

View File

@@ -19,99 +19,6 @@
namespace battle
{
CTotalsProxy::CTotalsProxy(const IBonusBearer * Target, CSelector Selector, int InitialValue)
: target(Target),
selector(Selector),
initialValue(InitialValue),
meleeCachedLast(0),
meleeValue(0),
rangedCachedLast(0),
rangedValue(0)
{
}
CTotalsProxy::CTotalsProxy(const CTotalsProxy & other)
: target(other.target),
selector(other.selector),
initialValue(other.initialValue),
meleeCachedLast(other.meleeCachedLast),
meleeValue(other.meleeValue),
rangedCachedLast(other.rangedCachedLast),
rangedValue(other.rangedValue)
{
}
CTotalsProxy & CTotalsProxy::operator=(const CTotalsProxy & other)
{
initialValue = other.initialValue;
meleeCachedLast = other.meleeCachedLast;
meleeValue = other.meleeValue;
rangedCachedLast = other.rangedCachedLast;
rangedValue = other.rangedValue;
return *this;
}
int CTotalsProxy::getMeleeValue() const
{
static const auto limit = Selector::effectRange(Bonus::NO_LIMIT).Or(Selector::effectRange(Bonus::ONLY_MELEE_FIGHT));
const auto treeVersion = target->getTreeVersion();
if(treeVersion != meleeCachedLast)
{
auto bonuses = target->getBonuses(selector, limit);
meleeValue = initialValue + bonuses->totalValue();
meleeCachedLast = treeVersion;
}
return meleeValue;
}
int CTotalsProxy::getRangedValue() const
{
static const auto limit = Selector::effectRange(Bonus::NO_LIMIT).Or(Selector::effectRange(Bonus::ONLY_DISTANCE_FIGHT));
const auto treeVersion = target->getTreeVersion();
if(treeVersion != rangedCachedLast)
{
auto bonuses = target->getBonuses(selector, limit);
rangedValue = initialValue + bonuses->totalValue();
rangedCachedLast = treeVersion;
}
return rangedValue;
}
///CCheckProxy
CCheckProxy::CCheckProxy(const IBonusBearer * Target, CSelector Selector)
: target(Target),
selector(Selector),
cachedLast(0),
hasBonus(false)
{
}
CCheckProxy::CCheckProxy(const CCheckProxy & other)
: target(other.target),
selector(other.selector),
cachedLast(other.cachedLast),
hasBonus(other.hasBonus)
{
}
bool CCheckProxy::getHasBonus() const
{
const auto treeVersion = target->getTreeVersion();
if(treeVersion != cachedLast)
{
hasBonus = target->hasBonus(selector);
cachedLast = treeVersion;
}
return hasBonus;
}
///CAmmo
CAmmo::CAmmo(const battle::Unit * Owner, CSelector totalSelector)
: used(0),