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

new partition and partitionTo function for entity bag #141

Merged
merged 1 commit into from
May 6, 2024

Conversation

Quillraven
Copy link
Owner

@Quillraven Quillraven commented May 6, 2024

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):

  • entities with z-index < 0 (background)
  • entities with z-index = 0
  • entities with z-index > 0 (foreground)

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.

@Quillraven Quillraven added the enhancement New feature or request label May 6, 2024
@Quillraven Quillraven added this to the 2.7 milestone May 6, 2024
@Quillraven Quillraven merged commit 69c7d5c into master May 6, 2024
4 checks passed
@Quillraven Quillraven deleted the entitybag-partition branch May 6, 2024 15:04
@Quillraven Quillraven mentioned this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant