Merge pull request #33 from BlackMATov/dev

Dev
This commit is contained in:
2025-12-28 06:48:21 +07:00
committed by GitHub
17 changed files with 828 additions and 535 deletions

View File

@@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v11
- uses: leafo/gh-actions-lua@v12
with:
luaVersion: ${{matrix.lua_version}}
- run: |

21
.github/workflows/lua5.2.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: lua5.2
on: [push, pull_request]
jobs:
build:
runs-on: ${{matrix.operating_system}}
strategy:
fail-fast: false
matrix:
lua_version: ["5.2"]
operating_system: ["ubuntu-latest", "macos-latest", "windows-latest"]
name: ${{matrix.operating_system}}-${{matrix.lua_version}}
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v12
with:
luaVersion: ${{matrix.lua_version}}
- run: |
lua ./develop/all.lua

21
.github/workflows/lua5.3.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: lua5.3
on: [push, pull_request]
jobs:
build:
runs-on: ${{matrix.operating_system}}
strategy:
fail-fast: false
matrix:
lua_version: ["5.3"]
operating_system: ["ubuntu-latest", "macos-latest", "windows-latest"]
name: ${{matrix.operating_system}}-${{matrix.lua_version}}
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v12
with:
luaVersion: ${{matrix.lua_version}}
- run: |
lua ./develop/all.lua

View File

@@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v11
- uses: leafo/gh-actions-lua@v12
with:
luaVersion: ${{matrix.lua_version}}
- run: |

View File

@@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v11
- uses: leafo/gh-actions-lua@v12
with:
luaVersion: ${{matrix.lua_version}}
- run: |

27
.vscode/launch.json vendored
View File

@@ -10,6 +10,24 @@
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.2)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.2",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.3)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.3",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.4)",
"type": "lua-local",
@@ -19,6 +37,15 @@
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.5)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.5",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (luajit)",
"type": "lua-local",

View File

@@ -60,6 +60,7 @@
- [Chunk](#chunk)
- [Builder](#builder)
- [Changelog](#changelog)
- [v1.6.0](#v160)
- [v1.5.0](#v150)
- [v1.4.0](#v140)
- [v1.3.0](#v130)
@@ -643,6 +644,10 @@ Now we know that structural changes are not allowed during iteration, but what i
---@return boolean started
function evolved.defer() end
---@return integer depth
---@nodiscard
function evolved.depth() end
---@return boolean committed
function evolved.commit() end
@@ -650,7 +655,7 @@ function evolved.commit() end
function evolved.cancel() end
```
The [`evolved.defer`](#evolveddefer) function starts a deferred scope. This means that all changes made inside the scope will be queued and applied after leaving the scope. The [`evolved.commit`](#evolvedcommit) function closes the last deferred scope and applies all queued changes. These functions can be nested, so you can start a new deferred scope inside an existing one. The [`evolved.commit`](#evolvedcommit) function will apply all queued changes only when the last deferred scope is closed.
The [`evolved.defer`](#evolveddefer) function starts a deferred scope. This means that all changes made inside the scope will be queued and applied after leaving the scope. The [`evolved.commit`](#evolvedcommit) function closes the last deferred scope and applies all queued changes. These functions can be nested, so you can start a new deferred scope inside an existing one. The [`evolved.commit`](#evolvedcommit) function will apply all queued changes only when the last deferred scope is closed. The [`evolved.depth`](#evolveddepth) function returns the current depth of deferred scopes. If there are no deferred scopes, it returns `0`.
```lua
local evolved = require 'evolved'
@@ -1184,6 +1189,7 @@ pack :: integer, integer -> id
unpack :: id -> integer, integer
defer :: boolean
depth :: integer
commit :: boolean
cancel :: boolean
@@ -1306,11 +1312,16 @@ builder_mt:destruction_policy :: id -> builder
## Changelog
### v1.6.0
- Significant performance improvements of the [`evolved.REQUIRES`](#evolvedrequires) fragment trait
- Added the new [`evolved.depth`](#evolveddepth) function that returns the current depth of deferred scopes
### v1.5.0
- Added a little [LÖVE](https://love2d.org) example;
- The spawn and clone operations with defaults have been significantly optimized;
- Added basic [Teal](https://github.com/teal-language) type definitions, thanks to [@p0sel0k](https://github.com/p0sel0k).
- Added a little [LÖVE](https://love2d.org) example
- The spawn and clone operations with defaults have been significantly optimized
- Added basic [Teal](https://github.com/teal-language) type definitions, thanks to [@p0sel0k](https://github.com/p0sel0k)
### v1.4.0
@@ -1446,6 +1457,14 @@ function evolved.unpack(id) end
function evolved.defer() end
```
### `evolved.depth`
```lua
---@return integer depth
---@nodiscard
function evolved.depth() end
```
### `evolved.commit`
```lua

View File

@@ -17,6 +17,7 @@
1. Insert the new function into the `evolved` table in `evolved.lua`.
2. Create tests for the function in `develop/testing/function_name_tests.lua`.
3. Add the new test to `develop/all.lua`.
4. Document the function in the **Cheat Sheet** and **API Reference** sections of `README.md`.
5. Provide a description in the **Overview** section of `README.md`.
6. Describe the update in the **Changelog** section of `README.md`.
4. Update the Teal type definitions in `evolved.d.tl`.
5. Document the function in the **Cheat Sheet** and **API Reference** sections of `README.md`.
6. Provide a description in the **Overview** section of `README.md`.
7. Describe the update in the **Changelog** section of `README.md`.

View File

@@ -9,10 +9,8 @@
## Thoughts
- We can return deferred status from modifying operations and spawn/clone methods.
- We should have a way to not copy components on deferred spawn/clone.
- We should have a way to not copy components on deferred spawn/clone
## Known Issues
- Required fragments are slower than they should be
- Errors in hooks are cannot be handled properly right now

View File

@@ -1,6 +1,8 @@
require 'develop.testing.build_tests'
require 'develop.testing.cancel_tests'
require 'develop.testing.clone_tests'
require 'develop.testing.depth_tests'
require 'develop.testing.destroy_tests'
require 'develop.testing.locate_tests'
require 'develop.testing.main_tests'
require 'develop.testing.multi_spawn_tests'

View File

@@ -173,6 +173,7 @@ basics.describe_bench(
local clone = evo.clone
local prefab = evo.spawn { [RF1] = true }
evo.remove(prefab, F1)
for _ = 1, N do
clone(prefab)
@@ -217,6 +218,7 @@ basics.describe_bench(
local clone = evo.clone
local prefab = evo.spawn { [RF123] = true }
evo.remove(prefab, F1, F2, F3)
for _ = 1, N do
clone(prefab)
@@ -261,6 +263,7 @@ basics.describe_bench(
local clone = evo.clone
local prefab = evo.spawn { [RF12345] = true }
evo.remove(prefab, F1, F2, F3, F4, F5)
for _ = 1, N do
clone(prefab)

View File

@@ -0,0 +1,65 @@
local evo = require 'evolved'
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.cancel())
assert(evo.depth() == 1)
assert(evo.cancel())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.commit())
assert(evo.depth() == 1)
assert(evo.commit())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.cancel())
assert(evo.depth() == 1)
assert(evo.commit())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.commit())
assert(evo.depth() == 1)
assert(evo.cancel())
assert(evo.depth() == 0)
end

View File

@@ -0,0 +1,104 @@
local evo = require 'evolved'
do
local e = evo.id()
assert(evo.alive(e))
evo.destroy(e)
assert(not evo.alive(e))
evo.destroy(e)
assert(not evo.alive(e))
end
do
local e1, e2 = evo.id(2)
assert(evo.alive_all(e1, e2))
evo.destroy(e1, e2)
assert(not evo.alive_any(e1, e2))
evo.destroy(e1, e2)
assert(not evo.alive_any(e1, e2))
end
do
do
local e, f1, f2, f3 = evo.id(4)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(evo.alive(e) and not evo.has_any(e, f1, f2) and evo.has(e, f3))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(evo.alive(e) and not evo.has_any(e, f1, f2) and evo.has(e, f3))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f2, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(evo.alive(e) and not evo.has_any(e, f1, f2) and evo.has(e, f3))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
evo.set(f2, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(evo.alive(e) and not evo.has_any(e, f1, f2) and evo.has(e, f3))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(not evo.alive(e))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f2, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(not evo.alive(e))
end
do
local e, f1, f2, f3 = evo.id(4)
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
evo.set(f2, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
evo.set(e, f1, 42)
evo.set(e, f2, 21)
evo.set(e, f3, 84)
evo.destroy(f1, f2)
assert(not evo.alive(e))
end
end

View File

@@ -243,3 +243,143 @@ do
end
end
end
do
local f1, f2, f3, f4 = evo.id(4)
evo.set(f1, evo.REQUIRES, { f2 })
evo.set(f2, evo.REQUIRES, { f3 })
evo.set(f3, evo.REQUIRES, { f4 })
do
local e1 = evo.builder():set(f1):spawn()
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(evo.has(e1, f3) and evo.get(e1, f3) == true)
assert(evo.has(e1, f4) and evo.get(e1, f4) == true)
local e2 = evo.builder():set(f2):spawn()
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(evo.has(e2, f3) and evo.get(e2, f3) == true)
assert(evo.has(e2, f4) and evo.get(e2, f4) == true)
local e3 = evo.builder():set(f3):spawn()
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
do
local e1 = evo.id()
evo.set(e1, f1)
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(evo.has(e1, f3) and evo.get(e1, f3) == true)
assert(evo.has(e1, f4) and evo.get(e1, f4) == true)
local e2 = evo.id()
evo.set(e2, f2)
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(evo.has(e2, f3) and evo.get(e2, f3) == true)
assert(evo.has(e2, f4) and evo.get(e2, f4) == true)
local e3 = evo.id()
evo.set(e3, f3)
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
evo.remove(f2, evo.REQUIRES)
do
local e1 = evo.builder():set(f1):spawn()
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(not evo.has(e1, f3) and evo.get(e1, f3) == nil)
assert(not evo.has(e1, f4) and evo.get(e1, f4) == nil)
local e2 = evo.builder():set(f2):spawn()
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(not evo.has(e2, f3) and evo.get(e2, f3) == nil)
assert(not evo.has(e2, f4) and evo.get(e2, f4) == nil)
local e3 = evo.builder():set(f3):spawn()
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
do
local e1 = evo.id()
evo.set(e1, f1)
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(not evo.has(e1, f3) and evo.get(e1, f3) == nil)
assert(not evo.has(e1, f4) and evo.get(e1, f4) == nil)
local e2 = evo.id()
evo.set(e2, f2)
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(not evo.has(e2, f3) and evo.get(e2, f3) == nil)
assert(not evo.has(e2, f4) and evo.get(e2, f4) == nil)
local e3 = evo.id()
evo.set(e3, f3)
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
evo.set(f2, evo.REQUIRES, { f4 })
do
local e1 = evo.builder():set(f1):spawn()
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(not evo.has(e1, f3) and evo.get(e1, f3) == nil)
assert(evo.has(e1, f4) and evo.get(e1, f4) == true)
local e2 = evo.builder():set(f2):spawn()
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(not evo.has(e2, f3) and evo.get(e2, f3) == nil)
assert(evo.has(e2, f4) and evo.get(e2, f4) == true)
local e3 = evo.builder():set(f3):spawn()
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
do
local e1 = evo.id()
evo.set(e1, f1)
assert(evo.has(e1, f1) and evo.get(e1, f1) == true)
assert(evo.has(e1, f2) and evo.get(e1, f2) == true)
assert(not evo.has(e1, f3) and evo.get(e1, f3) == nil)
assert(evo.has(e1, f4) and evo.get(e1, f4) == true)
local e2 = evo.id()
evo.set(e2, f2)
assert(not evo.has(e2, f1) and evo.get(e2, f1) == nil)
assert(evo.has(e2, f2) and evo.get(e2, f2) == true)
assert(not evo.has(e2, f3) and evo.get(e2, f3) == nil)
assert(evo.has(e2, f4) and evo.get(e2, f4) == true)
local e3 = evo.id()
evo.set(e3, f3)
assert(not evo.has(e3, f1) and evo.get(e3, f1) == nil)
assert(not evo.has(e3, f2) and evo.get(e3, f2) == nil)
assert(evo.has(e3, f3) and evo.get(e3, f3) == true)
assert(evo.has(e3, f4) and evo.get(e3, f4) == true)
end
end

View File

@@ -127,6 +127,7 @@
unpack: function(id: Id): integer, integer
defer: function(): boolean
depth: function(): integer
commit: function(): boolean
cancel: function(): boolean

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
rockspec_format = "3.0"
package = "evolved.lua"
version = "1.6.0-0"
source = {
url = "git://github.com/BlackMATov/evolved.lua",
tag = "v1.6.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",
}
}