-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

@ -49,12 +49,23 @@ class EntityManager
instance = null;
}
/************************************************************************************************************************
*Default constructor.
*/
this()
{
//event_manager = EventManager(this);
//event_manager.manager = this;
}
/************************************************************************************************************************
*Register new System into EntityManager. This funcion generate glue between EntityManager and System.
*Systems can be registered from external dynamic library, and can be registered after adding entities too.
*System mustn't be registered before components which system want to use, in this case functions call assertion.
*
*params:
*priority = system priority. Priority determines order of execution of systems updates.
*/
void registerSystem(Sys)(int priority)
{
alias STC = ParameterStorageClass;
@ -392,6 +403,9 @@ class EntityManager
return cast(Sys*) systems[Sys.system_id].m_system_pointer;
}
/************************************************************************************************************************
*Register component into EntityManager.
*/
void registerComponent(Comp)()
{
ComponentInfo info;
@ -469,6 +483,9 @@ class EntityManager
}
}
/************************************************************************************************************************
*Update systems. Should be called only between begin() and end().
*/
export void update()
{
foreach (info; &entities_infos.byValue)
@ -486,10 +503,10 @@ class EntityManager
num = cast(ushort)((num + alignment - 1) & (-cast(int) alignment)); //num += alignment - (num & (alignment - 1));
}
static ushort alignedNum(ushort num, ushort alignment)
/*static ushort alignedNum(ushort num, ushort alignment)
{
return cast(ushort)((num + alignment - 1) & (-cast(int) alignment));
}
}*/
extern (C) static int compareUShorts(const void* a, const void* b)
{
@ -503,6 +520,12 @@ class EntityManager
return 1;
}
/************************************************************************************************************************
*Allocate EntityTemplate with specifed components and returns pointer to it.
*
*params:
*components_ids = array of components allocated with template
*/
export EntityTemplate* allocateTemplate(ushort[] components_ids)
{
@ -541,6 +564,12 @@ class EntityManager
return temp;
}
/************************************************************************************************************************
*Returns entity type info.
*
*params:
*ids = array of components
*/
export EntityInfo* getEntityInfo(ushort[] ids)
{
EntityInfo* info = entities_infos.get(ids, null);
@ -651,11 +680,24 @@ class EntityManager
entity.callers.add(call_data, index);
}
/************************************************************************************************************************
*Returns pointer to entity.
*
*params:
*id = ID of entity
*/
export Entity* getEntity(EntityID id)
{
return cast(Entity*) id_manager.getEntityPointer(id);
}
/************************************************************************************************************************
*Remove components from entity by IDs. Components will be removed on end of frame.
*
*params:
*entity_id = ID of entity
*del_ids = array of components IDs
*/
export void removeComponents(EntityID entity_id, ushort[] del_ids)
{
uint num = cast(uint) del_ids.length;
@ -725,6 +767,13 @@ class EntityManager
removeEntityNoID(entity, block);
}
/************************************************************************************************************************
*Remove coponents from entity.
*
*params:
*Compoenents = components types to remove
*entity_id = ID of entity
*/
void removeComponents(Components...)(EntityID entity_id)
{
const uint num = Components.length;
@ -861,6 +910,13 @@ class EntityManager
removeEntityNoID(entity, block);
}
/************************************************************************************************************************
*Add components to entity. Components will be added on end of frame.
*
*params:
*entity_id = ID of entity to remove
*tmpl = pointer entity template allocated by EntityManager.
*/
void addComponents(Components...)(const EntityID entity_id, Components comps)
{
const uint num = Components.length;
@ -895,12 +951,24 @@ class EntityManager
//__addComponents(entity_id, new_ids, pointers);
}
/************************************************************************************************************************
*Free template memory.
*
*params:
*tmpl = pointer entity template allocated by EntityManager.
*/
export void freeTemplate(EntityTemplate* template_)
{
Mallocator.instance.dispose(template_.entity_data);
Mallocator.instance.dispose(template_);
}
/************************************************************************************************************************
*Add entity to system.
*
*params:
*tmpl = pointer entity template allocated by EntityManager.
*/
export ref Entity addEntity(EntityTemplate* tmpl)
{
EntitiesBlock* block = findBlockWithFreeSpace(tmpl.info);
@ -969,6 +1037,12 @@ class EntityManager
return block;
}
/************************************************************************************************************************
*Remove entity by ID. Entity will be removed on frame end.
*
*params:
*id = id of entity to remove
*/
export void removeEntity(EntityID id)
{
entities_to_remove.add(id);
@ -1125,6 +1199,9 @@ class EntityManager
entities_to_remove.clear();
}
/************************************************************************************************************************
*Begin of update process. Should be called before any update is called.
*/
export void begin()
{
updateBlocks();
@ -1137,6 +1214,9 @@ class EntityManager
}
}
/************************************************************************************************************************
*End of update process. Should be called after every update function.
*/
export void end()
{
foreach (ref system; instance.systems)
@ -1151,11 +1231,18 @@ class EntityManager
//clearEvents();
}
/************************************************************************************************************************
*Component info;
*/
struct ComponentInfo
{
///Component size
ushort size;
///Component data alignment
ushort alignment;
///Initialization data
ubyte[] init_data;
///Pointer to component destroy callback
void function(void* pointer) destroy_callback;
}