mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 16:44:05 +09:00
Compare commits
5 Commits
inventory-
...
test-cvec-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae52de85a2 | ||
|
|
585a20542f | ||
|
|
2ab1443885 | ||
|
|
046f2d4b6c | ||
|
|
e3fbb57530 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -38,7 +38,7 @@
|
|||||||
<property name="caretWidth" class="java.lang.Integer" />
|
<property name="caretWidth" class="java.lang.Integer" />
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</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_X" default="false" project-jdk-name="13-incubate" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -19,9 +19,10 @@ class GdxColorMap {
|
|||||||
height = pixmap.height
|
height = pixmap.height
|
||||||
is2D = pixmap.height > 1
|
is2D = pixmap.height > 1
|
||||||
|
|
||||||
data = kotlin.IntArray(pixmap.width * pixmap.height) {
|
dataRaw = kotlin.IntArray(pixmap.width * pixmap.height) {
|
||||||
pixmap.getPixel(it % pixmap.width, it / pixmap.width)
|
pixmap.getPixel(it % pixmap.width, it / pixmap.width)
|
||||||
}
|
}
|
||||||
|
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
|
||||||
|
|
||||||
pixmap.dispose()
|
pixmap.dispose()
|
||||||
}
|
}
|
||||||
@@ -31,39 +32,46 @@ class GdxColorMap {
|
|||||||
height = pixmap.height
|
height = pixmap.height
|
||||||
is2D = pixmap.height > 1
|
is2D = pixmap.height > 1
|
||||||
|
|
||||||
data = kotlin.IntArray(pixmap.width * pixmap.height) {
|
dataRaw = kotlin.IntArray(pixmap.width * pixmap.height) {
|
||||||
pixmap.getPixel(it % pixmap.width, it / pixmap.width)
|
pixmap.getPixel(it % pixmap.width, it / pixmap.width)
|
||||||
}
|
}
|
||||||
|
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
|
||||||
|
|
||||||
if (disposePixmap) pixmap.dispose()
|
if (disposePixmap) pixmap.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(color: Color) {
|
constructor(color: Color) {
|
||||||
data = intArrayOf(color.toIntBits())
|
dataRaw = intArrayOf(color.toIntBits())
|
||||||
|
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
|
||||||
width = 1
|
width = 1
|
||||||
height = 1
|
height = 1
|
||||||
is2D = false
|
is2D = false
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(gradStart: Color, gradEnd: Color) {
|
constructor(gradStart: Color, gradEnd: Color) {
|
||||||
data = intArrayOf(gradStart.toIntBits(), gradEnd.toIntBits())
|
dataRaw = intArrayOf(gradStart.toIntBits(), gradEnd.toIntBits())
|
||||||
|
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
|
||||||
width = 1
|
width = 1
|
||||||
height = 2
|
height = 2
|
||||||
is2D = true
|
is2D = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private val data: IntArray
|
private val dataRaw: IntArray
|
||||||
|
private val dataGdxColor: Array<Color>
|
||||||
|
//private val dataCvec: Array<Cvec>
|
||||||
val width: Int
|
val width: Int
|
||||||
val height: Int
|
val height: Int
|
||||||
val is2D: Boolean
|
val is2D: Boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun get(x: Int, y: Int): Color = Color(data[y * width + x])
|
fun get(x: Int, y: Int): Color = dataGdxColor[y * width + x]
|
||||||
operator fun get(x: Int): Color = if (is2D) throw OperationNotSupportedException("This is 2D color map") else Color(data[x])
|
operator fun get(x: Int): Color = if (is2D) throw OperationNotSupportedException("This is 2D color map") else dataGdxColor[x]
|
||||||
|
|
||||||
fun getRaw(x: Int, y: Int): RGBA8888 = data[y * width + x]
|
fun getRaw(x: Int, y: Int): RGBA8888 = dataRaw[y * width + x]
|
||||||
fun getRaw(x: Int): RGBA8888 = if (is2D) throw OperationNotSupportedException("This is 2D color map") else data[x]
|
fun getRaw(x: Int): RGBA8888 = if (is2D) throw OperationNotSupportedException("This is 2D color map") else dataRaw[x]
|
||||||
|
|
||||||
|
//fun getAsCvec(x: Int, y: Int): Cvec = dataCvec[y * width + x]
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.torvald.terrarum.blockproperties
|
package net.torvald.terrarum.blockproperties
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.AppLoader.printmsg
|
import net.torvald.terrarum.AppLoader.printmsg
|
||||||
import net.torvald.terrarum.gameworld.FluidType
|
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.MapLayer
|
||||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||||
import net.torvald.terrarum.utils.CSVFetcher
|
import net.torvald.terrarum.utils.CSVFetcher
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||||
import org.apache.commons.csv.CSVRecord
|
import org.apache.commons.csv.CSVRecord
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -110,7 +110,7 @@ object BlockCodex {
|
|||||||
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
|
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
|
||||||
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
|
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
|
||||||
prop.shadeColA = floatVal(record, "shduv") / 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(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA)
|
||||||
|
|
||||||
prop.strength = intVal(record, "str")
|
prop.strength = intVal(record, "str")
|
||||||
prop.density = intVal(record, "dsty")
|
prop.density = intVal(record, "dsty")
|
||||||
@@ -119,7 +119,7 @@ object BlockCodex {
|
|||||||
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
|
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
|
||||||
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
|
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
|
||||||
prop.lumColA = floatVal(record, "lumuv") / 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(prop.lumColR, prop.lumColG, prop.lumColB, prop.lumColA)
|
||||||
|
|
||||||
prop.friction = intVal(record, "fr")
|
prop.friction = intVal(record, "fr")
|
||||||
prop.viscosity = intVal(record, "vscs")
|
prop.viscosity = intVal(record, "vscs")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.blockproperties
|
package net.torvald.terrarum.blockproperties
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-02-16.
|
* Created by minjaesong on 2016-02-16.
|
||||||
@@ -17,7 +17,7 @@ class BlockProp {
|
|||||||
var shadeColB = 0f
|
var shadeColB = 0f
|
||||||
var shadeColA = 0f
|
var shadeColA = 0f
|
||||||
|
|
||||||
lateinit var opacity: Color
|
var opacity: Cvec = Cvec()
|
||||||
|
|
||||||
var strength: Int = 0
|
var strength: Int = 0
|
||||||
var density: Int = 0
|
var density: Int = 0
|
||||||
@@ -36,12 +36,12 @@ class BlockProp {
|
|||||||
var lumColG = 0f
|
var lumColG = 0f
|
||||||
var lumColB = 0f
|
var lumColB = 0f
|
||||||
var lumColA = 0f
|
var lumColA = 0f
|
||||||
lateinit var internalLumCol: Color
|
var internalLumCol: Cvec = Cvec()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param luminosity
|
* @param luminosity
|
||||||
*/
|
*/
|
||||||
inline val luminosity: Color
|
inline val luminosity: Cvec
|
||||||
get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction)
|
get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction)
|
||||||
|
|
||||||
var drop: Int = 0
|
var drop: Int = 0
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.torvald.terrarum.blockproperties
|
package net.torvald.terrarum.blockproperties
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
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,
|
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain,
|
||||||
flickerP0, flickerP1, flickerP2, flickerP3
|
flickerP0, flickerP1, flickerP2, flickerP3
|
||||||
)
|
)
|
||||||
@@ -45,13 +45,13 @@ object BlockPropUtil {
|
|||||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
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
|
val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange
|
||||||
|
|
||||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
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
|
val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange
|
||||||
|
|
||||||
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
|
||||||
@@ -91,11 +91,11 @@ object BlockPropUtil {
|
|||||||
|
|
||||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x
|
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) {
|
return when (type) {
|
||||||
1 -> getTorchFlicker(baseLum)
|
1 -> getTorchFlicker(baseLum)
|
||||||
2 -> (Terrarum.ingame!!.world).globalLight.cpy().mul(LightmapRenderer.DIV_FLOAT) // current global light
|
2 -> (Terrarum.ingame!!.world).globalLight * LightmapRenderer.DIV_FLOAT // current global light
|
||||||
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).cpy().mul(LightmapRenderer.DIV_FLOAT) // daylight at noon
|
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2) * LightmapRenderer.DIV_FLOAT // daylight at noon
|
||||||
4 -> getSlowBreath(baseLum)
|
4 -> getSlowBreath(baseLum)
|
||||||
5 -> getPulsate(baseLum)
|
5 -> getPulsate(baseLum)
|
||||||
else -> baseLum
|
else -> baseLum
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package net.torvald.terrarum.console
|
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.Terrarum
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
|
||||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
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.
|
* Created by minjaesong on 2016-02-17.
|
||||||
@@ -14,11 +13,12 @@ internal object SetGlobalLightOverride : ConsoleCommand {
|
|||||||
override fun execute(args: Array<String>) {
|
override fun execute(args: Array<String>) {
|
||||||
if (args.size == 5) {
|
if (args.size == 5) {
|
||||||
try {
|
try {
|
||||||
val r = args[1].toFloat()
|
val GL = Cvec(
|
||||||
val g = args[2].toFloat()
|
args[1].toFloat(),
|
||||||
val b = args[3].toFloat()
|
args[2].toFloat(),
|
||||||
val a = args[4].toFloat()
|
args[3].toFloat(),
|
||||||
val GL = Color(r, g, b, a)
|
args[4].toFloat()
|
||||||
|
)
|
||||||
|
|
||||||
WeatherMixer.globalLightOverridden = true
|
WeatherMixer.globalLightOverridden = true
|
||||||
(Terrarum.ingame!!.world).globalLight = GL
|
(Terrarum.ingame!!.world).globalLight = GL
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.gameactors
|
package net.torvald.terrarum.gameactors
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-02-19.
|
* Created by minjaesong on 2016-02-19.
|
||||||
@@ -26,7 +26,7 @@ interface Luminous {
|
|||||||
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
|
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
var color: Color
|
var color: Cvec
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arguments:
|
* Arguments:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
package net.torvald.terrarum.gameworld
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
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.modulebasegame.gameworld.WorldSimulator
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.serialise.ReadLayerDataZip
|
import net.torvald.terrarum.serialise.ReadLayerDataZip
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.util.SortedArrayList
|
import net.torvald.util.SortedArrayList
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import kotlin.math.absoluteValue
|
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 */
|
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
|
||||||
var gravitation: Vector2 = Vector2(0.0, 9.80665)
|
var gravitation: Vector2 = Vector2(0.0, 9.80665)
|
||||||
/** 0.0..1.0+ */
|
/** 0.0..1.0+ */
|
||||||
var globalLight = Color(0f,0f,0f,0f)
|
var globalLight = Cvec()
|
||||||
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
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.UICanvas
|
||||||
import net.torvald.terrarum.ui.UINSMenu
|
import net.torvald.terrarum.ui.UINSMenu
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
|
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.LightmapRenderer
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
@@ -279,7 +280,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
|
gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
|
||||||
gameWorld.globalLight = Color(.8f,.8f,.8f,.8f)
|
gameWorld.globalLight = Cvec(.8f)
|
||||||
|
|
||||||
essentialOverlays.add(blockPointingCursor)
|
essentialOverlays.add(blockPointingCursor)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.spriteanimation.HasAssembledSprite
|
import net.torvald.spriteanimation.HasAssembledSprite
|
||||||
import net.torvald.terrarum.*
|
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.gameworld.time_t
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -68,18 +68,18 @@ open class ActorHumanoid(
|
|||||||
if (houseDesignation != null) houseDesignation!!.clear()
|
if (houseDesignation != null) houseDesignation!!.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override var color: Color
|
override var color: Cvec
|
||||||
get() = Color(
|
get() = Cvec(
|
||||||
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||||
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||||
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
|
||||||
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT
|
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT
|
||||||
)
|
)
|
||||||
set(value) {
|
set(value) {
|
||||||
actorValue[AVKey.LUMR] = value.r * LightmapRenderer.MUL_FLOAT
|
actorValue[AVKey.LUMR] = value.vec.lane(0) * LightmapRenderer.MUL_FLOAT
|
||||||
actorValue[AVKey.LUMG] = value.g * LightmapRenderer.MUL_FLOAT
|
actorValue[AVKey.LUMG] = value.vec.lane(1) * LightmapRenderer.MUL_FLOAT
|
||||||
actorValue[AVKey.LUMB] = value.b * LightmapRenderer.MUL_FLOAT
|
actorValue[AVKey.LUMB] = value.vec.lane(2) * LightmapRenderer.MUL_FLOAT
|
||||||
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
|
actorValue[AVKey.LUMA] = value.vec.lane(3) * LightmapRenderer.MUL_FLOAT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ internal class FixtureTikiTorch : FixtureBase(
|
|||||||
BlockBox(BlockBox.NO_COLLISION, 1, 2)
|
BlockBox(BlockBox.NO_COLLISION, 1, 2)
|
||||||
), Luminous {
|
), Luminous {
|
||||||
|
|
||||||
override var color: Color
|
override var color: Cvec
|
||||||
get() = BlockCodex[Block.TORCH].luminosity
|
get() = BlockCodex[Block.TORCH].luminosity
|
||||||
set(value) {
|
set(value) {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
|
|||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -31,8 +32,8 @@ open class ProjectileSimple(
|
|||||||
val speed: Int
|
val speed: Int
|
||||||
|
|
||||||
|
|
||||||
override var color: Color
|
override var color: Cvec
|
||||||
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Color).cpy()
|
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Cvec)
|
||||||
set(value) {
|
set(value) {
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -118,8 +119,8 @@ open class ProjectileSimple(
|
|||||||
val OFFSET_LUMINOSITY = 4
|
val OFFSET_LUMINOSITY = 4
|
||||||
val bulletDatabase = arrayOf(
|
val bulletDatabase = arrayOf(
|
||||||
// damage, display colour, no gravity, speed
|
// damage, display colour, no gravity, speed
|
||||||
arrayOf(7, Color(0xFF5429_FF.toInt()), true, 40, 32),
|
arrayOf(7, Cvec(1f, .329f, .161f, 1f), true, 40, 32),
|
||||||
arrayOf(8, Color(0xFF5429_FF.toInt()), true, 20, 0)
|
arrayOf(8, Cvec(1f, .329f, .161f, 1f), true, 20, 0)
|
||||||
// ...
|
// ...
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
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.
|
* Created by minjaesong on 2016-04-26.
|
||||||
@@ -21,7 +20,7 @@ class WeaponSwung(val itemID: Int) : ActorWBMovable(RenderOrder.MIDTOP), Luminou
|
|||||||
actorValue[AVKey.LUMINOSITY] = value
|
actorValue[AVKey.LUMINOSITY] = value
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
override var color: Color
|
override var color: Cvec
|
||||||
get() = throw UnsupportedOperationException()
|
get() = throw UnsupportedOperationException()
|
||||||
set(value) {
|
set(value) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
|||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
|
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
|
||||||
import net.torvald.terrarum.utils.JsonFetcher
|
import net.torvald.terrarum.utils.JsonFetcher
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||||
|
import net.torvald.terrarum.worlddrawer.Cvec
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -51,7 +52,8 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
lateinit var mixedWeather: BaseModularWeather
|
lateinit var mixedWeather: BaseModularWeather
|
||||||
|
|
||||||
val globalLightNow = Color(0)
|
var globalLightNow = Cvec()
|
||||||
|
private set
|
||||||
|
|
||||||
// Weather indices
|
// Weather indices
|
||||||
const val WEATHER_GENERIC = "generic"
|
const val WEATHER_GENERIC = "generic"
|
||||||
@@ -133,7 +135,7 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
// calculate global light
|
// calculate global light
|
||||||
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
|
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
|
||||||
globalLightNow.set(globalLight)
|
globalLightNow = Cvec(globalLight.r, globalLight.g, globalLight.b, globalLight.a)
|
||||||
|
|
||||||
|
|
||||||
/* (copied from the shader source)
|
/* (copied from the shader source)
|
||||||
@@ -178,8 +180,10 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
/**
|
/**
|
||||||
* Get a GL of specific time
|
* Get a GL of specific time
|
||||||
*/
|
*/
|
||||||
fun getGlobalLightOfTime(timeInSec: Int): Color =
|
fun getGlobalLightOfTime(timeInSec: Int): Cvec {
|
||||||
getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
|
val c = getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
|
||||||
|
return Cvec(c.r, c.g, c.b, c.a)
|
||||||
|
}
|
||||||
|
|
||||||
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
|
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
|
||||||
val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width
|
val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width
|
||||||
|
|||||||
@@ -140,10 +140,10 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
val mtX = mouseTileX.toString()
|
val mtX = mouseTileX.toString()
|
||||||
val mtY = mouseTileY.toString()
|
val mtY = mouseTileY.toString()
|
||||||
val valRaw = LightmapRenderer.getLight(mouseTileX, mouseTileY)
|
val valRaw = LightmapRenderer.getLight(mouseTileX, mouseTileY)
|
||||||
val rawR = valRaw?.r?.times(100f)?.round()?.div(100f)
|
val rawR = valRaw?.vec?.lane(0)?.times(100f)?.round()?.div(100f)
|
||||||
val rawG = valRaw?.g?.times(100f)?.round()?.div(100f)
|
val rawG = valRaw?.vec?.lane(1)?.times(100f)?.round()?.div(100f)
|
||||||
val rawB = valRaw?.b?.times(100f)?.round()?.div(100f)
|
val rawB = valRaw?.vec?.lane(2)?.times(100f)?.round()?.div(100f)
|
||||||
val rawA = valRaw?.a?.times(100f)?.round()?.div(100f)
|
val rawA = valRaw?.vec?.lane(3)?.times(100f)?.round()?.div(100f)
|
||||||
|
|
||||||
lightVal = if (valRaw == null) "—"
|
lightVal = if (valRaw == null) "—"
|
||||||
else "$rawR $rawG $rawB $rawA"
|
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 jdk.incubator.vector.FloatVector
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and compile your OpenJDK-Panama for linux/mac/windows at https://jdk.java.net/panama/
|
||||||
|
* Or use pre-built ones in https://github.com/minjaesong/openjdk13-vectorintrinsic/tree/master
|
||||||
|
*
|
||||||
|
* NOTE: Panama's new vectors are all immutable.
|
||||||
|
* NOTE2: Class inlining vastly improves the performance
|
||||||
|
*
|
||||||
|
* Created by minjaesong on 2019-05-20.
|
||||||
|
*/
|
||||||
|
inline class Cvec constructor(val vec: FloatVector) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test log
|
||||||
|
|
||||||
|
I ran with following jvm args:
|
||||||
|
-XX:TypeProfileLevel=121 -XX:+UseVectorApiIntrinsics --add-modules=jdk.incubator.vector
|
||||||
|
and it's slower than the legacy.
|
||||||
|
|
||||||
|
This time I removed the TypeProfileLevel part. It now runs slightly faster than the legacy?
|
||||||
|
-XX:+UseVectorApiIntrinsics --add-modules=jdk.incubator.vector
|
||||||
|
|
||||||
|
<<append from here>>
|
||||||
|
*/
|
||||||
|
|
||||||
|
constructor(floatArray: FloatArray) : this(FloatVector.fromArray(SPECIES, floatArray, 0))
|
||||||
|
constructor(r: Float, g: Float, b: Float, a: Float) : this(FloatVector.scalars(SPECIES, r, g, b, a))
|
||||||
|
constructor(scalar: Float) : this(FloatVector.scalars(SPECIES, scalar, scalar, scalar, scalar))
|
||||||
|
constructor() : this(FloatVector.zero(SPECIES))
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val EPSILON = 1f / 512f
|
||||||
|
private val SPECIES = FloatVector.SPECIES_128
|
||||||
|
}
|
||||||
|
|
||||||
|
//fun cpy(): Cvec = Cvec(this.vec)
|
||||||
|
|
||||||
|
fun multiply(other: FloatVector) = Cvec(vec.mul(other))
|
||||||
|
infix operator fun times(other: Cvec) = multiply(other.vec)
|
||||||
|
infix operator fun times(scalar: Float) = Cvec(vec.mul(scalar))
|
||||||
|
|
||||||
|
fun subtract(other: FloatVector) = Cvec(vec.sub(other))
|
||||||
|
infix operator fun minus(other: Cvec) = subtract(other.vec)
|
||||||
|
infix operator fun minus(scalar: Float) = Cvec(vec.sub(scalar))
|
||||||
|
|
||||||
|
fun addition(other: FloatVector) = Cvec(vec.add(other))
|
||||||
|
infix operator fun plus(other: Cvec) = addition(other.vec)
|
||||||
|
infix operator fun plus(scalar: Float) = Cvec(vec.add(scalar))
|
||||||
|
|
||||||
|
fun maximum(other: FloatVector): Cvec = Cvec(vec.max(other))
|
||||||
|
infix fun max(other: Cvec): Cvec = maximum(other.vec)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true if at least one element in the vector is not zero.
|
||||||
|
*/
|
||||||
|
fun nonZero(): Boolean = vec.mulLanes() != 0f
|
||||||
|
|
||||||
|
fun toRGBA8888(): Int {
|
||||||
|
var acc = 0
|
||||||
|
for (i in 0..3)
|
||||||
|
acc += vec.lane(i).coerceIn(0f, 1f).times(255f).roundToInt().shl(8 * (3 - i))
|
||||||
|
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
/*override fun equals(other: Any?): Boolean {
|
||||||
|
return this.vec.equal((other as Cvec).vec).allTrue()
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,19 +1,5 @@
|
|||||||
package net.torvald.terrarum.worlddrawer
|
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)
|
* 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
|
// NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable
|
||||||
|
|
||||||
object LightmapRendererOld {
|
/*object LightmapRendererOld {
|
||||||
lateinit var world: GameWorld
|
lateinit var world: GameWorld
|
||||||
|
|
||||||
|
|
||||||
@@ -771,4 +757,4 @@ object LightmapRendererOld {
|
|||||||
}
|
}
|
||||||
return (1f - scale) * startValue + scale * endValue
|
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)
|
// 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 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 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, Color>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
private val lanternMap = HashMap<BlockAddress, Cvec>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
|
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
|
||||||
@@ -120,13 +120,13 @@ object LightmapRenderer {
|
|||||||
* @param x world tile coord
|
* @param x world tile coord
|
||||||
* @param y 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)
|
val col = getLightInternal(x, y)
|
||||||
if (col == null) {
|
if (col == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Color(col.r * MUL_FLOAT, col.g * MUL_FLOAT, col.b * MUL_FLOAT, col.a * MUL_FLOAT)
|
return col * MUL_FLOAT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ object LightmapRenderer {
|
|||||||
* @param y world tile coord
|
* @param y world tile coord
|
||||||
*/
|
*/
|
||||||
// TODO in regard of "colour math against integers", return Int?
|
// 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 &&
|
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
|
||||||
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ object LightmapRenderer {
|
|||||||
* @param colour Color to write
|
* @param colour Color to write
|
||||||
* @param applyFun A function ```foo(old_colour, given_colour)```
|
* @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 &&
|
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
|
||||||
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ object LightmapRenderer {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// set sunlight
|
// set sunlight
|
||||||
sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT)
|
sunLight = world.globalLight * DIV_FLOAT
|
||||||
|
|
||||||
// set no-op mask from solidity of the block
|
// set no-op mask from solidity of the block
|
||||||
AppLoader.measureDebugTime("Renderer.LightNoOpMask") {
|
AppLoader.measureDebugTime("Renderer.LightNoOpMask") {
|
||||||
@@ -394,15 +394,15 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
|
|
||||||
//private val ambientAccumulator = Color(0f,0f,0f,0f)
|
//private val ambientAccumulator = Color(0f,0f,0f,0f)
|
||||||
private val lightLevelThis = Color(0)
|
private var lightLevelThis = Cvec()
|
||||||
private var thisTerrain = 0
|
private var thisTerrain = 0
|
||||||
private var thisFluid = GameWorld.FluidInfo(Fluid.NULL, 0f)
|
private var thisFluid = GameWorld.FluidInfo(Fluid.NULL, 0f)
|
||||||
private val fluidAmountToCol = Color(0)
|
private var fluidAmountToCol = Cvec()
|
||||||
private var thisWall = 0
|
private var thisWall = 0
|
||||||
private val thisTileLuminosity = Color(0)
|
private var thisTileLuminosity = Cvec()
|
||||||
private val thisTileOpacity = Color(0)
|
private var thisTileOpacity = Cvec()
|
||||||
private val thisTileOpacity2 = Color(0) // thisTileOpacity * sqrt(2)
|
private var thisTileOpacity2 = Cvec() // thisTileOpacity * sqrt(2)
|
||||||
private val sunLight = Color(0)
|
private var sunLight = Cvec()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will alter following variables:
|
* This function will alter following variables:
|
||||||
@@ -416,35 +416,35 @@ object LightmapRenderer {
|
|||||||
* - sunlight
|
* - sunlight
|
||||||
*/
|
*/
|
||||||
private fun getLightsAndShades(x: Int, y: Int) {
|
private fun getLightsAndShades(x: Int, y: Int) {
|
||||||
lightLevelThis.set(colourNull)
|
lightLevelThis = colourNull
|
||||||
thisTerrain = world.getTileFromTerrain(x, y) ?: Block.STONE
|
thisTerrain = world.getTileFromTerrain(x, y) ?: Block.STONE
|
||||||
thisFluid = world.getFluid(x, y)
|
thisFluid = world.getFluid(x, y)
|
||||||
thisWall = world.getTileFromWall(x, y) ?: Block.STONE
|
thisWall = world.getTileFromWall(x, y) ?: Block.STONE
|
||||||
|
|
||||||
if (thisFluid.type != Fluid.NULL) {
|
if (thisFluid.type != Fluid.NULL) {
|
||||||
fluidAmountToCol.set(thisFluid.amount, thisFluid.amount, thisFluid.amount, thisFluid.amount)
|
fluidAmountToCol = Cvec(thisFluid.amount)
|
||||||
|
|
||||||
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity)
|
thisTileLuminosity = BlockCodex[thisTerrain].luminosity
|
||||||
thisTileLuminosity.maxAndAssign(BlockCodex[thisFluid.type].luminosity mul fluidAmountToCol) // already been div by four
|
thisTileLuminosity = thisTileLuminosity.max(BlockCodex[thisFluid.type].luminosity * fluidAmountToCol) // already been div by four
|
||||||
thisTileOpacity.set(BlockCodex[thisTerrain].opacity)
|
thisTileOpacity = BlockCodex[thisTerrain].opacity
|
||||||
thisTileOpacity.maxAndAssign(BlockCodex[thisFluid.type].opacity mul fluidAmountToCol) // already been div by four
|
thisTileOpacity = thisTileOpacity.max(BlockCodex[thisFluid.type].opacity * fluidAmountToCol) // already been div by four
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
thisTileLuminosity.set(BlockCodex[thisTerrain].luminosity)
|
thisTileLuminosity = BlockCodex[thisTerrain].luminosity
|
||||||
thisTileOpacity.set(BlockCodex[thisTerrain].opacity)
|
thisTileOpacity = BlockCodex[thisTerrain].opacity
|
||||||
}
|
}
|
||||||
|
|
||||||
thisTileOpacity2.set(thisTileOpacity); thisTileOpacity2.mul(1.41421356f)
|
thisTileOpacity2 = thisTileOpacity * 1.41421356f
|
||||||
//sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT) // moved to fireRecalculateEvent()
|
//sunLight.set(world.globalLight); sunLight.mul(DIV_FLOAT) // moved to fireRecalculateEvent()
|
||||||
|
|
||||||
|
|
||||||
// open air || luminous tile backed by sunlight
|
// open air || luminous tile backed by sunlight
|
||||||
if ((thisTerrain == AIR && thisWall == AIR) || (thisTileLuminosity.nonZero() && thisWall == AIR)) {
|
if ((thisTerrain == AIR && thisWall == AIR) || (thisTileLuminosity.nonZero() && thisWall == AIR)) {
|
||||||
lightLevelThis.set(sunLight)
|
lightLevelThis = sunLight
|
||||||
}
|
}
|
||||||
|
|
||||||
// blend lantern
|
// blend lantern
|
||||||
lightLevelThis.maxAndAssign(thisTileLuminosity).maxAndAssign(lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: colourNull)
|
lightLevelThis = lightLevelThis.max(thisTileLuminosity).max(lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: colourNull)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +499,7 @@ object LightmapRenderer {
|
|||||||
/**
|
/**
|
||||||
* Calculates the light simulation, using main lightmap as one of the input.
|
* 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
|
if (inNoopMask(x, y)) return
|
||||||
|
|
||||||
@@ -517,32 +517,27 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// will "overwrite" what's there in the lightmap if it's the first pass
|
// will "overwrite" what's there in the lightmap if it's the first pass
|
||||||
// takes about 2 ms on 6700K
|
// takes about 2 ms on 6700K
|
||||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, thisTileOpacity2))
|
/* + */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, thisTileOpacity2))
|
/* + */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x + 1, y - 1) ?: colourNull, thisTileOpacity2))
|
||||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, thisTileOpacity2))
|
/* + */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||||
/* + */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, thisTileOpacity2))
|
/* + */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x + 1, y + 1) ?: colourNull, thisTileOpacity2))
|
||||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity))
|
/* * */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x, y - 1) ?: colourNull, thisTileOpacity))
|
||||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity))
|
/* * */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x, y + 1) ?: colourNull, thisTileOpacity))
|
||||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity))
|
/* * */lightLevelThis = lightLevelThis.max(darkenColoured(getLightInternal(x - 1, y) ?: colourNull, thisTileOpacity))
|
||||||
/* * */lightLevelThis.maxAndAssign(darkenColoured(getLightInternal(x + 1, y) ?: colourNull, thisTileOpacity))
|
/* * */lightLevelThis = 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
|
//return lightLevelThis.cpy() // it HAS to be a cpy(), otherwise all cells gets the same instance
|
||||||
setLightOf(lightmap, x, y, lightLevelThis.cpy())
|
setLightOf(lightmap, x, y, lightLevelThis)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
val l = getLightInternal(x, y)
|
||||||
if (l == null) return null
|
if (l == null) return null
|
||||||
|
|
||||||
// brighten if solid
|
// brighten if solid
|
||||||
if (BlockCodex[world.getTileFromTerrain(x, y)].isSolid) {
|
if (BlockCodex[world.getTileFromTerrain(x, y)].isSolid) {
|
||||||
return Color(
|
return l * 1.2f
|
||||||
(l.r * 1.2f),
|
|
||||||
(l.g * 1.2f),
|
|
||||||
(l.b * 1.2f),
|
|
||||||
(l.a * 1.2f)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return l
|
return l
|
||||||
@@ -551,8 +546,7 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
var lightBuffer: Pixmap = Pixmap(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
private val colourNull = Color(0)
|
private val colourNull = Cvec()
|
||||||
private val epsilon = 1f/1024f
|
|
||||||
|
|
||||||
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
@@ -568,7 +562,7 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// wipe out beforehand. You DO need this
|
// 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.blending = Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)
|
||||||
lightBuffer.setColor(colourNull)
|
lightBuffer.setColor(0)
|
||||||
lightBuffer.fill()
|
lightBuffer.fill()
|
||||||
|
|
||||||
|
|
||||||
@@ -581,12 +575,11 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
for (x in this_x_start..this_x_end) {
|
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.setColor(color)
|
||||||
|
|
||||||
//lightBuffer.drawPixel(x - this_x_start, y - this_y_start)
|
//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
|
lightBuffer.drawPixel(x - this_x_start, lightBuffer.height - 1 - y + this_y_start) // flip Y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,6 +604,7 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val CVEC_ONE = Cvec(1f)
|
||||||
val lightScalingMagic = 8f
|
val lightScalingMagic = 8f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -620,15 +614,13 @@ object LightmapRenderer {
|
|||||||
* @param darken (0-255) per channel
|
* @param darken (0-255) per channel
|
||||||
* @return darkened data (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
|
// 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)
|
// this function, when done recursively (A_x = darken(A_x-1, C)), draws exponential curve. (R^2 = 1)
|
||||||
|
|
||||||
return Color(
|
// equation: data * (1 - darken * magic)
|
||||||
data.r * (1f - darken.r * lightScalingMagic),//.clampZero(),
|
|
||||||
data.g * (1f - darken.g * lightScalingMagic),//.clampZero(),
|
return data * (CVEC_ONE - darken * lightScalingMagic)
|
||||||
data.b * (1f - darken.b * lightScalingMagic),//.clampZero(),
|
|
||||||
data.a * (1f - darken.a * lightScalingMagic))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -638,13 +630,13 @@ object LightmapRenderer {
|
|||||||
* @param darken (0-255)
|
* @param darken (0-255)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
fun darkenUniformInt(data: Color, darken: Float): Color {
|
/*fun darkenUniformInt(data: Color, darken: Float): Color {
|
||||||
if (darken < 0 || darken > CHANNEL_MAX)
|
if (darken < 0 || darken > CHANNEL_MAX)
|
||||||
throw IllegalArgumentException("darken: out of range ($darken)")
|
throw IllegalArgumentException("darken: out of range ($darken)")
|
||||||
|
|
||||||
val darkenColoured = Color(darken, darken, darken, darken)
|
val darkenColoured = Color(darken, darken, darken, darken)
|
||||||
return darkenColoured(data, darkenColoured)
|
return darkenColoured(data, darkenColoured)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Darken or brighten colour by 'brighten' argument
|
* Darken or brighten colour by 'brighten' argument
|
||||||
@@ -653,26 +645,12 @@ object LightmapRenderer {
|
|||||||
* @param brighten (-1.0 - 1.0) negative means darkening
|
* @param brighten (-1.0 - 1.0) negative means darkening
|
||||||
* @return processed colour
|
* @return processed colour
|
||||||
*/
|
*/
|
||||||
fun alterBrightnessUniform(data: Color, brighten: Float): Color {
|
fun alterBrightnessUniform(data: Cvec, brighten: Float): Cvec {
|
||||||
return Color(
|
// equation = data + brighten
|
||||||
data.r + brighten,
|
|
||||||
data.g + brighten,
|
return data + brighten
|
||||||
data.b + brighten,
|
|
||||||
data.a + brighten
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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
|
private fun Float.inv() = 1f / this
|
||||||
fun Float.floor() = FastMath.floor(this)
|
fun Float.floor() = FastMath.floor(this)
|
||||||
@@ -723,7 +701,7 @@ object LightmapRenderer {
|
|||||||
_init = true
|
_init = true
|
||||||
}
|
}
|
||||||
lightBuffer = Pixmap(tilesInHorizontal, tilesInVertical, Pixmap.Format.RGBA8888)
|
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")
|
printdbg(this, "Resize event")
|
||||||
@@ -797,14 +775,11 @@ 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?
|
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 */
|
/** To eliminated visible edge on the gradient when 255/1023 is exceeded */
|
||||||
internal fun Color.normaliseToHDR() = Color(
|
internal fun Cvec.normaliseToHDR(): Cvec {
|
||||||
hdr(this.r.coerceIn(0f,1f)),
|
// equation: hdr(this.coerceIn)
|
||||||
hdr(this.g.coerceIn(0f,1f)),
|
val arr = this.vec.toArray().map { hdr(it.coerceIn(0f, 1f)) }
|
||||||
hdr(this.b.coerceIn(0f,1f)),
|
return Cvec(arr.toFloatArray())
|
||||||
hdr(this.a.coerceIn(0f,1f))
|
}
|
||||||
)
|
|
||||||
|
|
||||||
private fun Color.nonZero() = this.r + this.g + this.b + this.a > epsilon
|
|
||||||
|
|
||||||
val histogram: Histogram
|
val histogram: Histogram
|
||||||
get() {
|
get() {
|
||||||
@@ -820,10 +795,10 @@ object LightmapRenderer {
|
|||||||
try {
|
try {
|
||||||
//val colour = lightmap[y][x]
|
//val colour = lightmap[y][x]
|
||||||
val colour = lightmap[y * LIGHTMAP_WIDTH + x]
|
val colour = lightmap[y * LIGHTMAP_WIDTH + x]
|
||||||
reds[minOf(CHANNEL_MAX, colour.r.times(MUL).floorInt())] += 1
|
reds[minOf(CHANNEL_MAX, colour.vec.lane(0).times(MUL).floorInt())] += 1
|
||||||
greens[minOf(CHANNEL_MAX, colour.g.times(MUL).floorInt())] += 1
|
greens[minOf(CHANNEL_MAX, colour.vec.lane(1).times(MUL).floorInt())] += 1
|
||||||
blues[minOf(CHANNEL_MAX, colour.b.times(MUL).floorInt())] += 1
|
blues[minOf(CHANNEL_MAX, colour.vec.lane(2).times(MUL).floorInt())] += 1
|
||||||
uvs[minOf(CHANNEL_MAX, colour.a.times(MUL).floorInt())] += 1
|
uvs[minOf(CHANNEL_MAX, colour.vec.lane(3).times(MUL).floorInt())] += 1
|
||||||
}
|
}
|
||||||
catch (e: ArrayIndexOutOfBoundsException) { }
|
catch (e: ArrayIndexOutOfBoundsException) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="FacetManager">
|
<component name="FacetManager">
|
||||||
<facet type="kotlin-language" name="Kotlin">
|
<facet type="kotlin-language" name="Kotlin">
|
||||||
<configuration version="3" platform="JVM 1.8">
|
<configuration version="3" platform="JVM 9">
|
||||||
<compilerSettings />
|
<compilerSettings />
|
||||||
<compilerArguments>
|
<compilerArguments>
|
||||||
<option name="jvmTarget" value="1.8" />
|
<option name="jvmTarget" value="10" />
|
||||||
</compilerArguments>
|
</compilerArguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/net/torvald/terrarum/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/net/torvald/terrarum/tests" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="lib" level="project" />
|
<orderEntry type="library" name="lib" level="project" />
|
||||||
|
|||||||
Reference in New Issue
Block a user