camera clamping, UI resize

This commit is contained in:
minjaesong
2017-07-15 02:02:30 +09:00
parent 75795677be
commit f7867c1a6b
7 changed files with 83 additions and 39 deletions

View File

@@ -383,8 +383,9 @@ object BlocksDrawer {
private val tileDrawLightThreshold = 2f / LightmapRenderer.MUL
private fun canIHazRender(mode: Int, x: Int, y: Int) =
(world.getTileFrom(mode, x, y) != 0) && // not an air tile
// for WALLs:
(world.getTileFrom(mode, x, y) != 0) // not an air tile
&&
// for WALLs; else: ret true
if (mode == WALL) { // DRAW WHEN it is visible and 'is a lip'
( BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isClear ||
!
@@ -399,6 +400,18 @@ object BlocksDrawer {
// end
private fun hasLightNearby(x: Int, y: Int) = ( // check if light level of nearby or this tile is illuminated
LightmapRenderer.getHighestRGB(x, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0f >= tileDrawLightThreshold
)
private fun drawTiles(batch: SpriteBatch, mode: Int, drawModeTilesBlendMul: Boolean, color: Color) {
val for_y_start = y / TILE_SIZE
val for_y_end = BlocksDrawer.clampHTile(for_y_start + (height / TILE_SIZE) + 2)
@@ -430,18 +443,17 @@ object BlocksDrawer {
// draw a tile, but only when illuminated
try {
if (canIHazRender(mode, x, y)) {
// check if light level of nearby or this tile is illuminated
if ( LightmapRenderer.getHighestRGB(x, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0f >= tileDrawLightThreshold)
{
// FIXME bad scanlines bug
if (!hasLightNearby(x, y)) {
// draw black patch
zeroTileCounter += 1 // unused for now
// temporary solution; FIXME bad scanlines bug
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
}
else {
// commented out; FIXME bad scanlines bug
if (zeroTileCounter > 0) {
/*batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
@@ -504,12 +516,6 @@ object BlocksDrawer {
} // end if (is illuminated)
// draw black patch
else {
zeroTileCounter += 1 // unused for now
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
}
} // end if (not an air)
} catch (e: NullPointerException) {
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.blockproperties.BlockCodex
import com.jme3.math.FastMath
import net.torvald.dataclass.Float16
import net.torvald.terrarum.Ingame
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
@@ -40,6 +41,8 @@ object LightmapRenderer {
val LIGHTMAP_HEIGHT = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.HEIGHT)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
//data class Lux(var r: Float16, var g: Float16, var b: Float16, var uv: Float16)
/**
* Float value, 1.0 for 1023
*/

View File

@@ -15,13 +15,13 @@ object WorldCamera {
private val world: GameWorld? = Terrarum.ingame?.world
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
var x: Int = 0
var x: Int = 0 // left position
private set
var y: Int = 0
var y: Int = 0 // top position
private set
var gdxCamX: Float = 0f
var gdxCamX: Float = 0f // centre position
private set
var gdxCamY: Float = 0f
var gdxCamY: Float = 0f // centre position
private set
var width: Int = 0
private set
@@ -47,11 +47,21 @@ object WorldCamera {
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
TILE_SIZE.toFloat(),
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)).floorInt()
)).floorInt().clampCameraY()
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}
}
}
private fun Int.clampCameraY(): Int {
return if (this < 0)
0
else if (this > (world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT)
(world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT
else
this
}
}