From 96cdefb80009bc2a6e73cc89406f7b5d1711dbea Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 24 Aug 2024 01:37:31 +0900 Subject: [PATCH] brick tiling --- assets/mods/basegame/blocks/48.tga | 4 +- .../terrarum/worlddrawer/BlocksDrawer.kt | 59 ++++++++++++------- .../terrarum/worlddrawer/CreateTileAtlas.kt | 16 ++++- .../terrain_variable_subtiling_full.kra | 4 +- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/assets/mods/basegame/blocks/48.tga b/assets/mods/basegame/blocks/48.tga index 88eb4bab6..1eec854a8 100644 --- a/assets/mods/basegame/blocks/48.tga +++ b/assets/mods/basegame/blocks/48.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f4e1245287a1b0bcdada3b63989fd4f48d15ae83ee8b68ab59856fc047e2559 -size 50194 +oid sha256:c52df534a06b52464fa524a034df1289d56c10c3530334fd863949cd3606bd4d +size 56594 diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index a2ac1c158..21f885d06 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -169,12 +169,33 @@ internal object BlocksDrawer { val connectLut16 = intArrayOf(0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15) // order: TL, TR, BR, BL - val subtileVarBaseLuts = listOf( + val subtileVarBaseLuts = arrayOf( intArrayOf(10,2,2,2,1,1,3,1,10,1,10,3,10,3,2,1,1,2,0,3,3,10,0,0,0,0,0,3,10,0,0,0,3,3,3,1,3,1,0,0,3,10,0,10,3,0,3), intArrayOf(4,1,5,1,5,1,4,1,4,5,6,4,6,6,1,1,5,5,6,0,6,0,0,4,0,0,6,0,0,0,4,6,0,6,6,1,4,1,4,0,0,0,6,6,0,6,6), intArrayOf(4,7,4,9,4,9,4,7,8,8,7,8,9,7,0,0,4,8,0,9,9,0,0,4,9,0,9,9,7,7,8,0,0,9,0,0,4,9,4,9,0,9,7,0,7,9,0), intArrayOf(10,11,10,10,12,12,12,7,11,7,11,7,10,7,10,0,0,11,12,0,12,10,0,0,0,12,12,12,11,7,7,0,0,0,12,12,0,0,12,12,12,10,7,10,7,0,0), ) + // order: TL, TR, BR, BL + private val subtileReorientLUT = arrayOf( + intArrayOf(0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,13,14,15,16,17,18,19,20), /* normal */ + intArrayOf(0 ,1 ,5 ,6 ,10,2 ,3 ,7 ,11,12,4 ,8 ,9 ,14,13,20,19,18,17,16,15), /* horz flip */ + intArrayOf(0 ,10,11,12,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,19,20,13,14,15,16,17,18), /* CW 90 */ + intArrayOf(0 ,10,2 ,3 ,7 ,11,12,4 ,8 ,9 ,1 ,5 ,6 ,20,19,18,17,16,15,14,13), /* hfCW 90 */ + intArrayOf(0 ,7 ,8 ,9 ,10,11,12,1 ,2 ,3 ,4 ,5 ,6 ,17,18,19,20,13,14,15,16), /* CW 180 */ + intArrayOf(0 ,7 ,11,12,4 ,8 ,9 ,1 ,5 ,6 ,10,2 ,3 ,18,17,16,15,14,13,20,19), /* hfCW 180 */ + intArrayOf(0 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,1 ,2 ,3 ,15,16,17,18,19,20,13,14), /* CW 270 */ + intArrayOf(0 ,4 ,8 ,9 ,1 ,5 ,6 ,10,2 ,3 ,7 ,11,12,16,15,14,13,20,19,18,17), /* hfCW 270 */ + ) + // order: TL, TR, BR, BL + private val variantOpsLUT = arrayOf( + // newIndex = (oldIndex % A) + B for (a to b) + arrayOf(16 to 0,16 to 0,16 to 0,16 to 0), // TILING_FULL + arrayOf(16 to 0,16 to 0,16 to 0,16 to 0), // TILING_FULL_NOFLIP + arrayOf(8 to 0,8 to 8,8 to 8,8 to 0), // TILING_BRICK_SMALL + arrayOf(8 to 0,8 to 8,8 to 8,8 to 0), // TILING_BRICK_SMALL_NOFLIP + arrayOf(8 to 0,8 to 8,8 to 0,8 to 8), // TILING_BRICK_LARGE + arrayOf(8 to 0,8 to 8,8 to 0,8 to 8), // TILING_BRICK_LARGE_NOFLIP + ) init { assert(256 == connectLut47.size) @@ -524,13 +545,17 @@ internal object BlocksDrawer { if (renderTag.maskType >= CreateTileAtlas.RenderTag.MASK_SUBTILE_GENERIC) { hash = getHashCoord(x, y, 268435456, mode.modeToString()) - val subtileSwizzlers = listOf( - (hash ushr 16) and 7, - (hash ushr 19) and 7, - (hash ushr 22) and 7, - (hash ushr 25) and 7, - ) - val subtiles = getSubtileIndexOf(tileNumberBase, nearbyTilesInfo, hash, subtileSwizzlers, renderTag.maskType % 2 == 1) + val subtileSwizzlers = if (renderTag.tilingMode and 1 == 1) + intArrayOf(0,0,0,0) + else + intArrayOf( + (hash ushr 16) and 7, + (hash ushr 19) and 7, + (hash ushr 22) and 7, + (hash ushr 25) and 7, + ) + val variantOps = variantOpsLUT[renderTag.tilingMode] + val subtiles = getSubtileIndexOf(tileNumberBase, nearbyTilesInfo, hash, subtileSwizzlers, variantOps) /*TL*/writeToBufferSubtile(mode, bufferBaseX * 2 + 0, bufferBaseY * 2 + 0, subtiles[0].x, subtiles[0].y, breakingStage, subtileSwizzlers[0]) /*TR*/writeToBufferSubtile(mode, bufferBaseX * 2 + 1, bufferBaseY * 2 + 0, subtiles[1].x, subtiles[1].y, breakingStage, subtileSwizzlers[1]) @@ -874,8 +899,12 @@ internal object BlocksDrawer { * * @return subtile indices on the atlas, in the following order: TL, TR, BR, BL */ - private fun getSubtileIndexOf(base: Int, nearbyTilesInfo: Int, variants: Int, subtileSwizzlers: List, brickTiling: Boolean): List { - val variants = (0..3).map { variants.ushr(it * 4) and 15 } + private fun getSubtileIndexOf(base: Int, nearbyTilesInfo: Int, variants: Int, subtileSwizzlers: IntArray, variantOps: Array>): List { + val variants = (0..3).map { quadrant -> + (variants.ushr(quadrant * 4) and 15).let { oldIdx -> + variantOps[quadrant].let { (mod, add) -> (oldIdx % mod) + add } + } + } val tilenumInAtlas = (0..3).map { base.tileToSubtile() + 8*subtileVarBaseLuts[it][connectLut47[nearbyTilesInfo]].reorientSubtileUsingFliprotIdx( subtileSwizzlers[it] @@ -902,16 +931,6 @@ internal object BlocksDrawer { return subtileReorientLUT[fliprotIndex][this] } - private val subtileReorientLUT = arrayOf( - intArrayOf(0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,13,14,15,16,17,18,19,20), /* normal */ - intArrayOf(0 ,1 ,5 ,6 ,10,2 ,3 ,7 ,11,12,4 ,8 ,9 ,14,13,20,19,18,17,16,15), /* horz flip */ - intArrayOf(0 ,10,11,12,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,19,20,13,14,15,16,17,18), /* CW 90 */ - intArrayOf(0 ,10,2 ,3 ,7 ,11,12,4 ,8 ,9 ,1 ,5 ,6 ,20,19,18,17,16,15,14,13), /* hfCW 90 */ - intArrayOf(0 ,7 ,8 ,9 ,10,11,12,1 ,2 ,3 ,4 ,5 ,6 ,17,18,19,20,13,14,15,16), /* CW 180 */ - intArrayOf(0 ,7 ,11,12,4 ,8 ,9 ,1 ,5 ,6 ,10,2 ,3 ,18,17,16,15,14,13,20,19), /* hfCW 180 */ - intArrayOf(0 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,1 ,2 ,3 ,15,16,17,18,19,20,13,14), /* CW 270 */ - intArrayOf(0 ,4 ,8 ,9 ,1 ,5 ,6 ,10,2 ,3 ,7 ,11,12,16,15,14,13,20,19,18,17), /* hfCW 270 */ - ) /** * @param sheetX x-coord of the FULL TILE in an atlas diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index 18b2254cf..37dc5c141 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -419,7 +419,9 @@ class CreateTileAtlas { // Line 0: (reserved for manual subtile allocation) // Line 1: Tiling Mode // 0000 (0): Full Tiling - // 1000 (1): Brick Tiling + // 1000 (1): Full Tiling with No Fliprot + // 1100 (3): Brick Tiling Small (4 rows per full tile; indices: 0-7, 8-15, 8-15, 0-7) implies no fliprot + // 1010 (5): Brick Tiling Large (2 rows per full tile; indices: 0-7, 8-15, 0-7, 8-15) implies no fliprot // Line 2: Connection Type // 0000 (0): INVALID // 1000 (1): connect-mutual @@ -441,7 +443,7 @@ class CreateTileAtlas { else -> throw IllegalArgumentException("$connectionType0") } addTag(blockID, connectionType, maskType, tilingMode) -// println("drawToAtlantes tile: $blockID") +// println("drawToAtlantes tile: $blockID with mode $tilingMode") drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, maskType) } // 112x112 or 336x224 @@ -454,6 +456,10 @@ class CreateTileAtlas { // Line 0: Connection Type // not marked: connect-mutual // marked: connect-self + // Line 1: Mask Type + // 0000 (0): INVALID + // 0001 (1): 16-tiles tiling [Deprecated] + // 0010 (2): 47-tiles tiling var connectionType = 0 var maskType = 0 for (bit in 0 until TILE_SIZE) { @@ -680,7 +686,11 @@ class CreateTileAtlas { const val MASK_SUBTILE_GRASS_BRICK_TILING = 3 const val TILING_FULL = 0 - const val TILING_BRICK = 1 + const val TILING_FULL_NOFLIP = 1 + const val TILING_BRICK_SMALL = 2 + const val TILING_BRICK_SMALL_NOFLIP = 3 + const val TILING_BRICK_LARGE = 4 + const val TILING_BRICK_LARGE_NOFLIP = 5 fun maskTypeToTileCount(maskType: Int) = when (maskType) { MASK_NA -> 1 diff --git a/work_files/graphics/terrain/terrain_variable_subtiling_full.kra b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra index 2854307d2..a507c4859 100644 --- a/work_files/graphics/terrain/terrain_variable_subtiling_full.kra +++ b/work_files/graphics/terrain/terrain_variable_subtiling_full.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6ea5a3bf7e3d91dc052fa32156bc57fdbbbaa041064735337af6ad45c0e90a99 -size 682871 +oid sha256:93f05f4d33d8db208463095fc452eb596d344a6c133dcc5ee95a4e7d90862bf3 +size 617742