mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-03-22 12:55:31 +07:00
Compare commits
13 Commits
caa8cc5625
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39c0b988b5 | ||
|
|
766f7b92be | ||
|
|
e364aaab37 | ||
|
|
b941baf6bb | ||
|
|
8b77b45421 | ||
|
|
f9943c9fca | ||
|
|
eb853c8392 | ||
|
|
b38594fdfc | ||
|
|
655c0aef07 | ||
|
|
2c4cb179bc | ||
|
|
e49a339f5e | ||
|
|
340feacf55 | ||
|
|
cd1a583682 |
232
README.md
232
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)
|
||||
@@ -64,6 +65,7 @@
|
||||
- [Chunk](#chunk)
|
||||
- [Builder](#builder)
|
||||
- [Changelog](#changelog)
|
||||
- [v1.10.0](#v1100)
|
||||
- [v1.9.0](#v190)
|
||||
- [v1.8.0](#v180)
|
||||
- [v1.7.0](#v170)
|
||||
@@ -489,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
|
||||
@@ -497,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
|
||||
```
|
||||
|
||||
@@ -527,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:
|
||||
@@ -981,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
|
||||
|
||||
@@ -1463,9 +1532,13 @@ cancel :: boolean
|
||||
|
||||
spawn :: component_table?, component_mapper? -> entity
|
||||
multi_spawn :: integer, component_table?, component_mapper? -> entity[], integer
|
||||
multi_spawn_nr :: integer, component_table?, component_mapper? -> ()
|
||||
multi_spawn_to :: entity[], integer, integer, component_table?, component_mapper? -> ()
|
||||
|
||||
clone :: entity, component_table?, component_mapper? -> entity
|
||||
multi_clone :: integer, entity, component_table?, component_mapper? -> entity[], integer
|
||||
multi_clone_nr :: integer, entity, component_table?, component_mapper? -> ()
|
||||
multi_clone_to :: entity[], integer, integer, entity, component_table?, component_mapper? -> ()
|
||||
|
||||
alive :: entity -> boolean
|
||||
alive_all :: entity... -> boolean
|
||||
@@ -1496,6 +1569,10 @@ execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_sta
|
||||
|
||||
locate :: entity -> chunk?, integer
|
||||
|
||||
lookup :: string -> entity?
|
||||
multi_lookup :: string -> entity[], integer
|
||||
multi_lookup_to :: entity[], integer, string -> integer
|
||||
|
||||
process :: system... -> ()
|
||||
process_with :: system, ... -> ()
|
||||
|
||||
@@ -1529,12 +1606,18 @@ builder :: builder
|
||||
|
||||
builder_mt:build :: entity?, component_mapper? -> entity
|
||||
builder_mt:multi_build :: integer, entity?, component_mapper? -> entity[], integer
|
||||
builder_mt:multi_build_nr :: integer, entity?, component_mapper? -> ()
|
||||
builder_mt:multi_build_to :: entity[], integer, integer, entity?, component_mapper? -> ()
|
||||
|
||||
builder_mt:spawn :: component_mapper? -> entity
|
||||
builder_mt:multi_spawn :: integer, component_mapper? -> entity[], integer
|
||||
builder_mt:multi_spawn_nr :: integer, component_mapper? -> ()
|
||||
builder_mt:multi_spawn_to :: entity[], integer, integer, component_mapper? -> ()
|
||||
|
||||
builder_mt:clone :: entity, component_mapper? -> entity
|
||||
builder_mt:multi_clone :: integer, entity, component_mapper? -> entity[], integer
|
||||
builder_mt:multi_clone_nr :: integer, entity, component_mapper? -> ()
|
||||
builder_mt:multi_clone_to :: entity[], integer, integer, entity, component_mapper? -> ()
|
||||
|
||||
builder_mt:has :: fragment -> boolean
|
||||
builder_mt:has_all :: fragment... -> boolean
|
||||
@@ -1585,6 +1668,12 @@ builder_mt:destruction_policy :: id -> builder
|
||||
|
||||
## Changelog
|
||||
|
||||
### 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
|
||||
|
||||
- Performance improvements of the [`evolved.destroy`](#evolveddestroy) and [`evolved.batch_destroy`](#evolvedbatch_destroy) functions
|
||||
@@ -1790,9 +1879,31 @@ function evolved.spawn(component_table, component_mapper) end
|
||||
---@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
|
||||
```
|
||||
|
||||
### `evolved.multi_spawn_nr`
|
||||
|
||||
```lua
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.multi_spawn_nr(entity_count, component_table, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.multi_spawn_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.multi_spawn_to(out_entity_list, out_entity_first,
|
||||
entity_count, component_table, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.clone`
|
||||
|
||||
```lua
|
||||
@@ -1812,9 +1923,33 @@ function evolved.clone(prefab, component_table, component_mapper) end
|
||||
---@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
|
||||
```
|
||||
|
||||
### `evolved.multi_clone_nr`
|
||||
|
||||
```lua
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.multi_clone_nr(entity_count, prefab, component_table, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.multi_clone_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.multi_clone_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_table, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.alive`
|
||||
|
||||
```lua
|
||||
@@ -2001,6 +2136,35 @@ function evolved.execute(query) end
|
||||
function evolved.locate(entity) end
|
||||
```
|
||||
|
||||
### `evolved.lookup`
|
||||
|
||||
```lua
|
||||
---@param name string
|
||||
---@return evolved.entity? entity
|
||||
---@nodiscard
|
||||
function evolved.lookup(name) end
|
||||
```
|
||||
|
||||
### `evolved.multi_lookup`
|
||||
|
||||
```lua
|
||||
---@param name string
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.multi_lookup(name) end
|
||||
```
|
||||
|
||||
### `evolved.multi_lookup_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param name string
|
||||
---@return integer entity_count
|
||||
function evolved.multi_lookup_to(out_entity_list, out_entity_first, name) end
|
||||
```
|
||||
|
||||
### `evolved.process`
|
||||
|
||||
```lua
|
||||
@@ -2143,9 +2307,31 @@ function evolved.builder_mt:build(prefab, component_mapper) end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.builder_mt:multi_build(entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.builder_mt:multi_build_nr`
|
||||
|
||||
```lua
|
||||
---@param entity_count integer
|
||||
---@param prefab? evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_build_nr(entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
### `evolved.builder_mt:multi_build_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab? evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_build_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:spawn`
|
||||
|
||||
```lua
|
||||
@@ -2161,9 +2347,29 @@ function evolved.builder_mt:spawn(component_mapper) end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.builder_mt:multi_spawn(entity_count, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:multi_spawn_nr`
|
||||
|
||||
```lua
|
||||
---@param entity_count integer
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_spawn_nr(entity_count, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:multi_spawn_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_spawn_to(out_entity_list, out_entity_first,
|
||||
entity_count, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:clone`
|
||||
|
||||
```lua
|
||||
@@ -2181,9 +2387,31 @@ function evolved.builder_mt:clone(prefab, component_mapper) end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function evolved.builder_mt:multi_clone(entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:multi_clone_nr`
|
||||
|
||||
```lua
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_clone_nr(entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:multi_clone_to`
|
||||
|
||||
```lua
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function evolved.builder_mt:multi_clone_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_mapper) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:has`
|
||||
|
||||
```lua
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'develop.testing.clone_tests'
|
||||
require 'develop.testing.depth_tests'
|
||||
require 'develop.testing.destroy_tests'
|
||||
require 'develop.testing.locate_tests'
|
||||
require 'develop.testing.lookup_tests'
|
||||
require 'develop.testing.main_tests'
|
||||
require 'develop.testing.mappers_tests'
|
||||
require 'develop.testing.multi_spawn_tests'
|
||||
|
||||
@@ -307,11 +307,11 @@ print '----------------------------------------'
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -319,12 +319,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -333,11 +333,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [D1] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -345,11 +345,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -357,12 +357,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -371,11 +371,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [D1] = true, [D2] = true, [D3] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -383,11 +383,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -395,12 +395,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -409,11 +409,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [D1] = true, [D2] = true, [D3] = true, [D4] = true, [D5] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -423,11 +423,11 @@ print '----------------------------------------'
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF1] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -435,12 +435,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF1] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -449,11 +449,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RD1] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -461,11 +461,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF123] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -473,12 +473,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF123] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -487,11 +487,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RD123] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -499,11 +499,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF12345] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -511,12 +511,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Defer Clone | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RF12345] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -525,11 +525,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Clone Benchmarks: Multi Clone With Defaults | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_clone = evo.multi_clone
|
||||
local multi_clone_nr = evo.multi_clone_nr
|
||||
|
||||
local prefab = evo.spawn { [RD12345] = true }
|
||||
|
||||
multi_clone(N, prefab)
|
||||
multi_clone_nr(N, prefab)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
|
||||
@@ -54,7 +54,7 @@ basics.describe_bench(string.format('Common Benchmarks: Evolved Entity Cycle | %
|
||||
local prefab_a = evo.builder():prefab():set(world):set(a, 0):spawn()
|
||||
local prefab_b = evo.builder():prefab():set(world):set(b, 0):spawn()
|
||||
|
||||
evo.multi_clone(N, prefab_a)
|
||||
evo.multi_clone_nr(N, prefab_a)
|
||||
|
||||
evo.builder()
|
||||
:set(world):group(world):query(query_a)
|
||||
@@ -129,10 +129,10 @@ basics.describe_bench(string.format('Common Benchmarks: Evolved Simple Iteration
|
||||
local query_cd = evo.builder():set(world):include(c, d):spawn()
|
||||
local query_ce = evo.builder():set(world):include(c, e):spawn()
|
||||
|
||||
evo.multi_spawn(N, { [world] = true, [a] = 0, [b] = 0 })
|
||||
evo.multi_spawn(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0 })
|
||||
evo.multi_spawn(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [d] = 0 })
|
||||
evo.multi_spawn(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [e] = 0 })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [a] = 0, [b] = 0 })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0 })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [d] = 0 })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [e] = 0 })
|
||||
|
||||
evo.builder()
|
||||
:set(world):group(world):query(query_ab)
|
||||
@@ -223,7 +223,7 @@ basics.describe_bench(string.format('Common Benchmarks: Evolved Packed Iteration
|
||||
local query_d = evo.builder():set(world):include(d):spawn()
|
||||
local query_e = evo.builder():set(world):include(e):spawn()
|
||||
|
||||
evo.multi_spawn(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [d] = 0, [e] = 0 })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [a] = 0, [b] = 0, [c] = 0, [d] = 0, [e] = 0 })
|
||||
|
||||
evo.builder()
|
||||
:set(world):group(world):query(query_a)
|
||||
@@ -317,7 +317,7 @@ basics.describe_bench(string.format('Common Benchmarks: Evolved Fragmented Itera
|
||||
local query_z = evo.builder():set(world):include(chars[#chars]):spawn()
|
||||
|
||||
for i = 1, #chars do
|
||||
evo.multi_spawn(N, { [world] = true, [chars[i]] = i, [data] = i })
|
||||
evo.multi_spawn_nr(N, { [world] = true, [chars[i]] = i, [data] = i })
|
||||
end
|
||||
|
||||
evo.builder()
|
||||
|
||||
@@ -20,7 +20,7 @@ basics.describe_bench(string.format('Process Benchmarks: Evolved AoS Processing
|
||||
local pf = evo.builder():set(wf):spawn()
|
||||
local vf = evo.builder():set(wf):spawn()
|
||||
|
||||
evo.multi_spawn(N, {
|
||||
evo.multi_spawn_nr(N, {
|
||||
[wf] = true,
|
||||
[pf] = { x = 0, y = 0, z = 0, w = 0 },
|
||||
[vf] = { x = 0, y = 0, z = 0, w = 0 },
|
||||
@@ -67,7 +67,7 @@ basics.describe_bench(string.format('Process Benchmarks: Evolved SoA Processing
|
||||
local vzf = evo.builder():set(wf):spawn()
|
||||
local vwf = evo.builder():set(wf):spawn()
|
||||
|
||||
evo.multi_spawn(N, {
|
||||
evo.multi_spawn_nr(N, {
|
||||
[wf] = true,
|
||||
[pxf] = 0,
|
||||
[pyf] = 0,
|
||||
|
||||
@@ -536,11 +536,11 @@ print '----------------------------------------'
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -548,12 +548,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -562,11 +562,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 1 component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [D1] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -574,11 +574,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -586,12 +586,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -600,11 +600,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 3 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [D1] = true, [D2] = true, [D3] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -612,11 +612,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -624,12 +624,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true, [F2] = true, [F3] = true, [F4] = true, [F5] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -638,11 +638,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 5 components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [D1] = true, [D2] = true, [D3] = true, [D4] = true, [D5] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -652,11 +652,11 @@ print '----------------------------------------'
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -664,12 +664,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [F1] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -678,11 +678,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 1 required component', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [D1] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -690,11 +690,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RF123] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -702,12 +702,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RF123] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -716,11 +716,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 3 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RD123] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
@@ -728,11 +728,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RF12345] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
end)
|
||||
@@ -740,12 +740,12 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Defer Spawn | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RF12345] = true }
|
||||
|
||||
evo.defer()
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
evo.commit()
|
||||
|
||||
evo.batch_destroy(QF1)
|
||||
@@ -754,11 +754,11 @@ basics.describe_bench(
|
||||
basics.describe_bench(
|
||||
string.format('Spawn Benchmarks: Multi Spawn With Defaults | %d entities with 5 required components', N),
|
||||
function()
|
||||
local multi_spawn = evo.multi_spawn
|
||||
local multi_spawn_nr = evo.multi_spawn_nr
|
||||
|
||||
local components = { [RD12345] = true }
|
||||
|
||||
multi_spawn(N, components)
|
||||
multi_spawn_nr(N, components)
|
||||
|
||||
evo.batch_destroy(QD1)
|
||||
end)
|
||||
|
||||
@@ -397,3 +397,165 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.multi_clone_to(entity_list, 1, entity_count, p)
|
||||
assert(evo.has_all(entity_list[1], f1, f2))
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello')
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.multi_clone_to(entity_list, 2, entity_count, p)
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.has_all(entity_list[3], f1, f2))
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
|
||||
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello')
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.defer()
|
||||
evo.multi_clone_to(entity_list, 1, entity_count, p)
|
||||
assert(entity_list[1] and entity_list[2])
|
||||
assert(evo.empty_all(entity_list[1], entity_list[2]))
|
||||
evo.commit()
|
||||
assert(evo.has_all(entity_list[1], f1, f2))
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello')
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.defer()
|
||||
evo.multi_clone_to(entity_list, 2, entity_count, p)
|
||||
assert(entity_list[2] and entity_list[3])
|
||||
assert(evo.empty_all(entity_list[2], entity_list[3]))
|
||||
evo.commit()
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.has_all(entity_list[3], f1, f2))
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
|
||||
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello')
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
local q12 = evo.builder():include(f1, f2):build()
|
||||
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
|
||||
|
||||
do
|
||||
assert(select('#', evo.multi_clone_nr(2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 3)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, 'hello')
|
||||
|
||||
assert(select('#', b:multi_clone_nr(2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 5)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, 'hello')
|
||||
|
||||
assert(select('#', b:multi_build_nr(2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 7)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
local q12 = evo.builder():include(f1, f2):build()
|
||||
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
|
||||
|
||||
do
|
||||
local entity_list = {}
|
||||
assert(select('#', evo.multi_clone_to(entity_list, 1, 2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 3)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, 'hello')
|
||||
|
||||
local entity_list = {}
|
||||
assert(select('#', b:multi_clone_to(entity_list, 1, 2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 5)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, 'hello')
|
||||
|
||||
local entity_list = {}
|
||||
assert(select('#', b:multi_build_to(entity_list, 1, 2, p)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 7)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
195
develop/testing/lookup_tests.lua
Normal file
195
develop/testing/lookup_tests.lua
Normal file
@@ -0,0 +1,195 @@
|
||||
local evo = require 'evolved'
|
||||
|
||||
evo.debug_mode(true)
|
||||
|
||||
do
|
||||
local e1, e2, e3 = evo.id(3)
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == nil)
|
||||
assert(evo.lookup('lookup_world') == nil)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_world')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
end
|
||||
|
||||
evo.set(e1, evo.NAME, 'lookup_hello')
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == e1)
|
||||
assert(evo.lookup('lookup_world') == nil)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 1 and entity_count == 1)
|
||||
assert(entity_list[1] == e1)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_world')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
end
|
||||
|
||||
evo.set(e2, evo.NAME, 'lookup_hello')
|
||||
evo.set(e3, evo.NAME, 'lookup_hello')
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == e1)
|
||||
assert(evo.lookup('lookup_world') == nil)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 3 and entity_count == 3)
|
||||
assert(entity_list[1] == e1 and entity_list[2] == e2 and entity_list[3] == e3)
|
||||
end
|
||||
end
|
||||
|
||||
evo.set(e2, evo.NAME, 'lookup_world')
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == e1)
|
||||
assert(evo.lookup('lookup_world') == e2)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 2 and entity_count == 2)
|
||||
assert(entity_list[1] == e1 and entity_list[2] == e3)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_world')
|
||||
assert(entity_list and #entity_list == 1 and entity_count == 1)
|
||||
assert(entity_list[1] == e2)
|
||||
end
|
||||
end
|
||||
|
||||
evo.set(e3, evo.NAME, 'lookup_world')
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == e1)
|
||||
assert(evo.lookup('lookup_world') == e2)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 1 and entity_count == 1)
|
||||
assert(entity_list[1] == e1)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_world')
|
||||
assert(entity_list and #entity_list == 2 and entity_count == 2)
|
||||
assert(entity_list[1] == e2 or entity_list[1] == e3)
|
||||
end
|
||||
end
|
||||
|
||||
evo.remove(e1, evo.NAME)
|
||||
|
||||
do
|
||||
assert(evo.lookup('lookup_hello') == nil)
|
||||
assert(evo.lookup('lookup_world') == e2)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_hello')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_world')
|
||||
assert(entity_list and #entity_list == 2 and entity_count == 2)
|
||||
assert(entity_list[1] == e2 or entity_list[1] == e3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local e1, e2, e3 = evo.id(3)
|
||||
|
||||
evo.set(e1, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 1 and entity_count == 1)
|
||||
assert(entity_list[1] == e1)
|
||||
end
|
||||
|
||||
evo.set(e2, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 2 and entity_count == 2)
|
||||
assert(entity_list[1] == e1 and entity_list[2] == e2)
|
||||
end
|
||||
|
||||
evo.set(e3, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 3 and entity_count == 3)
|
||||
assert(entity_list[1] == e1 and entity_list[2] == e2 and entity_list[3] == e3)
|
||||
end
|
||||
|
||||
evo.clear(e1, e2, e3)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
|
||||
evo.set(e3, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 1 and entity_count == 1)
|
||||
assert(entity_list[1] == e3)
|
||||
end
|
||||
|
||||
evo.set(e2, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 2 and entity_count == 2)
|
||||
assert(entity_list[1] == e3 and entity_list[2] == e2)
|
||||
end
|
||||
|
||||
evo.set(e1, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 3 and entity_count == 3)
|
||||
assert(entity_list[1] == e3 and entity_list[2] == e2 and entity_list[3] == e1)
|
||||
end
|
||||
|
||||
evo.destroy(e3, e2, e1)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = evo.multi_lookup('lookup_e')
|
||||
assert(entity_list and #entity_list == 0 and entity_count == 0)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local e1, e2 = evo.id(2)
|
||||
|
||||
evo.set(e1, evo.NAME, 'lookup_e')
|
||||
evo.set(e2, evo.NAME, 'lookup_e')
|
||||
|
||||
do
|
||||
local entity_list = {}
|
||||
local entity_count = evo.multi_lookup_to(entity_list, 1, 'lookup_e')
|
||||
assert(entity_count == 2 and entity_list[1] == e1 and entity_list[2] == e2)
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list = {}
|
||||
local entity_count = evo.multi_lookup_to(entity_list, 2, 'lookup_e')
|
||||
assert(entity_count == 2 and entity_list[2] == e1 and entity_list[3] == e2)
|
||||
end
|
||||
end
|
||||
@@ -607,3 +607,164 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" })
|
||||
assert(evo.has_all(entity_list[1], f1, f2))
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello")
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" })
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.has_all(entity_list[3], f1, f2))
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
|
||||
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello")
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.defer()
|
||||
evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" })
|
||||
assert(entity_list[1] and entity_list[2])
|
||||
assert(evo.empty_all(entity_list[1], entity_list[2]))
|
||||
evo.commit()
|
||||
assert(evo.has_all(entity_list[1], f1, f2))
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello")
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
|
||||
end
|
||||
|
||||
do
|
||||
local entity_list, entity_count = {}, 2
|
||||
evo.defer()
|
||||
evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" })
|
||||
assert(entity_list[2] and entity_list[3])
|
||||
assert(evo.empty_all(entity_list[2], entity_list[3]))
|
||||
evo.commit()
|
||||
assert(evo.has_all(entity_list[2], f1, f2))
|
||||
assert(evo.has_all(entity_list[3], f1, f2))
|
||||
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
|
||||
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello")
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
local q12 = evo.builder():include(f1, f2):spawn()
|
||||
|
||||
do
|
||||
assert(select('#', evo.multi_spawn_nr(2, { [f1] = 42, [f2] = "hello" })) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 2)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, "hello")
|
||||
|
||||
assert(select('#', b:multi_spawn_nr(2)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 4)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, "hello")
|
||||
|
||||
assert(select('#', b:multi_build_nr(2)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 6)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
local q12 = evo.builder():include(f1, f2):spawn()
|
||||
|
||||
do
|
||||
local entity_list = {}
|
||||
assert(select('#', evo.multi_spawn_to(entity_list, 1, 2, { [f1] = 42, [f2] = "hello" })) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 2)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, "hello")
|
||||
|
||||
|
||||
local entity_list = {}
|
||||
assert(select('#', b:multi_spawn_to(entity_list, 1, 2)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 4)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local b = evo.builder():set(f1, 42):set(f2, "hello")
|
||||
|
||||
|
||||
local entity_list = {}
|
||||
assert(select('#', b:multi_build_to(entity_list, 1, 2)) == 0)
|
||||
|
||||
do
|
||||
local entity_count = 0
|
||||
|
||||
for chunk in evo.execute(q12) do
|
||||
local _, chunk_entity_count = chunk:entities()
|
||||
entity_count = entity_count + chunk_entity_count
|
||||
end
|
||||
|
||||
assert(entity_count == 6)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
64
evolved.d.tl
64
evolved.d.tl
@@ -40,6 +40,18 @@
|
||||
prefab?: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer)): { Entity }, integer
|
||||
|
||||
multi_build_nr: function(self: Builder,
|
||||
entity_count: integer,
|
||||
prefab?: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
multi_build_to: function(self: Builder,
|
||||
out_entity_list: { Entity },
|
||||
out_entity_first: integer,
|
||||
entity_count: integer,
|
||||
prefab?: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
spawn: function(self: Builder,
|
||||
component_mapper?: function(Chunk, integer)): Entity
|
||||
|
||||
@@ -47,6 +59,16 @@
|
||||
entity_count: integer,
|
||||
component_mapper?: function(Chunk, integer, integer)): { Entity }, integer
|
||||
|
||||
multi_spawn_nr: function(self: Builder,
|
||||
entity_count: integer,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
multi_spawn_to: function(self: Builder,
|
||||
out_entity_list: { Entity },
|
||||
out_entity_first: integer,
|
||||
entity_count: integer,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
clone: function(self: Builder,
|
||||
prefab: Entity,
|
||||
component_mapper?: function(Chunk, integer)): Entity
|
||||
@@ -56,6 +78,18 @@
|
||||
prefab: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer)): { Entity }, integer
|
||||
|
||||
multi_clone_nr: function(self: Builder,
|
||||
entity_count: integer,
|
||||
prefab: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
multi_clone_to: function(self: Builder,
|
||||
out_entity_list: { Entity },
|
||||
out_entity_first: integer,
|
||||
entity_count: integer,
|
||||
prefab: Entity,
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
has: function(self: Builder, fragment: Fragment): boolean
|
||||
has_all: function(self: Builder, ...: Fragment): boolean
|
||||
has_any: function(self: Builder, ...: Fragment): boolean
|
||||
@@ -164,6 +198,18 @@
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer)): { Entity }, integer
|
||||
|
||||
multi_spawn_nr: function(
|
||||
entity_count: integer,
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
multi_spawn_to: function(
|
||||
out_entity_list: { Entity },
|
||||
out_entity_first: integer,
|
||||
entity_count: integer,
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
clone: function(
|
||||
prefab: Entity,
|
||||
component_table?: { Fragment: any },
|
||||
@@ -175,6 +221,20 @@
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer)): { Entity }, integer
|
||||
|
||||
multi_clone_nr: function(
|
||||
entity_count: integer,
|
||||
prefab: Entity,
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
multi_clone_to: function(
|
||||
out_entity_list: { Entity },
|
||||
out_entity_first: integer,
|
||||
entity_count: integer,
|
||||
prefab: Entity,
|
||||
component_table?: { Fragment: any },
|
||||
component_mapper?: function(Chunk, integer, integer))
|
||||
|
||||
alive: function(entity: Entity): boolean
|
||||
alive_all: function(...: Entity): boolean
|
||||
alive_any: function(...: Entity): boolean
|
||||
@@ -208,6 +268,10 @@
|
||||
|
||||
locate: function(entity: Entity): Chunk | nil, integer
|
||||
|
||||
lookup: function(name: string): Entity | nil
|
||||
multi_lookup: function(name: string): { Entity }, integer
|
||||
multi_lookup_to: function(out_entity_list: { Entity }, out_entity_first: integer, name: string): integer
|
||||
|
||||
process: function(...: System)
|
||||
process_with: function(system: System, ...: any)
|
||||
|
||||
|
||||
499
evolved.lua
499
evolved.lua
@@ -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
|
||||
|
||||
@@ -144,6 +144,9 @@ local __major_queries = {} ---@type table<evolved.fragment, evolved.assoc_list<e
|
||||
local __entity_chunks = {} ---@type (evolved.chunk|false)[]
|
||||
local __entity_places = {} ---@type integer[]
|
||||
|
||||
local __named_entity = {} ---@type table<string, evolved.entity>
|
||||
local __named_entities = {} ---@type table<string, evolved.assoc_list<evolved.entity>>
|
||||
|
||||
local __sorted_includes = {} ---@type table<evolved.query, evolved.assoc_list<evolved.fragment>>
|
||||
local __sorted_excludes = {} ---@type table<evolved.query, evolved.assoc_list<evolved.fragment>>
|
||||
local __sorted_variants = {} ---@type table<evolved.query, evolved.assoc_list<evolved.fragment>>
|
||||
@@ -896,6 +899,22 @@ function __assoc_list_fns.new(reserve)
|
||||
}
|
||||
end
|
||||
|
||||
---@generic K
|
||||
---@param ... K
|
||||
---@return evolved.assoc_list<K>
|
||||
---@nodiscard
|
||||
function __assoc_list_fns.from(...)
|
||||
local item_count = __lua_select('#', ...)
|
||||
|
||||
local al = __assoc_list_fns.new(item_count)
|
||||
|
||||
for item_index = 1, item_count do
|
||||
__assoc_list_fns.insert(al, __lua_select(item_index, ...))
|
||||
end
|
||||
|
||||
return al
|
||||
end
|
||||
|
||||
---@generic K
|
||||
---@param src_item_list K[]
|
||||
---@param src_item_first integer
|
||||
@@ -1039,6 +1058,46 @@ function __assoc_list_fns.remove_ex(al_item_set, al_item_list, al_item_count, it
|
||||
return al_item_count
|
||||
end
|
||||
|
||||
---@generic K
|
||||
---@param al evolved.assoc_list<K>
|
||||
---@param item K
|
||||
---@return integer new_al_count
|
||||
function __assoc_list_fns.unordered_remove(al, item)
|
||||
local new_al_count = __assoc_list_fns.unordered_remove_ex(
|
||||
al.__item_set, al.__item_list, al.__item_count,
|
||||
item)
|
||||
|
||||
al.__item_count = new_al_count
|
||||
return new_al_count
|
||||
end
|
||||
|
||||
---@generic K
|
||||
---@param al_item_set table<K, integer>
|
||||
---@param al_item_list K[]
|
||||
---@param al_item_count integer
|
||||
---@param item K
|
||||
---@return integer new_al_count
|
||||
---@nodiscard
|
||||
function __assoc_list_fns.unordered_remove_ex(al_item_set, al_item_list, al_item_count, item)
|
||||
local item_index = al_item_set[item]
|
||||
|
||||
if not item_index then
|
||||
return al_item_count
|
||||
end
|
||||
|
||||
if item_index ~= al_item_count then
|
||||
local al_last_item = al_item_list[al_item_count]
|
||||
al_item_set[al_last_item] = item_index
|
||||
al_item_list[item_index] = al_last_item
|
||||
end
|
||||
|
||||
al_item_set[item] = nil
|
||||
al_item_list[al_item_count] = nil
|
||||
al_item_count = al_item_count - 1
|
||||
|
||||
return al_item_count
|
||||
end
|
||||
|
||||
---
|
||||
---
|
||||
---
|
||||
@@ -1120,9 +1179,13 @@ local __evolved_cancel
|
||||
|
||||
local __evolved_spawn
|
||||
local __evolved_multi_spawn
|
||||
local __evolved_multi_spawn_nr
|
||||
local __evolved_multi_spawn_to
|
||||
|
||||
local __evolved_clone
|
||||
local __evolved_multi_clone
|
||||
local __evolved_multi_clone_nr
|
||||
local __evolved_multi_clone_to
|
||||
|
||||
local __evolved_alive
|
||||
local __evolved_alive_all
|
||||
@@ -1155,6 +1218,10 @@ local __evolved_execute
|
||||
|
||||
local __evolved_locate
|
||||
|
||||
local __evolved_lookup
|
||||
local __evolved_multi_lookup
|
||||
local __evolved_multi_lookup_to
|
||||
|
||||
local __evolved_process
|
||||
local __evolved_process_with
|
||||
|
||||
@@ -2614,10 +2681,11 @@ end
|
||||
|
||||
---@param chunk? evolved.chunk
|
||||
---@param entity_list evolved.entity[]
|
||||
---@param entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __multi_spawn_entity(chunk, entity_list, entity_count, component_table, component_mapper)
|
||||
function __multi_spawn_entity(chunk, entity_list, entity_first, entity_count, component_table, component_mapper)
|
||||
if __defer_depth <= 0 then
|
||||
__error_fmt('spawn entity operations should be deferred')
|
||||
end
|
||||
@@ -2665,7 +2733,7 @@ function __multi_spawn_entity(chunk, entity_list, entity_count, component_table,
|
||||
local entity_places = __entity_places
|
||||
|
||||
for place = b_place, e_place do
|
||||
local entity = entity_list[place - b_place + 1]
|
||||
local entity = entity_list[place - b_place + entity_first]
|
||||
chunk_entity_list[place] = entity
|
||||
|
||||
local entity_primary = entity % 2 ^ 20
|
||||
@@ -2913,10 +2981,11 @@ end
|
||||
|
||||
---@param prefab evolved.entity
|
||||
---@param entity_list evolved.entity[]
|
||||
---@param entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
function __multi_clone_entity(prefab, entity_list, entity_first, entity_count, component_table, component_mapper)
|
||||
if __defer_depth <= 0 then
|
||||
__error_fmt('clone entity operations should be deferred')
|
||||
end
|
||||
@@ -2932,7 +3001,9 @@ function __multi_clone_entity(prefab, entity_list, entity_count, component_table
|
||||
end
|
||||
|
||||
if not prefab_chunk or not prefab_chunk.__without_unique_fragments then
|
||||
return __multi_spawn_entity(nil, entity_list, entity_count, component_table, component_mapper)
|
||||
return __multi_spawn_entity(nil,
|
||||
entity_list, entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
end
|
||||
|
||||
local chunk = component_table
|
||||
@@ -2981,7 +3052,7 @@ function __multi_clone_entity(prefab, entity_list, entity_count, component_table
|
||||
local entity_places = __entity_places
|
||||
|
||||
for place = b_place, e_place do
|
||||
local entity = entity_list[place - b_place + 1]
|
||||
local entity = entity_list[place - b_place + entity_first]
|
||||
chunk_entity_list[place] = entity
|
||||
|
||||
local entity_primary = entity % 2 ^ 20
|
||||
@@ -4312,10 +4383,10 @@ function __defer_spawn_entity(chunk, entity, component_table, component_mapper)
|
||||
end
|
||||
|
||||
__defer_ops[__defer_op.spawn_entity] = function(bytes, index)
|
||||
local chunk = bytes[index + 0]
|
||||
local entity = bytes[index + 1]
|
||||
local component_table2 = bytes[index + 2]
|
||||
local component_mapper = bytes[index + 3]
|
||||
local chunk = bytes[index + 0] ---@type evolved.chunk
|
||||
local entity = bytes[index + 1] ---@type evolved.entity
|
||||
local component_table2 = bytes[index + 2] ---@type evolved.component_table?
|
||||
local component_mapper = bytes[index + 3] ---@type evolved.component_mapper?
|
||||
|
||||
__evolved_defer()
|
||||
do
|
||||
@@ -4332,15 +4403,16 @@ end
|
||||
|
||||
---@param chunk? evolved.chunk
|
||||
---@param entity_list evolved.entity[]
|
||||
---@param entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __defer_multi_spawn_entity(chunk, entity_list, entity_count, component_table, component_mapper)
|
||||
function __defer_multi_spawn_entity(chunk, entity_list, entity_first, entity_count, component_table, component_mapper)
|
||||
---@type evolved.entity[]
|
||||
local entity_list2 = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
__lua_table_move(
|
||||
entity_list, 1, entity_count,
|
||||
entity_list, entity_first, entity_first + entity_count - 1,
|
||||
1, entity_list2)
|
||||
|
||||
---@type evolved.component_table?
|
||||
@@ -4368,15 +4440,17 @@ function __defer_multi_spawn_entity(chunk, entity_list, entity_count, component_
|
||||
end
|
||||
|
||||
__defer_ops[__defer_op.multi_spawn_entity] = function(bytes, index)
|
||||
local chunk = bytes[index + 0]
|
||||
local entity_count = bytes[index + 1]
|
||||
local entity_list2 = bytes[index + 2]
|
||||
local component_table2 = bytes[index + 3]
|
||||
local component_mapper = bytes[index + 4]
|
||||
local chunk = bytes[index + 0] ---@type evolved.chunk
|
||||
local entity_count = bytes[index + 1] ---@type integer
|
||||
local entity_list2 = bytes[index + 2] ---@type evolved.entity[]
|
||||
local component_table2 = bytes[index + 3] ---@type evolved.component_table?
|
||||
local component_mapper = bytes[index + 4] ---@type evolved.component_mapper?
|
||||
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_spawn_entity(chunk, entity_list2, entity_count, component_table2, component_mapper)
|
||||
__multi_spawn_entity(chunk,
|
||||
entity_list2, 1, entity_count,
|
||||
component_table2, component_mapper)
|
||||
|
||||
if entity_list2 then
|
||||
__release_table(__table_pool_tag.entity_list, entity_list2, false, true)
|
||||
@@ -4420,10 +4494,10 @@ function __defer_clone_entity(prefab, entity, component_table, component_mapper)
|
||||
end
|
||||
|
||||
__defer_ops[__defer_op.clone_entity] = function(bytes, index)
|
||||
local prefab = bytes[index + 0]
|
||||
local entity = bytes[index + 1]
|
||||
local component_table2 = bytes[index + 2]
|
||||
local component_mapper = bytes[index + 3]
|
||||
local prefab = bytes[index + 0] ---@type evolved.entity
|
||||
local entity = bytes[index + 1] ---@type evolved.entity
|
||||
local component_table2 = bytes[index + 2] ---@type evolved.component_table?
|
||||
local component_mapper = bytes[index + 3] ---@type evolved.component_mapper?
|
||||
|
||||
__evolved_defer()
|
||||
do
|
||||
@@ -4440,15 +4514,16 @@ end
|
||||
|
||||
---@param prefab evolved.entity
|
||||
---@param entity_list evolved.entity[]
|
||||
---@param entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __defer_multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
function __defer_multi_clone_entity(prefab, entity_list, entity_first, entity_count, component_table, component_mapper)
|
||||
---@type evolved.entity[]
|
||||
local entity_list2 = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
__lua_table_move(
|
||||
entity_list, 1, entity_count,
|
||||
entity_list, entity_first, entity_first + entity_count - 1,
|
||||
1, entity_list2)
|
||||
|
||||
---@type evolved.component_table?
|
||||
@@ -4476,15 +4551,17 @@ function __defer_multi_clone_entity(prefab, entity_list, entity_count, component
|
||||
end
|
||||
|
||||
__defer_ops[__defer_op.multi_clone_entity] = function(bytes, index)
|
||||
local prefab = bytes[index + 0]
|
||||
local entity_count = bytes[index + 1]
|
||||
local entity_list2 = bytes[index + 2]
|
||||
local component_table2 = bytes[index + 3]
|
||||
local component_mapper = bytes[index + 4]
|
||||
local prefab = bytes[index + 0] ---@type evolved.entity
|
||||
local entity_count = bytes[index + 1] ---@type integer
|
||||
local entity_list2 = bytes[index + 2] ---@type evolved.entity[]
|
||||
local component_table2 = bytes[index + 3] ---@type evolved.component_table?
|
||||
local component_mapper = bytes[index + 4] ---@type evolved.component_mapper?
|
||||
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_clone_entity(prefab, entity_list2, entity_count, component_table2, component_mapper)
|
||||
__multi_clone_entity(prefab,
|
||||
entity_list2, 1, entity_count,
|
||||
component_table2, component_mapper)
|
||||
|
||||
if entity_list2 then
|
||||
__release_table(__table_pool_tag.entity_list, entity_list2, false, true)
|
||||
@@ -4855,11 +4932,49 @@ end
|
||||
---@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)
|
||||
if entity_count <= 0 then
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
__evolved_multi_spawn_to(
|
||||
entity_list, 1, entity_count,
|
||||
component_table, component_mapper)
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __evolved_multi_spawn_nr(entity_count, component_table, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local entity_list = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
__evolved_multi_spawn_to(
|
||||
entity_list, 1, entity_count,
|
||||
component_table, component_mapper)
|
||||
|
||||
__release_table(__table_pool_tag.entity_list, entity_list, false, true)
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __evolved_multi_spawn_to(out_entity_list, out_entity_first,
|
||||
entity_count, component_table, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if __debug_mode then
|
||||
if component_table then
|
||||
for fragment in __lua_next, component_table do
|
||||
@@ -4871,27 +4986,27 @@ function __evolved_multi_spawn(entity_count, component_table, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
for entity_index = 1, entity_count do
|
||||
entity_list[entity_index] = __acquire_id()
|
||||
for entity_index = out_entity_first, out_entity_first + entity_count - 1 do
|
||||
out_entity_list[entity_index] = __acquire_id()
|
||||
end
|
||||
|
||||
if not component_table or not __lua_next(component_table) then
|
||||
return entity_list, entity_count
|
||||
return
|
||||
end
|
||||
|
||||
if __defer_depth > 0 then
|
||||
__defer_multi_spawn_entity(nil, entity_list, entity_count, component_table, component_mapper)
|
||||
__defer_multi_spawn_entity(nil,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
else
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_spawn_entity(nil, entity_list, entity_count, component_table, component_mapper)
|
||||
__multi_spawn_entity(nil,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
end
|
||||
__evolved_commit()
|
||||
end
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param prefab evolved.entity
|
||||
@@ -4936,11 +5051,51 @@ end
|
||||
---@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)
|
||||
if entity_count <= 0 then
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
__evolved_multi_clone_to(
|
||||
entity_list, 1, entity_count,
|
||||
prefab, component_table, component_mapper)
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __evolved_multi_clone_nr(entity_count, prefab, component_table, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local entity_list = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
__evolved_multi_clone_to(
|
||||
entity_list, 1, entity_count,
|
||||
prefab, component_table, component_mapper)
|
||||
|
||||
__release_table(__table_pool_tag.entity_list, entity_list, false, true)
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_table? evolved.component_table
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __evolved_multi_clone_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_table, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if __debug_mode then
|
||||
if not __evolved_alive(prefab) then
|
||||
__error_fmt('the prefab (%s) is not alive and cannot be used',
|
||||
@@ -4957,23 +5112,23 @@ function __evolved_multi_clone(entity_count, prefab, component_table, component_
|
||||
end
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
for entity_index = 1, entity_count do
|
||||
entity_list[entity_index] = __acquire_id()
|
||||
for entity_index = out_entity_first, out_entity_first + entity_count - 1 do
|
||||
out_entity_list[entity_index] = __acquire_id()
|
||||
end
|
||||
|
||||
if __defer_depth > 0 then
|
||||
__defer_multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
__defer_multi_clone_entity(prefab,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
else
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
__multi_clone_entity(prefab,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
end
|
||||
__evolved_commit()
|
||||
end
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param entity evolved.entity
|
||||
@@ -6086,6 +6241,53 @@ function __evolved_locate(entity)
|
||||
return entity_chunk, __entity_places[entity_primary]
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@return evolved.entity? entity
|
||||
---@nodiscard
|
||||
function __evolved_lookup(name)
|
||||
return __named_entity[name]
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function __evolved_multi_lookup(name)
|
||||
local entity_list = {}
|
||||
local entity_count = __evolved_multi_lookup_to(entity_list, 1, name)
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param name string
|
||||
---@return integer entity_count
|
||||
function __evolved_multi_lookup_to(out_entity_list, out_entity_first, name)
|
||||
do
|
||||
local named_entities = __named_entities[name]
|
||||
local named_entity_list = named_entities and named_entities.__item_list
|
||||
local named_entity_count = named_entities and named_entities.__item_count or 0
|
||||
|
||||
if named_entity_count > 0 then
|
||||
__lua_table_move(
|
||||
named_entity_list, 1, named_entity_count,
|
||||
out_entity_first, out_entity_list)
|
||||
return named_entity_count
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local named_entity = __named_entity[name]
|
||||
|
||||
if named_entity then
|
||||
out_entity_list[out_entity_first] = named_entity
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
---@param ... evolved.system systems
|
||||
function __evolved_process(...)
|
||||
local argument_count = __lua_select('#', ...)
|
||||
@@ -6431,6 +6633,7 @@ end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function __builder_mt:multi_build(entity_count, prefab, component_mapper)
|
||||
if prefab then
|
||||
return self:multi_clone(entity_count, prefab, component_mapper)
|
||||
@@ -6439,6 +6642,31 @@ function __builder_mt:multi_build(entity_count, prefab, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
---@param entity_count integer
|
||||
---@param prefab? evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_build_nr(entity_count, prefab, component_mapper)
|
||||
if prefab then
|
||||
self:multi_clone_nr(entity_count, prefab, component_mapper)
|
||||
else
|
||||
self:multi_spawn_nr(entity_count, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab? evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_build_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_mapper)
|
||||
if prefab then
|
||||
self:multi_clone_to(out_entity_list, out_entity_first, entity_count, prefab, component_mapper)
|
||||
else
|
||||
self:multi_spawn_to(out_entity_list, out_entity_first, entity_count, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity entity
|
||||
function __builder_mt:spawn(component_mapper)
|
||||
@@ -6479,11 +6707,43 @@ end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function __builder_mt:multi_spawn(entity_count, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
self:multi_spawn_to(entity_list, 1, entity_count, component_mapper)
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param entity_count integer
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_spawn_nr(entity_count, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local entity_list = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
self:multi_spawn_to(entity_list, 1, entity_count, component_mapper)
|
||||
|
||||
__release_table(__table_pool_tag.entity_list, entity_list, false, true)
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_spawn_to(out_entity_list, out_entity_first,
|
||||
entity_count, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local chunk = self.__chunk
|
||||
local component_table = self.__component_table
|
||||
|
||||
@@ -6498,27 +6758,27 @@ function __builder_mt:multi_spawn(entity_count, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
for entity_index = 1, entity_count do
|
||||
entity_list[entity_index] = __acquire_id()
|
||||
for entity_index = out_entity_first, out_entity_first + entity_count - 1 do
|
||||
out_entity_list[entity_index] = __acquire_id()
|
||||
end
|
||||
|
||||
if not component_table or not __lua_next(component_table) then
|
||||
return entity_list, entity_count
|
||||
return
|
||||
end
|
||||
|
||||
if __defer_depth > 0 then
|
||||
__defer_multi_spawn_entity(chunk, entity_list, entity_count, component_table, component_mapper)
|
||||
__defer_multi_spawn_entity(chunk,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
else
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_spawn_entity(chunk, entity_list, entity_count, component_table, component_mapper)
|
||||
__multi_spawn_entity(chunk,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
end
|
||||
__evolved_commit()
|
||||
end
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param prefab evolved.entity
|
||||
@@ -6563,11 +6823,45 @@ end
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
---@return evolved.entity[] entity_list
|
||||
---@return integer entity_count
|
||||
---@nodiscard
|
||||
function __builder_mt:multi_clone(entity_count, prefab, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
self:multi_clone_to(entity_list, 1, entity_count, prefab, component_mapper)
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_clone_nr(entity_count, prefab, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local entity_list = __acquire_table(__table_pool_tag.entity_list)
|
||||
|
||||
self:multi_clone_to(entity_list, 1, entity_count, prefab, component_mapper)
|
||||
|
||||
__release_table(__table_pool_tag.entity_list, entity_list, false, true)
|
||||
end
|
||||
|
||||
---@param out_entity_list evolved.entity[]
|
||||
---@param out_entity_first integer
|
||||
---@param entity_count integer
|
||||
---@param prefab evolved.entity
|
||||
---@param component_mapper? evolved.component_mapper
|
||||
function __builder_mt:multi_clone_to(out_entity_list, out_entity_first,
|
||||
entity_count, prefab, component_mapper)
|
||||
if entity_count <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local component_table = self.__component_table
|
||||
|
||||
if __debug_mode then
|
||||
@@ -6586,23 +6880,23 @@ function __builder_mt:multi_clone(entity_count, prefab, component_mapper)
|
||||
end
|
||||
end
|
||||
|
||||
local entity_list = __lua_table_new(entity_count)
|
||||
|
||||
for entity_index = 1, entity_count do
|
||||
entity_list[entity_index] = __acquire_id()
|
||||
for entity_index = out_entity_first, out_entity_first + entity_count - 1 do
|
||||
out_entity_list[entity_index] = __acquire_id()
|
||||
end
|
||||
|
||||
if __defer_depth > 0 then
|
||||
__defer_multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
__defer_multi_clone_entity(prefab,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
else
|
||||
__evolved_defer()
|
||||
do
|
||||
__multi_clone_entity(prefab, entity_list, entity_count, component_table, component_mapper)
|
||||
__multi_clone_entity(prefab,
|
||||
out_entity_list, out_entity_first, entity_count,
|
||||
component_table, component_mapper)
|
||||
end
|
||||
__evolved_commit()
|
||||
end
|
||||
|
||||
return entity_list, entity_count
|
||||
end
|
||||
|
||||
---@param fragment evolved.fragment
|
||||
@@ -7153,6 +7447,75 @@ __evolved_set(__ON_REMOVE, __UNIQUE)
|
||||
---
|
||||
---
|
||||
|
||||
---@param name string
|
||||
---@param entity evolved.entity
|
||||
local function __insert_named_entity(name, entity)
|
||||
---@type evolved.entity?
|
||||
local named_entity = __named_entity[name]
|
||||
|
||||
if not named_entity then
|
||||
__named_entity[name] = entity
|
||||
return
|
||||
end
|
||||
|
||||
---@type evolved.assoc_list<evolved.entity>?
|
||||
local named_entities = __named_entities[name]
|
||||
|
||||
if not named_entities then
|
||||
__named_entities[name] = __assoc_list_fns.from(named_entity, entity)
|
||||
return
|
||||
end
|
||||
|
||||
__assoc_list_fns.insert(named_entities, entity)
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param entity evolved.entity
|
||||
local function __remove_named_entity(name, entity)
|
||||
---@type evolved.assoc_list<evolved.entity>?
|
||||
local named_entities = __named_entities[name]
|
||||
|
||||
if named_entities then
|
||||
if __assoc_list_fns.remove(named_entities, entity) == 0 then
|
||||
__named_entities[name], named_entities = nil, nil
|
||||
end
|
||||
end
|
||||
|
||||
---@type evolved.entity?
|
||||
local named_entity = __named_entity[name]
|
||||
|
||||
if named_entity == entity then
|
||||
__named_entity[name] = named_entities and named_entities.__item_list[1] or nil
|
||||
end
|
||||
end
|
||||
|
||||
---@param entity evolved.entity
|
||||
---@param new_name? string
|
||||
---@param old_name? string
|
||||
__evolved_set(__NAME, __ON_SET, function(entity, _, new_name, old_name)
|
||||
if old_name then
|
||||
__remove_named_entity(old_name, entity)
|
||||
end
|
||||
|
||||
if new_name then
|
||||
__insert_named_entity(new_name, entity)
|
||||
end
|
||||
end)
|
||||
|
||||
---@param entity evolved.entity
|
||||
---@param old_name? string
|
||||
__evolved_set(__NAME, __ON_REMOVE, function(entity, _, old_name)
|
||||
if old_name then
|
||||
__remove_named_entity(old_name, entity)
|
||||
end
|
||||
end)
|
||||
|
||||
---
|
||||
---
|
||||
---
|
||||
---
|
||||
---
|
||||
|
||||
---@param query evolved.query
|
||||
local function __insert_query(query)
|
||||
local query_includes = __sorted_includes[query]
|
||||
@@ -7491,9 +7854,13 @@ evolved.cancel = __evolved_cancel
|
||||
|
||||
evolved.spawn = __evolved_spawn
|
||||
evolved.multi_spawn = __evolved_multi_spawn
|
||||
evolved.multi_spawn_nr = __evolved_multi_spawn_nr
|
||||
evolved.multi_spawn_to = __evolved_multi_spawn_to
|
||||
|
||||
evolved.clone = __evolved_clone
|
||||
evolved.multi_clone = __evolved_multi_clone
|
||||
evolved.multi_clone_nr = __evolved_multi_clone_nr
|
||||
evolved.multi_clone_to = __evolved_multi_clone_to
|
||||
|
||||
evolved.alive = __evolved_alive
|
||||
evolved.alive_all = __evolved_alive_all
|
||||
@@ -7524,6 +7891,10 @@ evolved.execute = __evolved_execute
|
||||
|
||||
evolved.locate = __evolved_locate
|
||||
|
||||
evolved.lookup = __evolved_lookup
|
||||
evolved.multi_lookup = __evolved_multi_lookup
|
||||
evolved.multi_lookup_to = __evolved_multi_lookup_to
|
||||
|
||||
evolved.process = __evolved_process
|
||||
evolved.process_with = __evolved_process_with
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ evolved.builder()
|
||||
:name('SYSTEMS.STARTUP')
|
||||
:group(STAGES.ON_SETUP)
|
||||
:prologue(function()
|
||||
evolved.multi_clone(500, PREFABS.CIRCLE, nil, function(chunk, b_place, e_place)
|
||||
evolved.multi_clone_nr(500, PREFABS.CIRCLE, nil, function(chunk, b_place, e_place)
|
||||
local screen_width, screen_height = love.graphics.getDimensions()
|
||||
|
||||
---@type number[], number[]
|
||||
|
||||
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