mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 14:34:04 +09:00
replacing min/max usage with kotlin's
This commit is contained in:
@@ -293,10 +293,10 @@ internal object BlocksDrawer {
|
||||
// the window frame which should NOT be MUL'd)
|
||||
|
||||
|
||||
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
|
||||
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorToInt()
|
||||
val for_y_end = for_y_start + tilesBuffer.height - 1
|
||||
|
||||
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
|
||||
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorToInt()
|
||||
val for_x_end = for_x_start + tilesBuffer.width - 1
|
||||
|
||||
// loop
|
||||
@@ -657,11 +657,11 @@ internal object BlocksDrawer {
|
||||
var tilesInVertical = -1; private set
|
||||
|
||||
fun resize(screenW: Int, screenH: Int) {
|
||||
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1
|
||||
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1
|
||||
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1
|
||||
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1
|
||||
|
||||
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilInt() + 1
|
||||
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilInt() + 1
|
||||
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt() + 1
|
||||
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt() + 1
|
||||
|
||||
// only update if it's really necessary
|
||||
if (oldTH != tilesInHorizontal || oldTV != tilesInVertical) {
|
||||
|
||||
@@ -3,11 +3,8 @@ package net.torvald.terrarum.worlddrawer
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.ColourTemp
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockstats.TileSurvey
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
@@ -32,26 +29,16 @@ object FeaturesDrawer {
|
||||
var colTemp: Int = 0
|
||||
private set
|
||||
|
||||
private val TILES_COLD = arrayOf(
|
||||
Block.ICE_MAGICAL
|
||||
, Block.ICE_FRAGILE
|
||||
, Block.ICE_NATURAL
|
||||
, Block.SNOW)
|
||||
|
||||
private val TILES_WARM = arrayOf(
|
||||
Block.SAND_DESERT
|
||||
, Block.SAND_RED)
|
||||
|
||||
init {
|
||||
TileSurvey.submitProposal(
|
||||
TileSurvey.SurveyProposal(
|
||||
"basegame.FeaturesDrawer.coldTiles", 72, 48, 2, 2
|
||||
) { world, x, y -> TILES_COLD.contains(world.getTileFromTerrain(x, y)) }
|
||||
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].tags.contains("COLD") }
|
||||
)
|
||||
TileSurvey.submitProposal(
|
||||
TileSurvey.SurveyProposal(
|
||||
"basegame.FeaturesDrawer.warmTiles", 72, 48, 2, 2
|
||||
) { world, x, y -> TILES_WARM.contains(world.getTileFromTerrain(x, y)) }
|
||||
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].tags.contains("WARM") }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -92,6 +79,6 @@ object FeaturesDrawer {
|
||||
private fun colTempLinearFunc(x: Float): Int {
|
||||
val colTempMedian = (ENV_COLTEMP_HIGHEST + ENV_COLTEMP_LOWEST) / 2
|
||||
|
||||
return Math.round((ENV_COLTEMP_HIGHEST - ENV_COLTEMP_LOWEST) / 2 * FastMath.clamp(x, -1f, 1f) + colTempMedian)
|
||||
return ((ENV_COLTEMP_HIGHEST - ENV_COLTEMP_LOWEST) / 2 * x.coerceIn(-1f, 1f) + colTempMedian).roundToInt()
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import net.torvald.terrarum.modulebasegame.ui.abs
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -66,8 +68,8 @@ object LightmapRenderer {
|
||||
const val overscan_opaque: Int = 10
|
||||
const val LIGHTMAP_OVERRENDER = 10
|
||||
|
||||
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
||||
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
||||
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||
|
||||
//private val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
|
||||
|
||||
@@ -257,8 +259,8 @@ object LightmapRenderer {
|
||||
*/
|
||||
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
||||
swipeLight(
|
||||
maxOf(1, i - LIGHTMAP_HEIGHT + 4), maxOf(1, LIGHTMAP_HEIGHT - 2 - i),
|
||||
minOf(LIGHTMAP_WIDTH - 2, i + 1), minOf(LIGHTMAP_HEIGHT - 2, (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) - i),
|
||||
max(1, i - LIGHTMAP_HEIGHT + 4), max(1, LIGHTMAP_HEIGHT - 2 - i),
|
||||
min(LIGHTMAP_WIDTH - 2, i + 1), min(LIGHTMAP_HEIGHT - 2, (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) - i),
|
||||
1, 1,
|
||||
lightmap
|
||||
)
|
||||
@@ -291,8 +293,8 @@ object LightmapRenderer {
|
||||
*/
|
||||
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
||||
swipeLight(
|
||||
maxOf(1, i - LIGHTMAP_HEIGHT + 4), minOf(LIGHTMAP_HEIGHT - 2, i + 1),
|
||||
minOf(LIGHTMAP_WIDTH - 2, i + 1), maxOf(1, (LIGHTMAP_HEIGHT - 2) - (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 6) + i),
|
||||
max(1, i - LIGHTMAP_HEIGHT + 4), min(LIGHTMAP_HEIGHT - 2, i + 1),
|
||||
min(LIGHTMAP_WIDTH - 2, i + 1), max(1, (LIGHTMAP_HEIGHT - 2) - (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 6) + i),
|
||||
1, -1,
|
||||
lightmap
|
||||
)
|
||||
@@ -355,10 +357,10 @@ object LightmapRenderer {
|
||||
val lightBoxY = it.hitbox.startY + (lightBox.startY * scale)
|
||||
val lightBoxW = lightBox.width * scale - 1
|
||||
val lightBoxH = lightBox.height * scale - 1
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorToInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorToInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorToInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorToInt()) {
|
||||
|
||||
val oldLight = lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
||||
val actorLight = colour
|
||||
@@ -374,10 +376,10 @@ object LightmapRenderer {
|
||||
val lightBoxY = it.hitbox.startY + (shadeBox.startY * scale)
|
||||
val lightBoxW = shadeBox.width * scale - 1
|
||||
val lightBoxH = shadeBox.height * scale - 1
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorToInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorToInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorToInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorToInt()) {
|
||||
|
||||
val oldLight = shadowMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
||||
val actorLight = colour
|
||||
@@ -706,10 +708,10 @@ object LightmapRenderer {
|
||||
/*lightBuffer.drawPixel(
|
||||
x - this_x_start,
|
||||
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
||||
(maxOf(red,grnw,bluw,uvlwr) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
||||
(maxOf(redw,grn,bluw,uvlwg) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
||||
(maxOf(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||
(maxOf(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||
(max(red,grnw,bluw,uvlwr) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
||||
(max(redw,grn,bluw,uvlwg) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
||||
(max(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||
(max(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||
)*/
|
||||
lightBuffer.drawPixel(
|
||||
x - this_x_start,
|
||||
@@ -809,10 +811,10 @@ object LightmapRenderer {
|
||||
private fun Cvec.maxAndAssign(other: Cvec): Cvec {
|
||||
// TODO investigate: if I use assignment instead of set(), it blackens like the vector branch. --Torvald, 2019-06-07
|
||||
// that was because you forgot 'this.r/g/b/a = ' part, bitch. --Torvald, 2019-06-07
|
||||
this.r = if (this.r > other.r) this.r else other.r
|
||||
this.g = if (this.g > other.g) this.g else other.g
|
||||
this.b = if (this.b > other.b) this.b else other.b
|
||||
this.a = if (this.a > other.a) this.a else other.a
|
||||
this.r = max(this.r, other.r)
|
||||
this.g = max(this.g, other.g)
|
||||
this.b = max(this.b, other.b)
|
||||
this.a = max(this.a, other.a)
|
||||
|
||||
return this
|
||||
}
|
||||
@@ -825,8 +827,8 @@ object LightmapRenderer {
|
||||
|
||||
// input: 0..1 for int 0..1023
|
||||
fun hdr(intensity: Float): Float {
|
||||
val intervalStart = (intensity / 4f * LightmapHDRMap.size).floorInt()
|
||||
val intervalEnd = (intensity / 4f * LightmapHDRMap.size).floorInt() + 1
|
||||
val intervalStart = (intensity / 4f * LightmapHDRMap.size).floorToInt()
|
||||
val intervalEnd = (intensity / 4f * LightmapHDRMap.size).floorToInt() + 1
|
||||
|
||||
if (intervalStart == intervalEnd) return LightmapHDRMap[intervalStart]
|
||||
|
||||
@@ -849,11 +851,11 @@ object LightmapRenderer {
|
||||
// copied from BlocksDrawer, duh!
|
||||
// FIXME 'lightBuffer' is not zoomable in this way
|
||||
|
||||
val tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||
val tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||
val tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||
val tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||
|
||||
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
||||
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
||||
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||
|
||||
if (_init) {
|
||||
lightBuffer.dispose()
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.ceilToInt
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
@@ -42,9 +42,9 @@ object WorldCamera {
|
||||
get() = y + (height * zoomSamplePoint).toInt()
|
||||
|
||||
val zoomedWidth: Int
|
||||
get() = (width / zoom).ceilInt()
|
||||
get() = (width / zoom).ceilToInt()
|
||||
val zoomedHeight: Int
|
||||
get() = (height / zoom).ceilInt()
|
||||
get() = (height / zoom).ceilToInt()
|
||||
|
||||
var xEnd: Int = 0 // right position
|
||||
private set
|
||||
@@ -89,14 +89,14 @@ object WorldCamera {
|
||||
else
|
||||
nullVec
|
||||
|
||||
x = ((player.hitbox.centeredX - pVecSum.x).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
||||
x = ((player.hitbox.centeredX - pVecSum.x).toFloat() - (width / 2)).floorToInt() // X only: ROUNDWORLD implementation
|
||||
|
||||
|
||||
y = (FastMath.clamp(
|
||||
(player.hitbox.centeredY - pVecSum.y).toFloat() - height / 2,
|
||||
TILE_SIZEF,
|
||||
world.height * TILE_SIZE - height - TILE_SIZEF
|
||||
)).floorInt().clampCameraY(world)*/
|
||||
)).floorToInt().clampCameraY(world)*/
|
||||
|
||||
|
||||
// val fpsRatio = App.UPDATE_RATE / Gdx.graphics.deltaTime // if FPS=32 & RATE=64, ratio will be 0.5
|
||||
|
||||
Reference in New Issue
Block a user