From fbd9a4ad648e1322246fc247a59eba2d79681c5e Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Sun, 17 May 2020 23:10:51 +0800 Subject: [PATCH] Update API.md --- doc/API.md | 78 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/doc/API.md b/doc/API.md index 54fb70d..525afbc 100644 --- a/doc/API.md +++ b/doc/API.md @@ -1,37 +1,39 @@ -# `Entity` +# API + +## `Entity` Entity = `index` + `version` -## Fields +### Fields -### `size_t index` +#### `size_t index` The ID of an entity. Entity indexes are recycled when an entity is destroyed. When an entity is destroyed, the EntityManager increments the version identifier. To represent the same entity, both the Index and the Version fields of the Entity object must match. If the Index is the same, but the Version is different, then the entity has been recycled. -`version` +#### `version` The generational version of the entity. The Version number can, theoretically, overflow and wrap around within the lifetime of an application. For this reason, you cannot assume that an Entity instance with a larger Version is a more recent incarnation of the entity than one with a smaller Version (and the same Index). -## Methods +### Methods - `size_t Idx() const`: entity's index. - `size_t Version() const`: entity's version. -# `CmptType` +## `CmptType` an ID to identify component's type, use `TypeID`(a **compile-time** hash code of `Component`) as default. -## Fields +### Fields -### `size_t hashcode` +#### `size_t hashcode` ID, it's unique in global. -## Methods +### Methods - `constexpr CmptType(size_t id)`: custom ID - `constexpr CmptType(std::string_view)`: use `RuntimeTypeID(std::string_view)` (use [fnv1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function)) to hash the string @@ -40,21 +42,21 @@ ID, it's unique in global. - `template static constexpr CmptType HashCodeOf()`: component's ID, equal to `CmptType::Of().HashCode()` - `template bool Is() const`: if ID is same with `TypeID`, return `true`, else return `false` -# `CmptPtr` +## `CmptPtr` `CmptPtr` = `CmptType` + `void*` -## Fields +### Fields -### `CmptType type` +#### `CmptType type` `CmptType` use to identify `void*` pointer's actual type. -### `void* ptr` +#### `void* ptr` a no-type pointer of a component. -## Methods +### Methods - `CmptPtr(CmptType, void*)`: constructor - `template CmptPtr(Cmpt*)`: use `CmptType::Of` as `type` @@ -62,7 +64,7 @@ a no-type pointer of a component. - `void* Ptr() const`: get `ptr` - `template Cmpt* As() const:`: reinterpret `ptr` -# `RTDCmptTraits` +## `RTDCmptTraits` runtime component traits for dynamic type @@ -77,7 +79,7 @@ you can register a dynamic class with - move constructor: optional, `memcpy` as default - destructor: optional, do nothing as default -## Methods +### Methods - `static RTDCmptTraits& Instance()`: get the instance of `RTDCmptTraits` - `RTDCmptTraits& RegisterSize(CmptType type, size_t size)` @@ -88,13 +90,13 @@ you can register a dynamic class with - `RTDCmptTraits& RegisterDestructor(CmptType type, std::function f)` - `RTDCmptTraits& Deregister(CmptType type)`: deregister size, alignment, default/copy/move constructor and destructor. -# `EntityMngr` +## `EntityMngr` The `EntityMngr` manages entities and components in a `World`. -## Fields +### Fields -### `private: std::vector entityTable` +#### `private: std::vector entityTable` an array to store entities's infomation. @@ -106,11 +108,11 @@ an array to store entities's infomation. > }; > ``` -### `private: std::vector> commandBuffer` +#### `private: std::vector> commandBuffer` a buffer to store commands added in `World::Update()` for methods which can not run in worker threads. -## Methods +### Methods **Entity** @@ -175,7 +177,7 @@ if `e` is invalid, throw `std::invalid_argument`. - `size_t EntityNum(const EntityQuery&) const`: get the number of entities which match the query. - `void AddCommand(const std::function& command)`: add a command in updating and run at the end of `World::Update` in the main thread. -# `CmptTag` +## `CmptTag` use tag to dstinguish write, read before write and read after write @@ -183,19 +185,19 @@ use tag to dstinguish write, read before write and read after write - `CmptTag::Write`: write, equal to ` *` - `CmptTag::Latest`: read after write, equal to `const *` -# `EntityLocator` +## `EntityLocator` locate components in function's argument list for Archetype -# `EntityFilter` +## `EntityFilter` filter Archetype with All, Any and None -# `EntityQuery` +## `EntityQuery` `EntityLocator` + `EntityFilter` -# `SystemFunc` +## `SystemFunc` system function registered by Schedule in `::OnUpdate(Schedule&)` @@ -212,13 +214,13 @@ query.filter can be change dynamically by other `` with Schedule - job: empty argument list - runtime dynamic function: `const EntityLocator* locator, void** cmpts` -## Fields +### Fields -### `EntityQuery query` +#### `EntityQuery query` query -## Methods +### Methods - `template SystemFunc(Func&& func, std::string name, EntityFilter filter = EntityFilter{})` - `template SystemFunc(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{})`: run-time dynamic function @@ -229,7 +231,7 @@ query - `bool IsJob() const` - `bool operator==(const SystemFunc& func) const` -# `Schedule` +## `Schedule` system infomation record @@ -239,7 +241,7 @@ system infomation record schedule will be clear at the beginning of the **next** `World::Update()` -### Methods +#### Methods - `template Schedule& Register(Func&& func, std::string name, EntityFilter filter = EntityFilter{})` - `template Schedule& Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{})` @@ -261,33 +263,33 @@ schedule will be clear at the beginning of the **next** `World::Update()` - `template Schedule& EraseAny(std::string_view sys)` - `template Schedule& EraseNone(std::string_view sys)` -# `SystemMngr` +## `SystemMngr` System is a struct with specific function signature: static void OnUpdate(Schedule&) -### Methods +#### Methods - `template void Register()` - `template bool IsRegistered() const` - `template void Deregister()` -# `World` +## `World` `World` = `EntityMngr` + `SystemMngr` -## Fields +### Fields -### `SystemMngr systemMngr` +#### `SystemMngr systemMngr` manage systems -### `EntityMngr entityMngr` +#### `EntityMngr entityMngr` manage entities -## Methods +### Methods - `void Update()`: schedule -> gen job graph -> run job graph in worker threads -> run commands in main thread