diff --git a/README.md b/README.md index d70058c..e4c2d77 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,11 @@ Online demo support multithreading and page tries to check if client support WAS ```d +import bubel.ecs.core; +import bubel.ecs.manager; +import bubel.ecs.attributes; +import std.array : staticArray; + struct Position { float x; @@ -122,7 +127,7 @@ struct UpdateSystem { mixin ECS.System; //makes struct system - ECS.ExcludedComponents!(StaticFlag); //prevents static entities from update + mixin ECS.ExcludedComponents!(StaticFlag); //prevents static entities from update struct EntitiesData { @@ -136,26 +141,31 @@ struct UpdateSystem { foreach(i; 0..data.length) //iterate over entities { - data.positions[i].x += data.velocities[i].x * dt; - data.positions[i].y += data.velocities[i].y * dt; + data.positions[i].x += data.velocities[i].x; + data.positions[i].y += data.velocities[i].y; } } } void main() { - manager.beginRegister(); + //initialize ECS + EntityManager.initialize(); + + //begin registering process + gEntityManager.beginRegister(); //register components - manager.registerComponent!Position; - manager.registerComponent!Velocity; - manager.registerComponent!StaticFlag; + gEntityManager.registerComponent!Position; + gEntityManager.registerComponent!Velocity; + gEntityManager.registerComponent!StaticFlag; //register system with priority 0 - manager.registerSystem!UpdateSystem(0); - manager.endRegister(); + gEntityManager.registerSystem!UpdateSystem(0); + //end registering process + gEntityManager.endRegister(); //allocate template - EntityTemplate* tmpl = manager.allocateEmplate([becsID!Velocity, becsID!Position].staticArray); - scope (exit) manager.freeTemplate(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!Velocity, becsID!Position].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl); //gets pointer to template component data Position* position = tmpl.getComponent!Position; @@ -163,12 +173,15 @@ void main() { position.x = i % 10; position.y = i / 10; - manager.addEntity(tmpl); + gEntityManager.addEntity(tmpl); } - manager.begin(); //start frame, inside system onBegin callbacks are called - manager.update(); //update all systems, there onUpdate callbacks are called - manager.end(); //end frame, inside system onEnd callbacks are called + gEntityManager.begin(); //start frame, inside system onBegin callbacks are called + gEntityManager.update(); //update all systems, there onUpdate callbacks are called + gEntityManager.end(); //end frame, inside system onEnd callbacks are called*/ + + //free ECS data + EntityManager.destroy(); } ``` diff --git a/demos/source/app.d b/demos/source/app.d index fa77aac..2c324ec 100644 --- a/demos/source/app.d +++ b/demos/source/app.d @@ -192,7 +192,7 @@ struct Launcher { vec2 rel_vec = data.location[i] - position; float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y; - if(length < size2)gEM.removeEntity(data.entity[i].id); + if(length < size2)gEntityManager.removeEntity(data.entity[i].id); } } @@ -203,7 +203,7 @@ struct Launcher { vec2 rel_vec = data.location[i] - position; float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y; - if(length < size2)gEM.addComponents(data.entity[i].id, add_comps); + if(length < size2)gEntityManager.addComponents(data.entity[i].id, add_comps); } } @@ -216,8 +216,8 @@ struct Launcher float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y; if(length < size2) { - gEM.removeComponents(data.entity[i].id, rem_comps); - gEM.addComponents(data.entity[i].id, add_comps); + gEntityManager.removeComponents(data.entity[i].id, rem_comps); + gEntityManager.addComponents(data.entity[i].id, add_comps); } } } @@ -229,7 +229,7 @@ struct Launcher { vec2 rel_vec = data.location[i] - position; float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y; - if(length < size2)gEM.removeComponents(data.entity[i].id, rem_comps); + if(length < size2)gEntityManager.removeComponents(data.entity[i].id, rem_comps); } } @@ -1231,7 +1231,7 @@ int app_main(int argc, char** argv) //launcher.job_updater.onCreate(); EntityManager.initialize(32, 1<<16); - launcher.manager = EntityManager.instance; + launcher.manager = gEntityManager; //launcher.manager.m_thread_id_func = &launcher.job_updater.getThreadID; //launcher.manager.setJobDispachFunc(&launcher.job_updater.dispatch); diff --git a/demos/source/game_core/collision.d b/demos/source/game_core/collision.d index 647bfdb..ba81a4f 100644 --- a/demos/source/game_core/collision.d +++ b/demos/source/game_core/collision.d @@ -188,7 +188,7 @@ struct ShootGridCleaner bool onBegin() { - grid = gEM.getSystem!ShootGridManager().grid; + grid = gEntityManager.getSystem!ShootGridManager().grid; if(grid != null)return true; else return false; } @@ -964,7 +964,7 @@ struct BVHBuilder2 void onCreate() { - tree = gEM.getSystem!BVHBuilder().tree; + tree = gEntityManager.getSystem!BVHBuilder().tree; } bool onBegin() diff --git a/demos/source/gui/manager.d b/demos/source/gui/manager.d index 26eba2b..b3f758b 100644 --- a/demos/source/gui/manager.d +++ b/demos/source/gui/manager.d @@ -119,7 +119,7 @@ struct GUIManager // void addComponent(ComponentRef comp, const (char)* name) // { - // uint size = EntityManager.instance.components[becsID(comp)].size; + // uint size = gEntityManager.components[becsID(comp)].size; // void* data = malloc(size); // memcpy(data, comp.ptr, size); // components.add(ComponentGUI(name, data, becsID(comp))); @@ -127,7 +127,7 @@ struct GUIManager void addComponent(T)(T comp, const (char)* name) { - uint size = EntityManager.instance.components[becsID(comp)].size; + uint size = gEntityManager.components[becsID(comp)].size; void* data = malloc(size); memcpy(data, &comp, size); components.add(ComponentGUI(name, data, becsID(comp))); @@ -472,7 +472,7 @@ struct GUIManager break; case Tool.selector: { - Entity* entity = gEM.getEntity(launcher.selected_entity); + Entity* entity = gEntityManager.getEntity(launcher.selected_entity); style.Colors[ImGuiCol_Header] = col; entityComponentsGUI(entity); } diff --git a/source/bubel/ecs/entity.d b/source/bubel/ecs/entity.d index 11c5edc..cb3f752 100644 --- a/source/bubel/ecs/entity.d +++ b/source/bubel/ecs/entity.d @@ -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 diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index 6afdca9..2dfbd58 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -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; + } diff --git a/tests/access_perf.d b/tests/access_perf.d index b1b16bf..87a0a75 100644 --- a/tests/access_perf.d +++ b/tests/access_perf.d @@ -54,26 +54,26 @@ EntityTemplate* tmpl; void beforeEveryTest() { - gEM.initialize(0); + gEntityManager.initialize(0); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CLong; - gEM.registerComponent!CInt; - gEM.registerComponent!CUInt; - gEM.registerComponent!CBig; + gEntityManager.registerComponent!CLong; + gEntityManager.registerComponent!CInt; + gEntityManager.registerComponent!CUInt; + gEntityManager.registerComponent!CBig; - gEM.endRegister(); + gEntityManager.endRegister(); - tmpl = gEM.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); - foreach(i; 0 .. 100_000)gEM.addEntity(tmpl); + tmpl = gEntityManager.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); + foreach(i; 0 .. 100_000)gEntityManager.addEntity(tmpl); } void afterEveryTest() { - if(tmpl)gEM.freeTemplate(tmpl); + if(tmpl)gEntityManager.freeTemplate(tmpl); tmpl = null; - gEM.destroy(); + gEntityManager.destroy(); } @("DirectAccess100k1comp") @@ -81,7 +81,7 @@ unittest { foreach(i;0..25000) { - Entity* entity = gEM.getEntity(EntityID(i*4+1,0)); + Entity* entity = gEntityManager.getEntity(EntityID(i*4+1,0)); CUInt* comp1 = entity.getComponent!CUInt; comp1.value = 4; } @@ -92,7 +92,7 @@ unittest { foreach(i;0..25000) { - Entity* entity = gEM.getEntity(EntityID(i*4+1,0)); + Entity* entity = gEntityManager.getEntity(EntityID(i*4+1,0)); CUInt* comp1 = entity.getComponent!CUInt; comp1.value = 4; CInt* comp2 = entity.getComponent!CInt; @@ -109,7 +109,7 @@ unittest { foreach(i;0..25000) { - Entity* entity = gEM.getEntity(EntityID(i*4+1,0)); + Entity* entity = gEntityManager.getEntity(EntityID(i*4+1,0)); EntityMeta meta = entity.getMeta(); CUInt* comp1 = meta.getComponent!CUInt; comp1.value = 4; @@ -121,7 +121,7 @@ unittest { foreach(i;0..25000) { - Entity* entity = gEM.getEntity(EntityID(i*4+1,0)); + Entity* entity = gEntityManager.getEntity(EntityID(i*4+1,0)); EntityMeta meta = entity.getMeta(); CUInt* comp1 = meta.getComponent!CUInt; comp1.value = 4; diff --git a/tests/basic.d b/tests/basic.d index 026fe20..aa730ea 100644 --- a/tests/basic.d +++ b/tests/basic.d @@ -116,31 +116,31 @@ struct EmptySystem void beforeEveryTest() { becsID!CUnregistered = ushort.max; - gEM.initialize(0); + gEntityManager.initialize(0); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CInt; - gEM.registerComponent!CFloat; - gEM.registerComponent!CDouble; - gEM.registerComponent!CLong; - gEM.registerComponent!CShort; - gEM.registerComponent!CFlag; + gEntityManager.registerComponent!CInt; + gEntityManager.registerComponent!CFloat; + gEntityManager.registerComponent!CDouble; + gEntityManager.registerComponent!CLong; + gEntityManager.registerComponent!CShort; + gEntityManager.registerComponent!CFlag; - gEM.endRegister(); + gEntityManager.endRegister(); } void afterEveryTest() { - gEM.destroy(); + gEntityManager.destroy(); } @("EntityMeta") unittest { - EntityTemplate* tmpl_ = gEM.allocateTemplate([becsID!CInt, becsID!CFloat, becsID!CFlag].staticArray); - scope(exit)gEM.freeTemplate(tmpl_); - Entity* entity = gEM.addEntity(tmpl_); + EntityTemplate* tmpl_ = gEntityManager.allocateTemplate([becsID!CInt, becsID!CFloat, becsID!CFlag].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_); + Entity* entity = gEntityManager.addEntity(tmpl_); EntityMeta meta = entity.getMeta(); assert(meta.hasComponent(becsID!CInt)); assert(meta.getComponent!CInt); @@ -157,8 +157,8 @@ unittest @("AddEntity") unittest { - EntityTemplate* tmpl_ = gEM.allocateTemplate([becsID!CInt, becsID!CFloat, becsID!CFlag].staticArray); - scope(exit)gEM.freeTemplate(tmpl_); + EntityTemplate* tmpl_ = gEntityManager.allocateTemplate([becsID!CInt, becsID!CFloat, becsID!CFlag].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_); assert(tmpl_.info.components.length == 3); assert(tmpl_.info.size == (CInt.sizeof + CFloat.sizeof + EntityID.sizeof)); assert(tmpl_.getComponent!CInt); @@ -169,14 +169,14 @@ unittest assert(*tmpl_.getComponent!CInt == 1); assert(*tmpl_.getComponent!CFloat == 2.0); - Entity* entity = gEM.addEntity(tmpl_); + Entity* entity = gEntityManager.addEntity(tmpl_); assert(entity.getComponent!CInt); assert(entity.getComponent!CFloat); assert(*entity.getComponent!CInt == 1); assert(*entity.getComponent!CFloat == 2.0); *entity.getComponent!CInt = 2; - Entity* entity2 = gEM.addEntityCopy(entity.id); + Entity* entity2 = gEntityManager.addEntityCopy(entity.id); assert(entity2.getComponent!CInt); assert(entity2.getComponent!CFloat); assert(*entity2.getComponent!CInt == 2); @@ -184,17 +184,17 @@ unittest //CInt cint = CInt(10); //CLong clong; - //Entity* entity3 = gEM.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray); - Entity* entity3 = gEM.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray); + //Entity* entity3 = gEntityManager.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray); + Entity* entity3 = gEntityManager.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray); EntityID id = entity3.id; assert(entity3.hasComponent(becsID!CInt)); assert(entity3.hasComponent(becsID!CFloat)); assert(*entity3.getComponent!CInt == 10); assert(*entity3.getComponent!CFloat == 2.0); - gEM.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); - gEM.commit(); - entity3 = gEM.getEntity(id); + gEntityManager.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); + gEntityManager.commit(); + entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CInt); assert(entity3.getComponent!CFloat); assert(entity3.getComponent!CFlag); @@ -203,9 +203,9 @@ unittest assert(*entity3.getComponent!CFloat == 2.0); assert(*entity3.getComponent!CShort == 2); - gEM.removeComponents(entity3.id, [becsID!CFlag,becsID!CShort].staticArray); - gEM.commit(); - entity3 = gEM.getEntity(id); + gEntityManager.removeComponents(entity3.id, [becsID!CFlag,becsID!CShort].staticArray); + gEntityManager.commit(); + entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CInt); assert(entity3.getComponent!CFloat); assert(!entity3.getComponent!CFlag); @@ -213,10 +213,10 @@ unittest assert(*entity3.getComponent!CInt == 10); assert(*entity3.getComponent!CFloat == 2.0); - gEM.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); - gEM.removeComponents(entity3.id, [becsID!CUnregistered].staticArray); - gEM.commit(); - entity3 = gEM.getEntity(id); + gEntityManager.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); + gEntityManager.removeComponents(entity3.id, [becsID!CUnregistered].staticArray); + gEntityManager.commit(); + entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CInt); assert(entity3.getComponent!CFloat); assert(entity3.getComponent!CFlag); @@ -225,21 +225,21 @@ unittest assert(*entity3.getComponent!CFloat == 2.0); assert(*entity3.getComponent!CShort == 2); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CUnregistered; + gEntityManager.registerComponent!CUnregistered; - gEM.endRegister(); + gEntityManager.endRegister(); - gEM.addComponents(entity3.id, [CUnregistered(4).ref_].staticArray); - gEM.commit(); - entity3 = gEM.getEntity(id); + gEntityManager.addComponents(entity3.id, [CUnregistered(4).ref_].staticArray); + gEntityManager.commit(); + entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CUnregistered); assert(*entity3.getComponent!CUnregistered == 4); - gEM.removeComponents(entity3.id, [becsID!CUnregistered].staticArray); - gEM.commit(); - entity3 = gEM.getEntity(id); + gEntityManager.removeComponents(entity3.id, [becsID!CUnregistered].staticArray); + gEntityManager.commit(); + entity3 = gEntityManager.getEntity(id); assert(!entity3.getComponent!CUnregistered); } @@ -250,9 +250,9 @@ unittest { //basic template allocation ushort[2] ids = [becsID!CInt, becsID!CFloat]; - EntityTemplate* tmpl_ = gEM.allocateTemplate(ids); - EntityTemplate* tmpl_d = gEM.allocateTemplate([becsID!CFloat, becsID!CInt, becsID!CFloat].staticArray); - EntityTemplate* tmpl_cp = gEM.allocateTemplate(tmpl_); + EntityTemplate* tmpl_ = gEntityManager.allocateTemplate(ids); + EntityTemplate* tmpl_d = gEntityManager.allocateTemplate([becsID!CFloat, becsID!CInt, becsID!CFloat].staticArray); + EntityTemplate* tmpl_cp = gEntityManager.allocateTemplate(tmpl_); assert(tmpl_d.info == tmpl_.info); assert(tmpl_cp.info == tmpl_cp.info); assert(tmpl_.info.components.length == 2); @@ -271,7 +271,7 @@ unittest //allocate template from template with additional components ushort[2] ids2 = [becsID!CDouble,becsID!CFlag]; - EntityTemplate* tmpl_2 = gEM.allocateTemplate(tmpl_, ids2); + EntityTemplate* tmpl_2 = gEntityManager.allocateTemplate(tmpl_, ids2); assert(tmpl_2.info.components.length == 4); assert(tmpl_2.getComponent!CInt); assert(tmpl_2.getComponent!CFloat); @@ -283,19 +283,19 @@ unittest assert(tmpl_.info.blocksCount() == 0); - Entity* entity = gEM.addEntity(tmpl_); - gEM.addComponents(entity.id, CFloat(100)); - gEM.addComponents(entity.id, CDouble(8.0), CFloat(100)); + Entity* entity = gEntityManager.addEntity(tmpl_); + gEntityManager.addComponents(entity.id, CFloat(100)); + gEntityManager.addComponents(entity.id, CDouble(8.0), CFloat(100)); assert(tmpl_.info.blocksCount() == 1); //apply entity changes - gEM.commit(); + gEntityManager.commit(); assert(tmpl_.info.blocksCount() == 0); //allocate template as entity copy - EntityTemplate* tmpl_3 = gEM.allocateTemplate(entity.id); + EntityTemplate* tmpl_3 = gEntityManager.allocateTemplate(entity.id); assert(tmpl_3.info.components.length == 3); assert(tmpl_3.getComponent!CInt); assert(tmpl_3.getComponent!CFloat); @@ -305,7 +305,7 @@ unittest assert(*tmpl_3.getComponent!CDouble == 8.0); //allocate template with entity data but default values - EntityTemplate* tmpl_4 = gEM.allocateTemplate(entity.id, true); + EntityTemplate* tmpl_4 = gEntityManager.allocateTemplate(entity.id, true); assert(tmpl_4.info.components.length == 3); assert(tmpl_4.getComponent!CInt); assert(tmpl_4.getComponent!CFloat); @@ -316,7 +316,7 @@ unittest //allocate template from template with three additional component ushort[3] ids3 = [becsID!CDouble, becsID!CLong, becsID!CShort]; - EntityTemplate* tmpl_5 = gEM.allocateTemplate(tmpl_2, ids3); + EntityTemplate* tmpl_5 = gEntityManager.allocateTemplate(tmpl_2, ids3); assert(tmpl_5.info.components.length == 6); assert(tmpl_5.getComponent!CInt); assert(tmpl_5.getComponent!CFloat); @@ -331,13 +331,13 @@ unittest //allocate template from template without one component ushort[1] rem_ids = [becsID!CFloat]; - EntityTemplate* tmpl_6 = gEM.allocateTemplate(tmpl_, null, rem_ids); + EntityTemplate* tmpl_6 = gEntityManager.allocateTemplate(tmpl_, null, rem_ids); assert(tmpl_6.info.components.length == 1); assert(tmpl_6.getComponent!CInt); assert(*tmpl_6.getComponent!CInt == 4); //allocate template from template without one component and two additional - EntityTemplate* tmpl_7 = gEM.allocateTemplate(tmpl_, ids3, rem_ids); + EntityTemplate* tmpl_7 = gEntityManager.allocateTemplate(tmpl_, ids3, rem_ids); assert(tmpl_7.info.components.length == 4); assert(tmpl_7.getComponent!CInt); assert(tmpl_7.getComponent!CDouble); @@ -346,15 +346,15 @@ unittest assert(*tmpl_7.getComponent!CDouble == 3.0); assert(*tmpl_7.getComponent!CLong == 10); - gEM.freeTemplate(tmpl_d); - gEM.freeTemplate(tmpl_cp); - gEM.freeTemplate(tmpl_); - gEM.freeTemplate(tmpl_2); - gEM.freeTemplate(tmpl_3); - gEM.freeTemplate(tmpl_4); - gEM.freeTemplate(tmpl_5); - gEM.freeTemplate(tmpl_6); - gEM.freeTemplate(tmpl_7); + gEntityManager.freeTemplate(tmpl_d); + gEntityManager.freeTemplate(tmpl_cp); + gEntityManager.freeTemplate(tmpl_); + gEntityManager.freeTemplate(tmpl_2); + gEntityManager.freeTemplate(tmpl_3); + gEntityManager.freeTemplate(tmpl_4); + gEntityManager.freeTemplate(tmpl_5); + gEntityManager.freeTemplate(tmpl_6); + gEntityManager.freeTemplate(tmpl_7); } @("UnsortedComponentIDs") @@ -363,56 +363,56 @@ unittest //basic template allocation ushort[2] ids = [becsID!CFloat, becsID!CInt]; ushort[2] ids2 = [becsID!CInt, becsID!CFloat]; - EntityTemplate* tmpl_ = gEM.allocateTemplate(ids); - EntityTemplate* tmpl_2 = gEM.allocateTemplate(ids2); + EntityTemplate* tmpl_ = gEntityManager.allocateTemplate(ids); + EntityTemplate* tmpl_2 = gEntityManager.allocateTemplate(ids2); assert(tmpl_.info.components.length == 2); assert(tmpl_.getComponent!CInt); assert(tmpl_.getComponent!CFloat); assert(*tmpl_.getComponent!CInt == 1); assert(*tmpl_.getComponent!CFloat == 2.0); assert(tmpl_.info == tmpl_2.info); - gEM.freeTemplate(tmpl_); - gEM.freeTemplate(tmpl_2); + gEntityManager.freeTemplate(tmpl_); + gEntityManager.freeTemplate(tmpl_2); } @("MultiRegister") unittest { - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.endRegister(); + gEntityManager.endRegister(); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CLong; - gEM.registerComponent!CShort; + gEntityManager.registerComponent!CLong; + gEntityManager.registerComponent!CShort; - gEM.endRegister(); + gEntityManager.endRegister(); } @("EmptySystem") unittest { - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!EmptySystem(0); + gEntityManager.registerSystem!EmptySystem(0); - gEM.endRegister(); + gEntityManager.endRegister(); - EmptySystem* system = gEM.getSystem!EmptySystem; + EmptySystem* system = gEntityManager.getSystem!EmptySystem; assert(system !is null); assert(system.count == 0); - System* ecs_system = gEM.getSystem(becsID!EmptySystem); + System* ecs_system = gEntityManager.getSystem(becsID!EmptySystem); assert(ecs_system !is null); assert(ecs_system.id == becsID!EmptySystem); assert(ecs_system.name == "tests.basic.EmptySystem"); - gEM.begin(); + gEntityManager.begin(); - gEM.update(); + gEntityManager.update(); - gEM.end(); + gEntityManager.end(); assert(system.count == 1); } @@ -480,23 +480,23 @@ unittest bool pass = true; } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem(0); - gEM.endRegister(); + gEntityManager.endRegister(); - TestSystem* system = gEM.getSystem!TestSystem; + TestSystem* system = gEntityManager.getSystem!TestSystem; int destroy = 0; system.destroy = &destroy; - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem(0); - gEM.endRegister(); + gEntityManager.endRegister(); - system = gEM.getSystem!TestSystem; + system = gEntityManager.getSystem!TestSystem; system.destroy = &destroy; assert(system !is null); assert(system.create == 1); @@ -507,7 +507,7 @@ unittest //FIXME: currently destroy is only called with Manager.destory which is bug, but there is no workaround for this by now //assert(destroy == 1); - System* ecs_system = gEM.getSystem(system.becsID); + System* ecs_system = gEntityManager.getSystem(system.becsID); ecs_system.enable(); assert(system.enable == 1); @@ -519,70 +519,70 @@ unittest ushort[2] ids = [becsID!CLong,becsID!CFloat]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); - gEM.addEntity(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); + gEntityManager.addEntity(tmpl); - gEM.begin(); + gEntityManager.begin(); assert(system.begin == 1); - gEM.update(); + gEntityManager.update(); assert(system.update == 1); - gEM.end(); + gEntityManager.end(); assert(system.end == 1); ushort[2] ids2 = [becsID!CLong, becsID!CInt]; - EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2); - scope (exit) gEM.freeTemplate(tmpl2); - gEM.addEntity(tmpl2); - gEM.addEntity(tmpl2); + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate(ids2); + scope (exit) gEntityManager.freeTemplate(tmpl2); + gEntityManager.addEntity(tmpl2); + gEntityManager.addEntity(tmpl2); - gEM.begin(); + gEntityManager.begin(); assert(system.begin == 2); - gEM.update(); + gEntityManager.update(); assert(system.update == 2);//system is updated number of entity blocks times - gEM.end(); + gEntityManager.end(); assert(system.end == 2); ushort[2] ids3 = [becsID!CLong, becsID!CShort]; - EntityTemplate* tmpl3 = gEM.allocateTemplate(ids3); - scope (exit) gEM.freeTemplate(tmpl3); - gEM.addEntity(tmpl3); + EntityTemplate* tmpl3 = gEntityManager.allocateTemplate(ids3); + scope (exit) gEntityManager.freeTemplate(tmpl3); + gEntityManager.addEntity(tmpl3); //entity with excluded component shouldn't be updated - gEM.begin(); + gEntityManager.begin(); assert(system.begin == 3); - gEM.update(); + gEntityManager.update(); assert(system.update == 2); - gEM.end(); + gEntityManager.end(); assert(system.end == 3); //system can be disable form update in onBegin() callback, onEnd() callback is called system.pass = false; - gEM.begin(); + gEntityManager.begin(); assert(system.begin == 4); - gEM.update(); + gEntityManager.update(); assert(system.update == 0); - gEM.end(); + gEntityManager.end(); assert(system.end == 4); system.pass = true; //disabled system is't called ecs_system.disable(); - gEM.begin(); + gEntityManager.begin(); assert(system.begin == 4); - gEM.update(); + gEntityManager.update(); assert(system.update == 0); - gEM.end(); + gEntityManager.end(); assert(system.end == 4); ecs_system.enable(); system.destroy = null; @@ -591,40 +591,40 @@ unittest @("CustomPass") unittest { - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerPass("custom"); - gEM.registerSystem!LongAddSystem(-1,"custom"); + gEntityManager.registerPass("custom"); + gEntityManager.registerSystem!LongAddSystem(-1,"custom"); - gEM.endRegister(); + gEntityManager.endRegister(); - assert(gEM.getPass("custom")); - assert(!gEM.getPass("custommm")); + assert(gEntityManager.getPass("custom")); + assert(!gEntityManager.getPass("custommm")); - LongAddSystem* system = gEM.getSystem!LongAddSystem; + LongAddSystem* system = gEntityManager.getSystem!LongAddSystem; assert(system !is null); assert(system.updates_count == 0); - System* ecs_system = gEM.getSystem(becsID!LongAddSystem); + System* ecs_system = gEntityManager.getSystem(becsID!LongAddSystem); assert(ecs_system !is null); assert(ecs_system.id == becsID!LongAddSystem); assert(ecs_system.priority == -1); assert(ecs_system.name == "tests.basic.LongAddSystem"); ushort[1] ids = [becsID!CLong]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); - gEM.addEntity(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); + gEntityManager.addEntity(tmpl); - gEM.begin(); + gEntityManager.begin(); - gEM.update(); + gEntityManager.update(); assert(system.updates_count == 0); - gEM.update("custom"); + gEntityManager.update("custom"); assert(system.updates_count == 1); - gEM.end(); + gEntityManager.end(); } @("SystemEntityCallbacks") @@ -748,91 +748,91 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem3(-1); - gEM.registerSystem!TestSystem(0); - gEM.registerSystem!TestSystem2(1); + gEntityManager.registerSystem!TestSystem3(-1); + gEntityManager.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem2(1); - gEM.endRegister(); + gEntityManager.endRegister(); - TestSystem* system = gEM.getSystem!TestSystem; + TestSystem* system = gEntityManager.getSystem!TestSystem; assert(system !is null); assert(system.add == 0); assert(system.remove == 0); assert(system.change == 0); - EntityTemplate* tmpl = gEM.allocateTemplate([becsID!CLong,becsID!CFloat].staticArray); - scope (exit) gEM.freeTemplate(tmpl); - EntityID id0 = gEM.addEntity(tmpl).id; - gEM.commit(); + EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!CLong,becsID!CFloat].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl); + EntityID id0 = gEntityManager.addEntity(tmpl).id; + gEntityManager.commit(); assert(system.add == 1); - EntityTemplate* tmpl2 = gEM.allocateTemplate([becsID!CLong, becsID!CInt].staticArray); - scope (exit) gEM.freeTemplate(tmpl2); - EntityID id1 = gEM.addEntity(tmpl2).id; - gEM.commit(); + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate([becsID!CLong, becsID!CInt].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl2); + EntityID id1 = gEntityManager.addEntity(tmpl2).id; + gEntityManager.commit(); assert(system.add == 2); - EntityTemplate* tmpl3 = gEM.allocateTemplate([becsID!CLong, becsID!CShort].staticArray); - scope (exit) gEM.freeTemplate(tmpl3); - EntityID id2 = gEM.addEntity(tmpl3).id; - gEM.commit(); + EntityTemplate* tmpl3 = gEntityManager.allocateTemplate([becsID!CLong, becsID!CShort].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl3); + EntityID id2 = gEntityManager.addEntity(tmpl3).id; + gEntityManager.commit(); assert(system.add == 2); - gEM.beginRegister(); - gEM.endRegister(); + gEntityManager.beginRegister(); + gEntityManager.endRegister(); - gEM.removeComponents(id0, [becsID!CFloat].staticArray); - gEM.commit(); + gEntityManager.removeComponents(id0, [becsID!CFloat].staticArray); + gEntityManager.commit(); assert(system.add == 2); assert(system.remove == 0); assert(system.change == 0); - gEM.removeComponents(id1, [becsID!CInt].staticArray); - gEM.commit(); + gEntityManager.removeComponents(id1, [becsID!CInt].staticArray); + gEntityManager.commit(); assert(system.add == 2); assert(system.remove == 0); assert(system.change == 1); - gEM.removeComponents(id2, [becsID!CShort].staticArray); - gEM.commit(); + gEntityManager.removeComponents(id2, [becsID!CShort].staticArray); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 0); assert(system.change == 1); - gEM.addComponents(id2, CShort(1)); - gEM.commit(); + gEntityManager.addComponents(id2, CShort(1)); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 1); assert(system.change == 1); - gEM.removeEntity(id0); - gEM.commit(); + gEntityManager.removeEntity(id0); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 2); assert(system.change == 1); - gEM.addComponents(id1, CInt(1)); - gEM.commit(); + gEntityManager.addComponents(id1, CInt(1)); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 2); assert(system.change == 2); - gEM.addComponents(id0, CFloat(1)); - gEM.commit(); + gEntityManager.addComponents(id0, CFloat(1)); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 2); assert(system.change == 2); - gEM.removeEntity(id1); - gEM.commit(); + gEntityManager.removeEntity(id1); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 3); assert(system.change == 2); - gEM.removeEntity(id2); - gEM.commit(); + gEntityManager.removeEntity(id2); + gEntityManager.commit(); assert(system.add == 3); assert(system.remove == 3); assert(system.change == 2); @@ -862,13 +862,13 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CUnregistered; + gEntityManager.registerComponent!CUnregistered; - gEM.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem(0); - gEM.endRegister(); + gEntityManager.endRegister(); } @("UnregisteredSystem") @@ -893,8 +893,8 @@ unittest } } - assert(gEM.getSystem!TestSystem is null); - assert(gEM.getSystem(becsID!TestSystem) is null); + assert(gEntityManager.getSystem!TestSystem is null); + assert(gEntityManager.getSystem(becsID!TestSystem) is null); } @("MultithreadedUpdate") @@ -953,68 +953,68 @@ unittest return 0; } - gEM.setMultithreadingCallbacks(&dispatch, &getID); + gEntityManager.setMultithreadingCallbacks(&dispatch, &getID); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerPass("custom"); - gEM.registerSystem!TestSystem(-1,"custom"); - gEM.registerSystem!TestEmptySystem(1,"custom"); + gEntityManager.registerPass("custom"); + gEntityManager.registerSystem!TestSystem(-1,"custom"); + gEntityManager.registerSystem!TestEmptySystem(1,"custom"); - gEM.endRegister(); + gEntityManager.endRegister(); - TestSystem* system = gEM.getSystem!TestSystem; - TestEmptySystem* empty_system = gEM.getSystem!TestEmptySystem; + TestSystem* system = gEntityManager.getSystem!TestSystem; + TestEmptySystem* empty_system = gEntityManager.getSystem!TestEmptySystem; ushort[2] ids = [becsID!CLong,becsID!CFloat]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); - EntityTemplate* tmpl2 = gEM.allocateTemplate([becsID!CLong,becsID!CInt,becsID!CShort,becsID!CFloat].staticArray); - scope (exit) gEM.freeTemplate(tmpl2); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate([becsID!CLong,becsID!CInt,becsID!CShort,becsID!CFloat].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl2); - gEM.begin(); + gEntityManager.begin(); - gEM.updateMT("custom"); + gEntityManager.updateMT("custom"); - gEM.end(); + gEntityManager.end(); assert(system.update == 0); assert(system.entities == 0); assert(empty_system.update == 1); - gEM.addEntity(tmpl); + gEntityManager.addEntity(tmpl); - gEM.begin(); + gEntityManager.begin(); - gEM.updateMT("custom"); + gEntityManager.updateMT("custom"); - gEM.end(); + gEntityManager.end(); assert(system.update == 1); assert(system.entities == 1); assert(empty_system.update == 2); system.entities = 0; - foreach(i;0..2000)gEM.addEntity(tmpl); + foreach(i;0..2000)gEntityManager.addEntity(tmpl); - gEM.begin(); + gEntityManager.begin(); - gEM.updateMT("custom"); + gEntityManager.updateMT("custom"); - gEM.end(); + gEntityManager.end(); assert(system.update > 2); assert(system.entities == 2001); assert(empty_system.update == 3); system.entities = 0; - // foreach(i;0..10000)gEM.addEntity(tmpl); + // foreach(i;0..10000)gEntityManager.addEntity(tmpl); - // gEM.begin(); + // gEntityManager.begin(); - // gEM.updateMT("custom"); + // gEntityManager.updateMT("custom"); - // gEM.end(); + // gEntityManager.end(); // assert(system.entities == 12001); @@ -1022,33 +1022,33 @@ unittest { foreach(i;0..data.length) { - gEM.removeEntity(data.entity[i].id); + gEntityManager.removeEntity(data.entity[i].id); } } - gEM.callEntitiesFunction!TestSystem(&clearEntities); - gEM.commit(); + gEntityManager.callEntitiesFunction!TestSystem(&clearEntities); + gEntityManager.commit(); foreach(i;0..2000) { - gEM.addEntity(tmpl); + gEntityManager.addEntity(tmpl); - gEM.begin(); - gEM.updateMT("custom"); - gEM.end(); + gEntityManager.begin(); + gEntityManager.updateMT("custom"); + gEntityManager.end(); assert(system.entities == i+1); system.entities = 0; } - foreach(i;0..90000)gEM.addEntity(tmpl); + foreach(i;0..90000)gEntityManager.addEntity(tmpl); foreach(i;0..2000) { - gEM.addEntity(tmpl); + gEntityManager.addEntity(tmpl); - gEM.begin(); - gEM.updateMT("custom"); - gEM.end(); + gEntityManager.begin(); + gEntityManager.updateMT("custom"); + gEntityManager.end(); assert(system.entities == i+92001); system.entities = 0; @@ -1057,16 +1057,16 @@ unittest unittest { - assert(gEM.pageSize == 32768); - assert(gEM.pagesInBlock == 128); + assert(gEntityManager.pageSize == 32768); + assert(gEntityManager.pagesInBlock == 128); } @("AddRemoveEntities") unittest { ushort[3] ids = [becsID!CLong,becsID!CFloat,becsID!CShort]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); EntityID[5000] entities; @@ -1074,33 +1074,33 @@ unittest { foreach(j;0..5000) { - entities[j] = gEM.addEntity(tmpl).id; + entities[j] = gEntityManager.addEntity(tmpl).id; } - gEM.commit(); + gEntityManager.commit(); foreach(j;0..5000) { - gEM.removeEntity(entities[j]); + gEntityManager.removeEntity(entities[j]); } - gEM.commit(); + gEntityManager.commit(); } } @("ChangeEntityComponents") unittest { - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CUnregistered; + gEntityManager.registerComponent!CUnregistered; - gEM.endRegister(); + gEntityManager.endRegister(); ushort[1] ids = [becsID!CLong]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); - EntityID id = gEM.addEntity(tmpl).id; - gEM.commit(); - Entity* entity = gEM.getEntity(id); + EntityID id = gEntityManager.addEntity(tmpl).id; + gEntityManager.commit(); + Entity* entity = gEntityManager.getEntity(id); assert(entity.id == id); assert(entity.getComponent!CLong !is null); assert(entity.getComponent!CFloat is null); @@ -1109,10 +1109,10 @@ unittest assert(entity.getComponent!CInt is null); assert(*entity.getComponent!CLong == 10); - gEM.addComponents(id, CShort(15), CFloat(13)); - gEM.commit(); + gEntityManager.addComponents(id, CShort(15), CFloat(13)); + gEntityManager.commit(); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(entity.id == id); assert(entity.getComponent!CLong !is null); assert(entity.getComponent!CFloat !is null); @@ -1124,10 +1124,10 @@ unittest assert(*entity.getComponent!CFloat == 13); ushort[3] ids2 = [becsID!CFloat, becsID!CLong, becsID!CUnregistered]; - gEM.removeComponents(id, ids2); - gEM.commit(); + gEntityManager.removeComponents(id, ids2); + gEntityManager.commit(); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(entity.id == id); assert(entity.getComponent!CLong is null); assert(entity.getComponent!CFloat is null); @@ -1136,11 +1136,11 @@ unittest assert(entity.getComponent!CInt is null); assert(*entity.getComponent!CShort == 15); - gEM.removeComponents(id, ids2); - gEM.addComponents(id, CShort(11), CLong(2)); //wrong order of components - gEM.commit(); + gEntityManager.removeComponents(id, ids2); + gEntityManager.addComponents(id, CShort(11), CLong(2)); //wrong order of components + gEntityManager.commit(); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(entity.id == id); assert(entity.getComponent!CLong !is null); assert(entity.getComponent!CFloat is null); @@ -1150,14 +1150,14 @@ unittest assert(*entity.getComponent!CLong == 2); assert(*entity.getComponent!CShort == 15); - gEM.removeEntity(id); + gEntityManager.removeEntity(id); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(entity !is null); assert(entity.id == id); - gEM.commit(); - entity = gEM.getEntity(id); + gEntityManager.commit(); + entity = gEntityManager.getEntity(id); assert(entity is null); } @@ -1245,52 +1245,52 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerEvent!ETest; - gEM.registerEvent!ETest2; + gEntityManager.registerEvent!ETest; + gEntityManager.registerEvent!ETest2; - gEM.registerEvent!ETest; - gEM.registerEvent!ETest2; + gEntityManager.registerEvent!ETest; + gEntityManager.registerEvent!ETest2; - gEM.registerSystem!TestSystem2(1); - gEM.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem2(1); + gEntityManager.registerSystem!TestSystem(0); - gEM.endRegister(); + gEntityManager.endRegister(); ushort[1] ids = [becsID!CLong]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); - scope (exit) gEM.freeTemplate(tmpl); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); + scope (exit) gEntityManager.freeTemplate(tmpl); ushort[1] ids2 = [becsID!CShort]; - EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2); - scope (exit) gEM.freeTemplate(tmpl2); + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate(ids2); + scope (exit) gEntityManager.freeTemplate(tmpl2); - Entity* entity = gEM.addEntity(tmpl); + Entity* entity = gEntityManager.addEntity(tmpl); EntityID id = entity.id; assert(*entity.getComponent!CLong == 10); - Entity* entity2 = gEM.addEntity(tmpl2); + Entity* entity2 = gEntityManager.addEntity(tmpl2); EntityID id2 = entity2.id; assert(*entity2.getComponent!CShort == 12); - gEM.sendEvent(id,ETest()); - gEM.sendEvent(id,ETest2(10)); - gEM.sendEvent(id2,ETest()); - gEM.sendEvent(id2,ETest2(12)); - gEM.commit(); + gEntityManager.sendEvent(id,ETest()); + gEntityManager.sendEvent(id,ETest2(10)); + gEntityManager.sendEvent(id2,ETest()); + gEntityManager.sendEvent(id2,ETest2(12)); + gEntityManager.commit(); assert(ETest2.destory == 2); - entity = gEM.getEntity(id); - entity2 = gEM.getEntity(id2); + entity = gEntityManager.getEntity(id); + entity2 = gEntityManager.getEntity(id2); assert(*entity.getComponent!CLong == 46); assert(*entity2.getComponent!CShort == 32); - gEM.addComponents(id, CInt(2), CShort(1)); - gEM.sendEvent(id,ETest()); - gEM.sendEvent(id,ETest2(2)); - gEM.commit(); + gEntityManager.addComponents(id, CInt(2), CShort(1)); + gEntityManager.sendEvent(id,ETest()); + gEntityManager.sendEvent(id,ETest2(2)); + gEntityManager.commit(); assert(ETest2.destory == 3); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(*entity.getComponent!CLong == 66); assert(*entity.getComponent!CInt == 2);//36); @@ -1298,18 +1298,18 @@ unittest long result = *entity.getComponent!CLong; foreach(i;0..10000) { - gEM.sendEvent(id,ETest()); - gEM.sendEvent(id,ETest2(4)); + gEntityManager.sendEvent(id,ETest()); + gEntityManager.sendEvent(id,ETest2(4)); result += 16; result += 8; } - gEM.commit(); + gEntityManager.commit(); assert(ETest2.destory == 10003); - entity = gEM.getEntity(id); + entity = gEntityManager.getEntity(id); assert(*entity.getComponent!CLong == result); //cover funcion to clearEvents before destroying manager - gEM.sendEvent(id,ETest()); + gEntityManager.sendEvent(id,ETest()); } @("EntitiesFunction") @@ -1347,36 +1347,36 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem(1); + gEntityManager.registerSystem!TestSystem(1); - gEM.endRegister(); + gEntityManager.endRegister(); - EntityTemplate* tmpl = gEM.allocateTemplate([becsID!CInt].staticArray); - scope (exit) gEM.freeTemplate(tmpl); - EntityID id1 = gEM.addEntity(tmpl).id; + EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!CInt].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl); + EntityID id1 = gEntityManager.addEntity(tmpl).id; - EntityTemplate* tmpl2 = gEM.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); - scope (exit) gEM.freeTemplate(tmpl2); - EntityID id2 = gEM.addEntity(tmpl2).id; + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); + scope (exit) gEntityManager.freeTemplate(tmpl2); + EntityID id2 = gEntityManager.addEntity(tmpl2).id; - gEM.begin(); + gEntityManager.begin(); - Entity* entity1 = gEM.getEntity(id1); - Entity* entity2 = gEM.getEntity(id2); + Entity* entity1 = gEntityManager.getEntity(id1); + Entity* entity2 = gEntityManager.getEntity(id2); assert(*entity1.getComponent!CInt == 1); assert(*entity2.getComponent!CInt == 1); - gEM.callEntitiesFunction!TestSystem(&func2); + gEntityManager.callEntitiesFunction!TestSystem(&func2); assert(*entity1.getComponent!CInt == 9); assert(*entity2.getComponent!CInt == 9); - gEM.callEntitiesFunction!TestSystem(&func1); + gEntityManager.callEntitiesFunction!TestSystem(&func1); assert(*entity1.getComponent!CInt == 13); assert(*entity2.getComponent!CInt == 13); - gEM.end(); + gEntityManager.end(); } @("SystemDependencies") @@ -1463,17 +1463,17 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem(0); - gEM.registerSystem!TestSystem2(1); - gEM.registerSystem!TestSystem3(2); - gEM.registerSystem!TestSystem4(3); - gEM.registerSystem!TestSystem5(4); + gEntityManager.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem2(1); + gEntityManager.registerSystem!TestSystem3(2); + gEntityManager.registerSystem!TestSystem4(3); + gEntityManager.registerSystem!TestSystem5(4); - gEM.endRegister(); + gEntityManager.endRegister(); - const (EntityManager.UpdatePass)* pass = gEM.getPass("update"); + const (EntityManager.UpdatePass)* pass = gEntityManager.getPass("update"); assert(pass != null); assert(pass.system_callers.length == 5); assert(pass.system_callers[0].system_id == becsID!TestSystem); @@ -1588,19 +1588,19 @@ unittest } } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerDependency(TestDependency); + gEntityManager.registerDependency(TestDependency); - gEM.registerSystem!TestSystem(0); - gEM.registerSystem!TestSystem2(1); - gEM.registerSystem!TestSystem3(2); - gEM.registerSystem!TestSystem4(3); - gEM.registerSystem!TestSystem5(4); + gEntityManager.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem2(1); + gEntityManager.registerSystem!TestSystem3(2); + gEntityManager.registerSystem!TestSystem4(3); + gEntityManager.registerSystem!TestSystem5(4); - gEM.endRegister(); + gEntityManager.endRegister(); - const (EntityManager.UpdatePass)* pass = gEM.getPass("update"); + const (EntityManager.UpdatePass)* pass = gEntityManager.getPass("update"); assert(pass != null); assert(pass.system_callers.length == 5); assert(pass.system_callers[0].system_id == becsID!TestSystem); @@ -1686,40 +1686,40 @@ unittest uint updates = 0; } - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerSystem!TestSystem(0); - gEM.registerSystem!TestSystem2(1); + gEntityManager.registerSystem!TestSystem(0); + gEntityManager.registerSystem!TestSystem2(1); - gEM.endRegister(); + gEntityManager.endRegister(); - EntityTemplate* tmpl_ = gEM.allocateTemplate([becsID!CInt, becsID!CLong, becsID!CFloat, becsID!CDouble].staticArray); - scope(exit)gEM.freeTemplate(tmpl_); - EntityTemplate* tmpl_2 = gEM.allocateTemplate([becsID!CInt, becsID!CFloat].staticArray); - scope(exit)gEM.freeTemplate(tmpl_2); - EntityTemplate* tmpl_3 = gEM.allocateTemplate([becsID!CLong, becsID!CDouble].staticArray); - scope(exit)gEM.freeTemplate(tmpl_3); - EntityTemplate* tmpl_4 = gEM.allocateTemplate([becsID!CInt, becsID!CLong, becsID!CDouble].staticArray); - scope(exit)gEM.freeTemplate(tmpl_4); - EntityTemplate* tmpl_5 = gEM.allocateTemplate([becsID!CInt, becsID!CDouble].staticArray); - scope(exit)gEM.freeTemplate(tmpl_5); - EntityTemplate* tmpl_6 = gEM.allocateTemplate([becsID!CDouble].staticArray); - scope(exit)gEM.freeTemplate(tmpl_6); + EntityTemplate* tmpl_ = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong, becsID!CFloat, becsID!CDouble].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_); + EntityTemplate* tmpl_2 = gEntityManager.allocateTemplate([becsID!CInt, becsID!CFloat].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_2); + EntityTemplate* tmpl_3 = gEntityManager.allocateTemplate([becsID!CLong, becsID!CDouble].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_3); + EntityTemplate* tmpl_4 = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong, becsID!CDouble].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_4); + EntityTemplate* tmpl_5 = gEntityManager.allocateTemplate([becsID!CInt, becsID!CDouble].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_5); + EntityTemplate* tmpl_6 = gEntityManager.allocateTemplate([becsID!CDouble].staticArray); + scope(exit)gEntityManager.freeTemplate(tmpl_6); - gEM.addEntity(tmpl_); - gEM.addEntity(tmpl_2); - gEM.addEntity(tmpl_3); - gEM.addEntity(tmpl_4); - gEM.addEntity(tmpl_5); - gEM.addEntity(tmpl_6); + gEntityManager.addEntity(tmpl_); + gEntityManager.addEntity(tmpl_2); + gEntityManager.addEntity(tmpl_3); + gEntityManager.addEntity(tmpl_4); + gEntityManager.addEntity(tmpl_5); + gEntityManager.addEntity(tmpl_6); - TestSystem* test_system = gEM.getSystem!TestSystem; - TestSystem2* test_system2 = gEM.getSystem!TestSystem2; + TestSystem* test_system = gEntityManager.getSystem!TestSystem; + TestSystem2* test_system2 = gEntityManager.getSystem!TestSystem2; - gEM.begin(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.end(); assert(test_system.updates == 2); assert(test_system2.updates == 2); diff --git a/tests/bugs.d b/tests/bugs.d index 25f2ad1..3c5f426 100644 --- a/tests/bugs.d +++ b/tests/bugs.d @@ -45,23 +45,23 @@ unittest void onCreate() { - tmpl = gEM.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); } void onDestroy() { - gEM.freeTemplate(tmpl); + gEntityManager.freeTemplate(tmpl); } void handleEvent(Entity* entity, Event1 event) { - gEM.removeEntity(event.id); - gEM.sendEvent(entity.id,Event2()); + gEntityManager.removeEntity(event.id); + gEntityManager.sendEvent(entity.id,Event2()); } void handleEvent(Entity* entity, Event2 event) { - id = gEM.addEntity(tmpl).id; + id = gEntityManager.addEntity(tmpl).id; } } @@ -94,49 +94,49 @@ unittest ///remove every entity void onUpdate(EntitiesData data) { - foreach(i;0..data.length)gEM.removeEntity(data.entity[i].id); + foreach(i;0..data.length)gEntityManager.removeEntity(data.entity[i].id); } } - gEM.initialize(0); + gEntityManager.initialize(0); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CInt; - gEM.registerComponent!CFloat; - gEM.registerComponent!CDouble; - gEM.registerComponent!CLong; - gEM.registerComponent!CShort; - gEM.registerComponent!CFlag; + gEntityManager.registerComponent!CInt; + gEntityManager.registerComponent!CFloat; + gEntityManager.registerComponent!CDouble; + gEntityManager.registerComponent!CLong; + gEntityManager.registerComponent!CShort; + gEntityManager.registerComponent!CFlag; - gEM.registerEvent!Event1; - gEM.registerEvent!Event2; + gEntityManager.registerEvent!Event1; + gEntityManager.registerEvent!Event2; - gEM.registerSystem!System1(0); - gEM.registerSystem!System2(-200); - gEM.registerSystem!System3(-200); + gEntityManager.registerSystem!System1(0); + gEntityManager.registerSystem!System2(-200); + gEntityManager.registerSystem!System3(-200); - gEM.endRegister(); + gEntityManager.endRegister(); - EntityTemplate* tmpl = gEM.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); - EntityID id = gEM.addEntity(tmpl,[CLong(10).ref_, CInt(6).ref_].staticArray).id; - EntityID id2 = gEM.addEntity(tmpl,[CInt(4).ref_].staticArray).id; - gEM.freeTemplate(tmpl); - gEM.commit(); + EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray); + EntityID id = gEntityManager.addEntity(tmpl,[CLong(10).ref_, CInt(6).ref_].staticArray).id; + EntityID id2 = gEntityManager.addEntity(tmpl,[CInt(4).ref_].staticArray).id; + gEntityManager.freeTemplate(tmpl); + gEntityManager.commit(); - gEM.sendEvent(id2, Event1(id)); + gEntityManager.sendEvent(id2, Event1(id)); - gEM.getSystem(becsID!System2).disable(); + gEntityManager.getSystem(becsID!System2).disable(); - gEM.begin(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.end(); - gEM.getSystem(becsID!System2).enable(); + gEntityManager.getSystem(becsID!System2).enable(); - gEM.begin(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.end(); - gEM.destroy(); + gEntityManager.destroy(); } \ No newline at end of file diff --git a/tests/perf.d b/tests/perf.d index cc6be94..695b46e 100644 --- a/tests/perf.d +++ b/tests/perf.d @@ -63,123 +63,123 @@ EntityTemplate* tmpl; void beforeEveryTest() { - gEM.initialize(0); + gEntityManager.initialize(0); - gEM.beginRegister(); + gEntityManager.beginRegister(); - gEM.registerComponent!CLong; - gEM.registerComponent!CShort; - gEM.registerComponent!CInt; - gEM.registerComponent!CUInt; - gEM.registerComponent!CBig; + gEntityManager.registerComponent!CLong; + gEntityManager.registerComponent!CShort; + gEntityManager.registerComponent!CInt; + gEntityManager.registerComponent!CUInt; + gEntityManager.registerComponent!CBig; - gEM.endRegister(); + gEntityManager.endRegister(); tmpl = null; } void afterEveryTest() { - if(tmpl)gEM.freeTemplate(tmpl); + if(tmpl)gEntityManager.freeTemplate(tmpl); tmpl = null; - gEM.destroy(); + gEntityManager.destroy(); } void smallTmpl() { - tmpl = gEM.allocateTemplate([becsID!CShort].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CShort].staticArray); } void bigTmpl() { - tmpl = gEM.allocateTemplate([becsID!CBig].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CBig].staticArray); } void multiSmallTmpl() { - tmpl = gEM.allocateTemplate([becsID!CShort, becsID!CLong, becsID!CInt, becsID!CUInt].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CShort, becsID!CLong, becsID!CInt, becsID!CUInt].staticArray); } void multiBigTmpl() { - tmpl = gEM.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); } @("AddEntities100k1comp2b") @(before, &smallTmpl) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k1comp128b") @(before, &bigTmpl) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k4comp18b") @(before, &multiSmallTmpl) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k4comp144b") @(before, &multiBigTmpl) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } void allocDealloc100k() { - foreach(i; 0..100_000)gEM.addEntity(tmpl); - gEM.commit(); - foreach(i; 0..100_000)gEM.removeEntity(EntityID(i + 1,0)); - gEM.commit(); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); + gEntityManager.commit(); + foreach(i; 0..100_000)gEntityManager.removeEntity(EntityID(i + 1,0)); + gEntityManager.commit(); } void smallTmplPreAlloc() { - tmpl = gEM.allocateTemplate([becsID!CShort].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CShort].staticArray); allocDealloc100k(); } void bigTmplPreAlloc() { - tmpl = gEM.allocateTemplate([becsID!CBig].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CBig].staticArray); allocDealloc100k(); } void multiSmallTmplPreAlloc() { - tmpl = gEM.allocateTemplate([becsID!CShort, becsID!CLong, becsID!CInt, becsID!CUInt].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CShort, becsID!CLong, becsID!CInt, becsID!CUInt].staticArray); allocDealloc100k(); } void multiBigTmplPreAlloc() { - tmpl = gEM.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); + tmpl = gEntityManager.allocateTemplate([becsID!CLong, becsID!CInt, becsID!CUInt, becsID!CBig].staticArray); allocDealloc100k(); } @("AddEntities100k1comp2bPreAlloc") @(before, &smallTmplPreAlloc) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k1comp128bPreAlloc") @(before, &bigTmplPreAlloc) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k4comp18bPreAlloc") @(before, &multiSmallTmplPreAlloc) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } @("AddEntities100k4comp144bPreAlloc") @(before, &multiBigTmplPreAlloc) unittest { - foreach(i; 0..100_000)gEM.addEntity(tmpl); + foreach(i; 0..100_000)gEntityManager.addEntity(tmpl); } \ No newline at end of file diff --git a/tests/tests.d b/tests/tests.d index f82519d..164eb30 100644 --- a/tests/tests.d +++ b/tests/tests.d @@ -226,7 +226,7 @@ struct EverySystem { foreach(i;0..data.length) { - gEM.removeEntity(data.entity[i].id); + gEntityManager.removeEntity(data.entity[i].id); } } @@ -234,7 +234,7 @@ struct EverySystem { foreach(i;0..data.length) { - gEM.addComponents(data.entity[i].id, TestComp2()); + gEntityManager.addComponents(data.entity[i].id, TestComp2()); } } } @@ -566,7 +566,7 @@ struct TestSystem2 test.bg = event.a; TestEvent2 event2; event2.a = event.a + 8; - gEM.sendEvent(entity.id, event2); + gEntityManager.sendEvent(entity.id, event2); } void handleEvent(Entity* entity, TestEvent2 event) @@ -601,12 +601,12 @@ struct TestSystem2 data.test[i].gg += 14; TestEvent event; event.a = data.test[i].gg + 4; - gEM.sendEvent(data.entity[i].id, event); //*/ + gEntityManager.sendEvent(data.entity[i].id, event); //*/ /*TestEvent2 event2; event2.a = data.test[i].gg + 8; - gEM.sendEvent(data.entity[i].id, event2);//*/ - //gEM.sendEvent!(TestEvent)(data.entity[i].id, event); - //gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent()); + gEntityManager.sendEvent(data.entity[i].id, event2);//*/ + //gEntityManager.sendEvent!(TestEvent)(data.entity[i].id, event); + //gEntityManager.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent()); } } @@ -615,7 +615,7 @@ struct TestSystem2 foreach (i; 0 .. data.test.length) { data.test[i].gg -= 1; - //gEM.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent()); + //gEntityManager.sendSelfEvent!(TestEvent)(data.entity[i].id, TestEvent()); } } @@ -686,25 +686,25 @@ else: EntityManager.initialize(1); - //gEM.setJobDispachFunc(&dispatch); - gEM.setMultithreadingCallbacks(&dispatch, &getID); - //assert(gEM !is null); + //gEntityManager.setJobDispachFunc(&dispatch); + gEntityManager.setMultithreadingCallbacks(&dispatch, &getID); + //assert(gEntityManager !is null); - gEM.beginRegister(); - gEM.registerPass("fixed"); + gEntityManager.beginRegister(); + gEntityManager.registerPass("fixed"); //MonoTime time = MonoTime.currTime; long time = Time.getUSecTime(); - gEM.registerComponent!TestComp2; - gEM.registerComponent!TestComp4; - gEM.registerComponent!TestComp; - gEM.registerComponent!TestComp3; - gEM.registerComponent!TestComp5; - gEM.registerComponent!CPosition; + gEntityManager.registerComponent!TestComp2; + gEntityManager.registerComponent!TestComp4; + gEntityManager.registerComponent!TestComp; + gEntityManager.registerComponent!TestComp3; + gEntityManager.registerComponent!TestComp5; + gEntityManager.registerComponent!CPosition; - gEM.registerEvent!TestEvent; - gEM.registerEvent!TestEvent2; + gEntityManager.registerEvent!TestEvent; + gEntityManager.registerEvent!TestEvent2; /*ulong dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Components register: ", dur, " usecs"); @@ -714,19 +714,19 @@ else: printf("Components register: %f usecs\n", cast(float)(Time.getUSecTime() - time)); time = Time.getUSecTime(); - gEM.registerSystem!TestSystemWithHighPriority(100, "fixed"); - gEM.registerSystem!TestSystem(0); - gEM.registerSystem!ChangeTestSystem(0); - gEM.registerSystem!Sys1(10); - gEM.registerSystem!Sys2(-100); - gEM.registerSystem!Sys3(-2); - gEM.registerSystem!EmptySystem(2); - gEM.registerSystem!EmptyEventSystem(2); - gEM.registerSystem!EventSystem(2); - gEM.registerSystem!EverySystem(0); - //gEM.registerSystem!TestSystemWithHighPriority(100); - //gEM.registerSystem!TestSystem2(0); - gEM.endRegister(); + gEntityManager.registerSystem!TestSystemWithHighPriority(100, "fixed"); + gEntityManager.registerSystem!TestSystem(0); + gEntityManager.registerSystem!ChangeTestSystem(0); + gEntityManager.registerSystem!Sys1(10); + gEntityManager.registerSystem!Sys2(-100); + gEntityManager.registerSystem!Sys3(-2); + gEntityManager.registerSystem!EmptySystem(2); + gEntityManager.registerSystem!EmptyEventSystem(2); + gEntityManager.registerSystem!EventSystem(2); + gEntityManager.registerSystem!EverySystem(0); + //gEntityManager.registerSystem!TestSystemWithHighPriority(100); + //gEntityManager.registerSystem!TestSystem2(0); + gEntityManager.endRegister(); /*dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Systems register: ", dur, " usecs"); @@ -737,11 +737,11 @@ else: //ushort[3] ids = [becsID!TestComp2, becsID!TestComp, becsID!TestComp4]; ushort[2] ids = [becsID!TestComp2, becsID!TestComp]; - EntityTemplate* tmpl = gEM.allocateTemplate(ids); + EntityTemplate* tmpl = gEntityManager.allocateTemplate(ids); //ushort[3] ids2 = [becsID!TestComp3, becsID!TestComp, becsID!TestComp4]; ushort[2] ids2 = [becsID!TestComp3, becsID!TestComp]; - EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2); + EntityTemplate* tmpl2 = gEntityManager.allocateTemplate(ids2); ////writeln(tmpl.info.components[]); //*cast(EntityID*) tmpl.entity_data.ptr = EntityID(1, 1); @@ -752,67 +752,67 @@ else: time = Time.getUSecTime(); ushort[1] empty_ids = [becsID!CPosition]; - EntityTemplate* tmpl_empty = gEM.allocateTemplate(empty_ids); + EntityTemplate* tmpl_empty = gEntityManager.allocateTemplate(empty_ids); - gEM.commit(); + gEntityManager.commit(); time = Time.getUSecTime(); - foreach(i;0..4_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); - foreach(i;0..4_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); - foreach(i;0..2_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); + foreach(i;0..4_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); + foreach(i;0..4_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); + foreach(i;0..2_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); printf("Adding 1M entities: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - gEM.commit(); + gEntityManager.commit(); time = Time.getUSecTime(); - gEM.callEntitiesFunction!EverySystem(&gEM.getSystem!EverySystem().iterate); + gEntityManager.callEntitiesFunction!EverySystem(&gEntityManager.getSystem!EverySystem().iterate); printf("Iterate 1M entities: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - gEM.begin(); + gEntityManager.begin(); time = Time.getUSecTime(); - gEM.update(); + gEntityManager.update(); printf("Iterate 1M entities (update): %f usecs\n", cast(float)(Time.getUSecTime() - time)); - gEM.end(); + gEntityManager.end(); time = Time.getUSecTime(); - gEM.callEntitiesFunction!EverySystem(&gEM.getSystem!EverySystem().free); - gEM.commit(); + gEntityManager.callEntitiesFunction!EverySystem(&gEntityManager.getSystem!EverySystem().free); + gEntityManager.commit(); printf("Deleting 1M entities: %f usecs\n", cast(float)(Time.getUSecTime() - time)); time = Time.getUSecTime(); - foreach(i;0..4_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); - foreach(i;0..4_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); - foreach(i;0..2_000_000)gEM.addEntity(tmpl_empty); - gEM.commit(); + foreach(i;0..4_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); + foreach(i;0..4_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); + foreach(i;0..2_000_000)gEntityManager.addEntity(tmpl_empty); + gEntityManager.commit(); printf("Adding 1M entities (prealloc): %f usecs\n", cast(float)(Time.getUSecTime() - time)); - gEM.commit(); + gEntityManager.commit(); time = Time.getUSecTime(); - gEM.callEntitiesFunction!EverySystem(&gEM.getSystem!EverySystem().addOne); - gEM.commit(); + gEntityManager.callEntitiesFunction!EverySystem(&gEntityManager.getSystem!EverySystem().addOne); + gEntityManager.commit(); printf("Adding 1M component: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - gEM.commit(); - gEM.callEntitiesFunction!EverySystem(&gEM.getSystem!EverySystem().free); - gEM.commit(); + gEntityManager.commit(); + gEntityManager.callEntitiesFunction!EverySystem(&gEntityManager.getSystem!EverySystem().free); + gEntityManager.commit(); time = Time.getUSecTime(); EntityID entity; { - entity = gEM.addEntity(tmpl).id; - writeEntityComponents(gEM.getEntity(entity)); - EntityManager.EntitiesBlock* block = EntityManager.instance.getMetaData( - gEM.getEntity(entity)); + entity = gEntityManager.addEntity(tmpl).id; + writeEntityComponents(gEntityManager.getEntity(entity)); + EntityManager.EntitiesBlock* block = gEntityManager.getMetaData( + gEntityManager.getEntity(entity)); EntityManager.EntityInfo* info = block.type_info; //writeln(info.add_listeners); //if(info)assert(0); @@ -821,9 +821,9 @@ else: //time = MonoTime.currTime; time = Time.getUSecTime(); - //foreach(i; 0..1_000_000)gEM.addEntity(tmpl); + //foreach(i; 0..1_000_000)gEntityManager.addEntity(tmpl); - //foreach(i; 0..1_000_000)gEM.removeEntity(gEM.addEntity(tmpl).id); + //foreach(i; 0..1_000_000)gEntityManager.removeEntity(gEntityManager.addEntity(tmpl).id); import bubel.ecs.std; @@ -832,14 +832,14 @@ else: foreach (i; 0 .. 200) { - gEM.begin(); + gEntityManager.begin(); foreach (j; 0 .. 5_000) - idss[j] = gEM.addEntity(tmpl).id; + idss[j] = gEntityManager.addEntity(tmpl).id; foreach (j; 0 .. 5_000) - gEM.removeEntity(idss[j]); - gEM.end(); + gEntityManager.removeEntity(idss[j]); + gEntityManager.end(); } - gEM.commit(); + gEntityManager.commit(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Entities adding: ", dur, " usecs"); @@ -847,7 +847,7 @@ else: time = Time.getUSecTime(); uint blocks = 0; - foreach (info; &gEM.entities_infos.byValue) + foreach (info; &gEntityManager.entities_infos.byValue) { EntityManager.EntitiesBlock* block = info.first_block; while (block !is null) @@ -859,13 +859,13 @@ else: //writeln("Entities blocks: ", blocks); printf("Entities blocks: %u\n", blocks); - //foreach(j; 0..1_000)gEM.addEntity(tmpl); + //foreach(j; 0..1_000)gEntityManager.addEntity(tmpl); - gEM.beginRegister(); - gEM.registerSystem!TestSystem2(0); - gEM.endRegister(); + gEntityManager.beginRegister(); + gEntityManager.registerSystem!TestSystem2(0); + gEntityManager.endRegister(); - //gEM.generateDependencies(); + //gEntityManager.generateDependencies(); //assert(*(cast(EntityID*)(cast(void*)tmpl.info.first_block+24)) == EntityID(1,1)); //assert(*(cast(EntityID*)(cast(void*)tmpl.info.first_block+48)) == EntityID(1,1)); @@ -878,12 +878,12 @@ else: EntityID[] entities = Mallocator.makeArray!EntityID(1_000_000); foreach (i; 0 .. 500_000) { - entity2 = gEM.addEntity(tmpl).id; + entity2 = gEntityManager.addEntity(tmpl).id; entities[i * 2] = entity2; - entities[i * 2 + 1] = gEM.addEntity(tmpl2).id; + entities[i * 2 + 1] = gEntityManager.addEntity(tmpl2).id; } - gEM.commit(); + gEntityManager.commit(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Entities adding2: ", dur, " usecs"); @@ -893,12 +893,12 @@ else: foreach (i; 0 .. 1_000_000) { - EntityManager.instance.addComponents(entities[i], TestComp5()); + gEntityManager.addComponents(entities[i], TestComp5()); if ((i & 0x00FFFF) == 0) - gEM.commit(); + gEntityManager.commit(); } - gEM.commit(); + gEntityManager.commit(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Components adding: ", dur, " usecs"); @@ -908,11 +908,11 @@ else: foreach (i; 0 .. 1_000_000) { - EntityManager.instance.removeComponents!TestComp5(entities[i]); - //if((i & 0x00FFFF) == 0)gEM.commit(); + gEntityManager.removeComponents!TestComp5(entities[i]); + //if((i & 0x00FFFF) == 0)gEntityManager.commit(); } - gEM.commit(); + gEntityManager.commit(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Components removing: ", dur, " usecs"); printf("Components removing: %f usecs\n", cast(float)(Time.getUSecTime() - time)); @@ -923,102 +923,102 @@ else: //time = MonoTime.currTime; time = Time.getUSecTime(); - gEM.begin(); - //gEM.updateMT(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + //gEntityManager.updateMT(); + gEntityManager.update(); + gEntityManager.end(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Update: ", dur, " usecs"); printf("Update: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - writeEntityComponents(gEM.getEntity(entity2)); + writeEntityComponents(gEntityManager.getEntity(entity2)); //time = MonoTime.currTime; time = Time.getUSecTime(); - gEM.begin(); - gEM.updateMT(); - //gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.updateMT(); + //gEntityManager.update(); + gEntityManager.end(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Update: ", dur, " usecs"); printf("Update: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - writeEntityComponents(gEM.getEntity(entity2)); + writeEntityComponents(gEntityManager.getEntity(entity2)); //time = MonoTime.currTime; time = Time.getUSecTime(); - gEM.begin(); - gEM.updateMT(); - //gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.updateMT(); + //gEntityManager.update(); + gEntityManager.end(); //dur = (MonoTime.currTime - time).total!"usecs"; //writeln("Update: ", dur, " usecs"); printf("Update: %f usecs\n", cast(float)(Time.getUSecTime() - time)); - writeEntityComponents(gEM.getEntity(entity2)); + writeEntityComponents(gEntityManager.getEntity(entity2)); - entity = gEM.addEntity(tmpl).id; + entity = gEntityManager.addEntity(tmpl).id; - gEM.begin(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.end(); - //Entity* pp;// = gEM.getEntity(entity.id); + //Entity* pp;// = gEntityManager.getEntity(entity.id); ////writeln((cast(uint*) pp)[0 .. 14], " ", pp); - writeEntityComponents(gEM.getEntity(entity)); + writeEntityComponents(gEntityManager.getEntity(entity)); //writeln("Entity, its copy, and template, and default filled tempalte"); - gEM.addEntity(tmpl); - writeEntityComponents(gEM.getEntity(entity)); - writeEntityComponents(gEM.addEntityCopy(entity)); - EntityTemplate* copy_tempalte = gEM.allocateTemplate(entity); - writeEntityComponents(gEM.addEntity(copy_tempalte)); - EntityTemplate* copy_default_tempalte = gEM.allocateTemplate(entity, true); - writeEntityComponents(gEM.addEntity(copy_default_tempalte)); + gEntityManager.addEntity(tmpl); + writeEntityComponents(gEntityManager.getEntity(entity)); + writeEntityComponents(gEntityManager.addEntityCopy(entity)); + EntityTemplate* copy_tempalte = gEntityManager.allocateTemplate(entity); + writeEntityComponents(gEntityManager.addEntity(copy_tempalte)); + EntityTemplate* copy_default_tempalte = gEntityManager.allocateTemplate(entity, true); + writeEntityComponents(gEntityManager.addEntity(copy_default_tempalte)); - gEM.addComponents(entity, TestComp4()); - gEM.addComponents(entity, TestComp3()); + gEntityManager.addComponents(entity, TestComp4()); + gEntityManager.addComponents(entity, TestComp3()); - gEM.begin(); - gEM.update(); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.end(); - writeEntityComponents(gEM.getEntity(entity)); + writeEntityComponents(gEntityManager.getEntity(entity)); - gEM.removeComponents!(TestComp)(entity); - gEM.addComponents(entity, TestComp()); - gEM.addComponents(entity, TestComp5()); + gEntityManager.removeComponents!(TestComp)(entity); + gEntityManager.addComponents(entity, TestComp()); + gEntityManager.addComponents(entity, TestComp5()); - gEM.begin(); - gEM.update(); - gEM.update("fixed"); - gEM.end(); + gEntityManager.begin(); + gEntityManager.update(); + gEntityManager.update("fixed"); + gEntityManager.end(); - gEM.removeComponents!(TestComp4)(entity); + gEntityManager.removeComponents!(TestComp4)(entity); - gEM.commit(); + gEntityManager.commit(); - System* sys = EntityManager.instance.getSystem(becsID!TestSystem2); + System* sys = gEntityManager.getSystem(becsID!TestSystem2); ExternalUpdateCallTest external_update_test; - EntityManager.instance.callEntitiesFunction!TestSystem2(&external_update_test.update); + gEntityManager.callEntitiesFunction!TestSystem2(&external_update_test.update); printf("pre end\n"); - writeEntityComponents(gEM.getEntity(entity)); + writeEntityComponents(gEntityManager.getEntity(entity)); //import std.stdio; ////writeln((cast(uint*)tmpl.info.first_block)[0..48]); - gEM.freeTemplate(tmpl_empty); - gEM.freeTemplate(tmpl); - gEM.freeTemplate(tmpl2); - gEM.freeTemplate(copy_tempalte); - gEM.freeTemplate(copy_default_tempalte); + gEntityManager.freeTemplate(tmpl_empty); + gEntityManager.freeTemplate(tmpl); + gEntityManager.freeTemplate(tmpl2); + gEntityManager.freeTemplate(copy_tempalte); + gEntityManager.freeTemplate(copy_default_tempalte); EntityManager.destroy(); Mallocator.dispose(idss);