diching RGB10; colors are now fully vec3

This commit is contained in:
minjaesong
2017-07-09 02:21:24 +09:00
parent b3a355f51d
commit c96fb5e017
23 changed files with 299 additions and 282 deletions

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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