libktx / ktx

Kotlin extensions for the libGDX game framework
https://libktx.github.io/
Creative Commons Zero v1.0 Universal
1.37k stars 74 forks source link

KTX pool's discard logic is inconsistent with the original Pool.discard(T) #476

Closed metaphore closed 9 months ago

metaphore commented 9 months ago

It seems like #363 brought a little inconsistency in how the pool discard logic works.

This is what the original discard method looks like:

protected void discard (T object) {
    reset(object);
}

And here's KTX:

override fun discard(element: Type) {
    discard(element)
}

So basically the reset call is gone and the default discard parameter to the KTX pool method is not replicating that logic. I don't think it's possible to call the same reset instance method from the default discard lambda parameter. So maybe adding an overload to the pool method without the discard parameter and without the discard(T) method override would be a good solution.

czyzby commented 9 months ago

You are right, adding the reset call would be problematic even if the lambda was given a Pool receiver, since it's a protected function. However, it's pretty easy to implement - all it does is calling reset on any object implementing the Poolable interface. I'll change it so that the default discard lambda attempts to reset the Poolable objects.

czyzby commented 9 months ago

Should be available in the snapshot version shortly. Cheers.