Skip to content

Commit

Permalink
Released 1.9.6-b6. #89
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Jun 22, 2017
2 parents ae52bd8 + e1fa1ae commit e806250
Show file tree
Hide file tree
Showing 39 changed files with 216 additions and 162 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.bat eol=crlf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jdk:
- oraclejdk8

install: ./gradlew assemble install -x dokka -x dokkaJavadoc
script: ./gradlew check -x dokka -x dokkaJavadoc
script: ./gradlew check

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#### 1.9.6-b6

- **[UPDATE]** Updated to Gradle 4.0.
- **[UPDATE]** Updated to Ashley 1.7.3.
- **[CHANGE]** (`ktx-ashley`) Extensions updated to support `Engine` base class additionally to the `PooledEngine`.
- `Engine.add` and `Engine.entity` extension methods to replace `PooledEngine` equivalents.
- Changed `PooledEntity` to `EngineEntity`, wrapping `Entity` and providing access to `Engine` API.
- **[CHANGE]** (`ktx-async`) `TextAssetLoader` now extends `AsynchronousAssetLoader` instead of `SynchronousAssetLoader`.
- **[FIX]** (`ktx-async`) `AssetStorage` now correctly handles `SynchronousAssetLoader` instances on the main rendering thread.

#### 1.9.6-b5

- **[UPDATE]** Updated to Kotlin 1.1.2-5.
Expand Down
4 changes: 2 additions & 2 deletions actors/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
testCompile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/ktx/app/application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class KotlinApplication(protected val fixedTimeStep: Float = 1f / 60f,
* since the last [render] call in case of subsequent [render] calls on devices unable to run the application at the
* chosen time step rate.*/
protected var timeSinceLastRender = 0f
private set
private set

override fun resize(width: Int, height: Int) {
}
Expand Down
4 changes: 2 additions & 2 deletions ashley/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ builder DSL.

`ktx-ashley` provides the following extensions and utilities:

- `PooledEngine.add` and `PooledEngine.entity` extension methods provide type-safe building DSL for creating pooled `Entities`.
- `PooledEntity` is an `Entity` wrapper that allows to create `Component` instances using using the `PooledEngine` via
- `Engine.add` and `Engine.entity` extension methods provide type-safe building DSL for creating `Entities`.
- `EngineEntity` is an `Entity` wrapper that allows to create `Component` instances using using the `Engine` via
`with` methods.
- `mapperFor` factory method allows to create `ComponentMapper` instances.
- Accessors for `Entity` objects using `ComponentMappers`: `get`, `has`, `hasNot`, `remove`.
Expand Down
81 changes: 81 additions & 0 deletions ashley/src/main/kotlin/ktx/ashley/engines.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ktx.ashley

import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.Engine
import com.badlogic.ashley.core.Entity

/**
* Get or create a [Component] by calling [Engine.createComponent].
*
* @param T the type of [Component] to get or create.
* @param configure inlined function with [T] as the receiver to allow further configuration.
* @return an [Component] instance of the selected type.
*/
inline fun <reified T : Component> Engine.create(configure: T.() -> Unit): T = create<T>().also(configure)

/**
* Get or create a [Component] by calling [Engine.createComponent].
*
* @param T the type of [Component] to get or create.
* @return an [Component] instance of the selected type.
*/
inline fun <reified T : Component> Engine.create(): T = createComponent(T::class.java)

/**
* An [Entity] created by the provided [Engine].
*
* Provides methods for adding [Component]s to the [Engine] and the [Entity].
*
* @property engine the [Engine] providing [Components][Component].
* @property entity the [Entity] to add [Components][Component] to.
*/
@AshleyDsl
class EngineEntity(
val engine: Engine,
val entity: Entity) {
/**
* Get or creates an instance of the component [T] and adds it to this [entity][EngineEntity].
*
* @param T the [Component] type to get or create.
* @param configure inlined function with [T] as the receiver to allow additional configuration of the [Component].
* @return the created ƒ[Component].
* @see [create]
*/
inline fun <reified T : Component> with(configure: (@AshleyDsl T).() -> Unit): T = with<T>().also(configure)

/**
* Get or creates an instance of the component [T] and adds it to this [entity][EngineEntity].
*
* @param T the [Component] type to get or create.
* @return the created [Component].
* @see [create]
*/
inline fun <reified T : Component> with(): T {
val component = engine.create<T>()
entity.add(component)
return component
}
}

/**
* Builder function for [Engine].
*
* @param configure inlined function with *this* [Engine] as the receiver to allow further configuration.
*/
inline fun Engine.add(configure: (@AshleyDsl Engine).() -> Unit) {
configure(this)
}

/**
* Create and add an [Entity] to the [Engine].
*
* @param configure inlined function with the created [Entity] as the receiver to allow further configuration of
* the [Entity]. The [Entity] holds the [Entity] created and the [Engine] that created it.
* @return the created [Entity].
*/
inline fun Engine.entity(configure: EngineEntity.() -> Unit): Entity {
val entity = createEntity()
configure(EngineEntity(this, entity))
addEntity(entity)
return entity
}
83 changes: 0 additions & 83 deletions ashley/src/main/kotlin/ktx/ashley/pooledEngines.kt

This file was deleted.

2 changes: 1 addition & 1 deletion ashley/src/test/kotlin/ktx/ashley/ComponentMappersSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it

object ComponentMappersSpec: Spek({
object ComponentMappersSpec : Spek({
describe("utilities for component mappers") {
val entity = Entity().apply {
add(Texture())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it

object PooledEnginesSpec : Spek({
describe("utilities for pooled engines") {
object EnginesSpec : Spek({
describe("utilities for engines") {
val engine by memoized {
PooledEngine()
}
Expand Down
2 changes: 1 addition & 1 deletion ashley/src/test/kotlin/ktx/ashley/FamiliesSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it

object FamiliesSpec: Spek({
object FamiliesSpec : Spek({
describe("utilities for component families") {
val textureEntity = Entity().apply {
add(Texture())
Expand Down
2 changes: 1 addition & 1 deletion ashley/src/test/kotlin/ktx/ashley/RigidBody.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package ktx.ashley

import com.badlogic.ashley.core.Component

class RigidBody: Component
class RigidBody : Component
2 changes: 1 addition & 1 deletion ashley/src/test/kotlin/ktx/ashley/Texture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ktx.ashley
import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.ComponentMapper

class Texture: Component {
class Texture : Component {
companion object {
val mapper = ComponentMapper.getFor(Texture::class.java)!!
}
Expand Down
2 changes: 1 addition & 1 deletion ashley/src/test/kotlin/ktx/ashley/Transform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ktx.ashley
import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.ComponentMapper

class Transform(var x:Float = 0f, var y: Float = 0f) : Component {
class Transform(var x: Float = 0f, var y: Float = 0f) : Component {
companion object {
val mapper = ComponentMapper.getFor(Transform::class.java)!!
}
Expand Down
8 changes: 2 additions & 6 deletions async/src/main/kotlin/ktx/async/assets/assets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ class AssetStorage(
return file
}

private suspend fun <Asset : Any> loadWithSynchronousLoader(
private fun <Asset : Any> loadWithSynchronousLoader(
synchronousLoader: SynchronousLoader<Asset>,
descriptor: AssetDescriptor<Asset>): Asset =
KtxAsync.asynchronous(executor) {
// Yes, LibGDX AssetManager handles SynchronousAssetLoader loading on a separate thread. Go figure.
synchronousLoader.load(asAssetManager, descriptor)
}
descriptor: AssetDescriptor<Asset>): Asset = synchronousLoader.load(asAssetManager, descriptor)

private suspend fun <Asset : Any> loadWithAsynchronousLoader(
asynchronousLoader: AsynchronousLoader<Asset>,
Expand Down
24 changes: 20 additions & 4 deletions async/src/main/kotlin/ktx/async/assets/loaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,36 @@ internal class AssetLoaderStorage {
}

/**
* Allows to read text files with an [AssetManager] or an [AssetStorage].
* Allows to read text files with an [AssetManager] or an [AssetStorage]. Note that [loadAsync] _must_ be called before
* [loadSync], as usual in case of [AsynchronousAssetLoader] implementations. The loader is not considered thread-safe
* and assumes that a single file is loaded at a time.
* @param fileResolver not used, required by the superclass.
* @param charset name of the charset used to read text. Can be overridden with [TextAssetLoaderParameters]. Should
* match text files encoding. Defaults to UTF-8.
*/
class TextAssetLoader(
fileResolver: FileHandleResolver,
private val charset: String = "UTF-8"
) : SynchronousAssetLoader<String, TextAssetLoaderParameters>(fileResolver) {
override fun load(
) : AsynchronousAssetLoader<String, TextAssetLoaderParameters>(fileResolver) {
@Volatile var fileContent: String? = null

override fun loadAsync(
assetManager: AssetManager?,
fileName: String?,
file: FileHandle,
parameter: TextAssetLoaderParameters?): String = file.readString(parameter?.charset ?: charset)
parameter: TextAssetLoaderParameters?) {
fileContent = file.readString(parameter?.charset ?: charset)
}

override fun loadSync(
assetManager: AssetManager?,
fileName: String?,
file: FileHandle,
parameter: TextAssetLoaderParameters?): String = try {
fileContent ?: throw AssetStorageException("File $fileName was not loaded asynchronously. Call #loadAsync first.")
} finally {
fileContent = null
}

override fun getDependencies(fileName: String?, file: FileHandle?, parameter: TextAssetLoaderParameters?):
GdxArray<AssetDescriptor<Any>>? = null
Expand Down
16 changes: 14 additions & 2 deletions async/src/test/kotlin/ktx/async/assets/loadersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.badlogic.gdx.files.FileHandle
import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import io.kotlintest.matchers.shouldThrow
import ktx.async.assets.TextAssetLoader.TextAssetLoaderParameters
import org.junit.Assert.*
import org.junit.Test
Expand Down Expand Up @@ -143,7 +144,8 @@ class TextAssetLoaderTest {
on(it.readString("UTF-8")) doReturn "Content."
}

val result = loader.load(mock(), "test.txt", file, null)
loader.loadAsync(mock(), "test.txt", file, null)
val result = loader.loadSync(mock(), "test.txt", file, null)

assertEquals("Content.", result)
verify(file).readString("UTF-8")
Expand All @@ -156,11 +158,21 @@ class TextAssetLoaderTest {
on(it.readString("UTF-16")) doReturn "Content."
}

val result = loader.load(mock(), "test.txt", file, TextAssetLoaderParameters(charset = "UTF-16"))
loader.loadAsync(mock(), "test.txt", file, TextAssetLoaderParameters(charset = "UTF-16"))
val result = loader.loadSync(mock(), "test.txt", file, TextAssetLoaderParameters(charset = "UTF-16"))

assertEquals("Content.", result)
verify(file).readString("UTF-16")
}

@Test
fun `should throw exception when trying to read file without loading it asynchronously`() {
val loader = TextAssetLoader(ClasspathFileHandleResolver(), charset = "UTF-8")

shouldThrow<AssetStorageException> {
loader.loadSync(mock(), "test.txt", mock(), null)
}
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion async/src/test/resources/ktx/async/assets/collection.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
[{"testInt":10,"testString":"Content."},{"testInt":20,"testString":"Test."}]
[
{
"testInt": 10,
"testString": "Content."
},
{
"testInt": 20,
"testString": "Test."
}
]
5 changes: 4 additions & 1 deletion async/src/test/resources/ktx/async/assets/object.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"testInt":10,"testString":"Content."}
{
"testInt": 10,
"testString": "Content."
}
Loading

0 comments on commit e806250

Please sign in to comment.