You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MANUAL.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@
2
2
3
3
## Identifiers
4
4
5
-
Identifier is a packed 40-bit integer number. The first 20 bits are the index, and the last 20 bits are the version. To create a new identifier, use the `evolved.id` function.
5
+
Identifiers are packed 40-bit integer numbers. The first 20 bits are the index, and the last 20 bits are the version. To create a new identifier, use the `evolved.id` function.
6
6
7
7
```lua
8
8
---@paramcount?integer
9
9
---@returnevolved.id ... ids
10
10
functionevolved.id(count) end
11
11
```
12
12
13
-
The `count` parameter is optional and defaults to `1`. The function returns one or more identifiers, depending on the `count` parameter. Maximum number of alive identifiers is `2^20-1` (1048575). After that, the function will throw an error`"| evolved.lua | id index overflow"`.
13
+
The `count` parameter is optional and defaults to `1`. The function returns one or more identifiers, depending on the `count` parameter. The maximum number of alive identifiers is `2^20-1` (1048575). After that, the function will throw an error: "| evolved.lua | id index overflow".
14
14
15
15
Identifiers can be recycled. When an identifier is no longer needed, use the `evolved.destroy` function to destroy it. This will free up the identifier for reuse.
16
16
@@ -39,7 +39,7 @@ function evolved.alive_all(...) end
39
39
functionevolved.alive_any(...) end
40
40
```
41
41
42
-
Sometimes (for debugging purposes for example), it is necessary to extract the index and version from an identifier (or pack them back). The `evolved.pack` and `evolved.unpack` functions can be used for this purpose.
42
+
Sometimes (for debugging purposes, for example), it is necessary to extract the index and version from an identifier (or pack them back). The `evolved.pack` and `evolved.unpack` functions can be used for this purpose.
43
43
44
44
```lua
45
45
---@paramindexinteger
@@ -53,7 +53,7 @@ function evolved.pack(index, version) end
53
53
functionevolved.unpack(id) end
54
54
```
55
55
56
-
Here is an little example of how to use identifiers:
56
+
Here is a little example of how to use identifiers:
57
57
58
58
```lua
59
59
localevolved=require'evolved'
@@ -70,7 +70,7 @@ assert(not evolved.alive(id)) -- check if the identifier is not alive now
70
70
71
71
## Entities, Fragments, and Components
72
72
73
-
First of all, we need to understand that entities and fragments are just identifiers. The differences between them are purely semantic. Entities are used to represent objects in the world, while fragments are used to represent types of components that can be attached to entities. Components, in the other hand, are any data that is attached to entities through fragments.
73
+
First of all, we need to understand that entities and fragments are just identifiers. The differences between them are purely semantic. Entities are used to represent objects in the world, while fragments are used to represent types of components that can be attached to entities. Components, on the other hand, are any data that is attached to entities through fragments.
74
74
75
75
Here is a simple example of how to attach a component to an entity:
We have created an entity called `player` and two fragments called `health` and `stamina`. We have attached the components `100` and `50` to the entity through our fragments. After that, we can retrieve the components using the `evolved.get` function.
104
104
105
-
We'll cover the `evolved.set` and `evolved.get` functions in more detail later in the section about modifying operations. For now, let's just say that they are used to setting and getting components from entities through fragments.
105
+
We'll cover the `evolved.set` and `evolved.get` functions in more detail later in the section about modifying operations. For now, let's just say that they are used for setting and getting components from entities through fragments.
106
106
107
-
The main thing to understand here is that we can attach any data to any identifiers using another identifiers. And yes, since fragments are just identifiers, we can use them as entities too! This very useful for marking fragments with some metadata, for example.
107
+
The main thing to understand here is that we can attach any data to any identifiers using other identifiers. And yes, since fragments are just identifiers, we can use them as entities too! This is very useful for marking fragments with some metadata, for example.
In this example, we have created a fragment called `serializable` and marked the fragments `position` and `velocity` as serializable. After that, we can write a function that will serialize entities. And this function will serialize only fragments that are marked as serializable. This is a very powerful feature of the library, and it allows us to create very flexible systems. Btw, fragments of fragments are usually called `traits`.
125
+
In this example, we have created a fragment called `serializable` and marked the fragments `position` and `velocity` as serializable. After that, we can write a function that will serialize entities. And this function will serialize only fragments that are marked as serializable. This is a very powerful feature of the library, and it allows us to create very flexible systems. By the way, fragments of fragments are usually called `traits`.
0 commit comments