mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
did my best to draw fluids. The thing is, tiles suck at this and I need polygon-based render for fluids
This commit is contained in:
@@ -124,7 +124,7 @@ internal object BlocksDrawer {
|
||||
|
||||
//TODO
|
||||
tilesWire = TextureRegionPack(Texture(8, 8, Pixmap.Format.RGBA8888), 1, 1)
|
||||
tilesFluid = TextureRegionPack(Texture(8, 8, Pixmap.Format.RGBA8888), 1, 1)
|
||||
tilesFluid = TextureRegionPack(Texture(CreateTileAtlas.atlasFluid), TILE_SIZE, TILE_SIZE)
|
||||
|
||||
|
||||
printdbg(this, "Making terrain and wall item textures...")
|
||||
@@ -322,7 +322,7 @@ internal object BlocksDrawer {
|
||||
WALL -> world.getTileFromWall(x, y)
|
||||
TERRAIN -> world.getTileFromTerrain(x, y)
|
||||
WIRE -> world.getTileFromWire(x, y)
|
||||
FLUID -> world.getFluid(x, y).toTileInFluidAtlas()
|
||||
FLUID -> world.getFluid(x, y).type.abs()
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
@@ -349,17 +349,27 @@ internal object BlocksDrawer {
|
||||
}
|
||||
|
||||
val renderTag = CreateTileAtlas.getRenderTag(thisTile)
|
||||
val tileNumberBase = renderTag.tileNumber
|
||||
val tileNumber = tileNumberBase + when (renderTag.maskType) {
|
||||
CreateTileAtlas.RenderTag.MASK_NA -> 0
|
||||
CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo]
|
||||
CreateTileAtlas.RenderTag.MASK_47 -> connectLut47[nearbyTilesInfo]
|
||||
CreateTileAtlas.RenderTag.MASK_TORCH, CreateTileAtlas.RenderTag.MASK_PLATFORM -> nearbyTilesInfo
|
||||
else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}")
|
||||
}
|
||||
val tileNumberBase =
|
||||
if (mode == FLUID)
|
||||
CreateTileAtlas.fluidToTileNumber(world.getFluid(x, y))
|
||||
else
|
||||
renderTag.tileNumber
|
||||
val tileNumber = if (thisTile == 0) 0
|
||||
else if (mode == FLUID) tileNumberBase + connectLut47[nearbyTilesInfo]
|
||||
else tileNumberBase + when (renderTag.maskType) {
|
||||
CreateTileAtlas.RenderTag.MASK_NA -> 0
|
||||
CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo]
|
||||
CreateTileAtlas.RenderTag.MASK_47 -> connectLut47[nearbyTilesInfo]
|
||||
CreateTileAtlas.RenderTag.MASK_TORCH, CreateTileAtlas.RenderTag.MASK_PLATFORM -> nearbyTilesInfo
|
||||
else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}")
|
||||
}
|
||||
|
||||
val thisTileX = tileNumber % TILES_IN_X
|
||||
val thisTileY = tileNumber / TILES_IN_X
|
||||
var thisTileX = tileNumber % TILES_IN_X
|
||||
var thisTileY = tileNumber / TILES_IN_X
|
||||
|
||||
if (mode == FLUID && thisTileX == 22 && thisTileY == 3) {
|
||||
//println("tileNumberBase = $tileNumberBase, tileNumber = $tileNumber, fluid = ${world.getFluid(x, y)}")
|
||||
}
|
||||
|
||||
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
|
||||
val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength
|
||||
@@ -430,7 +440,8 @@ internal object BlocksDrawer {
|
||||
|
||||
var ret = 0
|
||||
for (i in 0 until nearbyTiles.size) {
|
||||
if (BlockCodex[nearbyTiles[i]].isSolid || world.getFluid(nearbyPos[i].x, nearbyPos[i].y).isFluid()) {
|
||||
val fluid = world.getFluid(nearbyPos[i].x, nearbyPos[i].y)
|
||||
if (BlockCodex[nearbyTiles[i]].isSolid || (fluid.isFluid() && 0 < CreateTileAtlas.fluidFillToTileLevel(fluid.amount))) {
|
||||
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ import kotlin.math.roundToInt
|
||||
/**
|
||||
* This class implements work_files/dynamic_shape_2_0.psd
|
||||
*
|
||||
* Tile at (0,0) AND (5,0) must be transparent. Former is because block 0 is considered as an air, and the latter
|
||||
* is because it's breakage of 0, and 0 means no breakage. Breakage part is hard-coded in the tiling shader.
|
||||
*
|
||||
* Any real tiles must begin from (0,16), the first 256x16 section is reserved for special purpose (terrain: breakage, fluid: empty)
|
||||
*
|
||||
* Created by minjaesong on 2019-02-28.
|
||||
*/
|
||||
object CreateTileAtlas {
|
||||
@@ -57,6 +62,11 @@ object CreateTileAtlas {
|
||||
atlasSpring = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
atlasFluid = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
|
||||
|
||||
atlas.blending = Pixmap.Blending.None
|
||||
atlasAutumn.blending = Pixmap.Blending.None
|
||||
atlasWinter.blending = Pixmap.Blending.None
|
||||
atlasSpring.blending = Pixmap.Blending.None
|
||||
atlasFluid.blending = Pixmap.Blending.None
|
||||
|
||||
val initMap = Pixmap(Gdx.files.internal(atlasInit))
|
||||
drawToAtlantes(initMap, 16)
|
||||
@@ -129,6 +139,7 @@ object CreateTileAtlas {
|
||||
// pixmap <- (color SCREEN fluidMasterPixmap)
|
||||
// then occupy the atlasFluid
|
||||
val pixmap = Pixmap(fluidMasterPixmap.width, fluidMasterPixmap.height, Pixmap.Format.RGBA8888)
|
||||
pixmap.blending = Pixmap.Blending.None
|
||||
|
||||
for (y in 0 until pixmap.height) {
|
||||
for (x in 0 until pixmap.width) {
|
||||
@@ -145,10 +156,9 @@ object CreateTileAtlas {
|
||||
|
||||
// test print
|
||||
//PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/$i.tga"), pixmap, false)
|
||||
// using the test print, I figured out that the output is alpha premultiplied.
|
||||
|
||||
// to the atlas
|
||||
val atlasTargetPos = 1 + 47 * 8 * (i - BlockCodex.MAX_TERRAIN_TILES)
|
||||
val atlasTargetPos = 16 + 47 * 8 * (i - BlockCodex.MAX_TERRAIN_TILES)
|
||||
for (k in 0 until 47 * 8) {
|
||||
val srcX = (k % 47) * TILE_SIZE
|
||||
val srcY = (k / 47) * TILE_SIZE
|
||||
@@ -170,10 +180,12 @@ object CreateTileAtlas {
|
||||
return tags.getOrDefault(blockID, defaultRenderTag)
|
||||
}
|
||||
|
||||
fun fluidFillToTileLevel(fill: Float) = fill.times(8).roundToInt().coerceIn(0, 8)
|
||||
|
||||
fun fluidToTileNumber(fluid: GameWorld.FluidInfo): Int {
|
||||
val fluidLevel = fluid.amount.coerceIn(0f, 1f).times(9).roundToInt()
|
||||
val fluidLevel = fluidFillToTileLevel(fluid.amount)
|
||||
return if (fluid.type == Fluid.NULL || fluidLevel == 0) 0 else
|
||||
47 * 8 * (fluid.type.abs() - 1) + 47 * (fluidLevel - 1)
|
||||
16 + (376 * (fluid.type.abs() - 1)) + (47 * (fluidLevel - 1))
|
||||
}
|
||||
|
||||
private fun fileToAtlantes(it: FileHandle) {
|
||||
|
||||
Reference in New Issue
Block a user