-documentation

This commit is contained in:
Mergul 2018-10-01 19:40:24 +02:00
parent 288ad4c6cd
commit 437c672478
5 changed files with 154 additions and 4 deletions

View file

@ -3,8 +3,14 @@ module ecs.id_manager;
import ecs.entity;
import ecs.vector;
/************************************************************************************************************************
*IDManager is responsible for assignment and removing IDs. IDs are unique throughtout a whole duration of the program.
*/
struct IDManager
{
/************************************************************************************************************************
*Get new ID.
*/
EntityID getNewID()
{
if (m_next_id >= m_ids_array.length)
@ -18,6 +24,9 @@ struct IDManager
return id;
}
/************************************************************************************************************************
*Release ID.
*/
void releaseID(EntityID id)
{
Data* data = &m_ids_array[id.id];
@ -29,11 +38,17 @@ struct IDManager
m_next_id = id.id;
}
/************************************************************************************************************************
*Update pointer to entity. The purpose of this function is to ensure that pointer to entity is always correct.
*/
void update(ref Entity entity)
{
if(entity.id.counter == m_ids_array[entity.id.id].counter)m_ids_array[entity.id.id].entity = &entity;
}
/************************************************************************************************************************
*Returns pointer to entity.
*/
export Entity* getEntityPointer(EntityID id)
{
Data* data = &m_ids_array[id.id];
@ -43,20 +58,24 @@ struct IDManager
return data.entity;
}
/************************************************************************************************************************
*Check if entity with specified ID exist.
*/
export bool isExist(EntityID id)
{
Data* data = &m_ids_array[id.id];
return data.counter == id.counter;
}
struct Data
private static struct Data
{
uint counter = 0;
uint next_id = uint.max;
Entity* entity = null;
}
private uint m_next_id = 0;
private:
uint m_next_id;
Vector!Data m_ids_array;
}