Skip to content

Commit

Permalink
Update API.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed May 17, 2020
1 parent 33364af commit fbd9a4a
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions doc/API.md
Original file line number Diff line number Diff line change
@@ -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<Component>`(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
Expand All @@ -40,29 +42,29 @@ ID, it's unique in global.
- `template<typename Cmpt> static constexpr CmptType HashCodeOf()`: component's ID, equal to `CmptType::Of<Cmpt>().HashCode()`
- `template<typename Cmpt> bool Is() const`: if ID is same with `TypeID<Cmpt>`, 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<typename Cmpt> CmptPtr(Cmpt*)`: use `CmptType::Of<Cmpt>` as `type`
- `CmptType Type() const`: get `type`
- `void* Ptr() const`: get `ptr`
- `template<typename Cmpt> Cmpt* As() const:`: reinterpret `ptr`

# `RTDCmptTraits`
## `RTDCmptTraits`

runtime component traits for dynamic type

Expand All @@ -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)`
Expand All @@ -88,13 +90,13 @@ you can register a dynamic class with
- `RTDCmptTraits& RegisterDestructor(CmptType type, std::function<void(void*)> 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<EntityInfo> entityTable`
#### `private: std::vector<EntityInfo> entityTable`

an array to store entities's infomation.

Expand All @@ -106,11 +108,11 @@ an array to store entities's infomation.
> };
> ```
### `private: std::vector<std::function<void()>> commandBuffer`
#### `private: std::vector<std::function<void()>> commandBuffer`
a buffer to store commands added in `World::Update()` for methods which can not run in worker threads.
## Methods
### Methods
**Entity**
Expand Down Expand Up @@ -175,27 +177,27 @@ 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<void()>& 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
- `CmptTag::LastFrame<Component>`: read before write
- `CmptTag::Write<Component>`: write, equal to `<Component> *`
- `CmptTag::Latest<Component>`: read after write, equal to `const <Component> *`
# `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 `<System>::OnUpdate(Schedule&)`
Expand All @@ -212,13 +214,13 @@ query.filter can be change dynamically by other `<System>` with Schedule
- job: empty argument list
- runtime dynamic function: `const EntityLocator* locator, void** cmpts`
## Fields
### Fields
### `EntityQuery query`
#### `EntityQuery query`
query
## Methods
### Methods
- `template<typename Func> SystemFunc(Func&& func, std::string name, EntityFilter filter = EntityFilter{})`
- `template<typename Func> SystemFunc(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{})`: run-time dynamic function
Expand All @@ -229,7 +231,7 @@ query
- `bool IsJob() const`
- `bool operator==(const SystemFunc& func) const`
# `Schedule`
## `Schedule`
system infomation record
Expand All @@ -239,7 +241,7 @@ system infomation record
schedule will be clear at the beginning of the **next** `World::Update()`
### Methods
#### Methods
- `template<typename Func> Schedule& Register(Func&& func, std::string name, EntityFilter filter = EntityFilter{})`
- `template<typename Func> Schedule& Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{})`
Expand All @@ -261,33 +263,33 @@ schedule will be clear at the beginning of the **next** `World::Update()`
- `template<typename Cmpt> Schedule& EraseAny(std::string_view sys)`
- `template<typename Cmpt> Schedule& EraseNone(std::string_view sys)`
# `SystemMngr`
## `SystemMngr`
System is a struct with specific function
signature: static void OnUpdate(Schedule&)
### Methods
#### Methods
- `template<typename... Systems> void Register()`
- `template<typename System> bool IsRegistered() const`
- `template<typename System> 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
Expand Down

0 comments on commit fbd9a4a

Please sign in to comment.