removing redundant interface "Visible"

Former-commit-id: 3ecfd08eef27d9035bcc98a4f2a6a2f4f89bab01
Former-commit-id: 08dad158f609d0aaf6f999ea17c120a966f1ada5
This commit is contained in:
Song Minjae
2016-11-14 12:23:39 +09:00
parent 4dd74381a8
commit 0b20869fa4
6 changed files with 39 additions and 40 deletions

View File

@@ -18,7 +18,7 @@ import org.newdawn.slick.Graphics
*
* Created by minjaesong on 16-01-13.
*/
open class ActorWithBody : Actor(), Visible {
open class ActorWithBody : Actor() {
override var referenceID: Int = generateUniqueReferenceID()
override var actorValue: ActorValue = ActorValue()
@@ -26,6 +26,8 @@ open class ActorWithBody : Actor(), Visible {
@Transient internal var sprite: SpriteAnimation? = null
@Transient internal var spriteGlow: SpriteAnimation? = null
internal var drawMode: DrawMode = DrawMode.NORMAL
@Transient private val world: GameWorld = Terrarum.ingame.world
var hitboxTranslateX: Double = 0.0// relative to spritePosX
@@ -39,7 +41,7 @@ open class ActorWithBody : Actor(), Visible {
* * Unit: pixel
* !! external class should not hitbox.set(); use setHitboxDimension() and setPosition()
*/
override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double;
val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double;
@Transient val nextHitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // 52 mantissas ought to be enough for anybody...
/**
@@ -898,7 +900,7 @@ open class ActorWithBody : Actor(), Visible {
private fun updateHitbox() = hitbox.reassign(nextHitbox)
override fun drawGlow(gc: GameContainer, g: Graphics) {
open fun drawGlow(gc: GameContainer, g: Graphics) {
if (isVisible && spriteGlow != null) {
if (!sprite!!.flippedHorizontal()) {
spriteGlow!!.render(g,
@@ -916,8 +918,14 @@ open class ActorWithBody : Actor(), Visible {
}
}
override fun drawBody(gc: GameContainer, g: Graphics) {
open fun drawBody(gc: GameContainer, g: Graphics) {
if (isVisible && sprite != null) {
when (drawMode) {
DrawMode.NORMAL -> blendNormal()
DrawMode.MULTIPLY -> blendMul()
DrawMode.SCREEN -> blendScreen()
}
if (!sprite!!.flippedHorizontal()) {
sprite!!.render(g,
(hitbox.posX - hitboxTranslateX * scale).toFloat(),
@@ -934,11 +942,11 @@ open class ActorWithBody : Actor(), Visible {
}
}
override fun updateGlowSprite(gc: GameContainer, delta: Int) {
open fun updateGlowSprite(gc: GameContainer, delta: Int) {
if (spriteGlow != null) spriteGlow!!.update(delta)
}
override fun updateBodySprite(gc: GameContainer, delta: Int) {
open fun updateBodySprite(gc: GameContainer, delta: Int) {
if (sprite != null) sprite!!.update(delta)
}
@@ -1047,4 +1055,8 @@ fun absMax(left: Double, right: Double): Double {
}
}
fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr()
fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0
fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0
enum class DrawMode {
NORMAL, SCREEN, MULTIPLY
}

View File

@@ -1,19 +0,0 @@
package net.torvald.terrarum.gameactors
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
/**
* Created by minjaesong on 16-01-25.
*/
interface Visible {
val hitbox: Hitbox
fun drawBody(gc: GameContainer, g: Graphics)
fun updateBodySprite(gc: GameContainer, delta: Int)
fun drawGlow(gc: GameContainer, g: Graphics)
fun updateGlowSprite(gc: GameContainer, delta: Int)
}

View File

@@ -46,6 +46,12 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
t["width"] = actor.hitbox.width
t["height"] = actor.hitbox.height
t["mass"] = actor.mass
t["collision_type"] = actor.collisionType
t["strength"] = actor.actorValue.getAsInt(AVKey.STRENGTH) ?: 0
val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
val MUL_2 = LightmapRenderer.MUL_2
val MUL = LightmapRenderer.MUL
@@ -53,7 +59,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
t["luminosity_rgb"] = lumrgb
t["luminosity"] = (lumrgb.div(MUL_2).and(CHMAX).times(3) +
lumrgb.div(MUL).and(CHMAX).times(4) +
lumrgb.and(1023)) / 8
lumrgb.and(1023)) / 8 // quick luminosity calculation
return t
}