Concord
Concord copied to clipboard
World:query method to filter when needed
This proposal is for a method that allows you to query the World for all entities that match a Filter, and perform an action on them, including modifying/adding/removing Components or even destroying the Entity.
World:query({"position", "ai", "!boss"}, function (entity)
entity:give("something")
end)
The function (callable) could be optional and when not specified, it could return an array containing the Entities, or alternatively if a table is passed instead of a function, it would be filled with said Entities.
WARNING
This method would be far more expensive than just using a Pool in a System, and its main usage would be for things that happen once, for example upgrading the components of deserialized Entities to newer versions, removing all entities that were destroyed in a frame, etc. All this actions may not need their own Pools, since the Entities affected by them are not used repeatedly.
Then again this is NOT a recommended function:
It's expensive
- It needs to loop through all the Entities and perform a Filter check.
Generates Garbage
- A Filter is built in the process.
- The required function will most likely be used once only.
- If a table is returned instead, that table will only be valid at the callsite of the function.