Skip to content

Commit

Permalink
KTX 1.10.0-b2 release. #373
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Aug 4, 2021
2 parents 8c85207 + 2f3c876 commit 7c2730f
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 207 deletions.
2 changes: 2 additions & 0 deletions .github/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Project contributors listed chronologically.
* Contributed utilities to the [graphics module](../graphics).
* [@auraxangelic](https://github.com/auraxangelic)
* Tested KTX on iOS and documented RoboVM issue with Kotlin coroutines.
* [@RedGrapefruit09](https://github.com/RedGrapefruit09)
* Updated the project from Gradle 6 to Gradle 7.

### Metrics

Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
_See also: [the official LibGDX changelog](https://github.com/libgdx/libgdx/blob/master/CHANGES)._

#### 1.10.0-b2

- **[UPDATE]** Updated to Gradle 7.0.2.
- **[UPDATE]** Updated to Kotlin 1.5.21.
- **[UPDATE]** Updated to Kotlin Coroutines 1.5.1.
- **[UPDATE]** Updated to VisUI 1.5.0.
- **[CHANGE]** The JVM target compatibility of all modules was set to `1.8`, since Java `1.6` target was deprecated
and is incompatible with the latest coroutines library. Note that source compatibility level is still set to `1.7`.
- **[FEATURE]** (`ktx-assets`) Added `discard` lambda parameter to the `pool` factory method that is invoked after
an object is rejected from the created `Pool`.
- **[FEATURE]** (`ktx-scene2d`) Added support for `ParticleEffectActor` in Scene2D DSL via `particleEffect` factory method.
- **[FEATURE]** (`ktx-log`) Added `DEBUG`, `INFO` and `ERROR` constants with default logger tags.
- **[CHANGE]** (`ktx-log`) Default tags are no longer wrapped in square brackets. This caused a change of the logs structure.
- **[CHANGE]** (`ktx-log`) `Logger.tag` variable was renamed to `Logger.name`.
- **[CHANGE]** (`ktx-log`) Log prefix variables from `Logger` were removed. Message tags are now configurable directly through the constructor.
- **[CHANGE]** (`ktx-log`) Logger name is no longer a part of the message tag. Instead, it is now prepended to the message.
This causes a change of the logs structure.
- **[FEATURE]** (`ktx-log`) Added `Logger.buildMessage` method that allows to modify logged message structure. This method
can be overridden when extending the `Logger` class, simplifying the usage of custom message formats.

#### 1.10.0-b1

- **[UPDATE]** Updated to LibGDX 1.10.0.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![GitHub Build](https://github.com/libktx/ktx/workflows/build/badge.svg)](https://github.com/libktx/ktx/actions?query=workflow%3Abuild)
[![Kotlin](https://img.shields.io/badge/kotlin-1.4.32-orange.svg)](http://kotlinlang.org/)
[![Kotlin](https://img.shields.io/badge/kotlin-1.5.21-orange.svg)](http://kotlinlang.org/)
[![LibGDX](https://img.shields.io/badge/libgdx-1.10.0-red.svg)](https://libgdx.com/)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.libktx/ktx-async.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.libktx%22)

Expand Down Expand Up @@ -75,7 +75,7 @@ in your `build.gradle` file:
```Groovy
ext {
// Update this version to match the latest KTX release:
ktxVersion = '1.10.0-b1'
ktxVersion = '1.10.0-b2'
}
dependencies {
Expand Down
4 changes: 2 additions & 2 deletions assets-async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ class App : ApplicationAdapter() {
```

As a rule of thumb, you should use suspending `AssetStorage` methods only from non-blocking coroutines, e.g. those
launched with `KtxAsync.launch` or `GlobalScope.launch`. If you change `runBlocking` to a proper coroutine launch
in either of the examples, you will notice that the deadlocks no longer occur.
launched with `KtxAsync.launch`. If you change `runBlocking` to a proper coroutine launch in either of the examples,
you will notice that the deadlocks no longer occur.

It does not mean that `runBlocking` will always cause a deadlock, however. You can safely use `runBlocking`:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ktx.assets.async

import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -229,6 +230,7 @@ class LoadingProgressTest {
}

@Test
@OptIn(DelicateCoroutinesApi::class)
fun `should handle concurrent updates`() {
// Given:
val progress = LoadingProgress()
Expand All @@ -253,6 +255,7 @@ class LoadingProgressTest {
}

@Test
@OptIn(DelicateCoroutinesApi::class)
fun `should handle concurrent registration and removal`() {
// Given:
val progress = LoadingProgress()
Expand All @@ -277,8 +280,8 @@ class LoadingProgressTest {

// Then:
runBlocking { jobs.joinAll() }
assertEquals(900 - 600, progress.total)
assertEquals(500 - 200, progress.loaded)
assertEquals(250 - 200, progress.failed)
assertEquals((900 - 600), progress.total)
assertEquals((500 - 200), progress.loaded)
assertEquals((250 - 200), progress.failed)
}
}
14 changes: 13 additions & 1 deletion assets/src/main/kotlin/ktx/assets/pools.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ktx.assets

import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.Pool

/**
Expand All @@ -21,10 +22,21 @@ operator fun <Type> Pool<Type>.invoke(free: Type) = this.free(free)
/**
* @param initialCapacity initial size of the backing collection.
* @param max max amount stored in the pool. When exceeded, freed objects are no longer accepted.
* @param discard invoked each time an object is rejected or removed from the pool. This might happen if an object is
* freed with [Pool.free] or [Pool.freeAll] if the pool is full, or when [Pool.clear] is called. Optional, defaults
* to no operation. If the objects are [Disposable], this lambda might be used to dispose of them.
* @param provider creates instances of the requested objects.
* @return a new [Pool] instance, creating the object with the passed provider.
*/
inline fun <Type> pool(initialCapacity: Int = 16, max: Int = Int.MAX_VALUE, crossinline provider: () -> Type): Pool<Type> =
inline fun <Type> pool(
initialCapacity: Int = 16,
max: Int = Int.MAX_VALUE,
crossinline discard: (Type) -> Unit = {},
crossinline provider: () -> Type,
): Pool<Type> =
object : Pool<Type>(initialCapacity, max) {
override fun newObject(): Type = provider()
override fun discard(element: Type) {
discard(element)
}
}
31 changes: 28 additions & 3 deletions assets/src/test/kotlin/ktx/assets/PoolsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,70 @@ import org.junit.Test
class PoolsTest {
@Test
fun `should invoke pool as no parameter function to provide instances`() {
// Given:
val pool = MockPool()

val instance = pool() // Should work as "obtain".
// When: Pool is called as a function.
val instance = pool()

// Then: Should work as "obtain":
assertNotNull(instance)
pool.free(instance)
assertSame(instance, pool()) // Since the object was freed, pool should return the same instance.
}

@Test
fun `should invoke pool as one parameter function to return instances`() {
// Given:
val pool = MockPool()
val instance = pool.obtain()

pool(instance) // Should work as "free".
// When: Pool is called as a function with object parameter.
pool(instance)

// Then: Should work as "free".
assertEquals(1, pool.free)
assertSame(instance, pool.obtain()) // Since the object was freed, pool should return the same instance.
}

@Test
fun `should create new pools with custom providers`() {
// Given: A pool that always returns the same instance:
val provided = "10"
val pool = pool { provided } // Always returns `provided` string.
val pool = pool { provided }

// When:
val obtained = pool()

// Then:
assertSame(provided, obtained)
}

@Test
fun `should honor max setting`() {
// Given:
val pool = pool(max = 5) { "Mock." }

// When:
for (index in 1..10) pool.free("Value.")

// Then:
assertEquals(5, pool.free)
}

@Test
fun `should create new pools with a custom discard function`() {
// Given: A pool that adds discarded objects to a list:
val discarded = mutableListOf<String>()
val pool = pool(max = 5, discard = { discarded.add(it) }) { "Mock." }

// When:
for (index in 1..10) pool.free("Value$index")

// Then:
assertEquals(listOf("Value6", "Value7", "Value8", "Value9", "Value10"), discarded)
}

/**
* Provides new [Any] instances.
*/
Expand Down
2 changes: 1 addition & 1 deletion async/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Kotlin Coroutines](https://img.shields.io/badge/kotlin--coroutines-1.4.3-orange.svg)](http://kotlinlang.org/)
[![Kotlin Coroutines](https://img.shields.io/badge/kotlin--coroutines-1.5.1-orange.svg)](http://kotlinlang.org/)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.libktx/ktx-async.svg)](https://search.maven.org/artifact/io.github.libktx/ktx-async)

# KTX: coroutines support and threading utilities
Expand Down
2 changes: 2 additions & 0 deletions async/src/test/kotlin/ktx/async/KtxAsyncTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ktx.async

import com.badlogic.gdx.Gdx
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.cancel
Expand All @@ -17,6 +18,7 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong

@OptIn(DelicateCoroutinesApi::class)
class KtxAsyncTest : AsyncTest() {
@Test
fun `should execute tasks on the main rendering thread when launched via KtxAsync`() {
Expand Down
2 changes: 2 additions & 0 deletions async/src/test/kotlin/ktx/async/dispatchersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Timer
import com.badlogic.gdx.utils.async.AsyncExecutor
import com.nhaarman.mockitokotlin2.verify
import io.kotlintest.mock.mock
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Runnable
import kotlinx.coroutines.async
Expand All @@ -24,6 +25,7 @@ import java.util.concurrent.atomic.AtomicLong
/**
* Base class with coroutine dispatcher tests.
*/
@OptIn(DelicateCoroutinesApi::class)
abstract class CoroutineDispatcherTest : AsyncTest() {
abstract val tested: KtxDispatcher
abstract fun getExecutorThread(): Thread
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ subprojects {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_7 // For RoboVM compatibility.
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.6" // 1.7 is unsupported.
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/ktx/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ktx

const val gdxVersion = "1.10.0"
const val kotlinCoroutinesVersion = "1.4.3"
const val kotlinCoroutinesVersion = "1.5.1"

const val ashleyVersion = "1.7.4"
const val visUiVersion = "1.4.11"
const val visUiVersion = "1.5.0"

const val spekVersion = "1.2.1"
const val kotlinTestVersion = "2.0.7"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
libGroup=io.github.libktx

kotlinVersion=1.4.32
kotlinVersion=1.5.21

junitPlatformVersion=1.2.0
dokkaVersion=1.4.30
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 7c2730f

Please sign in to comment.