-added more documentation

-remove update() function from entity
-currently max supported components count is 64 per type
This commit is contained in:
Mergul 2020-03-21 13:27:14 +01:00
parent 546b73c567
commit 845f468d59
10 changed files with 199 additions and 64 deletions

View file

@ -7,7 +7,7 @@ import ecs.system;
import ecs.manager;
/************************************************************************************************************************
*Entity ID structure.
*Entity ID structure. Used as reference to Entity. Pointer to entity should be ever used to store entity reference!
*/
struct EntityID
{
@ -26,15 +26,8 @@ struct Entity
EntityID id;
/************************************************************************************************************************
*Update pointer to it in IDManager
*/
void updateID() nothrow @nogc
{
EntityManager.instance.id_manager.update(this);
}
/************************************************************************************************************************
*Get specified component. If component doesn't exist function retun null.
*Get specified component. If component doesn't exist function retun null. Pointer is valid only before next "commit()", "begin()" or "end()"
*function is called. Returned pointer shouldn't be used to store reference to entity data.
*/
T* getComponent(T)() const
{
@ -49,10 +42,21 @@ struct Entity
uint ind = cast(uint)((cast(void*)&this - block.dataBegin()) / EntityID.sizeof());
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + ind * T.sizeof);
}
/*package void updateID() nothrow @nogc
{
EntityManager.instance.id_manager.update(this);
}*/
}
/************************************************************************************************************************
*Entity template structure.
*Entity contain whole information needed to create new entity. Allocating EntityTemplate is considered as more expensive operation
*than adding entity. Whole components memory is stored in EntityTemplate and is copyied to newly added entity.
*If you want to place several entity with small difference in data then you should take pointer to component and change it before every
*entity addition.
*There is no restriction about number of allocated templates. Single template can be used from multiple threads, but if you
*want to changes some components data before add entity (entity position for example) it's better to use multiple templates.
*/
export struct EntityTemplate
{
@ -62,7 +66,7 @@ export struct EntityTemplate
EntityManager.EntityInfo* info;
/************************************************************************************************************************
*Get specified component. If component doesn't exist function return null.
*Get specified component. If component doesn't exist function return null. Returned pointer is valid during EntityTemplate lifetime.
*/
T* getComponent(T)() nothrow @nogc
{