Fixed bug with addComponents template
-deprecated Comonent.ref_ function -remover Comonent.ref_ usage from addComponents template -updated dub.json
This commit is contained in:
parent
54b210346d
commit
85e1f8a76e
5 changed files with 28 additions and 44 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -1,9 +1,8 @@
|
||||||
*
|
*
|
||||||
!*/
|
|
||||||
!source/**
|
!source/**
|
||||||
!tests/**
|
!tests/**
|
||||||
!README.md
|
!README.md
|
||||||
!./dub.json
|
!dub.json
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!codecov.yml
|
!codecov.yml
|
||||||
!skeleton.html
|
!skeleton.html
|
||||||
|
|
@ -11,4 +10,6 @@
|
||||||
!**/*.wrap
|
!**/*.wrap
|
||||||
!meson_options.txt
|
!meson_options.txt
|
||||||
!compile_wasm.py
|
!compile_wasm.py
|
||||||
!compile_android.py
|
!compile_android.py
|
||||||
|
!.gitlab-ci.yml
|
||||||
|
!LICENSE
|
||||||
|
|
@ -94,7 +94,7 @@ static struct ECS
|
||||||
*/
|
*/
|
||||||
mixin template Component()
|
mixin template Component()
|
||||||
{
|
{
|
||||||
ComponentRef ref_() @nogc nothrow return
|
deprecated ComponentRef ref_() @nogc nothrow return
|
||||||
{
|
{
|
||||||
return ComponentRef(&this, becsID!(typeof(this)));
|
return ComponentRef(&this, becsID!(typeof(this)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2424,29 +2424,11 @@ export struct EntityManager
|
||||||
void addComponents(Components...)(const EntityID entity_id, Components comps) nothrow @nogc
|
void addComponents(Components...)(const EntityID entity_id, Components comps) nothrow @nogc
|
||||||
{
|
{
|
||||||
const uint num = Components.length;
|
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;
|
ComponentRef[num] _comps;
|
||||||
static foreach (i, comp; comps)
|
static foreach (i, comp; comps)
|
||||||
{
|
{
|
||||||
_comps[i] = comp.ref_;
|
_comps[i] = ComponentRef(&comp, becsID!(typeof(comp)));
|
||||||
}
|
}
|
||||||
addComponents(entity_id, _comps);
|
addComponents(entity_id, _comps);
|
||||||
|
|
||||||
|
|
@ -2469,11 +2451,6 @@ export struct EntityManager
|
||||||
data.changeEntitiesList.add(
|
data.changeEntitiesList.add(
|
||||||
(cast(ubyte*) ref_.ptr)[0 .. components[ref_.component_id].size]);
|
(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]);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ else import std.array : staticArray;
|
||||||
|
|
||||||
struct CInt
|
struct CInt
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ struct CInt
|
||||||
|
|
||||||
struct CFloat
|
struct CFloat
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ struct CFloat
|
||||||
|
|
||||||
struct CDouble
|
struct CDouble
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct CDouble
|
||||||
|
|
||||||
struct CLong
|
struct CLong
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ struct CLong
|
||||||
|
|
||||||
struct CShort
|
struct CShort
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ struct CShort
|
||||||
|
|
||||||
struct CUnregistered
|
struct CUnregistered
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ struct CUnregistered
|
||||||
|
|
||||||
struct CFlag
|
struct CFlag
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LongAddSystem
|
struct LongAddSystem
|
||||||
|
|
@ -182,17 +182,18 @@ unittest
|
||||||
assert(*entity2.getComponent!CInt == 2);
|
assert(*entity2.getComponent!CInt == 2);
|
||||||
assert(*entity2.getComponent!CFloat == 2.0);
|
assert(*entity2.getComponent!CFloat == 2.0);
|
||||||
|
|
||||||
//CInt cint = CInt(10);
|
CInt int1 = CInt(10);
|
||||||
//CLong clong;
|
CLong long1 = CLong();
|
||||||
//Entity* entity3 = gEntityManager.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray);
|
CFlag flag1 = CFlag();
|
||||||
Entity* entity3 = gEntityManager.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray);
|
Entity* entity3 = gEntityManager.addEntity(tmpl_, [ComponentRef(&int1, becsID(int1)), ComponentRef(&long1, becsID(long1)), ComponentRef(&flag1, becsID(flag1))].staticArray);
|
||||||
EntityID id = entity3.id;
|
EntityID id = entity3.id;
|
||||||
assert(entity3.hasComponent(becsID!CInt));
|
assert(entity3.hasComponent(becsID!CInt));
|
||||||
assert(entity3.hasComponent(becsID!CFloat));
|
assert(entity3.hasComponent(becsID!CFloat));
|
||||||
assert(*entity3.getComponent!CInt == 10);
|
assert(*entity3.getComponent!CInt == 10);
|
||||||
assert(*entity3.getComponent!CFloat == 2.0);
|
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();
|
gEntityManager.commit();
|
||||||
entity3 = gEntityManager.getEntity(id);
|
entity3 = gEntityManager.getEntity(id);
|
||||||
assert(entity3.getComponent!CInt);
|
assert(entity3.getComponent!CInt);
|
||||||
|
|
@ -213,7 +214,7 @@ unittest
|
||||||
assert(*entity3.getComponent!CInt == 10);
|
assert(*entity3.getComponent!CInt == 10);
|
||||||
assert(*entity3.getComponent!CFloat == 2.0);
|
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.removeComponents(entity3.id, [becsID!CUnregistered].staticArray);
|
||||||
gEntityManager.commit();
|
gEntityManager.commit();
|
||||||
entity3 = gEntityManager.getEntity(id);
|
entity3 = gEntityManager.getEntity(id);
|
||||||
|
|
@ -231,7 +232,8 @@ unittest
|
||||||
|
|
||||||
gEntityManager.endRegister();
|
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();
|
gEntityManager.commit();
|
||||||
entity3 = gEntityManager.getEntity(id);
|
entity3 = gEntityManager.getEntity(id);
|
||||||
assert(entity3.getComponent!CUnregistered);
|
assert(entity3.getComponent!CUnregistered);
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,12 @@ unittest
|
||||||
gEntityManager.endRegister();
|
gEntityManager.endRegister();
|
||||||
|
|
||||||
EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray);
|
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.freeTemplate(tmpl);
|
||||||
gEntityManager.commit();
|
gEntityManager.commit();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue