FIxed GDC compilation (basic betterC WIP) and some improvements

-fixed issue with adding/removing entities inside events handling
-fixed EntityMeta.getComponent() (added check if component_id is valid)
-added function hasComponent to entity to check if component exists
This commit is contained in:
Mergul 2020-05-14 22:18:57 +02:00
parent f731b4cedb
commit 9589a5cb2d
11 changed files with 174 additions and 94 deletions

View file

@ -55,7 +55,8 @@ public:
/*foreach (ref el; array[0 .. used]) {
destroy(el);
}*/
freeData(cast(void[]) array);
//freeData(cast(void[]) array);
freeData((cast(void*)array.ptr)[0 .. array.length * T.sizeof]);
gVectorsDestroyed++;
}
array = null;
@ -78,7 +79,9 @@ public:
}
} else {
foreach (ref el; array[newLength .. used]) {
destroy(el);
//destroy(el);
static if(__traits(hasMember, T, "__xdtor"))el.__xdtor();
else static if(__traits(hasMember, T, "__dtor"))el.__dtor();
}
}
used = newLength;
@ -122,7 +125,8 @@ public:
T* memory = cast(T*) malloc(newSize);
memcpy(cast(void*) memory, cast(void*) oldArray.ptr, oldSize);
array = memory[0 .. newNumOfElements];
return cast(void[]) oldArray;
//return cast(void[]) oldArray;
return (cast(void*)oldArray.ptr)[0 .. oldArray.length * T.sizeof];
}
export Vector!T copy()() {
@ -169,7 +173,9 @@ public:
}
export void remove(size_t elemNum) {
destroy(array[elemNum]);
//destroy(array[elemNum]);
static if(__traits(hasMember, T, "__xdtor"))array[elemNum].__xdtor();
else static if(__traits(hasMember, T, "__dtor"))array[elemNum].__dtor();
//swap(array[elemNum], array[used - 1]);
array[elemNum] = array[used - 1];
used--;