old tiling is adapted to subtiling (no fliprot/breakage yet)

This commit is contained in:
minjaesong
2024-08-20 22:01:59 +09:00
parent 186733e4f8
commit ebcc2ef4bf
4 changed files with 40 additions and 26 deletions

View File

@@ -458,7 +458,7 @@ internal object BlocksDrawer {
(fillThis * 16f - 0.5f).floorToInt().coerceIn(0, 15)
}
else if (treeLeavesTiles.binarySearch(rawTileNum) >= 0) {
getNearbyTilesInfoTrees(x, y, mode).swizzle8(rawTileNum, hash)
getNearbyTilesInfoTrees(x, y, mode)//.swizzle8(rawTileNum, hash)
}
else if (treeTrunkTiles.binarySearch(rawTileNum) >= 0) {
hash = 0
@@ -466,17 +466,17 @@ internal object BlocksDrawer {
}
else if (platformTiles.binarySearch(rawTileNum) >= 0) {
hash %= 2
getNearbyTilesInfoPlatform(x, y).swizzleH2(rawTileNum, hash)
getNearbyTilesInfoPlatform(x, y)//.swizzleH2(rawTileNum, hash)
}
else if (wallStickerTiles.binarySearch(rawTileNum) >= 0) {
hash = 0
getNearbyTilesInfoWallSticker(x, y)
}
else if (connectMutualTiles.binarySearch(rawTileNum) >= 0) {
getNearbyTilesInfoConMutual(x, y, mode).swizzle8(rawTileNum, hash)
getNearbyTilesInfoConMutual(x, y, mode)//.swizzle8(rawTileNum, hash)
}
else if (connectSelfTiles.binarySearch(rawTileNum) >= 0) {
getNearbyTilesInfoConSelf(x, y, mode, rawTileNum).swizzle8(rawTileNum, hash)
getNearbyTilesInfoConSelf(x, y, mode, rawTileNum)//.swizzle8(rawTileNum, hash)
}
else {
0
@@ -510,8 +510,10 @@ internal object BlocksDrawer {
tileNumber = 2 // black solid
}
val thisTileX = tileNumber % App.tileMaker.TILES_IN_X
val thisTileY = tileNumber / App.tileMaker.TILES_IN_X
val subtileNum = tileNumber.tileToSubtile()
val thisTileX = subtileNum % App.tileMaker.TILES_IN_X
val thisTileY = subtileNum / App.tileMaker.TILES_IN_X
val breakage = if (mode == TERRAIN || mode == ORES) world.getTerrainDamage(x, y) else if (mode == WALL) world.getWallDamage(x, y) else 0f
if (breakage.isNaN()) throw IllegalStateException("Block breakage at ($x, $y) is NaN (mode=$mode)")
@@ -519,15 +521,20 @@ internal object BlocksDrawer {
val breakingStage = if (mode == TERRAIN || mode == WALL || mode == ORES) (breakage / maxHealth).coerceIn(0f, 1f).times(BREAKAGE_STEPS).roundToInt() else 0
// draw a tile
writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+0, thisTileX, thisTileY, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+0, thisTileX, thisTileY, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+1, thisTileX, thisTileY, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+1, thisTileX, thisTileY, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+0, thisTileX+0, thisTileY+0, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+0, thisTileX+1, thisTileY+0, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+0, bufferBaseY*2+1, thisTileX+0, thisTileY+2, breakingStage, hash)
writeToBuffer(mode, bufferBaseX*2+1, bufferBaseY*2+1, thisTileX+1, thisTileY+2, breakingStage, hash)
tempRenderTypeBuffer[bufferBaseY, bufferBaseX] = (nearbyTilesInfo or rawTileNum.shl(16)).toLong()
}
}
// println("App.tileMaker.TILES_IN_X = ${App.tileMaker.TILES_IN_X}\tApp.tileMaker.atlas.width = ${App.tileMaker.atlas.width}")
// println("tilesTerrain.horizontalCount = ${tilesTerrain.horizontalCount}")
}
private fun Int.tileToSubtile() = (this / App.tileMaker.TILES_IN_X) * 4*App.tileMaker.TILES_IN_X +
(this % App.tileMaker.TILES_IN_X) * 2
private val swizzleMap8 = arrayOf(
arrayOf(0,1,2,3,4,5,6,7), /* normal */
arrayOf(4,3,2,1,0,7,6,5), /* horz flip */
@@ -798,7 +805,8 @@ internal object BlocksDrawer {
}
/**
* Raw format of RGBA8888.
* @param sheetX x-coord of the SUBTILE in an atlas
* @param sheetY y-coord of the SUBTILE in an atlas
*
* @return Raw colour bits in RGBA8888 format
*/
@@ -938,14 +946,14 @@ internal object BlocksDrawer {
var hTilesInVertical = -1; private set
fun resize(screenW: Int, screenH: Int) {
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt().times(2) + 2
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt().times(2) + 2
hTilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1
hTilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt().times(2) + 1
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt().times(2) + 1
tilesInHorizontal = hTilesInHorizontal * 2
tilesInVertical = hTilesInVertical * 2
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt().times(2) + 2
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt().times(2) + 2
// only update if it's really necessary
if (oldTH != tilesInHorizontal || oldTV != tilesInVertical) {

View File

@@ -243,7 +243,7 @@ class CreateTileAtlas {
}
// test print
PixmapIO2.writeTGA(Gdx.files.absolute("${App.defaultDir}/atlas.tga"), atlas, false)
// PixmapIO2.writeTGA(Gdx.files.absolute("${App.defaultDir}/atlas.tga"), atlas, false)
// PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/atlasGlow.tga"), atlasGlow, false)

View File

@@ -15,7 +15,7 @@ in vec2 v_texCoords;
uniform sampler2D u_texture;
uniform vec2 tilesInAxes; // size of the tilemap texture; vec2(tiles_in_horizontal, tiles_in_vertical)
uniform vec2 tilesInAxes; // 8x8
uniform sampler2D tilemap; // RGBA8888
uniform sampler2D tilemap2; // RGBA8888
@@ -25,11 +25,11 @@ uniform sampler2D tilesBlendAtlas; // alternative terrain for the weather mix (e
uniform float tilesBlend = 0.0; // percentage of blending [0f..1f]. 0: draws tilesAtlas, 1: draws tilesBlendAtlas
uniform vec2 tilesInAtlas = vec2(256.0, 256.0);
uniform vec2 atlasTexSize = vec2(4096.0, 4096.0);
uniform vec2 atlasTexSize = vec2(2048.0, 2048.0);
vec2 _tilesInAtlas = vec2(1.0, 1.0) / tilesInAtlas;
vec2 tileSizeInPx = atlasTexSize * _tilesInAtlas; // should be like ivec2(16.0, 16.0)
vec2 _tileSizeInPx = vec2(1.0, 1.0) / tileSizeInPx; // should be like ivec2(0.06125, 0.06125)
vec2 tileSizeInPx = atlasTexSize * _tilesInAtlas; // should be like ivec2(8.0, 8.0)
vec2 _tileSizeInPx = vec2(1.0, 1.0) / tileSizeInPx; // should be like ivec2(0.125, 0.125)
uniform vec4 colourFilter = vec4(1, 1, 1, 1); // used by WALL to darken it
@@ -62,8 +62,8 @@ ivec3 _colToInt(vec4 map1, vec4 map2) {
return ivec3(
(col1.r << 16) | (col1.g << 8) | col1.b, // tile
col2.b, // breakage
col2.g // fliprot
0,//col2.b, // breakage
0//col2.g // fliprot
);
}
@@ -129,6 +129,12 @@ void main() {
vec4 finalColor = fma(mix(finalTile, finalBreakage, finalBreakage.a), bc.xxxy, finalTile * bc.yyyx);
fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity);
// fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity);
fragColor = finalTile;
// SUBTILE fixme:
// - breakage tile samples wrong coord -- needs bigtile-to-subtile adaptation
// - somehow make fliprot work again -- needs bigtile-to-subtile adaptation
}