diff --git a/demos/external/sources/mmutils/thread_pool.d b/demos/external/sources/mmutils/thread_pool.d index b830026..bd05fe5 100644 --- a/demos/external/sources/mmutils/thread_pool.d +++ b/demos/external/sources/mmutils/thread_pool.d @@ -396,8 +396,8 @@ version (MM_USE_POSIX_THREADS) void start(DG dg) { threadStart = dg; - int ok = pthread_create(&handle, null, &threadRunFunc, cast(void*)&this); - if(!ok)handle = pthread_t(); + int err = pthread_create(&handle, null, &threadRunFunc, cast(void*)&this); + if(err)handle = pthread_t(); //assert(ok == 0); } diff --git a/source/bubel/ecs/entity.d b/source/bubel/ecs/entity.d index 4cd0e70..f713c78 100644 --- a/source/bubel/ecs/entity.d +++ b/source/bubel/ecs/entity.d @@ -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 diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index c26a414..8ef4a20 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -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;