diff --git a/Source/automap.cpp b/Source/automap.cpp index 3147beeac..609dba2c3 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -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++) { diff --git a/Source/engine.h b/Source/engine.h index 818e070d8..c75043c82 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -27,6 +27,16 @@ namespace devilution { +#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 0) +using std::clamp; +#else +template +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; \ diff --git a/Source/items.cpp b/Source/items.cpp index 70ce940ab..7eefec76a 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -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;