even better fluid tiling

This commit is contained in:
minjaesong
2024-07-24 19:14:24 +09:00
parent af81bb0e0f
commit 97286e7d99
7 changed files with 57 additions and 56 deletions

View File

@@ -2037,8 +2037,8 @@ object BTeXParser {
private const val HEADING_NUM_TITLE_GAP = 9
val ccDefault = TerrarumSansBitmap.toColorCode(0,0,0)
val ccBucks = TerrarumSansBitmap.toColorCode(5,0,0)
val ccCode = TerrarumSansBitmap.toColorCode(7,0,0)
val ccBucks = TerrarumSansBitmap.toColorCode(10,0,6)
val ccCode = TerrarumSansBitmap.toColorCode(12,0,7)
val ccHref = TerrarumSansBitmap.toColorCode(0,3,11)
val ccEmph = TerrarumSansBitmap.toColorCode(0xfc11)
val ccItemName = TerrarumSansBitmap.toColorCode(0xf03b)

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Fluid
@@ -29,7 +30,12 @@ class ItemBottomlessWaterBucket(originalID: ItemID) : GameItem(originalID) {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
val mx = Terrarum.mouseTileX; val my =Terrarum.mouseTileY
INGAME.world.setFluid(mx, my, Fluid.WATER, 1f)
return 0L
if (!BlockCodex[INGAME.world.getTileFromTerrain(mx, my)].isSolid) {
INGAME.world.setFluid(mx, my, Fluid.WATER, 1f)
return 0L
}
else {
return -1L
}
}
}

View File

@@ -33,13 +33,13 @@ import kotlin.system.measureTimeMillis
*/
class BTeXTest : ApplicationAdapter() {
// val filePath = "btex.btxbook"
val filePath = "btex.xml"
// val filePath = "btex_ko.xml"
// val filePath = "test.xml"
// val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"
// val filePath = "literature/koKR/yisang_nalgae.xml"
val filePath = "literature/koKR/yisang_geonchukmuhanyukmyeongakche.xml"
// val filePath = "literature/koKR/yisang_geonchukmuhanyukmyeongakche.xml"
private var serialise = true

View File

@@ -377,10 +377,7 @@ internal object BlocksDrawer {
val solids = getNearbyTilesInfoTileCnx(x, y)
val notSolid = 15 - solids
val fluids = getNearbyFluidsInfo(x, y)
val fmask = getFluidMaskStatus(fluids)
val tileToUse = fluidCornerLut[notSolid and fmask] and fluidCornerLut[solids]
val fluidU = fluids[3].amount
val nearbyFluidType = fluids.asSequence().filter { it.amount >= 0.5f / 16f }.map { it.type }.filter { it.startsWith("fluid@") }.sorted().firstOrNull()
@@ -390,23 +387,48 @@ internal object BlocksDrawer {
val tile = world.getTileFromTerrain(wx, wy)
if (BlockCodex[tile].isSolidForTileCnx && nearbyFluidType != null) {
val fmask = getFluidMaskStatus(fluids)
var tileToUse = fluidCornerLut[notSolid and fmask] and fluidCornerLut[solids]
rawTileNum = world.tileNameToNumberMap[nearbyFluidType]!!
// upper points and lower points use different maths
// in either case, LR fluids are to be checked
val fluidR = fluids[0].amount
val fluidL = fluids[2].amount
// check LR for down points
if (tileToUse and 0b0110 != 0) {
if (fluidR < 0.5f / 16f)
tileToUse = tileToUse and 0b1101
if (fluidL < 0.5f / 16f)
tileToUse = tileToUse and 0b1011
}
// check R
else if (tileToUse and 0b0010 != 0) {
if (fluidR < 0.5f / 16f )
tileToUse = 0
}
// check L
else if (tileToUse and 0b0100 != 0) {
if (fluidL < 0.5f / 16f)
tileToUse = 0
}
18 + tileToUse
}
else if (rawTileNum == 0)
0
else if (fluids[3].amount >= 1.5f / 16f)
else if (bufferY > 0 && tempRenderTypeBuffer[bufferY - 1, bufferX].let {
it.ushr(16) == rawTileNum && it.and(255) == 0
})
16
else if (bufferY > 0 && tempRenderTypeBuffer[bufferY - 1, bufferX].let {
it.ushr(16) == rawTileNum && it.and(255) < 18
})
17
else if (fluids[3].amount >= 0.5f / 16f) {
//if tile above is fluid tile which use 16, use 17
if (bufferY > 0 && tempRenderTypeBuffer[bufferY - 1, bufferX].let {
(it.ushr(16) == rawTileNum && it.and(255) >= 16) ||
(it.ushr(16) == rawTileNum && it.and(255) == 1)
})
17
// else, use 16
else 16
}
else if (fillThis < 0.5f / 16f)
0
else if (fillThis >= 15.5f / 16f) {
@@ -433,7 +455,7 @@ internal object BlocksDrawer {
15
}
else
(fillThis * 16f - 0.5f).roundToInt().coerceIn(0, 15)
(fillThis * 16f - 0.5f).floorToInt().coerceIn(0, 15)
}
else if (treeLeavesTiles.binarySearch(rawTileNum) >= 0) {
getNearbyTilesInfoTrees(x, y, mode).swizzle8(rawTileNum, hash)

View File

@@ -91,8 +91,6 @@ object LightmapRenderer {
private var _mapThisTileOpacity = UnsafeCvecArray(LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT)
private var _mapThisTileOpacity2 = UnsafeCvecArray(LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT)
private const val AIR = Block.AIR
const val DRAW_TILE_SIZE: Float = TILE_SIZE / IngameRenderer.lightmapDownsample
internal var for_x_start = 0
@@ -540,7 +538,9 @@ object LightmapRenderer {
}*/
if (_thisFluid.type != Fluid.NULL) {
_fluidAmountToCol.set(_thisFluid.amount, _thisFluid.amount, _thisFluid.amount, _thisFluid.amount)
_thisFluid.amount.coerceAtMost(1f).let {
_fluidAmountToCol.set(it, it, it, it)
}
_thisTileLuminosity.set(_thisTerrainProp.getLumCol(worldX, worldY))
_thisTileLuminosity.maxAndAssign(_thisFluidProp.lumCol.mul(_fluidAmountToCol))
@@ -649,36 +649,6 @@ object LightmapRenderer {
return if (BlockCodex[world.getTileFromTerrain(x, y)].isSolid) 1.2f else 1f
}
internal class Ivec4 {
var r = 0
var g = 0
var b = 0
var a = 0
fun broadcast(scalar: Int) {
r=scalar
g=scalar
b=scalar
a=scalar
}
fun add(scalar: Int) {
r+=scalar
g+=scalar
b+=scalar
a+=scalar
}
fun lane(index: Int) = when(index) {
0 -> r
1 -> g
2 -> b
3 -> a
else -> throw IndexOutOfBoundsException("Invalid index $index")
}
}
var lightBuffer: Pixmap = Pixmap(64, 64, Pixmap.Format.RGBA8888) // must not be too small
private val colourNull = Cvec(0)