mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
something's screwing up but commiting anyway
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -38,7 +38,7 @@
|
||||
<property name="caretWidth" class="java.lang.Integer" />
|
||||
</properties>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="13 (Panama)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.AppLoader.printmsg
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
@@ -8,6 +7,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import java.io.IOException
|
||||
@@ -110,7 +110,7 @@ object BlockCodex {
|
||||
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
|
||||
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
|
||||
prop.shadeColA = floatVal(record, "shduv") / LightmapRenderer.MUL_FLOAT
|
||||
prop.opacity = Color(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA)
|
||||
prop.opacity = Cvec(floatArrayOf(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA))
|
||||
|
||||
prop.strength = intVal(record, "str")
|
||||
prop.density = intVal(record, "dsty")
|
||||
@@ -119,7 +119,7 @@ object BlockCodex {
|
||||
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
|
||||
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
|
||||
prop.lumColA = floatVal(record, "lumuv") / LightmapRenderer.MUL_FLOAT
|
||||
prop.internalLumCol = Color(prop.lumColR, prop.lumColG, prop.lumColB, prop.lumColA)
|
||||
prop.internalLumCol = Cvec(floatArrayOf(prop.lumColR, prop.lumColG, prop.lumColB, prop.lumColA))
|
||||
|
||||
prop.friction = intVal(record, "fr")
|
||||
prop.viscosity = intVal(record, "vscs")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-16.
|
||||
@@ -17,7 +17,7 @@ class BlockProp {
|
||||
var shadeColB = 0f
|
||||
var shadeColA = 0f
|
||||
|
||||
lateinit var opacity: Color
|
||||
lateinit var opacity: Cvec
|
||||
|
||||
var strength: Int = 0
|
||||
var density: Int = 0
|
||||
@@ -36,12 +36,12 @@ class BlockProp {
|
||||
var lumColG = 0f
|
||||
var lumColB = 0f
|
||||
var lumColA = 0f
|
||||
lateinit var internalLumCol: Color
|
||||
lateinit var internalLumCol: Cvec
|
||||
|
||||
/**
|
||||
* @param luminosity
|
||||
*/
|
||||
inline val luminosity: Color
|
||||
inline val luminosity: Cvec
|
||||
get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction)
|
||||
|
||||
var drop: Int = 0
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ object BlockPropUtil {
|
||||
|
||||
}
|
||||
|
||||
private fun getTorchFlicker(baseLum: Color): Color {
|
||||
private fun getTorchFlicker(baseLum: Cvec): Cvec {
|
||||
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain,
|
||||
flickerP0, flickerP1, flickerP2, flickerP3
|
||||
)
|
||||
@@ -45,13 +45,13 @@ object BlockPropUtil {
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
private fun getSlowBreath(baseLum: Color): Color {
|
||||
private fun getSlowBreath(baseLum: Cvec): Cvec {
|
||||
val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange
|
||||
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
private fun getPulsate(baseLum: Color): Color {
|
||||
private fun getPulsate(baseLum: Cvec): Cvec {
|
||||
val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange
|
||||
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
@@ -91,7 +91,7 @@ object BlockPropUtil {
|
||||
|
||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x
|
||||
|
||||
fun getDynamicLumFunc(baseLum: Color, type: Int): Color {
|
||||
fun getDynamicLumFunc(baseLum: Cvec, type: Int): Cvec {
|
||||
return when (type) {
|
||||
1 -> getTorchFlicker(baseLum)
|
||||
2 -> (Terrarum.ingame!!.world).globalLight.cpy().mul(LightmapRenderer.DIV_FLOAT) // current global light
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-17.
|
||||
@@ -14,11 +13,11 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 5) {
|
||||
try {
|
||||
val r = args[1].toFloat()
|
||||
val g = args[2].toFloat()
|
||||
val b = args[3].toFloat()
|
||||
val a = args[4].toFloat()
|
||||
val GL = Color(r, g, b, a)
|
||||
//val r = args[1].toFloat()
|
||||
//val g = args[2].toFloat()
|
||||
//val b = args[3].toFloat()
|
||||
//val a = args[4].toFloat()
|
||||
val GL = Cvec(args.sliceArray(1..4).map { it.toFloat() }.toFloatArray())
|
||||
|
||||
WeatherMixer.globalLightOverridden = true
|
||||
(Terrarum.ingame!!.world).globalLight = GL
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-19.
|
||||
@@ -26,7 +26,7 @@ interface Luminous {
|
||||
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
|
||||
}
|
||||
*/
|
||||
var color: Color
|
||||
var color: Cvec
|
||||
|
||||
/**
|
||||
* Arguments:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
package net.torvald.terrarum.gameworld
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
@@ -10,6 +9,7 @@ import net.torvald.terrarum.blockproperties.Fluid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.serialise.ReadLayerDataZip
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.util.SortedArrayList
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.absoluteValue
|
||||
@@ -90,7 +90,7 @@ open class GameWorld {
|
||||
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
|
||||
var gravitation: Vector2 = Vector2(0.0, 9.80665)
|
||||
/** 0.0..1.0+ */
|
||||
var globalLight = Color(0f,0f,0f,0f)
|
||||
var globalLight = Cvec()
|
||||
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.torvald.terrarum.serialise.toULittle48
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINSMenu
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -279,7 +280,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
init {
|
||||
gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
|
||||
gameWorld.globalLight = Color(.8f,.8f,.8f,.8f)
|
||||
gameWorld.globalLight = Cvec(.8f)
|
||||
|
||||
essentialOverlays.add(blockPointingCursor)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.spriteanimation.HasAssembledSprite
|
||||
import net.torvald.terrarum.*
|
||||
@@ -15,6 +14,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.time_t
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import java.util.*
|
||||
@@ -68,18 +68,18 @@ open class ActorHumanoid(
|
||||
if (houseDesignation != null) houseDesignation!!.clear()
|
||||
}
|
||||
|
||||
override var color: Color
|
||||
get() = Color(
|
||||
override var color: Cvec
|
||||
get() = Cvec(floatArrayOf(
|
||||
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT
|
||||
)
|
||||
))
|
||||
set(value) {
|
||||
actorValue[AVKey.LUMR] = value.r * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMG] = value.g * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMB] = value.b * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMR] = value.vec[0] * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMG] = value.vec[1] * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMB] = value.vec[2] * LightmapRenderer.MUL_FLOAT
|
||||
actorValue[AVKey.LUMA] = value.vec[3] * LightmapRenderer.MUL_FLOAT
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.*
|
||||
|
||||
@@ -17,7 +17,7 @@ internal class FixtureTikiTorch : FixtureBase(
|
||||
BlockBox(BlockBox.NO_COLLISION, 1, 2)
|
||||
), Luminous {
|
||||
|
||||
override var color: Color
|
||||
override var color: Cvec
|
||||
get() = BlockCodex[Block.TORCH].luminosity
|
||||
set(value) {
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import java.util.*
|
||||
|
||||
@@ -31,8 +32,8 @@ open class ProjectileSimple(
|
||||
val speed: Int
|
||||
|
||||
|
||||
override var color: Color
|
||||
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Color).cpy()
|
||||
override var color: Cvec
|
||||
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Cvec).cpy()
|
||||
set(value) {
|
||||
}
|
||||
/**
|
||||
@@ -118,8 +119,8 @@ open class ProjectileSimple(
|
||||
val OFFSET_LUMINOSITY = 4
|
||||
val bulletDatabase = arrayOf(
|
||||
// damage, display colour, no gravity, speed
|
||||
arrayOf(7, Color(0xFF5429_FF.toInt()), true, 40, 32),
|
||||
arrayOf(8, Color(0xFF5429_FF.toInt()), true, 20, 0)
|
||||
arrayOf(7, Cvec(1f, .329f, .161f, 1f), true, 40, 32),
|
||||
arrayOf(8, Cvec(1f, .329f, .161f, 1f), true, 20, 0)
|
||||
// ...
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-04-26.
|
||||
@@ -21,7 +20,7 @@ class WeaponSwung(val itemID: Int) : ActorWBMovable(RenderOrder.MIDTOP), Luminou
|
||||
actorValue[AVKey.LUMINOSITY] = value
|
||||
}
|
||||
*/
|
||||
override var color: Color
|
||||
override var color: Cvec
|
||||
get() = throw UnsupportedOperationException()
|
||||
set(value) {
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
import net.torvald.terrarum.worlddrawer.Cvec
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
@@ -51,7 +52,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
lateinit var mixedWeather: BaseModularWeather
|
||||
|
||||
val globalLightNow = Color(0)
|
||||
val globalLightNow = Cvec()
|
||||
|
||||
// Weather indices
|
||||
const val WEATHER_GENERIC = "generic"
|
||||
@@ -133,7 +134,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
// calculate global light
|
||||
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
|
||||
globalLightNow.set(globalLight)
|
||||
globalLightNow.setTo(floatArrayOf(globalLight.r, globalLight.g, globalLight.b, globalLight.a))
|
||||
|
||||
|
||||
/* (copied from the shader source)
|
||||
@@ -178,8 +179,10 @@ internal object WeatherMixer : RNGConsumer {
|
||||
/**
|
||||
* Get a GL of specific time
|
||||
*/
|
||||
fun getGlobalLightOfTime(timeInSec: Int): Color =
|
||||
getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
|
||||
fun getGlobalLightOfTime(timeInSec: Int): Cvec {
|
||||
val c = getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
|
||||
return Cvec(floatArrayOf(c.r, c.g, c.b, c.a))
|
||||
}
|
||||
|
||||
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
|
||||
val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width
|
||||
|
||||
@@ -140,10 +140,10 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
val mtX = mouseTileX.toString()
|
||||
val mtY = mouseTileY.toString()
|
||||
val valRaw = LightmapRenderer.getLight(mouseTileX, mouseTileY)
|
||||
val rawR = valRaw?.r?.times(100f)?.round()?.div(100f)
|
||||
val rawG = valRaw?.g?.times(100f)?.round()?.div(100f)
|
||||
val rawB = valRaw?.b?.times(100f)?.round()?.div(100f)
|
||||
val rawA = valRaw?.a?.times(100f)?.round()?.div(100f)
|
||||
val rawR = valRaw?.vec?.get(0)?.times(100f)?.round()?.div(100f)
|
||||
val rawG = valRaw?.vec?.get(1)?.times(100f)?.round()?.div(100f)
|
||||
val rawB = valRaw?.vec?.get(2)?.times(100f)?.round()?.div(100f)
|
||||
val rawA = valRaw?.vec?.get(3)?.times(100f)?.round()?.div(100f)
|
||||
|
||||
lightVal = if (valRaw == null) "—"
|
||||
else "$rawR $rawG $rawB $rawA"
|
||||
|
||||
75
src/net/torvald/terrarum/worlddrawer/Cvec.kt
Normal file
75
src/net/torvald/terrarum/worlddrawer/Cvec.kt
Normal file
@@ -0,0 +1,75 @@
|
||||
package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
//import jdk.incubator.vector.FloatVector
|
||||
|
||||
|
||||
/**
|
||||
* Get your panama JDK for linux/mac/windows at https://jdk.java.net/panama/
|
||||
*
|
||||
* Created by minjaesong on 2019-05-20.
|
||||
*/
|
||||
class Cvec(val vec: FloatArray) {
|
||||
|
||||
constructor(r: Float, g: Float, b: Float, a: Float) : this(floatArrayOf(r, g, b, a))
|
||||
constructor(scalar: Float) : this(FloatArray(4) { scalar })
|
||||
constructor() : this(FloatArray(4) { 0f })
|
||||
|
||||
private val epsilon = 1f / 512f
|
||||
|
||||
fun cpy(): Cvec = Cvec(this.vec)
|
||||
|
||||
fun setTo(scalar: Float) = setTo(FloatArray(4) { scalar })
|
||||
fun setTo(other: Cvec) = setTo(other.vec)
|
||||
fun setTo(other: FloatArray): Cvec {
|
||||
for (i in 0..3) {
|
||||
this.vec[i] = other[i]
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
infix fun mul(scalar: Float): Cvec = mul(FloatArray(4) { scalar })
|
||||
infix fun mul(other: Cvec) = mul(other.vec)
|
||||
|
||||
fun mul(other: FloatArray): Cvec {
|
||||
for (i in 0..3) {
|
||||
this.vec[i] *= other[i]
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun max(other: Cvec): Cvec = max(other.vec)
|
||||
|
||||
fun max(other: FloatArray): Cvec {
|
||||
for (i in 0..3) {
|
||||
this.vec[i] = if (this.vec[i] >= other[i]) this.vec[i] else other[i]
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* true if at least one element in the vector is not zero.
|
||||
*/
|
||||
fun nonZero(): Boolean {
|
||||
var oracc = 0 // set to 1 if the vector element is zero
|
||||
for (i in 0..3) {
|
||||
if (vec[i] in 0f..epsilon)
|
||||
oracc = oracc or 1
|
||||
}
|
||||
|
||||
return (oracc != 0)
|
||||
}
|
||||
|
||||
fun toRGBA8888(): Int {
|
||||
var acc = 0
|
||||
for (i in 0..3)
|
||||
acc += vec[i].coerceIn(0f, 1f).times(255f).roundToInt().shl(8 * (3 - i))
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//hg clone http://hg.openjdk.java.net/panama/dev/
|
||||
@@ -1,19 +1,5 @@
|
||||
package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.floorInt
|
||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Warning: you are not going to store float value to the lightmap -- see RGB_HDR_LUT (beziér)
|
||||
*
|
||||
@@ -24,7 +10,7 @@ import java.util.*
|
||||
|
||||
// NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable
|
||||
|
||||
object LightmapRendererOld {
|
||||
/*object LightmapRendererOld {
|
||||
lateinit var world: GameWorld
|
||||
|
||||
|
||||
@@ -771,4 +757,4 @@ object LightmapRendererOld {
|
||||
}
|
||||
return (1f - scale) * startValue + scale * endValue
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -82,8 +82,8 @@ object LightmapRenderer {
|
||||
*/
|
||||
// it utilises alpha channel to determine brightness of "glow" sprites (so that alpha channel works like UV light)
|
||||
//private val lightmap: Array<Array<Color>> = Array(LIGHTMAP_HEIGHT) { Array(LIGHTMAP_WIDTH, { Color(0f,0f,0f,0f) }) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
||||
private var lightmap: Array<Color> = Array(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Color(0) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
||||
private val lanternMap = HashMap<BlockAddress, Color>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
||||
private var lightmap: Array<Cvec> = Array(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Cvec() } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
||||
private val lanternMap = HashMap<BlockAddress, Cvec>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
||||
|
||||
init {
|
||||
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
|
||||
@@ -120,13 +120,13 @@ object LightmapRenderer {
|
||||
* @param x world tile coord
|
||||
* @param y world tile coord
|
||||
*/
|
||||
internal fun getLight(x: Int, y: Int): Color? {
|
||||
internal fun getLight(x: Int, y: Int): Cvec? {
|
||||
val col = getLightInternal(x, y)
|
||||
if (col == null) {
|
||||
return null
|
||||
}
|
||||
else {
|
||||
return Color(col.r * MUL_FLOAT, col.g * MUL_FLOAT, col.b * MUL_FLOAT, col.a * MUL_FLOAT)
|
||||
return col.cpy().mul(MUL_FLOAT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ object LightmapRenderer {
|
||||
* @param y world tile coord
|
||||
*/
|
||||
// TODO in regard of "colour math against integers", return Int?
|
||||
private fun getLightInternal(x: Int, y: Int): Color? {
|
||||
private fun getLightInternal(x: Int, y: Int): Cvec? {
|
||||
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
|
||||
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
||||
|
||||
@@ -164,7 +164,7 @@ object LightmapRenderer {
|
||||
* @param colour Color to write
|
||||
* @param applyFun A function ```foo(old_colour, given_colour)```
|
||||
*/
|
||||
private fun setLightOf(list: Array<Color>, x: Int, y: Int, colour: Color, applyFun: (Color, Color) -> Color = { _, c -> c }) {
|
||||
private fun setLightOf(list: Array<Cvec>, x: Int, y: Int, colour: Cvec, applyFun: (Cvec, Cvec) -> Cvec = { _, c -> c }) {
|
||||
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
|
||||
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
||||
|
||||
@@ -220,7 +220,8 @@ object LightmapRenderer {
|
||||
*/
|
||||
|
||||
// set sunlight
|
||||
sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT)
|
||||
sunLight.setTo(world.globalLight)
|
||||
sunLight.mul(DIV_FLOAT)
|
||||
|
||||
// set no-op mask from solidity of the block
|
||||
AppLoader.measureDebugTime("Renderer.LightNoOpMask") {
|
||||
@@ -394,15 +395,15 @@ object LightmapRenderer {
|
||||
|
||||
|
||||
//private val ambientAccumulator = Color(0f,0f,0f,0f)
|
||||
private val lightLevelThis = Color(0)
|
||||
private val lightLevelThis = Cvec()
|
||||
private var thisTerrain = 0
|
||||
private var thisFluid = GameWorld.FluidInfo(Fluid.NULL, 0f)
|
||||
private val fluidAmountToCol = Color(0)
|
||||
private val fluidAmountToCol = Cvec()
|
||||
private var thisWall = 0
|
||||
private val thisTileLuminosity = Color(0)
|
||||
private val thisTileOpacity = Color(0)
|
||||
private val thisTileOpacity2 = Color(0) // thisTileOpacity * sqrt(2)
|
||||
private val sunLight = Color(0)
|
||||
private val thisTileLuminosity = Cvec()
|
||||
private val thisTileOpacity = Cvec()
|
||||
private val thisTileOpacity2 = Cvec() // thisTileOpacity * sqrt(2)
|
||||
private val sunLight = Cvec()
|
||||
|
||||
/**
|
||||
* This function will alter following variables:
|
||||
@@ -416,35 +417,35 @@ object LightmapRenderer {
|
||||
* - sunlight
|
||||
*/
|
||||
private fun getLightsAndShades(x: Int, y: Int) {
|
||||
lightLevelThis.set(colourNull)
|
||||
lightLevelThis.setTo(colourNull)
|
||||
thisTerrain = world.getTileFromTerrain(x, y) ?: Block.STONE
|
||||
thisFluid = world.getFluid(x, y)
|
||||
thisWall = world.getTileFromWall(x, y) ?: Block.STONE
|
||||
|
||||
if (thisFluid.type != Fluid.NULL) {
|
||||
fluidAmountToCol.set(thisFluid.amount, thisFluid.amount, thisFluid.amount, thisFluid.amount)
|
||||
fluidAmountToCol.setTo(thisFluid.amount)
|
||||
|
||||
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity)
|
||||
thisTileLuminosity.maxAndAssign(BlockCodex[thisFluid.type].luminosity mul fluidAmountToCol) // already been div by four
|
||||
thisTileOpacity.set(BlockCodex[thisTerrain].opacity)
|
||||
thisTileOpacity.maxAndAssign(BlockCodex[thisFluid.type].opacity mul fluidAmountToCol) // already been div by four
|
||||
thisTileLuminosity.setTo(BlockCodex[thisTerrain].luminosity)
|
||||
thisTileLuminosity.max(BlockCodex[thisFluid.type].luminosity mul fluidAmountToCol) // already been div by four
|
||||
thisTileOpacity.setTo(BlockCodex[thisTerrain].opacity)
|
||||
thisTileOpacity.max(BlockCodex[thisFluid.type].opacity mul fluidAmountToCol) // already been div by four
|
||||
}
|
||||
else {
|
||||
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity)
|
||||
thisTileOpacity.set(BlockCodex[thisTerrain].opacity)
|
||||
thisTileLuminosity.setTo(BlockCodex[thisTerrain].luminosity)
|
||||
thisTileOpacity.setTo(BlockCodex[thisTerrain].opacity)
|
||||
}
|
||||
|
||||
thisTileOpacity2.set(thisTileOpacity); thisTileOpacity2.mul(1.41421356f)
|
||||
thisTileOpacity2.setTo(thisTileOpacity); thisTileOpacity2.mul(1.41421356f)
|
||||
//sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT) // moved to fireRecalculateEvent()
|
||||
|
||||
|
||||
// open air || luminous tile backed by sunlight
|
||||
if ((thisTerrain == AIR && thisWall == AIR) || (thisTileLuminosity.nonZero() && thisWall == AIR)) {
|
||||
lightLevelThis.set(sunLight)
|
||||
lightLevelThis.setTo(sunLight)
|
||||
}
|
||||
|
||||
// blend lantern
|
||||
lightLevelThis.maxAndAssign(thisTileLuminosity).maxAndAssign(lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: colourNull)
|
||||
lightLevelThis.max(thisTileLuminosity).max(lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: colourNull)
|
||||
|
||||
}
|
||||
|
||||
@@ -499,7 +500,7 @@ object LightmapRenderer {
|
||||
/**
|
||||
* Calculates the light simulation, using main lightmap as one of the input.
|
||||
*/
|
||||
private fun calculateAndAssign(lightmap: Array<Color>, x: Int, y: Int) {
|
||||
private fun calculateAndAssign(lightmap: Array<Cvec>, x: Int, y: Int) {
|
||||
|
||||
if (inNoopMask(x, y)) return
|
||||
|
||||
@@ -517,32 +518,27 @@ object LightmapRenderer {
|
||||
|
||||
// will "overwrite" what's there in the lightmap if it's the first pass
|
||||
// takes about 2 ms on 6700K
|
||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y) ?: colourNull, thisTileOpacity))
|
||||
/* + */lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.max(darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||
/* + */lightLevelThis.max(darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||
/* * */lightLevelThis.max(darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.max(darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity))
|
||||
/* * */lightLevelThis.max(darkenColoured(getLightInternal(x + 1, y) ?: colourNull, thisTileOpacity))
|
||||
|
||||
|
||||
//return lightLevelThis.cpy() // it HAS to be a cpy(), otherwise all cells gets the same instance
|
||||
setLightOf(lightmap, x, y, lightLevelThis.cpy())
|
||||
}
|
||||
|
||||
private fun getLightForOpaque(x: Int, y: Int): Color? { // ...so that they wouldn't appear too dark
|
||||
private fun getLightForOpaque(x: Int, y: Int): Cvec? { // ...so that they wouldn't appear too dark
|
||||
val l = getLightInternal(x, y)
|
||||
if (l == null) return null
|
||||
|
||||
// brighten if solid
|
||||
if (BlockCodex[world.getTileFromTerrain(x, y)].isSolid) {
|
||||
return Color(
|
||||
(l.r * 1.2f),
|
||||
(l.g * 1.2f),
|
||||
(l.b * 1.2f),
|
||||
(l.a * 1.2f)
|
||||
)
|
||||
return l.cpy().mul(1.2f)
|
||||
}
|
||||
else {
|
||||
return l
|
||||
@@ -551,8 +547,7 @@ object LightmapRenderer {
|
||||
|
||||
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
||||
|
||||
private val colourNull = Color(0)
|
||||
private val epsilon = 1f/1024f
|
||||
private val colourNull = Cvec()
|
||||
|
||||
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||
|
||||
@@ -568,7 +563,7 @@ object LightmapRenderer {
|
||||
|
||||
// wipe out beforehand. You DO need this
|
||||
lightBuffer.blending = Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)
|
||||
lightBuffer.setColor(colourNull)
|
||||
lightBuffer.setColor(0)
|
||||
lightBuffer.fill()
|
||||
|
||||
|
||||
@@ -581,12 +576,11 @@ object LightmapRenderer {
|
||||
|
||||
for (x in this_x_start..this_x_end) {
|
||||
|
||||
val color = (getLightForOpaque(x, y) ?: Color(0f, 0f, 0f, 0f)).normaliseToHDR()
|
||||
val color: RGBA8888 = (getLightForOpaque(x, y) ?: Cvec()).normaliseToHDR().toRGBA8888()
|
||||
|
||||
lightBuffer.setColor(color)
|
||||
|
||||
//lightBuffer.drawPixel(x - this_x_start, y - this_y_start)
|
||||
|
||||
lightBuffer.drawPixel(x - this_x_start, lightBuffer.height - 1 - y + this_y_start) // flip Y
|
||||
}
|
||||
}
|
||||
@@ -620,15 +614,17 @@ object LightmapRenderer {
|
||||
* @param darken (0-255) per channel
|
||||
* @return darkened data (0-255) per channel
|
||||
*/
|
||||
fun darkenColoured(data: Color, darken: Color): Color {
|
||||
fun darkenColoured(data: Cvec, darken: Cvec): Cvec {
|
||||
// use equation with magic number 8.0
|
||||
// this function, when done recursively (A_x = darken(A_x-1, C)), draws exponential curve. (R^2 = 1)
|
||||
|
||||
return Color(
|
||||
data.r * (1f - darken.r * lightScalingMagic),//.clampZero(),
|
||||
data.g * (1f - darken.g * lightScalingMagic),//.clampZero(),
|
||||
data.b * (1f - darken.b * lightScalingMagic),//.clampZero(),
|
||||
data.a * (1f - darken.a * lightScalingMagic))
|
||||
val newvec = data.cpy()
|
||||
|
||||
for (i in 0..3) {
|
||||
newvec.vec[i] = data.vec[i] * (1f - darken.vec[i] * lightScalingMagic)
|
||||
}
|
||||
|
||||
return newvec
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -638,13 +634,13 @@ object LightmapRenderer {
|
||||
* @param darken (0-255)
|
||||
* @return
|
||||
*/
|
||||
fun darkenUniformInt(data: Color, darken: Float): Color {
|
||||
/*fun darkenUniformInt(data: Color, darken: Float): Color {
|
||||
if (darken < 0 || darken > CHANNEL_MAX)
|
||||
throw IllegalArgumentException("darken: out of range ($darken)")
|
||||
|
||||
val darkenColoured = Color(darken, darken, darken, darken)
|
||||
return darkenColoured(data, darkenColoured)
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Darken or brighten colour by 'brighten' argument
|
||||
@@ -653,26 +649,16 @@ object LightmapRenderer {
|
||||
* @param brighten (-1.0 - 1.0) negative means darkening
|
||||
* @return processed colour
|
||||
*/
|
||||
fun alterBrightnessUniform(data: Color, brighten: Float): Color {
|
||||
return Color(
|
||||
data.r + brighten,
|
||||
data.g + brighten,
|
||||
data.b + brighten,
|
||||
data.a + brighten
|
||||
)
|
||||
fun alterBrightnessUniform(data: Cvec, brighten: Float): Cvec {
|
||||
val newvec = data.cpy()
|
||||
|
||||
for (i in 0..3) {
|
||||
newvec.vec[i] = data.vec[i] + brighten
|
||||
}
|
||||
|
||||
return newvec
|
||||
}
|
||||
|
||||
/** infix is removed to clarify the association direction */
|
||||
fun Color.maxAndAssign(other: Color): Color {
|
||||
this.set(
|
||||
if (this.r > other.r) this.r else other.r,
|
||||
if (this.g > other.g) this.g else other.g,
|
||||
if (this.b > other.b) this.b else other.b,
|
||||
if (this.a > other.a) this.a else other.a
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
private fun Float.inv() = 1f / this
|
||||
fun Float.floor() = FastMath.floor(this)
|
||||
@@ -723,7 +709,7 @@ object LightmapRenderer {
|
||||
_init = true
|
||||
}
|
||||
lightBuffer = Pixmap(tilesInHorizontal, tilesInVertical, Pixmap.Format.RGBA8888)
|
||||
lightmap = Array<Color>(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Color(0) }
|
||||
lightmap = Array<Cvec>(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Cvec() }
|
||||
|
||||
|
||||
printdbg(this, "Resize event")
|
||||
@@ -797,14 +783,15 @@ object LightmapRenderer {
|
||||
1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f // isn't it beautiful?
|
||||
)
|
||||
/** To eliminated visible edge on the gradient when 255/1023 is exceeded */
|
||||
internal fun Color.normaliseToHDR() = Color(
|
||||
hdr(this.r.coerceIn(0f,1f)),
|
||||
hdr(this.g.coerceIn(0f,1f)),
|
||||
hdr(this.b.coerceIn(0f,1f)),
|
||||
hdr(this.a.coerceIn(0f,1f))
|
||||
)
|
||||
internal fun Cvec.normaliseToHDR(): Cvec {
|
||||
val newvec = this.cpy()
|
||||
|
||||
private fun Color.nonZero() = this.r + this.g + this.b + this.a > epsilon
|
||||
for (i in 0..3) {
|
||||
newvec.vec[i] = hdr(newvec.vec[i].coerceIn(0f,1f))
|
||||
}
|
||||
|
||||
return newvec
|
||||
}
|
||||
|
||||
val histogram: Histogram
|
||||
get() {
|
||||
@@ -820,10 +807,10 @@ object LightmapRenderer {
|
||||
try {
|
||||
//val colour = lightmap[y][x]
|
||||
val colour = lightmap[y * LIGHTMAP_WIDTH + x]
|
||||
reds[minOf(CHANNEL_MAX, colour.r.times(MUL).floorInt())] += 1
|
||||
greens[minOf(CHANNEL_MAX, colour.g.times(MUL).floorInt())] += 1
|
||||
blues[minOf(CHANNEL_MAX, colour.b.times(MUL).floorInt())] += 1
|
||||
uvs[minOf(CHANNEL_MAX, colour.a.times(MUL).floorInt())] += 1
|
||||
reds[minOf(CHANNEL_MAX, colour.vec[0].times(MUL).floorInt())] += 1
|
||||
greens[minOf(CHANNEL_MAX, colour.vec[1].times(MUL).floorInt())] += 1
|
||||
blues[minOf(CHANNEL_MAX, colour.vec[2].times(MUL).floorInt())] += 1
|
||||
uvs[minOf(CHANNEL_MAX, colour.vec[3].times(MUL).floorInt())] += 1
|
||||
}
|
||||
catch (e: ArrayIndexOutOfBoundsException) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user