dunno why but setting camera position to negative works...

This commit is contained in:
minjaesong
2017-07-03 23:42:59 +09:00
parent b7fb8ff4da
commit 7b2b6caf82
10 changed files with 112 additions and 72 deletions

View File

@@ -407,14 +407,14 @@ object BlocksDrawer {
val for_x_start = x / TILE_SIZE - 1
val for_x_end = for_x_start + (width / TILE_SIZE) + 3
var zeroTileCounter = 0
val originalBatchColour = batch.color.cpy()
batch.color = color
// loop
for (y in for_y_start..for_y_end) {
for (x in for_x_start..for_x_end - 1) {
var zeroTileCounter = 0
for (x in for_x_start..for_x_end) {
val thisTile: Int?
if (mode % 3 == WALL)
@@ -440,11 +440,13 @@ object BlocksDrawer {
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) {
// blackness
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold)
{
// TODO coalesce non-lit black patches
if (zeroTileCounter > 0) {
/* unable to do anything */
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
batch.color = color
zeroTileCounter = 0
}
@@ -505,17 +507,22 @@ object BlocksDrawer {
} // end if (is illuminated)
// draw black patch
else {
zeroTileCounter++ // unused for now
batch.color = Color.BLACK
drawTile(batch, mode, x, y, 1, 0)
batch.color = color
zeroTileCounter += 1 // unused for now
}
} // end if (not an air)
} catch (e: NullPointerException) {
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
}
// hit the end of the current scanline
// FIXME bad scanlines bug
if (x == for_x_end) {
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
batch.color = color
zeroTileCounter = 0
}
}
}
@@ -650,14 +657,14 @@ object BlocksDrawer {
if (mode == TERRAIN || mode == WALL)
batch.draw(
tilesTerrain.get(sheetX, sheetY),
(tilewisePosX * TILE_SIZE).toFloat(),
(tilewisePosY * TILE_SIZE).toFloat()
tilewisePosX * TILE_SIZEF,
tilewisePosY * TILE_SIZEF
)
else if (mode == WIRE)
batch.draw(
tilesWire.get(sheetX, sheetY),
(tilewisePosX * TILE_SIZE).toFloat(),
(tilewisePosY * TILE_SIZE).toFloat()
tilewisePosX * TILE_SIZEF,
tilewisePosY * TILE_SIZEF
)
else
throw IllegalArgumentException()

View File

@@ -85,7 +85,7 @@ object LightmapRenderer {
}
}
fun renderLightMap() {
fun fireRecalculateEvent() {
for_x_start = WorldCamera.x / TILE_SIZE - 1 // fix for premature lightmap rendering
for_y_start = WorldCamera.y / TILE_SIZE - 1 // on topmost/leftmost side
@@ -244,6 +244,8 @@ object LightmapRenderer {
// O(9n) == O(n) where n is a size of the map
// TODO devise multithreading on this
var ambientAccumulator = 0
var lightLevelThis: Int = 0
val thisTerrain = TerrarumGDX.ingame!!.world.getTileFromTerrain(x, y)
val thisWall = TerrarumGDX.ingame!!.world.getTileFromWall(x, y)
@@ -281,16 +283,17 @@ object LightmapRenderer {
* sample ambient for eight points and apply attenuation for those
* maxblend eight values and use it
*/
var ambient = 0
/* + */ambient = ambient maxBlend darkenColoured(getLight(x - 1, y - 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambient = ambient maxBlend darkenColoured(getLight(x + 1, y - 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambient = ambient maxBlend darkenColoured(getLight(x - 1, y + 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambient = ambient maxBlend darkenColoured(getLight(x + 1, y + 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* * */ambient = ambient maxBlend darkenColoured(getLight(x , y - 1) ?: 0, thisTileOpacity)
/* * */ambient = ambient maxBlend darkenColoured(getLight(x , y + 1) ?: 0, thisTileOpacity)
/* * */ambient = ambient maxBlend darkenColoured(getLight(x - 1, y ) ?: 0, thisTileOpacity)
/* * */ambient = ambient maxBlend darkenColoured(getLight(x + 1, y ) ?: 0, thisTileOpacity)
return lightLevelThis maxBlend ambient
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y - 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y - 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y + 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y + 1) ?: 0, scaleColour(thisTileOpacity, 1.4142f))
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y - 1) ?: 0, thisTileOpacity)
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y + 1) ?: 0, thisTileOpacity)
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y ) ?: 0, thisTileOpacity)
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y ) ?: 0, thisTileOpacity)
return lightLevelThis maxBlend ambientAccumulator
}
else {
return lightLevelThis
@@ -457,19 +460,15 @@ object LightmapRenderer {
// use equation with magic number 8.0
// should draw somewhat exponential curve when you plot the propagation of light in-game
val r = data.r() * (1f - darken.r() * lightScalingMagic)
val g = data.g() * (1f - darken.g() * lightScalingMagic)
val b = data.b() * (1f - darken.b() * lightScalingMagic)
return constructRGBFromFloat(r.clampZero(), g.clampZero(), b.clampZero())
return ((data.r() * (1f - darken.r() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round() * MUL_2 +
((data.g() * (1f - darken.g() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round() * MUL +
((data.b() * (1f - darken.b() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round()
}
fun scaleColour(data: Int, scale: Float): RGB10 {
val r = data.r() * scale
val g = data.g() * scale
val b = data.b() * scale
return constructRGBFromFloat(r.clampOne(), g.clampOne(), b.clampOne())
return ((data.r() * scale).clampOne() * CHANNEL_MAX).round() * MUL_2 +
((data.g() * scale).clampOne() * CHANNEL_MAX).round() * MUL +
((data.b() * scale).clampOne() * CHANNEL_MAX).round()
}
/**
@@ -557,38 +556,38 @@ object LightmapRenderer {
* @param rgb2
* @return
*/
private inline infix fun RGB10.maxBlend(other: Int): RGB10 {
private infix fun RGB10.maxBlend(other: Int): RGB10 {
return (if (this.rawR() > other.rawR()) this.rawR() else other.rawR()) * MUL_2 +
(if (this.rawG() > other.rawG()) this.rawG() else other.rawG()) * MUL +
(if (this.rawB() > other.rawB()) this.rawB() else other.rawB())
}
private inline infix fun RGB10.linMix(other: Int): RGB10 {
private infix fun RGB10.linMix(other: Int): RGB10 {
return ((this.rawR() + other.rawR()) ushr 1) * MUL_2 +
((this.rawG() + other.rawG()) ushr 1) * MUL +
((this.rawB() + other.rawB()) ushr 1)
}
private inline infix fun RGB10.colSub(other: Int): RGB10 {
private infix fun RGB10.colSub(other: Int): RGB10 {
return ((this.rawR() - other.rawR()).clampChannel()) * MUL_2 +
((this.rawG() - other.rawG()).clampChannel()) * MUL +
((this.rawB() - other.rawB()).clampChannel())
}
private inline infix fun RGB10.colAdd(other: Int): RGB10 {
private infix fun RGB10.colAdd(other: Int): RGB10 {
return ((this.rawR() + other.rawR()).clampChannel()) * MUL_2 +
((this.rawG() + other.rawG()).clampChannel()) * MUL +
((this.rawB() + other.rawB()).clampChannel())
}
inline fun RGB10.rawR() = this / MUL_2
inline fun RGB10.rawG() = this % MUL_2 / MUL
inline fun RGB10.rawB() = this % MUL
fun RGB10.rawR() = this / MUL_2
fun RGB10.rawG() = this % MUL_2 / MUL
fun RGB10.rawB() = this % MUL
/** 0.0 - 1.0 for 0-1023 (0.0 - 0.25 for 0-255) */
inline fun RGB10.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT
inline fun RGB10.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT
inline fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT
fun RGB10.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT
fun RGB10.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT
fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT
/**
@@ -631,11 +630,11 @@ object LightmapRenderer {
(b * CHANNEL_MAX).round()
}
inline fun Int.clampZero() = if (this < 0) 0 else this
inline fun Float.clampZero() = if (this < 0) 0f else this
inline fun Int.clampChannel() = if (this < 0) 0 else if (this > CHANNEL_MAX) CHANNEL_MAX else this
inline fun Float.clampOne() = if (this < 0) 0f else if (this > 1) 1f else this
inline fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this
fun Int.clampZero() = if (this < 0) 0 else this
fun Float.clampZero() = if (this < 0) 0f else this
fun Int.clampChannel() = if (this < 0) 0 else if (this > CHANNEL_MAX) CHANNEL_MAX else this
fun Float.clampOne() = if (this < 0) 0f else if (this > 1) 1f else this
fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this
inline fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y)
fun getHighestRGB(x: Int, y: Int): Int? {