mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
tiles with light level <= 1 will be rendered as black square, phys support for non-self-moving bodies (e.g. balls)
Former-commit-id: 5611e2d89f4601e57d014c45f0479600778217f6 Former-commit-id: d900c0733a6d1dcbd9aaed8e9f7f1671c3866624
This commit is contained in:
@@ -432,17 +432,12 @@ object LightmapRenderer {
|
||||
if (darken < 0 || darken >= COLOUR_RANGE_SIZE)
|
||||
throw IllegalArgumentException("darken: out of range ($darken)")
|
||||
|
||||
// use equation with magic number 6.5:
|
||||
// =>> val r = data.r() * (1f + brighten.r() * 6.5f) <<=
|
||||
// gives 8-visible-tile penetration of sunlight, fairly smooth,
|
||||
// DOES NOT GO BELOW (2,2,2)
|
||||
// use equation with magic number 9.0
|
||||
// smooooooth
|
||||
|
||||
val r = data.r() * (1f - darken.r() * 6.5f)
|
||||
val g = data.g() * (1f - darken.g() * 6.5f)
|
||||
val b = data.b() * (1f - darken.b() * 6.5f)
|
||||
//val r = data.r() - darken.r()
|
||||
//val g = data.g() - darken.g()
|
||||
//val b = data.b() - darken.b()
|
||||
val r = data.r() * (1f - darken.r() * 9.0f)
|
||||
val g = data.g() * (1f - darken.g() * 9.0f)
|
||||
val b = data.b() * (1f - darken.b() * 9.0f)
|
||||
|
||||
return constructRGBFromFloat(r.clampZero(), g.clampZero(), b.clampZero())
|
||||
}
|
||||
@@ -629,6 +624,13 @@ object LightmapRenderer {
|
||||
private fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this
|
||||
|
||||
fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y)
|
||||
fun getLowestRGB(x: Int, y: Int): Int? {
|
||||
val value = getLight(x, y)
|
||||
if (value == null)
|
||||
return null
|
||||
else
|
||||
return FastMath.min(value.rawR(), value.rawG(), value.rawB())
|
||||
}
|
||||
|
||||
private fun purgeLightmap() {
|
||||
for (y in 0..LIGHTMAP_HEIGHT - 1) {
|
||||
|
||||
@@ -11,14 +11,18 @@ object MapCamera {
|
||||
private val world: GameWorld = Terrarum.ingame.world
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
var x = 0
|
||||
var x: Int = 0
|
||||
private set
|
||||
var y = 0
|
||||
var y: Int = 0
|
||||
private set
|
||||
var width: Int = 0
|
||||
private set
|
||||
var height: Int = 0
|
||||
private set
|
||||
val xCentre: Int
|
||||
get() = x + width.ushr(1)
|
||||
val yCentre: Int
|
||||
get() = y + height.ushr(1)
|
||||
|
||||
fun update() {
|
||||
val player = Terrarum.ingame.player
|
||||
|
||||
@@ -278,6 +278,8 @@ object TilesDrawer {
|
||||
blendNormal()
|
||||
}
|
||||
|
||||
private val tileDrawLightThreshold = 2
|
||||
|
||||
private fun drawTiles(g: Graphics, mode: Int, drawModeTilesBlendMul: Boolean) {
|
||||
val for_y_start = y / TILE_SIZE
|
||||
val for_y_end = TilesDrawer.clampHTile(for_y_start + (height / TILE_SIZE) + 2)
|
||||
@@ -305,59 +307,72 @@ object TilesDrawer {
|
||||
|
||||
// draw
|
||||
try {
|
||||
if (
|
||||
(mode == WALL || mode == TERRAIN) && // not an air tile
|
||||
(thisTile ?: 0) > 0) //&& // commented out: meh
|
||||
if ((mode == WALL || mode == TERRAIN) && // not an air tile
|
||||
(thisTile ?: 0) != Tile.AIR) {
|
||||
// check if light level of nearby or this tile is illuminated
|
||||
/*( LightmapRenderer.getValueFromMap(x, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y + 1) ?: 0 > 0)
|
||||
)*/ {
|
||||
val nearbyTilesInfo: Int
|
||||
if (isPlatform(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
|
||||
}
|
||||
else if (isWallSticker(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
|
||||
}
|
||||
else if (isConnectMutual(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
|
||||
}
|
||||
else if (isConnectSelf(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
|
||||
}
|
||||
if ( LightmapRenderer.getLowestRGB(x, y) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x - 1, y) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x + 1, y) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x, y - 1) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x, y + 1) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x - 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x + 1, y + 1) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
|
||||
LightmapRenderer.getLowestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) {
|
||||
// blackness
|
||||
/*if (zeroTileCounter > 0) {
|
||||
g.color = Color.black
|
||||
g.fillRect(
|
||||
(x - zeroTileCounter) * TILE_SIZE.toFloat(), y * TILE_SIZE.toFloat(),
|
||||
zeroTileCounter * TILE_SIZE.toFloat(), TILE_SIZE.toFloat()
|
||||
)
|
||||
g.color = Color.white
|
||||
zeroTileCounter = 0
|
||||
}*/
|
||||
|
||||
|
||||
val nearbyTilesInfo: Int
|
||||
if (isPlatform(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
|
||||
}
|
||||
else if (isWallSticker(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
|
||||
}
|
||||
else if (isConnectMutual(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
|
||||
}
|
||||
else if (isConnectSelf(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
|
||||
}
|
||||
else {
|
||||
nearbyTilesInfo = 0
|
||||
}
|
||||
|
||||
|
||||
val thisTileX: Int
|
||||
if (!noDamageLayer)
|
||||
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
|
||||
else
|
||||
thisTileX = nearbyTilesInfo
|
||||
|
||||
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
|
||||
|
||||
if (drawModeTilesBlendMul) {
|
||||
if (TilesDrawer.isBlendMul(thisTile)) {
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// do NOT add "if (!isBlendMul(thisTile))"!
|
||||
// or else they will not look like they should be when backed with wall
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} // end if (is illuminated)
|
||||
else {
|
||||
nearbyTilesInfo = 0
|
||||
zeroTileCounter++
|
||||
drawTile(mode, x, y, 1, 0) // black patch
|
||||
}
|
||||
|
||||
|
||||
val thisTileX: Int
|
||||
if (!noDamageLayer)
|
||||
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
|
||||
else
|
||||
thisTileX = nearbyTilesInfo
|
||||
|
||||
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
|
||||
|
||||
if (drawModeTilesBlendMul) {
|
||||
if (TilesDrawer.isBlendMul(thisTile)) {
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} else {
|
||||
// do NOT add "if (!isBlendMul(thisTile))"!
|
||||
// or else they will not look like they should be when backed with wall
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} // end if (not an air and is illuminated)
|
||||
else {
|
||||
zeroTileCounter++
|
||||
}
|
||||
} // end if (not an air)
|
||||
} catch (e: NullPointerException) {
|
||||
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user