mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
colorutil update, some code cleanup
Former-commit-id: 47b13e7e899dc9151f7a1ae71977ed8d4b403345 Former-commit-id: 136f9c787b76aec75d76535891cf264170bd3b04
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user