Browse Source

Remove utils/stdcompat/algorithm.hpp

pull/6464/head
Gleb Mazovetskiy 3 years ago
parent
commit
c19bfe87fa
  1. 12
      Source/automap.cpp
  2. 4
      Source/control.cpp
  3. 2
      Source/controls/controller_motion.cpp
  4. 4
      Source/cursor.cpp
  5. 2
      Source/effects.cpp
  6. 4
      Source/engine/animationinfo.cpp
  7. 2
      Source/engine/demomode.cpp
  8. 2
      Source/engine/palette.cpp
  9. 2
      Source/engine/point.hpp
  10. 5
      Source/engine/render/dun_render.cpp
  11. 4
      Source/engine/sound.cpp
  12. 2
      Source/engine/sound_position.cpp
  13. 4
      Source/gmenu.cpp
  14. 6
      Source/inv.cpp
  15. 11
      Source/items.cpp
  16. 10
      Source/levels/drlg_l2.cpp
  17. 2
      Source/loadsave.cpp
  18. 10
      Source/missiles.cpp
  19. 2
      Source/monster.cpp
  20. 4
      Source/msg.cpp
  21. 2
      Source/nthread.cpp
  22. 2
      Source/options.cpp
  23. 12
      Source/pack.cpp
  24. 2
      Source/platform/locale.cpp
  25. 26
      Source/player.cpp
  26. 5
      Source/player.h
  27. 2
      Source/qol/stash.cpp
  28. 2
      Source/stores.cpp
  29. 7
      Source/utils/stdcompat/algorithm.hpp

12
Source/automap.cpp

@ -5,6 +5,7 @@
*/
#include "automap.h"
#include <algorithm>
#include <cstdint>
#include <fmt/format.h>
@ -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<MapExplorationType>(AutomapView[clamp(map.x, 0, DMAXX - 1)][clamp(map.y, 0, DMAXY - 1)]);
MapExplorationType explorationType = static_cast<MapExplorationType>(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++) {

4
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);

2
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);

4
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 };

2
Source/effects.cpp

@ -5,6 +5,7 @@
*/
#include "effects.h"
#include <algorithm>
#include <cstdint>
#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 {

4
Source/engine/animationinfo.cpp

@ -6,12 +6,12 @@
#include "animationinfo.h"
#include <algorithm>
#include <cstdint>
#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<int8_t>(currentFrame, 0, numberOfFrames - 1);
currentFrame = std::clamp<int8_t>(currentFrame, 0, numberOfFrames - 1);
else
currentFrame = -1;

2
Source/engine/demomode.cpp

@ -560,7 +560,7 @@ bool GetRunGameLoop(bool &drawGame, bool &processInput)
}
} else {
int32_t fraction = ticksElapsed * AnimationInfo::baseValueFraction / gnTickDelay;
fraction = clamp<int32_t>(fraction, 0, AnimationInfo::baseValueFraction);
fraction = std::clamp<int32_t>(fraction, 0, AnimationInfo::baseValueFraction);
uint8_t progressToNextGameTick = static_cast<uint8_t>(fraction);
if (dmsg.type == DemoMsgType::GameTick || dmsg.progressToNextGameTick > progressToNextGameTick) {
// we are ahead of the replay => add a additional rendering for smoothness

2
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);
}

2
Source/engine/point.hpp

@ -1,5 +1,6 @@
#pragma once
#include <algorithm>
#include <cmath>
#include <type_traits>
#ifdef BUILD_TESTING
@ -8,7 +9,6 @@
#include "engine/direction.hpp"
#include "engine/displacement.hpp"
#include "utils/stdcompat/algorithm.hpp"
namespace devilution {

5
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 <bool OpaquePrefix, int8_t PrefixIncrement>
std::string prefixDebugString(int8_t prefix) {
std::string out(32, OpaquePrefix ? '0' : '1');
const uint8_t clamped = clamp<int8_t>(prefix, 0, 32);
const uint8_t clamped = std::clamp<int8_t>(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<Light, OpaquePrefix>(dst, src, n, tbl);
} else if (prefix >= static_cast<int8_t>(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<Light>(dst, src, n, tbl);
} else {

4
Source/engine/sound.cpp

@ -5,6 +5,7 @@
*/
#include "engine/sound.h"
#include <algorithm>
#include <cstdint>
#include <list>
#include <memory>
@ -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

2
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;

4
Source/gmenu.cpp

@ -5,6 +5,7 @@
*/
#include "gmenu.h"
#include <algorithm>
#include <cstdint>
#include <optional>
@ -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

6
Source/inv.cpp

@ -1752,7 +1752,7 @@ int ClampDurability(const Item &item, int durability)
if (item._iMaxDur == 0)
return 0;
return clamp<int>(durability, 1, item._iMaxDur);
return std::clamp<int>(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<int>(mch, 0, item._iMaxCharges);
item._iCharges = clamp<int>(ch, 0, item._iMaxCharges);
item._iMaxCharges = std::clamp<int>(mch, 0, item._iMaxCharges);
item._iCharges = std::clamp<int>(ch, 0, item._iMaxCharges);
if (gbIsHellfire) {
item._iPLToHit = ClampToHit(item, toHit);
item._iMaxDam = ClampMaxDam(item, maxDam);

11
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<size_t>(player._pClass)].itmLife) >> 6;
ihp += (vadd << 6); // BUGFIX: blood boil can cause negative shifts here (see line 757)

10
Source/levels/drlg_l2.cpp

@ -5,6 +5,7 @@
*/
#include "levels/drlg_l2.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <list>
@ -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<WorldTileCoord>(roomTopLeft.x, 1, 38);
roomTopLeft.y = clamp<WorldTileCoord>(roomTopLeft.y, 1, 38);
roomBottomRight.x = clamp<WorldTileCoord>(roomBottomRight.x, 1, 38);
roomBottomRight.y = clamp<WorldTileCoord>(roomBottomRight.y, 1, 38);
roomTopLeft.x = std::clamp<WorldTileCoord>(roomTopLeft.x, 1, 38);
roomTopLeft.y = std::clamp<WorldTileCoord>(roomTopLeft.y, 1, 38);
roomBottomRight.x = std::clamp<WorldTileCoord>(roomBottomRight.x, 1, 38);
roomBottomRight.y = std::clamp<WorldTileCoord>(roomBottomRight.y, 1, 38);
DefineRoom(roomTopLeft, roomBottomRight, static_cast<bool>(size));

2
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<TSource>()) + modifier;
return static_cast<TDesired>(clamp<TSource>(value, std::numeric_limits<TDesired>::min(), std::numeric_limits<TDesired>::max()));
return static_cast<TDesired>(std::clamp<TSource>(value, std::numeric_limits<TDesired>::min(), std::numeric_limits<TDesired>::max()));
}
bool NextBool8()

10
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) {

2
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) {

4
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<int>(messageItem.bMCh, 0, item._iMaxCharges);
item._iCharges = clamp<int>(messageItem.bCh, 0, item._iMaxCharges);
item._iMaxCharges = std::clamp<int>(messageItem.bMCh, 0, item._iMaxCharges);
item._iCharges = std::clamp<int>(messageItem.bCh, 0, item._iMaxCharges);
if (gbIsHellfire) {
item._iPLToHit = ClampToHit(item, SDL_SwapLE16(messageItem.wToHit));
item._iMaxDam = ClampMaxDam(item, SDL_SwapLE16(messageItem.wMaxDam));

2
Source/nthread.cpp

@ -258,7 +258,7 @@ void nthread_UpdateProgressToNextGameTick()
}
int ticksAdvanced = gnTickDelay - ticksMissing;
int32_t fraction = ticksAdvanced * AnimationInfo::baseValueFraction / gnTickDelay;
fraction = clamp<int32_t>(fraction, 0, AnimationInfo::baseValueFraction);
fraction = std::clamp<int32_t>(fraction, 0, AnimationInfo::baseValueFraction);
ProgressToNextGameTick = static_cast<uint8_t>(fraction);
}

2
Source/options.cpp

@ -4,6 +4,7 @@
* Load and save options from the diablo.ini file.
*/
#include <algorithm>
#include <cstdint>
#include <cstdio>
@ -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"

12
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<int>(packedItem.bMCh, 0, item._iMaxCharges);
item._iCharges = clamp<int>(packedItem.bCh, 0, item._iMaxCharges);
item._iMaxCharges = std::clamp<int>(packedItem.bMCh, 0, item._iMaxCharges);
item._iCharges = std::clamp<int>(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<int8_t>(packed.pLevel, 1, MaxCharacterLevel);
player._pLevel = std::clamp<int8_t>(packed.pLevel, 1, MaxCharacterLevel);
player._pMaxHPBase = SDL_SwapLE32(packed.pMaxHPBase);
player._pHPBase = SDL_SwapLE32(packed.pHPBase);
player._pHPBase = clamp<int32_t>(player._pHPBase, 0, player._pMaxHPBase);
player._pHPBase = std::clamp<int32_t>(player._pHPBase, 0, player._pMaxHPBase);
player._pMaxHP = player._pMaxHPBase;
player._pHitPoints = player._pHPBase;
player.position.tile = position;
player.position.future = position;
player.setLevel(clamp<int8_t>(packed.plrlevel, 0, NUMLEVELS));
player.setLevel(std::clamp<int8_t>(packed.plrlevel, 0, NUMLEVELS));
player._pClass = static_cast<HeroClass>(clamp<uint8_t>(packed.pClass, 0, enum_size<HeroClass>::value - 1));
player._pClass = static_cast<HeroClass>(std::clamp<uint8_t>(packed.pClass, 0, enum_size<HeroClass>::value - 1));
ClrPlrPath(player);
player.destAction = ACTION_NONE;

2
Source/platform/locale.cpp

@ -1,5 +1,6 @@
#include "locale.hpp"
#include <algorithm>
#include <cstdint>
#ifdef __ANDROID__
@ -26,7 +27,6 @@
#include <clocale>
#endif
#include "utils/stdcompat/algorithm.hpp"
#include "utils/stdcompat/string_view.hpp"
namespace devilution {

26
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<size_t>(graphic)].spritesForDirection(dir);
if (player.previewCelSprite && (*sprites)[0] == *player.previewCelSprite && !player.isWalking()) {
previewShownGameTickFragments = clamp<int>(AnimationInfo::baseValueFraction - player.progressToNextGameTickWhenPreviewWasSet, 0, AnimationInfo::baseValueFraction);
previewShownGameTickFragments = std::clamp<int>(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<int>(player._pLevel), 1, MaxCharacterLevel);
const uint32_t clampedPlayerLevel = std::clamp(static_cast<int>(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;

5
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;

2
Source/qol/stash.cpp

@ -1,5 +1,6 @@
#include "qol/stash.h"
#include <algorithm>
#include <cstdint>
#include <utility>
@ -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"

2
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);

7
Source/utils/stdcompat/algorithm.hpp

@ -1,7 +0,0 @@
#pragma once
#include <algorithm> // IWYU pragma: export
namespace devilution {
using ::std::clamp;
} // namespace devilution
Loading…
Cancel
Save