8 Commits

Author SHA1 Message Date
c072842c3a Merge pull request #44 from BlackMATov/dev
Dev
2026-02-13 23:24:38 +07:00
BlackMATov
39c0b988b5 v1.10.0 2026-02-13 23:18:20 +07:00
BlackMATov
766f7b92be update README 2026-02-13 21:13:51 +07:00
f6b8844a82 Merge pull request #40 from BlackMATov/dev
Dev
2026-02-02 08:30:39 +07:00
e48bdf0511 Merge pull request #39 from BlackMATov/dev
Dev
2026-01-18 20:27:35 +07:00
a945401e9b Merge pull request #37 from BlackMATov/dev
Dev
2026-01-11 21:19:41 +07:00
a1423ea9ee Merge pull request #33 from BlackMATov/dev
Dev
2025-12-28 06:48:21 +07:00
12a720bd9e Merge pull request #31 from BlackMATov/dev
Dev
2025-11-24 13:49:59 +07:00
3 changed files with 108 additions and 41 deletions

113
README.md
View File

@@ -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

View File

@@ -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

View 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",
}
}