mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
removing redundant interface "Visible"
Former-commit-id: 3ecfd08eef27d9035bcc98a4f2a6a2f4f89bab01 Former-commit-id: 08dad158f609d0aaf6f999ea17c120a966f1ada5
This commit is contained in:
@@ -299,7 +299,7 @@ constructor() : BasicGameState() {
|
||||
// draw actors //
|
||||
/////////////////
|
||||
actorContainer.forEach { actor ->
|
||||
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||
actor.drawBody(gc, actorsDrawFrameBuffer.graphics)
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ constructor() : BasicGameState() {
|
||||
// draw actor glows //
|
||||
//////////////////////
|
||||
actorContainer.forEach { actor ->
|
||||
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||
actor.drawGlow(gc, actorsDrawFrameBuffer.graphics)
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,7 @@ constructor() : BasicGameState() {
|
||||
// draw reference ID if debugWindow is open
|
||||
if (debugWindow.isVisible) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is Visible) {
|
||||
if (actor is ActorWithBody) {
|
||||
actorsDrawFrameBuffer.graphics.color = Color.white
|
||||
actorsDrawFrameBuffer.graphics.font = Terrarum.fontSmallNumbers
|
||||
actorsDrawFrameBuffer.graphics.drawString(
|
||||
@@ -463,7 +463,7 @@ constructor() : BasicGameState() {
|
||||
while (i < actorContainerSize) { // loop through actorContainerInactive
|
||||
val actor = actorContainerInactive[i]
|
||||
val actorIndex = i
|
||||
if (actor is Visible && actor.inUpdateRange()) {
|
||||
if (actor is ActorWithBody && actor.inUpdateRange()) {
|
||||
addActor(actor) // duplicates are checked here
|
||||
actorContainerInactive.removeAt(actorIndex)
|
||||
actorContainerSize -= 1
|
||||
@@ -491,7 +491,7 @@ constructor() : BasicGameState() {
|
||||
i-- // array removed 1 elem, so we also decrement counter by 1
|
||||
}
|
||||
// inactivate distant actors
|
||||
else if (actor is Visible && !actor.inUpdateRange()) {
|
||||
else if (actor is ActorWithBody && !actor.inUpdateRange()) {
|
||||
if (actor !is Projectile) { // if it's a projectile, just kill it.
|
||||
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
|
||||
}
|
||||
@@ -533,14 +533,14 @@ constructor() : BasicGameState() {
|
||||
|
||||
fun Double.sqr() = this * this
|
||||
fun Int.sqr() = this * this
|
||||
private fun distToActorSqr(a: Visible, p: ActorWithBody): Double =
|
||||
private fun distToActorSqr(a: ActorWithBody, p: ActorWithBody): Double =
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
||||
/** whether the actor is within screen */
|
||||
private fun Visible.inScreen() = distToActorSqr(this, player) <=
|
||||
private fun ActorWithBody.inScreen() = distToActorSqr(this, player) <=
|
||||
(Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr() +
|
||||
Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.ingame.screenZoom).sqr())
|
||||
/** whether the actor is within update range */
|
||||
private fun Visible.inUpdateRange() = distToActorSqr(this, player) <= ACTOR_UPDATE_RANGE.sqr()
|
||||
private fun ActorWithBody.inUpdateRange() = distToActorSqr(this, player) <= ACTOR_UPDATE_RANGE.sqr()
|
||||
/**
|
||||
* actorContainer extensions
|
||||
*/
|
||||
|
||||
@@ -96,13 +96,13 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
gc.graphics.clear() // clean up any 'dust' in the buffer
|
||||
|
||||
//addState(StateVTTest())
|
||||
addState(StateTestingSandbox())
|
||||
//addState(StateTestingSandbox())
|
||||
//addState(StateSplash())
|
||||
//addState(StateMonitorCheck())
|
||||
//addState(StateFontTester())
|
||||
|
||||
//ingame = StateInGame()
|
||||
//addState(ingame)
|
||||
ingame = StateInGame()
|
||||
addState(ingame)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.torvald.terrarum.tileproperties.TilePropCodex
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.RGB
|
||||
import net.torvald.colourutil.CIELuvUtil.additiveLuv
|
||||
import net.torvald.terrarum.gameactors.Visible
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||
import net.torvald.terrarum.tileproperties.TilePropUtil
|
||||
import org.newdawn.slick.Color
|
||||
@@ -175,7 +175,7 @@ object LightmapRenderer {
|
||||
// scan for luminous actors and store their lighting info to the lanterns
|
||||
lanternMap.clear()
|
||||
Terrarum.ingame.actorContainer.forEach { it ->
|
||||
if (it is Luminous && it is Visible) {
|
||||
if (it is Luminous && it is ActorWithBody) {
|
||||
// put lanterns to the area the luminantBox is occupying
|
||||
for (lightBox in it.lightBoxList) {
|
||||
val lightBoxX = it.hitbox.posX + lightBox.posX
|
||||
|
||||
Reference in New Issue
Block a user