Compare commits

..

No commits in common. "f9b589547ba83afc4fe2f7c18ec2a54f404e6e6b" and "6811b6de0edb686cd045a579a062c591f0829387" have entirely different histories.

4 changed files with 21 additions and 54 deletions

View file

@ -45,9 +45,9 @@ type ecs_id_record_t = {
flags: number,
size: number,
hooks: {
on_add: ((entity: i53, id: i53, data: any?) -> ())?,
on_change: ((entity: i53, id: i53, data: any) -> ())?,
on_remove: ((entity: i53, id: i53) -> ())?,
on_add: ((entity: i53, data: any?) -> ())?,
on_change: ((entity: i53, data: any) -> ())?,
on_remove: ((entity: i53) -> ())?,
},
}
@ -144,7 +144,7 @@ end
local function ECS_META(id: i53, ty: i53, value: any?)
local bundle = ecs_metadata[id]
if bundle == nil then
if bundle then
bundle = {}
ecs_metadata[id] = bundle
end
@ -500,14 +500,6 @@ local function world_has_one_inline(world: ecs_world_t, entity: i53, id: i53): b
return records[id] ~= nil
end
local function ecs_is_tag(world: ecs_world_t, entity: i53): boolean
local idr = world.component_index[entity]
if idr then
return bit32.band(idr.flags, ECS_ID_IS_TAG) ~= 0
end
return not world_has_one_inline(world, entity, EcsComponent)
end
local function world_has(world: ecs_world_t, entity: i53,
a: i53, b: i53?, c: i53?, d: i53?, e: i53?): boolean
@ -857,7 +849,7 @@ local function world_add(
local on_add = idr.hooks.on_add
if on_add then
on_add(entity, id)
on_add(entity)
end
end
@ -882,7 +874,7 @@ local function world_set(world: ecs_world_t, entity: i53, id: i53, data: unknown
-- and just set the data directly.
local on_change = idr_hooks.on_change
if on_change then
on_change(entity, id, data)
on_change(entity, data)
end
return
@ -905,7 +897,7 @@ local function world_set(world: ecs_world_t, entity: i53, id: i53, data: unknown
local on_add = idr_hooks.on_add
if on_add then
on_add(entity, id, data)
on_add(entity, data)
end
end
@ -937,7 +929,7 @@ local function world_remove(world: ecs_world_t, entity: i53, id: i53)
local idr = world.component_index[id]
local on_remove = idr.hooks.on_remove
if on_remove then
on_remove(entity, id)
on_remove(entity)
end
local to = archetype_traverse_remove(world, id, record.archetype)
@ -989,7 +981,7 @@ local function archetype_delete(world: ecs_world_t, archetype: ecs_archetype_t,
local idr = component_index[id]
local on_remove = idr.hooks.on_remove
if on_remove then
on_remove(delete, id)
on_remove(delete)
end
end
@ -1049,7 +1041,7 @@ local function world_clear(world: ecs_world_t, entity: i53)
continue
end
if not ids then
ids = {} :: { [i53]: boolean }
ids = {}
end
ids[id] = true
removal_queued = true
@ -1060,7 +1052,7 @@ local function world_clear(world: ecs_world_t, entity: i53)
end
if not queue then
queue = {} :: { i53 }
queue = {}
end
local n = #entities
@ -1250,7 +1242,7 @@ local function world_delete(world: ecs_world_t, entity: i53)
break
else
if not ids then
ids = {} :: { [i53]: boolean }
ids = {}
end
ids[id] = true
removal_queued = true
@ -1261,7 +1253,7 @@ local function world_delete(world: ecs_world_t, entity: i53)
continue
end
if not children then
children = {} :: { i53 }
children = {}
end
local n = #entities
table.move(entities, 1, n, count + 1, children)
@ -2531,7 +2523,6 @@ return {
component = (ECS_COMPONENT :: any) :: <T>() -> Entity<T>,
tag = (ECS_TAG :: any) :: <T>() -> Entity<T>,
meta = (ECS_META :: any) :: <T>(id: Entity, id: Id<T>, value: T) -> Entity<T>,
is_tag = (ecs_is_tag :: any) :: <T>(World, Id<T>) -> boolean,
OnAdd = EcsOnAdd :: Entity<(entity: Entity) -> ()>,
OnRemove = EcsOnRemove :: Entity<(entity: Entity) -> ()>,

View file

@ -82,25 +82,6 @@ TEST("addons/observers", function()
world:set(e, A, true)
CHECK(count == 3)
end
do CASE "Call on pairs"
local A = world:component()
local callcount = 0
world:added(A, function(entity)
callcount += 1
end)
world:added(A, function(entity)
callcount += 1
end)
local e = world:entity()
local e1 = world:entity()
world:add(e1, jecs.pair(A, e))
world:add(e, jecs.pair(A, e1))
CHECK(callcount == 4)
end
end)
return FINISH()

View file

@ -22,7 +22,6 @@ type Entity<T=nil> = jecs.Entity<T>
type Id<T=unknown> = jecs.Id<T>
local entity_visualiser = require("@tools/entity_visualiser")
local lifetime_tracker_add = require("@tools/lifetime_tracker")
local dwi = entity_visualiser.stringify
TEST("world:add()", function()
@ -247,7 +246,6 @@ TEST("world:component()", function()
end)
TEST("world:contains()", function()
local tag = jecs.tag()
local world = jecs.world()
local id = world:entity()
CHECK(world:contains(id))
@ -257,9 +255,6 @@ TEST("world:contains()", function()
world:delete(id)
CHECK(not world:contains(id))
end
CHECK(world:contains(tag))
jecs.ECS_META_RESET()
end)
TEST("world:delete()", function()
@ -633,7 +628,6 @@ end)
TEST("world:entity()", function()
local N = 2^8
do CASE "unique IDs"
local world = jecs.world()
local set = {}
@ -1433,6 +1427,8 @@ TEST("#adding a recycled target", function()
end)
TEST("#repro2", function()
local world = jecs.world()
local Lifetime = world:component() :: Id<number>

View file

@ -226,8 +226,6 @@ local function CHECK<T>(value: T, stack: number?): T?
return value
end
local test_focused = false
local function TEST(name: string, fn: () -> ())
test = {
@ -240,10 +238,6 @@ local function TEST(name: string, fn: () -> ())
local t = test
if check_for_focused and not test_focused then
test.focus = true
test_focused = true
end
table.insert(tests, t)
end
@ -251,10 +245,15 @@ local function FOCUS()
assert(test, "no active test")
check_for_focused = true
test_focused = false
if test.case then
test.case.focus = true
else
test.focus = true
end
end
local function FINISH(): number
local success = true
local total_cases = 0
local passed_cases = 0
local passed_focus_cases = 0