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>,
|
||||
Player: Entity,
|
||||
Target: Entity,
|
||||
Transform: Entity<{ old: CFrame, new: CFrame }>,
|
||||
Transform: Entity<CFrame>,
|
||||
Velocity: Entity<number>,
|
||||
Previous: Entity,
|
||||
} = {
|
||||
Character = world:component(),
|
||||
Mob = world:component(),
|
||||
|
@ -18,6 +19,7 @@ local components: {
|
|||
Target = world:component(),
|
||||
Transform = world:component(),
|
||||
Velocity = world:component(),
|
||||
Previous = world:component(),
|
||||
}
|
||||
|
||||
return table.freeze(components)
|
||||
|
|
|
@ -2,7 +2,13 @@ local world = require(script.Parent.world)
|
|||
local handle = require(script.Parent.handle)
|
||||
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
|
||||
return handle(world:entity())
|
||||
end
|
||||
|
@ -12,7 +18,7 @@ local function ref(key)
|
|||
refs[key] = e
|
||||
end
|
||||
-- Cannot cache handles because they will get invalidated
|
||||
return handle(e)
|
||||
return handle(e), fini(e, key)
|
||||
end
|
||||
|
||||
return ref
|
||||
|
|
Loading…
Reference in a new issue