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

5
.gitignore vendored
View file

@ -1,9 +1,8 @@
*
!*/
!source/**
!tests/**
!README.md
!./dub.json
!dub.json
!.gitignore
!codecov.yml
!skeleton.html
@ -12,3 +11,5 @@
!meson_options.txt
!compile_wasm.py
!compile_android.py
!.gitlab-ci.yml
!LICENSE

View file

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

View file

@ -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]);
}*/
}
/************************************************************************************************************************

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