mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
nuked fluidcodex
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
@@ -110,6 +111,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.shadeColor = Color(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA)
|
||||
|
||||
prop.strength = intVal(record, "str")
|
||||
prop.density = intVal(record, "dsty")
|
||||
@@ -118,6 +120,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.friction = intVal(record, "fr")
|
||||
prop.viscosity = intVal(record, "vscs")
|
||||
|
||||
@@ -16,6 +16,7 @@ class BlockProp {
|
||||
var shadeColG = 0f
|
||||
var shadeColB = 0f
|
||||
var shadeColA = 0f
|
||||
lateinit var shadeColor: Color
|
||||
|
||||
/**
|
||||
* @param opacity Raw RGB value, without alpha
|
||||
@@ -39,12 +40,13 @@ class BlockProp {
|
||||
var lumColG = 0f
|
||||
var lumColB = 0f
|
||||
var lumColA = 0f
|
||||
lateinit var internalLumCol: Color
|
||||
|
||||
/**
|
||||
* @param luminosity
|
||||
*/
|
||||
inline val luminosity: Color
|
||||
get() = BlockPropUtil.getDynamicLumFunc(Color(lumColR, lumColG, lumColB, lumColA), dynamicLuminosityFunction)
|
||||
get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction)
|
||||
|
||||
var drop: Int = 0
|
||||
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
package net.torvald.terrarum.gameworld
|
||||
|
||||
import net.torvald.terrarum.blockproperties.Fluid
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-08-06.
|
||||
*/
|
||||
object FluidCodex {
|
||||
|
||||
operator fun get(type: FluidType): FluidProp {
|
||||
return if (type sameAs Fluid.NULL)
|
||||
nullProp
|
||||
else
|
||||
waterProp
|
||||
}
|
||||
|
||||
// TODO temporary, should read from CSV
|
||||
val nullProp = FluidProp.getNullProp()
|
||||
val waterProp = FluidProp()
|
||||
|
||||
init {
|
||||
waterProp.shadeColR = 0.1016f
|
||||
waterProp.shadeColG = 0.0744f
|
||||
waterProp.shadeColB = 0.0508f
|
||||
waterProp.shadeColA = 0.0508f
|
||||
|
||||
waterProp.density = 1000
|
||||
}
|
||||
}
|
||||
// Use BlockCodex. --Torvald, 2019-01-27
|
||||
@@ -1,14 +1,9 @@
|
||||
package net.torvald.terrarum.gameworld
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2018-12-29.
|
||||
*/
|
||||
class FluidProp {
|
||||
/*class FluidProp {
|
||||
|
||||
var density: Int = 0
|
||||
|
||||
@@ -45,4 +40,4 @@ class FluidProp {
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -412,7 +412,7 @@ open class GameWorld {
|
||||
data class FluidInfo(val type: FluidType, val amount: Float) {
|
||||
/** test if this fluid should be considered as one */
|
||||
fun isFluid() = type != Fluid.NULL && amount >= WorldSimulator.FLUID_MIN_MASS
|
||||
fun getProp() = FluidCodex[type]
|
||||
fun getProp() = BlockCodex[type]
|
||||
override fun toString() = "Fluid type: ${type.value}, amount: $amount"
|
||||
}
|
||||
|
||||
|
||||
62
src/net/torvald/terrarum/tests/FixedMathTest.kt
Normal file
62
src/net/torvald/terrarum/tests/FixedMathTest.kt
Normal file
@@ -0,0 +1,62 @@
|
||||
import kotlin.system.measureNanoTime
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-01-27.
|
||||
*/
|
||||
|
||||
class FixedMathTest {
|
||||
fun invoke() {
|
||||
val testSet = (1..100000).toList().shuffled()
|
||||
val m1 = measureNanoTime {
|
||||
testSet.forEach {
|
||||
val x = (it * 1.41421356f)
|
||||
}
|
||||
}
|
||||
val testSet2 = (1..100000).toList().shuffled()
|
||||
val m2 = measureNanoTime {
|
||||
testSet2.forEach {
|
||||
val x2 = it.mulSqrt2()
|
||||
}
|
||||
}
|
||||
val m3 = measureNanoTime {
|
||||
testSet.forEach {
|
||||
val x = (it * 1.41421356f)
|
||||
}
|
||||
}
|
||||
val m4 = measureNanoTime {
|
||||
testSet2.forEach {
|
||||
val x2 = it.mulSqrt2()
|
||||
}
|
||||
}
|
||||
|
||||
println(m3)
|
||||
println(m4)
|
||||
println(m3.toDouble() / m4)
|
||||
}
|
||||
|
||||
fun Int.mulSqrt2(): Int {
|
||||
val xl = this
|
||||
val yl = 92681
|
||||
|
||||
val xlo = xl and 0x0000FFFF
|
||||
val xhi = xl shr 16
|
||||
val ylo = yl and 0x0000FFFF
|
||||
val yhi = yl shr 16
|
||||
|
||||
val lolo = xlo * ylo
|
||||
val lohi = xlo * yhi
|
||||
val hilo = xhi * ylo
|
||||
val hihi = xhi * yhi
|
||||
|
||||
val loResult = lolo shr 16
|
||||
val hiResult = hihi shl 16
|
||||
|
||||
val sum = loResult + lohi + hilo + hiResult
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
FixedMathTest().invoke()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user