feat: sync with Whoa implementation

This commit is contained in:
VDm 2026-04-26 17:10:11 +04:00
parent 12ab8f7721
commit 6928bf3f0c
46 changed files with 2980 additions and 441 deletions

View file

@ -19,6 +19,7 @@ class TSBaseArray {
// Member functions
T& operator[](uint32_t index);
const T& operator[](uint32_t index) const;
void CheckArrayBounds(uint32_t index) const;
void Constructor();
uint32_t Count() const;
@ -33,6 +34,12 @@ T& TSBaseArray<T>::operator[](uint32_t index) {
return this->m_data[index];
}
template <class T>
const T& TSBaseArray<T>::operator[](uint32_t index) const {
this->CheckArrayBounds(index);
return this->m_data[index];
}
template <class T>
void TSBaseArray<T>::CheckArrayBounds(uint32_t index) const {
if (index < this->Count()) {
@ -40,14 +47,15 @@ void TSBaseArray<T>::CheckArrayBounds(uint32_t index) const {
}
SErrDisplayErrorFmt(
0x85100080,
STORM_ERROR_ACCESS_OUT_OF_BOUNDS,
this->MemFileName(),
this->MemLineNo(),
1,
1,
"index (0x%08X), array size (0x%08X)",
index,
this->Count());
this->Count()
);
}
template <class T>

View file

@ -8,9 +8,11 @@
template <class T>
class TSFixedArray : public TSBaseArray<T> {
public:
// Member functions
TSFixedArray();
TSFixedArray(const TSFixedArray& source);
~TSFixedArray();
TSFixedArray<T>& operator=(const TSFixedArray<T>& source);
TSFixedArray& operator=(const TSFixedArray& source);
void Clear();
void ReallocAndClearData(uint32_t count);
void ReallocData(uint32_t count);
@ -23,6 +25,12 @@ TSFixedArray<T>::TSFixedArray() {
this->Constructor();
}
template <class T>
TSFixedArray<T>::TSFixedArray(const TSFixedArray<T>& source) {
this->Constructor();
this->Set(source.Count(), source.Ptr());
}
template <class T>
TSFixedArray<T>::~TSFixedArray() {
for (uint32_t i = 0; i < this->Count(); i++) {
@ -41,22 +49,31 @@ TSFixedArray<T>& TSFixedArray<T>::operator=(const TSFixedArray<T>& source) {
this->Set(source.Count(), source.Ptr());
}
return *this;
return *this;
}
template <class T>
void TSFixedArray<T>::Clear() {
this->~TSFixedArray<T>();
this->Constructor();
this->~TSFixedArray<T>();
this->Constructor();
}
template <class T>
void TSFixedArray<T>::ReallocAndClearData(uint32_t count) {
this->m_alloc = count;
// Destruct existing array elements
for (uint32_t i = 0; i < this->Count(); i++) {
auto element = &this->operator[](i);
element->~T();
}
if (this->m_data || count) {
void* m = SMemReAlloc(this->m_data, sizeof(T) * count, this->MemFileName(), this->MemLineNo(), 0x0);
this->m_data = static_cast<T*>(m);
// Reallocate if count changed
if (count != this->m_count) {
this->m_alloc = count;
if (this->m_data || count) {
void* m = SMemReAlloc(this->m_data, sizeof(T) * count, this->MemFileName(), this->MemLineNo(), 0x0);
this->m_data = static_cast<T*>(m);
}
}
}

View file

@ -6,17 +6,20 @@
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <new>
template <class T>
class TSGrowableArray : public TSFixedArray<T> {
public:
// Member variables
uint32_t m_chunk = 0;
// Member functions
uint32_t Add(uint32_t count, const T* data);
uint32_t Add(uint32_t count, uint32_t incr, const T* data);
uint32_t CalcChunkSize(uint32_t count);
void GrowToFit(uint32_t index, int32_t zero);
T* New(void);
T* New();
void Reserve(uint32_t count, int32_t round);
uint32_t Reserved() const;
uint32_t RoundToChunk(uint32_t count, uint32_t chunk);