I have a piece of code to render a grid from which I will render a maze. My build function:
fun buildAsync(): Deferred<RegularMaze> {
return KtxAsync.async(newSingleThreadAsyncContext()) {
addEmptyFields()
enableLeftBordersRender()
enableBottomBordersRender()
regularMazeService.convertFieldsToMaze(fields, colsNo, rowsNo)
}
}
But when I move addEmptyFields()
before async
section it is rendering correctly
And my Wall
class
class Wall (width: Float, height: Float, x: Float = 0F, y: Float = 0F, rotation: Float = 0F) : BasePart() {
private val textureRegion: TextureRegion
private val size: Size = Size(width, height)
private val position: Position = Position(x, y, rotation)
var relatedFieldIndex: Int? = null
var shouldBeDraw = true
init {
inject()
val wallTexture = assetsHelper.getTextureFromAsset(TextureAsset.WALL)
wallTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat)
textureRegion = TextureRegion(wallTexture, 0, 0, size.widthInt, size.heightInt)
setBounds(
position.x,
position.y,
width,
height
)
rotateBy(position.rotation)
}
override fun draw(batch: Batch, parentAlpha: Float) {
super.draw(batch, parentAlpha)
if (shouldBeDraw) {
batch.draw(textureRegion, position.x, position.y, 0F, 0F, size.width, size.height, 1F, 1F, position.rotation)
}
}
class Size (val width: Float, val height: Float) {
val widthInt: Int
get() = ceil(width).toInt()
val heightInt: Int
get() = ceil(height).toInt()
}
data class Position(val x: Float, val y: Float, val rotation: Float)
}
[EDIT/UPDATE]
I discover something strange, when I create a single Wall
without dimensions before async
it starts working. "Working" code:
fun buildAsync(): Deferred<RegularMaze> {
Wall(0f,0f) // <---- new line
return KtxAsync.async(newSingleThreadAsyncContext()) {
addEmptyFields()
enableLeftBordersRender()
enableBottomBordersRender()
regularMazeService.convertFieldsToMaze(fields, colsNo, rowsNo)
}
}
Why?