32 lines
777 B
Lua
32 lines
777 B
Lua
local ecs = require("tiny-ecs")
|
|
|
|
ecs.init = function()
|
|
print("[i] loading ecs")
|
|
baseEntify = ecs.processingSystem()
|
|
baseEntify.filter = ecs.rejectAll('commit')
|
|
baseEntify.updatethread = true
|
|
function baseEntify:onAdd(obj)
|
|
|
|
obj.commit = api.util.commit( api.world, obj, api )
|
|
api.world.commit = api.util.commit( api.world, false, api)
|
|
api.world.get = function(filter)
|
|
local found = false
|
|
foreach( api.world.entities, function(k,obj)
|
|
if type(obj) == 'table' then
|
|
if filter(obj) then found = obj end
|
|
end
|
|
end)
|
|
return found
|
|
end
|
|
|
|
end
|
|
ecs.addSystem( api.world, baseEntify )
|
|
end
|
|
|
|
ecs.clear = function()
|
|
api.ext.exec("onClear")
|
|
api.ecs.clearEntities( api.world )
|
|
api.world.commit()
|
|
end
|
|
|
|
return ecs
|