mirror of
https://github.com/Ukendio/jecs.git
synced 2025-11-18 17:22:52 +00:00
* Initial commit * Add tests * Dedup observers * Handle filters on table creation * Handle Archetype deletion * Remove print * Fix type errors * Cleanup code * Manually inline code * Build terms for cached queries * Specialized cached query iterator * Remove shadowed variable * Inverse statement * Rework demo * Fix metatable * Use generalized iteration
26 lines
529 B
Text
26 lines
529 B
Text
local world = require(script.Parent.world)
|
|
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
|
local refs: {[any]: jecs.Entity} = {}
|
|
|
|
local function fini(key): () -> ()
|
|
return function()
|
|
refs[key] = nil
|
|
end
|
|
end
|
|
|
|
local function noop() end
|
|
|
|
local function ref(key): (jecs.Entity, () -> ())
|
|
if not key then
|
|
return world:entity(), noop
|
|
end
|
|
local e = refs[key]
|
|
if not e then
|
|
e = world:entity()
|
|
refs[key] = e
|
|
end
|
|
-- Cannot cache handles because they will get invalidated
|
|
return e, fini(key)
|
|
end
|
|
|
|
return ref
|