wall render bug fixed

- wall wouldn't render if transparent-yet-sold tiles like glass is placed on top of it
This commit is contained in:
minjaesong
2017-07-15 00:02:00 +09:00
parent eff1cb1e62
commit 1002f910e4
12 changed files with 242 additions and 155 deletions

View File

@@ -674,14 +674,14 @@ object BlendMode {
const val SCREEN = "GL_BLEND screen"
const val MULTIPLY = "GL_BLEND multiply"
const val NORMAL = "GL_BLEND normal"
//const val MAX = "GL_MAX"
//const val MAX = "GL_MAX" // not supported by GLES -- use shader
fun resolve(mode: String) {
when (mode) {
SCREEN -> blendScreen()
MULTIPLY -> blendMul()
NORMAL -> blendNormal()
//MAX -> blendLightenOnly()
//MAX -> blendLightenOnly() // not supported by GLES -- use shader
else -> throw Error("Unknown blend mode: $mode")
}
}

View File

@@ -0,0 +1,85 @@
package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.io.BufferedOutputStream
import java.io.FileOutputStream
import java.util.zip.GZIPInputStream
/**
* Created by minjaesong on 2017-07-14.
*/
fun main(args: Array<String>) { // LWJGL 3 won't work? java.lang.VerifyError
val config = LwjglApplicationConfiguration()
//config.useGL30 = true
config.vSyncEnabled = false
config.resizable = false
config.width = 1072
config.height = 742
config.foregroundFPS = 9999
LwjglApplication(TexRegionTilingTest, config)
}
object TexRegionTilingTest : ApplicationAdapter() {
lateinit var batch: SpriteBatch
lateinit var tilesTerrain: TextureRegionPack
override fun render() {
Gdx.gl.glClearColor(.094f, .094f, .094f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
val tile = BlocksDrawer.tilesTerrain.get(0, 1)
tile.texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat)
batch.inUse {
batch.draw(tile.texture, 10f, 10f, TILE_SIZE * 5f, TILE_SIZE * 5f, 0, 16, TILE_SIZE, TILE_SIZE, false, false)
}
}
private val TILE_SIZE: Int = 16
override fun create() {
batch = SpriteBatch()
// hard-coded as tga.gz
val gzFileList = listOf("blocks/terrain.tga.gz", "blocks/wire.tga.gz")
val gzTmpFName = listOf("tmp_terrain.tga", "tmp_wire.tga")
// unzip GZIP temporarily
gzFileList.forEachIndexed { index, filename ->
val terrainTexFile = Gdx.files.internal("assets/modules/basegame/" + filename)
val gzi = GZIPInputStream(terrainTexFile.read(8192))
val wholeFile = gzi.readBytes()
gzi.close()
val fos = BufferedOutputStream(FileOutputStream(gzTmpFName[index]))
fos.write(wholeFile)
fos.flush()
fos.close()
}
val terrainPixMap = Pixmap(Gdx.files.internal(gzTmpFName[0]))
tilesTerrain = TextureRegionPack(Texture(terrainPixMap), TILE_SIZE, TILE_SIZE)
tilesTerrain.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
}
override fun dispose() {
super.dispose()
}
}

View File

@@ -106,6 +106,7 @@ object BlockCodex {
prop.isFluid = boolVal(record, "fluid")
prop.isSolid = boolVal(record, "solid")
prop.isClear = boolVal(record, "clear")
prop.isWallable = boolVal(record, "wall")
prop.isFallable = boolVal(record, "fall")
prop.isVertFriction = boolVal(record, "fv")

View File

@@ -29,6 +29,7 @@ class BlockProp {
var isFluid: Boolean = false
var isSolid: Boolean = false
var isClear: Boolean = false
var isWallable: Boolean = false
var isVertFriction: Boolean = false

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.ccO
import net.torvald.terrarum.ccW
import net.torvald.terrarum.langpack.Lang
@@ -38,7 +39,7 @@ internal object CodexEdictis : ConsoleCommand {
private fun printList() {
Echo(Lang["DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS"])
CommandDict.dict.forEach { name, cmd ->
Echo("$ccW" + name)
Echo("$ccO" + name)
cmd.printUsage()
}
}

View File

@@ -27,7 +27,7 @@ import java.util.zip.GZIPInputStream
* Created by minjaesong on 16-01-19.
*/
object BlocksDrawer {
private val world: GameWorld = Terrarum.ingame!!.world
private inline val world: GameWorld; get() = Terrarum.ingame!!.world
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
@@ -385,17 +385,15 @@ object BlocksDrawer {
private fun canIHazRender(mode: Int, x: Int, y: Int) =
(world.getTileFrom(mode, x, y) != 0) && // not an air tile
// for WALLs:
if (mode == WALL)
mode == WALL && (
// DRAW WHEN it is visible and 'is a lip'
!BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isSolid ||
!(BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isSolid &&
((BlockCodex[world.getTileFromTerrain(x, y - 1) ?: 0].isSolid && BlockCodex[world.getTileFromTerrain(x, y + 1) ?: 0].isSolid)
&&
(BlockCodex[world.getTileFromTerrain(x - 1, y) ?: 0].isSolid && BlockCodex[world.getTileFromTerrain(x + 1, y + 1) ?: 0].isSolid)
)
)
)
if (mode == WALL) { // DRAW WHEN it is visible and 'is a lip'
( BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isClear ||
!
((!BlockCodex[world.getTileFromTerrain(x, y - 1) ?: 0].isClear && !BlockCodex[world.getTileFromTerrain(x, y + 1) ?: 0].isClear)
&&
(!BlockCodex[world.getTileFromTerrain(x - 1, y) ?: 0].isClear && !BlockCodex[world.getTileFromTerrain(x + 1, y + 1) ?: 0].isClear)
)
)
}
else
true