mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Iter should not drain by default (#123)
This commit is contained in:
parent
87754c19d2
commit
62ac6e62c0
3 changed files with 35 additions and 10 deletions
|
@ -956,14 +956,16 @@ local EMPTY_QUERY = {
|
||||||
setmetatable(EMPTY_QUERY, EMPTY_QUERY)
|
setmetatable(EMPTY_QUERY, EMPTY_QUERY)
|
||||||
|
|
||||||
local function query_init(query)
|
local function query_init(query)
|
||||||
local world_query_iter_next = query.iter_next
|
local world_query_iter_next
|
||||||
if world_query_iter_next then
|
|
||||||
return world_query_iter_next
|
if query.should_drain then
|
||||||
|
world_query_iter_next = query.iter_next
|
||||||
|
if world_query_iter_next then
|
||||||
|
return world_query_iter_next
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local compatible_archetypes = query.compatible_archetypes
|
local compatible_archetypes = query.compatible_archetypes
|
||||||
local ids = query.ids
|
|
||||||
local A, B, C, D, E, F, G, H, I = unpack(ids)
|
|
||||||
local a, b, c, d, e, f, g, h
|
|
||||||
local lastArchetype = 1
|
local lastArchetype = 1
|
||||||
local archetype = compatible_archetypes[1]
|
local archetype = compatible_archetypes[1]
|
||||||
if not archetype then
|
if not archetype then
|
||||||
|
@ -972,8 +974,12 @@ local function query_init(query)
|
||||||
local columns = archetype.columns
|
local columns = archetype.columns
|
||||||
local entities = archetype.entities
|
local entities = archetype.entities
|
||||||
local i = #entities
|
local i = #entities
|
||||||
|
|
||||||
local records = archetype.records
|
local records = archetype.records
|
||||||
|
|
||||||
|
local ids = query.ids
|
||||||
|
local A, B, C, D, E, F, G, H, I = unpack(ids)
|
||||||
|
local a, b, c, d, e, f, g, h
|
||||||
|
|
||||||
if not B then
|
if not B then
|
||||||
a = columns[records[A].column]
|
a = columns[records[A].column]
|
||||||
elseif not C then
|
elseif not C then
|
||||||
|
@ -1216,6 +1222,7 @@ end
|
||||||
local function query_drain(query)
|
local function query_drain(query)
|
||||||
local query_iter_next = query_init(query)
|
local query_iter_next = query_init(query)
|
||||||
query.next = query_iter_next
|
query.next = query_iter_next
|
||||||
|
query.should_drain = true
|
||||||
return query
|
return query
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,24 @@ TEST("world:add()", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:query()", function()
|
TEST("world:query()", function()
|
||||||
|
do CASE "multiple iter"
|
||||||
|
local world = jecs.World.new()
|
||||||
|
local A = world:component()
|
||||||
|
local B = world:component()
|
||||||
|
local e = world:entity()
|
||||||
|
world:add(e, A, "a")
|
||||||
|
world:add(e, B)
|
||||||
|
local q = world:query(A, B)
|
||||||
|
local counter = 0
|
||||||
|
for x in q:iter() do
|
||||||
|
counter += 1
|
||||||
|
end
|
||||||
|
for x in q:iter() do
|
||||||
|
counter += 1
|
||||||
|
end
|
||||||
|
print(counter)
|
||||||
|
CHECK(counter == 2)
|
||||||
|
end
|
||||||
do CASE "tag"
|
do CASE "tag"
|
||||||
local world = jecs.World.new()
|
local world = jecs.World.new()
|
||||||
local A = world:entity()
|
local A = world:entity()
|
||||||
|
@ -545,8 +563,8 @@ TEST("world:query()", function()
|
||||||
|
|
||||||
do CASE("should error when setting invalid pair")
|
do CASE("should error when setting invalid pair")
|
||||||
local world = jecs.World.new()
|
local world = jecs.World.new()
|
||||||
local Eats = world:entity()
|
local Eats = world:component()
|
||||||
local Apples = world:entity()
|
local Apples = world:component()
|
||||||
local bob = world:entity()
|
local bob = world:entity()
|
||||||
|
|
||||||
world:delete(Apples)
|
world:delete(Apples)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ukendio/jecs"
|
name = "ukendio/jecs"
|
||||||
version = "0.3.0-rc.1"
|
version = "0.3.0-rc.2"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
include = [
|
include = [
|
||||||
|
|
Loading…
Reference in a new issue