ECS core imprevement
-Adedd function to resize array to Mallocator -significant speed up for first time ID allocation by using resizeArray instead of makeArray -fix: onUpdate called with zero length arrays -call updateBlocks before updateEvents (it's more accurate behaviour) -some minore fixes -fixed meson.build for GDC
This commit is contained in:
parent
66860b9042
commit
13e6ed8fd5
4 changed files with 83 additions and 36 deletions
|
|
@ -152,6 +152,50 @@ else
|
|||
|
||||
static struct Mallocator
|
||||
{
|
||||
static T[] resizeArray(T)(T[] array, size_t length) nothrow @nogc
|
||||
{
|
||||
T[] ret;
|
||||
|
||||
if(length > array.length)
|
||||
{
|
||||
ret = (cast(T*) realloc(array.ptr, T.sizeof * length))[0 .. length];
|
||||
static if (__traits(isPOD, T))
|
||||
{
|
||||
__gshared immutable T init = T.init;
|
||||
|
||||
foreach (i; array.length .. ret.length)
|
||||
{
|
||||
memcpy(&ret[i], &init, T.sizeof);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static import std.conv;
|
||||
|
||||
foreach (i; array.length .. ret.length)
|
||||
{
|
||||
std.conv.emplace(&ret[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static if (__traits(hasMember, T, "__xdtor"))
|
||||
foreach (i; length .. array.length)
|
||||
{
|
||||
array[i].__xdtor();
|
||||
}
|
||||
else static if (__traits(hasMember, T, "__dtor"))
|
||||
foreach (i; length .. array.length)
|
||||
{
|
||||
array[i].__dtor();
|
||||
}
|
||||
ret = (cast(T*) realloc(array.ptr, T.sizeof * length))[0 .. length];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static T[] makeArray(T)(size_t length) nothrow @nogc
|
||||
{
|
||||
T[] ret = (cast(T*) malloc(T.sizeof * length))[0 .. length];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue