mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Add cleanup for ref
This commit is contained in:
parent
fb218dc419
commit
a4fe3b29d1
2 changed files with 11 additions and 3 deletions
|
@ -8,8 +8,9 @@ local components: {
|
||||||
Model: Entity<Model>,
|
Model: Entity<Model>,
|
||||||
Player: Entity,
|
Player: Entity,
|
||||||
Target: Entity,
|
Target: Entity,
|
||||||
Transform: Entity<{ old: CFrame, new: CFrame }>,
|
Transform: Entity<CFrame>,
|
||||||
Velocity: Entity<number>,
|
Velocity: Entity<number>,
|
||||||
|
Previous: Entity,
|
||||||
} = {
|
} = {
|
||||||
Character = world:component(),
|
Character = world:component(),
|
||||||
Mob = world:component(),
|
Mob = world:component(),
|
||||||
|
@ -18,6 +19,7 @@ local components: {
|
||||||
Target = world:component(),
|
Target = world:component(),
|
||||||
Transform = world:component(),
|
Transform = world:component(),
|
||||||
Velocity = world:component(),
|
Velocity = world:component(),
|
||||||
|
Previous = world:component(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return table.freeze(components)
|
return table.freeze(components)
|
||||||
|
|
|
@ -2,7 +2,13 @@ local world = require(script.Parent.world)
|
||||||
local handle = require(script.Parent.handle)
|
local handle = require(script.Parent.handle)
|
||||||
local refs = {}
|
local refs = {}
|
||||||
|
|
||||||
local function ref(key)
|
local function fini(e, key)
|
||||||
|
return function()
|
||||||
|
refs[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ref(key): (handle.Handle, (() -> ())?)
|
||||||
if not key then
|
if not key then
|
||||||
return handle(world:entity())
|
return handle(world:entity())
|
||||||
end
|
end
|
||||||
|
@ -12,7 +18,7 @@ local function ref(key)
|
||||||
refs[key] = e
|
refs[key] = e
|
||||||
end
|
end
|
||||||
-- Cannot cache handles because they will get invalidated
|
-- Cannot cache handles because they will get invalidated
|
||||||
return handle(e)
|
return handle(e), fini(e, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ref
|
return ref
|
||||||
|
|
Loading…
Reference in a new issue