diff --git a/assets/tiling.frag b/assets/tiling.frag index 64bd0243b..991be0f03 100644 --- a/assets/tiling.frag +++ b/assets/tiling.frag @@ -34,10 +34,23 @@ ivec2 getTileXY(int tileNumber) { return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x)); } -int getTileFromColor(vec4 color) { +// return: int=0xrrggbb +int _colToInt(vec4 color) { return int(color.b * 255) | (int(color.g * 255) << 8) | (int(color.r * 255) << 16); } +// 0x0rggbb where int=0xaarrggbb +// return: [0..1048575] +int getTileFromColor(vec4 color) { + return _colToInt(color) & 0x0FFFFF; +} + +// 0xr00000 where int=0xaarrggbb +// return: [0..15] +int getBreakageFromColor(vec4 color) { + return (_colToInt(color) >> 20) & 0xF; +} + void main() { // READ THE FUCKING MANUAL, YOU DONKEY !! // @@ -54,28 +67,31 @@ void main() { mediump vec4 tileFromMap = texture2D(tilemap, flippedFragCoord / overscannedScreenDimension); // <- THE CULPRIT int tile = getTileFromColor(tileFromMap); + int breakage = getBreakageFromColor(tileFromMap); ivec2 tileXY = getTileXY(tile); + ivec2 breakageXY = getTileXY(breakage + 5); vec2 coordInTile = mod(pxCoord, tileSizeInPx) / tileSizeInPx; // 0..1 regardless of tile position in atlas highp vec2 singleTileSizeInUV = vec2(1) / tilesInAtlas; // constant 0.00390625 + highp vec2 uvCoordForTile = coordInTile * singleTileSizeInUV; // 0..0.00390625 regardless of tile position in atlas highp vec2 uvCoordOffset = tileXY * singleTileSizeInUV; // where the tile starts in the atlas, using uv coord (0..1) + highp vec2 uvCoordOffsetBreakage = breakageXY * singleTileSizeInUV; highp vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffset;// where we should be actually looking for in atlas, using UV coord (0..1) + highp vec2 finalUVCoordForBreakage = uvCoordForTile + uvCoordOffsetBreakage; - // TODO blend a breakage (0xrrggbb where 0xr0 -- upper 4 bits of int_red component) + // TODO finally "blend" a breakage (0xrrggbb where 0xr00000 -- upper 4 bits of int_red component) + mediump vec4 finalTile = texture2D(tilesAtlas, finalUVCoordForTile); + mediump vec4 finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage); + + gl_FragColor = colourFilter * (mix(finalTile, finalBreakage, finalBreakage.a)); - // if statements considered harmful (on shader program) - // --definitely not Dijkstra - /*if (tileXY.x == 0 && tileXY.y == 0) - gl_FragColor = nocolour; - else*/ - gl_FragColor = colourFilter * texture2D(tilesAtlas, finalUVCoordForTile); } diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index 8458a378f..ec3b83c4f 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -216,7 +216,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } fun updateScreen(delta: Float) { - Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) + //Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) demoWorld.globalLight = WeatherMixer.globalLightNow demoWorld.updateWorldTime(delta) diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 6a0cc4ae0..40afc4392 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -463,7 +463,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { - Gdx.graphics.setTitle(getCanonicalTitle()) + //Gdx.graphics.setTitle(getCanonicalTitle()) // ASYNCHRONOUS UPDATE AND RENDER // diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt index f4fca2e10..d87021da9 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt @@ -81,7 +81,8 @@ object PlayerBuilderSigrid { Block.STONE_QUARRIED, Block.STONE_TILE_WHITE, Block.TORCH, Block.DAYLIGHT_CAPACITOR, Block.ICE_FRAGILE, Block.ILLUMINATOR_WHITE, Block.ILLUMINATOR_BLACK, Block.ILLUMINATOR_ORANGE, - Block.ILLUMINATOR_GREEN, Block.ILLUMINATOR_CYAN, Block.SUNSTONE + Block.ILLUMINATOR_GREEN, Block.ILLUMINATOR_CYAN, Block.SUNSTONE, + Block.ORE_COPPER ) val walls = arrayOf( Block.AIR, Block.DIRT, Block.GLASS_CRUDE, diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index fd78cb0c3..1ebeba7b8 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -179,7 +179,14 @@ internal object BlocksDrawer { Block.ILLUMINATOR_TAN_OFF, Block.ILLUMINATOR_WHITE_OFF, Block.ILLUMINATOR_YELLOW, - Block.DAYLIGHT_CAPACITOR + Block.DAYLIGHT_CAPACITOR, + + Block.ORE_COPPER, + Block.ORE_IRON, + Block.ORE_GOLD, + Block.ORE_SILVER, + Block.ORE_ILMENITE, + Block.ORE_AURICHALCUM ) /** @@ -216,12 +223,6 @@ internal object BlocksDrawer { Block.SNOW, Block.ICE_NATURAL, Block.ICE_MAGICAL, - Block.ORE_COPPER, - Block.ORE_IRON, - Block.ORE_GOLD, - Block.ORE_SILVER, - Block.ORE_ILMENITE, - Block.ORE_AURICHALCUM, Block.SANDSTONE, Block.SANDSTONE_BLACK, @@ -499,20 +500,28 @@ internal object BlocksDrawer { val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE + val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y) + val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength + val breakingStage = (breakage / maxHealth).times(breakAnimSteps).roundInt() + + // draw a tile if (drawModeTilesBlendMul) { + // while iterating through, only the some tiles are actually eligible to be drawn as MUL, + // so obviously when we caught not eligible tile, we need to skip that by marking as Tile No. zero + if (isBlendMul(thisTile)) { - writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY) + writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage) } else { - writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0) + writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0, 0) } } else { // do NOT add "if (!isBlendMul(thisTile))"! // or else they will not look like they should be when backed with wall - writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY) + writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage) } // draw a breakage @@ -664,13 +673,17 @@ internal object BlocksDrawer { * * @return Raw colour bits in RGBA8888 format */ - private fun sheetXYToTilemapColour(mode: Int, sheetX: Int, sheetY: Int): Int = when (mode) { - TERRAIN, WALL -> (tilesTerrain.horizontalCount * sheetY + sheetX).shl(8) or 255 - WIRE -> (tilesWire.horizontalCount * sheetY + sheetX).shl(8) or 255 + private fun sheetXYToTilemapColour(mode: Int, sheetX: Int, sheetY: Int, breakage: Int): Int = when (mode) { + // the tail ".or(255)" is there to write 1.0 to the A channel (remember, return type is RGBA) + + TERRAIN, WALL -> + (tilesTerrain.horizontalCount * sheetY + sheetX).shl(8).or(255) or // the actual tile bits + breakage.and(15).shl(28) // breakage bits + WIRE -> (tilesWire.horizontalCount * sheetY + sheetX).shl(8).or(255) else -> throw IllegalArgumentException() } - private fun writeToBuffer(mode: Int, bufferPosX: Int, bufferPosY: Int, sheetX: Int, sheetY: Int) { + private fun writeToBuffer(mode: Int, bufferPosX: Int, bufferPosY: Int, sheetX: Int, sheetY: Int, breakage: Int) { val sourceBuffer = when(mode) { TERRAIN -> terrainTilesBuffer WALL -> wallTilesBuffer @@ -679,7 +692,7 @@ internal object BlocksDrawer { } - sourceBuffer[bufferPosY][bufferPosX] = sheetXYToTilemapColour(mode, sheetX, sheetY) + sourceBuffer[bufferPosY][bufferPosX] = sheetXYToTilemapColour(mode, sheetX, sheetY, breakage) } private fun renderUsingBuffer(mode: Int, projectionMatrix: Matrix4) { diff --git a/work_files/graphics/terrain/terrain.psd.gz b/work_files/graphics/terrain/terrain.psd.gz index cd617fff4..fd2df1cf6 100644 --- a/work_files/graphics/terrain/terrain.psd.gz +++ b/work_files/graphics/terrain/terrain.psd.gz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a2bd3eb3b413af8e7b657440831297801c464354df77f955446afad41033bcb4 -size 509697 +oid sha256:500417790ec4bd9468c48ab1535d7fbbc69f59f22b0ef4ede110e57118a42489 +size 516881