diff --git a/src/net/torvald/dataclass/CircularArray.kt b/src/net/torvald/dataclass/CircularArray.kt index 0f735c2d7..90d57e42d 100644 --- a/src/net/torvald/dataclass/CircularArray.kt +++ b/src/net/torvald/dataclass/CircularArray.kt @@ -11,9 +11,9 @@ package net.torvald.dataclass */ class CircularArray(val size: Int) { - private val buffer: Array = arrayOfNulls(size) as Array - private var tail: Int = 0 - private var head: Int = 0 + val buffer: Array = arrayOfNulls(size) as Array + var tail: Int = 0 + var head: Int = 0 val elemCount: Int get() = if (tail >= head) tail - head else size @@ -26,7 +26,7 @@ class CircularArray(val size: Int) { } } - fun forEach(action: (T) -> Unit) { + inline fun forEach(action: (T) -> Unit) { /*if (tail >= head) { // queue not full (head..tail - 1).map { buffer[it] }.forEach { action(it) } } @@ -45,11 +45,11 @@ class CircularArray(val size: Int) { } } - fun forEachConcurrent(action: (T) -> Unit) { + inline fun forEachConcurrent(action: (T) -> Unit) { TODO() } - fun forEachConcurrentWaitFor(action: (T) -> Unit) { + inline fun forEachConcurrentWaitFor(action: (T) -> Unit) { TODO() } diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index b71cb674e..78ddf0d70 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -61,7 +61,7 @@ class StateInGame : BasicGameState() { var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT! private set - val player: ActorHumanoid? // currently POSSESSED actor :) + inline val player: ActorHumanoid? // currently POSSESSED actor :) get() = playableActorDelegate?.actor var screenZoom = 1.0f @@ -106,12 +106,12 @@ class StateInGame : BasicGameState() { lateinit var uiAlasesPausing: ArrayList private set - var paused: Boolean = false + inline val paused: Boolean get() = uiAlasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmply is always false, which we want /** * Set to false if UI is opened; set to true if UI is closed. */ - var canPlayerControl: Boolean = false + inline val canPlayerControl: Boolean get() = !paused // FIXME temporary behab (block movement if the game is paused or paused by UIs) @Throws(SlickException::class) diff --git a/src/net/torvald/terrarum/console/CommandDict.kt b/src/net/torvald/terrarum/console/CommandDict.kt index 5a9bee6fb..8f445363a 100644 --- a/src/net/torvald/terrarum/console/CommandDict.kt +++ b/src/net/torvald/terrarum/console/CommandDict.kt @@ -47,7 +47,6 @@ object CommandDict { "gsontest" to GsonTest, "tips" to PrintRandomTips, "langtest" to LangTest, - "testgetlight" to TestGetLight, "spawnball" to SpawnPhysTestBall, "spawntorch" to SpawnTikiTorch, "musictest" to MusicTest, diff --git a/src/net/torvald/terrarum/console/TestGetLight.kt b/src/net/torvald/terrarum/console/TestGetLight.kt deleted file mode 100644 index f4a122971..000000000 --- a/src/net/torvald/terrarum/console/TestGetLight.kt +++ /dev/null @@ -1,24 +0,0 @@ -package net.torvald.terrarum.console - -import net.torvald.terrarum.worlddrawer.LightmapRenderer - -/** - * Created by minjaesong on 16-09-07. - */ -internal object TestGetLight : ConsoleCommand { - /** - * Args 0: command given - * Args 1: first argument - * - * e.g. in ```setav mass 74```, zeroth args will be ```setav```. - */ - override fun execute(args: Array) { - val x = args[1].toInt() - val y = args[2].toInt() - val l = LightmapRenderer.getLightRawPos(x, y) - EchoConsole.execute(l.toString()) - } - - override fun printUsage() { - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt index cbf65af91..5c96b1d47 100644 --- a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt @@ -135,7 +135,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) protected var isLeftDown = false protected var isRightDown = false protected var isJumpDown = false - protected val isGamer: Boolean + protected inline val isGamer: Boolean get() = this == Terrarum.ingame!!.player @@ -221,7 +221,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) } } - private val hasController: Boolean + private inline val hasController: Boolean get() = if (isGamer) Terrarum.controller != null else true @@ -318,7 +318,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) if (isJumpDown) { if (!noClip) { if (airJumpingAllowed || - (!airJumpingAllowed && grounded)) { + (!airJumpingAllowed && walledBottom)) { jumping = true } jump() @@ -525,7 +525,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) //println("$this\tsprite current frame: ${sprite!!.currentFrame}") - if (grounded) { + if (walledBottom) { // set anim row if (controllerMoveDelta?.x != 0.0) { sprite?.switchRow(SPRITE_ROW_WALK) diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index e14e7d58e..33c579d58 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -31,8 +31,8 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode /** * Sorted by referenceID. */ - private val itemList = ArrayList() - private val quickBar = Array(10, { null }) // 0: Slot 1, 9: Slot 10 + val itemList = ArrayList() + val quickBar = Array(10, { null }) // 0: Slot 1, 9: Slot 10 init { } @@ -129,7 +129,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode /** * HashMap */ - fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer) + inline fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer) /** * Get capacity of inventory diff --git a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt index efa302765..9ff9d05ea 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt @@ -58,7 +58,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean */ override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double; - val tilewiseHitbox: Hitbox + inline val tilewiseHitbox: Hitbox get() = Hitbox.fromTwoPoints( hitbox.startX.div(TILE_SIZE).floor(), hitbox.startY.div(TILE_SIZE).floor(), @@ -91,7 +91,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean */ /** Apparent scale. Use "avBaseScale" for base scale */ var scale: Double - get() = (actorValue.getAsDouble(AVKey.SCALE) ?: 1.0) * + inline get() = (actorValue.getAsDouble(AVKey.SCALE) ?: 1.0) * (actorValue.getAsDouble(AVKey.SCALEBUFF) ?: 1.0) set(value) { val scaleDelta = value - scale @@ -101,7 +101,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean } @Transient val MASS_LOWEST = 0.1 // Kilograms /** Apparent mass. Use "avBaseMass" for base mass */ - val mass: Double + inline val mass: Double get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT * Math.pow(scale, 3.0) /*set(value) { // use "var avBaseMass: Double" if (value <= 0) @@ -113,7 +113,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean actorValue[AVKey.BASEMASS] = value / Math.pow(scale, 3.0) }*/ - @Transient private val MASS_DEFAULT: Double = 60.0 + @Transient val MASS_DEFAULT: Double = 60.0 /** Valid range: [0, 1] */ var elasticity: Double = 0.0 set(value) { @@ -139,7 +139,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean set(value) { elasticity = 1.0 - value } - get() = 1.0 - elasticity + inline get() = 1.0 - elasticity var density = 1000.0 set(value) { @@ -153,7 +153,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean * Flags and Properties */ - val grounded: Boolean + private inline val grounded: Boolean get() = isPlayerNoClip || (world.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) || world.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP)) @@ -182,7 +182,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean @Transient private val gravitation: Vector2 = world.gravitation @Transient val DRAG_COEFF_DEFAULT = 1.2 /** Drag coefficient. Parachutes have much higher value than bare body (1.2) */ - var dragCoefficient: Double + inline var dragCoefficient: Double get() = actorValue.getAsDouble(AVKey.DRAGCOEFF) ?: DRAG_COEFF_DEFAULT set(value) { if (value < 0) @@ -234,9 +234,9 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean internal var walledBottom = false // UNUSED; only for BasicDebugInfoWindow internal var colliding = false - protected val gameContainer: GameContainer + protected inline val gameContainer: GameContainer get() = Terrarum.appgc - protected val updateDelta: Int + protected inline val updateDelta: Int get() = Terrarum.delta @@ -303,15 +303,15 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean hitbox.translate(dx, dy) } - val centrePosVector: Vector2 + inline val centrePosVector: Vector2 get() = Vector2(hitbox.centeredX, hitbox.centeredY) - val centrePosPoint: Point2d + inline val centrePosPoint: Point2d get() = Point2d(hitbox.centeredX, hitbox.centeredY) - val feetPosVector: Vector2 + inline val feetPosVector: Vector2 get() = Vector2(hitbox.centeredX, hitbox.endY) - val feetPosPoint: Point2d + inline val feetPosPoint: Point2d get() = Point2d(hitbox.centeredX, hitbox.endY) - val feetPosTile: IntArray + inline val feetPosTile: IntArray get() = intArrayOf(tilewiseHitbox.centeredX.floorInt(), tilewiseHitbox.endY.floorInt()) override fun run() = update(gameContainer, updateDelta) @@ -1054,20 +1054,20 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean } }*/ - private val submergedRatio: Double + private inline val submergedRatio: Double get() = submergedHeight / hitbox.height - private val submergedVolume: Double + private inline val submergedVolume: Double get() = submergedHeight * hitbox.width * hitbox.width - private val submergedHeight: Double + private inline val submergedHeight: Double get() = Math.max( getContactingAreaFluid(COLLIDING_LEFT), getContactingAreaFluid(COLLIDING_RIGHT) ).toDouble() - internal val bodyFriction: Double + internal inline val bodyFriction: Double get() { var friction = 0.0 forEachOccupyingTileNum { @@ -1078,7 +1078,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return friction } - internal val feetFriction: Double + internal inline val feetFriction: Double get() { var friction = 0.0 forEachFeetTileNum { @@ -1092,7 +1092,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean fun Int.frictionToMult(): Double = this / 16.0 - internal val bodyViscosity: Int + internal inline val bodyViscosity: Int get() { var viscosity = 0 forEachOccupyingTile { @@ -1103,7 +1103,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return viscosity } - internal val feetViscosity: Int + internal inline val feetViscosity: Int get() { var viscosity = 0 forEachFeetTile { @@ -1117,7 +1117,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean fun Int.viscosityToMult(): Double = 16.0 / (16.0 + this) - internal val speedMultByTile: Double + internal inline val speedMultByTile: Double get() { val notSubmergedCap = if (grounded) feetViscosity.viscosityToMult() @@ -1129,7 +1129,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean } /** about get going * for about stopping, see setHorizontalFriction */ - internal val accelMultMovement: Double + internal inline val accelMultMovement: Double get() { if (!isPlayerNoClip) { val notSubmergedAccel = if (grounded) @@ -1148,7 +1148,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean /** * Get highest tile density from occupying tiles, fluid only */ - private val tileDensityFluid: Int + private inline val tileDensityFluid: Int get() { var density = 0 forEachOccupyingTile { @@ -1165,7 +1165,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean * Get highest density (specific gravity) value from tiles that the body occupies. * @return */ - private val tileDensity: Int + private inline val tileDensity: Int get() { var density = 0 forEachOccupyingTile { @@ -1334,7 +1334,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean - private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) { + private inline fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) { val tiles = ArrayList() for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { @@ -1345,7 +1345,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return tiles.forEach(consumer) } - private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) { + private inline fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) { val tileProps = ArrayList() for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { @@ -1356,7 +1356,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return tileProps.forEach(consumer) } - private fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) { + private inline fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) { val newTilewiseHitbox = Hitbox.fromTwoPoints( hitbox.startX.div(TILE_SIZE).floor(), hitbox.startY.div(TILE_SIZE).floor(), @@ -1374,7 +1374,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return tilePosList.forEach(consumer) } - private fun forEachFeetTileNum(consumer: (Int?) -> Unit) { + private inline fun forEachFeetTileNum(consumer: (Int?) -> Unit) { val tiles = ArrayList() // offset 1 pixel to the down so that friction would work @@ -1387,7 +1387,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean return tiles.forEach(consumer) } - private fun forEachFeetTile(consumer: (BlockProp?) -> Unit) { + private inline fun forEachFeetTile(consumer: (BlockProp?) -> Unit) { val tileProps = ArrayList() // offset 1 pixel to the down so that friction would work @@ -1437,7 +1437,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean @Transient const val COLLISION_KNOCKBACK_GIVER = 4 // mobs @Transient const val COLLISION_KNOCKBACK_TAKER = 5 // benevolent NPCs - @Transient private val TILE_SIZE = FeaturesDrawer.TILE_SIZE + @Transient val TILE_SIZE = FeaturesDrawer.TILE_SIZE private fun div16TruncateToMapWidth(x: Int): Int { if (x < 0) @@ -1472,52 +1472,52 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean /** * Apparent strength. 1 000 is default value */ - val avStrength: Double + internal inline val avStrength: Double get() = (actorValue.getAsDouble(AVKey.STRENGTH) ?: 1000.0) * (actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 1.0) * scale - var avBaseStrength: Double? + internal inline var avBaseStrength: Double? get() = actorValue.getAsDouble(AVKey.STRENGTH) set(value) { actorValue[AVKey.STRENGTH] = value!! } - var avBaseMass: Double + internal inline var avBaseMass: Double get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT set(value) { actorValue[AVKey.BASEMASS] = value } - val avAcceleration: Double + internal inline val avAcceleration: Double get() = actorValue.getAsDouble(AVKey.ACCEL)!! * actorValue.getAsDouble(AVKey.ACCELBUFF)!! * accelMultMovement * scale.sqrt() - val avSpeedCap: Double + internal inline val avSpeedCap: Double get() = actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDBUFF)!! * speedMultByTile * scale.sqrt() } -fun Int.sqr(): Int = this * this -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) -fun Double.ceil() = this.floor() + 1.0 -fun Double.roundInt(): Int = Math.round(this).toInt() -fun Float.roundInt(): Int = Math.round(this) -fun Double.abs() = Math.abs(this) -fun Double.sqr() = this * this -fun Double.sqrt() = Math.sqrt(this) -fun Float.sqrt() = FastMath.sqrt(this) -fun Int.abs() = if (this < 0) -this else this -fun Double.bipolarClamp(limit: Double) = +inline fun Int.sqr(): Int = this * this +inline fun Double.floorInt() = Math.floor(this).toInt() +inline fun Float.floorInt() = FastMath.floor(this) +inline fun Float.floor() = FastMath.floor(this).toFloat() +inline fun Float.ceilInt() = FastMath.ceil(this) +inline fun Double.round() = Math.round(this).toDouble() +inline fun Double.floor() = Math.floor(this) +inline fun Double.ceil() = this.floor() + 1.0 +inline fun Double.roundInt(): Int = Math.round(this).toInt() +inline fun Float.roundInt(): Int = Math.round(this) +inline fun Double.abs() = Math.abs(this) +inline fun Double.sqr() = this * this +inline fun Double.sqrt() = Math.sqrt(this) +inline fun Float.sqrt() = FastMath.sqrt(this) +inline fun Int.abs() = if (this < 0) -this else this +inline fun Double.bipolarClamp(limit: Double) = if (this > 0 && this > limit) limit else if (this < 0 && this < -limit) -limit else this -fun absMax(left: Double, right: Double): Double { +inline fun absMax(left: Double, right: Double): Double { if (left > 0 && right > 0) if (left > right) return left else return right @@ -1532,8 +1532,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 +inline fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr() +inline fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0 fun interpolateLinear(scale: Double, startValue: Double, endValue: Double): Double { if (startValue == endValue) { diff --git a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt index bcffdfe47..e2a42b3f8 100644 --- a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt @@ -71,7 +71,7 @@ open class ProjectileSimple( override fun update(gc: GameContainer, delta: Int) { // hit something and despawn lifetimeCounter += delta - if (grounded || lifetimeCounter >= lifetimeMax || // ccdCollided || + if (walledTop || walledBottom || walledRight || walledLeft || lifetimeCounter >= lifetimeMax || // stuck check BlockCodex[Terrarum.ingame!!.world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid ) { diff --git a/src/net/torvald/terrarum/gameworld/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt index 7ab9661d3..efc3fe487 100644 --- a/src/net/torvald/terrarum/gameworld/WorldTime.kt +++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt @@ -50,38 +50,38 @@ class WorldTime(initTime: Long = 0L) { TIME_T = initTime } - val seconds: Int // 0 - 59 + inline val seconds: Int // 0 - 59 get() = TIME_T.toPositiveInt() % MINUTE_SEC - val minutes: Int // 0 - 59 + inline val minutes: Int // 0 - 59 get() = TIME_T.div(MINUTE_SEC).abs().toInt() % HOUR_MIN - val hours: Int // 0 - 21 + inline val hours: Int // 0 - 21 get() = TIME_T.div(HOUR_SEC).abs().toInt() % HOURS_PER_DAY - val yearlyDays: Int // 0 - 364 + inline val yearlyDays: Int // 0 - 364 get() = (TIME_T.toPositiveInt().div(DAY_LENGTH) % YEAR_DAYS) - val days: Int // 1 - 31 + inline val days: Int // 1 - 31 get() = quarterlyDays + 1 - if (quarterlyMonthOffset == 0) 0 else if (quarterlyMonthOffset == 1) 31 else 61 - val months: Int // 1 - 12 + inline val months: Int // 1 - 12 get() = if (yearlyDays == YEAR_DAYS - 1) 12 else quarter * 3 + 1 + if (quarterlyDays < 31) 0 else if (quarterlyDays < 61) 1 else 2 - val years: Int + inline val years: Int get() = TIME_T.div(YEAR_DAYS * DAY_LENGTH).abs().toInt() + EPOCH_YEAR - val quarter: Int // 0 - 3 + inline val quarter: Int // 0 - 3 get() = if (yearlyDays == YEAR_DAYS - 1) 3 else yearlyDays / QUARTER_LENGTH - val quarterlyDays: Int // 0 - 90(91) + inline val quarterlyDays: Int // 0 - 90(91) get() = if (yearlyDays == YEAR_DAYS - 1) 91 else (yearlyDays % QUARTER_LENGTH) - val quarterlyMonthOffset: Int // 0 - 2 + inline val quarterlyMonthOffset: Int // 0 - 2 get() = months.minus(1) % 3 - val dayOfWeek: Int //0: Mondag-The first day of weekday (0 - 7) + inline val dayOfWeek: Int //0: Mondag-The first day of weekday (0 - 7) get() = if (yearlyDays == YEAR_DAYS - 1) 7 else yearlyDays % 7 var timeDelta: Int = 1 @@ -89,8 +89,8 @@ class WorldTime(initTime: Long = 0L) { field = if (value < 0) 0 else value } - val moonPhase: Double - get() = (TIME_T % LUNAR_CYCLE).toDouble() / LUNAR_CYCLE + inline val moonPhase: Double + get() = (TIME_T.plus(1700000L) % LUNAR_CYCLE).toDouble() / LUNAR_CYCLE @Transient private var realMillisec: Double = 0.0 @Transient private val REAL_SEC_TO_GAME_SECS = 60 @@ -108,7 +108,7 @@ class WorldTime(initTime: Long = 0L) { val MONTH_NAMES_SHORT = arrayOf("Opal", "Obsi", "Gran", "Slat", "Fels", "Hema", "Mala", "Gale", "Lime", "Sand", "Timb", "Moon") - val currentTimeAsGameDate: GameDate + inline val currentTimeAsGameDate: GameDate get() = GameDate(years, yearlyDays) companion object { @@ -166,8 +166,8 @@ class WorldTime(initTime: Long = 0L) { val dayName: String get() = DAY_NAMES[dayOfWeek] - private fun Long.toPositiveInt() = this.and(0x7FFFFFFF).toInt() - private fun Long.abs() = Math.abs(this) + inline fun Long.toPositiveInt() = this.and(0x7FFFFFFF).toInt() + inline fun Long.abs() = Math.abs(this) /** Format: "%A, %d %B %Y %X" */ fun getFormattedTime() = "${getDayNameShort()}, " + diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 22d224471..28b6d4d12 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -150,8 +150,7 @@ class BasicDebugInfoWindow : UICanvas { " (${Terrarum.ingame!!.world.time.getFormattedTime()})") printLineColumn(g, 2, 6, "Mass $ccG${player?.mass}") - printLineColumn(g, 2, 7, "grounded $ccG${player?.grounded}") - printLineColumn(g, 2, 8, "noClip $ccG${player?.noClip}") + printLineColumn(g, 2, 7, "noClip $ccG${player?.noClip}") drawHistogram(g, LightmapRenderer.histogram, diff --git a/src/net/torvald/terrarum/ui/UIBasicNotifier.kt b/src/net/torvald/terrarum/ui/UIBasicNotifier.kt index 9144d1ff7..cacc395b1 100644 --- a/src/net/torvald/terrarum/ui/UIBasicNotifier.kt +++ b/src/net/torvald/terrarum/ui/UIBasicNotifier.kt @@ -17,7 +17,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas { override var openCloseTime: Millisec = 0 private var ELuptimer = 9999 // to make the light turned off by default - private val ELuptime = 5000 + private val ELuptime = 4000 private var ELon = false private var atlas = SpriteSheet(ModMgr.getPath("basegame", "gui/basic_meter_atlas.tga"), width, height) @@ -99,7 +99,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas { if (player != null) { val playerPos = player.tilewiseHitbox - lightLevel = (LightmapRenderer.getLight(playerPos.canonicalX.toInt(), playerPos.canonicalY.toInt()) ?: + lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: Terrarum.ingame!!.world.globalLight ).normaliseToColour() } diff --git a/src/net/torvald/terrarum/ui/UITierOneWatch.kt b/src/net/torvald/terrarum/ui/UITierOneWatch.kt index 16353348c..167f996f8 100644 --- a/src/net/torvald/terrarum/ui/UITierOneWatch.kt +++ b/src/net/torvald/terrarum/ui/UITierOneWatch.kt @@ -18,7 +18,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas { override var openCloseTime: Millisec = 0 private var ELuptimer = 9999 // to make the light turned off by default - private val ELuptime = 5000 + private val ELuptime = 4000 private var ELon = false private var atlas = SpriteSheet(ModMgr.getPath("basegame", "gui/watchface_atlas.tga"), width, height) @@ -71,7 +71,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas { if (player != null) { val playerPos = player.tilewiseHitbox - lightLevel = (LightmapRenderer.getLight(playerPos.canonicalX.toInt(), playerPos.canonicalY.toInt()) ?: + lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: Terrarum.ingame!!.world.globalLight ).normaliseToColour() } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index d29b01435..39c30ee86 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -577,8 +577,7 @@ object BlocksDrawer_NEW { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT) - //inGLMatrixStack { // disabled for debugging: won't hotswap - GL11.glPushMatrix() + inGLMatrixStack { // disabled for debugging: won't hotswap TEST: what if we inline? GL11.glTranslatef(WorldCamera.x.clampTileSize().toFloat() - TILE_SIZEF, WorldCamera.y.clampTileSize().toFloat(), 0f) @@ -594,8 +593,7 @@ object BlocksDrawer_NEW { GL11.glDrawArrays(GL11.GL_QUADS, 0, 4 * VBO_WIDTH * VBO_HEIGHT) - GL11.glPopMatrix() - //} + } } private fun Int.clampTileSize() = this.div(TILE_SIZE).times(TILE_SIZE) @@ -778,7 +776,7 @@ object BlocksDrawer_NEW { fun Float.floor() = FastMath.floor(this) fun Float.ceil() = FastMath.ceil(this) - fun inGLMatrixStack(action: () -> Unit) { + inline fun inGLMatrixStack(action: () -> Unit) { GL11.glPushMatrix() action() GL11.glPopMatrix() diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index 8cb1192b0..f4cd3fc5e 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -57,29 +57,24 @@ object LightmapRenderer { internal var for_y_end: Int = 0 - fun getLightRawPos(x: Int, y: Int) = lightmap[y][x] + //inline fun getLightRawPos(x: Int, y: Int) = lightmap[y][x] fun getLight(x: Int, y: Int): Int? { - /*if (x !in 0..Terrarum.game.map.width - 1 || y !in 0..Terrarum.game.map.height - 1) - // if out of range then - null - else - lightmap[y][x]*/ - try { + if (y - for_y_start + overscan_open in 0..lightmap.lastIndex && + x - for_x_start + overscan_open in 0..lightmap[0].lastIndex) { + return lightmap[y - for_y_start + overscan_open][x - for_x_start + overscan_open] } - catch (e: ArrayIndexOutOfBoundsException) { - return null - } + + return null } fun setLight(x: Int, y: Int, colour: Int) { - //lightmap[y][x] = colour - try { + if (y - for_y_start + overscan_open in 0..lightmap.lastIndex && + x - for_x_start + overscan_open in 0..lightmap[0].lastIndex) { + lightmap[y - for_y_start + overscan_open][x - for_x_start + overscan_open] = colour } - catch (e: ArrayIndexOutOfBoundsException) { - } } fun renderLightMap() { @@ -491,13 +486,13 @@ object LightmapRenderer { * @param darken (0-255) * @return */ - fun darkenUniformInt(data: Int, darken: Int): Int { + fun darkenUniformInt(data: Int, darken: Int): Int { if (darken < 0 || darken > CHANNEL_MAX) throw IllegalArgumentException("darken: out of range ($darken)") val darkenColoured = constructRGBFromInt(darken, darken, darken) return darkenColoured(data, darkenColoured) - } + } /** * Darken or brighten colour by 'brighten' argument @@ -518,19 +513,6 @@ object LightmapRenderer { brightenColoured(data, modifier) } - /** Get each channel from two RGB values, return new RGB that has max value of each channel - * @param rgb - * @param rgb2 - * @return - */ - private infix fun Int.maxBlend(other: Int): Int { - val r1 = this.rawR(); val r2 = other.rawR(); val newR = if (r1 > r2) r1 else r2 - val g1 = this.rawG(); val g2 = other.rawG(); val newG = if (g1 > g2) g1 else g2 - val b1 = this.rawB(); val b2 = other.rawB(); val newB = if (b1 > b2) b1 else b2 - - return constructRGBFromInt(newR, newG, newB) - } - /** * Deprecated: Fuck it, this vittupää just doesn't want to work */ @@ -559,26 +541,43 @@ object LightmapRenderer { return constructRGBFromFloat(newR, newG, newB) } - private infix fun Int.colSub(other: Int) = constructRGBFromInt( - (this.rawR() - other.rawR()).clampChannel() , - (this.rawG() - other.rawG()).clampChannel() , - (this.rawB() - other.rawB()).clampChannel() - ) + /** Get each channel from two RGB values, return new RGB that has max value of each channel + * @param rgb + * @param rgb2 + * @return + */ + private inline infix fun Int.maxBlend(other: Int): Int { + return (if (this.rawR() > other.rawR()) this.rawR() else other.rawR()) * MUL_2 + + (if (this.rawG() > other.rawG()) this.rawG() else other.rawG()) * MUL + + (if (this.rawB() > other.rawB()) this.rawB() else other.rawB()) + } - private infix fun Int.colAdd(other: Int) = constructRGBFromInt( - (this.rawR() + other.rawR()).clampChannel() , - (this.rawG() + other.rawG()).clampChannel() , - (this.rawB() + other.rawB()).clampChannel() - ) + private inline infix fun Int.linMix(other: Int): Int { + return ((this.rawR() + other.rawR()) ushr 1) * MUL_2 + + ((this.rawG() + other.rawG()) ushr 1) * MUL + + ((this.rawB() + other.rawB()) ushr 1) + } - fun Int.rawR() = this / MUL_2 - fun Int.rawG() = this % MUL_2 / MUL - fun Int.rawB() = this % MUL + private inline infix fun Int.colSub(other: Int): Int { + return ((this.rawR() - other.rawR()).clampChannel()) * MUL_2 + + ((this.rawG() - other.rawG()).clampChannel()) * MUL + + ((this.rawB() - other.rawB()).clampChannel()) + } + + private inline infix fun Int.colAdd(other: Int): Int { + return ((this.rawR() + other.rawR()).clampChannel()) * MUL_2 + + ((this.rawG() + other.rawG()).clampChannel()) * MUL + + ((this.rawB() + other.rawB()).clampChannel()) + } + + inline fun Int.rawR() = this / MUL_2 + inline fun Int.rawG() = this % MUL_2 / MUL + inline fun Int.rawB() = this % MUL /** 0.0 - 1.0 for 0-1023 (0.0 - 0.25 for 0-255) */ - fun Int.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT - fun Int.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT - fun Int.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT + inline fun Int.r(): Float = this.rawR() / CHANNEL_MAX_FLOAT + inline fun Int.g(): Float = this.rawG() / CHANNEL_MAX_FLOAT + inline fun Int.b(): Float = this.rawB() / CHANNEL_MAX_FLOAT /** @@ -601,43 +600,33 @@ object LightmapRenderer { return constructRGBFromInt(newR, newG, newB) } - fun constructRGBFromInt(r: Int, g: Int, b: Int): Int { + inline fun constructRGBFromInt(r: Int, g: Int, b: Int): Int { if (r !in 0..CHANNEL_MAX) throw IllegalArgumentException("Red: out of range ($r)") if (g !in 0..CHANNEL_MAX) throw IllegalArgumentException("Green: out of range ($g)") if (b !in 0..CHANNEL_MAX) throw IllegalArgumentException("Blue: out of range ($b)") - return r * MUL_2 + g * MUL + b + + return r * MUL_2 + + g * MUL + + b } - fun constructRGBFromFloat(r: Float, g: Float, b: Float): Int { + inline fun constructRGBFromFloat(r: Float, g: Float, b: Float): Int { if (r < 0 || r > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Red: out of range ($r)") if (g < 0 || g > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Green: out of range ($g)") if (b < 0 || b > CHANNEL_MAX_DECIMAL) throw IllegalArgumentException("Blue: out of range ($b)") - val intR = (r * CHANNEL_MAX).round() - val intG = (g * CHANNEL_MAX).round() - val intB = (b * CHANNEL_MAX).round() - - return constructRGBFromInt(intR, intG, intB) + return (r * CHANNEL_MAX).round() * MUL_2 + + (g * CHANNEL_MAX).round() * MUL + + (b * CHANNEL_MAX).round() } - private infix fun Int.linMix(other: Int): Int { - val r = (this.rawR() + other.rawR()) ushr 1 - val g = (this.rawG() + other.rawG()) ushr 1 - val b = (this.rawB() + other.rawB()) ushr 1 - return constructRGBFromInt(r, g, b) - } + inline fun Int.clampZero() = if (this < 0) 0 else this + inline fun Float.clampZero() = if (this < 0) 0f else this + inline fun Int.clampChannel() = if (this < 0) 0 else if (this > CHANNEL_MAX) CHANNEL_MAX else this + inline fun Float.clampOne() = if (this < 0) 0f else if (this > 1) 1f else this + inline fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this - private fun Int.clampZero() = if (this < 0) 0 else this - - private fun Float.clampZero() = if (this < 0) 0f else this - - private fun Int.clampChannel() = if (this < 0) 0 else if (this > CHANNEL_MAX) CHANNEL_MAX else this - - private fun Float.clampOne() = if (this < 0) 0f else if (this > 1) 1f else this - - private fun Float.clampChannel() = if (this > CHANNEL_MAX_DECIMAL) CHANNEL_MAX_DECIMAL else this - - fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y) + inline fun getValueFromMap(x: Int, y: Int): Int? = getLight(x, y) fun getHighestRGB(x: Int, y: Int): Int? { val value = getLight(x, y) if (value == null) @@ -654,33 +643,23 @@ object LightmapRenderer { } } - private fun arithmeticAverage(vararg i: Int): Int { - var sum = 0 - for (k in i.indices) { - sum += i[k] - } - return Math.round(sum / i.size.toFloat()) - } - - private fun Int.clamp256() = if (this > 255) 255 else this - - infix fun Float.powerOf(f: Float) = FastMath.pow(this, f) - private fun Float.sqr() = this * this - private fun Float.sqrt() = FastMath.sqrt(this) - private fun Float.inv() = 1f / this - fun Float.floor() = FastMath.floor(this) - fun Double.floorInt() = Math.floor(this).toInt() - fun Float.round(): Int = Math.round(this) - fun Double.round(): Int = Math.round(this).toInt() - fun Float.ceil() = FastMath.ceil(this) - fun Int.even(): Boolean = this and 1 == 0 - fun Int.odd(): Boolean = this and 1 == 1 - fun Int.normaliseToColour(): Color = Color( + inline infix fun Float.powerOf(f: Float) = FastMath.pow(this, f) + private inline fun Float.sqr() = this * this + private inline fun Float.sqrt() = FastMath.sqrt(this) + private inline fun Float.inv() = 1f / this + inline fun Float.floor() = FastMath.floor(this) + inline fun Double.floorInt() = Math.floor(this).toInt() + inline fun Float.round(): Int = Math.round(this) + inline fun Double.round(): Int = Math.round(this).toInt() + inline fun Float.ceil() = FastMath.ceil(this) + inline fun Int.even(): Boolean = this and 1 == 0 + inline fun Int.odd(): Boolean = this and 1 == 1 + inline fun Int.normaliseToColour(): Color = Color( Math.min(this.rawR(), 256), Math.min(this.rawG(), 256), Math.min(this.rawB(), 256) ) - private val RGB_HDR_LUT = floatArrayOf( // polymonial of 6.0 please refer to work_files/HDRcurveBezierLinIntp.kts + val RGB_HDR_LUT = floatArrayOf( // polymonial of 6.0 please refer to work_files/HDRcurveBezierLinIntp.kts 0.0f,0.0f,0.0020097627f,0.0059880256f,0.009966114f,0.013944201f,0.01792211f,0.021899965f,0.025877733f,0.029855346f,0.033832956f,0.037810322f,0.041787688f,0.045764867f,0.04974198f,0.053718954f, 0.05769581f,0.061672557f,0.065649144f,0.06962565f,0.07360197f,0.07757821f,0.08155425f,0.0855302f,0.08950596f,0.0934816f,0.097457066f,0.101432376f,0.10540755f,0.1093825f,0.11335737f,0.11733195f, 0.12130644f,0.12528068f,0.12925476f,0.13322866f,0.1372023f,0.14117579f,0.14514904f,0.14912204f,0.1530949f,0.15706745f,0.16103975f,0.16501188f,0.1689837f,0.17295523f,0.17692655f,0.1808976f, @@ -747,7 +726,7 @@ object LightmapRenderer { 1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f ) /** To eliminated visible edge on the gradient when 255/1023 is exceeded */ - fun Int.normaliseToColourHDR() = Color( + inline fun Int.normaliseToColourHDR() = Color( RGB_HDR_LUT[this.rawR()], RGB_HDR_LUT[this.rawG()], RGB_HDR_LUT[this.rawB()] diff --git a/work_files/UI/portable_computer_mockup.psd b/work_files/UI/portable_computer_mockup.psd index 7b2884b7b..34ef243b3 100644 --- a/work_files/UI/portable_computer_mockup.psd +++ b/work_files/UI/portable_computer_mockup.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:419174e65ff14673014ab48e6923e73804b49bfac07d5733498323b4ee82bee3 -size 290844 +oid sha256:2366d3b746cefe7edc6912026dc1129b12663299bf7621c7bfa4f42ef683cfc5 +size 308940