mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-03-22 12:55:31 +07:00
Compare commits
8 Commits
e364aaab37
...
v1.10.0
| Author | SHA1 | Date | |
|---|---|---|---|
| c072842c3a | |||
|
|
39c0b988b5 | ||
|
|
766f7b92be | ||
| f6b8844a82 | |||
| e48bdf0511 | |||
| a945401e9b | |||
| a1423ea9ee | |||
| 12a720bd9e |
113
README.md
113
README.md
@@ -45,7 +45,8 @@
|
||||
- [Batch Operations](#batch-operations)
|
||||
- [Systems](#systems)
|
||||
- [Processing Payloads](#processing-payloads)
|
||||
- [Predefined Traits](#predefined-traits)
|
||||
- [Predefined Fragments](#predefined-fragments)
|
||||
- [Entity Names](#entity-names)
|
||||
- [Fragment Tags](#fragment-tags)
|
||||
- [Fragment Hooks](#fragment-hooks)
|
||||
- [Unique Fragments](#unique-fragments)
|
||||
@@ -53,7 +54,6 @@
|
||||
- [Internal Fragments](#internal-fragments)
|
||||
- [Shared Components](#shared-components)
|
||||
- [Fragment Requirements](#fragment-requirements)
|
||||
- [Id Names](#id-names)
|
||||
- [Destruction Policies](#destruction-policies)
|
||||
- [Custom Component Storages](#custom-component-storages)
|
||||
- [Garbage Collection](#garbage-collection)
|
||||
@@ -65,7 +65,7 @@
|
||||
- [Chunk](#chunk)
|
||||
- [Builder](#builder)
|
||||
- [Changelog](#changelog)
|
||||
- [vX.Y.Z](#vxyz)
|
||||
- [v1.10.0](#v1100)
|
||||
- [v1.9.0](#v190)
|
||||
- [v1.8.0](#v180)
|
||||
- [v1.7.0](#v170)
|
||||
@@ -491,6 +491,7 @@ When you need to spawn multiple entities with identical fragments, use `multi_sp
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.multi_spawn(entity_count, component_table, component_mapper) end
|
||||
|
||||
---@param entity_count integer
|
||||
@@ -499,6 +500,7 @@ function evolved.multi_spawn(entity_count, component_table, component_mapper) en
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.multi_clone(entity_count, prefab, component_table, component_mapper) end
|
||||
```
|
||||
|
||||
@@ -529,6 +531,36 @@ end)
|
||||
|
||||
Of course, you can use `evolved.multi_clone` in the same way. Builders can also be used for multi-entity spawning and cloning by calling the corresponding methods on the builder object.
|
||||
|
||||
Also, for all `multi_` functions, the library provides [`_nr`](#evolvedmulti_spawn_nr) and [`_to`](#evolvedmulti_spawn_to) suffix variants that allow you to perform these operations without returning the list of spawned entities or by copying the spawned entities to your own table, which can be more efficient because it avoids the overhead of allocating and returning a new table.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local position_x, position_y = evolved.id(2)
|
||||
|
||||
do
|
||||
-- we don't interest in the list of spawned entities,
|
||||
-- so we use the _nr variant of the multi_spawn function
|
||||
|
||||
evolved.multi_spawn_nr(100, {
|
||||
[position_x] = 0,
|
||||
[position_y] = 0,
|
||||
})
|
||||
end
|
||||
|
||||
do
|
||||
-- store spawned entities in our own table starting at index 1,
|
||||
-- so we use the _to variant of the multi_spawn function
|
||||
|
||||
local entity_list = {}
|
||||
|
||||
evolved.multi_spawn_to(entity_list, 1, 100, {
|
||||
[position_x] = 0,
|
||||
[position_y] = 0,
|
||||
})
|
||||
end
|
||||
```
|
||||
|
||||
### Access Operations
|
||||
|
||||
The library provides all the necessary functions to access entities and their components. I'm not going to cover all the accessor functions here, because they are pretty straightforward and self-explanatory. You can check the [API Reference](#api-reference) for all of them. Here are some of the most important ones:
|
||||
@@ -983,7 +1015,42 @@ evolved.process_with(physics_system, delta_time)
|
||||
|
||||
`delta_time` in this example is passed as a processing payload to the system's execution callback. Payloads can be of any type and can be multiple values. Also, payloads are passed to prologue and epilogue callbacks if they are defined. Every subsystem in a group will receive the same payload when the group is processed with [`evolved.process_with`](#evolvedprocess_with).
|
||||
|
||||
### Predefined Traits
|
||||
### Predefined Fragments
|
||||
|
||||
#### Entity Names
|
||||
|
||||
The library provides a way to assign names to any id using the [`evolved.NAME`](#evolvedname) fragment. This is useful for debugging and development purposes, as it allows you to identify entities or fragments by their names instead of their identifiers. The name of an entity can be retrieved using the [`evolved.name`](#evolvedname-1) function.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local player = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
assert(evolved.name(player) == 'Player')
|
||||
```
|
||||
|
||||
Names are not unique, so multiple entities can have the same name. Also, the name of an entity can be changed at any time by setting a new name using the [`evolved.NAME`](#evolvedname) fragment as a usual component.
|
||||
|
||||
You can find entities by their names using the [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions. The [`evolved.lookup`](#evolvedlookup) function returns the first entity with the specified name, while the [`evolved.multi_lookup`](#evolvedmulti_lookup) function returns a list of all entities with the specified name.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local player1 = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
local player2 = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
assert(evolved.lookup('Player') == player1)
|
||||
|
||||
local player_list, player_count = evolved.multi_lookup('Player')
|
||||
assert(player_count == 2 and player_list[1] == player1 and player_list[2] == player2)
|
||||
```
|
||||
|
||||
#### Fragment Tags
|
||||
|
||||
@@ -1163,41 +1230,6 @@ local enemy = evolved.builder()
|
||||
assert(evolved.has_all(enemy, position, velocity))
|
||||
```
|
||||
|
||||
#### Id Names
|
||||
|
||||
The library provides a way to assign names to any id using the [`evolved.NAME`](#evolvedname) fragment. This is useful for debugging and development purposes, as it allows you to identify entities or fragments by their names instead of their identifiers. The name of an entity can be retrieved using the [`evolved.name`](#evolvedname-1) function.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local player = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
assert(evolved.name(player) == 'Player')
|
||||
```
|
||||
|
||||
Names are not unique, so multiple entities can have the same name. Also, the name of an entity can be changed at any time by setting a new name using the [`evolved.NAME`](#evolvedname) fragment as a usual component.
|
||||
|
||||
You can find entities by their names using the [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions. The [`evolved.lookup`](#evolvedlookup) function returns the first entity with the specified name, while the [`evolved.multi_lookup`](#evolvedmulti_lookup) function returns a list of all entities with the specified name.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local player1 = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
local player2 = evolved.builder()
|
||||
:name('Player')
|
||||
:build()
|
||||
|
||||
assert(evolved.lookup('Player') == player1)
|
||||
|
||||
local player_list, player_count = evolved.multi_lookup('Player')
|
||||
assert(player_count == 2 and player_list[1] == player1 and player_list[2] == player2)
|
||||
```
|
||||
|
||||
#### Destruction Policies
|
||||
|
||||
Typically, fragments remain alive for the entire lifetime of the program. However, in some cases, you might want to destroy fragments when they are no longer needed. For example, you can use some runtime entities as fragments for other entities. In this case, you might want to destroy such fragments even while they are still attached to other entities. Since entities cannot have destroyed fragments, a destruction policy must be applied to resolve this. By default, the library will remove the destroyed fragment from all entities that have it.
|
||||
@@ -1636,10 +1668,11 @@ builder_mt:destruction_policy :: id -> builder
|
||||
|
||||
## Changelog
|
||||
|
||||
### vX.Y.Z
|
||||
### v1.10.0
|
||||
|
||||
- Added the new [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions that allow finding ids by their names
|
||||
- Added a non-shrinking version of the [`evolved.collect_garbage`](#evolvedcollect_garbage) function that only collects garbage without shrinking storages
|
||||
- Added [`_nr`](#evolvedmulti_spawn_nr) and [`_to`](#evolvedmulti_spawn_to) variants of the [`evolved.multi_spawn`](#evolvedmulti_spawn) and [`evolved.multi_clone`](#evolvedmulti_clone) functions that provide more efficient ways to spawn or clone entities in some cases
|
||||
|
||||
### v1.9.0
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local evolved = {
|
||||
__HOMEPAGE = 'https://github.com/BlackMATov/evolved.lua',
|
||||
__DESCRIPTION = 'Evolved ECS (Entity-Component-System) for Lua',
|
||||
__VERSION = '1.9.0',
|
||||
__VERSION = '1.10.0',
|
||||
__LICENSE = [[
|
||||
MIT License
|
||||
|
||||
|
||||
34
rockspecs/evolved.lua-1.10.0-0.rockspec
Normal file
34
rockspecs/evolved.lua-1.10.0-0.rockspec
Normal file
@@ -0,0 +1,34 @@
|
||||
rockspec_format = "3.0"
|
||||
package = "evolved.lua"
|
||||
version = "1.10.0-0"
|
||||
source = {
|
||||
url = "git://github.com/BlackMATov/evolved.lua",
|
||||
tag = "v1.10.0",
|
||||
}
|
||||
description = {
|
||||
homepage = "https://github.com/BlackMATov/evolved.lua",
|
||||
summary = "Evolved ECS (Entity-Component-System) for Lua",
|
||||
detailed = [[
|
||||
`evolved.lua` is a fast and flexible ECS (Entity-Component-System) library for Lua.
|
||||
It is designed to be simple and easy to use, while providing all the features needed to create complex systems with blazing performance.
|
||||
]],
|
||||
license = "MIT",
|
||||
labels = {
|
||||
"ecs",
|
||||
"entity",
|
||||
"entities",
|
||||
"component",
|
||||
"components",
|
||||
"entity-component",
|
||||
"entity-component-system",
|
||||
},
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1",
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
evolved = "evolved.lua",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user