-update README code example (to one that compile)
-remove Entity.instance and gEM, global manager is now gEntityManager
This commit is contained in:
parent
d1c48e4c5f
commit
3b954b732b
11 changed files with 617 additions and 604 deletions
|
|
@ -35,7 +35,7 @@ struct Entity
|
|||
*/
|
||||
T* getComponent(T)() const
|
||||
{
|
||||
/*EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
/*EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
||||
EntityManager.EntityInfo* info = block.type_info;
|
||||
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
|
||||
return null;
|
||||
|
|
@ -46,17 +46,17 @@ struct Entity
|
|||
|
||||
void* getComponent(ushort component_id) const
|
||||
{
|
||||
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
||||
EntityManager.EntityInfo* info = block.type_info;
|
||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)
|
||||
return null;
|
||||
|
||||
return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEM.components[component_id].size);
|
||||
return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEntityManager.components[component_id].size);
|
||||
}
|
||||
|
||||
bool hasComponent(ushort component_id) const
|
||||
{
|
||||
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
EntityManager.EntitiesBlock* block = gEntityManager.getMetaData(&this);
|
||||
EntityManager.EntityInfo* info = block.type_info;
|
||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
||||
return true;
|
||||
|
|
@ -65,7 +65,7 @@ struct Entity
|
|||
EntityMeta getMeta() const
|
||||
{
|
||||
EntityMeta meta;
|
||||
meta.block = gEM.getMetaData(&this);
|
||||
meta.block = gEntityManager.getMetaData(&this);
|
||||
meta.index = meta.block.entityIndex(&this);
|
||||
return meta;
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ struct EntityMeta
|
|||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)
|
||||
return null;
|
||||
|
||||
return (cast(void*)block + info.deltas[component_id] + index * gEM.components[component_id].size);
|
||||
return (cast(void*)block + info.deltas[component_id] + index * gEntityManager.components[component_id].size);
|
||||
}
|
||||
|
||||
bool hasComponent(ushort component_id) const
|
||||
|
|
|
|||
|
|
@ -26,10 +26,11 @@ import bubel.ecs.traits;
|
|||
import bubel.ecs.vector;
|
||||
import bubel.ecs.atomic;
|
||||
|
||||
export alias gEM = EntityManager.instance;
|
||||
export alias gEntityManager = EntityManager.instance;
|
||||
alias SerializeVector = bubel.ecs.vector.Vector!ubyte;
|
||||
|
||||
///Global EntityManager used for everything.
|
||||
export __gshared EntityManager* gEntityManager = null;
|
||||
|
||||
/************************************************************************************************************************
|
||||
Entity manager is responsible for everything.
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ Entity manager can be in three states:
|
|||
|
||||
Manager can be only in one state simultaneously.
|
||||
|
||||
Manager must be initialized before use. There is global instance of EntityManager: EntityManager.instance or gEM as alias.
|
||||
Manager must be initialized before use. There is global instance of EntityManager: gEntityManager or gEntityManager as alias.
|
||||
|
||||
Registration process consist of registration of passes, systems, entities and events.
|
||||
|
||||
|
|
@ -64,15 +65,15 @@ export struct EntityManager
|
|||
/************************************************************************************************************************
|
||||
Initialize ECS.
|
||||
*/
|
||||
export static void initialize(uint threads_count, uint page_size = 32768,
|
||||
export static void initialize(uint threads_count = 1, uint page_size = 32768,
|
||||
uint block_pages_count = 128)
|
||||
{
|
||||
if (instance is null)
|
||||
if (gEntityManager is null)
|
||||
{
|
||||
//instance = Mallocator.make!EntityManager(threads_count);
|
||||
instance = Mallocator.make!EntityManager(threads_count, page_size, block_pages_count);
|
||||
//gEntityManager = Mallocator.make!EntityManager(threads_count);
|
||||
gEntityManager = Mallocator.make!EntityManager(threads_count, page_size, block_pages_count);
|
||||
|
||||
with (instance)
|
||||
with (gEntityManager)
|
||||
{
|
||||
UpdatePass* pass = Mallocator.make!UpdatePass;
|
||||
pass.name = Mallocator.makeArray(cast(char[]) "update");
|
||||
|
|
@ -89,10 +90,10 @@ export struct EntityManager
|
|||
*/
|
||||
export static void destroy()
|
||||
{
|
||||
if (instance is null)
|
||||
if (gEntityManager is null)
|
||||
return;
|
||||
|
||||
with (instance)
|
||||
with (gEntityManager)
|
||||
{
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
|
|
@ -131,8 +132,8 @@ export struct EntityManager
|
|||
}
|
||||
}
|
||||
|
||||
Mallocator.dispose(instance);
|
||||
instance = null;
|
||||
Mallocator.dispose(gEntityManager);
|
||||
gEntityManager = null;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
|
|
@ -1904,8 +1905,8 @@ export struct EntityManager
|
|||
addSystemCaller(*info, cast(uint) i);
|
||||
}
|
||||
|
||||
info.comp_add_info = Mallocator.makeArray!(EntityInfo*)(instance.components.length);
|
||||
//info.comp_rem_info = Mallocator.makeArray!(EntityInfo*)(instance.components.length);
|
||||
info.comp_add_info = Mallocator.makeArray!(EntityInfo*)(gEntityManager.components.length);
|
||||
//info.comp_rem_info = Mallocator.makeArray!(EntityInfo*)(gEntityManager.components.length);
|
||||
info.comp_rem_info = Mallocator.makeArray!(EntityInfo*)(info.deltas.length);
|
||||
|
||||
foreach (comp; info.components)
|
||||
|
|
@ -3406,7 +3407,7 @@ export struct EntityManager
|
|||
if (comp_add_info.length <= id)
|
||||
{
|
||||
EntityInfo*[] new_infos = Mallocator.makeArray!(EntityInfo*)(
|
||||
instance.components.length);
|
||||
gEntityManager.components.length);
|
||||
if (comp_add_info !is null)
|
||||
{
|
||||
//new_infos[0 .. comp_add_info.length] = comp_add_info[0 .. $];
|
||||
|
|
@ -3445,7 +3446,7 @@ export struct EntityManager
|
|||
|
||||
assert(len == components.length + 1);
|
||||
|
||||
EntityInfo* new_info = instance.getEntityInfo(ids);
|
||||
EntityInfo* new_info = gEntityManager.getEntityInfo(ids);
|
||||
|
||||
comp_add_info[id] = new_info;
|
||||
return new_info;
|
||||
|
|
@ -3456,7 +3457,7 @@ export struct EntityManager
|
|||
/*if (comp_rem_info.length <= id)
|
||||
{
|
||||
EntityInfo*[] new_infos = Mallocator.makeArray!(EntityInfo*)(
|
||||
instance.components.length, &this);
|
||||
gEntityManager.components.length, &this);
|
||||
if (comp_rem_info !is null)
|
||||
{
|
||||
//new_infos[0 .. comp_rem_info.length] = comp_rem_info[0 .. $];
|
||||
|
|
@ -3486,7 +3487,7 @@ export struct EntityManager
|
|||
|
||||
assert(len == components.length - 1);
|
||||
|
||||
EntityInfo* new_info = instance.getEntityInfo(ids[0 .. len]);
|
||||
EntityInfo* new_info = gEntityManager.getEntityInfo(ids[0 .. len]);
|
||||
|
||||
comp_rem_info[id] = new_info;
|
||||
return new_info;
|
||||
|
|
@ -3646,10 +3647,10 @@ export struct EntityManager
|
|||
|
||||
export void execute() nothrow @nogc
|
||||
{
|
||||
//EntityManager.instance.getThreadID();
|
||||
//gEntityManager.getThreadID();
|
||||
foreach (ref caller; callers)
|
||||
{
|
||||
caller.thread_id = EntityManager.instance.threadID();
|
||||
caller.thread_id = gEntityManager.threadID();
|
||||
caller.job_id = id;
|
||||
caller.update();
|
||||
}
|
||||
|
|
@ -3866,6 +3867,5 @@ export struct EntityManager
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
export __gshared EntityManager* instance = null;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue