Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tiny.filterWorld function #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tiny.lua
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,25 @@ function tiny.getSystemCount(world)
return #world.systems
end

--- Gets entities according to filter (not in base)
function tiny.filterWorld(world, filter)
local t = {}
for i = 1, #(world.entities) do
if ((not filter) or filter(world, world.entities[i])) then
table.insert(t, world.entities[i])
end
end
local index = 0
return function()
index = index + 1
if index <= #t then
return t[index]
end
end
end



--- Sets the index of a System in the World, and returns the old index. Changes
-- the order in which they Systems processed, because lower indexed Systems are
-- processed first. Returns the old system.index.
Expand Down Expand Up @@ -854,7 +873,9 @@ worldMetaTable = {
clearSystems = tiny.clearSystems,
getEntityCount = tiny.getEntityCount,
getSystemCount = tiny.getSystemCount,
setSystemIndex = tiny.setSystemIndex
setSystemIndex = tiny.setSystemIndex,

filterWorld = tiny.filterWorld
},
__tostring = function()
return "<tiny-ecs_World>"
Expand Down