diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index c47032720..14cfb3c8c 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -401,11 +401,12 @@ void UiSettingsMenu() if (selectedOption == pEntry) itemToSelect = vecDialogItems.size(); auto formatArgs = CreateDrawStringFormatArgForEntry(pEntry); + int optionId = static_cast(vecOptions.size()); if (NeedsTwoLinesToDisplayOption(formatArgs)) { - vecDialogItems.push_back(std::make_unique("{}:", formatArgs, vecOptions.size(), UiFlags::ColorUiGold | UiFlags::NeedsNextElement)); - vecDialogItems.push_back(std::make_unique(pEntry->GetValueDescription(), vecOptions.size(), UiFlags::ColorUiSilver | UiFlags::ElementDisabled)); + vecDialogItems.push_back(std::make_unique("{}:", formatArgs, optionId, UiFlags::ColorUiGold | UiFlags::NeedsNextElement)); + vecDialogItems.push_back(std::make_unique(pEntry->GetValueDescription(), optionId, UiFlags::ColorUiSilver | UiFlags::ElementDisabled)); } else { - vecDialogItems.push_back(std::make_unique("{}: {}", formatArgs, vecOptions.size(), UiFlags::ColorUiGold)); + vecDialogItems.push_back(std::make_unique("{}: {}", formatArgs, optionId, UiFlags::ColorUiGold)); } vecOptions.push_back(pEntry); } @@ -413,7 +414,7 @@ void UiSettingsMenu() case ShownMenuType::ListOption: { auto *pOptionList = static_cast(selectedOption); for (size_t i = 0; i < pOptionList->GetListSize(); i++) { - vecDialogItems.push_back(std::make_unique(pOptionList->GetListDescription(i), i, UiFlags::ColorUiGold)); + vecDialogItems.push_back(std::make_unique(pOptionList->GetListDescription(i), static_cast(i), UiFlags::ColorUiGold)); } itemToSelect = pOptionList->GetActiveListIndex(); UpdateDescription(*pOptionList); diff --git a/Source/engine/actor_position.cpp b/Source/engine/actor_position.cpp index 70a1fd5df..31d4b9142 100644 --- a/Source/engine/actor_position.cpp +++ b/Source/engine/actor_position.cpp @@ -108,9 +108,7 @@ constexpr std::array WalkParameters { { DisplacementOf ActorPosition::CalculateWalkingOffset(Direction dir, const AnimationInfo &animInfo) const { DisplacementOf offset = CalculateWalkingOffsetShifted4(dir, animInfo); - offset.deltaX >>= 4; - offset.deltaY >>= 4; - return offset; + return { static_cast(offset.deltaX >> 4), static_cast(offset.deltaY >> 4) }; } DisplacementOf ActorPosition::CalculateWalkingOffsetShifted4(Direction dir, const AnimationInfo &animInfo) const diff --git a/Source/engine/displacement.hpp b/Source/engine/displacement.hpp index 2cecb37e0..4056335dc 100644 --- a/Source/engine/displacement.hpp +++ b/Source/engine/displacement.hpp @@ -131,7 +131,7 @@ struct DisplacementOf { assert(deltaX * deltaX + deltaY * deltaY < (1 << 24)); // We do not use `std::hypot` here because it is slower and we do not need the extra precision. - return sqrtf(deltaX * deltaX + deltaY * deltaY); + return sqrtf(static_cast(deltaX * deltaX + deltaY * deltaY)); } /** diff --git a/Source/engine/load_file.hpp b/Source/engine/load_file.hpp index ce57ae536..1c91b2ef6 100644 --- a/Source/engine/load_file.hpp +++ b/Source/engine/load_file.hpp @@ -123,7 +123,7 @@ struct MultiFileLoader { totalSize += size; ++j; } - outOffsets[files.size()] = totalSize; + outOffsets[files.size()] = static_cast(totalSize); std::unique_ptr buf { new std::byte[totalSize] }; for (size_t i = 0, j = 0; i < numFiles; ++i) { if (!filterFn(i)) diff --git a/Source/utils/clx_encode.hpp b/Source/utils/clx_encode.hpp index 5b23f9463..01f7670ba 100644 --- a/Source/utils/clx_encode.hpp +++ b/Source/utils/clx_encode.hpp @@ -61,7 +61,7 @@ inline void AppendClxPixelsOrFillRun(const uint8_t *src, unsigned length, std::v // 3 appears to be optimal for most of our data (much better than 2, rarely very slightly worse than 4). constexpr unsigned MinFillRunLength = 3; if (prevColorRunLength >= MinFillRunLength) { - AppendClxPixelsRun(begin, prevColorBegin - begin, out); + AppendClxPixelsRun(begin, static_cast(prevColorBegin - begin), out); AppendClxFillRun(prevColor, prevColorRunLength, out); begin = src; } @@ -76,10 +76,10 @@ inline void AppendClxPixelsOrFillRun(const uint8_t *src, unsigned length, std::v // is followed by transparent pixels. // Width=2 Fill command takes 2 bytes, while the Pixels command is 3 bytes. if (prevColorRunLength >= 2) { - AppendClxPixelsRun(begin, prevColorBegin - begin, out); + AppendClxPixelsRun(begin, static_cast(prevColorBegin - begin), out); AppendClxFillRun(prevColor, prevColorRunLength, out); } else { - AppendClxPixelsRun(begin, prevColorBegin - begin + prevColorRunLength, out); + AppendClxPixelsRun(begin, static_cast(prevColorBegin - begin + prevColorRunLength), out); } } diff --git a/Source/utils/str_cat.cpp b/Source/utils/str_cat.cpp index 410d09d2c..ebb99c2d0 100644 --- a/Source/utils/str_cat.cpp +++ b/Source/utils/str_cat.cpp @@ -4,14 +4,25 @@ namespace devilution { -char *BufCopy(char *out, int value) +char *BufCopy(char *out, long long value) +{ + const fmt::format_int formatted { value }; + std::memcpy(out, formatted.data(), formatted.size()); + return out + formatted.size(); +} +char *BufCopy(char *out, unsigned long long value) { const fmt::format_int formatted { value }; std::memcpy(out, formatted.data(), formatted.size()); return out + formatted.size(); } -void StrAppend(std::string &out, int value) +void StrAppend(std::string &out, long long value) +{ + const fmt::format_int formatted { value }; + out.append(formatted.data(), formatted.size()); +} +void StrAppend(std::string &out, unsigned long long value) { const fmt::format_int formatted { value }; out.append(formatted.data(), formatted.size()); diff --git a/Source/utils/str_cat.hpp b/Source/utils/str_cat.hpp index 12c7152a4..b8a03fc95 100644 --- a/Source/utils/str_cat.hpp +++ b/Source/utils/str_cat.hpp @@ -11,12 +11,71 @@ namespace devilution { * @brief Writes the integer to the given buffer. * @return char* end of the buffer */ -char *BufCopy(char *out, int value); +char *BufCopy(char *out, long long value); +inline char *BufCopy(char *out, long value) +{ + return BufCopy(out, static_cast(value)); +} +inline char *BufCopy(char *out, int value) +{ + return BufCopy(out, static_cast(value)); +} +inline char *BufCopy(char *out, short value) +{ + return BufCopy(out, static_cast(value)); +} + +/** + * @brief Writes the integer to the given buffer. + * @return char* end of the buffer + */ +char *BufCopy(char *out, unsigned long long value); +inline char *BufCopy(char *out, unsigned long value) +{ + return BufCopy(out, static_cast(value)); +} +inline char *BufCopy(char *out, unsigned int value) +{ + return BufCopy(out, static_cast(value)); +} +inline char *BufCopy(char *out, unsigned short value) +{ + return BufCopy(out, static_cast(value)); +} /** * @brief Appends the integer to the given string. */ -void StrAppend(std::string &out, int value); +void StrAppend(std::string &out, long long value); +inline void StrAppend(std::string &out, long value) +{ + StrAppend(out, static_cast(value)); +} +inline void StrAppend(std::string &out, int value) +{ + StrAppend(out, static_cast(value)); +} +inline void StrAppend(std::string &out, short value) +{ + StrAppend(out, static_cast(value)); +} + +/** + * @brief Appends the integer to the given string. + */ +void StrAppend(std::string &out, unsigned long long value); +inline void StrAppend(std::string &out, unsigned long value) +{ + StrAppend(out, static_cast(value)); +} +inline void StrAppend(std::string &out, unsigned int value) +{ + StrAppend(out, static_cast(value)); +} +inline void StrAppend(std::string &out, unsigned short value) +{ + StrAppend(out, static_cast(value)); +} /** * @brief Copies the given std::string_view to the given buffer. diff --git a/test/player_test.h b/test/player_test.h index 955d8b25b..539010ee7 100644 --- a/test/player_test.h +++ b/test/player_test.h @@ -10,22 +10,22 @@ using namespace devilution; -static int CountItems(Item *items, int n) +static size_t CountItems(Item *items, int n) { return std::count_if(items, items + n, [](Item x) { return !x.isEmpty(); }); } -static int Count8(int8_t *ints, int n) +static size_t Count8(int8_t *ints, int n) { return std::count_if(ints, ints + n, [](int8_t x) { return x != 0; }); } -static int CountU8(uint8_t *ints, int n) +static size_t CountU8(uint8_t *ints, int n) { return std::count_if(ints, ints + n, [](uint8_t x) { return x != 0; }); } -static int CountBool(bool *bools, int n) +static size_t CountBool(bool *bools, int n) { return std::count_if(bools, bools + n, [](bool x) { return x; }); }