mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Compare commits
2 commits
de8e263828
...
b26fc39fce
Author | SHA1 | Date | |
---|---|---|---|
|
b26fc39fce | ||
|
0e4f40ced7 |
4 changed files with 91 additions and 40 deletions
|
@ -2512,6 +2512,8 @@ 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,
|
||||||
|
|
|
@ -2,23 +2,24 @@ 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 world = lifetime_tracker_add(jecs.world())
|
local pe = require("@tools/entity_visualiser").prettify
|
||||||
world:print_snapshot()
|
local world = lifetime_tracker_add(jecs.world(), {padding_enabled=false})
|
||||||
local e = world:entity()
|
local FriendsWith = world:component()
|
||||||
|
local _1 = world:print_snapshot()
|
||||||
local e1 = world:entity()
|
local e1 = world:entity()
|
||||||
world:delete(e)
|
|
||||||
|
|
||||||
world:print_snapshot()
|
|
||||||
local e2 = world:entity()
|
local e2 = world:entity()
|
||||||
world:add(e2, pair(ChildOf, e1))
|
world:delete(e2)
|
||||||
|
|
||||||
|
local _2 = world:print_snapshot()
|
||||||
local e3 = world:entity()
|
local e3 = world:entity()
|
||||||
world:add(e3, pair(ChildOf, e1))
|
world:add(e3, pair(ChildOf, e1))
|
||||||
world:print_snapshot()
|
local e4 = world:entity()
|
||||||
|
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)
|
||||||
world:print_snapshot()
|
local _4 = world:print_snapshot()
|
||||||
world:print_entity_index()
|
world:print_entity_index()
|
||||||
world:entity()
|
world:entity()
|
||||||
world:entity()
|
world:entity()
|
||||||
world:print_snapshot()
|
local _5 = world:print_snapshot()
|
||||||
|
|
|
@ -37,14 +37,7 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@ local ECS_ID = jecs.ECS_ID
|
||||||
local __ = jecs.Wildcard
|
local __ = jecs.Wildcard
|
||||||
local pair = jecs.pair
|
local pair = jecs.pair
|
||||||
|
|
||||||
local pe = require("@tools/entity_visualiser").prettify
|
local prettify = 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)
|
||||||
|
@ -20,37 +23,37 @@ function print_centered_entity(entity, width: number)
|
||||||
print("|" .. centered_str .. "|")
|
print("|" .. centered_str .. "|")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lifetime_tracker_add(world: jecs.World)
|
local function name(world, e)
|
||||||
|
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)}`)
|
|
||||||
|
|
||||||
local idr_t = component_index[pair(__, e)]
|
padding_enabled = opt.padding_enabled
|
||||||
if idr_t then
|
|
||||||
print(`{pe(e)} has the following dependencies:`)
|
|
||||||
for archetype_id in idr_t.cache do
|
|
||||||
local archetype = world.archetypes[archetype_id]
|
|
||||||
local entities = {}
|
|
||||||
for _, dependency in archetype.entities do
|
|
||||||
print(` {pe(dependency)}`)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
world_delete(world, e)
|
local world_entity = world.entity
|
||||||
print(`*deleted {pe(e)}`)
|
|
||||||
end
|
|
||||||
w.entity = function(self)
|
w.entity = function(self)
|
||||||
|
local will_recycle = entity_index.max_id ~= entity_index.alive_count
|
||||||
local e = world_entity(world)
|
local e = world_entity(world)
|
||||||
print(`*created {pe(e)}`)
|
if will_recycle then
|
||||||
|
print(`*recycled {pe(e)}`)
|
||||||
|
else
|
||||||
|
print(`*created {pe(e)}`)
|
||||||
|
end
|
||||||
|
pad()
|
||||||
return e
|
return e
|
||||||
end
|
end
|
||||||
w.print_entity_index = function(self)
|
w.print_entity_index = function(self)
|
||||||
|
@ -77,6 +80,7 @@ local function lifetime_tracker_add(world: jecs.World)
|
||||||
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)
|
||||||
|
@ -150,6 +154,57 @@ local function lifetime_tracker_add(world: jecs.World)
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue