Compare commits

..

No commits in common. "b26fc39fce9a80869106e85673615486b9affa4c" and "de8e2638285e18dd75a2de757d2b421d05ec4ccf" have entirely different histories.

4 changed files with 42 additions and 93 deletions

View file

@ -2512,8 +2512,6 @@ return {
ECS_GENERATION = ECS_GENERATION, ECS_GENERATION = ECS_GENERATION,
ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD, ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
ECS_ID_DELETE = ECS_ID_DELETE,
IS_PAIR = ECS_IS_PAIR, IS_PAIR = ECS_IS_PAIR,
pair_first = ecs_pair_first, pair_first = ecs_pair_first,
pair_second = ecs_pair_second, pair_second = ecs_pair_second,

View file

@ -2,24 +2,23 @@ local jecs = require("@jecs")
local pair = jecs.pair local pair = jecs.pair
local ChildOf = jecs.ChildOf local ChildOf = jecs.ChildOf
local lifetime_tracker_add = require("@tools/lifetime_tracker") local lifetime_tracker_add = require("@tools/lifetime_tracker")
local pe = require("@tools/entity_visualiser").prettify local world = lifetime_tracker_add(jecs.world())
local world = lifetime_tracker_add(jecs.world(), {padding_enabled=false}) world:print_snapshot()
local FriendsWith = world:component() local e = world:entity()
local _1 = world:print_snapshot()
local e1 = world:entity() local e1 = world:entity()
local e2 = world:entity() world:delete(e)
world:delete(e2)
local _2 = world:print_snapshot() world:print_snapshot()
local e2 = world:entity()
world:add(e2, pair(ChildOf, e1))
local e3 = world:entity() local e3 = world:entity()
world:add(e3, pair(ChildOf, e1)) world:add(e3, pair(ChildOf, e1))
local e4 = world:entity() world:print_snapshot()
world:add(e4, pair(FriendsWith, e3))
local _3 = world:print_snapshot()
world:delete(e1) world:delete(e1)
world:delete(e2)
world:delete(e3) world:delete(e3)
local _4 = world:print_snapshot() world:print_snapshot()
world:print_entity_index() world:print_entity_index()
world:entity() world:entity()
world:entity() world:entity()
local _5 = world:print_snapshot() world:print_snapshot()

View file

@ -37,7 +37,14 @@ local function components(world: jecs.World, entity: any)
return true return true
end end
local world = jecs.world()
local A = world:component()
world:set(A, jecs.Name, "A")
local e = world:entity()
world:set(e, A, true)
components(world, e)
return { return {
components = components, components = components,
prettify = pe, prettify = pe
} }

View file

@ -4,10 +4,7 @@ local ECS_ID = jecs.ECS_ID
local __ = jecs.Wildcard local __ = jecs.Wildcard
local pair = jecs.pair local pair = jecs.pair
local prettify = require("@tools/entity_visualiser").prettify local pe = require("@tools/entity_visualiser").prettify
local pe = prettify
local ansi = require("@tools/ansi")
function print_centered_entity(entity, width: number) function print_centered_entity(entity, width: number)
local entity_str = tostring(entity) local entity_str = tostring(entity)
@ -23,37 +20,37 @@ function print_centered_entity(entity, width: number)
print("|" .. centered_str .. "|") print("|" .. centered_str .. "|")
end end
local function name(world, e) local function lifetime_tracker_add(world: jecs.World)
return world:get(world, e, jecs.Name) or pe(e)
end
local padding_enabled = false
local function pad()
if padding_enabled then
print("")
end
end
local function lifetime_tracker_add(world: jecs.World, opt)
local entity_index = world.entity_index local entity_index = world.entity_index
local dense_array = entity_index.dense_array local dense_array = entity_index.dense_array
local world_delete = world.delete
local world_entity = world.entity
local component_index = world.component_index local component_index = world.component_index
local ENTITY_RANGE = (jecs.Rest :: any) + 1 local ENTITY_RANGE = (jecs.Rest :: any) + 1
local w = setmetatable({}, { __index = world }) local w = setmetatable({}, { __index = world })
w.delete = function(self, e)
print(`*deleting {pe(e)}`)
padding_enabled = opt.padding_enabled local idr_t = component_index[pair(__, e)]
if idr_t then
local world_entity = world.entity print(`{pe(e)} has the following dependencies:`)
w.entity = function(self) for archetype_id in idr_t.cache do
local will_recycle = entity_index.max_id ~= entity_index.alive_count local archetype = world.archetypes[archetype_id]
local e = world_entity(world) local entities = {}
if will_recycle then for _, dependency in archetype.entities do
print(`*recycled {pe(e)}`) print(` {pe(dependency)}`)
else end
print(`*created {pe(e)}`) end
end end
pad()
world_delete(world, e)
print(`*deleted {pe(e)}`)
end
w.entity = function(self)
local e = world_entity(world)
print(`*created {pe(e)}`)
return e return e
end end
w.print_entity_index = function(self) w.print_entity_index = function(self)
@ -80,7 +77,6 @@ local function lifetime_tracker_add(world: jecs.World, opt)
print(sep) print(sep)
end end
end end
pad()
end end
local timelines = {} local timelines = {}
w.print_snapshot = function(self) w.print_snapshot = function(self)
@ -154,57 +150,6 @@ local function lifetime_tracker_add(world: jecs.World, opt)
print(row) print(row)
end end
print("-------------------------------------------------------------------") print("-------------------------------------------------------------------")
pad()
end
local world_add = world.add
local relations = {}
w.add = function(self, entity: any, component: any)
world_add(world, entity, component)
if jecs.IS_PAIR(component) then
local relation = jecs.pair_first(world, component)
local target = jecs.pair_second(world, component)
print(`*added ({pe(relation)}, {pe(target)}) to {pe(entity)}`)
pad()
end
end
local world_delete = world.delete
w.delete = function(self, e)
world_delete(world, e)
local idr_t = component_index[pair(__, e)]
if idr_t then
for archetype_id in idr_t.cache do
local archetype = world.archetypes[archetype_id]
for _, id in archetype.types do
if not jecs.IS_PAIR(id) then
continue
end
local object = jecs.pair_second(world, id)
if object ~= e then
continue
end
local id_record = component_index[id]
local flags = id_record.flags
local flags_delete_mask: number = bit32.band(flags, jecs.ECS_ID_DELETE)
if flags_delete_mask ~= 0 then
for _, entity in archetype.entities do
print(`*deleted dependant {pe(entity)} of {pe(e)}`)
pad()
end
break
else
for _, entity in archetype.entities do
print(`*removed dependency ({pe(jecs.pair_first(world, id))}, {pe(object)}) from {pe(entity)}`)
end
end
end
end
end
print(`*deleted {pe(e)}`)
pad()
end end
return w return w
end end