ECS fixes
-fixed bug with addEntityCopy (on create was called for bad entity, and incorrect block was added to update) -added function to retrieve Component pointer from Entity (not template function) -fixed thread_pool bug
This commit is contained in:
parent
64dc099e0a
commit
8960423935
3 changed files with 31 additions and 9 deletions
|
|
@ -34,12 +34,23 @@ struct Entity
|
|||
*/
|
||||
T* getComponent(T)() const
|
||||
{
|
||||
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
/*EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
EntityManager.EntityInfo* info = block.type_info;
|
||||
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
|
||||
return null;
|
||||
|
||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);
|
||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);*/
|
||||
return cast(T*)getComponent(T.component_id);
|
||||
}
|
||||
|
||||
void* getComponent(ushort component_id) const
|
||||
{
|
||||
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||
EntityManager.EntityInfo* info = block.type_info;
|
||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)
|
||||
return null;
|
||||
|
||||
return (cast(void*)block + info.deltas[component_id] + block.entityIndex(&this) * gEM.components[component_id].size);
|
||||
}
|
||||
|
||||
bool hasComponent(ushort component_id) const
|
||||
|
|
@ -66,10 +77,21 @@ struct EntityMeta
|
|||
|
||||
T* getComponent(T)() const
|
||||
{
|
||||
const (EntityManager.EntityInfo)* info = block.type_info;
|
||||
/*const (EntityManager.EntityInfo)* info = block.type_info;
|
||||
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
|
||||
return null;
|
||||
return cast(T*)(cast(void*)block + block.type_info.deltas[T.component_id] + index * T.sizeof);
|
||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + index * T.sizeof);*/
|
||||
return cast(T*)getComponent(T.component_id);
|
||||
}
|
||||
|
||||
void* getComponent(ushort component_id) const
|
||||
{
|
||||
const (EntityManager.EntityInfo)* info = block.type_info;
|
||||
|
||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)
|
||||
return null;
|
||||
|
||||
return (cast(void*)block + info.deltas[component_id] + index * gEM.components[component_id].size);
|
||||
}
|
||||
|
||||
bool hasComponent(ushort component_id) const
|
||||
|
|
|
|||
|
|
@ -2513,17 +2513,17 @@ export struct EntityManager
|
|||
{
|
||||
ushort size = components[comp].size;
|
||||
if (size != 0)
|
||||
memcpy(cast(void*) new_block + info.deltas[comp] + size * new_id,
|
||||
memcpy(cast(void*) new_block + info.deltas[comp] + new_id * size,
|
||||
cast(void*) block + info.deltas[comp] + size * index, size);
|
||||
|
||||
if (components[comp].create_callback)
|
||||
{
|
||||
components[comp].create_callback(
|
||||
cast(void*) block + info.deltas[comp] + new_id * size);
|
||||
cast(void*) new_block + info.deltas[comp] + new_id * size);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_index == 1 && info.update_block == block)
|
||||
if (new_index == 1 && info.update_block == new_block)
|
||||
threads[threadID].infosToUpdate.add(info);
|
||||
|
||||
Entity* new_entity = cast(Entity*) start;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue