💚 Packport std::clamp for pre GCC 7.1
This commit is contained in:
parent
a5f062b747
commit
433fc9fa8d
3 changed files with 19 additions and 9 deletions
|
|
@ -257,11 +257,11 @@ void SearchAutomapItem(const CelOutputBuffer &out)
|
|||
y++;
|
||||
}
|
||||
|
||||
const int startX = std::clamp(x - 8, 0, MAXDUNX);
|
||||
const int startY = std::clamp(y - 8, 0, MAXDUNY);
|
||||
const int startX = clamp(x - 8, 0, MAXDUNX);
|
||||
const int startY = clamp(y - 8, 0, MAXDUNY);
|
||||
|
||||
const int endX = std::clamp(x + 8, 0, MAXDUNX);
|
||||
const int endY = std::clamp(y + 8, 0, MAXDUNY);
|
||||
const int endX = clamp(x + 8, 0, MAXDUNX);
|
||||
const int endY = clamp(y + 8, 0, MAXDUNY);
|
||||
|
||||
for (int i = startX; i < endX; i++) {
|
||||
for (int j = startY; j < endY; j++) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,16 @@
|
|||
|
||||
namespace devilution {
|
||||
|
||||
#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 0)
|
||||
using std::clamp;
|
||||
#else
|
||||
template <typename T>
|
||||
constexpr const T &clamp(const T &x, const T &lower, const T &upper)
|
||||
{
|
||||
return std::min(std::max(x, lower), upper);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MemFreeDbg(p) \
|
||||
{ \
|
||||
void *p__p; \
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ void CalcPlrItemVals(int p, bool Loadgfx)
|
|||
plr[p]._pIBonusDamMod = dmod;
|
||||
plr[p]._pIGetHit = ghit;
|
||||
|
||||
lrad = std::clamp(lrad, 2, 15);
|
||||
lrad = clamp(lrad, 2, 15);
|
||||
|
||||
if (plr[p]._pLightRad != lrad && p == myplr) {
|
||||
ChangeLightRadius(plr[p]._plid, lrad);
|
||||
|
|
@ -752,9 +752,9 @@ void CalcPlrItemVals(int p, bool Loadgfx)
|
|||
lr = 0;
|
||||
}
|
||||
|
||||
plr[p]._pMagResist = std::clamp(mr, 0, MAXRESIST);
|
||||
plr[p]._pFireResist = std::clamp(fr, 0, MAXRESIST);
|
||||
plr[p]._pLghtResist = std::clamp(lr, 0, MAXRESIST);
|
||||
plr[p]._pMagResist = clamp(mr, 0, MAXRESIST);
|
||||
plr[p]._pFireResist = clamp(fr, 0, MAXRESIST);
|
||||
plr[p]._pLghtResist = clamp(lr, 0, MAXRESIST);
|
||||
|
||||
if (plr[p]._pClass == HeroClass::Warrior) {
|
||||
vadd *= 2;
|
||||
|
|
@ -4383,7 +4383,7 @@ static void SpawnOnePremium(int i, int plvl, int myplr)
|
|||
dexterity *= 1.2;
|
||||
magic *= 1.2;
|
||||
|
||||
plvl = std::clamp(plvl, 1, 30);
|
||||
plvl = clamp(plvl, 1, 30);
|
||||
|
||||
int count = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue