mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 07:36:06 +09:00
dunno why but setting camera position to negative works...
This commit is contained in:
@@ -7,7 +7,7 @@ import org.dyn4j.geometry.Vector2
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-01-15.
|
* Created by minjaesong on 16-01-15.
|
||||||
*/
|
*/
|
||||||
class Point2d(var x: Double, var y: Double) : Cloneable {
|
data class Point2d(var x: Double, var y: Double) : Cloneable {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "($x, $y)"
|
return "($x, $y)"
|
||||||
@@ -53,4 +53,5 @@ class Point2d(var x: Double, var y: Double) : Cloneable {
|
|||||||
|
|
||||||
fun length(other: Point2d) = distSqr(other).sqrt()
|
fun length(other: Point2d) = distSqr(other).sqrt()
|
||||||
fun distSqr(other: Point2d) = ((this.x - other.x).sqr() + (this.y - other.y).sqr())
|
fun distSqr(other: Point2d) = ((this.x - other.x).sqr() + (this.y - other.y).sqr())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
val ZOOM_MIN = 0.5f
|
val ZOOM_MIN = 0.5f
|
||||||
|
|
||||||
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
|
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
|
||||||
//var backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
|
|
||||||
|
|
||||||
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
|
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
|
||||||
//private lateinit var shaderBlur: Shader
|
//private lateinit var shaderBlur: Shader
|
||||||
@@ -265,7 +264,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
)
|
)
|
||||||
uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer
|
uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer
|
||||||
uiAliases.forEach { addUI(it) } // put them all to the UIContainer
|
uiAliases.forEach { addUI(it) } // put them all to the UIContainer
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
LightmapRenderer.fireRecalculateEvent()
|
||||||
|
}// END enter
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
@@ -379,7 +382,6 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
|
|
||||||
// Post-update; ones that needs everything is completed //
|
// Post-update; ones that needs everything is completed //
|
||||||
LightmapRenderer.renderLightMap() //
|
|
||||||
FeaturesDrawer.render(batch) //
|
FeaturesDrawer.render(batch) //
|
||||||
// end of post-update //
|
// end of post-update //
|
||||||
|
|
||||||
@@ -387,9 +389,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
// now the actual drawing part //
|
// now the actual drawing part //
|
||||||
worldDrawFrameBuffer.inAction {
|
worldDrawFrameBuffer.inAction {
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
|
// using custom code; this is obscure and tricky
|
||||||
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
|
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
@@ -423,6 +427,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
blendNormal()
|
blendNormal()
|
||||||
else
|
else
|
||||||
blendMul()
|
blendMul()
|
||||||
|
LightmapRenderer.fireRecalculateEvent()
|
||||||
LightmapRenderer.draw(batch)
|
LightmapRenderer.draw(batch)
|
||||||
|
|
||||||
|
|
||||||
@@ -806,20 +811,25 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadParallel.startAll()
|
ThreadParallel.startAll()
|
||||||
|
|
||||||
|
playableActorDelegate?.update(delta)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actorContainer.forEach {
|
actorContainer.forEach {
|
||||||
it.update(delta)
|
if (it != playableActorDelegate?.actor) {
|
||||||
|
it.update(delta)
|
||||||
|
|
||||||
if (it is Pocketed) {
|
if (it is Pocketed) {
|
||||||
it.inventory.forEach { inventoryEntry ->
|
it.inventory.forEach { inventoryEntry ->
|
||||||
inventoryEntry.item.effectWhileInPocket(delta)
|
inventoryEntry.item.effectWhileInPocket(delta)
|
||||||
if (it.equipped(inventoryEntry.item)) {
|
if (it.equipped(inventoryEntry.item)) {
|
||||||
inventoryEntry.item.effectWhenEquipped(delta)
|
inventoryEntry.item.effectWhenEquipped(delta)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
playableActorDelegate?.update(delta)
|
||||||
//AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
|
//AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1085,6 +1095,9 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
// Set up viewport when window is resized
|
// Set up viewport when window is resized
|
||||||
initViewPort(width, height)
|
initViewPort(width, height)
|
||||||
|
|
||||||
|
|
||||||
|
LightmapRenderer.fireRecalculateEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
@@ -1098,7 +1111,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
|
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
|
||||||
*/
|
*/
|
||||||
fun setCameraPosition(newX: Float, newY: Float) {
|
fun setCameraPosition(newX: Float, newY: Float) {
|
||||||
camera.position.set(newX + TerrarumGDX.HALFW, newY + TerrarumGDX.HALFH, 0f)
|
camera.position.set(-newX + TerrarumGDX.HALFW, -newY + TerrarumGDX.HALFH, 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
|
|||||||
|
|
||||||
@Volatile var hitboxStart: Point2d
|
@Volatile var hitboxStart: Point2d
|
||||||
private set
|
private set
|
||||||
val hitboxEnd: Point2d
|
inline val hitboxEnd: Point2d
|
||||||
get() = Point2d(hitboxStart.x + width, hitboxStart.y + height)
|
get() = Point2d(hitboxStart.x + width, hitboxStart.y + height)
|
||||||
var width: Double = 0.0
|
var width: Double = 0.0
|
||||||
private set
|
private set
|
||||||
@@ -135,4 +135,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
|
|||||||
operator fun minus(other: Hitbox): Vector2 {
|
operator fun minus(other: Hitbox): Vector2 {
|
||||||
return Vector2(other.centeredX - this.centeredX, other.centeredY - this.centeredY)
|
return Vector2(other.centeredX - this.centeredX, other.centeredY - this.centeredY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return this.hitboxStart == (other as Hitbox).hitboxStart && this.hitboxEnd == (other as Hitbox).hitboxEnd
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.torvald.terrarum.gameactors
|
package net.torvald.terrarum.gameactors
|
||||||
|
|
||||||
|
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper to support instant player changing (or possessing other NPCs maybe)
|
* A wrapper to support instant player changing (or possessing other NPCs maybe)
|
||||||
*
|
*
|
||||||
@@ -13,4 +15,17 @@ class PlayableActorDelegate(val actor: ActorHumanoid) {
|
|||||||
throw IllegalArgumentException("Player must be 'Controllable'!")
|
throw IllegalArgumentException("Player must be 'Controllable'!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun update(delta: Float) {
|
||||||
|
//val oldTilewisePos = actor.tilewiseHitbox
|
||||||
|
|
||||||
|
actor.update(delta)
|
||||||
|
|
||||||
|
// fire lightmap recalculate event upon tilewise pos change
|
||||||
|
//val newTilewisePos = actor.tilewiseHitbox
|
||||||
|
//if (oldTilewisePos != newTilewisePos) {
|
||||||
|
// LightmapRenderer.fireRecalculateEvent()
|
||||||
|
//}
|
||||||
|
// not going to work: think about stationery tiki torches, global lights, etc
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ object PlayerBuilderSigrid {
|
|||||||
p.actorValue[AVKey.SPEEDBUFF] = 1.0
|
p.actorValue[AVKey.SPEEDBUFF] = 1.0
|
||||||
p.actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
|
p.actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
|
||||||
p.actorValue[AVKey.ACCELBUFF] = 1.0
|
p.actorValue[AVKey.ACCELBUFF] = 1.0
|
||||||
p.actorValue[AVKey.JUMPPOWER] = 9.0
|
p.actorValue[AVKey.JUMPPOWER] = 8.0
|
||||||
|
|
||||||
p.actorValue[AVKey.BASEMASS] = 80.0
|
p.actorValue[AVKey.BASEMASS] = 80.0
|
||||||
p.actorValue[AVKey.SCALEBUFF] = 1.0 // Constant 1.0 for player, meant to be used by random mobs
|
p.actorValue[AVKey.SCALEBUFF] = 1.0 // Constant 1.0 for player, meant to be used by random mobs
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ class BasicDebugInfoWindow : UICanvas {
|
|||||||
|
|
||||||
private fun drawHistogram(batch: SpriteBatch, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
private fun drawHistogram(batch: SpriteBatch, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
||||||
val uiColour = Color(0x000000_80.toInt())
|
val uiColour = Color(0x000000_80.toInt())
|
||||||
val barR = Color(0xDD0000_FF.toInt())
|
val barR = Color(0xFF0000_FF.toInt())
|
||||||
val barG = Color(0x00DD00_FF.toInt())
|
val barG = Color(0x00FF00_FF.toInt())
|
||||||
val barB = Color(0x0000DD_FF.toInt())
|
val barB = Color(0x0000FF_FF.toInt())
|
||||||
val barColour = arrayOf(barR, barG, barB)
|
val barColour = arrayOf(barR, barG, barB)
|
||||||
val w = histogramW.toFloat()
|
val w = histogramW.toFloat()
|
||||||
val h = histogramH.toFloat()
|
val h = histogramH.toFloat()
|
||||||
@@ -223,7 +223,7 @@ class BasicDebugInfoWindow : UICanvas {
|
|||||||
TerrarumGDX.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
TerrarumGDX.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||||
TerrarumGDX.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
TerrarumGDX.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
||||||
|
|
||||||
//blendScreen()
|
blendScreen()
|
||||||
for (c in 0..2) {
|
for (c in 0..2) {
|
||||||
for (i in 0..255) {
|
for (i in 0..255) {
|
||||||
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
|
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
|
||||||
@@ -242,7 +242,7 @@ class BasicDebugInfoWindow : UICanvas {
|
|||||||
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
|
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//blendNormal()
|
blendNormal()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawGamepadAxis(batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
private fun drawGamepadAxis(batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
|
|||||||
class UIHandler(val UI: UICanvas,
|
class UIHandler(val UI: UICanvas,
|
||||||
val toggleKey: Int? = null, val toggleButton: Int? = null,
|
val toggleKey: Int? = null, val toggleButton: Int? = null,
|
||||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
var customPositioning: Boolean = false,
|
var customPositioning: Boolean = false, // mainly used by vital meter
|
||||||
val doNotWarnConstant: Boolean = false
|
val doNotWarnConstant: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class UIQuickBar : UICanvas, MouseControlled {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch) {
|
override fun render(batch: SpriteBatch) {
|
||||||
|
|
||||||
for (i in 0..SLOT_COUNT - 1) {
|
for (i in 0..SLOT_COUNT - 1) {
|
||||||
val image = if (i == selection)
|
val image = if (i == selection)
|
||||||
ItemSlotImageBuilder.produceLarge(false, i + 1)
|
ItemSlotImageBuilder.produceLarge(false, i + 1)
|
||||||
|
|||||||
@@ -407,14 +407,14 @@ object BlocksDrawer {
|
|||||||
val for_x_start = x / TILE_SIZE - 1
|
val for_x_start = x / TILE_SIZE - 1
|
||||||
val for_x_end = for_x_start + (width / TILE_SIZE) + 3
|
val for_x_end = for_x_start + (width / TILE_SIZE) + 3
|
||||||
|
|
||||||
var zeroTileCounter = 0
|
|
||||||
|
|
||||||
val originalBatchColour = batch.color.cpy()
|
val originalBatchColour = batch.color.cpy()
|
||||||
batch.color = color
|
batch.color = color
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
for (y in for_y_start..for_y_end) {
|
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?
|
val thisTile: Int?
|
||||||
if (mode % 3 == WALL)
|
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 ||
|
||||||
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
|
{
|
||||||
|
// TODO coalesce non-lit black patches
|
||||||
if (zeroTileCounter > 0) {
|
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
|
zeroTileCounter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,17 +507,22 @@ object BlocksDrawer {
|
|||||||
} // end if (is illuminated)
|
} // end if (is illuminated)
|
||||||
// draw black patch
|
// draw black patch
|
||||||
else {
|
else {
|
||||||
zeroTileCounter++ // unused for now
|
zeroTileCounter += 1 // unused for now
|
||||||
|
|
||||||
batch.color = Color.BLACK
|
|
||||||
drawTile(batch, mode, x, y, 1, 0)
|
|
||||||
batch.color = color
|
|
||||||
}
|
}
|
||||||
} // end if (not an air)
|
} // end if (not an air)
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
// 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)
|
if (mode == TERRAIN || mode == WALL)
|
||||||
batch.draw(
|
batch.draw(
|
||||||
tilesTerrain.get(sheetX, sheetY),
|
tilesTerrain.get(sheetX, sheetY),
|
||||||
(tilewisePosX * TILE_SIZE).toFloat(),
|
tilewisePosX * TILE_SIZEF,
|
||||||
(tilewisePosY * TILE_SIZE).toFloat()
|
tilewisePosY * TILE_SIZEF
|
||||||
)
|
)
|
||||||
else if (mode == WIRE)
|
else if (mode == WIRE)
|
||||||
batch.draw(
|
batch.draw(
|
||||||
tilesWire.get(sheetX, sheetY),
|
tilesWire.get(sheetX, sheetY),
|
||||||
(tilewisePosX * TILE_SIZE).toFloat(),
|
tilewisePosX * TILE_SIZEF,
|
||||||
(tilewisePosY * TILE_SIZE).toFloat()
|
tilewisePosY * TILE_SIZEF
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
throw IllegalArgumentException()
|
throw IllegalArgumentException()
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun renderLightMap() {
|
fun fireRecalculateEvent() {
|
||||||
for_x_start = WorldCamera.x / TILE_SIZE - 1 // fix for premature lightmap rendering
|
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
|
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
|
// O(9n) == O(n) where n is a size of the map
|
||||||
// TODO devise multithreading on this
|
// TODO devise multithreading on this
|
||||||
|
|
||||||
|
var ambientAccumulator = 0
|
||||||
|
|
||||||
var lightLevelThis: Int = 0
|
var lightLevelThis: Int = 0
|
||||||
val thisTerrain = TerrarumGDX.ingame!!.world.getTileFromTerrain(x, y)
|
val thisTerrain = TerrarumGDX.ingame!!.world.getTileFromTerrain(x, y)
|
||||||
val thisWall = TerrarumGDX.ingame!!.world.getTileFromWall(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
|
* sample ambient for eight points and apply attenuation for those
|
||||||
* maxblend eight values and use it
|
* maxblend eight values and use it
|
||||||
*/
|
*/
|
||||||
var ambient = 0
|
/* + */ambientAccumulator = ambientAccumulator 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))
|
/* + */ambientAccumulator = ambientAccumulator 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))
|
/* + */ambientAccumulator = ambientAccumulator 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))
|
/* + */ambientAccumulator = ambientAccumulator 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)
|
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y - 1) ?: 0, thisTileOpacity)
|
||||||
/* * */ambient = ambient maxBlend darkenColoured(getLight(x , y + 1) ?: 0, thisTileOpacity)
|
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y + 1) ?: 0, thisTileOpacity)
|
||||||
/* * */ambient = ambient maxBlend darkenColoured(getLight(x - 1, y ) ?: 0, thisTileOpacity)
|
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y ) ?: 0, thisTileOpacity)
|
||||||
/* * */ambient = ambient maxBlend darkenColoured(getLight(x + 1, y ) ?: 0, thisTileOpacity)
|
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y ) ?: 0, thisTileOpacity)
|
||||||
return lightLevelThis maxBlend ambient
|
|
||||||
|
return lightLevelThis maxBlend ambientAccumulator
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return lightLevelThis
|
return lightLevelThis
|
||||||
@@ -457,19 +460,15 @@ object LightmapRenderer {
|
|||||||
// use equation with magic number 8.0
|
// use equation with magic number 8.0
|
||||||
// should draw somewhat exponential curve when you plot the propagation of light in-game
|
// should draw somewhat exponential curve when you plot the propagation of light in-game
|
||||||
|
|
||||||
val r = data.r() * (1f - darken.r() * lightScalingMagic)
|
return ((data.r() * (1f - darken.r() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round() * MUL_2 +
|
||||||
val g = data.g() * (1f - darken.g() * lightScalingMagic)
|
((data.g() * (1f - darken.g() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round() * MUL +
|
||||||
val b = data.b() * (1f - darken.b() * lightScalingMagic)
|
((data.b() * (1f - darken.b() * lightScalingMagic)).clampZero() * CHANNEL_MAX).round()
|
||||||
|
|
||||||
return constructRGBFromFloat(r.clampZero(), g.clampZero(), b.clampZero())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scaleColour(data: Int, scale: Float): RGB10 {
|
fun scaleColour(data: Int, scale: Float): RGB10 {
|
||||||
val r = data.r() * scale
|
return ((data.r() * scale).clampOne() * CHANNEL_MAX).round() * MUL_2 +
|
||||||
val g = data.g() * scale
|
((data.g() * scale).clampOne() * CHANNEL_MAX).round() * MUL +
|
||||||
val b = data.b() * scale
|
((data.b() * scale).clampOne() * CHANNEL_MAX).round()
|
||||||
|
|
||||||
return constructRGBFromFloat(r.clampOne(), g.clampOne(), b.clampOne())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -557,38 +556,38 @@ object LightmapRenderer {
|
|||||||
* @param rgb2
|
* @param rgb2
|
||||||
* @return
|
* @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 +
|
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.rawG() > other.rawG()) this.rawG() else other.rawG()) * MUL +
|
||||||
(if (this.rawB() > other.rawB()) this.rawB() else other.rawB())
|
(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 +
|
return ((this.rawR() + other.rawR()) ushr 1) * MUL_2 +
|
||||||
((this.rawG() + other.rawG()) ushr 1) * MUL +
|
((this.rawG() + other.rawG()) ushr 1) * MUL +
|
||||||
((this.rawB() + other.rawB()) ushr 1)
|
((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 +
|
return ((this.rawR() - other.rawR()).clampChannel()) * MUL_2 +
|
||||||
((this.rawG() - other.rawG()).clampChannel()) * MUL +
|
((this.rawG() - other.rawG()).clampChannel()) * MUL +
|
||||||
((this.rawB() - other.rawB()).clampChannel())
|
((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 +
|
return ((this.rawR() + other.rawR()).clampChannel()) * MUL_2 +
|
||||||
((this.rawG() + other.rawG()).clampChannel()) * MUL +
|
((this.rawG() + other.rawG()).clampChannel()) * MUL +
|
||||||
((this.rawB() + other.rawB()).clampChannel())
|
((this.rawB() + other.rawB()).clampChannel())
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun RGB10.rawR() = this / MUL_2
|
fun RGB10.rawR() = this / MUL_2
|
||||||
inline fun RGB10.rawG() = this % MUL_2 / MUL
|
fun RGB10.rawG() = this % MUL_2 / MUL
|
||||||
inline fun RGB10.rawB() = this % MUL
|
fun RGB10.rawB() = this % MUL
|
||||||
|
|
||||||
/** 0.0 - 1.0 for 0-1023 (0.0 - 0.25 for 0-255) */
|
/** 0.0 - 1.0 for 0-1023 (0.0 - 0.25 for 0-255) */
|
||||||
inline fun RGB10.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT
|
fun RGB10.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT
|
||||||
inline fun RGB10.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT
|
fun RGB10.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT
|
||||||
inline fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT
|
fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
@@ -631,11 +630,11 @@ object LightmapRenderer {
|
|||||||
(b * CHANNEL_MAX).round()
|
(b * CHANNEL_MAX).round()
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun Int.clampZero() = if (this < 0) 0 else this
|
fun Int.clampZero() = if (this < 0) 0 else this
|
||||||
inline fun Float.clampZero() = if (this < 0) 0f else this
|
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
|
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
|
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 Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this
|
||||||
|
|
||||||
inline fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y)
|
inline fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y)
|
||||||
fun getHighestRGB(x: Int, y: Int): Int? {
|
fun getHighestRGB(x: Int, y: Int): Int? {
|
||||||
|
|||||||
Reference in New Issue
Block a user