Design
This commit is contained in:
parent
f851e3c2ec
commit
a984824ec5
5 changed files with 311 additions and 2 deletions
51
source/ecs/entity_allocator.d
Normal file
51
source/ecs/entity_allocator.d
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
module ecs.entity_allocator;
|
||||
|
||||
enum bucketSize = 4096;
|
||||
enum bucketsInAllocation = 128;
|
||||
|
||||
struct Bucket
|
||||
{
|
||||
union
|
||||
{
|
||||
ubyte[bucketSize] memory;
|
||||
Bucket* next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct BucketArray
|
||||
{
|
||||
Bucket[bucketsInAllocation] buckets;
|
||||
}
|
||||
|
||||
struct EntityAllocator
|
||||
{
|
||||
BucketArray[] arrays;
|
||||
Bucket* lastEmptyBucket;
|
||||
|
||||
void initBucketArray(ref BucketArray bArr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void allocateBucketArray()
|
||||
{
|
||||
auto bucketArray = new BucketArray();
|
||||
assert(bucketArray.buckets[0].ptr % bucketSize == 0) arrays ~= bucketArray;
|
||||
Bucket* lasBucket = initBucketArray(bucketArray);
|
||||
lastEmptyBucket = lasBucket;
|
||||
}
|
||||
|
||||
ubyte[] getMemory()
|
||||
{
|
||||
if (lastEmptyBucket is null)
|
||||
{
|
||||
allocateBucket();
|
||||
}
|
||||
auto bucketTmp = lastEmptyBucket;
|
||||
lastEmptyBucket = bucketTmp.next;
|
||||
|
||||
return bucketTmp.memory[];
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue