diff --git a/Source/Engine/Core/Collections/Array.h b/Source/Engine/Core/Collections/Array.h index a17d8f686..8f73cfba7 100644 --- a/Source/Engine/Core/Collections/Array.h +++ b/Source/Engine/Core/Collections/Array.h @@ -66,7 +66,7 @@ public: /// The initial values defined in the array. Array(std::initializer_list initList) { - _count = _capacity = (int32)initList.size(); + _count = _capacity = static_cast(initList.size()); if (_count > 0) { _allocation.Allocate(_count); @@ -160,8 +160,8 @@ public: Clear(); if (initList.size() > 0) { - EnsureCapacity((int32)initList.size()); - _count = (int32)initList.size(); + EnsureCapacity(static_cast(initList.size())); + _count = static_cast(initList.size()); Memory::ConstructItems(_allocation.Get(), initList.begin(), _count); } return *this; diff --git a/Source/Engine/Core/Collections/BitArray.h b/Source/Engine/Core/Collections/BitArray.h index 267885438..97674974c 100644 --- a/Source/Engine/Core/Collections/BitArray.h +++ b/Source/Engine/Core/Collections/BitArray.h @@ -214,8 +214,8 @@ public: { ASSERT(index >= 0 && index < _count); const ItemType offset = index / sizeof(ItemType); - const ItemType bitMask = (ItemType)(int32)(1 << (index & ((int32)sizeof(ItemType) - 1))); - const ItemType item = ((ItemType*)_allocation.Get())[offset]; + const ItemType bitMask = static_cast((int32)(1 << (index & (static_cast(sizeof(ItemType)) - 1)))); + const ItemType item = static_cast(_allocation.Get())[offset]; return (item & bitMask) != 0; } @@ -228,8 +228,8 @@ public: { ASSERT(index >= 0 && index < _count); const ItemType offset = index / sizeof(ItemType); - const ItemType bitMask = (ItemType)(int32)(1 << (index & ((int32)sizeof(ItemType) - 1))); - ItemType& item = ((ItemType*)_allocation.Get())[offset]; + const ItemType bitMask = static_cast((int32)(1 << (index & (static_cast(sizeof(ItemType)) - 1)))); + ItemType& item = reinterpret_cast(_allocation.Get())[offset]; if (value) item |= bitMask; else diff --git a/Source/Engine/Core/Collections/Dictionary.h b/Source/Engine/Core/Collections/Dictionary.h index 1ce1db21b..438e1bb75 100644 --- a/Source/Engine/Core/Collections/Dictionary.h +++ b/Source/Engine/Core/Collections/Dictionary.h @@ -498,7 +498,7 @@ public: FindPosition(key, pos); if (pos.ObjectIndex == -1) return nullptr; - return (ValueType*)&_allocation.Get()[pos.ObjectIndex].Value; + return static_cast(&_allocation.Get()[pos.ObjectIndex].Value); } public: diff --git a/Source/Engine/Core/Memory/Allocation.h b/Source/Engine/Core/Memory/Allocation.h index 6e8342515..bdf30a16d 100644 --- a/Source/Engine/Core/Memory/Allocation.h +++ b/Source/Engine/Core/Memory/Allocation.h @@ -31,12 +31,12 @@ public: FORCE_INLINE T* Get() { - return (T*)_data; + return reinterpret_cast(_data); } FORCE_INLINE const T* Get() const { - return (T*)_data; + return reinterpret_cast(_data); } FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, const int32 minCapacity) const @@ -134,7 +134,7 @@ public: #if ENABLE_ASSERTION_LOW_LAYERS ASSERT(!_data); #endif - _data = (T*)Allocator::Allocate(capacity * sizeof(T)); + _data = static_cast(Allocator::Allocate(capacity * sizeof(T))); #if !BUILD_RELEASE if (!_data) OUT_OF_MEMORY; @@ -143,7 +143,7 @@ public: FORCE_INLINE void Relocate(const int32 capacity, int32 oldCount, int32 newCount) { - T* newData = capacity != 0 ? (T*)Allocator::Allocate(capacity * sizeof(T)) : nullptr; + T* newData = capacity != 0 ? static_cast(Allocator::Allocate(capacity * sizeof(T))) : nullptr; #if !BUILD_RELEASE if (!newData && capacity != 0) OUT_OF_MEMORY; @@ -203,12 +203,12 @@ public: FORCE_INLINE T* Get() { - return _useOther ? _other.Get() : (T*)_data; + return _useOther ? _other.Get() : reinterpret_cast(_data); } FORCE_INLINE const T* Get() const { - return _useOther ? _other.Get() : (T*)_data; + return _useOther ? _other.Get() : reinterpret_cast(_data); } FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const @@ -227,13 +227,15 @@ public: FORCE_INLINE void Relocate(int32 capacity, int32 oldCount, int32 newCount) { + T* data = reinterpret_cast(_data); + // Check if the new allocation will fit into inlined storage if (capacity <= Capacity) { if (_useOther) { // Move the items from other allocation to the inlined storage - Memory::MoveItems((T*)_data, _other.Get(), newCount); + Memory::MoveItems(data, _other.Get(), newCount); // Free the other allocation Memory::DestructItems(_other.Get(), oldCount); @@ -255,8 +257,8 @@ public: _useOther = true; // Move the items from the inlined storage to the other allocation - Memory::MoveItems(_other.Get(), (T*)_data, newCount); - Memory::DestructItems((T*)_data, oldCount); + Memory::MoveItems(_other.Get(), data, newCount); + Memory::DestructItems(data, oldCount); } } } diff --git a/Source/Engine/Renderer/RenderListBuffer.h b/Source/Engine/Renderer/RenderListBuffer.h index 486b1715b..bbe087e6e 100644 --- a/Source/Engine/Renderer/RenderListBuffer.h +++ b/Source/Engine/Renderer/RenderListBuffer.h @@ -76,7 +76,7 @@ public: if (_capacity > 0) { _allocation.Allocate(_capacity); - Memory::ConstructItems(_allocation.Get(), other.Get(), (int32)other._count); + Memory::ConstructItems(_allocation.Get(), other.Get(), static_cast(other._count)); } } @@ -102,7 +102,7 @@ public: { if (this != &other) { - Memory::DestructItems(_allocation.Get(), (int32)_count); + Memory::DestructItems(_allocation.Get(), static_cast(_count)); if (_capacity < other.Count()) { _allocation.Free(); @@ -110,7 +110,7 @@ public: _allocation.Allocate(_capacity); } _count = other.Count(); - Memory::ConstructItems(_allocation.Get(), other.Get(), (int32)_count); + Memory::ConstructItems(_allocation.Get(), other.Get(), static_cast(_count)); } return *this; } @@ -124,7 +124,7 @@ public: { if (this != &other) { - Memory::DestructItems(_allocation.Get(), (int32)_count); + Memory::DestructItems(_allocation.Get(), static_cast(_count)); _allocation.Free(); _count = other._count; _capacity = other._capacity; @@ -140,7 +140,7 @@ public: /// ~RenderListBuffer() { - Memory::DestructItems(_allocation.Get(), (int32)_count); + Memory::DestructItems(_allocation.Get(), static_cast(_count)); } public: @@ -149,7 +149,7 @@ public: /// FORCE_INLINE int32 Count() const { - return (int32)Platform::AtomicRead((volatile int64*)&_count); + return static_cast(Platform::AtomicRead((volatile int64*)&_count)); } /// @@ -157,7 +157,7 @@ public: /// FORCE_INLINE int32 Capacity() const { - return (int32)Platform::AtomicRead((volatile int64*)&_capacity); + return static_cast(Platform::AtomicRead((volatile int64*)&_capacity)); } /// @@ -232,7 +232,7 @@ public: void Clear() { _locker.Lock(); - Memory::DestructItems(_allocation.Get(), (int32)_count); + Memory::DestructItems(_allocation.Get(), static_cast(_count)); _count = 0; _locker.Unlock(); } @@ -248,8 +248,8 @@ public: return; _locker.Lock(); ASSERT(capacity >= 0); - const int32 count = preserveContents ? ((int32)_count < capacity ? (int32)_count : capacity) : 0; - _allocation.Relocate(capacity, (int32)_count, count); + const int32 count = preserveContents ? (static_cast(_count) < capacity ? static_cast(_count) : capacity) : 0; + _allocation.Relocate(capacity, static_cast(_count), count); Platform::AtomicStore(&_capacity, capacity); Platform::AtomicStore(&_count, count); _locker.Unlock(); @@ -265,12 +265,12 @@ public: _locker.Lock(); if (_count > size) { - Memory::DestructItems(_allocation.Get() + size, (int32)_count - size); + Memory::DestructItems(_allocation.Get() + size, static_cast(_count) - size); } else { EnsureCapacity(size, preserveContents); - Memory::ConstructItems(_allocation.Get() + _count, size - (int32)_count); + Memory::ConstructItems(_allocation.Get() + _count, size - static_cast(_count)); } _count = size; _locker.Unlock(); @@ -283,11 +283,11 @@ public: void EnsureCapacity(int32 minCapacity) { _locker.Lock(); - int32 capacity = (int32)Platform::AtomicRead(&_capacity); + int32 capacity = static_cast(Platform::AtomicRead(&_capacity)); if (capacity < minCapacity) { capacity = _allocation.CalculateCapacityGrow(capacity, minCapacity); - const int32 count = (int32)_count; + const int32 count = static_cast(_count); _allocation.Relocate(capacity, count, count); Platform::AtomicStore(&_capacity, capacity); } @@ -324,8 +324,8 @@ private: int32 AddOne() { Platform::InterlockedIncrement(&_threadsAdding); - int32 count = (int32)Platform::AtomicRead(&_count); - int32 capacity = (int32)Platform::AtomicRead(&_capacity); + int32 count = static_cast(Platform::AtomicRead(&_count)); + int32 capacity = static_cast(Platform::AtomicRead(&_capacity)); const int32 minCapacity = GetMinCapacity(count); if (minCapacity > capacity || Platform::AtomicRead(&_threadsResizing)) // Resize if not enough space or someone else is already doing it (don't add mid-resizing) { @@ -340,7 +340,7 @@ private: // Thread-safe resizing _locker.Lock(); - capacity = (int32)Platform::AtomicRead(&_capacity); + capacity = static_cast(Platform::AtomicRead(&_capacity)); if (capacity < minCapacity) { if (Platform::AtomicRead(&_threadsAdding)) @@ -350,7 +350,7 @@ private: goto RETRY; } capacity = _allocation.CalculateCapacityGrow(capacity, minCapacity); - count = (int32)Platform::AtomicRead(&_count); + count = static_cast(Platform::AtomicRead(&_count)); _allocation.Relocate(capacity, count, count); Platform::AtomicStore(&_capacity, capacity); } @@ -362,7 +362,7 @@ private: // Let other thread enter resizing-area _locker.Unlock(); } - return (int32)Platform::InterlockedIncrement(&_count) - 1; + return static_cast(Platform::InterlockedIncrement(&_count)) - 1; } FORCE_INLINE static int32 GetMinCapacity(const int32 count)