-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
43
README.md
43
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();
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
660
tests/basic.d
660
tests/basic.d
File diff suppressed because it is too large
Load diff
70
tests/bugs.d
70
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();
|
||||
}
|
||||
60
tests/perf.d
60
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);
|
||||
}
|
||||
280
tests/tests.d
280
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue