diff --git a/Source/automap.cpp b/Source/automap.cpp index 94da6860b..2c7b1ea86 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -5,6 +5,7 @@ */ #include "automap.h" +#include #include #include @@ -17,7 +18,6 @@ #include "levels/setmaps.h" #include "player.h" #include "utils/language.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/ui_fwd.h" #include "utils/utf8.hpp" @@ -480,7 +480,7 @@ void DrawAutomapTile(const Surface &out, Point center, Point map) AutomapTile tile = GetAutomapTypeView(map); uint8_t colorBright = MapColorsBright; uint8_t colorDim = MapColorsDim; - MapExplorationType explorationType = static_cast(AutomapView[clamp(map.x, 0, DMAXX - 1)][clamp(map.y, 0, DMAXY - 1)]); + MapExplorationType explorationType = static_cast(AutomapView[std::clamp(map.x, 0, DMAXX - 1)][std::clamp(map.y, 0, DMAXY - 1)]); switch (explorationType) { case MAP_EXP_SHRINE: @@ -593,11 +593,11 @@ void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset, i tile.y++; } - const int startX = clamp(tile.x - searchRadius, 0, MAXDUNX); - const int startY = clamp(tile.y - searchRadius, 0, MAXDUNY); + const int startX = std::clamp(tile.x - searchRadius, 0, MAXDUNX); + const int startY = std::clamp(tile.y - searchRadius, 0, MAXDUNY); - const int endX = clamp(tile.x + searchRadius, 0, MAXDUNX); - const int endY = clamp(tile.y + searchRadius, 0, MAXDUNY); + const int endX = std::clamp(tile.x + searchRadius, 0, MAXDUNX); + const int endY = std::clamp(tile.y + searchRadius, 0, MAXDUNY); for (int i = startX; i < endX; i++) { for (int j = startY; j < endY; j++) { diff --git a/Source/control.cpp b/Source/control.cpp index 80ecde88d..d3db112f3 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -214,7 +214,7 @@ void DrawFlask(const Surface &out, const Surface &celBuf, Point sourcePosition, void DrawFlaskUpper(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) { // clamping because this function only draws the top 12% of the flask display - int emptyPortion = clamp(80 - fillPer, 0, 11) + 2; // +2 to account for the frame being included in the sprite + int emptyPortion = std::clamp(80 - fillPer, 0, 11) + 2; // +2 to account for the frame being included in the sprite // Draw the empty part of the flask DrawFlask(out, sourceBuffer, { 13, 3 }, GetMainPanel().position + Displacement { offset, -13 }, emptyPortion); @@ -233,7 +233,7 @@ void DrawFlaskUpper(const Surface &out, const Surface &sourceBuffer, int offset, */ void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) { - int filled = clamp(fillPer, 0, 69); + int filled = std::clamp(fillPer, 0, 69); if (filled < 69) DrawFlaskTop(out, GetMainPanel().position + Displacement { offset, 0 }, sourceBuffer, 16, 85 - filled); diff --git a/Source/controls/controller_motion.cpp b/Source/controls/controller_motion.cpp index c959b35f1..85d2976a3 100644 --- a/Source/controls/controller_motion.cpp +++ b/Source/controls/controller_motion.cpp @@ -48,7 +48,7 @@ void ScaleJoystickAxes(float *x, float *y, float deadzone) analogX = (analogX * scalingFactor); analogY = (analogY * scalingFactor); - // clamp to ensure results will never exceed the max_axis value + // std::clamp to ensure results will never exceed the max_axis value float clampingFactor = 1.F; float absAnalogX = std::fabs(analogX); float absAnalogY = std::fabs(analogY); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 5043225bc..4b7994800 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -753,8 +753,8 @@ void CheckCursMove() mx++; } - mx = clamp(mx, 0, MAXDUNX - 1); - my = clamp(my, 0, MAXDUNY - 1); + mx = std::clamp(mx, 0, MAXDUNX - 1); + my = std::clamp(my, 0, MAXDUNY - 1); const Point currentTile { mx, my }; diff --git a/Source/effects.cpp b/Source/effects.cpp index 5bca71ed4..2fc7bb536 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -5,6 +5,7 @@ */ #include "effects.h" +#include #include #include "engine/random.hpp" @@ -13,7 +14,6 @@ #include "engine/sound_position.hpp" #include "init.h" #include "player.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/str_cat.hpp" namespace devilution { diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 488e3b888..232f5af08 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -6,12 +6,12 @@ #include "animationinfo.h" +#include #include #include "appfat.h" #include "nthread.h" #include "utils/log.hpp" -#include "utils/stdcompat/algorithm.hpp" namespace devilution { @@ -182,7 +182,7 @@ void AnimationInfo::changeAnimationData(OptionalClxSpriteList celSprite, int8_t if (numberOfFrames != this->numberOfFrames || ticksPerFrame != this->ticksPerFrame) { // Ensure that the currentFrame is still valid and that we disable ADL cause the calculcated values (for example tickModifier_) could be wrong if (numberOfFrames >= 1) - currentFrame = clamp(currentFrame, 0, numberOfFrames - 1); + currentFrame = std::clamp(currentFrame, 0, numberOfFrames - 1); else currentFrame = -1; diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 128de0f2c..6869f02f7 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -560,7 +560,7 @@ bool GetRunGameLoop(bool &drawGame, bool &processInput) } } else { int32_t fraction = ticksElapsed * AnimationInfo::baseValueFraction / gnTickDelay; - fraction = clamp(fraction, 0, AnimationInfo::baseValueFraction); + fraction = std::clamp(fraction, 0, AnimationInfo::baseValueFraction); uint8_t progressToNextGameTick = static_cast(fraction); if (dmsg.type == DemoMsgType::GameTick || dmsg.progressToNextGameTick > progressToNextGameTick) { // we are ahead of the replay => add a additional rendering for smoothness diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index 5a77e49ad..9e1271095 100644 --- a/Source/engine/palette.cpp +++ b/Source/engine/palette.cpp @@ -38,7 +38,7 @@ bool sgbFadedIn = true; void LoadGamma() { int gammaValue = *sgOptions.Graphics.gammaCorrection; - gammaValue = clamp(gammaValue, 30, 100); + gammaValue = std::clamp(gammaValue, 30, 100); sgOptions.Graphics.gammaCorrection.SetValue(gammaValue - gammaValue % 5); } diff --git a/Source/engine/point.hpp b/Source/engine/point.hpp index 95a410af3..1c3cf02be 100644 --- a/Source/engine/point.hpp +++ b/Source/engine/point.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #ifdef BUILD_TESTING @@ -8,7 +9,6 @@ #include "engine/direction.hpp" #include "engine/displacement.hpp" -#include "utils/stdcompat/algorithm.hpp" namespace devilution { diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 1d39d2d9e..0fd02324d 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -22,7 +22,6 @@ #include "lighting.h" #include "options.h" #include "utils/attributes.h" -#include "utils/stdcompat/algorithm.hpp" #ifdef DEBUG_STR #include "engine/render/text_render.hpp" #endif @@ -139,7 +138,7 @@ DVL_ALWAYS_INLINE int8_t InitPrefix(int8_t y) template std::string prefixDebugString(int8_t prefix) { std::string out(32, OpaquePrefix ? '0' : '1'); - const uint8_t clamped = clamp(prefix, 0, 32); + const uint8_t clamped = std::clamp(prefix, 0, 32); out.replace(0, clamped, clamped, OpaquePrefix ? '1' : '0'); StrAppend(out, " prefix=", prefix, " OpaquePrefix=", OpaquePrefix, " PrefixIncrement=", PrefixIncrement); return out; @@ -242,7 +241,7 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderLine(uint8_t *DVL_RESTRICT dst, c if (PrefixIncrement == 0) { RenderLineTransparentOrOpaque(dst, src, n, tbl); } else if (prefix >= static_cast(n)) { - // We clamp the prefix to (0, n] and avoid calling `RenderLineTransparent/Opaque` with width=0. + // We std::clamp the prefix to (0, n] and avoid calling `RenderLineTransparent/Opaque` with width=0. if (OpaquePrefix) { RenderLineOpaque(dst, src, n, tbl); } else { diff --git a/Source/engine/sound.cpp b/Source/engine/sound.cpp index d0f704555..b91258818 100644 --- a/Source/engine/sound.cpp +++ b/Source/engine/sound.cpp @@ -5,6 +5,7 @@ */ #include "engine/sound.h" +#include #include #include #include @@ -19,7 +20,6 @@ #include "utils/log.hpp" #include "utils/math.h" #include "utils/sdl_mutex.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/stdcompat/shared_ptr_array.hpp" #include "utils/str_cat.hpp" #include "utils/stubs.h" @@ -152,7 +152,7 @@ const char *const MusicTracks[NUM_MUSIC] = { int CapVolume(int volume) { - return clamp(volume, VOLUME_MIN, VOLUME_MAX); + return std::clamp(volume, VOLUME_MIN, VOLUME_MAX); } } // namespace diff --git a/Source/engine/sound_position.cpp b/Source/engine/sound_position.cpp index 088890a13..9e0afdacd 100644 --- a/Source/engine/sound_position.cpp +++ b/Source/engine/sound_position.cpp @@ -11,7 +11,7 @@ bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan) const Displacement delta = soundPosition - playerPosition; const int pan = (delta.deltaX - delta.deltaY) * 256; - *plPan = clamp(pan, PAN_MIN, PAN_MAX); + *plPan = std::clamp(pan, PAN_MIN, PAN_MAX); const int volume = playerPosition.ApproxDistance(soundPosition) * -64; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 12d6ea3ca..52e78bab8 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -5,6 +5,7 @@ */ #include "gmenu.h" +#include #include #include @@ -20,7 +21,6 @@ #include "options.h" #include "stores.h" #include "utils/language.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/ui_fwd.h" namespace devilution { @@ -161,7 +161,7 @@ bool GmenuMouseIsOverSlider() int GmenuGetSliderFill() { - return clamp(MousePosition.x - SliderValueLeft - GetUIRectangle().position.x, SliderFillMin, SliderFillMax); + return std::clamp(MousePosition.x - SliderValueLeft - GetUIRectangle().position.x, SliderFillMin, SliderFillMax); } } // namespace diff --git a/Source/inv.cpp b/Source/inv.cpp index 737538fd5..2c90416b9 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1752,7 +1752,7 @@ int ClampDurability(const Item &item, int durability) if (item._iMaxDur == 0) return 0; - return clamp(durability, 1, item._iMaxDur); + return std::clamp(durability, 1, item._iMaxDur); } int16_t ClampToHit(const Item &item, int16_t toHit) @@ -1783,8 +1783,8 @@ int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int is item._iIdentified = true; item._iMaxDur = mdur; item._iDurability = ClampDurability(item, dur); - item._iMaxCharges = clamp(mch, 0, item._iMaxCharges); - item._iCharges = clamp(ch, 0, item._iMaxCharges); + item._iMaxCharges = std::clamp(mch, 0, item._iMaxCharges); + item._iCharges = std::clamp(ch, 0, item._iMaxCharges); if (gbIsHellfire) { item._iPLToHit = ClampToHit(item, toHit); item._iMaxDam = ClampMaxDam(item, maxDam); diff --git a/Source/items.cpp b/Source/items.cpp index 86e02f4d6..6a76c4f7c 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -45,7 +45,6 @@ #include "utils/language.h" #include "utils/log.hpp" #include "utils/math.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/str_case.hpp" #include "utils/str_cat.hpp" #include "utils/utf8.hpp" @@ -1992,7 +1991,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player) dexterity += dexterity / 5; magic += magic / 5; - plvl = clamp(plvl, 1, 30); + plvl = std::clamp(plvl, 1, 30); int maxCount = 150; const bool unlimited = !gbIsHellfire; // TODO: This could lead to an infinite loop if a suitable item can never be generated @@ -2664,7 +2663,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx) player._pIBonusDamMod = dmod; player._pIGetHit = ghit; - lrad = clamp(lrad, 2, 15); + lrad = std::clamp(lrad, 2, 15); if (player._pLightRad != lrad) { ChangeLightRadius(player.lightId, lrad); @@ -2742,9 +2741,9 @@ void CalcPlrItemVals(Player &player, bool loadgfx) lr = 0; } - player._pMagResist = clamp(mr, 0, MaxResistance); - player._pFireResist = clamp(fr, 0, MaxResistance); - player._pLghtResist = clamp(lr, 0, MaxResistance); + player._pMagResist = std::clamp(mr, 0, MaxResistance); + player._pFireResist = std::clamp(fr, 0, MaxResistance); + player._pLghtResist = std::clamp(lr, 0, MaxResistance); vadd = (vadd * PlayersData[static_cast(player._pClass)].itmLife) >> 6; ihp += (vadd << 6); // BUGFIX: blood boil can cause negative shifts here (see line 757) diff --git a/Source/levels/drlg_l2.cpp b/Source/levels/drlg_l2.cpp index 1eba5a3e4..eeb7b9fdf 100644 --- a/Source/levels/drlg_l2.cpp +++ b/Source/levels/drlg_l2.cpp @@ -5,6 +5,7 @@ */ #include "levels/drlg_l2.h" +#include #include #include #include @@ -18,7 +19,6 @@ #include "levels/setmaps.h" #include "player.h" #include "quests.h" -#include "utils/stdcompat/algorithm.hpp" namespace devilution { @@ -1788,10 +1788,10 @@ void CreateRoom(WorldTilePosition topLeft, WorldTilePosition bottomRight, int nR roomTopLeft.y = bottomRight.y - roomSize.height; } - roomTopLeft.x = clamp(roomTopLeft.x, 1, 38); - roomTopLeft.y = clamp(roomTopLeft.y, 1, 38); - roomBottomRight.x = clamp(roomBottomRight.x, 1, 38); - roomBottomRight.y = clamp(roomBottomRight.y, 1, 38); + roomTopLeft.x = std::clamp(roomTopLeft.x, 1, 38); + roomTopLeft.y = std::clamp(roomTopLeft.y, 1, 38); + roomBottomRight.x = std::clamp(roomBottomRight.x, 1, 38); + roomBottomRight.y = std::clamp(roomBottomRight.y, 1, 38); DefineRoom(roomTopLeft, roomBottomRight, static_cast(size)); diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index d829ed489..0805825b4 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -151,7 +151,7 @@ public: { static_assert(sizeof(TSource) > sizeof(TDesired), "Can only narrow to a smaller type"); TSource value = SwapLE(Next()) + modifier; - return static_cast(clamp(value, std::numeric_limits::min(), std::numeric_limits::max())); + return static_cast(std::clamp(value, std::numeric_limits::min(), std::numeric_limits::max())); } bool NextBool8() diff --git a/Source/missiles.cpp b/Source/missiles.cpp index dcffcf481..69f9b0438 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -221,7 +221,7 @@ bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, Miss hper = player.GetMagicToHit() - (monster.level(sgGameInitInfo.nDifficulty) * 2) - dist; } - hper = clamp(hper, 5, 95); + hper = std::clamp(hper, 5, 95); if (monster.mode == MonsterMode::Petrified) hit = 0; @@ -337,7 +337,7 @@ bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist, - dist; } - hit = clamp(hit, 5, 95); + hit = std::clamp(hit, 5, 95); if (hper >= hit) { return false; @@ -349,7 +349,7 @@ bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist, } int blk = target.GetBlockChance() - (player._pLevel * 2); - blk = clamp(blk, 0, 100); + blk = std::clamp(blk, 0, 100); int dam; if (mtype == MissileID::BoneSpirit) { @@ -948,7 +948,7 @@ bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, MissileID t int hit = GenerateRnd(100); int hper = 90 - monster.armorClass - dist; - hper = clamp(hper, 5, 95); + hper = std::clamp(hper, 5, 95); if (monster.tryLiftGargoyle()) return true; if (hit >= hper && monster.mode != MonsterMode::Petrified) { @@ -1041,7 +1041,7 @@ bool PlayerMHit(int pnum, Monster *monster, int dist, int mind, int maxd, Missil int blkper = player.GetBlockChance(false); if (monster != nullptr) blkper -= (monster->level(sgGameInitInfo.nDifficulty) - player._pLevel) * 2; - blkper = clamp(blkper, 0, 100); + blkper = std::clamp(blkper, 0, 100); int8_t resper; switch (damageType) { diff --git a/Source/monster.cpp b/Source/monster.cpp index 128e398be..b6e6aa5ad 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1169,7 +1169,7 @@ void MonsterAttackPlayer(Monster &monster, Player &player, int hit, int minDam, blkper = GenerateRnd(100); } int blk = player.GetBlockChance() - (monster.level(sgGameInitInfo.nDifficulty) * 2); - blk = clamp(blk, 0, 100); + blk = std::clamp(blk, 0, 100); if (hper >= hit) return; if (blkper < blk) { diff --git a/Source/msg.cpp b/Source/msg.cpp index 08ed05af9..d6d9dce8b 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -2351,8 +2351,8 @@ void RecreateItem(const Player &player, const TItem &messageItem, Item &item) item._iIdentified = true; item._iMaxDur = messageItem.bMDur; item._iDurability = ClampDurability(item, messageItem.bDur); - item._iMaxCharges = clamp(messageItem.bMCh, 0, item._iMaxCharges); - item._iCharges = clamp(messageItem.bCh, 0, item._iMaxCharges); + item._iMaxCharges = std::clamp(messageItem.bMCh, 0, item._iMaxCharges); + item._iCharges = std::clamp(messageItem.bCh, 0, item._iMaxCharges); if (gbIsHellfire) { item._iPLToHit = ClampToHit(item, SDL_SwapLE16(messageItem.wToHit)); item._iMaxDam = ClampMaxDam(item, SDL_SwapLE16(messageItem.wMaxDam)); diff --git a/Source/nthread.cpp b/Source/nthread.cpp index edc7fa3a6..720cc81eb 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -258,7 +258,7 @@ void nthread_UpdateProgressToNextGameTick() } int ticksAdvanced = gnTickDelay - ticksMissing; int32_t fraction = ticksAdvanced * AnimationInfo::baseValueFraction / gnTickDelay; - fraction = clamp(fraction, 0, AnimationInfo::baseValueFraction); + fraction = std::clamp(fraction, 0, AnimationInfo::baseValueFraction); ProgressToNextGameTick = static_cast(fraction); } diff --git a/Source/options.cpp b/Source/options.cpp index 148a68b24..09f67c02d 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -4,6 +4,7 @@ * Load and save options from the diablo.ini file. */ +#include #include #include @@ -30,7 +31,6 @@ #include "utils/language.h" #include "utils/log.hpp" #include "utils/paths.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/str_cat.hpp" #include "utils/str_split.hpp" #include "utils/utf8.hpp" diff --git a/Source/pack.cpp b/Source/pack.cpp index 851908ac5..6f1df4971 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -404,8 +404,8 @@ void UnPackItem(const ItemPack &packedItem, const Player &player, Item &item, bo item._iIdentified = (packedItem.bId & 1) != 0; item._iMaxDur = packedItem.bMDur; item._iDurability = ClampDurability(item, packedItem.bDur); - item._iMaxCharges = clamp(packedItem.bMCh, 0, item._iMaxCharges); - item._iCharges = clamp(packedItem.bCh, 0, item._iMaxCharges); + item._iMaxCharges = std::clamp(packedItem.bMCh, 0, item._iMaxCharges); + item._iCharges = std::clamp(packedItem.bCh, 0, item._iMaxCharges); RemoveInvalidItem(item); @@ -421,17 +421,17 @@ void UnPackPlayer(const PlayerPack &packed, Player &player) Point position { packed.px, packed.py }; player = {}; - player._pLevel = clamp(packed.pLevel, 1, MaxCharacterLevel); + player._pLevel = std::clamp(packed.pLevel, 1, MaxCharacterLevel); player._pMaxHPBase = SDL_SwapLE32(packed.pMaxHPBase); player._pHPBase = SDL_SwapLE32(packed.pHPBase); - player._pHPBase = clamp(player._pHPBase, 0, player._pMaxHPBase); + player._pHPBase = std::clamp(player._pHPBase, 0, player._pMaxHPBase); player._pMaxHP = player._pMaxHPBase; player._pHitPoints = player._pHPBase; player.position.tile = position; player.position.future = position; - player.setLevel(clamp(packed.plrlevel, 0, NUMLEVELS)); + player.setLevel(std::clamp(packed.plrlevel, 0, NUMLEVELS)); - player._pClass = static_cast(clamp(packed.pClass, 0, enum_size::value - 1)); + player._pClass = static_cast(std::clamp(packed.pClass, 0, enum_size::value - 1)); ClrPlrPath(player); player.destAction = ACTION_NONE; diff --git a/Source/platform/locale.cpp b/Source/platform/locale.cpp index 4dfa84c9c..33aa5908e 100644 --- a/Source/platform/locale.cpp +++ b/Source/platform/locale.cpp @@ -1,5 +1,6 @@ #include "locale.hpp" +#include #include #ifdef __ANDROID__ @@ -26,7 +27,6 @@ #include #endif -#include "utils/stdcompat/algorithm.hpp" #include "utils/stdcompat/string_view.hpp" namespace devilution { diff --git a/Source/player.cpp b/Source/player.cpp index 2000f44bb..a740b8974 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -590,7 +590,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) } hper += player.GetMeleePiercingToHit() - player.CalculateArmorPierce(monster.armorClass, true); - hper = clamp(hper, 5, 95); + hper = std::clamp(hper, 5, 95); if (monster.tryLiftGargoyle()) return true; @@ -754,7 +754,7 @@ bool PlrHitPlr(Player &attacker, Player &target) int hit = GenerateRnd(100); int hper = attacker.GetMeleeToHit() - target.GetArmor(); - hper = clamp(hper, 5, 95); + hper = std::clamp(hper, 5, 95); int blk = 100; if ((target._pmode == PM_STAND || target._pmode == PM_ATTACK) && target._pBlockFlag) { @@ -762,7 +762,7 @@ bool PlrHitPlr(Player &attacker, Player &target) } int blkper = target.GetBlockChance() - (attacker._pLevel * 2); - blkper = clamp(blkper, 0, 100); + blkper = std::clamp(blkper, 0, 100); if (hit >= hper) { return false; @@ -2193,7 +2193,7 @@ void NewPlrAnim(Player &player, player_graphic graphic, Direction dir, Animation if (!HeadlessMode) { sprites = player.AnimationData[static_cast(graphic)].spritesForDirection(dir); if (player.previewCelSprite && (*sprites)[0] == *player.previewCelSprite && !player.isWalking()) { - previewShownGameTickFragments = clamp(AnimationInfo::baseValueFraction - player.progressToNextGameTickWhenPreviewWasSet, 0, AnimationInfo::baseValueFraction); + previewShownGameTickFragments = std::clamp(AnimationInfo::baseValueFraction - player.progressToNextGameTickWhenPreviewWasSet, 0, AnimationInfo::baseValueFraction); } } @@ -2447,7 +2447,7 @@ void AddPlrExperience(Player &player, int lvl, int exp) // Prevent power leveling if (gbIsMultiplayer) { - const uint32_t clampedPlayerLevel = clamp(static_cast(player._pLevel), 1, MaxCharacterLevel); + const uint32_t clampedPlayerLevel = std::clamp(static_cast(player._pLevel), 1, MaxCharacterLevel); // for low level characters experience gain is capped to 1/20 of current levels xp // for high level characters experience gain is capped to 200 * current level - this is a smaller value than 1/20 of the exp needed for the next level after level 5. @@ -3303,16 +3303,16 @@ void CheckStats(Player &player) int maxStatPoint = player.GetMaximumAttributeValue(attribute); switch (attribute) { case CharacterAttribute::Strength: - player._pBaseStr = clamp(player._pBaseStr, 0, maxStatPoint); + player._pBaseStr = std::clamp(player._pBaseStr, 0, maxStatPoint); break; case CharacterAttribute::Magic: - player._pBaseMag = clamp(player._pBaseMag, 0, maxStatPoint); + player._pBaseMag = std::clamp(player._pBaseMag, 0, maxStatPoint); break; case CharacterAttribute::Dexterity: - player._pBaseDex = clamp(player._pBaseDex, 0, maxStatPoint); + player._pBaseDex = std::clamp(player._pBaseDex, 0, maxStatPoint); break; case CharacterAttribute::Vitality: - player._pBaseVit = clamp(player._pBaseVit, 0, maxStatPoint); + player._pBaseVit = std::clamp(player._pBaseVit, 0, maxStatPoint); break; } } @@ -3320,7 +3320,7 @@ void CheckStats(Player &player) void ModifyPlrStr(Player &player, int l) { - l = clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Strength) - player._pBaseStr); + l = std::clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Strength) - player._pBaseStr); player._pStrength += l; player._pBaseStr += l; @@ -3334,7 +3334,7 @@ void ModifyPlrStr(Player &player, int l) void ModifyPlrMag(Player &player, int l) { - l = clamp(l, 0 - player._pBaseMag, player.GetMaximumAttributeValue(CharacterAttribute::Magic) - player._pBaseMag); + l = std::clamp(l, 0 - player._pBaseMag, player.GetMaximumAttributeValue(CharacterAttribute::Magic) - player._pBaseMag); player._pMagic += l; player._pBaseMag += l; @@ -3358,7 +3358,7 @@ void ModifyPlrMag(Player &player, int l) void ModifyPlrDex(Player &player, int l) { - l = clamp(l, 0 - player._pBaseDex, player.GetMaximumAttributeValue(CharacterAttribute::Dexterity) - player._pBaseDex); + l = std::clamp(l, 0 - player._pBaseDex, player.GetMaximumAttributeValue(CharacterAttribute::Dexterity) - player._pBaseDex); player._pDexterity += l; player._pBaseDex += l; @@ -3371,7 +3371,7 @@ void ModifyPlrDex(Player &player, int l) void ModifyPlrVit(Player &player, int l) { - l = clamp(l, 0 - player._pBaseVit, player.GetMaximumAttributeValue(CharacterAttribute::Vitality) - player._pBaseVit); + l = std::clamp(l, 0 - player._pBaseVit, player.GetMaximumAttributeValue(CharacterAttribute::Vitality) - player._pBaseVit); player._pVitality += l; player._pBaseVit += l; diff --git a/Source/player.h b/Source/player.h index e7a1cf455..a466f2a91 100644 --- a/Source/player.h +++ b/Source/player.h @@ -25,7 +25,6 @@ #include "spelldat.h" #include "utils/attributes.h" #include "utils/enum_traits.h" -#include "utils/stdcompat/algorithm.hpp" namespace devilution { @@ -638,7 +637,7 @@ struct Player { // Maximum achievable HP is approximately 1200. Diablo uses fixed point integers where the last 6 bits are // fractional values. This means that we will never overflow HP values normally by doing this multiplication // as the max value is representable in 17 bits and the multiplication result will be at most 23 bits - _pHPPer = clamp(_pHitPoints * 80 / _pMaxHP, 0, 80); // hp should never be greater than maxHP but just in case + _pHPPer = std::clamp(_pHitPoints * 80 / _pMaxHP, 0, 80); // hp should never be greater than maxHP but just in case } return _pHPPer; @@ -649,7 +648,7 @@ struct Player { if (_pMaxMana <= 0) { _pManaPer = 0; } else { - _pManaPer = clamp(_pMana * 80 / _pMaxMana, 0, 80); + _pManaPer = std::clamp(_pMana * 80 / _pMaxMana, 0, 80); } return _pManaPer; diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 14e5105e3..867f117e3 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -1,5 +1,6 @@ #include "qol/stash.h" +#include #include #include @@ -20,7 +21,6 @@ #include "stores.h" #include "utils/format_int.hpp" #include "utils/language.h" -#include "utils/stdcompat/algorithm.hpp" #include "utils/str_cat.hpp" #include "utils/utf8.hpp" diff --git a/Source/stores.cpp b/Source/stores.cpp index b8a95ae0a..230686cdf 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2135,7 +2135,7 @@ void SetupTownStores() SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks()); } - l = clamp(l + 2, 6, 16); + l = std::clamp(l + 2, 6, 16); SpawnSmith(l); SpawnWitch(l); SpawnHealer(l); diff --git a/Source/utils/stdcompat/algorithm.hpp b/Source/utils/stdcompat/algorithm.hpp deleted file mode 100644 index 7c29d8b69..000000000 --- a/Source/utils/stdcompat/algorithm.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include // IWYU pragma: export - -namespace devilution { -using ::std::clamp; -} // namespace devilution