mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-10 13:51:53 +09:00
diching RGB10; colors are now fully vec3
This commit is contained in:
@@ -398,7 +398,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
WeatherMixer.update(delta)
|
||||
BlockStats.update()
|
||||
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
|
||||
world.globalLight = WeatherMixer.globalLightNow.toRGB10()
|
||||
world.globalLight = WeatherMixer.globalLightNow
|
||||
|
||||
|
||||
///////////////////////////
|
||||
|
||||
@@ -72,6 +72,10 @@ open class KVHashMap {
|
||||
return value as Double
|
||||
}
|
||||
|
||||
fun getAsFloat(key: String): Float? {
|
||||
return getAsDouble(key)?.toFloat()
|
||||
}
|
||||
|
||||
fun getAsString(key: String): String? {
|
||||
val value = get(key)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import net.torvald.terrarum.worlddrawer.RGB10
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.lwjgl.input.Controllers
|
||||
@@ -562,12 +561,12 @@ infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
|
||||
|
||||
|
||||
|
||||
inline fun Color.toRGB10(): RGB10 {
|
||||
/*inline fun Color.toRGB10(): RGB10 {
|
||||
val bits = this.toIntBits() // ABGR
|
||||
// 0bxxRRRRRRRRRRGGGGGGGGGGBBBBBBBBBB
|
||||
// 0bAAAAAAAABBBBBBBBGGGGGGGGRRRRRRRR
|
||||
return bits.and(0x0000FF).shl(20) or bits.and(0x00FF00).shl(2) or bits.and(0xFF0000).ushr(16)
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.blockproperties
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
|
||||
import java.io.IOException
|
||||
@@ -29,11 +30,11 @@ object BlockCodex {
|
||||
println("[BlockCodex] Building block properties table")
|
||||
|
||||
records.forEach {
|
||||
if (intVal(it, "blid") == -1) {
|
||||
if (intVal(it, "id") == -1) {
|
||||
setProp(nullProp, it)
|
||||
}
|
||||
else {
|
||||
setProp(blockProps[intVal(it, "blid")], it)
|
||||
setProp(blockProps[intVal(it, "id")], it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,13 +85,20 @@ object BlockCodex {
|
||||
private fun setProp(prop: BlockProp, record: CSVRecord) {
|
||||
prop.nameKey = record.get("name")
|
||||
|
||||
prop.id = intVal(record, "blid")
|
||||
prop.drop = intVal(record, "drid")
|
||||
prop.id = intVal(record, "id")
|
||||
prop.drop = intVal(record, "drop")
|
||||
|
||||
prop.shadeColR = floatVal(record, "shdr") / LightmapRenderer.MUL_FLOAT
|
||||
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
|
||||
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
|
||||
|
||||
prop.opacity = intVal(record, "opacity")
|
||||
prop.strength = intVal(record, "strength")
|
||||
prop.density = intVal(record, "dsty")
|
||||
prop.luminosity = intVal(record, "lumcolor")
|
||||
|
||||
prop.lumColR = floatVal(record, "lumr") / LightmapRenderer.MUL_FLOAT
|
||||
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
|
||||
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
|
||||
|
||||
prop.friction = intVal(record, "friction")
|
||||
prop.viscosity = intVal(record, "vscs")
|
||||
|
||||
@@ -102,22 +110,31 @@ object BlockCodex {
|
||||
|
||||
prop.dynamicLuminosityFunction = intVal(record, "dlfn")
|
||||
|
||||
print("${intVal(record, "blid")}")
|
||||
print("${intVal(record, "id")}")
|
||||
println("\t" + prop.nameKey)
|
||||
}
|
||||
|
||||
private fun intVal(rec: CSVRecord, s: String): Int {
|
||||
var ret = -1
|
||||
try {
|
||||
ret = Integer.decode(rec.get(s))!!
|
||||
ret = rec.get(s).toInt()
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
catch (e: NumberFormatException) {
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun floatVal(rec: CSVRecord, s: String): Float {
|
||||
var ret = -1f
|
||||
try {
|
||||
ret = rec.get(s).toFloat()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun boolVal(rec: CSVRecord, s: String) = intVal(rec, s) != 0
|
||||
|
||||
private fun formatNum2(i: Int) = if (i < 10) "0" + i else i.toString()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-16.
|
||||
*/
|
||||
@@ -9,10 +11,16 @@ class BlockProp {
|
||||
|
||||
var nameKey: String = ""
|
||||
|
||||
|
||||
var shadeColR = 0f
|
||||
var shadeColG = 0f
|
||||
var shadeColB = 0f
|
||||
|
||||
/**
|
||||
* @param opacity Raw RGB value, without alpha
|
||||
*/
|
||||
var opacity: Int = 0 // colour attenuation
|
||||
inline val opacity: Color
|
||||
get() = Color(shadeColR, shadeColG, shadeColB, 1f)
|
||||
|
||||
var strength: Int = 0
|
||||
var density: Int = 0
|
||||
@@ -23,14 +31,16 @@ class BlockProp {
|
||||
var isWallable: Boolean = false
|
||||
var isVertFriction: Boolean = false
|
||||
|
||||
|
||||
var lumColR = 0f
|
||||
var lumColG = 0f
|
||||
var lumColB = 0f
|
||||
|
||||
/**
|
||||
* @param luminosity Raw RGB value, without alpha
|
||||
*/
|
||||
var luminosity: Int = 0
|
||||
set(value) {
|
||||
field = value
|
||||
}
|
||||
get() = BlockPropUtil.getDynamicLumFunc(field, dynamicLuminosityFunction)
|
||||
inline val luminosity: Color
|
||||
get() = BlockPropUtil.getDynamicLumFunc(Color(lumColR, lumColG, lumColB, 1f), dynamicLuminosityFunction)
|
||||
|
||||
var drop: Int = 0
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
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.Terrarum
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.toRGB10
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.RGB10
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-06-16.
|
||||
@@ -38,21 +37,21 @@ object BlockPropUtil {
|
||||
|
||||
}
|
||||
|
||||
private fun getTorchFlicker(baseLum: Int): RGB10 {
|
||||
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX.toFloat() / flickerFuncDomain,
|
||||
private fun getTorchFlicker(baseLum: Color): Color {
|
||||
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain,
|
||||
flickerP0, flickerP1, flickerP2, flickerP3
|
||||
)
|
||||
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
private fun getSlowBreath(baseLum: Int): RGB10 {
|
||||
private fun getSlowBreath(baseLum: Color): Color {
|
||||
val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange
|
||||
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
private fun getPulsate(baseLum: Int): RGB10 {
|
||||
private fun getPulsate(baseLum: Color): Color {
|
||||
val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange
|
||||
|
||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||
@@ -92,11 +91,11 @@ object BlockPropUtil {
|
||||
|
||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x
|
||||
|
||||
fun getDynamicLumFunc(baseLum: Int, type: Int): Int {
|
||||
fun getDynamicLumFunc(baseLum: Color, type: Int): Color {
|
||||
return when (type) {
|
||||
1 -> getTorchFlicker(baseLum)
|
||||
2 -> Terrarum.ingame!!.world.globalLight // current global light
|
||||
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).toRGB10() // daylight at noon
|
||||
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2) // daylight at noon
|
||||
4 -> getSlowBreath(baseLum)
|
||||
5 -> getPulsate(baseLum)
|
||||
else -> baseLum
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
|
||||
@@ -14,10 +15,10 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 4) {
|
||||
try {
|
||||
val r = args[1].toInt()
|
||||
val g = args[2].toInt()
|
||||
val b = args[3].toInt()
|
||||
val GL = LightmapRenderer.constructRGBFromInt(r, g, b)
|
||||
val r = args[1].toFloat()
|
||||
val g = args[2].toFloat()
|
||||
val b = args[3].toFloat()
|
||||
val GL = Color(r, g, b, 1f)
|
||||
|
||||
lightOverride = true
|
||||
Terrarum.ingame!!.world.globalLight = GL
|
||||
@@ -29,25 +30,6 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
||||
Echo("Range: 0-" + LightmapRenderer.CHANNEL_MAX + " per channel")
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.size == 2) {
|
||||
try {
|
||||
val GL = args[1].toInt()
|
||||
|
||||
if (GL.toInt() < 0 || GL.toInt() >= LightmapRenderer.COLOUR_RANGE_SIZE) {
|
||||
Echo("Range: 0-" + (LightmapRenderer.COLOUR_RANGE_SIZE - 1))
|
||||
}
|
||||
else {
|
||||
Terrarum.ingame!!.world.globalLight = GL
|
||||
}
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
if (args[1].toLowerCase() == "none")
|
||||
lightOverride = false
|
||||
else
|
||||
Echo("Wrong number input.")
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
|
||||
@@ -39,7 +39,9 @@ object AVKey {
|
||||
* 0000 0010000000 0010000000 0010000000
|
||||
* ^ Red ^ Green ^ Blue
|
||||
*/
|
||||
const val LUMINOSITY = "luminosity"
|
||||
const val LUMR = "luminosityred"
|
||||
const val LUMG = "luminositygreen"
|
||||
const val LUMB = "luminosityblue"
|
||||
const val DRAGCOEFF = "dragcoeff"
|
||||
const val FALLDAMPENMULT = "falldampenmult"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
@@ -8,6 +9,7 @@ import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.ui.UIInventory
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -47,19 +49,17 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
if (houseDesignation != null) houseDesignation!!.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* Recommended implementation:
|
||||
*
|
||||
override var luminosity: Int
|
||||
get() = actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
|
||||
set(value) {
|
||||
actorValue[AVKey.LUMINOSITY] = value
|
||||
}
|
||||
*/
|
||||
override var luminosity: Int
|
||||
get() = actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
|
||||
override var luminosity: Color
|
||||
get() = Color(
|
||||
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
1f
|
||||
)
|
||||
set(value) {
|
||||
actorValue[AVKey.LUMINOSITY] = 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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,8 @@ typealias Second = Float
|
||||
*
|
||||
* Created by minjaesong on 16-01-13.
|
||||
*/
|
||||
open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) : ActorWithBody(renderOrder) {
|
||||
open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) :
|
||||
ActorWithBody(renderOrder) {
|
||||
|
||||
|
||||
val COLLISION_TEST_MODE = false
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
@@ -11,11 +12,12 @@ import java.util.*
|
||||
*/
|
||||
internal class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
|
||||
override var luminosity: Int
|
||||
override var luminosity: Color
|
||||
get() = BlockCodex[Block.TORCH].luminosity
|
||||
set(value) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override val lightBoxList: ArrayList<Hitbox>
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-19.
|
||||
*/
|
||||
@@ -8,13 +10,20 @@ interface Luminous {
|
||||
/**
|
||||
* Recommended implementation:
|
||||
*
|
||||
override var luminosity: Int
|
||||
get() = actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
|
||||
override var luminosity: Color
|
||||
get() = Color(
|
||||
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||
1f
|
||||
)
|
||||
set(value) {
|
||||
actorValue[AVKey.LUMINOSITY] = 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
|
||||
}
|
||||
*/
|
||||
var luminosity: Int
|
||||
var luminosity: Color
|
||||
|
||||
/**
|
||||
* Arguments:
|
||||
|
||||
@@ -49,8 +49,9 @@ object PlayerBuilderSigrid {
|
||||
|
||||
p.actorValue[AVKey.INTELLIGENT] = true
|
||||
|
||||
//p.actorValue[AVKey.LUMINOSITY] = Color(0x434aff).to10bit()
|
||||
//p.actorValue[AVKey.LUMINOSITY] = 214127943 // bright purple
|
||||
//p.actorValue[AVKey.LUMR] = 0.84f
|
||||
//p.actorValue[AVKey.LUMR] = 0.93f
|
||||
//p.actorValue[AVKey.LUMR] = 1.37f
|
||||
|
||||
p.actorValue[AVKey.BASEDEFENCE] = 141
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ open class ProjectileSimple(
|
||||
val speed: Int
|
||||
|
||||
|
||||
override var luminosity: Int
|
||||
get() = bulletDatabase[type][OFFSET_LUMINOSITY] as Int
|
||||
override var luminosity: Color
|
||||
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Color).cpy()
|
||||
set(value) {
|
||||
}
|
||||
/**
|
||||
@@ -115,8 +115,8 @@ open class ProjectileSimple(
|
||||
val OFFSET_LUMINOSITY = 4
|
||||
val bulletDatabase = arrayOf(
|
||||
// damage, display colour, no gravity, speed
|
||||
arrayOf(7, Color(0xFF5429), true, 40, 32),
|
||||
arrayOf(8, Color(0xFF5429), true, 20, 0)
|
||||
arrayOf(7, Color(0xFF5429_FF.toInt()), true, 40, 32),
|
||||
arrayOf(8, Color(0xFF5429_FF.toInt()), true, 20, 0)
|
||||
// ...
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-04-26.
|
||||
*/
|
||||
@@ -15,7 +17,7 @@ class WeaponSwung(val itemID: Int) : ActorWithPhysics(Actor.RenderOrder.MIDTOP),
|
||||
actorValue[AVKey.LUMINOSITY] = value
|
||||
}
|
||||
*/
|
||||
override var luminosity: Int
|
||||
override var luminosity: Color
|
||||
get() = throw UnsupportedOperationException()
|
||||
set(value) {
|
||||
}
|
||||
|
||||
@@ -73,14 +73,6 @@ internal class AILuaAPI(g: Globals, actor: ActorWithPhysics) {
|
||||
|
||||
t["strength"] = actor.avStrength.toLua()
|
||||
|
||||
val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
|
||||
val MUL_2 = LightmapRenderer.MUL_2
|
||||
val MUL = LightmapRenderer.MUL
|
||||
val CHMAX = LightmapRenderer.CHANNEL_MAX
|
||||
t["luminosityRGB"] = lumrgb.toLua()
|
||||
t["luminosity"] = (lumrgb.div(MUL_2).and(CHMAX).times(3) +
|
||||
lumrgb.div(MUL).and(CHMAX).times(4) +
|
||||
lumrgb.and(1023)).div(8.0).toLua() // quick luminosity calculation
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
package net.torvald.terrarum.gameworld
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.worlddrawer.RGB10
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
typealias BlockAddress = Long
|
||||
@@ -32,8 +32,8 @@ class GameWorld(val width: Int, val height: Int) {
|
||||
//physics
|
||||
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
|
||||
var gravitation: Vector2 = Vector2(0.0, 9.8)
|
||||
/** RGB in Integer */
|
||||
var globalLight: RGB10 = 0
|
||||
/** 0.0..1.0+ */
|
||||
var globalLight = Color(0f,0f,0f,1f)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
val lightVal: String
|
||||
val mtX = mouseTileX.toString()
|
||||
val mtY = mouseTileY.toString()
|
||||
val valRaw = LightmapRenderer.getValueFromMap(mouseTileX, mouseTileY)
|
||||
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)
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.abs
|
||||
import net.torvald.terrarum.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.toColor
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
@@ -94,11 +93,11 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas {
|
||||
if (player != null) {
|
||||
val playerPos = player.tilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
Terrarum.ingame!!.world.globalLight.toColor()
|
||||
Terrarum.ingame!!.world.globalLight
|
||||
)
|
||||
}
|
||||
else {
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight.toColor()
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.torvald.terrarum.imagefont.Watch7SegMain
|
||||
import net.torvald.terrarum.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.imagefont.WatchDotAlph
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.toColor
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
@@ -69,11 +68,11 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas {
|
||||
if (player != null) {
|
||||
val playerPos = player.tilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
Terrarum.ingame!!.world.globalLight.toColor()
|
||||
Terrarum.ingame!!.world.globalLight
|
||||
)
|
||||
}
|
||||
else {
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight.toColor()
|
||||
lightLevel = Terrarum.ingame!!.world.globalLight
|
||||
}
|
||||
|
||||
// backplate
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ParticleTestRain
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@ import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.toRGB10
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.b
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.g
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.r
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -22,7 +18,7 @@ import java.util.*
|
||||
* Created by minjaesong on 16-01-25.
|
||||
*/
|
||||
|
||||
typealias RGB10 = Int
|
||||
//typealias RGB10 = Int
|
||||
|
||||
object LightmapRenderer {
|
||||
private val world: GameWorld = Terrarum.ingame!!.world
|
||||
@@ -30,8 +26,8 @@ object LightmapRenderer {
|
||||
|
||||
// TODO if (VBO works on BlocksDrawer) THEN overscan of 256, utilise same technique in here
|
||||
|
||||
val overscan_open: Int = Math.min(32, 256f.div(BlockCodex[Block.AIR].opacity and 0xFF).ceil())
|
||||
val overscan_opaque: Int = Math.min(8, 256f.div(BlockCodex[Block.STONE].opacity and 0xFF).ceil())
|
||||
val overscan_open: Int = 32
|
||||
val overscan_opaque: Int = 8
|
||||
|
||||
init {
|
||||
println("[LightmapRenderer] Overscan open: $overscan_open; opaque: $overscan_opaque")
|
||||
@@ -45,7 +41,7 @@ object LightmapRenderer {
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
|
||||
/**
|
||||
* 8-Bit RGB values
|
||||
* Float value, 1.0 for 1023
|
||||
*/
|
||||
private val lightmap: Array<Array<Color>> = Array(LIGHTMAP_HEIGHT) { Array(LIGHTMAP_WIDTH, { Color(0f,0f,0f,1f) }) } // TODO framebuffer?
|
||||
private val lanternMap = ArrayList<Lantern>(Terrarum.ingame!!.ACTORCONTAINER_INITIAL_SIZE * 4)
|
||||
@@ -63,6 +59,7 @@ object LightmapRenderer {
|
||||
const val CHANNEL_MAX_FLOAT = CHANNEL_MAX.toFloat()
|
||||
const val COLOUR_RANGE_SIZE = MUL * MUL_2
|
||||
const val MUL_FLOAT = MUL / 256f
|
||||
const val DIV_FLOAT = 256f / MUL
|
||||
|
||||
internal var for_x_start: Int = 0
|
||||
internal var for_y_start: Int = 0
|
||||
@@ -72,7 +69,21 @@ object LightmapRenderer {
|
||||
|
||||
//inline fun getLightRawPos(x: Int, y: Int) = lightmap[y][x]
|
||||
|
||||
|
||||
/**
|
||||
* Conventional level (multiplied by four)
|
||||
*/
|
||||
fun getLight(x: Int, y: Int): Color? {
|
||||
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, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLightInternal(x: Int, y: Int): Color? {
|
||||
if (y - for_y_start + overscan_open in 0..lightmap.lastIndex &&
|
||||
x - for_x_start + overscan_open in 0..lightmap[0].lastIndex) {
|
||||
|
||||
@@ -82,7 +93,7 @@ object LightmapRenderer {
|
||||
return null
|
||||
}
|
||||
|
||||
fun setLight(x: Int, y: Int, colour: Color) {
|
||||
private fun setLight(x: Int, y: Int, colour: Color) {
|
||||
if (y - for_y_start + overscan_open in 0..lightmap.lastIndex &&
|
||||
x - for_x_start + overscan_open in 0..lightmap[0].lastIndex) {
|
||||
|
||||
@@ -254,9 +265,9 @@ object LightmapRenderer {
|
||||
var lightLevelThis: Color = Color(0f,0f,0f,1f)
|
||||
val thisTerrain = Terrarum.ingame!!.world.getTileFromTerrain(x, y)
|
||||
val thisWall = Terrarum.ingame!!.world.getTileFromWall(x, y)
|
||||
val thisTileLuminosity = BlockCodex[thisTerrain].luminosity.toColor()
|
||||
val thisTileOpacity = BlockCodex[thisTerrain].opacity.toColor()
|
||||
val sunLight = Terrarum.ingame!!.world.globalLight.toColor()
|
||||
val thisTileLuminosity = BlockCodex[thisTerrain].luminosity // already been div by four
|
||||
val thisTileOpacity = BlockCodex[thisTerrain].opacity // already been div by four
|
||||
val sunLight = Terrarum.ingame!!.world.globalLight.cpy().mul(DIV_FLOAT, DIV_FLOAT, DIV_FLOAT, 1f)
|
||||
|
||||
// MIX TILE
|
||||
// open air
|
||||
@@ -276,7 +287,7 @@ object LightmapRenderer {
|
||||
for (i in 0..lanternMap.size - 1) {
|
||||
val lmap = lanternMap[i]
|
||||
if (lmap.posX == x && lmap.posY == y)
|
||||
lightLevelThis = lightLevelThis maxBlend lmap.luminosity.toColor() // maximise to not exceed 1.0 with normal (<= 1.0) light
|
||||
lightLevelThis = lightLevelThis maxBlend lmap.luminosity // maximise to not exceed 1.0 with normal (<= 1.0) light
|
||||
}
|
||||
|
||||
|
||||
@@ -288,15 +299,15 @@ object LightmapRenderer {
|
||||
* sample ambient for eight points and apply attenuation for those
|
||||
* maxblend eight values and use it
|
||||
*/
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y - 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y - 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y + 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y + 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y - 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y - 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y + 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
/* + */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y + 1) ?: Color(0f,0f,0f,1f), scaleSqrt2(thisTileOpacity))
|
||||
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y - 1) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x , y + 1) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x - 1, y ) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLight(x + 1, y ) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x , y - 1) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x , y + 1) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x - 1, y ) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
/* * */ambientAccumulator = ambientAccumulator maxBlend darkenColoured(getLightInternal(x + 1, y ) ?: Color(0f,0f,0f,1f), thisTileOpacity)
|
||||
|
||||
return lightLevelThis maxBlend ambientAccumulator
|
||||
}
|
||||
@@ -306,7 +317,7 @@ object LightmapRenderer {
|
||||
}
|
||||
|
||||
private fun getLightForOpaque(x: Int, y: Int): Color? { // ...so that they wouldn't appear too dark
|
||||
val l = getLight(x, y)
|
||||
val l = getLightInternal(x, y)
|
||||
if (l == null) return null
|
||||
|
||||
if (BlockCodex[world.getTileFromTerrain(x, y)].isSolid) {
|
||||
@@ -396,12 +407,6 @@ object LightmapRenderer {
|
||||
1f)
|
||||
}
|
||||
|
||||
fun scaleColour(data: Int, scale: Float): RGB10 {
|
||||
return ((data.r() * scale).clampOne() * CHANNEL_MAX).round().shl(20) or
|
||||
((data.g() * scale).clampOne() * CHANNEL_MAX).round().shl(10) or
|
||||
((data.b() * scale).clampOne() * CHANNEL_MAX).round()
|
||||
}
|
||||
|
||||
private fun scaleSqrt2(data: Color): Color {
|
||||
return Color(
|
||||
data.r * 1.41421356f,
|
||||
@@ -410,8 +415,6 @@ object LightmapRenderer {
|
||||
1f)
|
||||
}
|
||||
|
||||
private val scaleSqrt2Lookup = IntArray(MUL, { it -> minOf(MUL - 1, (it * 1.41421356).roundInt()) })
|
||||
|
||||
/**
|
||||
* Add each channel's RGB value.
|
||||
*
|
||||
@@ -450,13 +453,13 @@ object LightmapRenderer {
|
||||
* @param brighten (-1.0 - 1.0) negative means darkening
|
||||
* @return processed colour
|
||||
*/
|
||||
fun alterBrightnessUniform(data: RGB10, brighten: Float): RGB10 {
|
||||
fun alterBrightnessUniform(data: Color, brighten: Float): Color {
|
||||
return Color(
|
||||
data.r() + brighten,
|
||||
data.g() + brighten,
|
||||
data.b() + brighten,
|
||||
data.r + brighten,
|
||||
data.g + brighten,
|
||||
data.b + brighten,
|
||||
1f
|
||||
).toRGB10()
|
||||
)
|
||||
}
|
||||
|
||||
/** Get each channel from two RGB values, return new RGB that has max value of each channel
|
||||
@@ -473,17 +476,17 @@ object LightmapRenderer {
|
||||
}
|
||||
|
||||
|
||||
inline fun RGB10.rawR() = this.ushr(20) and 1023
|
||||
/*inline fun RGB10.rawR() = this.ushr(20) and 1023
|
||||
inline fun RGB10.rawG() = this.ushr(10) and 1023
|
||||
inline fun RGB10.rawB() = this and 1023
|
||||
|
||||
/** 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
|
||||
inline fun RGB10.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT*/
|
||||
|
||||
|
||||
inline fun constructRGBFromInt(r: Int, g: Int, b: Int): RGB10 {
|
||||
/*inline fun constructRGBFromInt(r: Int, g: Int, b: Int): RGB10 {
|
||||
//if (r !in 0..CHANNEL_MAX) throw IllegalArgumentException("Red: out of range ($r)")
|
||||
//if (g !in 0..CHANNEL_MAX) throw IllegalArgumentException("Green: out of range ($g)")
|
||||
//if (b !in 0..CHANNEL_MAX) throw IllegalArgumentException("Blue: out of range ($b)")
|
||||
@@ -491,7 +494,7 @@ object LightmapRenderer {
|
||||
return r.shl(20) or
|
||||
g.shl(10) or
|
||||
b
|
||||
}
|
||||
}*/
|
||||
|
||||
/*inline fun constructRGBFromFloat(r: Float, g: Float, b: Float): RGB10 {
|
||||
//if (r < 0 || r > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Red: out of range ($r)")
|
||||
@@ -509,9 +512,8 @@ object LightmapRenderer {
|
||||
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): Color? = getLight(x, y)
|
||||
fun getHighestRGB(x: Int, y: Int): Float? {
|
||||
val value = getLight(x, y)
|
||||
val value = getLightInternal(x, y)
|
||||
if (value == null)
|
||||
return null
|
||||
else
|
||||
@@ -636,7 +638,7 @@ object LightmapRenderer {
|
||||
1f
|
||||
)
|
||||
|
||||
data class Lantern(val posX: Int, val posY: Int, val luminosity: Int)
|
||||
data class Lantern(val posX: Int, val posY: Int, val luminosity: Color)
|
||||
|
||||
private fun Color.nonZero() = this.r != 0f || this.g != 0f || this.b != 0f
|
||||
|
||||
@@ -650,9 +652,9 @@ object LightmapRenderer {
|
||||
// excluiding overscans; only reckon echo lights
|
||||
for (y in overscan_open..render_height + overscan_open + 1) {
|
||||
for (x in overscan_open..render_width + overscan_open + 1) {
|
||||
reds[lightmap[y][x].r.times(MUL).floorInt()] += 1
|
||||
greens[lightmap[y][x].g.times(MUL).floorInt()] += 1
|
||||
blues[lightmap[y][x].b.times(MUL).floorInt()] += 1
|
||||
reds [minOf(CHANNEL_MAX, lightmap[y][x].r.times(MUL).floorInt())] += 1
|
||||
greens[minOf(CHANNEL_MAX, lightmap[y][x].g.times(MUL).floorInt())] += 1
|
||||
blues [minOf(CHANNEL_MAX, lightmap[y][x].b.times(MUL).floorInt())] += 1
|
||||
}
|
||||
}
|
||||
return Histogram(reds, greens, blues)
|
||||
@@ -714,8 +716,3 @@ object LightmapRenderer {
|
||||
return (1f - scale) * startValue + scale * endValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun RGB10.toColor(): Color {
|
||||
return Color(this.r(), this.g(), this.b(), 1f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user