Skip to content

Commit

Permalink
Released KTX 1.9.7-b1. #110
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Nov 2, 2017
2 parents 5ebf487 + cb1ac07 commit 667216c
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 118 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#### 1.9.7-b1

- **[UPDATE]** Updated LibGDX to 1.9.7.
- **[UPDATE]** Updated to Kotlin 1.1.51.
- **[UPDATE]** Updated to Kotlin Coroutines 0.19.3.
- **[UPDATE]** Updated to Gradle 4.3.
- **[BUG]** (`ktx-box2d`) `ChainShape` does not work correctly in LibGDX 1.9.7, and hence is not supported in KTX.
This might break existing applications.

#### 1.9.6-b7

- **[UPDATE]** Updated to Kotlin 1.1.3-2.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Travis CI](https://travis-ci.org/libktx/ktx.svg?branch=master)](https://travis-ci.org/libktx/ktx)
[![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)
[![Kotlin](https://img.shields.io/badge/kotlin-1.1.3--2-orange.svg)](http://kotlinlang.org/)
[![LibGDX](https://img.shields.io/badge/libgdx-1.9.6-red.svg)](https://libgdx.badlogicgames.com/)
[![Kotlin](https://img.shields.io/badge/kotlin-1.1.51-orange.svg)](http://kotlinlang.org/)
[![LibGDX](https://img.shields.io/badge/libgdx-1.9.7-red.svg)](https://libgdx.badlogicgames.com/)

[![KTX](.github/ktx-logo.png "KTX")](http://libktx.github.io)

Expand Down
9 changes: 1 addition & 8 deletions actors/src/test/kotlin/kts/actors/actionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package kts.actors

import com.badlogic.gdx.scenes.scene2d.Action
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction
import ktx.actors.*
import org.junit.Assert.*
import org.junit.Test
Expand Down Expand Up @@ -66,7 +64,6 @@ class ActionsTest {

val sequence = firstAction.then(secondAction) // === firstAction then secondAction

assertTrue(sequence is SequenceAction)
assertEquals(firstAction, sequence.actions[0])
assertEquals(secondAction, sequence.actions[1])
assertEquals(2, sequence.actions.size)
Expand All @@ -81,7 +78,6 @@ class ActionsTest {
// / Note that the second "then" is a different extension function - it prevents from creating multiple sequences.
val sequence = firstAction then secondAction then thirdAction

assertTrue(sequence is SequenceAction)
assertEquals(firstAction, sequence.actions[0])
assertEquals(secondAction, sequence.actions[1])
assertEquals(thirdAction, sequence.actions[2])
Expand All @@ -95,7 +91,6 @@ class ActionsTest {

val parallel = firstAction.parallelTo(secondAction) // === firstAction parallelTo secondAction

assertTrue(parallel is ParallelAction)
assertTrue(firstAction in parallel.actions)
assertTrue(secondAction in parallel.actions)
assertEquals(2, parallel.actions.size)
Expand All @@ -110,7 +105,6 @@ class ActionsTest {
// Note that the second "parallelTo" is a different extension function - it prevents from creating multiple parallels.
val parallel = firstAction parallelTo secondAction parallelTo thirdAction

assertTrue(parallel is ParallelAction)
assertTrue(firstAction in parallel.actions)
assertTrue(secondAction in parallel.actions)
assertTrue(thirdAction in parallel.actions)
Expand All @@ -121,13 +115,12 @@ class ActionsTest {
fun `should create actions repeating forever`() {
val action = MockAction().repeatForever()

assertTrue(action is RepeatAction)
assertEquals(RepeatAction.FOREVER, action.count)
}

/** Action testing utility. */
class MockAction : Action() {
var acted = false
private var acted = false
override fun act(delta: Float): Boolean {
acted = true
return true
Expand Down
9 changes: 1 addition & 8 deletions actors/src/test/kotlin/kts/actors/eventsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import com.badlogic.gdx.Input.Keys
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputEvent.Type.*
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener.FocusEvent
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener.FocusEvent.Type.keyboard
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener.FocusEvent.Type.scroll
Expand All @@ -28,7 +26,6 @@ class EventsTest {

assertNotNull(listener)
assertTrue(listener in actor.listeners)
assertTrue(listener is ChangeListener)
actor.fire(ChangeEvent())
assertTrue(changed)
}
Expand All @@ -42,7 +39,6 @@ class EventsTest {

assertNotNull(listener)
assertTrue(listener in actor.listeners)
assertTrue(listener is ChangeListener)
actor.fire(ChangeEvent())
assertTrue(changed)
}
Expand All @@ -55,7 +51,6 @@ class EventsTest {

assertNotNull(listener)
assertTrue(listener in actor.listeners)
assertTrue(listener is ClickListener)
}

@Test
Expand All @@ -66,7 +61,6 @@ class EventsTest {

assertNotNull(listener)
assertTrue(listener in actor.listeners)
assertTrue(listener is ClickListener)
}

@Test
Expand All @@ -77,7 +71,6 @@ class EventsTest {

assertNotNull(listener)
assertTrue(listener in actor.listeners)
assertTrue(listener is ClickListener)
}

@Test
Expand Down Expand Up @@ -248,7 +241,7 @@ class EventsTest {
assertTrue(focused)
}

@Suppress("unused")
@Suppress("unused", "ClassName")
class `should extend KtxInputListener with no methods overridden` : KtxInputListener() {
// Guarantees all KtxInputListener methods are optional to implement.
}
Expand Down
20 changes: 8 additions & 12 deletions app/src/test/kotlin/ktx/app/gameTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ktx.app

import com.badlogic.gdx.Application
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Graphics
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.utils.GdxRuntimeException
Expand All @@ -18,15 +16,15 @@ import org.junit.Test
class KtxGameTest {
@Before
fun `set up OpenGL`() {
Gdx.gl20 = mock<GL20>()
Gdx.gl20 = mock()
Gdx.gl = Gdx.gl20
}

@Test
fun `should display firstScreen without registration`() {
val screen = mock<Screen>()
val game = KtxGame(firstScreen = screen)
Gdx.graphics = mock<Graphics> {
Gdx.graphics = mock {
on(it.width) doReturn 800
on(it.height) doReturn 600
}
Expand Down Expand Up @@ -162,7 +160,7 @@ class KtxGameTest {
val secondScreen = mock<KtxScreen>()
val game = KtxGame(firstScreen)
game.addScreen(secondScreen)
Gdx.graphics = mock<Graphics> {
Gdx.graphics = mock {
on(it.width) doReturn 800
on(it.height) doReturn 600
}
Expand Down Expand Up @@ -198,7 +196,7 @@ class KtxGameTest {

@Test
fun `should dispose of all registered Screen instances with error handling`() {
Gdx.app = mock<Application>()
Gdx.app = mock()
val screen = mock<Screen>()
val ktxScreen = mock<KtxScreen> {
on(it.dispose()) doThrow GdxRuntimeException("Expected.")
Expand Down Expand Up @@ -229,13 +227,11 @@ class KtxGameTest {

/** [Screen] implementation that tracks how many times it was rendered. */
open class MockScreen : KtxScreen {
var lastDelta = -1f
var rendered = false
var renderedTimes = 0
private var rendered = false
private var renderedTimes = 0

override fun render(delta: Float) {
rendered = true
lastDelta = delta
renderedTimes++
}
}
Expand All @@ -249,10 +245,10 @@ class KtxScreenTest {
fun `should provide mock-up screen instance`() {
val screen = emptyScreen()

assertTrue(screen is Screen)
assertTrue(Screen::class.isInstance(screen))
}

@Suppress("unused")
@Suppress("unused", "ClassName")
class `should implement KtxScreen with no methods overridden` : KtxScreen {
// Guarantees all KtxScreen methods are optional to implement.
}
Expand Down
1 change: 1 addition & 0 deletions assets/src/test/kotlin/ktx/assets/assetsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.junit.Test
/**
* Tests asset-related utilities and [AssetManager] extensions.
*/
@Suppress("USELESS_IS_CHECK") // Explicitly checking loaded asset types.
class AssetsTest {
val assetManager: AssetManager = managerWithMockAssetLoader()

Expand Down
6 changes: 3 additions & 3 deletions async/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Kotlin](https://img.shields.io/badge/kotlin--coroutines-0.17-orange.svg)](http://kotlinlang.org/)
[![Kotlin](https://img.shields.io/badge/kotlin--coroutines-0.19.3-orange.svg)](http://kotlinlang.org/)

# KTX: coroutines support and threading utilities

Expand Down Expand Up @@ -116,7 +116,7 @@ class Application: ApplicationAdapter() {
}
```

**KTX** `AssetStorage`:
The same use case rewritten with **KTX** `AssetStorage`:

```Kotlin
class Application: ApplicationAdapter() {
Expand Down Expand Up @@ -145,7 +145,7 @@ class Application: ApplicationAdapter() {

Feature | `AssetStorage` | `AssetManager`
--- | --- | ---
*Asynchronous loading* | **Supported.** Asset loading is performed on a separate thread, while the main rendering thread is suspended (_not blocked_) and resumed once the asset is fully loaded | **Supported.** All assets are loaded on a separate thread and are available after the loading is finished.
*Asynchronous loading* | **Supported.** Asset loading is performed on a separate thread, while the action on main rendering thread is suspended (_not blocked_) and resumed once the asset is fully loaded. | **Supported.** All assets are loaded on a separate thread and are available after the loading is finished.
*Synchronous loading* | **Limited.** A blocking coroutine can be launched to load assets eagerly, but it cannot block the rendering thread. | **Limited.** `finishLoading(String fileName)` method can be used to block the thread until the asset is loaded, but since it has no effect on loading order, all _other_ assets can be loaded before the requested one.
*Error handling* | **Build-in language syntax.** Use a regular try-catch block within coroutine body to handle loading errors. Provides a clean way to separately handle exceptions thrown by different assets. | **Via listener.** One can register a global error handling listener that will be notified if a loading exception is thrown.
*Loading order* | **Controlled by the user.** `AssetStorage` starts loading assets as soon as the `load` method is called, giving the user full control over the order of asset loading. | **Unpredictable.** If multiple assets are scheduled at once it is difficult to reason about loading order. `finishLoading` has no effect on loading order.
Expand Down
1 change: 1 addition & 0 deletions async/src/test/kotlin/ktx/async/assets/assetsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.badlogic.gdx.utils.Array as GdxArray
/**
* Tests [AssetStorage]: coroutines-based asset manager.
*/
@Suppress("USELESS_IS_CHECK") // Explicitly checking loaded asset types.
class AssetStorageTest {
@Test
fun `should load text assets`() = `coroutine test`(concurrencyLevel = 1) { ktxAsync ->
Expand Down
28 changes: 18 additions & 10 deletions async/src/test/kotlin/ktx/async/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,32 @@ fun `with timer`(
scheduler.schedule(task, (delay * 1000f).toLong(), MILLISECONDS)
},
test: (Timer) -> Unit) {
// Tries to replace the default Timer instance used by LibGDX by our mock-up implementation. LibGDX is a pain to mock.
val timerClass = Timer::class.java
val timer = mock<Timer> {
on(it.scheduleTask(any(), any())) doAnswer {
it.getArgument<Task>(0).apply {
onSchedule(this, it.getArgument(1))
}
}
}
Timer::class.java.getDeclaredField("instance").let {
it.isAccessible = true
it.set(null, timer)
timerClass.getDeclaredMethod("thread").apply {
isAccessible = true
invoke(null)
}
val threadField = timerClass.getDeclaredField("thread").apply {
isAccessible = true
}
val thread = threadField.get(null)
val threadClass = thread.javaClass
val timerField = threadClass.getDeclaredField("instance").apply {
isAccessible = true
}
timerField.set(thread, timer)
try {
test(timer)
} finally {
Timer::class.java.getDeclaredField("instance").let {
it.isAccessible = true
it.set(null, null)
}
timerField.set(thread, null)
}
}

Expand Down Expand Up @@ -104,7 +112,7 @@ fun `coroutine test`(
try {
KtxAsync.coroutine(it)
testStatuses[coroutine] = TestStatus.FINISHED
} catch(exception: Throwable) {
} catch (exception: Throwable) {
error.set(exception)
testStatuses[coroutine] = TestStatus.FAILED
}
Expand Down Expand Up @@ -165,9 +173,9 @@ fun `cancelled coroutine test`(
try {
KtxAsync.coroutine(it)
testStatus.set(TestStatus.FINISHED)
} catch(exception: CancellationException) {
} catch (exception: CancellationException) {
cancellationExceptionThrown = true
} catch(exception: Throwable) {
} catch (exception: Throwable) {
error.set(exception)
testStatus.set(TestStatus.FAILED)
}
Expand Down
Loading

0 comments on commit 667216c

Please sign in to comment.