From 85e1f8a76e984ae1c4f7d2c72f6bb1bb7ca9c825 Mon Sep 17 00:00:00 2001 From: Mergul Date: Wed, 17 Nov 2021 15:03:25 +0100 Subject: [PATCH] Fixed bug with addComponents template -deprecated Comonent.ref_ function -remover Comonent.ref_ usage from addComponents template -updated dub.json --- .gitignore | 7 ++++--- source/bubel/ecs/core.d | 2 +- source/bubel/ecs/manager.d | 25 +------------------------ tests/basic.d | 30 ++++++++++++++++-------------- tests/bugs.d | 8 ++++++-- 5 files changed, 28 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index f2e30a3..e0e6fff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ * -!*/ !source/** !tests/** !README.md -!./dub.json +!dub.json !.gitignore !codecov.yml !skeleton.html @@ -11,4 +10,6 @@ !**/*.wrap !meson_options.txt !compile_wasm.py -!compile_android.py \ No newline at end of file +!compile_android.py +!.gitlab-ci.yml +!LICENSE \ No newline at end of file diff --git a/source/bubel/ecs/core.d b/source/bubel/ecs/core.d index 1a5e711..f8511ea 100644 --- a/source/bubel/ecs/core.d +++ b/source/bubel/ecs/core.d @@ -94,7 +94,7 @@ static struct ECS */ mixin template Component() { - ComponentRef ref_() @nogc nothrow return + deprecated ComponentRef ref_() @nogc nothrow return { return ComponentRef(&this, becsID!(typeof(this))); } diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index e3ad7bc..1ca7a86 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -2424,29 +2424,11 @@ export struct EntityManager void addComponents(Components...)(const EntityID entity_id, Components comps) nothrow @nogc { const uint num = Components.length; - /*ushort[num] new_ids; - - static foreach (i, comp; Components) - { - new_ids[i] = comp.component_id; - } - - ThreadData* data = &threads[threadID]; - data.changeEntitiesList.add(cast(ubyte) 1u); - data.changeEntitiesList.add((cast(ubyte*)&entity_id)[0 .. EntityID.sizeof]); - data.changeEntitiesList.add((cast(ubyte*)&num)[0 .. uint.sizeof]); - data.changeEntitiesList.add(cast(ubyte[]) new_ids); - static foreach (i, comp; comps) - { - data.changeEntitiesList.add((cast(ubyte*)&comp)[0 .. comp.sizeof]); - }*/ - - //__addComponents(entity_id, new_ids, pointers); ComponentRef[num] _comps; static foreach (i, comp; comps) { - _comps[i] = comp.ref_; + _comps[i] = ComponentRef(&comp, becsID!(typeof(comp))); } addComponents(entity_id, _comps); @@ -2469,11 +2451,6 @@ export struct EntityManager data.changeEntitiesList.add( (cast(ubyte*) ref_.ptr)[0 .. components[ref_.component_id].size]); } - /*data.changeEntitiesList.add(cast(ubyte[]) new_ids); - static foreach (i, comp; comps) - { - data.changeEntitiesList.add((cast(ubyte*)&comp)[0 .. comp.sizeof]); - }*/ } /************************************************************************************************************************ diff --git a/tests/basic.d b/tests/basic.d index aa730ea..084500a 100644 --- a/tests/basic.d +++ b/tests/basic.d @@ -16,7 +16,7 @@ else import std.array : staticArray; struct CInt { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -25,7 +25,7 @@ struct CInt struct CFloat { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -34,7 +34,7 @@ struct CFloat struct CDouble { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -43,7 +43,7 @@ struct CDouble struct CLong { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -52,7 +52,7 @@ struct CLong struct CShort { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -61,7 +61,7 @@ struct CShort struct CUnregistered { - mixin ECS.Component; + // mixin ECS.Component; alias value this; @@ -70,7 +70,7 @@ struct CUnregistered struct CFlag { - mixin ECS.Component; + // mixin ECS.Component; } struct LongAddSystem @@ -182,17 +182,18 @@ unittest assert(*entity2.getComponent!CInt == 2); assert(*entity2.getComponent!CFloat == 2.0); - //CInt cint = CInt(10); - //CLong clong; - //Entity* entity3 = gEntityManager.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray); - Entity* entity3 = gEntityManager.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray); + CInt int1 = CInt(10); + CLong long1 = CLong(); + CFlag flag1 = CFlag(); + Entity* entity3 = gEntityManager.addEntity(tmpl_, [ComponentRef(&int1, becsID(int1)), ComponentRef(&long1, becsID(long1)), ComponentRef(&flag1, becsID(flag1))].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); - gEntityManager.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); + CShort short1 = CShort(2); + gEntityManager.addComponents(entity3.id, [ComponentRef(&flag1, becsID(flag1)),ComponentRef(&short1, becsID(short1))].staticArray); gEntityManager.commit(); entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CInt); @@ -213,7 +214,7 @@ unittest assert(*entity3.getComponent!CInt == 10); assert(*entity3.getComponent!CFloat == 2.0); - gEntityManager.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray); + gEntityManager.addComponents(entity3.id, [ComponentRef(&flag1, becsID(flag1)),ComponentRef(&short1, becsID(short1))].staticArray); gEntityManager.removeComponents(entity3.id, [becsID!CUnregistered].staticArray); gEntityManager.commit(); entity3 = gEntityManager.getEntity(id); @@ -231,7 +232,8 @@ unittest gEntityManager.endRegister(); - gEntityManager.addComponents(entity3.id, [CUnregistered(4).ref_].staticArray); + CUnregistered unregistered1 = CUnregistered(4); + gEntityManager.addComponents(entity3.id, [ComponentRef(&unregistered1, becsID(unregistered1))].staticArray); gEntityManager.commit(); entity3 = gEntityManager.getEntity(id); assert(entity3.getComponent!CUnregistered); diff --git a/tests/bugs.d b/tests/bugs.d index 3c5f426..1a3968c 100644 --- a/tests/bugs.d +++ b/tests/bugs.d @@ -119,8 +119,12 @@ unittest gEntityManager.endRegister(); 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; + + CLong clong = CLong(10); + CInt cint = CInt(6); + CInt cint2 = CInt(4); + EntityID id = gEntityManager.addEntity(tmpl,[ComponentRef(&clong, becsID(clong)), ComponentRef(&cint, becsID(cint))].staticArray).id; + EntityID id2 = gEntityManager.addEntity(tmpl,[ComponentRef(&cint2, becsID(cint2))].staticArray).id; gEntityManager.freeTemplate(tmpl); gEntityManager.commit(); -- 2.47.2