mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Replaced vstd clamp with std version
This commit is contained in:
parent
5f74aca341
commit
506c3d29bc
23
Global.h
23
Global.h
@ -425,27 +425,11 @@ namespace vstd
|
||||
}
|
||||
}
|
||||
|
||||
// c++17: makes a to fit the range <b, c>
|
||||
template <typename t1, typename t2, typename t3>
|
||||
t1 clamp(const t1 &value, const t2 &low, const t3 &high)
|
||||
{
|
||||
if ( value > high)
|
||||
return high;
|
||||
|
||||
if ( value < low)
|
||||
return low;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
//makes a to fit the range <b, c>
|
||||
template <typename t1, typename t2, typename t3>
|
||||
t1 &abetween(t1 &a, const t2 &b, const t3 &c)
|
||||
template <typename T>
|
||||
void abetween(T &value, const T &min, const T &max)
|
||||
{
|
||||
amax(a,b);
|
||||
amin(a,c);
|
||||
return a;
|
||||
value = std::clamp(value, min, max);
|
||||
}
|
||||
|
||||
//checks if a is between b and c
|
||||
@ -727,7 +711,6 @@ namespace vstd
|
||||
return a + (b - a) * f;
|
||||
}
|
||||
|
||||
|
||||
///compile-time version of std::abs for ints for int3, in clang++15 std::abs is constexpr
|
||||
static constexpr int abs(int i) {
|
||||
if(i < 0) return -i;
|
||||
|
@ -759,7 +759,7 @@ uint32_t ShootingAnimation::getAttackClimaxFrame() const
|
||||
|
||||
uint32_t maxFrames = stackAnimation(attackingStack)->framesInGroup(getGroup());
|
||||
uint32_t climaxFrame = shooterInfo->animation.attackClimaxFrame;
|
||||
uint32_t selectedFrame = vstd::clamp(shooterInfo->animation.attackClimaxFrame, 1, maxFrames);
|
||||
uint32_t selectedFrame = std::clamp<int>(shooterInfo->animation.attackClimaxFrame, 1, maxFrames);
|
||||
|
||||
if (climaxFrame != selectedFrame)
|
||||
logGlobal->warn("Shooter %s has ranged attack climax frame set to %d, but only %d available!", shooterInfo->getNamePluralTranslated(), climaxFrame, maxFrames);
|
||||
|
@ -58,10 +58,10 @@ void MapViewController::setViewCenter(const Point & position, int level)
|
||||
lowerLimit = actualLowerLimit;
|
||||
}
|
||||
|
||||
Point betterPosition = {vstd::clamp(position.x, lowerLimit.x, upperLimit.x), vstd::clamp(position.y, lowerLimit.y, upperLimit.y)};
|
||||
Point betterPosition = {std::clamp(position.x, lowerLimit.x, upperLimit.x), std::clamp(position.y, lowerLimit.y, upperLimit.y)};
|
||||
|
||||
model->setViewCenter(betterPosition);
|
||||
model->setLevel(vstd::clamp(level, 0, context->getMapSize().z));
|
||||
model->setLevel(std::clamp(level, 0, context->getMapSize().z));
|
||||
|
||||
if(adventureInt) // may be called before adventureInt is initialized
|
||||
adventureInt->onMapViewMoved(model->getTilesTotalRect(), model->getLevel());
|
||||
|
@ -488,7 +488,7 @@ void CVolumeSlider::setVolume(int value_)
|
||||
|
||||
void CVolumeSlider::moveTo(int id)
|
||||
{
|
||||
vstd::abetween(id, 0, animImage->size() - 1);
|
||||
vstd::abetween<int>(id, 0, animImage->size() - 1);
|
||||
animImage->setFrame(id);
|
||||
animImage->moveTo(Point(pos.x + (animImage->pos.w + 1) * id, pos.y));
|
||||
if (active)
|
||||
|
@ -433,7 +433,7 @@ void CSpellWindow::keyPressed(const SDL_Keycode & key)
|
||||
int index = -1;
|
||||
while(schoolsOrder[++index] != selectedTab);
|
||||
index += (down ? 1 : -1);
|
||||
vstd::abetween(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
||||
vstd::abetween<int>(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
||||
if(selectedTab != schoolsOrder[index])
|
||||
selectSchool(schoolsOrder[index]);
|
||||
break;
|
||||
|
@ -1907,7 +1907,7 @@ void CObjectListWindow::keyPressed (const SDL_Keycode & key)
|
||||
return;
|
||||
}
|
||||
|
||||
vstd::abetween(sel, 0, items.size()-1);
|
||||
vstd::abetween<int>(sel, 0, items.size()-1);
|
||||
list->scrollTo(sel);
|
||||
changeSelection(sel);
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ int BonusList::totalValue() const
|
||||
};
|
||||
|
||||
auto percent = [](int64_t base, int64_t percent) -> int {
|
||||
return static_cast<int>(vstd::clamp((base * (100 + percent)) / 100, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
|
||||
return static_cast<int>(std::clamp<int64_t>((base * (100 + percent)) / 100, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
|
||||
};
|
||||
std::array <BonusCollection, Bonus::BonusSource::NUM_BONUS_SOURCE> sources = {};
|
||||
BonusCollection any;
|
||||
@ -520,7 +520,7 @@ int BonusList::totalValue() const
|
||||
}));
|
||||
|
||||
if(notIndepBonuses)
|
||||
return vstd::clamp(valFirst, any.indepMax, any.indepMin);
|
||||
return std::clamp(valFirst, any.indepMax, any.indepMin);
|
||||
|
||||
return hasIndepMin ? any.indepMin : hasIndepMax ? any.indepMax : 0;
|
||||
}
|
||||
@ -709,9 +709,7 @@ int IBonusBearer::MoraleVal() const
|
||||
if(anaffectedByMorale.getHasBonus())
|
||||
return 0;
|
||||
|
||||
int ret = moraleValue.getValue();
|
||||
|
||||
return vstd::abetween(ret, -3, +3);
|
||||
return std::clamp(moraleValue.getValue(), -3, +3);
|
||||
}
|
||||
|
||||
int IBonusBearer::LuckVal() const
|
||||
@ -719,9 +717,7 @@ int IBonusBearer::LuckVal() const
|
||||
if(hasBonusOfType(Bonus::NO_LUCK))
|
||||
return 0;
|
||||
|
||||
int ret = luckValue.getValue();
|
||||
|
||||
return vstd::abetween(ret, -3, +3);
|
||||
return std::clamp(luckValue.getValue(), -3, +3);
|
||||
}
|
||||
|
||||
int IBonusBearer::MoraleValAndBonusList(TConstBonusListPtr & bonusList) const
|
||||
@ -732,9 +728,8 @@ int IBonusBearer::MoraleValAndBonusList(TConstBonusListPtr & bonusList) const
|
||||
bonusList = std::make_shared<const BonusList>();
|
||||
return 0;
|
||||
}
|
||||
int ret = moraleValue.getValueAndList(bonusList);
|
||||
|
||||
return vstd::abetween(ret, -3, +3);
|
||||
return std::clamp(moraleValue.getValueAndList(bonusList), -3, +3);
|
||||
}
|
||||
|
||||
int IBonusBearer::LuckValAndBonusList(TConstBonusListPtr & bonusList) const
|
||||
@ -745,9 +740,8 @@ int IBonusBearer::LuckValAndBonusList(TConstBonusListPtr & bonusList) const
|
||||
bonusList = std::make_shared<const BonusList>();
|
||||
return 0;
|
||||
}
|
||||
int ret = luckValue.getValueAndList(bonusList);
|
||||
|
||||
return vstd::abetween(ret, -3, +3);
|
||||
return std::clamp(luckValue.getValueAndList(bonusList), -3, +3);
|
||||
}
|
||||
|
||||
ui32 IBonusBearer::MaxHealth() const
|
||||
|
@ -1688,7 +1688,9 @@ void RebalanceStacks::applyGs(CGameState * gs)
|
||||
|
||||
if(srcCount == count) //moving whole stack
|
||||
{
|
||||
if([[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
|
||||
[[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot);
|
||||
|
||||
if(c) //stack at dest -> merge
|
||||
{
|
||||
assert(c == srcType);
|
||||
auto alHere = ArtifactLocation (src.getStack(), ArtifactPosition::CREATURE_SLOT);
|
||||
@ -1742,7 +1744,8 @@ void RebalanceStacks::applyGs(CGameState * gs)
|
||||
}
|
||||
else
|
||||
{
|
||||
if([[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
|
||||
[[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot);
|
||||
if(c) //stack at dest -> rebalance
|
||||
{
|
||||
assert(c == srcType);
|
||||
if (stackExp)
|
||||
|
@ -249,7 +249,7 @@ void CHealth::heal(int64_t & amount, EHealLevel level, EHealPower power)
|
||||
}
|
||||
|
||||
vstd::amax(maxHeal, 0);
|
||||
vstd::abetween(amount, 0, maxHeal);
|
||||
vstd::abetween(amount, int64_t(0), maxHeal);
|
||||
|
||||
if(amount == 0)
|
||||
return;
|
||||
|
@ -66,15 +66,14 @@ void CCreGenAsCastleInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
void CCreGenLeveledInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
handler.serializeInt("minLevel", minLevel, static_cast<ui8>(1));
|
||||
handler.serializeInt("maxLevel", maxLevel, static_cast<ui8>(7));
|
||||
handler.serializeInt("minLevel", minLevel, static_cast<uint8_t>(1));
|
||||
handler.serializeInt("maxLevel", maxLevel, static_cast<uint8_t>(7));
|
||||
|
||||
if(!handler.saving)
|
||||
{
|
||||
//todo: safely allow any level > 7
|
||||
vstd::amax(minLevel, 1);
|
||||
vstd::amin(minLevel, 7);
|
||||
vstd::abetween(maxLevel, minLevel, 7);
|
||||
vstd::abetween<uint8_t>(minLevel, 1, 7);
|
||||
vstd::abetween<uint8_t>(maxLevel, minLevel, 7);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ void ApplyOnServerNetPackVisitor::visitLobbySetTurnTime(LobbySetTurnTime & pack)
|
||||
|
||||
void ApplyOnServerNetPackVisitor::visitLobbySetDifficulty(LobbySetDifficulty & pack)
|
||||
{
|
||||
srv.si->difficulty = vstd::abetween(pack.difficulty, 0, 4);
|
||||
srv.si->difficulty = std::clamp<uint8_t>(pack.difficulty, 0, 4);
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user