mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
working subtiling (for atlas size 2048)
This commit is contained in:
Binary file not shown.
@@ -883,14 +883,19 @@ internal object BlocksDrawer {
|
|||||||
}
|
}
|
||||||
val baseXY = tilenumInAtlas.map { Point2i(
|
val baseXY = tilenumInAtlas.map { Point2i(
|
||||||
it % (App.tileMaker.TILES_IN_X * 2),
|
it % (App.tileMaker.TILES_IN_X * 2),
|
||||||
it / (App.tileMaker.TILES_IN_X * 2),
|
(it / (App.tileMaker.TILES_IN_X * 2)).let {
|
||||||
|
if (it % 2 == 1) it + 1 else it
|
||||||
|
},
|
||||||
) }
|
) }
|
||||||
|
|
||||||
// apply variants
|
// apply variants
|
||||||
return (baseXY zip variants).map { (base, va) -> Point2i(
|
return (baseXY zip variants).map { (base, va) -> Point2i(
|
||||||
base.x + va / 2,
|
base.x + va / 2,
|
||||||
base.y + va % 2,
|
base.y + va % 2,
|
||||||
) }
|
) }.also {
|
||||||
|
// println("Base: $base")
|
||||||
|
// println("Tiles: $it")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.reorientSubtileUsingFliprotIdx(fliprotIndex: Int): Int {
|
private fun Int.reorientSubtileUsingFliprotIdx(fliprotIndex: Int): Int {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.Texture
|
|||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
|
import net.torvald.gdx.graphics.PixmapIO2
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.SUBTILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.SUBTILE_SIZE
|
||||||
@@ -407,13 +408,13 @@ class CreateTileAtlas {
|
|||||||
addTag(blockID, RenderTag.CONNECT_SELF, RenderTag.MASK_FLUID)
|
addTag(blockID, RenderTag.CONNECT_SELF, RenderTag.MASK_FLUID)
|
||||||
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, RenderTag.MASK_FLUID)
|
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, RenderTag.MASK_FLUID)
|
||||||
}
|
}
|
||||||
// subtitle generic
|
// subtitles
|
||||||
else if (tilesPixmap.width == W_SUBTILE_GENERIC && tilesPixmap.height == H_SUBTILE ||
|
else if (tilesPixmap.width == W_SUBTILE_GENERIC && tilesPixmap.height == H_SUBTILE ||
|
||||||
tilesPixmap.width == W_SUBTILE_GRASS && tilesPixmap.height == H_SUBTILE ||
|
tilesPixmap.width == W_SUBTILE_GRASS && tilesPixmap.height == H_SUBTILE ||
|
||||||
tilesPixmap.width == 3*W_SUBTILE_GENERIC && tilesPixmap.height == 2*H_SUBTILE ||
|
tilesPixmap.width == 3*W_SUBTILE_GENERIC && tilesPixmap.height == 2*H_SUBTILE ||
|
||||||
tilesPixmap.width == 3*W_SUBTILE_GRASS && tilesPixmap.height == 2*H_SUBTILE) {
|
tilesPixmap.width == 3*W_SUBTILE_GRASS && tilesPixmap.height == 2*H_SUBTILE) {
|
||||||
|
|
||||||
// TODO figure out the tags
|
// figure out the tags
|
||||||
// tags are arranged horizontally, left-to-right, starting from (0,0)
|
// tags are arranged horizontally, left-to-right, starting from (0,0)
|
||||||
// Line 0: (reserved for manual subtile allocation)
|
// Line 0: (reserved for manual subtile allocation)
|
||||||
// Line 1: Tiling Mode
|
// Line 1: Tiling Mode
|
||||||
@@ -440,6 +441,7 @@ class CreateTileAtlas {
|
|||||||
else -> throw IllegalArgumentException("$connectionType0")
|
else -> throw IllegalArgumentException("$connectionType0")
|
||||||
}
|
}
|
||||||
addTag(blockID, connectionType, maskType, tilingMode)
|
addTag(blockID, connectionType, maskType, tilingMode)
|
||||||
|
// println("drawToAtlantes tile: $blockID")
|
||||||
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, maskType)
|
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, maskType)
|
||||||
}
|
}
|
||||||
// 112x112 or 336x224
|
// 112x112 or 336x224
|
||||||
@@ -453,19 +455,19 @@ class CreateTileAtlas {
|
|||||||
// not marked: connect-mutual
|
// not marked: connect-mutual
|
||||||
// marked: connect-self
|
// marked: connect-self
|
||||||
var connectionType = 0
|
var connectionType = 0
|
||||||
// var maskType = 0
|
var maskType = 0
|
||||||
for (bit in 0 until TILE_SIZE) {
|
for (bit in 0 until TILE_SIZE) {
|
||||||
val x = (7 * TILE_SIZE - 1) - bit
|
val x = (7 * TILE_SIZE - 1) - bit
|
||||||
val y1 = 5 * TILE_SIZE; val y2 = y1 + 1
|
val y1 = 5 * TILE_SIZE; val y2 = y1 + 1
|
||||||
val pixel1 = (tilesPixmap.getPixel(x, y1).and(255) >= 128).toInt(bit)
|
val pixel1 = (tilesPixmap.getPixel(x, y1).and(255) >= 128).toInt(bit)
|
||||||
// val pixel2 = (tilesPixmap.getPixel(x, y2).and(255) >= 128).toInt(bit)
|
val pixel2 = (tilesPixmap.getPixel(x, y2).and(255) >= 128).toInt(bit)
|
||||||
|
|
||||||
connectionType += pixel1
|
connectionType += pixel1
|
||||||
// maskType += pixel2
|
maskType += pixel2
|
||||||
}
|
}
|
||||||
|
|
||||||
addTag(blockID, connectionType, RenderTag.MASK_47)
|
addTag(blockID, connectionType, maskType)
|
||||||
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, RenderTag.MASK_47)
|
drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, maskType)
|
||||||
}
|
}
|
||||||
|
|
||||||
itemSheetNumbers[blockID] = itemSheetCursor
|
itemSheetNumbers[blockID] = itemSheetCursor
|
||||||
@@ -512,10 +514,16 @@ class CreateTileAtlas {
|
|||||||
val txOfPixmapEmissive = emissive.width / TILE_SIZE
|
val txOfPixmapEmissive = emissive.width / TILE_SIZE
|
||||||
|
|
||||||
if (renderMask >= MASK_SUBTILE_GENERIC) {
|
if (renderMask >= MASK_SUBTILE_GENERIC) {
|
||||||
|
|
||||||
for (i in 0 until tilesCount) {
|
for (i in 0 until tilesCount) {
|
||||||
val srcX = SUBTILE_SIZE * (i / 4)
|
val srcX = SUBTILE_SIZE * (i / 4)
|
||||||
val srcY = SUBTILE_SIZE * 4 * (i % 4) + SUBTILE_SIZE
|
val srcY = SUBTILE_SIZE * 4 * (i % 4) + SUBTILE_SIZE
|
||||||
|
|
||||||
|
// snippet straight from the _drawToAtlantesFourSubtiles
|
||||||
|
// val atlasX = (atlasCursor % TILES_IN_X) * TILE_SIZE
|
||||||
|
// val atlasY = (atlasCursor / TILES_IN_X) * TILE_SIZE
|
||||||
|
// println("Drawing tile to the atlas: atlasCursor=${atlasCursor}, atlasXY=($atlasX,$atlasY)")
|
||||||
|
|
||||||
if (sixSeasonal) {
|
if (sixSeasonal) {
|
||||||
_drawToAtlantesFourSubtiles(diffuse, atlasCursor, srcX + 0*wSubtileSheet, srcY, PREVERNAL)
|
_drawToAtlantesFourSubtiles(diffuse, atlasCursor, srcX + 0*wSubtileSheet, srcY, PREVERNAL)
|
||||||
_drawToAtlantesFourSubtiles(diffuse, atlasCursor, srcX + 1*wSubtileSheet, srcY, VERNAL)
|
_drawToAtlantesFourSubtiles(diffuse, atlasCursor, srcX + 1*wSubtileSheet, srcY, VERNAL)
|
||||||
@@ -581,8 +589,8 @@ class CreateTileAtlas {
|
|||||||
else {
|
else {
|
||||||
// destTileNum increments by one, which means FOUR SUBTILES
|
// destTileNum increments by one, which means FOUR SUBTILES
|
||||||
|
|
||||||
val atlasX = (destTileNum % SUBTILES_IN_X) * TILE_SIZE
|
val atlasX = (destTileNum % TILES_IN_X) * TILE_SIZE
|
||||||
val atlasY = (destTileNum / SUBTILES_IN_X) * TILE_SIZE
|
val atlasY = (destTileNum / TILES_IN_X) * TILE_SIZE
|
||||||
|
|
||||||
val target = when (source) {
|
val target = when (source) {
|
||||||
PREVERNAL -> atlasPrevernal
|
PREVERNAL -> atlasPrevernal
|
||||||
@@ -596,8 +604,18 @@ class CreateTileAtlas {
|
|||||||
else -> throw IllegalArgumentException("Unknown draw source $source")
|
else -> throw IllegalArgumentException("Unknown draw source $source")
|
||||||
}
|
}
|
||||||
|
|
||||||
target.drawPixmap(pixmap, sourceX, sourceY, SUBTILE_SIZE, TILE_SIZE, atlasX, atlasY, SUBTILE_SIZE, TILE_SIZE)
|
target.drawPixmap(pixmap,
|
||||||
target.drawPixmap(pixmap, sourceX, sourceY + TILE_SIZE, SUBTILE_SIZE, TILE_SIZE, atlasX + SUBTILE_SIZE, atlasY, SUBTILE_SIZE, TILE_SIZE)
|
sourceX, sourceY,
|
||||||
|
SUBTILE_SIZE, TILE_SIZE,
|
||||||
|
atlasX, atlasY,
|
||||||
|
SUBTILE_SIZE, TILE_SIZE
|
||||||
|
)
|
||||||
|
target.drawPixmap(pixmap,
|
||||||
|
sourceX, sourceY + TILE_SIZE,
|
||||||
|
SUBTILE_SIZE, TILE_SIZE,
|
||||||
|
atlasX + SUBTILE_SIZE, atlasY,
|
||||||
|
SUBTILE_SIZE, TILE_SIZE
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user