mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 20:33:54 -04:00
Initial commit
This commit is contained in:
commit
58549d6b0a
14 changed files with 665 additions and 0 deletions
57
fluid/pool.lua
Normal file
57
fluid/pool.lua
Normal file
|
@ -0,0 +1,57 @@
|
|||
local Pool = {}
|
||||
Pool.__index = Pool
|
||||
|
||||
function Pool.new(name, filter)
|
||||
local pool = setmetatable({
|
||||
__filter = filter,
|
||||
__name = name,
|
||||
}, Pool)
|
||||
|
||||
return pool
|
||||
end
|
||||
|
||||
function Pool:eligible(e)
|
||||
for _, component in ipairs(self.__filter) do
|
||||
if not e.components[component] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Pool:add(e)
|
||||
local key = #self + 1
|
||||
|
||||
self[key] = e
|
||||
e.keys[self] = key
|
||||
end
|
||||
|
||||
function Pool:has(e)
|
||||
return e.keys[self] and true
|
||||
end
|
||||
|
||||
function Pool:remove(e, pool)
|
||||
local key = e.keys[self]
|
||||
|
||||
if key then
|
||||
local count = #self
|
||||
|
||||
if key == count then
|
||||
self[key] = nil
|
||||
e.keys[self] = nil
|
||||
else
|
||||
local swap = self[count]
|
||||
|
||||
self[key] = swap
|
||||
self[count] = nil
|
||||
swap.keys[self] = key
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable(Pool, {
|
||||
__call = function(_, ...) return Pool.new(...) end,
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue