new partition and partitionTo function for entity bag #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
also fixes a test that breaks with wasm (ComponentHolderById). Looks like in the WASM tests the id of the component was 2 instead of 0. Using the component's real ID is anyway cleaner.
This PR was created to simplify a certain problem that I faced in QuillyJumper for the render system. I needed to iterate over an index of entities of a family in the render system (background entities, normal entities and foreground entities).
Between those entity render calls I also had the tiledmap render calls. I solved it by simply introducing entity tags and tag background and foreground entities with a bgd and fgd tag. The RenderSystem then had three separate families for foreground, normal and background entities.
While that worked, I did not like it a lot.
Giving a family the possibility to iterate from index A to index B might also not be that useful and maybe even tricky to implement (not sure).
That's why I came up with the idea to use the partition function of Kotlin (which actually could also be solved by using filter calls e.g.).
The new solution to my RenderSystem now is to have just one family of entities, sort them at the beginning of the system's onTick function (=normal behavior = good :) ) and then split that family into three parts (=partition):
I will use the new
partitionTo
function for that to avoid creating new collections each frame.In my scenario this should simplify the RenderSystem and also make it faster because I just have one family and one sort call instead of three families with three separate sort calls.