Files
Project-Reboot-3.0/Project Reboot 3.0/ContainerAllocationPolicies.h
Milxnor cb57a1b843 too much stuff
fix s3, fix health + backpack bug on 1.11, change replciation, fix 7.20 & 12.61, fix backpack on >S9, probably some other stuff i forgot
2023-04-03 02:04:29 -04:00

71 lines
1.7 KiB
C++

#pragma once
template <int NumElements>
class TInlineAllocator
{
private:
template <int Size, int Alignment>
struct alignas(Alignment) TAlignedBytes
{
unsigned char Pad[Size];
};
template <typename ElementType>
struct TTypeCompatibleBytes : public TAlignedBytes<sizeof(ElementType), alignof(ElementType)>
{
};
public:
template <typename ElementType>
class ForElementType
{
friend class TBitArray;
private:
TTypeCompatibleBytes<ElementType> InlineData[NumElements];
ElementType* SecondaryData;
public:
FORCEINLINE int32 NumInlineBytes() const
{
return sizeof(ElementType) * NumElements;
}
FORCEINLINE int32 NumInlineBits() const
{
return NumInlineBytes() * 8;
}
FORCEINLINE ElementType& operator[](int32 Index)
{
return *(ElementType*)(&InlineData[Index]);
}
FORCEINLINE const ElementType& operator[](int32 Index) const
{
return *(ElementType*)(&InlineData[Index]);
}
FORCEINLINE void operator=(void* InElements)
{
SecondaryData = InElements;
}
FORCEINLINE ElementType& GetInlineElement(int32 Index)
{
return *(ElementType*)(&InlineData[Index]);
}
FORCEINLINE const ElementType& GetInlineElement(int32 Index) const
{
return *(ElementType*)(&InlineData[Index]);
}
FORCEINLINE ElementType& GetSecondaryElement(int32 Index)
{
return SecondaryData[Index];
}
FORCEINLINE const ElementType& GetSecondaryElement(int32 Index) const
{
return SecondaryData[Index];
}
};
};