-LinearLayout proggress:
*EntityTemplate.getComponent *Adding/removing components for Entitites -better code for adding components
This commit is contained in:
parent
cb9bac5dde
commit
c18ac54265
4 changed files with 95 additions and 40 deletions
|
|
@ -156,7 +156,9 @@ class EntityManager
|
|||
}
|
||||
else
|
||||
{
|
||||
ret ~= "types[" ~ i.to!string ~ "][] array" ~ req.to!string ~ " = (cast(types[" ~ i.to!string ~ "]*)(cast(void*)block + info.deltas[types[" ~ i.to!string ~ "].component_id]))[0..block.entities_count];";
|
||||
ret ~= "types[" ~ i.to!string ~ "][] array" ~ req.to!string ~ " = (cast(types["
|
||||
~ i.to!string ~ "]*)(cast(void*)block + info.deltas[types["
|
||||
~ i.to!string ~ "].component_id]))[0..block.entities_count];";
|
||||
req++;
|
||||
}
|
||||
}
|
||||
|
|
@ -235,7 +237,8 @@ class EntityManager
|
|||
pointer = null;
|
||||
}*/
|
||||
EntityInfo* info = block.type_info;
|
||||
Entity[] id_array = (cast(Entity*)block.dataBegin())[0..block.entities_count];
|
||||
Entity[] id_array = (cast(Entity*) block.dataBegin())[0
|
||||
.. block.entities_count];
|
||||
mixin(genArrays());
|
||||
foreach (i; 0 .. block.entities_count)
|
||||
{
|
||||
|
|
@ -710,10 +713,26 @@ class EntityManager
|
|||
new_entity.id = entity.id;
|
||||
new_entity.updateID();
|
||||
|
||||
foreach (comp; new_info.components)
|
||||
version (LinearLayout)
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[comp],
|
||||
cast(void*) entity + info.deltas[comp], components[comp].size);
|
||||
static if (EntityID.sizeof == 8)
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) >> 3);
|
||||
else
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) / EntityID.sizeof());
|
||||
foreach (comp; new_info.components)
|
||||
{
|
||||
uint comp_size = components[comp].size;
|
||||
memcpy(cast(void*) new_block + new_info.deltas[comp] + new_block.entities_count * comp_size,
|
||||
cast(void*) block + info.deltas[comp] + ind * comp_size, comp_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (comp; new_info.components)
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[comp],
|
||||
cast(void*) entity + info.deltas[comp], components[comp].size);
|
||||
}
|
||||
}
|
||||
|
||||
new_block.entities_count++;
|
||||
|
|
@ -817,42 +836,74 @@ class EntityManager
|
|||
Entity* new_entity = cast(Entity*) start;
|
||||
new_entity.id = entity.id;
|
||||
new_entity.updateID();
|
||||
new_block.entities_count++;
|
||||
|
||||
//removeEntityNoID(entity, block);
|
||||
|
||||
j = 0;
|
||||
k = 0;
|
||||
foreach (ref id; ids)
|
||||
version (LinearLayout)
|
||||
{
|
||||
if (k >= new_ids.length)
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[id],
|
||||
cast(void*) entity + info.deltas[info.components[j]],
|
||||
components[info.components[j]].size); //id = info.components[j++];
|
||||
j++;
|
||||
}
|
||||
else if (j >= info.components.length)
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[id],
|
||||
data_pointers[k], components[new_ids[k]].size); //id = new_ids[k++];
|
||||
k++;
|
||||
}
|
||||
else if (id == new_ids[k])
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[id],
|
||||
data_pointers[k], components[new_ids[k]].size); //id = new_ids[k++];
|
||||
k++;
|
||||
}
|
||||
static if (EntityID.sizeof == 8)
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) >> 3);
|
||||
else
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) / EntityID.sizeof());
|
||||
foreach (ref id; ids)
|
||||
{
|
||||
memcpy(cast(void*) new_entity + new_info.deltas[id],
|
||||
cast(void*) entity + info.deltas[info.components[j]],
|
||||
components[info.components[j]].size); //id = info.components[j++];
|
||||
j++;
|
||||
void* dst = cast(void*) new_block + new_info.deltas[id] + (
|
||||
new_block.entities_count + new_block.added_count) * components[id].size;
|
||||
uint size = components[id].size;
|
||||
if (k >= new_ids.length)
|
||||
{
|
||||
memcpy(dst, cast(void*) block + info.deltas[id] + ind * size, size);
|
||||
j++;
|
||||
}
|
||||
else if (j >= info.components.length)
|
||||
{
|
||||
memcpy(dst, data_pointers[k], size);
|
||||
k++;
|
||||
}
|
||||
else if (id == new_ids[k])
|
||||
{
|
||||
memcpy(dst, data_pointers[k], size);
|
||||
k++;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(dst, cast(void*) block + info.deltas[id] + ind * size, size);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (ref id; ids)
|
||||
{
|
||||
void* dst = cast(void*) new_entity + new_info.deltas[id];
|
||||
uint size = components[id].size;
|
||||
if (k >= new_ids.length)
|
||||
{
|
||||
memcpy(dst, cast(void*) entity + info.deltas[id], size);
|
||||
j++;
|
||||
}
|
||||
else if (j >= info.components.length)
|
||||
{
|
||||
memcpy(dst, data_pointers[k], size);
|
||||
k++;
|
||||
}
|
||||
else if (id == new_ids[k])
|
||||
{
|
||||
memcpy(dst, data_pointers[k], size);
|
||||
k++;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(dst, cast(void*) entity + info.deltas[id], size);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_block.entities_count++;
|
||||
removeEntityNoID(entity, block);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue