-formatted all files with dfmt
-more messy tests -some documentation -some useful code moved to functions -adding components to existing entity -opportunity to get entity by ID -fixed calculating deltas -sorting IDs arrays for allocating Templates -fixed alignment caluclation -added compile-time checks for "component_id" member existing in component
This commit is contained in:
parent
d3222eefbb
commit
4b19907c03
4 changed files with 395 additions and 124 deletions
|
|
@ -7,19 +7,22 @@ struct IDManager
|
|||
{
|
||||
EntityID getNewID()
|
||||
{
|
||||
if(m_next_id >= m_ids_array.length)m_ids_array.add(Data());
|
||||
if (m_next_id >= m_ids_array.length)
|
||||
m_ids_array.add(Data());
|
||||
EntityID id;
|
||||
id.id = m_next_id;
|
||||
id.counter = ++m_ids_array[m_next_id].counter;
|
||||
m_next_id = m_ids_array[m_next_id].next_id;
|
||||
if(m_next_id == uint.max)m_next_id = cast(uint)m_ids_array.length;
|
||||
if (m_next_id == uint.max)
|
||||
m_next_id = cast(uint) m_ids_array.length;
|
||||
return id;
|
||||
}
|
||||
|
||||
void releaseID(EntityID id)
|
||||
{
|
||||
Data* data = &m_ids_array[id.id];
|
||||
if(data.counter != id.counter)return;
|
||||
if (data.counter != id.counter)
|
||||
return;
|
||||
data.next_id = m_next_id;
|
||||
data.entity = null;
|
||||
m_next_id = id.id;
|
||||
|
|
@ -33,8 +36,10 @@ struct IDManager
|
|||
Entity* getEntityPointer(EntityID id)
|
||||
{
|
||||
Data* data = &m_ids_array[id.id];
|
||||
if(data.counter != id.counter)return null;
|
||||
else return data.entity;
|
||||
if (data.counter != id.counter)
|
||||
return null;
|
||||
else
|
||||
return data.entity;
|
||||
}
|
||||
|
||||
bool isExist(EntityID id)
|
||||
|
|
@ -61,9 +66,9 @@ unittest
|
|||
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(0, 1));
|
||||
assert(id2 == EntityID(1, 1));
|
||||
assert(id3 == EntityID(2, 1));
|
||||
|
||||
manager.releaseID(id2);
|
||||
manager.releaseID(id1);
|
||||
|
|
@ -71,10 +76,10 @@ unittest
|
|||
id2 = manager.getNewID();
|
||||
id1 = manager.getNewID();
|
||||
|
||||
assert(id1 == EntityID(1,2));
|
||||
assert(id2 == EntityID(0,2));
|
||||
assert(id3 == EntityID(2,1));
|
||||
assert(id1 == EntityID(1, 2));
|
||||
assert(id2 == EntityID(0, 2));
|
||||
assert(id3 == EntityID(2, 1));
|
||||
assert(manager.isExist(id3));
|
||||
assert(!manager.isExist(EntityID(0,1)));
|
||||
assert(!manager.isExist(EntityID(0, 1)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue