en:toolworks:docs:apparatus:ecs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:toolworks:docs:apparatus:ecs [2021/04/02 22:13] – Add some dummy text jisparen:toolworks:docs:apparatus:ecs [2021/04/08 10:24] vladius
Line 1: Line 1:
-==== Introduction to ECS==== +====== Introduction to ECS ====== 
-Talking about OOP (object-oriented programming) we consider our practical task as multiplicity of special abstract things. In terms of UE4 these abstractions are named UObjects and over them we can apply such a principle like an inheritance. What does it mean? We create some main abstraction called 'Base class', define properties (i.e. variables and functions) and by deriving from that class we can create other abstractions which will get all the parent properties and define their own additional or distinctive ones. The most popular example in that way is the tree of animals inheritance, where the base class represent any animal exist, but the others (derived from the base one) represent separate animal sorts:+ 
 +Talking about object-oriented programming (OOP)we consider our practical task as multiplicity of special abstract things. In terms of Unreal Engine these abstractions are mainly called Objects (or ''UObjects'' code-wise). Furthermore we apply a principle like an inheritance upon them. We create some main abstraction layer called 'Base class', define some properties (i.e. variables and functions) and by deriving from that class we can create other abstractions which in turn get all the parent properties and define their own additionaldistinctive ones. The most popular example for that approach is tree of animal inheritance, where the base class represent any animal existing, but the others (derived from the base one) represent some separate animal sorts and kinds: 
 {{ :en:toolworks:docs:oop-example.jpg?nolink |}} {{ :en:toolworks:docs:oop-example.jpg?nolink |}}
-By using base class properties we can change current state of objects of derived class. But the problem is the game logic can become too scattered across the classes. 
-In game development there is such an approach named ECS (that is [[https://en.wikipedia.org/wiki/Entity_component_system|Entity component system]]). 
  
-So what are the main concepts? Here we make an attempt to understand each abstraction as individual entityGlobally, there are some states each entity may be in or notFrom this point of vieweach entity can be represented as vector of 1-es and 0-eswhere each vector's component represents if the entity at the current moment is in the defined state or notThat's more: some entities may be constructed in such way that they fundamentally can't go to certain statesFor examplelet us say we declare state 'swimmingand the entity 'housethen (that's quite logical) we can't move 'houseentity to the 'swimmingstate. So then each vector now have different components number depending on which entity it represents. Now let's call vector component representing certain state type as 'detail'. Each entity has a variety of details and each detail of the entity has the value 0 ('disabled') if the entity isn't in the detail state right nowand the value 1('enabled'if the entity is in the corresponding state.+By using the base class properties we can change the current state of the objects in the derived class. But the problem is the game logic can become too scattered across those classes and layers. 
 + 
 +A solution to this game development problem is an approach called [[wp>Entity_component_system|ECS]]. 
 + 
 +Apparatus provides all of the basic ECS idioms and even more. To be unambiguous the framework it uses a different naming scheme as compared to classic ECSHere is the list of analogous terms: 
 + 
 +^ ECS Term            ^ Apparatus Term  ^ 
 +| Entity              | Subject         | 
 +| Component           | Detail          | 
 +| System              | Mechanic        | 
 +| A group of Systems  | Mechanism       | 
 +| Archetype           | Fingerprint     | 
 +| Chunk               | Belt            | 
 + 
 +==== About ECS+ ==== 
 + 
 +Apparatus takes a broader approach on ECS that we essentially call ECS+ over here. It introduces a greater amount of flexibility with the help of detail (component) inheritance support and sparse expandabledynamic belts (chunks and archetypes). The term ECS+ in itself should be treated as more of a synonym for the "Apparatus" wording itself, since it actually implements it and uses a different terminology from a classic ECS. 
 + 
 +Generally speaking, in our own philosophy, engineering should never be "pure" or "mathematically correct" but mainly applicable and useful to the end user and/or the developerUnreal Engine in itself is actually good demonstration of this approach with so many special cases. 
 + 
 +==== Built-in Subjects ==== 
 + 
 +At a lower level, ''Subjective'' is an interface and any class that implements it may be called a ''Subject''. There are several subjects already implemented in the framework: 
 + 
 +  * ''SubjectiveActorComponent'' (based on ''ActorComponent''),  
 +  * ''SubjectiveUserWidget'' (based on ''UserWidget''), 
 +  * ''SubjectiveActor'' (based on ''Actor'')
 + 
 +Those should be sufficient for the most cases, but you can easily implement your own additional subject classes in C++.
  
-You can imagine each entity as a box of details. +==== Built-in Mechanisms ====
-These details have the bool variable 'bActive' and if it's set to 0 then the detail is disabled and is enabled otherwise. There is ability to remove and add details dynamically if it's necessary. For example 'man' can get hurt from the pistol shot in the chest but only not when he has the bulletproof vest (technically you can declare such a detail like 'getting a pistol shot' what will be something like 'temporary state' and immediately should be replaced by other detail like 'injured' one).+
  
-Ok, we have some entities which contain different details. Furthermore we can apply some changes to all the entities based on which details they have and if these details are enabled or not. For example, for each entity which has the details 'burnableand 'burning' both enabled, we can decrease their health (or armor) and then disable (or absolutely remove) 'burningdetails from them (simply speaking, the fire went out).+The ''Mechanical'' class is also an interfacewith the most useful mechanisms already implemented: 
  
-As you understand these changes are actually defining the whole game logic and we have to run them continuously during the playing to keep dynamics of states. It's also quite clear we can place all the code which will apply these changes in the one class, so it becomes easier to view and modify them. That class called 'Mechanismand it's responsible for applying changes to each object depending on which details it has. Now the whole picture is next: +  * ''MechanicalActor'' (inherited from ''Actor''), 
-{{ :en:toolworks:docs:ecs-example.jpg?nolink |}} +  * ''MechanicalGameModeBase'' (''GameModeBase''), 
-Here disabled details are crossed out, but details which will produce some changes are highlighted. Of course a mechanism can't process entities parallelly, instead it iterate other each entity and check determined cases. Each case declares which details should the entity has and which of them should be enabled or disabled. If an entity complies with the case requirements, some changes will be applied to it, else the next case will be checked out and so so on. Thus, the 'caseis something contains a vector of 0-es and 1-es representing 'being in certain states': +  * ''MechanicalGameMode'' (''GameMode'').
-{{ :en:toolworks:docs:apparatus-case-examples.png?nolink |}} +
-A programmer declares cases and what actions to undertake for each entity what complying with the case. **You should also understand that the 'another casein the example above will determine what to execute over the entities what have the detail 'hurtdisabled and the entities what haven't this detail.** +
-You also may say the iteration across all the entities is **slower** than the use of UE4 dispatchers or simple function calling, but on the low level it's coded in the most optimized way, so actually there is no any difference.+
  
 +You would hardly ever need to implement your own mechanisms. Should you wish to, you can also do it in C++.
  • en/toolworks/docs/apparatus/ecs.txt
  • Last modified: 2021/12/18 15:19
  • by jispar