mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 14:04:05 +09:00
TilePropCodex is now object, torch flicker (WIP as all the torches are in unison)
Former-commit-id: df9c0e3a9ace2ba976da5e81f1f2d2217db541a0 Former-commit-id: 81a25a938023f318937e1f4ded15e6047fdf8864
This commit is contained in:
@@ -36,10 +36,13 @@ class TileProp {
|
||||
set(value) {
|
||||
realLum = value
|
||||
}
|
||||
get() = if (id == TileNameCode.SUNSTONE)
|
||||
get() = // specify special tiles; else return real luminosity recorded in CSV
|
||||
if (id == TileNameCode.SUNSTONE)
|
||||
Terrarum.game.map.globalLight
|
||||
else if (id == TileNameCode.DAYLIGHT_CAPACITOR)
|
||||
Terrarum.game.globalLightByTime(WorldTime.DAY_LENGTH / 2)
|
||||
else if (id == TileNameCode.TORCH)
|
||||
TilePropUtil.getTorchFlicker(realLum)
|
||||
else
|
||||
realLum
|
||||
|
||||
|
||||
@@ -10,7 +10,13 @@ import java.io.IOException
|
||||
/**
|
||||
* Created by minjaesong on 16-02-16.
|
||||
*/
|
||||
class TilePropCodex {
|
||||
object TilePropCodex {
|
||||
|
||||
private lateinit var tileProps: Array<TileProp>
|
||||
|
||||
val CSV_PATH = "./src/net/torvald/terrarum/tileproperties/tileprop.csv"
|
||||
|
||||
const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE
|
||||
|
||||
init {
|
||||
tileProps = Array<TileProp>(TILE_UNIQUE_MAX + 1,
|
||||
@@ -38,82 +44,73 @@ class TilePropCodex {
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private lateinit var tileProps: Array<TileProp>
|
||||
|
||||
val CSV_PATH = "./src/net/torvald/terrarum/tileproperties/tileprop.csv"
|
||||
|
||||
const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE
|
||||
|
||||
fun getProp(index: Int, damage: Int): TileProp {
|
||||
try {
|
||||
tileProps[idDamageToIndex(index, damage)].id
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
throw NullPointerException("Tile prop with id $index and damage $damage does not exist.")
|
||||
}
|
||||
|
||||
return tileProps[idDamageToIndex(index, damage)]
|
||||
fun getProp(index: Int, damage: Int): TileProp {
|
||||
try {
|
||||
tileProps[idDamageToIndex(index, damage)].id
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
throw NullPointerException("Tile prop with id $index and damage $damage does not exist.")
|
||||
}
|
||||
|
||||
fun getProp(rawIndex: Int?): TileProp {
|
||||
try {
|
||||
tileProps[rawIndex ?: TileNameCode.NULL].id
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
throw NullPointerException("Tile prop with raw id $rawIndex does not exist.")
|
||||
}
|
||||
|
||||
return tileProps[rawIndex ?: TileNameCode.NULL]
|
||||
}
|
||||
|
||||
private fun setProp(prop: TileProp, record: CSVRecord) {
|
||||
prop.nameKey = record.get("name")
|
||||
|
||||
prop.id = idDamageToIndex(intVal(record, "id"), intVal(record, "dmg"))
|
||||
|
||||
prop.opacity = intVal(record, "opacity")
|
||||
prop.strength = intVal(record, "strength")
|
||||
prop.density = intVal(record, "dsty")
|
||||
prop.luminosity = intVal(record, "lumcolor")
|
||||
prop.drop = intVal(record, "drop")
|
||||
prop.dropDamage = intVal(record, "ddmg")
|
||||
prop.friction = intVal(record, "friction")
|
||||
|
||||
prop.isFluid = boolVal(record, "fluid")
|
||||
prop.isSolid = boolVal(record, "solid")
|
||||
prop.isWallable = boolVal(record, "wall")
|
||||
prop.isFallable = boolVal(record, "fall")
|
||||
|
||||
print(formatNum3(intVal(record, "id")) + ":" + formatNum2(intVal(record, "dmg")))
|
||||
println("\t" + prop.nameKey)
|
||||
}
|
||||
|
||||
private fun intVal(rec: CSVRecord, s: String): Int {
|
||||
var ret = -1
|
||||
try {
|
||||
ret = Integer.decode(rec.get(s))!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun boolVal(rec: CSVRecord, s: String) = intVal(rec, s) != 0
|
||||
|
||||
fun idDamageToIndex(index: Int, damage: Int) = index * PairedMapLayer.RANGE + damage
|
||||
|
||||
private fun formatNum3(i: Int): String {
|
||||
if (i < 10)
|
||||
return "00" + i
|
||||
else if (i < 100)
|
||||
return "0" + i
|
||||
else
|
||||
return i.toString()
|
||||
}
|
||||
|
||||
private fun formatNum2(i: Int) = if (i < 10) "0" + i else i.toString()
|
||||
return tileProps[idDamageToIndex(index, damage)]
|
||||
}
|
||||
|
||||
fun getProp(rawIndex: Int?): TileProp {
|
||||
try {
|
||||
tileProps[rawIndex ?: TileNameCode.NULL].id
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
throw NullPointerException("Tile prop with raw id $rawIndex does not exist.")
|
||||
}
|
||||
|
||||
return tileProps[rawIndex ?: TileNameCode.NULL]
|
||||
}
|
||||
|
||||
private fun setProp(prop: TileProp, record: CSVRecord) {
|
||||
prop.nameKey = record.get("name")
|
||||
|
||||
prop.id = idDamageToIndex(intVal(record, "id"), intVal(record, "dmg"))
|
||||
|
||||
prop.opacity = intVal(record, "opacity")
|
||||
prop.strength = intVal(record, "strength")
|
||||
prop.density = intVal(record, "dsty")
|
||||
prop.luminosity = intVal(record, "lumcolor")
|
||||
prop.drop = intVal(record, "drop")
|
||||
prop.dropDamage = intVal(record, "ddmg")
|
||||
prop.friction = intVal(record, "friction")
|
||||
|
||||
prop.isFluid = boolVal(record, "fluid")
|
||||
prop.isSolid = boolVal(record, "solid")
|
||||
prop.isWallable = boolVal(record, "wall")
|
||||
prop.isFallable = boolVal(record, "fall")
|
||||
|
||||
print(formatNum3(intVal(record, "id")) + ":" + formatNum2(intVal(record, "dmg")))
|
||||
println("\t" + prop.nameKey)
|
||||
}
|
||||
|
||||
private fun intVal(rec: CSVRecord, s: String): Int {
|
||||
var ret = -1
|
||||
try {
|
||||
ret = Integer.decode(rec.get(s))!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun boolVal(rec: CSVRecord, s: String) = intVal(rec, s) != 0
|
||||
|
||||
fun idDamageToIndex(index: Int, damage: Int) = index * PairedMapLayer.RANGE + damage
|
||||
|
||||
private fun formatNum3(i: Int): String {
|
||||
if (i < 10)
|
||||
return "00" + i
|
||||
else if (i < 100)
|
||||
return "0" + i
|
||||
else
|
||||
return i.toString()
|
||||
}
|
||||
|
||||
private fun formatNum2(i: Int) = if (i < 10) "0" + i else i.toString()
|
||||
}
|
||||
|
||||
57
src/net/torvald/terrarum/tileproperties/TilePropUtil.kt
Normal file
57
src/net/torvald/terrarum/tileproperties/TilePropUtil.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package net.torvald.terrarum.tileproperties
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-06-16.
|
||||
*/
|
||||
object TilePropUtil {
|
||||
var flickerFuncX = 0 // in milliseconds; saves current status of func
|
||||
val flickerFuncDomain = 50 // time between two noise sample, in milliseconds
|
||||
val flickerFuncRange = 0.012f // intensity [0, 1]
|
||||
//val torchIntensityOffset = -0.04f
|
||||
|
||||
val random = HQRNG();
|
||||
var funcY = 0f
|
||||
|
||||
var patternThis = getNewPattern()
|
||||
var patternNext = getNewPattern()
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun getTorchFlicker(baseLum: Int): Int {
|
||||
funcY = linearInterpolation1D(patternThis, patternNext,
|
||||
flickerFuncX.toFloat() / flickerFuncDomain
|
||||
)
|
||||
|
||||
return LightmapRenderer.brightenUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
fun torchFlickerTickClock() {
|
||||
flickerFuncX += Terrarum.game.DELTA_T
|
||||
|
||||
if (flickerFuncX > flickerFuncDomain) {
|
||||
flickerFuncX -= flickerFuncDomain
|
||||
|
||||
patternThis = patternNext
|
||||
patternNext = getNewPattern()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNewPattern(): Float = random.nextFloat().times(2).minus(1f) * flickerFuncRange
|
||||
|
||||
private fun cosineInterpolation1D(a: Float, b: Float, x: Float): Float{
|
||||
val ft: Float = x * FastMath.PI;
|
||||
val f: Float = (1 - FastMath.cos(ft)) * 0.5f;
|
||||
|
||||
return a * (1 - f) + b * f;
|
||||
}
|
||||
|
||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) =
|
||||
a * (1 - x) + b * x;
|
||||
}
|
||||
@@ -41,7 +41,7 @@
|
||||
"10"; "2";"TILE_PLATFORM_EBONY" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "2"; "0";"16"
|
||||
"10"; "3";"TILE_PLATFORM_BIRCH" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "3"; "0";"16"
|
||||
"10"; "4";"TILE_PLATFORM_BLOODROSE" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "4"; "0";"16"
|
||||
"11"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "267518016"; "11"; "0"; "0";"16"
|
||||
"11"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "266453040"; "11"; "0"; "0";"16"
|
||||
"11"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "81916159"; "11"; "1"; "0";"16"
|
||||
"12"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "0"; "0";"16"
|
||||
"12"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "1"; "0";"16"
|
||||
@@ -122,7 +122,7 @@
|
||||
## Notes ##
|
||||
|
||||
# Friction: 0: frictionless, <16: slippery, 16: regular, >16: sticky
|
||||
# Opacity/Lumcolor: 40-step RGB
|
||||
# Opacity/Lumcolor: 30-bit RGB
|
||||
# Solid: whether the tile has full collision
|
||||
# movr: Movement resistance, (walkspeedmax) / (1 + (n/16)), 16 halves movement speed
|
||||
# dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l]
|
||||
@@ -131,7 +131,7 @@
|
||||
## Illuminators ##
|
||||
|
||||
# Illuminator white: RGB(228,238,234), simulation of a halophosphate FL lamp (If you want high CRI lamp, collect a daylight!)
|
||||
# Defalut torch : L 70 a 51 b 59; real candlelight colour taken from properly configured camera.
|
||||
# Defalut torch : L 64 a 51 b 59; real candlelight colour taken from properly configured camera.
|
||||
# Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code.
|
||||
# Sunlight capacitor: daylight at noon. Set by game's code.
|
||||
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 18.
|
Reference in New Issue
Block a user