-IDManager
-times counting for tests
This commit is contained in:
parent
86e4e57f74
commit
17551b08a5
4 changed files with 118 additions and 10 deletions
|
|
@ -12,6 +12,7 @@ import ecs.system;
|
|||
import ecs.entity;
|
||||
import ecs.vector;
|
||||
import ecs.hash_map;
|
||||
import ecs.id_manager;
|
||||
|
||||
alias gEM = EntityManager.instance;
|
||||
|
||||
|
|
@ -23,6 +24,12 @@ class EntityManager
|
|||
instance = Mallocator.instance.make!EntityManager;
|
||||
}
|
||||
|
||||
static void destory()
|
||||
{
|
||||
Mallocator.instance.dispose(instance);
|
||||
instance = null;
|
||||
}
|
||||
|
||||
void registerSystem(Sys)(int priority)
|
||||
{
|
||||
alias types = Parameters!(Sys.update);
|
||||
|
|
@ -197,7 +204,7 @@ class EntityManager
|
|||
{
|
||||
if (block is null)
|
||||
{
|
||||
block = cast(EntitiesBlock*) AlignedMallocator.instance.alignedAllocate(4096, 4096);
|
||||
block = cast(EntitiesBlock*) AlignedMallocator.instance.alignedAllocate(page_size, page_size);
|
||||
*block = EntitiesBlock(tmpl.info);
|
||||
if (previous_block is null)
|
||||
{
|
||||
|
|
@ -211,7 +218,7 @@ class EntityManager
|
|||
break; // new block certainly has free space
|
||||
}
|
||||
// check if there is enought space
|
||||
if (block.dataDelta() + (block.entities_count + 1) * tmpl.info.size > 4096)
|
||||
if (block.dataDelta() + (block.entities_count + 1) * tmpl.info.size > page_size)
|
||||
{
|
||||
previous_block = block;
|
||||
block = block.next_block;
|
||||
|
|
@ -224,6 +231,9 @@ class EntityManager
|
|||
|
||||
void* start = block.dataBegin() + block.entities_count * tmpl.info.size;
|
||||
memcpy(start, tmpl.entity_data.ptr, tmpl.info.size);
|
||||
Entity* entity = cast(Entity*)start;
|
||||
entity.id = id_manager.getNewID();
|
||||
entity.updateID();
|
||||
block.entities_count++;
|
||||
}
|
||||
|
||||
|
|
@ -273,8 +283,13 @@ class EntityManager
|
|||
///there is a loooot of data (4kB, pure magic)
|
||||
}
|
||||
|
||||
enum page_size = 4096;
|
||||
enum pages_in_block = 128;
|
||||
|
||||
alias SytemFuncType = void function(ref EntityManager.CallData data, void* entity);
|
||||
|
||||
IDManager id_manager;
|
||||
|
||||
HashMap!(ushort[], EntityInfo*) entities_infos;
|
||||
HashMap!(string, uint) components_map;
|
||||
System[] systems;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue