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

Make iterating system private sorting-related fields protected. #133

Merged

Conversation

metaphore
Copy link
Contributor

Here's a small change that allows for fully custom IteratingSystem.onTick() implementations.

It happened so I needed to modify the entity processing flow of the IteratingSystem by inserting one extra call right after the sorting is done and before the entity iteration. Like this:

override fun onTick() {
        if (doSort) {
            doSort = sortingType == Automatic
            family.sort(comparator)
        }
        
        // Do something here.

        family.forEach { onTickEntity(it) }
}

But it turns out, that I cannot fully replicate the original logic as the sorting-related fields are private.

@Quillraven
Copy link
Owner

What about extracting the sorting logic to a separate open fun onSort() method? That way you could more easily add logic before and after sorting. I personally don't like that logic has to be "copy & pasted" when overriding something because it could happen that the original source changes and then you need to be aware of that and also adjust your code.

It is safer to do something like:

override fun onTick() {
  // either add stuff here ...
  super.onSort() // <-- this can also be skipped by users if they never care about sorting in their system
  // ... or here ...
  family.forEach{ onTickEntity(it) }
  // ... or here
}

@metaphore
Copy link
Contributor Author

Yep, a great idea!

@metaphore metaphore force-pushed the feature/protected-sort-fields branch from 66c7275 to 538b483 Compare December 3, 2023 17:31
@Quillraven Quillraven added this to the 2.6 milestone Dec 3, 2023
@Quillraven Quillraven added the enhancement New feature or request label Dec 3, 2023
@Quillraven Quillraven merged commit e00a8ce into Quillraven:master Dec 3, 2023
4 checks passed
@metaphore metaphore deleted the feature/protected-sort-fields branch December 3, 2023 18:34
@Quillraven Quillraven mentioned this pull request Dec 12, 2023
3 tasks
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.

2 participants