cleanup predef fragments setup

This commit is contained in:
BlackMATov
2024-12-30 01:06:17 +07:00
parent 2d4126ef09
commit a7ab4360fd
3 changed files with 83 additions and 77 deletions

View File

@@ -1,6 +1,6 @@
# evolved.lua (work in progress)
## Constants
## Predefs
```
TAG :: fragment

View File

@@ -582,7 +582,7 @@ end
do
local f1, f2, f3 = evo.id(3)
local e0 = evo.id()
local _ = evo.id()
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -827,7 +827,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_assign(q, f1, 60) == 3)
@@ -887,7 +887,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_assign(q, f1, 60) == 3)
@@ -945,7 +945,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_clear(q) == 3)
@@ -1015,7 +1015,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_clear(q) == 3)
assert(entity_sum == e2 * 2 + e3 * 3 + e4 * 4)
@@ -1063,7 +1063,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_destroy(q) == 3)
@@ -1133,7 +1133,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_destroy(q) == 3)
assert(entity_sum == e2 * 2 + e3 * 3 + e4 * 4)
@@ -1181,7 +1181,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_remove(q, f2, f3) == 3)
@@ -1254,7 +1254,7 @@ do
assert(evo.insert(e5, f4, 53))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f1, f2 })
evo.insert(q, evo.INCLUDE_LIST, f1, f2)
assert(evo.batch_remove(q, f2, f3) == 3)
assert(entity_sum == e2 + e3 * 2 + e4 * 2)
@@ -1290,7 +1290,7 @@ do
assert(evo.insert(e4, f4, 50))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f2 })
evo.insert(q, evo.INCLUDE_LIST, f2)
assert(evo.batch_insert(q, f1, 60) == 1)
@@ -1335,7 +1335,7 @@ do
assert(evo.insert(e4, f4, 50))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f2 })
evo.insert(q, evo.INCLUDE_LIST, f2)
entity_sum = 0
component_sum = 0
@@ -1378,7 +1378,7 @@ do
assert(evo.insert(e4, f4, 50))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f2 })
evo.insert(q, evo.INCLUDE_LIST, f2)
assert(evo.batch_set(q, f1, 60) == 3)
@@ -1423,7 +1423,7 @@ do
assert(evo.insert(e4, f4, 50))
local q = evo.id()
evo.insert(q, evo.INCLUDE_LIST, { f2 })
evo.insert(q, evo.INCLUDE_LIST, f2)
entity_sum = 0
component_sum = 0
@@ -1816,12 +1816,12 @@ do
do
do
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.batch_destroy(q)
end
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1, f2 })
evo.set(q, evo.INCLUDE_LIST, f1, f2)
do
local e = evo.id()
@@ -1866,12 +1866,12 @@ do
do
do
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.batch_destroy(q)
end
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1, f2 })
evo.set(q, evo.INCLUDE_LIST, f1, f2)
do
local e1 = evo.id()
@@ -1912,12 +1912,12 @@ do
do
do
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.batch_destroy(q)
end
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1, f2 })
evo.set(q, evo.INCLUDE_LIST, f1, f2)
do
local e1 = evo.id()
@@ -1959,12 +1959,12 @@ do
do
do
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.batch_destroy(q)
end
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1, f2 })
evo.set(q, evo.INCLUDE_LIST, f1, f2)
do
local e1 = evo.id()
@@ -2002,12 +2002,12 @@ do
do
do
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.batch_destroy(q)
end
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1, f2 })
evo.set(q, evo.INCLUDE_LIST, f1, f2)
do
local e1 = evo.id()
@@ -2047,7 +2047,7 @@ do
local f1, f2 = evo.id(2)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2083,7 +2083,7 @@ do
local f1, f2 = evo.id(2)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2119,7 +2119,7 @@ do
local f1, f2 = evo.id(2)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2155,7 +2155,7 @@ do
local f1 = evo.id(1)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2178,7 +2178,7 @@ do
local f1 = evo.id(1)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2203,7 +2203,7 @@ do
local f1 = evo.id(1)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2228,8 +2228,8 @@ do
local f1, f2 = evo.id(2)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, { f2 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.set(q, evo.INCLUDE_LIST, f2)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))
@@ -2260,10 +2260,10 @@ do
local f1, f2 = evo.id(2)
local q = evo.id()
evo.set(q, evo.INCLUDE_LIST, { f1 })
evo.set(q, evo.INCLUDE_LIST, f1)
evo.set(q, evo.EXCLUDE_LIST, { f1 })
evo.set(q, evo.EXCLUDE_LIST, { f2 })
evo.set(q, evo.EXCLUDE_LIST, f1)
evo.set(q, evo.EXCLUDE_LIST, f2)
local e1 = evo.id()
assert(evo.insert(e1, f1, 41))

View File

@@ -52,7 +52,7 @@ local __structural_changes = 0 ---@type integer
---
---
local __lua_move = table.move or function(a1, f, e, t, a2)
local __table_move = table.move or function(a1, f, e, t, a2)
if a2 == nil then
a2 = a1
end
@@ -72,11 +72,7 @@ local __lua_move = table.move or function(a1, f, e, t, a2)
return a2
end
local __lua_pack = table.pack or function(...)
return { n = select('#', ...), ... }
end
local __lua_unpack = table.unpack or function(list, i, j)
local __table_unpack = table.unpack or function(list, i, j)
return unpack(list, i, j)
end
@@ -779,14 +775,14 @@ local function __chunk_insert(chunk, fragment, ...)
local new_chunk_size = #new_chunk_entities
local new_chunk_fragment_components = new_chunk_components[fragment]
__lua_move(
__table_move(
old_chunk_entities, 1, old_chunk_size,
new_chunk_size + 1, new_chunk_entities)
for old_f, old_cs in pairs(old_chunk_components) do
local new_cs = new_chunk_components[old_f]
if new_cs then
__lua_move(old_cs, 1, old_chunk_size, new_chunk_size + 1, new_cs)
__table_move(old_cs, 1, old_chunk_size, new_chunk_size + 1, new_cs)
end
end
@@ -906,14 +902,14 @@ local function __chunk_remove(chunk, ...)
local new_chunk_size = #new_chunk.__entities
__lua_move(
__table_move(
old_chunk_entities, 1, old_chunk_size,
new_chunk_size + 1, new_chunk_entities)
for new_f, new_cs in pairs(new_chunk_components) do
local old_cs = old_chunk_components[new_f]
if old_cs then
__lua_move(old_cs, 1, old_chunk_size, new_chunk_size + 1, new_cs)
__table_move(old_cs, 1, old_chunk_size, new_chunk_size + 1, new_cs)
end
end
@@ -1119,27 +1115,27 @@ local __defer_ops = {
local entity = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.set(entity, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.set(entity, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.assign] = function(bytes, index)
local entity = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.assign(entity, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.assign(entity, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.insert] = function(bytes, index)
local entity = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.insert(entity, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.insert(entity, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.remove] = function(bytes, index)
local entity = bytes[index + 0]
local fragment_count = bytes[index + 1]
evolved.remove(entity, __lua_unpack(bytes, index + 2, index + 1 + fragment_count))
evolved.remove(entity, __table_unpack(bytes, index + 2, index + 1 + fragment_count))
return 2 + fragment_count
end,
[__defer_op.clear] = function(bytes, index)
@@ -1156,27 +1152,27 @@ local __defer_ops = {
local query = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.batch_set(query, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.batch_set(query, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.batch_assign] = function(bytes, index)
local query = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.batch_assign(query, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.batch_assign(query, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.batch_insert] = function(bytes, index)
local query = bytes[index + 0]
local fragment = bytes[index + 1]
local argument_count = bytes[index + 2]
evolved.batch_insert(query, fragment, __lua_unpack(bytes, index + 3, index + 2 + argument_count))
evolved.batch_insert(query, fragment, __table_unpack(bytes, index + 3, index + 2 + argument_count))
return 3 + argument_count
end,
[__defer_op.batch_remove] = function(bytes, index)
local query = bytes[index + 0]
local fragment_count = bytes[index + 1]
evolved.batch_remove(query, __lua_unpack(bytes, index + 2, index + 1 + fragment_count))
evolved.batch_remove(query, __table_unpack(bytes, index + 2, index + 1 + fragment_count))
return 2 + fragment_count
end,
[__defer_op.batch_clear] = function(bytes, index)
@@ -2125,33 +2121,26 @@ local __SORTED_EXCLUDE_LIST = __acquire_id()
assert(evolved.insert(evolved.TAG, evolved.TAG))
assert(evolved.insert(evolved.INCLUDE_LIST, evolved.CONSTRUCT, function(_, _, include_list)
return include_list or {}
end))
---@param ... evolved.fragment
assert(evolved.insert(evolved.INCLUDE_LIST, evolved.CONSTRUCT, function(_, _, ...)
local include_list = {}
assert(evolved.insert(evolved.INCLUDE_LIST, evolved.ON_REMOVE, function(query)
evolved.remove(query, __INCLUDE_SET, __SORTED_INCLUDE_LIST)
end))
for i = 1, select('#', ...) do
include_list[i] = select(i, ...)
end
assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.CONSTRUCT, function(_, _, exclude_list)
return exclude_list or {}
end))
assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.ON_REMOVE, function(query)
evolved.remove(query, __EXCLUDE_SET, __SORTED_EXCLUDE_LIST)
return include_list
end))
---@param query evolved.query
---@param include_list? evolved.entity[]
---@param include_list evolved.entity[]
assert(evolved.insert(evolved.INCLUDE_LIST, evolved.ON_SET, function(query, _, include_list)
---@type table<evolved.fragment, boolean>, evolved.fragment[]
local include_set, sorted_include_list = {}, {}
if include_list then
for _, f in ipairs(include_list) do
include_set[f] = true
sorted_include_list[#sorted_include_list + 1] = f
end
for _, f in ipairs(include_list) do
include_set[f] = true
sorted_include_list[#sorted_include_list + 1] = f
end
table.sort(sorted_include_list)
@@ -2160,17 +2149,30 @@ assert(evolved.insert(evolved.INCLUDE_LIST, evolved.ON_SET, function(query, _, i
evolved.set(query, __SORTED_INCLUDE_LIST, sorted_include_list)
end))
assert(evolved.insert(evolved.INCLUDE_LIST, evolved.ON_REMOVE, function(query)
evolved.remove(query, __INCLUDE_SET, __SORTED_INCLUDE_LIST)
end))
---@param ... evolved.fragment
assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.CONSTRUCT, function(_, _, ...)
local exclude_list = {}
for i = 1, select('#', ...) do
exclude_list[i] = select(i, ...)
end
return exclude_list
end))
---@param query evolved.query
---@param exclude_list? evolved.entity[]
---@param exclude_list evolved.entity[]
assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.ON_SET, function(query, _, exclude_list)
---@type table<evolved.fragment, boolean>, evolved.fragment[]
local exclude_set, sorted_exclude_list = {}, {}
if exclude_list then
for _, f in ipairs(exclude_list) do
exclude_set[f] = true
sorted_exclude_list[#sorted_exclude_list + 1] = f
end
for _, f in ipairs(exclude_list) do
exclude_set[f] = true
sorted_exclude_list[#sorted_exclude_list + 1] = f
end
table.sort(sorted_exclude_list)
@@ -2179,6 +2181,10 @@ assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.ON_SET, function(query, _, e
evolved.set(query, __SORTED_EXCLUDE_LIST, sorted_exclude_list)
end))
assert(evolved.insert(evolved.EXCLUDE_LIST, evolved.ON_REMOVE, function(query)
evolved.remove(query, __EXCLUDE_SET, __SORTED_EXCLUDE_LIST)
end))
---
---
---