EntityManager

Entity manager is responsible for everything.

Entity manager can be in three states: - registration: time between beginRegister() and endRegister() calls. - update: time between being() and end() calls. - default: when it's not in registration or update time

Manager can be only in one state simultaneously.

Manager must be initialized before use. There is global instance of EntityManager: gEntityManager or gEntityManager as alias.

Registration process consist of registration of passes, systems, entities and events.

Pass is group of system which should be used inside one update() call. Passes are added as name (string) and can be referenced by name or id. System is structure responsible for update of specified group of entities. System consist of EntitiesData structure which contain components used by system and some callback. Main callback is onUpdate() which is called by update() entity manager function. Other callbacks are used as listeners for adding entites, tracking system lifetime and events handling.

Component is basicly small fraction of data which is considered to be used as whole. In best scenario every byte of component is used when it's refered to. In practice sometimes it's better to join data into one component even if it's can be accessed separetly. Events are structures with data used to handle events. Event can contain for exmaple one floating point number used as damage dealt to entity. Entity is group of components. In memory entity is only ID which makes it's possible to take it's components. Components are grouped into chunks, and grouped by component type so entity can be fracted in big memory chunk.

There is two types of update: - update(): function used to call update pass. - updateMT(): function used to call update pass multithreaded. This call only generates jobs which must be called by user.

WARNING! No fileds from EntityManager should be used directly, they are not private for special, advanced things which are not implemented in library. So if you don't need anything special, simply use only EntityManager methods.

export export
struct EntityManager {}

Constructors

this
this(uint threads_count, uint page_size, uint block_pages_count)

Default constructor.

Destructor

~this
~this()
Undocumented in source.

Members

Aliases

SytemFuncType
alias SytemFuncType = void function(ref EntityManager.CallData data) nothrow @(nogc)
Undocumented in source.

Functions

addComponents
void addComponents(EntityID entity_id, Components comps)

Add components to entity. Components will be added on end of frame.

addComponents
void addComponents(EntityID entity_id, ComponentRef[] comps)
Undocumented in source. Be warned that the author may not have intended to support it.
addEntity
Entity* addEntity(EntityTemplate* tmpl)

Add entity to system. Returen pointer is valid only before one from commit(), begin() or end() will be called. To save entity to further use you should save ID instead of pointer.

addEntity
Entity* addEntity(EntityTemplate* tmpl, ComponentRef[] replacement)

Add entity to system. Returen pointer is valid only before one from commit(), begin() or end() will be called. To save entity to further use you should save ID instead of pointer.

addEntityCopy
Entity* addEntityCopy(EntityID id)

Add copy of entity to system and returns pointer to it. Added copy has same data as copied entity. Returen pointer is valid only before one from commit(), begin() or end() will be called. To save entity to further use you should save ID instead of pointer.

addSystemCaller
void addSystemCaller(uint system_id)
Undocumented in source. Be warned that the author may not have intended to support it.
addSystemCaller
void addSystemCaller(EntityInfo info, uint system_id)
Undocumented in source. Be warned that the author may not have intended to support it.
allocateTemplate
EntityTemplate* allocateTemplate(EntityID entity_id, bool fill_default)

Allocate EntityTemplate with all components from entity witch it's data and returns pointer to it.

allocateTemplate
EntityTemplate* allocateTemplate(ushort[] components_ids)

Allocate EntityTemplate with specifed components and returns pointer to it.

allocateTemplate
EntityTemplate* allocateTemplate(EntityTemplate* base_tmpl, ushort[] components_ids, ushort[] remove_components_ids)

Allocate EntityTemplate from basic Template with modifications by adding and removing some components and returns pointer to it. Arrays of components needen't to be checked for repeated components, as function itself check if components exist in base template.

allocateTemplate
EntityTemplate* allocateTemplate(EntityTemplate* copy_tmpl)

Allocate EntityTemplate copy.

begin
void begin()

Begin of update process. Should be called before any update is called.

beginRegister
void beginRegister()

Begin registering process. Every register function should be called between beginRegister() and endRegister().

callEntitiesFunction
void callEntitiesFunction(T func)
Undocumented in source. Be warned that the author may not have intended to support it.
commit
void commit()
Undocumented in source. Be warned that the author may not have intended to support it.
connectListenerToEntityInfo
void connectListenerToEntityInfo(EntityInfo entity, uint system_id)
Undocumented in source. Be warned that the author may not have intended to support it.
end
void end()

End of update process. Should be called after every update function.

endRegister
void endRegister()

End registering process. Every register function should be called between beginRegister() and endRegister().

freeTemplate
void freeTemplate(EntityTemplate* template_)

Free template memory.

getEntity
Entity* getEntity(EntityID id)

Returns pointer to entity.

getEntityInfo
EntityInfo* getEntityInfo(ushort[] ids)

Returns entity type info.

getMetaData
EntitiesBlock* getMetaData(void* pointer)

functions return MetaData of page.

getPass
const(UpdatePass)* getPass(const(char)[] name)
Undocumented in source. Be warned that the author may not have intended to support it.
getPassID
ushort getPassID(const(char)[] name)
Undocumented in source. Be warned that the author may not have intended to support it.
getSystem
System* getSystem(ushort id)

Return system ECS api by id

getSystem
Sys* getSystem()

Return pointer to system registered in manager

pageSize
uint pageSize()

Return size of single page (block). Every entity data block has size of page.

pagesInBlock
uint pagesInBlock()

Return number of pages in single block allocation. Library allocate defined number of pages at once and assign it's for entities.

registerComponent
void registerComponent()

Register component into EntityManager.

registerDependency
void registerDependency(const(char)[] name)
Undocumented in source. Be warned that the author may not have intended to support it.
registerEvent
void registerEvent()
Undocumented in source. Be warned that the author may not have intended to support it.
registerPass
ushort registerPass(const(char)[] name)
Undocumented in source. Be warned that the author may not have intended to support it.
registerSystem
void registerSystem(int priority, const(char)[] pass_name)

Same as "void registerSystem(Sys)(int priority, int pass = 0)" but use pass name instead of id.

registerSystem
void registerSystem(int priority, ushort pass)

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.

removeComponents
void removeComponents(EntityID entity_id, ushort[] del_ids)

Remove components from entity by IDs. Components will be removed on end of frame.

removeComponents
void removeComponents(EntityID entity_id)

Remove coponents from entity.

removeEntity
void removeEntity(EntityID id)

Remove entity by ID. Entity will be removed on frame end.

sendEvent
void sendEvent(EntityID id, Ev event)
Undocumented in source. Be warned that the author may not have intended to support it.
setMultithreadingCallbacks
void setMultithreadingCallbacks(void delegate(JobGroup) dispatch_callback, uint delegate() get_id_callback)
Undocumented in source. Be warned that the author may not have intended to support it.
threadID
uint threadID()
Undocumented in source. Be warned that the author may not have intended to support it.
unregisterSystem
void unregisterSystem()

Unregister given system form EntityManager.

update
void update(const(char)[] pass_name)

Same as "void update(int pass = 0)" but use pass name instead of id.

update
void update(ushort pass)

Update systems. Should be called only between begin() and end().

updateMT
void updateMT(const(char)[] pass_name)

Same as "void updateMT(int pass = 0)" but use pass name instead of id.

updateMT
void updateMT(ushort pass)
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

alignNum
void alignNum(ushort num, ushort alignment)
Undocumented in source. Be warned that the author may not have intended to support it.
compareUShorts
int compareUShorts(void* a, void* b)
Undocumented in source. Be warned that the author may not have intended to support it.
destroy
void destroy()

Deinitialize and destroy ECS. This function release whole memory.

initialize
void initialize(uint threads_count, uint page_size, uint block_pages_count)

Initialize ECS.

Structs

CallData
struct CallData

Structure with data used to calling System calls.

CallDataAllocator
struct CallDataAllocator
Undocumented in source.
ComponentInfo
struct ComponentInfo

Component info;

EntitiesBlock
struct EntitiesBlock

Meta data of every block of entities (contained at the begining of block).

EntityInfo
struct EntityInfo

Entity type info.

EventCallData
struct EventCallData
Undocumented in source.
EventCaller
struct EventCaller
Undocumented in source.
EventInfo
struct EventInfo
Undocumented in source.
Job
struct Job
Undocumented in source.
JobGroup
struct JobGroup
Undocumented in source.
ListenerCallData
struct ListenerCallData
Undocumented in source.
SystemCaller
struct SystemCaller
Undocumented in source.
ThreadData
struct ThreadData
Undocumented in source.
UpdatePass
struct UpdatePass
Undocumented in source.

Variables

allocator
BlockAllocator allocator;
Undocumented in source.
components
Vector!ComponentInfo components;
Undocumented in source.
components_map
HashMap!(char[], ushort) components_map;
Undocumented in source.
entities_infos
HashMap!(ushort[], EntityInfo*) entities_infos;
Undocumented in source.
entity_block_alloc_mutex
Mutex* entity_block_alloc_mutex;
Undocumented in source.
event_manager
EventManager event_manager;
Undocumented in source.
events
Vector!EventInfo events;
Undocumented in source.
events_map
HashMap!(const(char)[], ushort) events_map;
Undocumented in source.
external_dependencies_map
HashMap!(const(char)[], ushort) external_dependencies_map;
Undocumented in source.
id_manager
IDManager id_manager;
Undocumented in source.
m_call_data_allocator
CallDataAllocator m_call_data_allocator;
Undocumented in source.
m_dispatch_jobs
void delegate(JobGroup jobs) nothrow @(nogc) m_dispatch_jobs;
Undocumented in source.
m_page_size
int m_page_size;

Single page size. Must be power of two.

m_pages_in_block
int m_pages_in_block;

Number of pages in block.

m_thread_id_func
uint delegate() nothrow @(nogc) m_thread_id_func;
Undocumented in source.
passes
Vector!(UpdatePass*) passes;
Undocumented in source.
passes_map
HashMap!(const(char)[], ushort) passes_map;
Undocumented in source.
register_state
bool register_state;
Undocumented in source.
systems
Vector!System systems;
Undocumented in source.
systems_map
HashMap!(char[], ushort) systems_map;
Undocumented in source.
threads
ThreadData[] threads;
Undocumented in source.

Meta