bubel-ecs/source/ecs/entity_allocator.d
Mergul b3dce6560a -suport system callback: onCreate, onDestroy, onBegin, onEnd
-support for optional Components for System
-Components IDs in Systems are now stored as ushorts
2018-09-16 22:40:55 +02:00

29 lines
817 B
D

module ecs.entity_allocator;
import ecs.manager;
import std.experimental.allocator;
import std.experimental.allocator.mallocator : AlignedMallocator, Mallocator;
struct EntityAllocator
{
void* next_block;
void* getBlock()
{
if(next_block is null)allocBlock();
void* ret = next_block;
next_block = *cast(void**)next_block;
return ret;
}
private void allocBlock()
{
next_block = cast(void*)AlignedMallocator.instance.alignedAllocate(EntityManager.page_size * EntityManager.pages_in_block, EntityManager.page_size);
foreach(i;0..EntityManager.pages_in_block-1)
{
void** pointer = cast(void**)(next_block + i * EntityManager.page_size);
*pointer = next_block + (i+1) * EntityManager.page_size;
}
}
}