-IDManager reserve EntityID(0) as empty
-fixed bug with events called on destroyed entities (crash) -don't call event on system for unsupported entity -added "entity_id" property to EntitiesData
This commit is contained in:
parent
87e9a31d7f
commit
5399b584dd
3 changed files with 44 additions and 10 deletions
|
|
@ -136,7 +136,9 @@ begin:
|
|||
*/
|
||||
export bool isExist(EntityID id) nothrow @nogc
|
||||
{
|
||||
if(id.id >= m_ids_array.length)return false;
|
||||
Data* data = &m_ids_array[id.id];
|
||||
if(data.entity is null)return false;
|
||||
return data.counter == id.counter;
|
||||
}
|
||||
|
||||
|
|
@ -151,6 +153,9 @@ begin:
|
|||
|
||||
add_mutex = Mallocator.make!Mutex();
|
||||
add_mutex.initialize();
|
||||
|
||||
getNewID();
|
||||
optimize();
|
||||
}
|
||||
|
||||
void deinitialize() @trusted @nogc nothrow
|
||||
|
|
@ -243,23 +248,31 @@ private:
|
|||
unittest
|
||||
{
|
||||
IDManager manager;
|
||||
manager.initialize();
|
||||
EntityID id1 = manager.getNewID();
|
||||
EntityID id2 = manager.getNewID();
|
||||
EntityID id3 = manager.getNewID();
|
||||
|
||||
assert(id1 == EntityID(0, 1));
|
||||
assert(id2 == EntityID(1, 1));
|
||||
assert(id3 == EntityID(2, 1));
|
||||
assert(id1 == EntityID(1, 0));
|
||||
assert(id2 == EntityID(2, 0));
|
||||
assert(id3 == EntityID(3, 0));
|
||||
|
||||
manager.optimize();
|
||||
manager.releaseID(id2);
|
||||
manager.releaseID(id1);
|
||||
|
||||
id2 = manager.getNewID();
|
||||
id1 = manager.getNewID();
|
||||
|
||||
assert(id1 == EntityID(1, 2));
|
||||
assert(id2 == EntityID(0, 2));
|
||||
assert(id3 == EntityID(2, 1));
|
||||
Entity e;
|
||||
e.id = id3;
|
||||
manager.update(e);
|
||||
|
||||
assert(id1 == EntityID(2, 1));
|
||||
assert(id2 == EntityID(1, 1));
|
||||
assert(id3 == EntityID(3, 0));
|
||||
assert(manager.isExist(id3));
|
||||
assert(!manager.isExist(EntityID(0, 1)));
|
||||
assert(!manager.isExist(EntityID(1, 0)));
|
||||
assert(!manager.isExist(EntityID(0, 0)));
|
||||
manager.deinitialize();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue