-fixed stack-overflow error
This commit is contained in:
parent
1396d0bf85
commit
9824b587fb
3 changed files with 38 additions and 15 deletions
3
dub.json
3
dub.json
|
|
@ -8,7 +8,8 @@
|
|||
"license": "BSD",
|
||||
"sourcePaths" : ["source\/"],
|
||||
"dflags-posix-ldc": [
|
||||
"-defaultlib=phobos2-ldc,druntime-ldc"
|
||||
"-defaultlib=phobos2-ldc,druntime-ldc",
|
||||
"-fsanitize=address"
|
||||
],
|
||||
"dflagss": [
|
||||
"-betterC"
|
||||
|
|
|
|||
|
|
@ -1331,8 +1331,8 @@ export class EntityManager
|
|||
ThreadData* data = &threads[thread_id];
|
||||
uint num = cast(uint) del_ids.length;
|
||||
data.change_entities_list.add(0);
|
||||
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. 8]);
|
||||
data.change_entities_list.add((cast(ubyte*)&num)[0 .. 4]);
|
||||
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. EntityID.sizeof]);
|
||||
data.change_entities_list.add((cast(ubyte*)&num)[0 .. uint.sizeof]);
|
||||
data.change_entities_list.add(cast(ubyte[]) del_ids);
|
||||
}
|
||||
|
||||
|
|
@ -1646,9 +1646,9 @@ export class EntityManager
|
|||
pointers[i] = ∁
|
||||
}*/
|
||||
ThreadData* data = &threads[thread_id];
|
||||
data.change_entities_list.add(1);
|
||||
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. 8]);
|
||||
data.change_entities_list.add((cast(ubyte*)&num)[0 .. 4]);
|
||||
data.change_entities_list.add(cast(ubyte)1u);
|
||||
data.change_entities_list.add((cast(ubyte*)&entity_id)[0 .. EntityID.sizeof]);
|
||||
data.change_entities_list.add((cast(ubyte*)&num)[0 .. uint.sizeof]);
|
||||
data.change_entities_list.add(cast(ubyte[]) new_ids);
|
||||
static foreach (i, comp; comps)
|
||||
{
|
||||
|
|
@ -1903,6 +1903,7 @@ export class EntityManager
|
|||
{
|
||||
uint index = 0;
|
||||
uint len = cast(uint) thread.change_entities_list.length;
|
||||
void*[32] pointers;// = (cast(void**) alloca(num * (void*).sizeof))[0 .. num];
|
||||
while (index < len)
|
||||
{
|
||||
if (!thread.change_entities_list[index++])
|
||||
|
|
@ -1911,8 +1912,8 @@ export class EntityManager
|
|||
index += EntityID.sizeof;
|
||||
uint num = *cast(uint*)&thread.change_entities_list[index];
|
||||
index += uint.sizeof;
|
||||
ushort[] ids = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num];
|
||||
ids[0 .. $] = (cast(ushort*)&thread.change_entities_list[index])[0 .. num];
|
||||
ushort[] ids;// = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num];
|
||||
ids = (cast(ushort*)&thread.change_entities_list[index])[0 .. num];
|
||||
index += ushort.sizeof * num;
|
||||
__removeComponents(id, ids);
|
||||
}
|
||||
|
|
@ -1922,16 +1923,16 @@ export class EntityManager
|
|||
index += EntityID.sizeof;
|
||||
uint num = *cast(uint*)&thread.change_entities_list[index];
|
||||
index += uint.sizeof;
|
||||
ushort[] ids = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num];
|
||||
ids[0 .. $] = (cast(ushort*)&thread.change_entities_list[index])[0 .. num];
|
||||
ushort[] ids;// = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num];
|
||||
ids = (cast(ushort*)&thread.change_entities_list[index])[0 .. num];
|
||||
index += ushort.sizeof * num;
|
||||
void*[] pointers = (cast(void**) alloca(num * (void*).sizeof))[0 .. num];
|
||||
//void*[] pointers = (cast(void**) alloca(num * (void*).sizeof))[0 .. num];
|
||||
foreach (i; 0 .. num)
|
||||
{
|
||||
pointers[i] = &thread.change_entities_list[index];
|
||||
index += components[ids[i]].size;
|
||||
}
|
||||
__addComponents(id, ids, pointers);
|
||||
__addComponents(id, ids, pointers[0..num]);
|
||||
}
|
||||
}
|
||||
thread.change_entities_list.clear();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
module tests.tests;
|
||||
|
||||
import std.experimental.allocator;
|
||||
import std.experimental.allocator.mallocator;
|
||||
|
||||
import ecs.entity;
|
||||
import ecs.events;
|
||||
import ecs.manager;
|
||||
|
|
@ -136,8 +139,10 @@ struct ChangeTestSystem
|
|||
|
||||
void onAddEntity(EntitiesData data)
|
||||
{
|
||||
//printf("Entity added! ID: ");
|
||||
foreach (i; 0 .. data.length)
|
||||
writeln("Entity added! ID: ", data.entites[i].id.id);
|
||||
printf("Entity added! ID: %u\n",data.entites[i].id.id);
|
||||
//writeln("Entity added! ID: ", data.entites[i].id.id);
|
||||
}
|
||||
|
||||
void onRemoveEntity(EntitiesData data)
|
||||
|
|
@ -532,7 +537,7 @@ int main()
|
|||
|
||||
//foreach(i; 0..1_000_000)gEM.removeEntity(gEM.addEntity(tmpl).id);
|
||||
|
||||
EntityID[5000] idss;
|
||||
EntityID[] idss = Mallocator.instance.makeArray!EntityID(5000);//[5000]
|
||||
|
||||
foreach (i; 0 .. 200)
|
||||
{
|
||||
|
|
@ -575,10 +580,12 @@ int main()
|
|||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
EntityID[] entities = Mallocator.instance.makeArray!EntityID(1_000_000);
|
||||
foreach (i; 0 .. 500_000)
|
||||
{
|
||||
entity2 = gEM.addEntity(tmpl);
|
||||
gEM.addEntity(tmpl2);
|
||||
entities[i*2] = entity2.id;
|
||||
entities[i*2+1] = gEM.addEntity(tmpl2).id;
|
||||
}
|
||||
|
||||
gEM.commit();
|
||||
|
|
@ -587,6 +594,20 @@ int main()
|
|||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
foreach (i; 0 .. 1_000_000)
|
||||
{
|
||||
EntityManager.instance.addComponents(entities[i],TestComp5());
|
||||
//if((i & 0x00FFFF) == 0)gEM.commit();
|
||||
}
|
||||
|
||||
gEM.commit();
|
||||
dur = (MonoTime.currTime - time).total!"usecs";
|
||||
writeln("Components adding: ", dur, " usecs");
|
||||
|
||||
Mallocator.instance.dispose(entities);
|
||||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
gEM.begin();
|
||||
//gEM.updateMT();
|
||||
gEM.update();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue