Concord
Concord copied to clipboard
Sorting Pools
Sorting Pools before looping through the Entities could be useful for rendering and collision checks.
The feature can be easily added to Lists and Pools would inherit it.
I have already implemented this at a00ee08
Hi, where is it possible to see an exemple on how to use this ? The main read-me do not talk about this amazing feature.
Thanks for the amazing library.
Yes, this can already be used in the dev
branch. It's really simple to use:
function RenderSystem:draw () --An event in one of your systems
--self.pool is the Pool we want to sort
self.pool:sort(function (e1, e2)
return e1.zindex > e2.zindex
end)
-- Your renderer code goes here
end
The sort function has the same signature as table.sort
(since that's used internally)
Thanks, amazing !
When will this be available in the stable branch ?
Thanks
Once we complete the 4.0 Milestone, we will do a big release. It will probably happen this month, since most of those features are already implemented, and only Entity IDs (#38) and World:query (#44) are missing.
If you are watching the repository, you will most likely receive a notification on the new release, otherwise you can jump over to our Discord server to get notified once the new version is announced.
Yes, this can already be used in the
dev
branch. It's really simple to use:function RenderSystem:draw () --An event in one of your systems --self.pool is the Pool we want to sort self.pool:sort(function (e1, e2) return e1.zindex > e2.zindex end) -- Your renderer code goes here end
Hello,
Just one quick question about this exemple. What does e1 and e2 stands for? I just can't wrap my head around the way this sort actually works.
Thanks
e1 and e2 are the entities in the pool that are currently to be sorted
Ah ok,
I thought that was something I need to replace.
Thanks for your answer.
As said in my original comment, it works the same was as table.sort
. In the sorting function (also called order function) receive two elements (in this case two Entities) of the Pool and you need to compare them and return a true
/false
value.
If you return true
then the first element will appear before the second element.
If you return false
then the second element will appear before the first element.
Indeed I should have made a bit of research before asking.
Is there any performances drawbacks to sort pools right in the draw function ?
Should be fairly cheap since it will only happen once per frame, but it will also depend on the number of entities