Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
da4a992
remove public multi api
BlackMATov Apr 19, 2025
c08243f
remove private multi api impl
BlackMATov Apr 19, 2025
265323a
remove private defer multi api impl
BlackMATov Apr 19, 2025
dce83d1
remove private chunk multi api impl
BlackMATov Apr 19, 2025
63c0e17
cleanup after multi api removing
BlackMATov Apr 19, 2025
6b54ad1
style fixes
BlackMATov Apr 20, 2025
e89b91f
remove multi chunk_or_entity api
BlackMATov Apr 20, 2025
189269f
aos variant of spawn/clone functions WIP
BlackMATov Apr 21, 2025
72979b4
remove legacy spawn_with
BlackMATov Apr 22, 2025
b2c3672
remove legacy spawn_at / spawn_as
BlackMATov Apr 22, 2025
513bf21
remove singles api
BlackMATov Apr 24, 2025
3fb1467
style fixes
BlackMATov Apr 24, 2025
777b80b
is_alive, is_empty -> alive, empty
BlackMATov Apr 24, 2025
a8a5113
style fixes
BlackMATov Apr 24, 2025
5aa72e0
more spawn/clone debug checks
BlackMATov Apr 24, 2025
9c81f3f
Merge branch 'feature/remove_multi_api' into dev
BlackMATov Apr 24, 2025
473881a
name empty containers
BlackMATov Apr 25, 2025
1799f57
new builtin prefab/hidden fragments, without additional functionality…
BlackMATov Apr 25, 2025
f816d42
cache has_hidden_fragments flag in chunks
BlackMATov Apr 25, 2025
bea5058
don't clone hidden fragments (while they are not explicit)
BlackMATov Apr 25, 2025
4632a61
don't match chunks with hidden fragments (while they are not explicit)
BlackMATov Apr 27, 2025
943f6ea
separate unique/explicit traits instead hidden
BlackMATov Apr 27, 2025
d5d5620
mark on_xxx fragments as unique
BlackMATov Apr 27, 2025
b263e89
update roadmap
BlackMATov Apr 28, 2025
dcd27e9
Merge branch 'feature/prefab_trait' into dev
BlackMATov Apr 28, 2025
0395e04
mark builtin disabled fragment as unique and explicit
BlackMATov Apr 29, 2025
da11298
style fixes
BlackMATov Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 56 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@
```
TAG :: fragment
NAME :: fragment

UNIQUE :: fragment
EXPLICIT :: fragment

DEFAULT :: fragment
DUPLICATE :: fragment

PREFAB :: fragment
DISABLED :: fragment

INCLUDES :: fragment
EXCLUDES :: fragment

Expand All @@ -48,8 +55,6 @@ EXECUTE :: fragment
PROLOGUE :: fragment
EPILOGUE :: fragment

DISABLED :: fragment

DESTROY_POLICY :: fragment
DESTROY_POLICY_DESTROY_ENTITY :: id
DESTROY_POLICY_REMOVE_FRAGMENT :: id
Expand All @@ -66,17 +71,20 @@ unpack :: id -> integer, integer
defer :: boolean
commit :: boolean

is_alive :: chunk | entity -> boolean
is_alive_all :: chunk | entity... -> boolean
is_alive_any :: chunk | entity... -> boolean
spawn :: <fragment, component>? -> entity
clone :: entity -> <fragment, component>? -> entity

alive :: entity -> boolean
alive_all :: entity... -> boolean
alive_any :: entity... -> boolean

is_empty :: chunk | entity -> boolean
is_empty_all :: chunk | entity... -> boolean
is_empty_any :: chunk | entity... -> boolean
empty :: entity -> boolean
empty_all :: entity... -> boolean
empty_any :: entity... -> boolean

has :: chunk | entity, fragment -> boolean
has_all :: chunk | entity, fragment... -> boolean
has_any :: chunk | entity, fragment... -> boolean
has :: entity, fragment -> boolean
has_all :: entity, fragment... -> boolean
has_any :: entity, fragment... -> boolean

get :: entity, fragment... -> component...

Expand All @@ -85,67 +93,84 @@ remove :: entity, fragment... -> ()
clear :: entity... -> ()
destroy :: entity... -> ()

multi_set :: entity, fragment[], component[]? -> ()
multi_remove :: entity, fragment[] -> ()

batch_set :: query, fragment, component -> ()
batch_remove :: query, fragment... -> ()
batch_clear :: query... -> ()
batch_destroy :: query... -> ()

batch_multi_set :: query, fragment[], component[]? -> ()
batch_multi_remove :: query, fragment[] -> ()

chunk :: fragment, fragment... -> chunk, entity[], integer

entities :: chunk -> entity[], integer
fragments :: chunk -> fragment[], integer
components :: chunk, fragment... -> component[]...

each :: entity -> {each_state? -> fragment?, component?}, each_state?
execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_state?

process :: system... -> ()

spawn_at :: chunk?, fragment[]?, component[]? -> entity
spawn_as :: entity?, fragment[]?, component[]? -> entity
spawn_with :: fragment[]?, component[]? -> entity

debug_mode :: boolean -> ()
collect_garbage :: ()
```

## Chunk

```
chunk :: fragment, fragment... -> chunk, entity[], integer

chunk:alive :: boolean
chunk:empty :: boolean

chunk:has :: fragment -> boolean
chunk:has_all :: fragment... -> boolean
chunk:has_any :: fragment... -> boolean

chunk:entities :: entity[], integer
chunk:fragments :: fragment[], integer
chunk:components :: fragment... -> component[]...
```

## Builder

```
builder :: builder

builder:spawn :: entity
builder:clone :: entity -> entity

builder:has :: fragment -> boolean
builder:has_all :: fragment... -> boolean
builder:has_any :: fragment... -> boolean

builder:get :: fragment... -> component...

builder:set :: fragment, component -> builder
builder:remove :: fragment... -> builder
builder:clear :: builder

builder:tag :: builder
builder:name :: string -> builder
builder:prefab :: entity -> builder
builder:single :: component -> builder

builder:unique :: builder
builder:explicit :: builder

builder:default :: component -> builder
builder:duplicate :: {component -> component} -> builder

builder:prefab :: builder
builder:disabled :: builder

builder:include :: fragment... -> builder
builder:exclude :: fragment... -> builder

builder:on_set :: {entity, fragment, component, component?} -> builder
builder:on_assign :: {entity, fragment, component, component} -> builder
builder:on_insert :: {entity, fragment, component} -> builder
builder:on_remove :: {entity, fragment} -> builder

builder:group :: system -> builder

builder:query :: query -> builder
builder:execute :: {chunk, entity[], integer} -> builder

builder:prologue :: {} -> builder
builder:epilogue :: {} -> builder
builder:disabled :: builder

builder:destroy_policy :: id -> builder
builder:build :: boolean -> entity
```

## [License (MIT)](./LICENSE.md)
4 changes: 0 additions & 4 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

## Backlog

- builders should be rewritten :/
- add PREFAB entity trait
- is/has_all/any for lists?

## After first release

- cached queries
Expand Down
6 changes: 6 additions & 0 deletions develop/all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ require 'develop.usbench'

local basics = require 'develop.basics'

print '----------------------------------------'
basics.describe_fuzz 'develop.fuzzing.destroy_fuzz'
print '----------------------------------------'
basics.describe_fuzz 'develop.fuzzing.batch_destroy_fuzz'
print '----------------------------------------'
basics.describe_fuzz 'develop.fuzzing.explicit_fuzz'
print '----------------------------------------'
basics.describe_fuzz 'develop.fuzzing.unique_fuzz'
49 changes: 23 additions & 26 deletions develop/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ local function vector2(x, y)
return { x = x, y = y }
end

local groups = {
awake = evo.builder():build(),
physics = evo.builder():build(),
graphics = evo.builder():build(),
shutdown = evo.builder():build(),
local consts = {
delta_time = 0.016,
physics_gravity = vector2(0, 9.81),
}

local singles = {
delta_time = evo.builder():single(0.016):build(),
physics_gravity = evo.builder():single(vector2(0, 9.81)):build(),
local groups = {
awake = evo.spawn(),
physics = evo.spawn(),
graphics = evo.spawn(),
shutdown = evo.spawn(),
}

local fragments = {
force = evo.builder():build(),
position = evo.builder():build(),
velocity = evo.builder():build(),
force = evo.spawn(),
position = evo.spawn(),
velocity = evo.spawn(),
}

local queries = {
physics_bodies = evo.builder()
:include(fragments.force, fragments.position, fragments.velocity)
:build(),
:spawn(),
}

local awake_system = evo.builder()
Expand All @@ -49,20 +49,18 @@ local awake_system = evo.builder()
:set(fragments.force, vector2(0, 0))
:set(fragments.position, vector2(0, 0))
:set(fragments.velocity, vector2(0, 0))
:build()
end):build()
:spawn()
end):spawn()

local integrate_forces_system = evo.builder()
:group(groups.physics)
:query(queries.physics_bodies)
:execute(function(chunk, entities, entity_count)
---@type number, evolved.vector2
local delta_time, physics_gravity =
evo.get(singles.delta_time, singles.delta_time),
evo.get(singles.physics_gravity, singles.physics_gravity)
consts.delta_time, consts.physics_gravity

---@type evolved.vector2[], evolved.vector2[]
local forces, velocities = evo.components(chunk,
local forces, velocities = chunk:components(
fragments.force, fragments.velocity)

for i = 1, entity_count do
Expand All @@ -71,18 +69,17 @@ local integrate_forces_system = evo.builder()
velocity.x = velocity.x + (physics_gravity.x + force.x) * delta_time
velocity.y = velocity.y + (physics_gravity.y + force.y) * delta_time
end
end):build()
end):spawn()

local integrate_velocities_system = evo.builder()
:group(groups.physics)
:query(queries.physics_bodies)
:execute(function(chunk, entities, entity_count)
---@type number
local delta_time =
evo.get(singles.delta_time, singles.delta_time)
consts.delta_time

---@type evolved.vector2[], evolved.vector2[], evolved.vector2[]
local forces, positions, velocities = evo.components(chunk,
local forces, positions, velocities = chunk:components(
fragments.force, fragments.position, fragments.velocity)

for i = 1, entity_count do
Expand All @@ -94,14 +91,14 @@ local integrate_velocities_system = evo.builder()
force.x = 0
force.y = 0
end
end):build()
end):spawn()

local graphics_system = evo.builder()
:group(groups.graphics)
:query(queries.physics_bodies)
:execute(function(chunk, entities, entity_count)
---@type evolved.vector2[]
local positions = evo.components(chunk,
local positions = chunk:components(
fragments.position)

for i = 1, entity_count do
Expand All @@ -111,14 +108,14 @@ local graphics_system = evo.builder()
'|-> {entity %d} at {%.4f, %.4f}',
entity, position.x, position.y))
end
end):build()
end):spawn()

local shutdown_system = evo.builder()
:group(groups.shutdown)
:epilogue(function()
print '-= | Shutdown | =-'
evo.batch_destroy(queries.physics_bodies)
end):build()
end):spawn()

do
evo.process(groups.awake)
Expand Down
10 changes: 5 additions & 5 deletions develop/fuzzing/batch_destroy_fuzz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end

do
local r = math.random(1, 2)
local q = evo.builder():include(__table_unpack(destroying_include_list)):build()
local q = evo.builder():include(__table_unpack(destroying_include_list)):spawn()

if r == 1 then
evo.batch_destroy(q)
Expand All @@ -98,17 +98,17 @@ end
---
---

local all_chunk_query = evo.builder():build()
local all_chunk_query = evo.spawn()

for chunk in evo.execute(all_chunk_query) do
assert(not evo.has_any(chunk, __table_unpack(should_be_destroyed_entity_list)))
for _, fragment in ipairs(evo.fragments(chunk)) do
assert(not chunk:has_any(__table_unpack(should_be_destroyed_entity_list)))
for _, fragment in ipairs(chunk:fragments()) do
assert(not evo.has_all(fragment, __table_unpack(destroying_include_list)))
end
end

for _, destroyed_entity in ipairs(should_be_destroyed_entity_list) do
assert(not evo.is_alive(destroyed_entity))
assert(not evo.alive(destroyed_entity))
end

---
Expand Down
10 changes: 5 additions & 5 deletions develop/fuzzing/destroy_fuzz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ end
---
---

local all_chunk_query = evo.builder():build()
local all_chunk_query = evo.spawn()

for chunk in evo.execute(all_chunk_query) do
assert(not evo.has_any(chunk, __table_unpack(destroying_entity_list)))
assert(not evo.has_any(chunk, __table_unpack(should_be_destroyed_entity_list)))
assert(not chunk:has_any(__table_unpack(destroying_entity_list)))
assert(not chunk:has_any(__table_unpack(should_be_destroyed_entity_list)))
end

for _, destroying_entity in ipairs(destroying_entity_list) do
assert(not evo.is_alive(destroying_entity))
assert(not evo.alive(destroying_entity))
end

for _, destroyed_entity in ipairs(should_be_destroyed_entity_list) do
assert(not evo.is_alive(destroyed_entity))
assert(not evo.alive(destroyed_entity))
end

---
Expand Down
Loading
Loading