From c57de3a21f394b994c9448d97ddad966ed323ed8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 17 Sep 2018 23:10:29 +0900 Subject: [PATCH] we have a render (but not colour) --- .../gdx/PixmapRegionPack.kt | 81 +++++++++++++------ 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt b/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt index 4df8cfd..2914468 100644 --- a/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/PixmapRegionPack.kt @@ -53,32 +53,41 @@ class PixmapRegionPack( val regions: Array init { + // test print the whole sheet + /*pixmap.pixels.rewind() + for (y in 0 until pixmap.height) { + for (x in 0 until pixmap.width) { + pixmap.pixels.get() // discard r + pixmap.pixels.get() // discard g + pixmap.pixels.get() // discard b + val a = pixmap.pixels.get() + + if (a == 255.toByte()) print("█") else print("·") + } + println() + } + println()*/ + + + + pixmap.pixels.rewind() + if (!xySwapped) { regions = Array(horizontalCount * verticalCount, { val rx = (it % horizontalCount * (tileW + hGap)) + hFrame // pixel, not index val ry = (it / horizontalCount * (tileH + vGap)) + vFrame // pixel, not index val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888) - - /*region.setColor(Color.WHITE) - region.drawPixmap(pixmap, 0, 0, - rx * (tileW + hGap), - ry * (tileH + vGap), - tileW, - tileH - )*/ - region.pixels.rewind() - //println(region.pixels.capacity()) + // for every "scanline" for (y in 0 until tileH) { - //println("${pixmap.width * pixmap.height * 4} ==? ${pixmap.pixels.capacity()}") - val offsetY = ry * (pixmap.width * 4) + (vFrame * pixmap.width * 4) + val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4) val offsetX = rx * 4 + hFrame * 4 - //println("($rx, $ry): ${offsetY + offsetX} / ${pixmap.pixels.capacity()}; $offsetY, $offsetX") + //println("offset: ${offsetX + offsetY}") val bytesBuffer = ByteArray(4 * tileW) @@ -86,22 +95,19 @@ class PixmapRegionPack( pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size) // test print bytesbuffer - bytesBuffer.forEachIndexed { index, it -> + /*bytesBuffer.forEachIndexed { index, it -> if (index % 4 == 3) { if (it == 255.toByte()) print("█") else print("·") } } - println() + println()*/ region.pixels.put(bytesBuffer) } + //println() - println() - //val region = Pixmap(5, 20, Pixmap.Format.RGBA8888) - //region.pixels.rewind() - //region.pixels.put(byteArrayOf(-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,0)) // todo globalFlipY ? @@ -110,15 +116,40 @@ class PixmapRegionPack( } else { regions = Array(horizontalCount * verticalCount, { - val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888) val rx = (it / verticalCount * (tileW + hGap)) + hFrame val ry = (it % verticalCount * (tileH + vGap)) + vFrame - region.drawPixmap(pixmap, 0, 0, - rx * (tileW + hGap), - ry * (tileH + vGap), - tileW, tileH - ) + val region = Pixmap(tileW, tileH, Pixmap.Format.RGBA8888) + region.pixels.rewind() + + + // for every "scanline" + for (y in 0 until tileH) { + + val offsetY = (ry + y) * (pixmap.width * 4) + (vFrame * pixmap.width * 4) + val offsetX = rx * 4 + hFrame * 4 + + //println("offset: ${offsetX + offsetY}") + + val bytesBuffer = ByteArray(4 * tileW) + + pixmap.pixels.position(offsetY + offsetX) + pixmap.pixels.get(bytesBuffer, 0, bytesBuffer.size) + + // test print bytesbuffer + /*bytesBuffer.forEachIndexed { index, it -> + if (index % 4 == 3) { + if (it == 255.toByte()) print("█") else print("·") + } + } + println()*/ + + region.pixels.put(bytesBuffer) + } + + //println() + + // todo globalFlipY ?