-fixed crash on getComponent when component doesn't exist
-fixed Components ids sorting -added deferred object removing -new EntityManager functions: begin(), end().
This commit is contained in:
parent
a066a97f01
commit
8fdb56e840
3 changed files with 43 additions and 18 deletions
|
|
@ -1,22 +1,23 @@
|
|||
module ecs.manager;
|
||||
|
||||
import std.experimental.allocator.mallocator : Mallocator, AlignedMallocator;
|
||||
import std.experimental.allocator;
|
||||
import std.traits;
|
||||
import std.algorithm : max;
|
||||
import std.conv : to;
|
||||
import std.experimental.allocator;
|
||||
import std.experimental.allocator.mallocator : AlignedMallocator, Mallocator;
|
||||
import std.traits;
|
||||
|
||||
import core.stdc.string;
|
||||
import core.stdc.stdlib;
|
||||
import core.stdc.string;
|
||||
|
||||
import ecs.system;
|
||||
import ecs.entity;
|
||||
import ecs.vector;
|
||||
import ecs.entity_allocator;
|
||||
import ecs.hash_map;
|
||||
import ecs.id_manager;
|
||||
import ecs.entity_allocator;
|
||||
import ecs.system;
|
||||
import ecs.vector;
|
||||
|
||||
alias gEM = EntityManager.instance;
|
||||
alias SerializeVector = ecs.vector.Vector!ubyte;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
|
|
@ -410,7 +411,7 @@ class EntityManager
|
|||
{
|
||||
ushort min = new_ids[i];
|
||||
int pos = i;
|
||||
foreach(int j;0..new_ids.length)
|
||||
foreach(int j;i..new_ids.length)
|
||||
{
|
||||
if(new_ids[j] < min)
|
||||
{
|
||||
|
|
@ -562,6 +563,11 @@ class EntityManager
|
|||
}
|
||||
|
||||
void removeEntity(EntityID id)
|
||||
{
|
||||
entities_to_remove.add(id);
|
||||
}
|
||||
|
||||
void __removeEntity(EntityID id)
|
||||
{
|
||||
//get entity and block meta data pointers
|
||||
Entity* entity = id_manager.getEntityPointer(id);
|
||||
|
|
@ -571,7 +577,6 @@ class EntityManager
|
|||
id_manager.releaseID(id); //release id from manager
|
||||
|
||||
removeEntityNoID(entity, block, true);
|
||||
|
||||
}
|
||||
|
||||
private void removeEntityNoID(Entity* entity, EntitiesBlock* block,
|
||||
|
|
@ -624,6 +629,25 @@ class EntityManager
|
|||
return cast(EntitiesBlock*)(cast(size_t) pointer & (~cast(size_t)(page_size - 1)));
|
||||
}
|
||||
|
||||
void removeEntites()
|
||||
{
|
||||
foreach(id;entities_to_remove)
|
||||
{
|
||||
__removeEntity(id);
|
||||
}
|
||||
entities_to_remove.clear();
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void end()
|
||||
{
|
||||
removeEntites();
|
||||
}
|
||||
|
||||
struct ComponentInfo
|
||||
{
|
||||
ushort size;
|
||||
|
|
@ -710,6 +734,8 @@ class EntityManager
|
|||
IDManager id_manager;
|
||||
EntityAllocator allocator;
|
||||
|
||||
Vector!EntityID entities_to_remove;
|
||||
|
||||
HashMap!(ushort[], EntityInfo*) entities_infos;
|
||||
HashMap!(string, uint) components_map;
|
||||
Vector!System systems;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue