Finally fixed CIELabUtil's anomaly; apparently past me was dumb fucking perkeleen vittupää

Former-commit-id: 731df40639ccf1463238f70dd615bd1771eee259
Former-commit-id: fdf00fbe30f876731d9d952b2a65f448b90c7913
This commit is contained in:
Song Minjae
2016-09-05 17:15:51 +09:00
parent 562fc182ad
commit d817c586e9
7 changed files with 86 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ import org.newdawn.slick.Color
object CIELChUtil {
/** Sweet Lch linear gradient */
/** Sweet LCh linear gradient */
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val from = fromCol.toLCh()
val to = toCol.toLCh()

View File

@@ -60,20 +60,20 @@ object CIELabUtil {
}
fun CIEXYZ.toRGB(): Color {
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
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 * r.powerOf(1f / 2.4f) - 0.055f
g = 1.055f * g.powerOf(1f / 2.4f) - 0.055f
else
g *= 12.92f
if (b > 0.0031308f)
b = 1.055f * r.powerOf(1f / 2.4f) - 0.055f
b = 1.055f * b.powerOf(1f / 2.4f) - 0.055f
else
b *= 12.92f

View File

@@ -0,0 +1,34 @@
package net.torvald.terrarum
import net.torvald.colourutil.CIELabUtil.toXYZ
import net.torvald.colourutil.CIELabUtil.toLab
import net.torvald.colourutil.CIELabUtil.toRGB
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.state.BasicGameState
import org.newdawn.slick.state.StateBasedGame
/**
* Created by minjaesong on 16-09-05.
*/
class StateTestingSandbox : BasicGameState() {
val colRGB = Color(0x51621D)
val colAfter1 = colRGB.toXYZ().toRGB()
//val colAfter2 = colRGB.toXYZ().toLab().toXYZ().toRGB()
override fun init(container: GameContainer?, game: StateBasedGame?) {
println("Color:\n$colRGB")
println("Color -> XYZ -> Color:\n$colAfter1")
//println("Color -> XYZ -> Lab -> XYZ -> Color:\n$colAfter2")
}
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getID() = Terrarum.STATE_ID_TEST_SHIT
override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) {
}
}

View File

@@ -99,6 +99,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
gc.graphics.clear() // clean up any 'dust' in the buffer
//addState(StateTestingSandbox())
//addState(StateSplash())
//addState(StateMonitorCheck())
//addState(StateFontTester())
@@ -192,6 +193,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
val STATE_ID_CONFIG_CALIBRATE = 0x11
val STATE_ID_TEST_FONT = 0x100
val STATE_ID_TEST_SHIT = 0x5617
var hasController = false
val CONTROLLER_DEADZONE = 0.1f

View File

@@ -5,8 +5,11 @@ import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 16-08-29.
*/
class ProjectileHoming(type: Int, position: Vector2, velocity: Vector2, luminosity: Int = 0) :
ProjectileSimple(type, position, velocity, luminosity) {
class ProjectileHoming(
type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2, // arriving coord
override var luminosity: Int = 0) : ProjectileSimple(type, fromPoint, toPoint, luminosity) {

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.colourutil.CIELabUtil.brighterLab
import net.torvald.spriteanimation.SpriteAnimation
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
@@ -8,16 +9,20 @@ import org.newdawn.slick.Graphics
import java.util.*
/**
* Simplest projectile.
*
* Created by minjaesong on 16-08-29.
*/
open class ProjectileSimple(
type: Int,
position: Vector2,
velocity: Vector2,
fromPoint: Vector2, // projected coord
toPoint: Vector2, // arriving coord
override var luminosity: Int = 0) : ActorWithBody(), Luminous {
val damage: Int
val displayColour: Color
/** scalar part of velocity */
val speed: Int
/**
* Arguments:
@@ -28,19 +33,35 @@ open class ProjectileSimple(
override val lightBoxList = ArrayList<Hitbox>()
init {
hitbox.set(position.x, position.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels
lightBoxList.add(Hitbox(0.0, 0.0, 2.0, 2.0))
hitbox.set(fromPoint.x, fromPoint.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels
// lightbox sized 8x8 centered to the bullet
lightBoxList.add(Hitbox(-4.0, -4.0, 8.0, 8.0))
this.velocity.set(velocity)
damage = bulletDatabase[type][0] as Int
displayColour = bulletDatabase[type][1] as Color
damage = bulletDatabase[type][OFFSET_DAMAGE] as Int
displayColour = bulletDatabase[type][OFFSET_COL] as Color
isNoSubjectToGrav = bulletDatabase[type][OFFSET_NOGRAVITY] as Boolean
speed = bulletDatabase[type][OFFSET_SPEED] as Int
if (displayColour == Color(254, 0, 0, 0)) {
sprite = bulletDatabase[type][OFFSET_SPRITE] as SpriteAnimation
}
val initVelo = Vector2(speed.toDouble(), 0.0)
initVelo.setDirection((fromPoint to toPoint).direction)
velocity.set(initVelo)
collisionType = KINEMATIC
}
override fun update(gc: GameContainer, delta: Int) {
// hit something and despawn
if (ccdCollided) flagDespawn()
if (ccdCollided || grounded) flagDespawn()
super.update(gc, delta)
}
@@ -59,11 +80,15 @@ open class ProjectileSimple(
}
companion object {
val TYPE_BULLET_BASIC = 0
val OFFSET_DAMAGE = 0
val OFFSET_COL = 1 // set it to Color(254, 0, 0, 0) to use sprite
val OFFSET_NOGRAVITY = 2
val OFFSET_SPEED = 3
val OFFSET_SPRITE = 4
val bulletDatabase = arrayOf(
arrayOf(7, Color(0xFF5429)),
arrayOf(8, Color(0xFF5429))
// damage, display colour, no gravity, speed
arrayOf(7, Color(0xFF5429), true, 50),
arrayOf(8, Color(0xFF5429), true, 50)
// ...
)
}

View File

@@ -86,7 +86,7 @@ object LightmapRenderer {
* * true: overscanning is limited to 8 tiles in width (overscan_opaque)
* * false: overscanning will fully applied to 32 tiles in width (overscan_open)
*/
/*val rect_width = for_x_end - for_x_start
val rect_width = for_x_end - for_x_start
val rect_height_rem_hbars = for_y_end - for_y_start - 2
val noop_mask = BitSet(2 * (rect_width) +
2 * (rect_height_rem_hbars))
@@ -148,11 +148,11 @@ object LightmapRenderer {
// build noop map
for (i in 0..rect_size) {
val point = edgeToMaskNum(i)
val tile = Terrarum.game.map.getTileFromTerrain(point.first, point.second) ?: TileNameCode.NULL
val tile = Terrarum.ingame.world.getTileFromTerrain(point.first, point.second) ?: TileNameCode.NULL
val isSolid = TilePropCodex.getProp(tile).isSolid
noop_mask.set(i, isSolid)
}*/
}
/**
* Updating order: