mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
colorutil update, some code cleanup
Former-commit-id: 47b13e7e899dc9151f7a1ae71977ed8d4b403345 Former-commit-id: 136f9c787b76aec75d76535891cf264170bd3b04
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELChUtil.toLCh
|
||||
import net.torvald.colourutil.CIELChUtil.toLab
|
||||
import net.torvald.colourutil.CIELChabUtil.toLCh
|
||||
import net.torvald.colourutil.CIELChabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
@@ -16,7 +17,7 @@ import org.newdawn.slick.Color
|
||||
* Created by minjaesong on 16-09-01.
|
||||
*/
|
||||
|
||||
object CIELChUtil {
|
||||
object CIELChabUtil {
|
||||
|
||||
/** Sweet LCh_ab linear gradient */
|
||||
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
||||
@@ -34,7 +35,7 @@ object CIELChUtil {
|
||||
else
|
||||
newH = FastMath.interpolateLinear(scale, from.h, to.h)
|
||||
|
||||
return CIELCh(newL, newC, newH, newAlpha).toRGB()
|
||||
return CIELCh(newL, newC, newH, newAlpha).toColor()
|
||||
}
|
||||
|
||||
fun CIELab.toLCh(): CIELCh {
|
||||
@@ -58,7 +59,7 @@ object CIELChUtil {
|
||||
}
|
||||
|
||||
fun Color.toLCh() = this.toXYZ().toLab().toLCh()
|
||||
fun CIELCh.toRGB() = this.toLab().toXYZ().toRGB()
|
||||
fun CIELCh.toColor() = this.toLab().toXYZ().toColor()
|
||||
|
||||
/**
|
||||
* @param L : Luminosity in 0.0 - 1.0
|
||||
|
||||
@@ -2,8 +2,9 @@ package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toRawRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIEXYZUtil.toRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
@@ -28,7 +29,7 @@ object CIELabUtil {
|
||||
|
||||
val lab = this.toLab()
|
||||
lab.L *= brighten
|
||||
return lab.toRGB()
|
||||
return lab.toColor()
|
||||
}
|
||||
|
||||
fun Color.darkerLab(scale: Float): Color {
|
||||
@@ -36,7 +37,7 @@ object CIELabUtil {
|
||||
|
||||
val lab = this.toLab()
|
||||
lab.L *= darken
|
||||
return lab.toRGB()
|
||||
return lab.toColor()
|
||||
}
|
||||
|
||||
/** Sweet Lab linear gradient */
|
||||
@@ -48,53 +49,7 @@ object CIELabUtil {
|
||||
val newB = FastMath.interpolateLinear(scale, from.b, to.b)
|
||||
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
|
||||
|
||||
return CIELab(newL, newA, newB, newAlpha).toRGB()
|
||||
}
|
||||
|
||||
fun RGB.toXYZ(): CIEXYZ {
|
||||
val newR = if (r > 0.04045f)
|
||||
((r + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else r / 12.92f
|
||||
val newG = if (g > 0.04045f)
|
||||
((g + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else g / 12.92f
|
||||
val newB = if (b > 0.04045f)
|
||||
((b + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else b / 12.92f
|
||||
|
||||
val x = 0.4124564f * newR + 0.3575761f * newG + 0.1804375f * newB
|
||||
val y = 0.2126729f * newR + 0.7151522f * newG + 0.0721750f * newB
|
||||
val z = 0.0193339f * newR + 0.1191920f * newG + 0.9503041f * newB
|
||||
|
||||
return CIEXYZ(x, y, z, alpha)
|
||||
}
|
||||
|
||||
fun Color.toXYZ(): CIEXYZ = RGB(this).toXYZ()
|
||||
|
||||
fun CIEXYZ.toRawRGB(): RGB {
|
||||
var r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z
|
||||
var g = -0.9692660f * X + 1.8760108f * Y + 0.0415560f * Z
|
||||
var b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z
|
||||
|
||||
if (r > 0.0031308f)
|
||||
r = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
r *= 12.92f
|
||||
if (g > 0.0031308f)
|
||||
g = 1.055f * g.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
g *= 12.92f
|
||||
if (b > 0.0031308f)
|
||||
b = 1.055f * b.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
b *= 12.92f
|
||||
|
||||
return RGB(r, g, b, alpha)
|
||||
}
|
||||
|
||||
fun CIEXYZ.toRGB(): Color {
|
||||
val rgb = this.toRawRGB()
|
||||
return Color(rgb.r, rgb.g, rgb.b, rgb.alpha)
|
||||
return CIELab(newL, newA, newB, newAlpha).toColor()
|
||||
}
|
||||
|
||||
fun CIEXYZ.toLab(): CIELab {
|
||||
@@ -134,20 +89,13 @@ object CIELabUtil {
|
||||
|
||||
fun Color.toLab() = this.toXYZ().toLab()
|
||||
fun RGB.toLab() = this.toXYZ().toLab()
|
||||
fun CIELab.toColor() = this.toXYZ().toColor()
|
||||
fun CIELab.toRGB() = this.toXYZ().toRGB()
|
||||
fun CIELab.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
|
||||
internal val D65 = CIEXYZ(0.95047f, 1.00f, 1.08883f)
|
||||
internal val D65 = CIEXYZ(0.95047f, 1f, 1.08883f)
|
||||
val epsilon = 216f/24389f
|
||||
val kappa = 24389f/27f
|
||||
|
||||
/** Range: X, Y, Z: 0 - 1.0+ (One-based-plus) */
|
||||
data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val alpha: Float = 1f) {
|
||||
init {
|
||||
if (X > 2f || Y > 2f || Z > 2f)
|
||||
throw IllegalArgumentException("Value range error - CIEXYZ is one-based (0.0 - 1.0+): ($X, $Y, $Z)")
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Range:
|
||||
* L: 0-100.0
|
||||
@@ -155,9 +103,4 @@ data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val a
|
||||
* (Hundred-based-plus)
|
||||
*/
|
||||
data class CIELab(var L: Float = 0f, var a: Float = 0f, var b: Float = 0f, val alpha: Float = 1f)
|
||||
/** Range: r, g, b: 0 - 1.0 (One-based) */
|
||||
data class RGB(var r: Float = 0f, var g: Float = 0f, var b: Float = 0f, val alpha: Float = 1f) {
|
||||
constructor(color: Color) : this() {
|
||||
r = color.r; g = color.g; b = color.b
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ package net.torvald.colourutil
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELabUtil.toRawRGB
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIEXYZUtil.toRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELuvUtil.toLuv
|
||||
import net.torvald.colourutil.CIELuvUtil.toXYZ
|
||||
|
||||
@@ -25,7 +26,7 @@ object CIELuvUtil {
|
||||
|
||||
val luv = this.toLuv()
|
||||
luv.L *= brighten
|
||||
return luv.toRGB()
|
||||
return luv.toColor()
|
||||
}
|
||||
|
||||
fun Color.darkerLuv(scale: Float): Color {
|
||||
@@ -33,7 +34,7 @@ object CIELuvUtil {
|
||||
|
||||
val luv = this.toLuv()
|
||||
luv.L *= darken
|
||||
return luv.toRGB()
|
||||
return luv.toColor()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ object CIELuvUtil {
|
||||
val newU = thisLuv.u.times(otherLuv.L / newL) + otherLuv.u.times(otherLuv.L).times(1f - thisLuv.L).div(newL)
|
||||
val newV = thisLuv.v.times(otherLuv.L / newL) + otherLuv.v.times(otherLuv.L).times(1f - thisLuv.L).div(newL)
|
||||
|
||||
return CIELuv(newL, newU, newV).toRawRGB()
|
||||
return CIELuv(newL, newU, newV).toRGB()
|
||||
}
|
||||
|
||||
fun CIEXYZ.toLuv(): CIELuv {
|
||||
@@ -98,8 +99,8 @@ object CIELuvUtil {
|
||||
}
|
||||
|
||||
fun Color.toLuv() = this.toXYZ().toLuv()
|
||||
fun CIELuv.toRawRGB() = this.toXYZ().toRawRGB()
|
||||
fun CIELuv.toRGB() = this.toXYZ().toRGB()
|
||||
fun CIELuv.toColor() = this.toXYZ().toColor()
|
||||
|
||||
/**
|
||||
* Range:
|
||||
|
||||
@@ -1,5 +1,111 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-01-12.
|
||||
*/
|
||||
object CIEXYZUtil {
|
||||
fun Color.brighterXYZ(scale: Float): Color {
|
||||
val xyz = this.toXYZ()
|
||||
xyz.X = xyz.X.times(1f + scale).clampOne()
|
||||
xyz.Y = xyz.Y.times(1f + scale).clampOne()
|
||||
xyz.Z = xyz.Z.times(1f + scale).clampOne()
|
||||
return xyz.toColor()
|
||||
}
|
||||
|
||||
fun Color.darkerXYZ(scale: Float): Color {
|
||||
val xyz = this.toXYZ()
|
||||
xyz.X = xyz.X.times(1f - scale).clampOne()
|
||||
xyz.Y = xyz.Y.times(1f - scale).clampOne()
|
||||
xyz.Z = xyz.Z.times(1f - scale).clampOne()
|
||||
return xyz.toColor()
|
||||
}
|
||||
|
||||
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
||||
val from = fromCol.toXYZ()
|
||||
val to = toCol.toXYZ()
|
||||
val newX = FastMath.interpolateLinear(scale, from.X, to.X)
|
||||
val newY = FastMath.interpolateLinear(scale, from.Y, to.Y)
|
||||
val newZ = FastMath.interpolateLinear(scale, from.Z, to.Z)
|
||||
val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha)
|
||||
|
||||
return CIEXYZ(newX, newY, newZ, newAlpha).toColor()
|
||||
}
|
||||
|
||||
fun Color.toXYZ(): CIEXYZ = RGB(this).toXYZ()
|
||||
|
||||
fun RGB.toXYZ(): CIEXYZ {
|
||||
val newR = if (r > 0.04045f)
|
||||
((r + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else r / 12.92f
|
||||
val newG = if (g > 0.04045f)
|
||||
((g + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else g / 12.92f
|
||||
val newB = if (b > 0.04045f)
|
||||
((b + 0.055f) / 1.055f).powerOf(2.4f)
|
||||
else b / 12.92f
|
||||
|
||||
val x = 0.4124564f * newR + 0.3575761f * newG + 0.1804375f * newB
|
||||
val y = 0.2126729f * newR + 0.7151522f * newG + 0.0721750f * newB
|
||||
val z = 0.0193339f * newR + 0.1191920f * newG + 0.9503041f * newB
|
||||
|
||||
return CIEXYZ(x, y, z, alpha)
|
||||
}
|
||||
|
||||
fun CIEXYZ.toRGB(): RGB {
|
||||
var r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z
|
||||
var g = -0.9692660f * X + 1.8760108f * Y + 0.0415560f * Z
|
||||
var b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z
|
||||
|
||||
if (r > 0.0031308f)
|
||||
r = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
r *= 12.92f
|
||||
if (g > 0.0031308f)
|
||||
g = 1.055f * g.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
g *= 12.92f
|
||||
if (b > 0.0031308f)
|
||||
b = 1.055f * b.powerOf(1f / 2.4f) - 0.055f
|
||||
else
|
||||
b *= 12.92f
|
||||
|
||||
return RGB(r, g, b, alpha)
|
||||
}
|
||||
|
||||
fun CIEXYZ.toColor(): Color {
|
||||
val rgb = this.toRGB()
|
||||
return Color(rgb.r, rgb.g, rgb.b, rgb.alpha)
|
||||
}
|
||||
|
||||
fun colourTempToXYZ(temp: Float, Y: Float): CIEXYZ {
|
||||
val x = if (temp < 7000)
|
||||
-4607000000f / FastMath.pow(temp, 3f) + 2967800f / FastMath.pow(temp, 2f) + 99.11f / temp + 0.244063f
|
||||
else
|
||||
-2006400000f / FastMath.pow(temp, 3f) + 1901800f / FastMath.pow(temp, 2f) + 247.48f / temp + 0.237040f
|
||||
|
||||
val y = -3f * FastMath.pow(x, 2f) + 2.870f * x - 0.275f
|
||||
|
||||
return CIEXYZ(x * Y / y, Y, (1 - x - y) * Y / y)
|
||||
}
|
||||
|
||||
private fun Float.powerOf(exp: Float) = FastMath.pow(this, exp)
|
||||
private fun Float.clampOne() = if (this > 1f) 1f else if (this < 0f) 0f else this
|
||||
}
|
||||
|
||||
/** Range: X, Y, Z: 0 - 1.0+ (One-based-plus) */
|
||||
data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val alpha: Float = 1f) {
|
||||
init {
|
||||
if (X > 2f || Y > 2f || Z > 2f)
|
||||
throw IllegalArgumentException("Value range error - CIEXYZ is one-based (0.0 - 1.0+): ($X, $Y, $Z)")
|
||||
}
|
||||
}
|
||||
|
||||
/** Range: r, g, b: 0 - 1.0 (One-based) */
|
||||
data class RGB(var r: Float = 0f, var g: Float = 0f, var b: Float = 0f, val alpha: Float = 1f) {
|
||||
constructor(color: Color) : this() {
|
||||
r = color.r; g = color.g; b = color.b
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import net.torvald.terrarum.getPixel
|
||||
import net.torvald.terrarum.weather.toColor
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Image
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
|
||||
/**
|
||||
* RGB-modeled CCT calculator
|
||||
* Created by minjaesong on 16-07-26.
|
||||
*/
|
||||
object ColourTemp {
|
||||
@@ -14,5 +18,12 @@ object ColourTemp {
|
||||
return (K - 1000) / 10
|
||||
}
|
||||
|
||||
operator fun invoke(temp: Int): Color = envOverlayColourmap.getColor(colTempToImagePos(temp), 0)
|
||||
/** returns sRGB-normalised colour */
|
||||
operator fun invoke(temp: Int): Color =
|
||||
envOverlayColourmap.getPixel(colTempToImagePos(temp), 0).toColor()
|
||||
|
||||
/** returns CIExyY-based colour converted to slick.color
|
||||
* @param CIE_Y 0.0 - 1.0+ */
|
||||
operator fun invoke(temp: Float, CIE_Y: Float): Color =
|
||||
CIEXYZUtil.colourTempToXYZ(temp, CIE_Y).toColor()
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.torvald.serialise
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
@@ -15,12 +16,7 @@ object WriteGameMapData {
|
||||
|
||||
val META_FILENAME = "worldinfo1"
|
||||
|
||||
val MAGIC: ByteArray = byteArrayOf(
|
||||
'T'.toByte(),
|
||||
'E'.toByte(),
|
||||
'M'.toByte(),
|
||||
'D'.toByte()
|
||||
)
|
||||
val MAGIC = "TEMD".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
|
||||
val BYTE_NULL: Byte = 0
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.apache.commons.codec.digest.DigestUtils
|
||||
import java.io.FileInputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.*
|
||||
import java.util.*
|
||||
|
||||
@@ -21,12 +22,8 @@ object WriteMeta {
|
||||
|
||||
val META_FILENAME = "world"
|
||||
|
||||
val MAGIC: ByteArray = byteArrayOf(
|
||||
'T'.toByte(),
|
||||
'E'.toByte(),
|
||||
'S'.toByte(),
|
||||
'V'.toByte()
|
||||
)
|
||||
val MAGIC = "TESV".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
|
||||
|
||||
val BYTE_NULL: Byte = 0
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class SpriteAnimation(val parentActor: ActorWithBody) {
|
||||
private set
|
||||
var width: Int = 0
|
||||
private set
|
||||
private var currentFrame = 1
|
||||
private var currentRow = 1
|
||||
private var nFrames: Int = 0
|
||||
private var nRows: Int = 0
|
||||
private var currentFrame = 1 // one-based!
|
||||
private var currentRow = 1 // one-based!
|
||||
private var nFrames: Int = 1
|
||||
private var nRows: Int = 1
|
||||
private var delay = 200
|
||||
private var delta = 0
|
||||
private val looping = true
|
||||
@@ -46,11 +46,14 @@ class SpriteAnimation(val parentActor: ActorWithBody) {
|
||||
* *
|
||||
* @throws SlickException
|
||||
*/
|
||||
@Throws(SlickException::class)
|
||||
fun setSpriteImage(imagePath: String) {
|
||||
spriteImage = SpriteSheet(imagePath, this.width, this.height)
|
||||
}
|
||||
|
||||
fun setSpriteImage(image: Image) {
|
||||
spriteImage = SpriteSheet(image, this.width, this.height)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets animation delay. Will default to 200 if not called.
|
||||
* @param delay in milliseconds
|
||||
@@ -60,10 +63,9 @@ class SpriteAnimation(val parentActor: ActorWithBody) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sprite dimension. This is necessary.
|
||||
* @param w
|
||||
* *
|
||||
* @param h
|
||||
* Sets sprite dimension. This is necessary for this to work.
|
||||
* @param w width of the animation frame
|
||||
* @param h height of the animation frame
|
||||
*/
|
||||
fun setDimension(w: Int, h: Int) {
|
||||
width = w
|
||||
|
||||
@@ -53,14 +53,17 @@ class StateBlurTest : BasicGameState() {
|
||||
g.flush()
|
||||
}
|
||||
|
||||
private val isLE: Boolean
|
||||
get() = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN
|
||||
|
||||
/** three iterations of box blur \simeq gaussian blur */
|
||||
fun fastBoxBlur(from: Image, to: ImageBuffer, radius: Int) {
|
||||
|
||||
/** 0xRRGGBBAA */
|
||||
fun getPixelData(index: Int): Int {
|
||||
val r = from.texture.textureData[4 * index].toUint()
|
||||
val r = from.texture.textureData[4 * index + if (isLE) 0 else 2].toUint()
|
||||
val g = from.texture.textureData[4 * index + 1].toUint()
|
||||
val b = from.texture.textureData[4 * index + 2].toUint()
|
||||
val b = from.texture.textureData[4 * index + if (isLE) 2 else 0].toUint()
|
||||
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
||||
return r.shl(16) or g.shl(8) or b
|
||||
@@ -76,9 +79,9 @@ class StateBlurTest : BasicGameState() {
|
||||
val g = value.ushr(16).and(0xff)
|
||||
val b = value.ushr(8).and(0xff)
|
||||
|
||||
to.rgba[4 * index] = r.toByte()
|
||||
to.rgba[4 * index + if (isLE) 0 else 2] = r.toByte()
|
||||
to.rgba[4 * index + 1] = g.toByte()
|
||||
to.rgba[4 * index + 2] = b.toByte()
|
||||
to.rgba[4 * index + if (isLE) 2 else 0] = b.toByte()
|
||||
}
|
||||
|
||||
if (radius < 1) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import javax.sound.sampled.AudioSystem
|
||||
/**
|
||||
* Created by minjaesong on 16-09-05.
|
||||
*/
|
||||
class StateTestingSandbox : BasicGameState() {
|
||||
class StateTestingLightning : BasicGameState() {
|
||||
|
||||
val lightning_start = Point2d(50.0, 100.0)
|
||||
val lightning_end = Point2d(750.0, 300.0)
|
||||
@@ -48,7 +48,7 @@ class StateTestingSandbox : BasicGameState() {
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_SHIT
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_LIGHTNING_GFX
|
||||
|
||||
|
||||
private var timer = 0
|
||||
@@ -104,10 +104,6 @@ class StateTestingSandbox : BasicGameState() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Graphics.drawLine(p1: Point2d, p2: Point2d) {
|
||||
drawLine(p1.x.toFloat(), p1.y.toFloat(), p2.x.toFloat(), p2.y.toFloat())
|
||||
}
|
||||
|
||||
class LightingBolt(val start: Point2d, val end: Point2d, val segments: Int) {
|
||||
val mainBolt = LinkedList<Point2d>() //Pair<Length, Y-Pos>
|
||||
|
||||
@@ -134,4 +130,8 @@ class LightingBolt(val start: Point2d, val end: Point2d, val segments: Int) {
|
||||
g.drawLine(startpoint, endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
fun Graphics.drawLine(p1: Point2d, p2: Point2d) {
|
||||
drawLine(p1.x.toFloat(), p1.y.toFloat(), p2.x.toFloat(), p2.y.toFloat())
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.torvald.imagefont.GameFontWhite
|
||||
import net.torvald.JsonFetcher
|
||||
import net.torvald.JsonWriter
|
||||
import net.torvald.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarum.gameworld.toUint
|
||||
import org.lwjgl.input.Controllers
|
||||
import org.lwjgl.opengl.*
|
||||
import org.newdawn.slick.*
|
||||
@@ -14,6 +15,7 @@ import org.newdawn.slick.state.StateBasedGame
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.ByteOrder
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.logging.FileHandler
|
||||
@@ -116,11 +118,12 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
gc.graphics.clear() // clean up any 'dust' in the buffer
|
||||
|
||||
//addState(StateVTTest())
|
||||
//addState(StateTestingSandbox())
|
||||
//addState(StateTestingLightning())
|
||||
//addState(StateSplash())
|
||||
//addState(StateMonitorCheck())
|
||||
//addState(StateFontTester())
|
||||
//addState(StateNoiseTexGen())
|
||||
//addState(StateBlurTest())
|
||||
|
||||
ingame = StateInGame()
|
||||
addState(ingame)
|
||||
@@ -219,8 +222,9 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
val STATE_ID_CONFIG_CALIBRATE = 0x11
|
||||
|
||||
val STATE_ID_TEST_FONT = 0x100
|
||||
val STATE_ID_TEST_SHIT = 0x101
|
||||
val STATE_ID_TEST_LIGHTNING_GFX = 0x101
|
||||
val STATE_ID_TEST_TTY = 0x102
|
||||
val STATE_ID_TEST_BLUR = 0x103
|
||||
|
||||
val STATE_ID_TOOL_NOISEGEN = 0x200
|
||||
|
||||
@@ -491,4 +495,33 @@ fun blendDisable() {
|
||||
|
||||
enum class RunningEnvironment {
|
||||
PC, CONSOLE, MOBILE
|
||||
}
|
||||
|
||||
/** @return Intarray(R, G, B, A) */
|
||||
fun Image.getPixel(x: Int, y: Int): IntArray {
|
||||
val textureWidth = this.texture.textureWidth
|
||||
val hasAlpha = this.texture.hasAlpha()
|
||||
|
||||
val offset = (if (hasAlpha) 4 else 3) * (textureWidth * y + x) // 4: # of channels (RGBA)
|
||||
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
||||
return intArrayOf(
|
||||
this.texture.textureData[offset].toUint(),
|
||||
this.texture.textureData[offset + 1].toUint(),
|
||||
this.texture.textureData[offset + 2].toUint(),
|
||||
if (hasAlpha)
|
||||
this.texture.textureData[offset + 3].toUint()
|
||||
else 255
|
||||
)
|
||||
}
|
||||
else {
|
||||
return intArrayOf(
|
||||
this.texture.textureData[offset + 2].toUint(),
|
||||
this.texture.textureData[offset + 1].toUint(),
|
||||
this.texture.textureData[offset].toUint(),
|
||||
if (hasAlpha)
|
||||
this.texture.textureData[offset + 3].toUint()
|
||||
else 255
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -274,8 +274,8 @@ open class ActorWithBody : Actor() {
|
||||
/**
|
||||
* @param w
|
||||
* @param h
|
||||
* @param tx +: translate drawn sprite to LEFT.
|
||||
* @param ty +: translate drawn sprite to DOWN.
|
||||
* @param tx positive: translate drawn sprite to LEFT.
|
||||
* @param ty positive: translate drawn sprite to DOWN.
|
||||
* @see ActorWithBody.drawBody
|
||||
* @see ActorWithBody.drawGlow
|
||||
*/
|
||||
@@ -1180,6 +1180,7 @@ open class ActorWithBody : Actor() {
|
||||
|
||||
fun Double.floorInt() = Math.floor(this).toInt()
|
||||
fun Float.floorInt() = FastMath.floor(this)
|
||||
fun Float.floor() = FastMath.floor(this).toFloat()
|
||||
fun Float.ceilInt() = FastMath.ceil(this)
|
||||
fun Double.round() = Math.round(this).toDouble()
|
||||
fun Double.floor() = Math.floor(this)
|
||||
|
||||
@@ -232,6 +232,9 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
|
||||
if (radius < 0) {
|
||||
return LuaValue.NONE
|
||||
}
|
||||
else if (radius > 8) {
|
||||
throw IllegalArgumentException("Radius too large -- must be 8 or less")
|
||||
}
|
||||
else {
|
||||
val luatable = LuaTable()
|
||||
val feetTilePos = actor.feetPosTile
|
||||
|
||||
@@ -61,7 +61,7 @@ constructor(val UI: UICanvas) {
|
||||
var openCloseCounter: Int = 0
|
||||
|
||||
init {
|
||||
println("[UIHandler] Creating UI '${UI.javaClass.simpleName}'")
|
||||
println("[UIHandler] Creating framebuffer for UI '${UI.javaClass.simpleName}'")
|
||||
|
||||
UIDrawnCanvas = Image(UI.width, UI.height)
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ open class SimpleTextTerminal(
|
||||
Color(0x000000), // 0 black
|
||||
Color(0xffffff), // 1 white
|
||||
Color(0x666666), // 2 dim grey
|
||||
Color(0xcccccc) // 3 bright grey
|
||||
) // THESE ARE THE STANDARD
|
||||
Color(0xcccccc) // 3 bright grey
|
||||
) // THESE ARE THE STANDARD
|
||||
|
||||
val phosphor = if (colour) WHITE7500 else phosphorColour
|
||||
open val colourScreen = if (colour) Color(8, 8, 8) else Color(19, 19, 19)
|
||||
|
||||
@@ -2,11 +2,13 @@ package net.torvald.terrarum.weather
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.JsonFetcher
|
||||
import net.torvald.colourutil.CIELChUtil
|
||||
import net.torvald.colourutil.CIELChabUtil
|
||||
import net.torvald.colourutil.CIEXYZUtil
|
||||
import net.torvald.colourutil.ColourUtil
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.getPixel
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
@@ -19,6 +21,11 @@ import java.util.*
|
||||
/**
|
||||
* Current, next are there for cross-fading two weathers
|
||||
*
|
||||
*
|
||||
* Building a CLUT:
|
||||
* Brightest:Darkest must be "around" 10:1
|
||||
* Is RGBA-formatted (32-bit)
|
||||
*
|
||||
* Created by minjaesong on 16-07-11.
|
||||
*/
|
||||
object WeatherMixer {
|
||||
@@ -110,14 +117,13 @@ object WeatherMixer {
|
||||
val phaseThis: Int = timeInSec / dataPointDistance // x-coord in gradmap
|
||||
val phaseNext: Int = (phaseThis + 1) % image.width
|
||||
|
||||
val colourThis = image.getColor(phaseThis, row)
|
||||
val colourNext = image.getColor(phaseNext, row)
|
||||
val colourThis = image.getPixel(phaseThis, row).toColor()
|
||||
val colourNext = image.getPixel(phaseNext, row).toColor()
|
||||
|
||||
// interpolate R, G and B
|
||||
val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
|
||||
|
||||
//val newCol = ColourUtil.getGradient(scale, colourThis, colourNext)
|
||||
val newCol = CIELChUtil.getGradient(scale, colourThis, colourNext)
|
||||
val newCol = CIELChabUtil.getGradient(scale, colourThis, colourNext)
|
||||
|
||||
/* // very nice monitor code
|
||||
// 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
|
||||
@@ -205,3 +211,5 @@ object WeatherMixer {
|
||||
return BaseModularWeather(globalLight, skybox, classification, extraImages)
|
||||
}
|
||||
}
|
||||
|
||||
fun IntArray.toColor() = Color(this[0], this[1], this[2], this[3])
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
MUL = 40
|
||||
MUL_2 = MUL ** 2
|
||||
MAX_STEP = MUL - 1
|
||||
MAX_F = 39.0
|
||||
|
||||
def getch(eightbit):
|
||||
return int(round(eightbit / 255.0 * MAX_STEP))
|
||||
|
||||
|
||||
def getR(rgb24):
|
||||
return (rgb24 >> 16) & 0xFF
|
||||
def getG(rgb24):
|
||||
return (rgb24 >> 8) & 0xFF
|
||||
def getB(rgb24):
|
||||
return rgb24 & 0xFF
|
||||
|
||||
|
||||
def getR40(raw):
|
||||
return raw / MUL_2
|
||||
def getG40(raw):
|
||||
return (raw % MUL_2) / MUL
|
||||
def getB40(raw):
|
||||
return raw % MUL
|
||||
|
||||
|
||||
def intFromCol(r, g, b):
|
||||
return int(r * MUL_2 + g * MUL + b)
|
||||
def intFromRGB24(r24, g24, b24):
|
||||
roundR = round(r24 / 255.0 * MAX_STEP)
|
||||
roundG = round(g24 / 255.0 * MAX_STEP)
|
||||
roundB = round(b24 / 255.0 * MAX_STEP)
|
||||
return intFromCol(roundR, roundG, roundB)
|
||||
def colFromNum(raw):
|
||||
return getR40(raw), getG40(raw), getB40(raw)
|
||||
def to24B(num):
|
||||
return int((getR40(num)) / MAX_F * 255.0), \
|
||||
int((getG40(num)) / MAX_F * 255.0),\
|
||||
int((getB40(num)) / MAX_F * 255.0)
|
||||
def to24BHex(num):
|
||||
r, g, b = to24B(num)
|
||||
return hex(r)+hex(g)+hex(b)
|
||||
def to24BInt(num):
|
||||
r, g, b = to24B(num)
|
||||
return r << 16 | g << 8 | b
|
||||
|
||||
print(to24BInt(27239))
|
||||
Reference in New Issue
Block a user