diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-11-23 01:06:40 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-11-23 01:06:40 +0100 |
commit | 848fa5bbaa35c187f125a0656aef6f44f0c56061 (patch) | |
tree | 139dd4a82277093e49b8f2623a5b8ef8a48d0ef2 /src | |
parent | 799422ec272b0bcf1d1e9ad3308eb494c400bb93 (diff) |
Core/Entities: Make EntityFragmentsHolder more resilient to unexpected inputs and fix nopch build
Diffstat (limited to 'src')
3 files changed, 14 insertions, 10 deletions
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index fd6952e22fd..c4087827424 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -35,6 +35,7 @@ #include <numeric> #include <sstream> #include <cctype> +#include <cmath> // temporary hack until includes are sorted out (don't want to pull in Windows.h) #ifdef GetClassName diff --git a/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.cpp b/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.cpp index c68a657c066..85249caab78 100644 --- a/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.cpp +++ b/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.cpp @@ -25,12 +25,14 @@ void EntityFragmentsHolder::Add(EntityFragment fragment, bool update) { ASSERT(Count < Ids.size()); - auto insertSorted = [](auto& arr, uint8& count, EntityFragment f) + auto insertSorted = []<size_t N>(std::array<EntityFragment, N>& arr, uint8& count, EntityFragment f) { - auto where = std::ranges::lower_bound(arr.begin(), arr.begin() + count, f); + auto end = arr.begin() + count; + auto where = std::ranges::lower_bound(arr.begin(), end, f); if (*where == f) return std::pair(where, false); - std::rotate(where, arr.begin() + count, arr.begin() + count + 1); + + std::ranges::move_backward(where, end, end + 1); ++count; *where = f; return std::pair(where, true); @@ -44,7 +46,7 @@ void EntityFragmentsHolder::Add(EntityFragment fragment, bool update) ASSERT(UpdateableCount < UpdateableIds.size()); auto insertedItr = insertSorted(UpdateableIds, UpdateableCount, fragment).first; - std::ptrdiff_t index = std::distance(UpdateableIds.begin(), insertedItr); + std::ptrdiff_t index = std::ranges::distance(UpdateableIds.begin(), insertedItr); uint8 maskLowPart = ContentsChangedMask & ((1 << index) - 1); uint8 maskHighPart = (ContentsChangedMask & ~((1 << index) - 1)) << (1 + IsIndirectFragment(fragment)); ContentsChangedMask = maskLowPart | maskHighPart; @@ -65,13 +67,13 @@ void EntityFragmentsHolder::Add(EntityFragment fragment, bool update) void EntityFragmentsHolder::Remove(EntityFragment fragment) { - auto removeSorted = [](auto& arr, uint8& count, EntityFragment f) + auto removeSorted = []<size_t N>(std::array<EntityFragment, N>& arr, uint8& count, EntityFragment f) { - auto where = std::ranges::find(arr.begin(), arr.begin() + count, f); - if (where != arr.end()) + auto end = arr.begin() + count; + auto where = std::ranges::find(arr.begin(), end, f); + if (where != end) { - *where = EntityFragment::End; - std::rotate(where, where + 1, arr.begin() + count); + *std::ranges::move(where + 1, end, where).out = EntityFragment::End; --count; return std::pair(where, true); } @@ -86,7 +88,7 @@ void EntityFragmentsHolder::Remove(EntityFragment fragment) auto [removedItr, removed] = removeSorted(UpdateableIds, UpdateableCount, fragment); if (removed) { - std::ptrdiff_t index = std::distance(UpdateableIds.begin(), removedItr); + std::ptrdiff_t index = std::ranges::distance(UpdateableIds.begin(), removedItr); uint8 maskLowPart = ContentsChangedMask & ((1 << index) - 1); uint8 maskHighPart = (ContentsChangedMask & ~((1 << index) - 1)) >> (1 + IsIndirectFragment(fragment)); ContentsChangedMask = maskLowPart | maskHighPart; diff --git a/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.h b/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.h index 42d1ec52063..dba9e0a11a9 100644 --- a/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.h +++ b/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.h @@ -19,6 +19,7 @@ #define TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H #include "Define.h" +#include <array> #include <span> namespace WowCS |