Skip to content

Conversation

@tylerwilbanks
Copy link
Contributor

@tylerwilbanks tylerwilbanks commented Oct 1, 2025

The Problem

EMPTY_COMPARATOR is private, so I must write this:

private val EMPTY_COMPARATOR = EntityComparator { _, _ -> 0 }

abstract class SockIteratingSystem(
    family: Family,
    comparator: Comparator<Entity> = EMPTY_COMPARATOR,

This does a weird thing with jetbrains IDEs with

import com.github.quillraven.fleks.collection.EntityComparator

Saying it is unsused, but if I remove the import,

image

so I must:

image

The Why

In my personal game engine, I am creating my own abstraction off of IteratingSystem like so:

import com.github.quillraven.fleks.collection.EntityComparator
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel

private val EMPTY_COMPARATOR = EntityComparator { _, _ -> 0 }

abstract class SockIteratingSystem(
    family: Family,
    comparator: Comparator<Entity> = EMPTY_COMPARATOR,
    sortingType: SortingType = Automatic,
    interval: Interval = EachFrame,
    enabled: Boolean = true,
    systemDispatcher: CoroutineDispatcher = inject(InjectionKey.SockSystemDispatcher.name),
): IteratingSystem(
    family = family,
    comparator = comparator,
    sortingType = sortingType,
    interval = interval,
    enabled = enabled,
) {

    protected val systemScope: CoroutineScope = CoroutineScope(systemDispatcher + SupervisorJob())

    override fun onDispose() {
        super.onDispose()
        systemScope.cancel()
    }
}

This class makes it easy for me to subscribe to events with automatic cleanup onDispose(). Example:

class SystemUIClick: SockIteratingSystem(
    family = family { all(ComponentUITransform, ComponentUIClickable) },
) {

    init {
        SockEngineEventBroadcaster
            .clickableEvent
            .onEach { event ->
                when (event) {
                    is SockEngineEvent.ClickableLifecycle.ClickableCreated -> {
                        event.entity.configure {
                            it += ComponentUIClickable(
                                clickable = event.clickable,
                            )
                        }
                    }

                    is SockEngineEvent.ClickableLifecycle.ClickableDestroyed -> {
                        event.entity.configure {
                            it -= ComponentUIClickable
                        }
                    }
                }
            }
            .launchIn(systemScope)
    }

The Solution

Just make EMPTY_COMPARATOR public, so I don't have to shadow what you did!

@Quillraven Quillraven merged commit 3b7bcc9 into Quillraven:master Oct 2, 2025
4 checks passed
@Quillraven
Copy link
Owner

Fine by me :) Should be available in the SNAPSHOT version soon

@tylerwilbanks
Copy link
Contributor Author

Fine by me :) Should be available in the SNAPSHOT version soon

Where will I be able to find the snapshot?

I see here: https://central.sonatype.com/repository/maven-snapshots/io/github/quillraven/fleks/Fleks/maven-metadata.xml
There is a 2.13-SNAPSHOT with a last updated timestamp of 20250823224620 which is August, so I see it isn't updated yet.

Oh, there is an issue with browsing snapshots on sonatype's side haha.

image

I guess I'll check back in a few days and see if snapshot browsing is back up on sonatype's website.

Anyways, thanks so much for the PR approval and awesome library! I love fleks and your vids on youtube!

@Quillraven
Copy link
Owner

@tylerwilbanks note that with the last release the snapshot url has changed to:

https://central.sonatype.com/repository/maven-snapshots/

@Quillraven Quillraven added the enhancement New feature or request label Nov 29, 2025
@Quillraven Quillraven added this to the 2.13 milestone Nov 29, 2025
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