mirror of https://github.com/zeldaret/botw.git
Havok: Add more basic hkArray functions
This commit is contained in:
parent
000ca1c6d9
commit
743b3cf28e
|
@ -5,6 +5,7 @@ add_library(hkStubs OBJECT
|
|||
|
||||
Havok/Common/Base/Container/hkContainerAllocators.h
|
||||
Havok/Common/Base/Container/Array/hkArray.h
|
||||
Havok/Common/Base/Container/Array/hkArrayUtil.h
|
||||
Havok/Common/Base/Container/String/hkStringPtr.h
|
||||
|
||||
Havok/Common/Base/Math/hkMath.h
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/Container/Array/hkArrayUtil.h>
|
||||
#include <Havok/Common/Base/Container/hkContainerAllocators.h>
|
||||
#include <Havok/Common/Base/Types/hkBaseDefs.h>
|
||||
#include <Havok/Common/Base/Types/hkBaseTypes.h>
|
||||
#include <type_traits>
|
||||
|
||||
/// Base class for hkArray (a std::vector-like container).
|
||||
// FIXME: incomplete
|
||||
|
@ -18,6 +20,7 @@ public:
|
|||
};
|
||||
|
||||
HK_FORCE_INLINE hkArrayBase();
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
|
||||
explicit hkArrayBase(hkFinishLoadedObjectFlag f) {}
|
||||
|
||||
HK_FORCE_INLINE ~hkArrayBase();
|
||||
|
@ -25,6 +28,14 @@ public:
|
|||
hkArrayBase(const hkArrayBase&) = delete;
|
||||
auto operator=(const hkArrayBase&) = delete;
|
||||
|
||||
HK_FORCE_INLINE int getSize() const;
|
||||
HK_FORCE_INLINE int getCapacity() const;
|
||||
HK_FORCE_INLINE int getCapacityAndFlags() const;
|
||||
HK_FORCE_INLINE hkBool isEmpty() const;
|
||||
|
||||
HK_FORCE_INLINE void clear();
|
||||
HK_FORCE_INLINE void _clearAndDeallocate(hkMemoryAllocator& allocator);
|
||||
|
||||
protected:
|
||||
T* m_data;
|
||||
int m_size;
|
||||
|
@ -41,11 +52,13 @@ public:
|
|||
HK_FORCE_INLINE hkArray() = default;
|
||||
explicit hkArray(hkFinishLoadedObjectFlag f) : hkArrayBase<T>(f) {}
|
||||
|
||||
HK_FORCE_INLINE ~hkArray();
|
||||
HK_FORCE_INLINE ~hkArray() { clearAndDeallocate(); }
|
||||
|
||||
HK_FORCE_INLINE hkArray& operator=(const hkArrayBase<T>& other);
|
||||
HK_FORCE_INLINE hkArray& operator=(const hkArray& other);
|
||||
|
||||
HK_FORCE_INLINE void clearAndDeallocate();
|
||||
|
||||
protected:
|
||||
HK_FORCE_INLINE hkArray(const hkArray& other);
|
||||
};
|
||||
|
@ -58,3 +71,47 @@ template <typename T>
|
|||
inline hkArrayBase<T>::~hkArrayBase() {
|
||||
// Assert non-POD element destruction
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int hkArrayBase<T>::getSize() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int hkArrayBase<T>::getCapacity() const {
|
||||
return m_capacityAndFlags & static_cast<int>(CAPACITY_MASK);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int hkArrayBase<T>::getCapacityAndFlags() const {
|
||||
return m_capacityAndFlags;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline hkBool hkArrayBase<T>::isEmpty() const {
|
||||
return m_size == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::clear() {
|
||||
hkArrayUtil::destruct(m_data, m_size);
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::_clearAndDeallocate(hkMemoryAllocator& allocator) {
|
||||
clear();
|
||||
if ((m_capacityAndFlags & DONT_DEALLOCATE_FLAG) == 0) {
|
||||
const int SIZE_ELEM = hkSizeOfTypeOrVoid<T>::val;
|
||||
int numBytes = getCapacity() * SIZE_ELEM;
|
||||
void* storage = const_cast<std::remove_const_t<T>*>(m_data);
|
||||
allocator.bufFree(storage, numBytes);
|
||||
}
|
||||
m_data = nullptr;
|
||||
m_capacityAndFlags = DONT_DEALLOCATE_FLAG;
|
||||
}
|
||||
|
||||
template <typename T, typename Allocator>
|
||||
inline void hkArray<T, Allocator>::clearAndDeallocate() {
|
||||
this->_clearAndDeallocate(AllocatorType().get());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
|
||||
class hkArrayUtil {
|
||||
public:
|
||||
template <typename T>
|
||||
static HK_FORCE_INLINE void construct(T* t, int n);
|
||||
|
||||
template <typename T>
|
||||
static HK_FORCE_INLINE void constructWithCopy(T* t, int n, const T& tcopy);
|
||||
|
||||
template <typename T>
|
||||
static HK_FORCE_INLINE void constructWithArray(T* t, int n, const T* tcopy);
|
||||
|
||||
template <typename T>
|
||||
static HK_FORCE_INLINE void destruct(T* t, int n);
|
||||
|
||||
static hkResult _reserve(hkMemoryAllocator& a, void*, int reqElem, int sizeElem);
|
||||
static void _reserveMore(hkMemoryAllocator& a, void* array, int sizeElem);
|
||||
static void _reduce(hkMemoryAllocator& a, void* array, int sizeElem, char* inplaceMem,
|
||||
int requestedCapacity);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayUtil::construct(T* t, int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
::new (static_cast<void*>(t + i)) T;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayUtil::constructWithCopy(T* t, int n, const T& tcopy) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
::new (static_cast<void*>(t + i)) T(tcopy);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayUtil::constructWithArray(T* t, int n, const T* tcopy) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
::new (static_cast<void*>(t + i)) T(tcopy[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayUtil::destruct(T* t, int n) {
|
||||
for (int i = n - 1; i >= 0; --i) {
|
||||
static_cast<T*>(t)[i].~T();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue