Fixed bug with addComponents template

-deprecated Comonent.ref_ function
-remover Comonent.ref_ usage from addComponents template
-updated dub.json
This commit is contained in:
Mergul 2021-11-17 15:03:25 +01:00
parent 54b210346d
commit 85e1f8a76e
5 changed files with 28 additions and 44 deletions

View file

@ -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);

View file

@ -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();