diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 3058433f8..24ee1a052 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -4,6 +4,9 @@ - + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 2c55e21aa..bfa906295 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -38,7 +38,7 @@ - + \ No newline at end of file diff --git a/assets/graphics/circle_512.tga b/assets/graphics/circle_512.tga new file mode 100644 index 000000000..c87ba2794 --- /dev/null +++ b/assets/graphics/circle_512.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:669f7aa334eac94a2dc03781eaa899de42de0c2a7ccd9d6e3285f97866e82c5d +size 1048620 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga index 9ebc7f1c1..759c376f9 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtA_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a2409045e7c639c04f43be989ed3d78c2bbb50121a069403a558e1781134cc08 +oid sha256:fa7ae9e01fb6d6d5566fce7430c28399499e9c6f4f3991df2299e3b5f4cf7d73 size 163884 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga index 1ff7dfba9..c8de6a8b7 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/LatinExtB_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ad0a7c9ad92ddfdf268f77ec47f5e056174730518689c2540bd80795096717bc +oid sha256:5f8e9a4dfaeee8f617f076b0f738c49ffb07e9804c4a8a68f3981d9871775c81 size 266284 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga index 3547356bc..b7c503dbe 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_bulgarian_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c1640dd83ed0769dd8f58105fb360990f3252e8c83997f8357864d74151738b9 -size 389164 +oid sha256:e822a1af84fab5ae35878b834a5d75a368b9c3eb9ad5360e4b41baa85c906991 +size 122924 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga index d8b9594d7..e2e5bb78b 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_serbian_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ccb7284e79124b69cdbb18fefad8546103313694b9769ec206d92e0c3f12f919 -size 389164 +oid sha256:e1d62f47acd0ecad148612ed07b732f50bdcc0e21e9dfaa0bc35eae8390dc346 +size 122924 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga index bef5d99b7..f70516d5a 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/cyrilic_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b99a942250f176fe695215ea9a452034e4eba778d76beb3b75e3c9a97e73e407 +oid sha256:1345ff1d34e23f1bc3adcf4de2079f893b73719c10b4bce2b79140f3f4546224 size 389164 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/tsalagi_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/tsalagi_variable.tga new file mode 100644 index 000000000..005f3fe6f --- /dev/null +++ b/assets/graphics/fonts/terrarum-sans-bitmap/tsalagi_variable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d629220fa462d24bce18c0e816a42ae94da95ffad5dfe639eda6dd291da16d2 +size 122924 diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga index 3bbfe6f6e..2413c9f1e 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/unipunct_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9dc59291aa88c1eb1dc211f277bf6dcc32e8dab9ba4067962c092adc85f3993f +oid sha256:31e139dde40617e1328c49f3d4adc82983f007f011001e35450037318c28d922 size 122924 diff --git a/assets/mods/basegame/gui/building_maker_toolbox.tga b/assets/mods/basegame/gui/building_maker_toolbox.tga new file mode 100644 index 000000000..f8c9c648e --- /dev/null +++ b/assets/mods/basegame/gui/building_maker_toolbox.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50cb9bd6a929a73cfc83b299da5ef0dc3754ae40f4b9e6ca1ff097316cf56327 +size 8236 diff --git a/assets/mods/basegame/items/testpick.nope b/assets/mods/basegame/items/testpick.nope index 56cb86103..b9e5ea9b3 100644 --- a/assets/mods/basegame/items/testpick.nope +++ b/assets/mods/basegame/items/testpick.nope @@ -4,10 +4,10 @@ */ -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.gameactors.AVKey -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material @@ -60,7 +60,7 @@ class TestPick extends GameItem { int mouseTileY = Terrarum.getMouseTileY() def mousePoint = new Point2d(mouseTileX, mouseTileY) - def actorvalue = Terrarum.ingame.player.actorValue + def actorvalue = Terrarum.ingame.playableActor.actorValue using = true @@ -80,7 +80,7 @@ class TestPick extends GameItem { Terrarum.ingame.world.inflictTerrainDamage( mouseTileX, mouseTileY, - Calculate.pickaxePower(Terrarum.ingame.player, material) * swingDmgToFrameDmg + Calculate.pickaxePower(Terrarum.ingame.playableActor, material) * swingDmgToFrameDmg ) return true @@ -90,7 +90,7 @@ class TestPick extends GameItem { boolean endPrimaryUse(float delta) { using = false // reset action timer to zero - Terrarum.ingame.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0) + Terrarum.ingame.playableActor.actorValue.set(AVKey.__ACTION_TIMER, 0.0) return true } } diff --git a/assets/mods/basegame/weathers/generic_skybox.tga b/assets/mods/basegame/weathers/generic_skybox.tga index 852241f50..9b35a1f34 100644 --- a/assets/mods/basegame/weathers/generic_skybox.tga +++ b/assets/mods/basegame/weathers/generic_skybox.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1670c01d6a38c63f776f1148c36c97746c06ae435ac9bbf40ff005f1b4bf9fba +oid sha256:24c9e5e2eb919f33e326c2f22319d0c769614ab38b01bc9455a4647b667211fa size 3212 diff --git a/lib/TerrarumSansBitmap.jar b/lib/TerrarumSansBitmap.jar index 112d06133..396a142c1 100644 Binary files a/lib/TerrarumSansBitmap.jar and b/lib/TerrarumSansBitmap.jar differ diff --git a/lib/kotlin-reflect.jar b/lib/kotlin-reflect.jar index 2194938dc..b44caf1c4 100755 Binary files a/lib/kotlin-reflect.jar and b/lib/kotlin-reflect.jar differ diff --git a/lib/kotlin-stdlib.jar b/lib/kotlin-stdlib.jar index 7bb6ac304..779e622be 100644 Binary files a/lib/kotlin-stdlib.jar and b/lib/kotlin-stdlib.jar differ diff --git a/src/net/torvald/aa/KDHeapifiedTree.kt b/src/net/torvald/aa/KDHeapifiedTree.kt index 4ca4313ce..799c83fb6 100644 --- a/src/net/torvald/aa/KDHeapifiedTree.kt +++ b/src/net/torvald/aa/KDHeapifiedTree.kt @@ -1,7 +1,7 @@ package net.torvald.aa -import net.torvald.point.Point2d -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.Point2d +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.sqr /** @@ -21,7 +21,7 @@ class KDHeapifiedTree() { private val dimension = 2 private val initialSize = 128 - private val nodes = Array(initialSize, { null }) + private val nodes = Array(initialSize, { null }) private val root: Int = 0 @@ -32,13 +32,13 @@ class KDHeapifiedTree() { private fun Int.getActor() = nodes[this] private fun Int.getLeft() = this * 2 + 1 private fun Int.getRight() = this * 2 + 2 - private fun Int.set(value: ActorWithPhysics?) { nodes[this] = value } - private fun Int.setLeftChild(value: ActorWithPhysics?) { nodes[this.getLeft()] = value } - private fun Int.setRightChild(value: ActorWithPhysics?) { nodes[this.getRight()] = value } + private fun Int.set(value: ActorWBMovable?) { nodes[this] = value } + private fun Int.setLeftChild(value: ActorWBMovable?) { nodes[this.getLeft()] = value } + private fun Int.setRightChild(value: ActorWBMovable?) { nodes[this.getRight()] = value } private val zeroPoint = Point2d(0.0, 0.0) - private fun create(points: List, depth: Int, index: Int): ActorWithPhysics? { + private fun create(points: List, depth: Int, index: Int): ActorWBMovable? { if (points.isEmpty()) { index.set(null) @@ -89,7 +89,7 @@ class KDHeapifiedTree() { private fun expandArray() { val prevNodes = nodes.copyOf() - Array(prevNodes.size * 2, { null }) + Array(prevNodes.size * 2, { null }) create(prevNodes.toList(), 0, 0) } diff --git a/src/net/torvald/colourutil/CIEXYZUtil.kt b/src/net/torvald/colourutil/CIEXYZUtil.kt index 5cb9bf227..eb0c84378 100644 --- a/src/net/torvald/colourutil/CIEXYZUtil.kt +++ b/src/net/torvald/colourutil/CIEXYZUtil.kt @@ -143,18 +143,35 @@ object CIEXYZUtil { } fun CIEXYZ.toRGB(): RGB { - val r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z + val r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z val g = -0.9692660f * X + 1.8760108f * Y + 0.0415560f * Z - val b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z + val b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z return RGB(r, g, b, alpha).unLinearise() } + fun CIEXYZ.toRGBRaw(): RGB { + val r = 3.2404542f * X - 1.5371385f * Y - 0.4985314f * Z + val g = -0.9692660f * X + 1.8760108f * Y + 0.0415560f * Z + val b = 0.0556434f * X - 0.2040259f * Y + 1.0572252f * Z + + return RGB(r, g, b, alpha) + } + fun CIEXYZ.toColor(): Color { val rgb = this.toRGB() return Color(rgb.r, rgb.g, rgb.b, rgb.alpha) } + fun CIEXYZ.toColorRaw(): Color { + val rgb = this.toRGBRaw() + return Color(rgb.r, rgb.g, rgb.b, rgb.alpha) + } + + fun CIEYXY.toXYZ(): CIEXYZ { + return CIEXYZ(x * yy / y, yy, (1f - x - y) * yy / y) + } + fun colourTempToXYZ(temp: Float, Y: Float): CIEXYZ { val x = if (temp < 7000) -4607000000f / FastMath.pow(temp, 3f) + 2967800f / FastMath.pow(temp, 2f) + 99.11f / temp + 0.244063f @@ -187,11 +204,18 @@ object CIEXYZUtil { /** Range: X, Y, Z: 0 - 1.0+ (One-based-plus) */ data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, var alpha: Float = 1f) { init { - if (X > 2f || Y > 2f || Z > 2f) + if (X !in -5f..5f || Y!in -5f..5f || Z !in -5f..5f) throw IllegalArgumentException("Value range error - this version of CIEXYZ is one-based (0.0 - 1.0+): ($X, $Y, $Z)") } } +data class CIEYXY(val yy: Float = 0f, var x: Float = 0f, var y: Float = 0f, var alpha: Float = 1f) { + init { + if (yy < 0f || x < 0f || y < 0f) + throw IllegalArgumentException("Value range error - parametres of YXY cannot be negative: ($yy, $x, $y)") + } +} + /** Range: r, g, b: 0 - 1.0 (One-based) */ data class RGB(var r: Float = 0f, var g: Float = 0f, var b: Float = 0f, var alpha: Float = 1f) { constructor(color: Color) : this() { diff --git a/src/net/torvald/dataclass/ArrayListMap.kt b/src/net/torvald/dataclass/ArrayListMap.kt new file mode 100644 index 000000000..babf8c0cd --- /dev/null +++ b/src/net/torvald/dataclass/ArrayListMap.kt @@ -0,0 +1,134 @@ +package net.torvald.dataclass + +import java.util.function.BiConsumer +import java.util.function.BiFunction +import java.util.function.Function + +/** + * Created by minjaesong on 2018-07-15. + */ +class ArrayListMap : MutableMap { + + private val keysArray = ArrayList() + private val valuesArray = ArrayList() + + override val entries: MutableSet> + get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + + override val size: Int + get() = keysArray.size + + override val values: MutableCollection + get() = valuesArray.toMutableSet() + + override val keys: MutableSet + get() = keysArray.toMutableSet() + + + + override fun containsKey(key: K): Boolean { + return keysArray.contains(key) + } + + override fun containsValue(value: V): Boolean { + return valuesArray.contains(value) + } + + override fun forEach(action: BiConsumer) { + for (i in 0 until size) { + action.accept(keysArray[i], valuesArray[i]) + } + } + + override fun get(key: K): V? { + val index = keysArray.linearSearch(key) + index?.let { + return valuesArray[index] + } + return null + } + + override fun getOrDefault(key: K, defaultValue: V): V { + return get(key) ?: defaultValue + } + + override fun isEmpty(): Boolean { + return size == 0 + } + + + private fun ArrayList.linearSearch(element: K): Int? { + var found = 0 + while (found < keysArray.size) { + if (keysArray[found] == element) + return found + + found++ + } + + return null + } + + override fun put(key: K, value: V): V? { + val index = keysArray.linearSearch(key) + if (index != null) { + val oldValue = valuesArray[index] + valuesArray[index] = value + return oldValue + } + else { + keysArray.add(key) + valuesArray.add(value) + return null + } + } + + override fun clear() { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun compute(key: K, remappingFunction: BiFunction): V? { + return super.compute(key, remappingFunction) + } + + override fun computeIfAbsent(key: K, mappingFunction: Function): V { + return super.computeIfAbsent(key, mappingFunction) + } + + override fun computeIfPresent(key: K, remappingFunction: BiFunction): V? { + return super.computeIfPresent(key, remappingFunction) + } + + override fun merge(key: K, value: V, remappingFunction: BiFunction): V? { + return super.merge(key, value, remappingFunction) + } + + override fun putAll(from: Map) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun putIfAbsent(key: K, value: V): V? { + return super.putIfAbsent(key, value) + } + + override fun remove(key: K): V? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun remove(key: K, value: V): Boolean { + return super.remove(key, value) + } + + override fun replace(key: K, oldValue: V, newValue: V): Boolean { + return super.replace(key, oldValue, newValue) + } + + override fun replace(key: K, value: V): V? { + return super.replace(key, value) + } + + override fun replaceAll(function: BiFunction) { + super.replaceAll(function) + } + +} \ No newline at end of file diff --git a/src/net/torvald/dataclass/Matrix.kt b/src/net/torvald/dataclass/Matrix.kt new file mode 100644 index 000000000..b0f118cca --- /dev/null +++ b/src/net/torvald/dataclass/Matrix.kt @@ -0,0 +1,171 @@ +package net.torvald.dataclass + +/** + * Taken and improved from https://introcs.cs.princeton.edu/java/95linear/Matrix.java.html + * + * Created by minjaesong on 2018-08-01. + */ +class Matrix { + val rows: Int // number of rows; M + val cols: Int // number of columns; N + val data: Array // M-by-N array + + // create M-by-N matrix of 0's + constructor(M: Int, N: Int) { + this.rows = M + this.cols = N + data = Array(M) { DoubleArray(N) } + } + + // create matrix based on 2d array + constructor(data: Array) { + rows = data.size + cols = data[0].size + this.data = Array(rows) { DoubleArray(cols) } + for (i in 0 until rows) + for (j in 0 until cols) + this.data[i][j] = data[i][j] + } + + // copy constructor + private constructor(A: Matrix) : this(A.data) {} + + // swap rows i and j + private fun swap(i: Int, j: Int) { + val temp = data[i] + data[i] = data[j] + data[j] = temp + } + + // create and return the transpose of the invoking matrix + fun transpose(): Matrix { + val A = Matrix(cols, rows) + for (i in 0 until rows) + for (j in 0 until cols) + A.data[j][i] = this.data[i][j] + return A + } + + // return C = A + B + operator fun plus(B: Matrix): Matrix { + val A = this + if (B.rows != A.rows || B.cols != A.cols) throw RuntimeException("Illegal matrix dimensions.") + val C = Matrix(rows, cols) + for (i in 0 until rows) + for (j in 0 until cols) + C.data[i][j] = A.data[i][j] + B.data[i][j] + return C + } + + + // return C = A - B + operator fun minus(B: Matrix): Matrix { + val A = this + if (B.rows != A.rows || B.cols != A.cols) throw RuntimeException("Illegal matrix dimensions.") + val C = Matrix(rows, cols) + for (i in 0 until rows) + for (j in 0 until cols) + C.data[i][j] = A.data[i][j] - B.data[i][j] + return C + } + + // does A = B exactly? + override fun equals(B: Any?): Boolean { + if (B !is Matrix) throw RuntimeException("Not a Matrix.") + + val A = this + if (B.rows != A.rows || B.cols != A.cols) throw RuntimeException("Illegal matrix dimensions.") + for (i in 0 until rows) + for (j in 0 until cols) + if (A.data[i][j] != B.data[i][j]) return false + return true + } + + // return C = A * B + operator fun times(B: Matrix): Matrix { + val A = this + if (A.cols != B.rows) throw RuntimeException("Illegal matrix dimensions.") + val C = Matrix(A.rows, B.cols) + for (i in 0 until C.rows) + for (j in 0 until C.cols) + for (k in 0 until A.cols) + C.data[i][j] += A.data[i][k] * B.data[k][j] + return C + } + + + // return x = A^-1 b, assuming A is square and has full rank + fun solve(rhs: Matrix): Matrix { + if (rows != cols || rhs.rows != cols || rhs.cols != 1) + throw RuntimeException("Illegal matrix dimensions.") + + // create copies of the data + val A = Matrix(this) + val b = Matrix(rhs) + + // Gaussian elimination with partial pivoting + for (i in 0 until cols) { + + // find pivot row and swap + var max = i + for (j in i + 1 until cols) + if (Math.abs(A.data[j][i]) > Math.abs(A.data[max][i])) + max = j + A.swap(i, max) + b.swap(i, max) + + // singular + if (A.data[i][i] == 0.0) throw RuntimeException("Matrix is singular.") + + // pivot within b + for (j in i + 1 until cols) + b.data[j][0] -= b.data[i][0] * A.data[j][i] / A.data[i][i] + + // pivot within A + for (j in i + 1 until cols) { + val m = A.data[j][i] / A.data[i][i] + for (k in i + 1 until cols) { + A.data[j][k] -= A.data[i][k] * m + } + A.data[j][i] = 0.0 + } + } + + // back substitution + val x = Matrix(cols, 1) + for (j in cols - 1 downTo 0) { + var t = 0.0 + for (k in j + 1 until cols) + t += A.data[j][k] * x.data[k][0] + x.data[j][0] = (b.data[j][0] - t) / A.data[j][j] + } + return x + + } + + /** + * for idioms of ```element = mat[row][column]``` + */ + operator fun get(i: Int): DoubleArray = data[i] + + companion object { + + // create and return a random M-by-N matrix with values between 0 and 1 + fun random(M: Int, N: Int): Matrix { + val A = Matrix(M, N) + for (i in 0 until M) + for (j in 0 until N) + A.data[i][j] = Math.random() + return A + } + + // create and return the N-by-N identity matrix + fun identity(N: Int): Matrix { + val I = Matrix(N, N) + for (i in 0 until N) + I.data[i][i] = 1.0 + return I + } + + } +} \ No newline at end of file diff --git a/src/net/torvald/spriteanimation/SpriteAnimation.kt b/src/net/torvald/spriteanimation/SpriteAnimation.kt index 0306573ae..093a9a88d 100644 --- a/src/net/torvald/spriteanimation/SpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/SpriteAnimation.kt @@ -7,10 +7,10 @@ package net.torvald.spriteanimation import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.jme3.math.FastMath -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack -class SpriteAnimation(val parentActor: ActorWithPhysics) { +class SpriteAnimation(val parentActor: ActorWBMovable) { private lateinit var textureRegion: TextureRegionPack diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 8bf00e178..f455f64b7 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -36,7 +36,7 @@ public class AppLoader implements ApplicationListener { } public static final String GAME_NAME = "Terrarum"; - public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2017 Torvald (minjaesong)"; + public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2018 Torvald (minjaesong)"; public static String GAME_LOCALE = System.getProperty("user.language") + System.getProperty("user.country"); private static final String[] localeSimple = {"de", "en", "es", "it"}; // must be sorted!! @@ -64,9 +64,6 @@ public class AppLoader implements ApplicationListener { GAME_LOCALE = value; } } - - - fontGame.reload(value); } @@ -99,8 +96,10 @@ public class AppLoader implements ApplicationListener { appConfig = new LwjglApplicationConfiguration(); appConfig.vSyncEnabled = false; appConfig.resizable = false;//true; - appConfig.width = 1072; - appConfig.height = 742; + //appConfig.width = 1072; // IMAX ratio + //appConfig.height = 742; // IMAX ratio + appConfig.width = 1110; // photographic ratio (1.5:1) + appConfig.height = 740; // photographic ratio (1.5:1) appConfig.backgroundFPS = 9999; appConfig.foregroundFPS = 9999; appConfig.title = GAME_NAME; diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index fe95c93c5..825bab737 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -90,6 +90,8 @@ object DefaultConfig { jsonObject.addProperty("fx3dlut", false) + jsonObject.addProperty("__debug", false) + return jsonObject } diff --git a/src/net/torvald/point/Point2d.kt b/src/net/torvald/terrarum/Point2d.kt similarity index 94% rename from src/net/torvald/point/Point2d.kt rename to src/net/torvald/terrarum/Point2d.kt index ceb2cee9d..e2182bc7b 100644 --- a/src/net/torvald/point/Point2d.kt +++ b/src/net/torvald/terrarum/Point2d.kt @@ -1,7 +1,5 @@ -package net.torvald.point +package net.torvald.terrarum -import net.torvald.terrarum.sqr -import net.torvald.terrarum.sqrt import org.dyn4j.geometry.Vector2 /** diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt index 1ec4b2be6..1949f94c7 100644 --- a/src/net/torvald/terrarum/PostProcessor.kt +++ b/src/net/torvald/terrarum/PostProcessor.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.glutils.FrameBuffer +import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.math.Matrix4 import kotlin.system.measureNanoTime @@ -30,17 +31,13 @@ object PostProcessor { if (textureRegion == null) { textureRegion = TextureRegion(fbo.colorBufferTexture) batch = SpriteBatch() - //camera = OrthographicCamera(AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat()) - - //camera.setToOrtho(true, AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat()) - //camera.update() Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height) } - Terrarum.debugTimers["GFX.PostProcessor"] = measureNanoTime { + Terrarum.debugTimers["Renderer.PostProcessor"] = measureNanoTime { Gdx.gl.glClearColor(.094f, .094f, .094f, 0f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) @@ -48,18 +45,20 @@ object PostProcessor { Gdx.gl.glEnable(GL20.GL_BLEND) Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) - val shader = AppLoader.shaderHicolour - - // no-screen screen renders but the game don't? wtf? + val shader: ShaderProgram? = + if (Terrarum.getConfigBoolean("fxdither")) + AppLoader.shaderHicolour + else + null fbo.colorBufferTexture.bind(0) - shader.begin() - shader.setUniformf("resolution", AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat()) - shader.setUniformMatrix("u_projTrans", projMat) - shader.setUniformi("u_texture", 0) + shader?.begin() + shader?.setUniformf("resolution", AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat()) + shader?.setUniformMatrix("u_projTrans", projMat) + shader?.setUniformi("u_texture", 0) AppLoader.fullscreenQuad.render(shader, GL20.GL_TRIANGLES) - shader.end() + shader?.end() Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 2adaeed37..993eb8c7c 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -12,10 +12,14 @@ import com.badlogic.gdx.utils.GdxRuntimeException import com.google.gson.JsonArray import com.google.gson.JsonPrimitive import com.jme3.math.FastMath +import net.torvald.dataclass.ArrayListMap +import net.torvald.random.HQRNG import net.torvald.terrarum.gameactors.Actor +import net.torvald.terrarum.gameactors.ActorID +import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.imagefont.TinyAlphNum import net.torvald.terrarum.itemproperties.ItemCodex -import net.torvald.terrarum.modulebasegame.IngameRenderer +import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.ui.ConsoleWindow import net.torvald.terrarum.utils.JsonFetcher import net.torvald.terrarum.utils.JsonWriter @@ -27,7 +31,7 @@ import org.lwjgl.BufferUtils import org.lwjgl.input.Controllers import java.io.File import java.io.IOException -import java.util.ArrayList +import java.util.* import java.util.concurrent.locks.Lock import java.util.concurrent.locks.ReentrantLock import javax.swing.JOptionPane @@ -44,7 +48,12 @@ typealias RGBA8888 = Int */ object Terrarum : Screen { - val debugTimers = HashMap() + /** + * All singleplayer "Player" must have this exact reference ID. + */ + const val PLAYER_REF_ID: Int = 0x91A7E2 + + val debugTimers = ArrayListMap() var screenW = 0 var screenH = 0 @@ -209,11 +218,12 @@ object Terrarum : Screen { val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime - lateinit var assetManager: AssetManager + lateinit var assetManager: AssetManager // TODO init { println("$NAME version ${AppLoader.getVERSION_STRING()}") + println("Java Runtime version ${System.getProperty("java.version")}") getDefaultDirectory() @@ -401,26 +411,28 @@ object Terrarum : Screen { //appLoader.setScreen(FuckingWorldRenderer(batch)) } - internal fun setScreen(screen: Screen) { + fun setScreen(screen: Screen) { AppLoader.getINSTANCE().setScreen(screen) } override fun render(delta: Float) { + Terrarum.debugTimers["GDX.delta"] = delta.times(1000_000_000f).toLong() AppLoader.getINSTANCE().screen.render(deltaTime) //GLOBAL_RENDER_TIMER += 1 // moved to AppLoader; global event must be place at the apploader to prevent ACCIDENTAL forgot-to-update type of bug. } override fun pause() { - //appLoader.screen.pause() + AppLoader.getINSTANCE().screen.pause() } override fun resume() { - //appLoader.screen.resume() + AppLoader.getINSTANCE().screen.resume() } override fun dispose() { - //appLoader.screen.dispose() + AppLoader.getINSTANCE().screen.dispose() + fontGame.dispose() fontSmallNumbers.dispose() @@ -439,7 +451,7 @@ object Terrarum : Screen { } override fun hide() { - + AppLoader.getINSTANCE().screen.hide() } override fun resize(width: Int, height: Int) { @@ -456,6 +468,11 @@ object Terrarum : Screen { screenH = height + try { + AppLoader.getINSTANCE().screen.resize(screenW, screenH) + } + catch (e: NullPointerException) { } + // re-calculate fullscreen quad //updateFullscreenQuad(screenW, screenH) @@ -664,6 +681,35 @@ object Terrarum : Screen { get() = Gdx.input.x inline val mouseScreenY: Int get() = Gdx.input.y + + + /** + * Usage: + * + * override var referenceID: Int = generateUniqueReferenceID() + */ + fun generateUniqueReferenceID(renderOrder: Actor.RenderOrder): ActorID { + fun hasCollision(value: ActorID) = + try { + Terrarum.ingame!!.theGameHasActor(value) || + value < ItemCodex.ACTORID_MIN || + value !in when (renderOrder) { + Actor.RenderOrder.BEHIND -> Actor.RANGE_BEHIND + Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE + Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP + Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT + } + } + catch (gameNotInitialisedException: KotlinNullPointerException) { + false + } + + var ret: Int + do { + ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID + } while (hasCollision(ret)) // check for collision + return ret + } } open class IngameInstance(val batch: SpriteBatch) : Screen { @@ -672,7 +718,16 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { val ZOOM_MAXIMUM = 4.0f val ZOOM_MINIMUM = 0.5f - lateinit var consoleHandler: ConsoleWindow + open lateinit var consoleHandler: ConsoleWindow + + open lateinit var world: GameWorld + /** The actor the game is currently allowing you to control. + * + * Most of the time it'd be the "player", but think about the case where you have possessed + * some random actor of the game. Now that actor is now playableActor, the actual gamer's avatar + * (reference ID of 0x91A7E2) (must) stay in the actorContainer, but it's not a playableActor. + */ + open lateinit var playableActor: ActorHumanoid val ACTORCONTAINER_INITIAL_SIZE = 64 val actorContainer = ArrayList(ACTORCONTAINER_INITIAL_SIZE) @@ -760,10 +815,10 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { } } - open /** + /** * Check for duplicates, append actor and sort the list */ - fun addNewActor(actor: Actor) { + open fun addNewActor(actor: Actor) { if (theGameHasActor(actor.referenceID!!)) { throw Error("The actor $actor already exists in the game") } @@ -986,9 +1041,7 @@ inline fun Double.sqrt() = Math.sqrt(this) inline fun Float.sqrt() = FastMath.sqrt(this) inline fun Int.abs() = if (this < 0) -this else this fun Double.bipolarClamp(limit: Double) = - if (this > 0 && this > limit) limit - else if (this < 0 && this < -limit) -limit - else this + this.coerceIn(-limit, limit) fun absMax(left: Double, right: Double): Double { if (left > 0 && right > 0) diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index ce61b8c13..13500a2fa 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.jme3.math.FastMath import net.torvald.random.HQRNG import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameworld.GameWorld @@ -18,10 +19,11 @@ import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.gameactors.* +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.serialise.ReadLayerData import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConRoot -import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.worlddrawer.* import java.io.FileInputStream @@ -48,7 +50,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { private var loadDone = false - private lateinit var demoWorld: GameWorld + private lateinit var demoWorld: GameWorldExtension private lateinit var cameraNodes: FloatArray // camera Y-pos private val cameraAI = object : ActorAI { private val axisMax = 1f @@ -135,23 +137,23 @@ class TitleScreen(val batch: SpriteBatch) : Screen { }) - cameraPlayer = object : HumanoidNPC(demoWorld, cameraAI, born = 0, usePhysics = false, forceAssignRefID = Player.PLAYER_REF_ID) { + cameraPlayer = object : HumanoidNPC(demoWorld, cameraAI, born = 0, usePhysics = false, forceAssignRefID = Terrarum.PLAYER_REF_ID) { init { setHitboxDimension(2, 2, 0, 0) hitbox.setPosition( HQRNG().nextInt(demoWorld.width) * FeaturesDrawer.TILE_SIZE.toDouble(), 0.0 // Y pos: placeholder; camera AI will take it over ) - noClip = true + isNoClip = true } } demoWorld.time.timeDelta = 150 - LightmapRenderer.world = demoWorld - BlocksDrawer.world = demoWorld - FeaturesDrawer.world = demoWorld + //LightmapRenderer.setWorld(demoWorld) + //BlocksDrawer.world = demoWorld + //FeaturesDrawer.world = demoWorld uiMenu = UITitleRemoConRoot() diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 5fd09eb10..98c014d8a 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -137,7 +137,7 @@ class UIItemInventoryElem( override fun keyDown(keycode: Int): Boolean { if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_1..Input.Keys.NUM_0) { - val inventory = (Terrarum.ingame!! as Ingame).player.inventory + val inventory = (Terrarum.ingame!! as Ingame).playableActor.inventory val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1 val currentSlotItem = inventory?.getQuickBar(slot) @@ -167,7 +167,7 @@ class UIItemInventoryElem( // equip da shit val itemEquipSlot = item!!.equipPosition - val player = (Terrarum.ingame!! as Ingame).player + val player = (Terrarum.ingame!! as Ingame).playableActor if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it player.equipItem(item!!) diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index 71ec85b6f..0a43a4d73 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -125,7 +125,7 @@ class UIItemInventoryElemSimple( println("keydown elemgrid") - val inventory = (Terrarum.ingame!! as Ingame).player.inventory + val inventory = (Terrarum.ingame!! as Ingame).playableActor.inventory val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1 val currentSlotItem = inventory.getQuickBar(slot) @@ -157,7 +157,7 @@ class UIItemInventoryElemSimple( // equip da shit val itemEquipSlot = item!!.equipPosition - val player = (Terrarum.ingame!! as Ingame).player + val player = (Terrarum.ingame!! as Ingame).playableActor if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it player.equipItem(item!!) diff --git a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt index c87e73792..a2fa8f2e3 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt @@ -6,10 +6,9 @@ import com.jme3.math.FastMath import net.torvald.random.HQRNG import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Second -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.worlddrawer.LightmapRenderer -import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.modulebasegame.weather.WeatherMixer /** * Created by minjaesong on 2016-06-16. @@ -95,7 +94,7 @@ object BlockPropUtil { fun getDynamicLumFunc(baseLum: Color, type: Int): Color { return when (type) { 1 -> getTorchFlicker(baseLum) - 2 -> (Terrarum.ingame!! as Ingame).world.globalLight.cpy().mul(LightmapRenderer.DIV_FLOAT) // current global light + 2 -> (Terrarum.ingame!!.world).globalLight.cpy().mul(LightmapRenderer.DIV_FLOAT) // current global light 3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).cpy().mul(LightmapRenderer.DIV_FLOAT) // daylight at noon 4 -> getSlowBreath(baseLum) 5 -> getPulsate(baseLum) diff --git a/src/net/torvald/terrarum/blockstats/BlockStats.kt b/src/net/torvald/terrarum/blockstats/BlockStats.kt index df32eb5ac..06801ae9d 100644 --- a/src/net/torvald/terrarum/blockstats/BlockStats.kt +++ b/src/net/torvald/terrarum/blockstats/BlockStats.kt @@ -27,8 +27,8 @@ object BlockStats { // Get stats on no-zoomed screen area. In other words, will behave as if screen zoom were 1.0 // no matter how the screen is zoomed. - val map = (Terrarum.ingame!! as Ingame).world - val player = (Terrarum.ingame!! as Ingame).player + val map = (Terrarum.ingame!!.world) + val player = (Terrarum.ingame!! as Ingame).playableActor val renderWidth = FastMath.ceil(Terrarum.WIDTH.toFloat()) val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat()) diff --git a/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt index c7676171d..b4e136dc7 100644 --- a/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt +++ b/src/net/torvald/terrarum/console/SetGlobalLightOverride.kt @@ -23,7 +23,7 @@ internal object SetGlobalLightOverride : ConsoleCommand { val GL = Color(r, g, b, a) lightOverride = true - (Terrarum.ingame!! as Ingame).world.globalLight = GL + (Terrarum.ingame!!.world).globalLight = GL } catch (e: NumberFormatException) { Echo("Wrong number input.") diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/AVKey.kt b/src/net/torvald/terrarum/gameactors/AVKey.kt similarity index 98% rename from src/net/torvald/terrarum/modulebasegame/gameactors/AVKey.kt rename to src/net/torvald/terrarum/gameactors/AVKey.kt index ee16ce2b8..b76cbfe2a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/AVKey.kt +++ b/src/net/torvald/terrarum/gameactors/AVKey.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.modulebasegame.gameactors +package net.torvald.terrarum.gameactors /** * See [res/raw/Creature_raw_doc.md] for information about raw. diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt similarity index 96% rename from src/net/torvald/terrarum/modulebasegame/gameactors/ActorWithPhysics.kt rename to src/net/torvald/terrarum/gameactors/ActorWBMovable.kt index bb597fd7e..7a719d8a5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWBMovable.kt @@ -1,9 +1,9 @@ -package net.torvald.terrarum.modulebasegame.gameactors +package net.torvald.terrarum.gameactors import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import net.torvald.terrarum.* import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.worlddrawer.FeaturesDrawer @@ -12,12 +12,8 @@ import net.torvald.spriteanimation.SpriteAnimation import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.BlockProp -import net.torvald.terrarum.gameactors.ActorWithBody -import net.torvald.terrarum.gameactors.Controllable -import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameworld.BlockAddress -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import org.dyn4j.geometry.Vector2 @@ -25,7 +21,7 @@ import java.util.* /** - * Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc. + * Actor with body movable. Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc. * Also has all the usePhysics * * @param renderOrder Rendering order (BEHIND, MIDDLE, MIDTOP, FRONT) @@ -34,7 +30,7 @@ import java.util.* * * Created by minjaesong on 2016-01-13. */ -open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) : +open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) : ActorWithBody(renderOrder) { @@ -121,7 +117,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val if (value <= 0) throw IllegalArgumentException("mass cannot be less than or equal to zero.") else if (value < MASS_LOWEST) { - println("[ActorWithPhysics] input too small; using $MASS_LOWEST instead.") + println("[ActorWBMovable] input too small; using $MASS_LOWEST instead.") actorValue[AVKey.BASEMASS] = MASS_LOWEST } @@ -134,7 +130,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val if (value < 0) throw IllegalArgumentException("invalid elasticity value $value; valid elasticity value is [0, 1].") else if (value >= ELASTICITY_MAX) { - println("[ActorWithPhysics] Elasticity were capped to $ELASTICITY_MAX.") + println("[ActorWBMovable] Elasticity were capped to $ELASTICITY_MAX.") field = ELASTICITY_MAX } else @@ -158,7 +154,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val var density = 1000.0 set(value) { if (value < 0) - throw IllegalArgumentException("[ActorWithPhysics] $value: density cannot be negative.") + throw IllegalArgumentException("[ActorWBMovable] $value: density cannot be negative.") field = value } @@ -200,7 +196,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val get() = actorValue.getAsDouble(AVKey.DRAGCOEFF) ?: DRAG_COEFF_DEFAULT set(value) { if (value < 0) - throw IllegalArgumentException("[ActorWithPhysics] drag coefficient cannot be negative.") + throw IllegalArgumentException("[ActorWBMovable] drag coefficient cannot be negative.") actorValue[AVKey.DRAGCOEFF] = value } @@ -274,8 +270,8 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val * @param h * @param tx positive: translate sprite to LEFT. * @param ty positive: translate sprite to DOWN. - * @see ActorWithPhysics.drawBody - * @see ActorWithPhysics.drawGlow + * @see ActorWBMovable.drawBody + * @see ActorWBMovable.drawGlow */ fun setHitboxDimension(w: Int, h: Int, tx: Int, ty: Int) { baseHitboxH = h @@ -340,7 +336,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val if (spriteGlow != null) spriteGlow!!.update(delta) // make NoClip work for player - if (this is Player) { + if (true) {//this == Terrarum.ingame!!.playableActor) { isNoSubjectToGrav = isNoClip || COLLISION_TEST_MODE isNoCollideWorld = isNoClip isNoSubjectToFluidResistance = isNoClip @@ -655,7 +651,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val } when (selfCollisionStatus) { - 0 -> { debug1("[ActorWithPhysics] Contradiction -- collision detected by CCD, but isWalled() says otherwise") } + 0 -> { debug1("[ActorWBMovable] Contradiction -- collision detected by CCD, but isWalled() says otherwise") } 5 -> { zeroX = true } 10 -> { zeroY = true } 15 -> { newHitbox.reassign(sixteenStep[0]); zeroX = true; zeroY = true } @@ -913,23 +909,23 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val val tileY: Int if (side == COLLIDING_LEFT) { tileX = div16TruncateToMapWidth(hitbox.hitboxStart.x.roundInt() - + i + translateX) + + i + translateX) tileY = div16TruncateToMapHeight(hitbox.hitboxEnd.y.roundInt() + translateY) } else if (side == COLLIDING_TOP) { tileX = div16TruncateToMapWidth(hitbox.hitboxStart.x.roundInt() - + i + translateX) + + i + translateX) tileY = div16TruncateToMapHeight(hitbox.hitboxStart.y.roundInt() + translateY) } else if (side == COLLIDING_RIGHT) { tileX = div16TruncateToMapWidth(hitbox.hitboxEnd.x.roundInt() + translateX) tileY = div16TruncateToMapHeight(hitbox.hitboxStart.y.roundInt() - + i + translateY) + + i + translateY) } else if (side == COLLIDING_LEFT) { tileX = div16TruncateToMapWidth(hitbox.hitboxStart.x.roundInt() + translateX) tileY = div16TruncateToMapHeight(hitbox.hitboxStart.y.roundInt() - + i + translateY) + + i + translateY) } else { throw IllegalArgumentException(side.toString() + ": Wrong side input") @@ -1276,8 +1272,15 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val if (x < 0) 0 else if (x >= world.height) world.height - 1 else x - private val isNoClip: Boolean - get() = this is ActorHumanoid && this.isNoClip() + var isNoClip: Boolean = false + set(value) { + field = value + + if (value) { + externalForce.zero() + controllerMoveDelta?.zero() + } + } private val AUTO_CLIMB_RATE: Int get() = Math.min(TILE_SIZE / 8 * Math.sqrt(scale), TILE_SIZE.toDouble()).toInt() @@ -1289,9 +1292,9 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val // warnings if (sprite == null && isVisible) - println("[ActorWithPhysics] Caution: actor ${this.javaClass.simpleName} is visible but the sprite was not set.") + println("[ActorWBMovable] Caution: actor ${this.javaClass.simpleName} is visible but the sprite was not set.") else if (sprite != null && !isVisible) - println("[ActorWithPhysics] Caution: actor ${this.javaClass.simpleName} is invisible but the sprite was given.") + println("[ActorWBMovable] Caution: actor ${this.javaClass.simpleName} is invisible but the sprite was given.") assertPrinted = true } @@ -1301,7 +1304,6 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val } - private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) { val tiles = ArrayList() for (y in hIntTilewiseHitbox.startY.toInt()..hIntTilewiseHitbox.endY.toInt()) { @@ -1411,8 +1413,8 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val private fun div16TruncateToMapWidth(x: Int): Int { if (x < 0) return 0 - else if (x >= (Terrarum.ingame!! as Ingame).world.width shl 4) - return (Terrarum.ingame!! as Ingame).world.width - 1 + else if (x >= Terrarum.ingame!!.world.width shl 4) + return Terrarum.ingame!!.world.width - 1 else return x and 0x7FFFFFFF shr 4 } @@ -1420,8 +1422,8 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val private fun div16TruncateToMapHeight(y: Int): Int { if (y < 0) return 0 - else if (y >= (Terrarum.ingame!! as Ingame).world.height shl 4) - return (Terrarum.ingame!! as Ingame).world.height - 1 + else if (y >= Terrarum.ingame!!.world.height shl 4) + return Terrarum.ingame!!.world.height - 1 else return y and 0x7FFFFFFF shr 4 } diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 8f30610e6..d62ad3a7f 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -1,8 +1,6 @@ package net.torvald.terrarum.gameactors import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.gameactors.Actor -import net.torvald.terrarum.gameactors.Hitbox /** * Actor with visible body diff --git a/src/net/torvald/terrarum/gameactors/Hitbox.kt b/src/net/torvald/terrarum/gameactors/Hitbox.kt index 23146d4bd..3f38194c0 100644 --- a/src/net/torvald/terrarum/gameactors/Hitbox.kt +++ b/src/net/torvald/terrarum/gameactors/Hitbox.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameactors -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import org.dyn4j.geometry.Vector2 /** diff --git a/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt b/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt index fc200364c..0471e2113 100644 --- a/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt +++ b/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt @@ -1,20 +1,11 @@ package net.torvald.terrarum.gameactors.ai -import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.AppLoader -import net.torvald.terrarum.gameactors.AIControlled -import net.torvald.terrarum.modulebasegame.gameactors.AVKey -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics -import net.torvald.terrarum.blockproperties.Block -import net.torvald.terrarum.blockproperties.BlockCodex import org.luaj.vm2.* -import org.luaj.vm2.lib.OneArgFunction -import org.luaj.vm2.lib.ZeroArgFunction /** * Created by minjaesong on 2016-10-24. */ -/*internal class AILuaAPI(g: Globals, actor: ActorWithPhysics) { +/*internal class AILuaAPI(g: Globals, actor: ActorWBMovable) { // FIXME when actor jumps, the actor releases left/right stick @@ -51,9 +42,9 @@ import org.luaj.vm2.lib.ZeroArgFunction companion object { /** - * Reads arbitrary ActorWithPhysics and returns its information as Lua table + * Reads arbitrary ActorWBMovable and returns its information as Lua table */ - fun composeActorObject(actor: ActorWithPhysics): LuaTable { + fun composeActorObject(actor: ActorWBMovable): LuaTable { val t: LuaTable = LuaTable() val moveDelta = actor.externalForce + actor.controllerMoveDelta @@ -80,7 +71,7 @@ import org.luaj.vm2.lib.ZeroArgFunction operator fun LuaTable.set(index: Int, value: Int) { this[index] = value.toLua() } } - class GetSelfActorInfo(val actor: ActorWithPhysics) : ZeroArgFunction() { + class GetSelfActorInfo(val actor: ActorWBMovable) : ZeroArgFunction() { override fun call(): LuaValue { return composeActorObject(actor) } @@ -116,13 +107,13 @@ import org.luaj.vm2.lib.ZeroArgFunction } } - class GetX(val actor: ActorWithPhysics) : ZeroArgFunction() { + class GetX(val actor: ActorWBMovable) : ZeroArgFunction() { override fun call(): LuaValue { return LuaValue.valueOf(actor.hitbox.centeredX) } } - class GetY(val actor: ActorWithPhysics) : ZeroArgFunction() { + class GetY(val actor: ActorWBMovable) : ZeroArgFunction() { override fun call(): LuaValue { return LuaValue.valueOf(actor.hitbox.centeredY) } @@ -205,7 +196,7 @@ import org.luaj.vm2.lib.ZeroArgFunction } } - class GetNearbyTiles(val actor: ActorWithPhysics) : OneArgFunction() { + class GetNearbyTiles(val actor: ActorWBMovable) : OneArgFunction() { /** @param radius * * 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3 @@ -232,7 +223,7 @@ import org.luaj.vm2.lib.ZeroArgFunction luatable[y - feetTilePos[1]] = LuaTable() for (x in feetTilePos[0] - radius..feetTilePos[0] + radius) { - val tile = BlockCodex[(Terrarum.ingame!! as Ingame).world.getTileFromTerrain(x, y) ?: Block.NULL] + val tile = BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(x, y) ?: Block.NULL] val solidity = tile.isSolid.toInt() val liquidity = tile.isFluid.toInt() val gravity = tile.isFallable.toInt() @@ -247,7 +238,7 @@ import org.luaj.vm2.lib.ZeroArgFunction } } - class GetFloorsHeight(val actor: ActorWithPhysics) : OneArgFunction() { + class GetFloorsHeight(val actor: ActorWBMovable) : OneArgFunction() { /** @param radius * * 3 will return len:7 array, 0 will return len:1, 1 will return len:3 @@ -276,7 +267,7 @@ import org.luaj.vm2.lib.ZeroArgFunction // search down var searchDownCounter = 0 while (true) { - val tile = (Terrarum.ingame!! as Ingame).world.getTileFromTerrain(x, feetTilePos[1] + searchDownCounter) ?: Block.STONE + val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] + searchDownCounter) ?: Block.STONE if (BlockCodex[tile].isSolid || searchDownCounter >= searchDownLimit) { luatable[x - feetTilePos[0]] = searchDownCounter break @@ -290,7 +281,7 @@ import org.luaj.vm2.lib.ZeroArgFunction } } - class GetCeilingsHeight(val actor: ActorWithPhysics) : OneArgFunction() { + class GetCeilingsHeight(val actor: ActorWBMovable) : OneArgFunction() { /** @param arg radius * * 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3 @@ -319,7 +310,7 @@ import org.luaj.vm2.lib.ZeroArgFunction // search up var searchUpCounter = 0 while (true) { - val tile = (Terrarum.ingame!! as Ingame).world.getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE + val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE if (BlockCodex[tile].isSolid || searchUpCounter >= searchUpLimit) { luatable[x - feetTilePos[0]] = searchUpCounter break @@ -333,7 +324,7 @@ import org.luaj.vm2.lib.ZeroArgFunction } } - class GetLedgesHeight(val actor: ActorWithPhysics) : OneArgFunction() { + class GetLedgesHeight(val actor: ActorWBMovable) : OneArgFunction() { /** @param arg radius * == * <- (non-solid found) @@ -361,7 +352,7 @@ import org.luaj.vm2.lib.ZeroArgFunction // search up var searchUpCounter = 0 while (true) { - val tile = (Terrarum.ingame!! as Ingame).world.getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE + val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE if (!BlockCodex[tile].isSolid || searchUpCounter >= searchUpLimit) { luatable[x - feetTilePos[0]] = searchUpCounter break diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 65a85cb9e..1929611d0 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -41,14 +41,14 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) if (ingame.canPlayerControl) { if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) { - val itemOnGrip = ingame.player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] + val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] itemOnGrip?.let { if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))) { - ingame.player.consumePrimary(it) + ingame.playableActor.consumePrimary(it) } if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) { - ingame.player.consumeSecondary(it) + ingame.playableActor.consumeSecondary(it) } } } @@ -63,7 +63,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() { override fun keyDown(keycode: Int): Boolean { if (ingame.canPlayerControl) { - ingame.player.keyDown(keycode) + ingame.playableActor.keyDown(keycode) } if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode) @@ -112,7 +112,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { // don't separate Player from this! Physics will break, esp. airborne manoeuvre if (ingame.canPlayerControl) { - val itemOnGrip = ingame.player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] + val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] if (itemOnGrip != null) { if (button == Terrarum.getConfigInt("mouseprimary")) { diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index c4ba2ef72..6f8ad7833 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -4,14 +4,12 @@ package net.torvald.terrarum.gameworld import com.badlogic.gdx.graphics.Color import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.blockproperties.BlockCodex -import net.torvald.terrarum.modulebasegame.gameworld.GameEconomy -import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import org.dyn4j.geometry.Vector2 typealias BlockAddress = Long typealias BlockDamage = Float -class GameWorld(val width: Int, val height: Int) { +open class GameWorld(val width: Int, val height: Int) { //layers @@ -22,7 +20,8 @@ class GameWorld(val width: Int, val height: Int) { val layerWallLowBits: PairedMapLayer val layerTerrainLowBits: PairedMapLayer - val layerThermal: MapLayerFloat // in Kelvins + val layerThermal: MapLayerHalfFloat // in Kelvins + val layerAirPressure: MapLayerHalfFloat // (milibar - 1000) /** Tilewise spawn point */ var spawnX: Int @@ -42,10 +41,6 @@ class GameWorld(val width: Int, val height: Int) { - val time: WorldTime - val economy = GameEconomy() - - var generatorSeed: Long = 0 @@ -61,14 +56,11 @@ class GameWorld(val width: Int, val height: Int) { layerTerrainLowBits = PairedMapLayer(width, height) layerWallLowBits = PairedMapLayer(width, height) - layerThermal = MapLayerFloat(width / 2, height / 2, averageTemperature) + // temperature layer: 2x2 is one cell + layerThermal = MapLayerHalfFloat(width / 2, height / 2, averageTemperature) - - time = WorldTime( - 71 * WorldTime.DAY_LENGTH + - 7 * WorldTime.HOUR_SEC + - 30L * WorldTime.MINUTE_SEC - ) + // air pressure layer: 4 * 8 is one cell + layerAirPressure = MapLayerHalfFloat(width / 4, height / 8, 13f) // 1013 mBar } /** @@ -187,10 +179,6 @@ class GameWorld(val width: Int, val height: Int) { throw IllegalArgumentException("illegal mode input: " + mode.toString()) } - fun updateWorldTime(delta: Float) { - time.update(delta) - } - fun terrainIterator(): Iterator { return object : Iterator { @@ -297,6 +285,11 @@ class GameWorld(val width: Int, val height: Int) { return layerThermal.getValue((worldTileX fmod width) / 2, worldTileY / 2) } + fun getAirPressure(worldTileX: Int, worldTileY: Int): Float? { + return layerAirPressure.getValue((worldTileX fmod width) / 4, worldTileY / 8) + } + + companion object { diff --git a/src/net/torvald/terrarum/gameworld/MapLayer.kt b/src/net/torvald/terrarum/gameworld/MapLayer.kt index 6b65e7de3..0124600a2 100644 --- a/src/net/torvald/terrarum/gameworld/MapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/MapLayer.kt @@ -1,11 +1,9 @@ package net.torvald.terrarum.gameworld -import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.ByteArray64 - /** * Created by minjaesong on 2016-01-17. */ -class MapLayer(val width: Int, val height: Int) : Iterable { +open class MapLayer(val width: Int, val height: Int) : Iterable { internal @Volatile var data: ByteArray // in parallel programming: do not trust your register; always read freshly from RAM! diff --git a/src/net/torvald/terrarum/gameworld/MapLayerFloat.kt b/src/net/torvald/terrarum/gameworld/MapLayerHalfFloat.kt similarity index 95% rename from src/net/torvald/terrarum/gameworld/MapLayerFloat.kt rename to src/net/torvald/terrarum/gameworld/MapLayerHalfFloat.kt index 0a5c99e54..c7955f0c5 100644 --- a/src/net/torvald/terrarum/gameworld/MapLayerFloat.kt +++ b/src/net/torvald/terrarum/gameworld/MapLayerHalfFloat.kt @@ -8,7 +8,7 @@ import net.torvald.dataclass.Float16Bits * * Created by minjaesong on 2017-04-21. */ -class MapLayerFloat(val width: Int, val height: Int) : Iterable { +open class MapLayerHalfFloat(val width: Int, val height: Int) : Iterable { constructor(width: Int, height: Int, init: Float) : this(width, height) { data = Array(height) { Array(width, { Float16.fromFloat(init) }) } diff --git a/src/net/torvald/terrarum/gameworld/MapPoint.kt b/src/net/torvald/terrarum/gameworld/MapPoint.kt index 9677c8a76..ec904ab16 100644 --- a/src/net/torvald/terrarum/gameworld/MapPoint.kt +++ b/src/net/torvald/terrarum/gameworld/MapPoint.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.gameworld -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d class MapPoint { diff --git a/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt index bb394a23f..8c88fb8e3 100644 --- a/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.gameworld /** * Created by minjaesong on 2016-02-15. */ -class PairedMapLayer(width: Int, val height: Int) : Iterable { +open class PairedMapLayer(width: Int, val height: Int) : Iterable { /** * 0b_xxxx_yyyy, x for lower index, y for higher index diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 94da20b5c..8555baba1 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -2,14 +2,11 @@ package net.torvald.terrarum.itemproperties import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.TextureRegion -import net.torvald.point.Point2d import net.torvald.terrarum.KVHashMap import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.worlddrawer.BlocksDrawer -import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE import java.util.* @@ -75,7 +72,7 @@ object ItemCodex { // check for collision with actors (BLOCK only) if (this.inventoryCategory == Category.BLOCK) { ingame.actorContainer.forEach { - if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) + if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint)) return false } } @@ -135,7 +132,7 @@ object ItemCodex { override fun primaryUse(delta: Float): Boolean { val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble()) - val actorvalue = ingame.player.actorValue + val actorvalue = ingame.playableActor.actorValue using = true @@ -143,7 +140,7 @@ object ItemCodex { // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors ingame.actorContainer.forEach { - if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) + if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint)) return false } @@ -158,7 +155,7 @@ object ItemCodex { ingame.world.inflictTerrainDamage( Terrarum.mouseTileX, Terrarum.mouseTileY, - Calculate.pickaxePower(ingame.player, material) * swingDmgToFrameDmg + Calculate.pickaxePower(ingame.playableActor, material) * swingDmgToFrameDmg ) return true } @@ -166,7 +163,7 @@ object ItemCodex { override fun endPrimaryUse(delta: Float): Boolean { using = false // reset action timer to zero - ingame.player.actorValue[AVKey.__ACTION_TIMER] = 0.0 + ingame.playableActor.actorValue[AVKey.__ACTION_TIMER] = 0.0 return true } }*/ diff --git a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt b/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt index 9e0df4b1f..80c27149e 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt @@ -44,13 +44,13 @@ class ItemEffectsLuaAPI(g: Globals) { class StrikeEarth : ThreeArgFunction() { override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue { - (Terrarum.ingame!! as Ingame).world.inflictTerrainDamage(x.checkint(), y.checkint(), power.checkdouble()) + (Terrarum.ingame!!.world).inflictTerrainDamage(x.checkint(), y.checkint(), power.checkdouble()) return LuaValue.NONE } } class StrikeWall : ThreeArgFunction() { override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue { - (Terrarum.ingame!! as Ingame).world.inflictWallDamage(x.checkint(), y.checkint(), power.checkdouble()) + (Terrarum.ingame!!.world).inflictWallDamage(x.checkint(), y.checkint(), power.checkdouble()) return LuaValue.NONE } } diff --git a/src/net/torvald/terrarum/langpack/Lang.kt b/src/net/torvald/terrarum/langpack/Lang.kt index a08af6793..b29e0fa64 100644 --- a/src/net/torvald/terrarum/langpack/Lang.kt +++ b/src/net/torvald/terrarum/langpack/Lang.kt @@ -119,7 +119,12 @@ object Lang { if (key.startsWith("MENU_LABEL_PRESS_START_SYMBOL")) return ret2.replace('>', Terrarum.joypadLabelStart).capitalize() - return ret2.capitalize() + return if (AppLoader.GAME_LOCALE.contains("bg")) + "${AppLoader.fontGame.charsetOverrideBulgarian}${ret2.capitalize()}${AppLoader.fontGame.charsetOverrideNormal}" + else if (AppLoader.GAME_LOCALE.contains("sr")) + "${AppLoader.fontGame.charsetOverrideBulgarian}${ret2.capitalize()}${AppLoader.fontGame.charsetOverrideNormal}" + else + ret2.capitalize() } fun pluraliseLang(key: String, count: Int): String { @@ -210,7 +215,7 @@ object Lang { } private fun isHangul(c: Char): Boolean { - return c.toInt() >= 0xAC00 && c.toInt() <= 0xD7A3 + return c.toInt() in 0xAC00..0xD7A3 } private fun getLastChar(s: String): Char { diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt new file mode 100644 index 000000000..0f5a1c0e4 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -0,0 +1,201 @@ +package net.torvald.terrarum.modulebasegame + +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.IngameInstance +import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.blockproperties.Block +import net.torvald.terrarum.gameactors.* +import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension +import net.torvald.terrarum.modulebasegame.ui.Notification +import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerToolbox +import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.worlddrawer.LightmapRenderer +import net.torvald.terrarum.worlddrawer.WorldCamera +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import kotlin.system.measureNanoTime + +/** + * Created by minjaesong on 2018-07-06. + */ +class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { + + val gameWorld = GameWorldExtension(1024, 256) + + init { + // ghetto world for building + + println("[BuildingMaker] Generating builder world...") + + for (y in 150 until gameWorld.height) { + for (x in 0 until gameWorld.width) { + // wall layer + gameWorld.setTileWall(x, y, Block.DIRT) + + // terrain layer + gameWorld.setTileTerrain(x, y, if (y == 150) Block.GRASS else Block.DIRT) + } + } + + + world = gameWorld + } + + + override var playableActor: ActorHumanoid = MovableWorldCamera(world) + + val uiToolbox = UIBuildingMakerToolbox() + val notifier = Notification() + + val uiContainer = ArrayList() + + val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.FRONT) { + + override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder) + val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16) + override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0) + + override fun drawBody(batch: SpriteBatch) { + batch.color = Color.YELLOW + batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat()) + } + + override fun drawGlow(batch: SpriteBatch) { } + override fun dispose() { + body.dispose() + } + + override fun update(delta: Float) { + hitbox.setPosition( + Terrarum.mouseTileX * 16.0, + Terrarum.mouseTileY * 16.0 + ) + } + + override fun onActorValueChange(key: String, value: Any?) { } + + override fun run() { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + } + + protected var updateDeltaCounter = 0.0 + protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS + + private val actorsRenderTop = ArrayList() + + init { + actorsRenderTop.add(blockPointingCursor) + + uiContainer.add(uiToolbox) + uiContainer.add(notifier) + + + + uiToolbox.setPosition(Terrarum.WIDTH - 20, 4) + notifier.setPosition( + (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height) + + + playableActor.setPosition(512 * 16.0, 149 * 16.0) + + + + LightmapRenderer.fireRecalculateEvent() + } + + override fun render(delta: Float) { + Gdx.graphics.setTitle("${AppLoader.GAME_NAME} Building Maker" + + " — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" + + " — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" + ) + + // ASYNCHRONOUS UPDATE AND RENDER // + + + /** UPDATE CODE GOES HERE */ + updateDeltaCounter += delta + + + + if (false && Terrarum.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) + // else, NOP; + } + else { + var updateTries = 0 + while (updateDeltaCounter >= updateRate) { + + //updateGame(delta) + Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } + + updateDeltaCounter -= updateRate + updateTries++ + + if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) { + break + } + } + } + + + + /** RENDER CODE GOES HERE */ + //renderGame(batch) + Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() } + } + + private fun updateGame(delta: Float) { + blockPointingCursor.update(delta) + playableActor.update(delta) + uiContainer.forEach { it.update(delta) } + + WorldCamera.update(world, playableActor) + } + + private fun renderGame() { + IngameRenderer(world as GameWorldExtension, actorsRenderFront = actorsRenderTop, uisToDraw = uiContainer) + } + + override fun resize(width: Int, height: Int) { + IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) + uiToolbox.setPosition(Terrarum.WIDTH - 20, 4) + notifier.setPosition( + (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height) + println("[BuildingMaker] Resize event") + } +} + + +class MovableWorldCamera(world: GameWorld) : ActorHumanoid(world, 0, usePhysics = false) { + + init { + referenceID = Terrarum.PLAYER_REF_ID + isNoClip = true + + setHitboxDimension(1, 1, 0, 0) + + + actorValue[AVKey.SPEED] = 8.0 + actorValue[AVKey.SPEEDBUFF] = 1.0 + actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE + actorValue[AVKey.ACCELBUFF] = 1.0 + actorValue[AVKey.JUMPPOWER] = 0.0 + } + + override fun drawBody(batch: SpriteBatch) { + } + + override fun drawGlow(batch: SpriteBatch) { + } + + override fun onActorValueChange(key: String, value: Any?) { + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt index 62922fee4..585adbe98 100644 --- a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt +++ b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.modulebasegame -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import net.torvald.terrarum.ModMgr import net.torvald.terrarum.ModuleEntryPoint import net.torvald.terrarum.Terrarum @@ -8,7 +8,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.Material -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable /** * Created by minjaesong on 2018-06-21. @@ -61,7 +61,7 @@ class EntryPoint : ModuleEntryPoint() { // check for collision with actors (BLOCK only) if (this.inventoryCategory == Category.BLOCK) { ingame.actorContainer.forEach { - if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) + if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint)) return false } } diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 6b9c45e4c..a0fa34751 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -1,11 +1,8 @@ package net.torvald.terrarum.modulebasegame import com.badlogic.gdx.Gdx -import com.badlogic.gdx.Input -import com.badlogic.gdx.Screen import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch -import com.badlogic.gdx.graphics.glutils.FrameBuffer import net.torvald.dataclass.CircularArray import net.torvald.terrarum.blockproperties.BlockPropUtil @@ -18,28 +15,24 @@ import net.torvald.terrarum.gamecontroller.IngameController import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator -import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.WorldCamera import java.util.ArrayList -import java.util.concurrent.locks.Lock import java.util.concurrent.locks.ReentrantLock -import javax.swing.JOptionPane - -import com.badlogic.gdx.graphics.OrthographicCamera import net.torvald.random.HQRNG import net.torvald.terrarum.* -import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.modulebasegame.console.AVTracker import net.torvald.terrarum.modulebasegame.console.ActorsList import net.torvald.terrarum.console.Authenticator import net.torvald.terrarum.console.SetGlobalLightOverride import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.gameactors.* +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain import net.torvald.terrarum.modulebasegame.imagefont.WatchDotAlph import net.torvald.terrarum.modulebasegame.ui.* @@ -53,14 +46,16 @@ import kotlin.system.measureNanoTime * Created by minjaesong on 2017-06-16. */ -class Ingame(batch: SpriteBatch) : IngameInstance(batch) { - +open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { private val ACTOR_UPDATE_RANGE = 4096 - lateinit var world: GameWorld lateinit var historicalFigureIDBucket: ArrayList + lateinit var gameworld: GameWorldExtension + + lateinit var theRealGamer: IngamePlayer + /** * list of Actors that is sorted by Actors' referenceID */ @@ -76,55 +71,18 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { private val actorsRenderMidTop = ArrayList(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderFront = ArrayList(ACTORCONTAINER_INITIAL_SIZE) - lateinit var playableActorDelegate: PlayableActorDelegate // player must exist; use dummy player if there is none (required for camera) - private set - inline val player: ActorHumanoid // currently POSSESSED actor :) - get() = playableActorDelegate.actor //var screenZoom = 1.0f // definition moved to IngameInstance //val ZOOM_MAXIMUM = 4.0f // definition moved to IngameInstance //val ZOOM_MINIMUM = 0.5f // definition moved to IngameInstance companion object { - //val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred - - /** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */ fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) { camera.position.set((-newX + Terrarum.HALFW).round(), (-newY + Terrarum.HALFH).round(), 0f) camera.update() batch.projectionMatrix = camera.combined } - - - - /** - * Usage: - * - * override var referenceID: Int = generateUniqueReferenceID() - */ - fun generateUniqueReferenceID(renderOrder: Actor.RenderOrder): ActorID { - fun hasCollision(value: ActorID) = - try { - Terrarum.ingame!!.theGameHasActor(value) || - value < ItemCodex.ACTORID_MIN || - value !in when (renderOrder) { - Actor.RenderOrder.BEHIND -> Actor.RANGE_BEHIND - Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE - Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP - Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT - } - } - catch (gameNotInitialisedException: KotlinNullPointerException) { - false - } - - var ret: Int - do { - ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID - } while (hasCollision(ret)) // check for collision - return ret - } } @@ -134,13 +92,6 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { - private val useShader: Boolean = false - private val shaderProgram = 0 - - val KEY_LIGHTMAP_RENDER = Input.Keys.F7 - - - lateinit var debugWindow: UICanvas lateinit var notifier: UICanvas @@ -213,7 +164,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { GameLoadMode.LOAD_FROM -> enter(gameLoadInfoPayload as GameSaveData) } - LightmapRenderer.world = this.world + //LightmapRenderer.world = this.world //BlocksDrawer.world = this.world FeaturesDrawer.world = this.world @@ -221,9 +172,9 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { } data class GameSaveData( - val world: GameWorld, + val world: GameWorldExtension, val historicalFigureIDBucket: ArrayList, - val realGamePlayer: ActorHumanoid + val realGamePlayer: IngamePlayer ) data class NewWorldParameters( @@ -244,10 +195,12 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { LoadScreen.addMessage("Loading world from save") - world = gameSaveData.world + gameworld = gameSaveData.world + world = gameworld historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket - playableActorDelegate = PlayableActorDelegate(gameSaveData.realGamePlayer) - addNewActor(player) + theRealGamer = gameSaveData.realGamePlayer + playableActor = gameSaveData.realGamePlayer + addNewActor(playableActor) @@ -268,7 +221,8 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { // init map as chosen size - world = GameWorld(worldParams.width, worldParams.height) + gameworld = GameWorldExtension(worldParams.width, worldParams.height) + world = gameworld as GameWorld // generate terrain for the map WorldGenerator.attachMap(world) @@ -301,7 +255,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { /** Load rest of the game with GL context */ fun postInit() { //LightmapRenderer.world = this.world - BlocksDrawer.world = this.world + //BlocksDrawer.world = this.world //FeaturesDrawer.world = this.world @@ -342,7 +296,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { -uiInventoryPlayer.width, 70 )*/ - uiInventoryPlayer = UIInventoryFull(player, + uiInventoryPlayer = UIInventoryFull(playableActor, toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") ) uiInventoryPlayer.setPosition(0, 0) @@ -368,11 +322,11 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { //uiVitalItem.setAsAlwaysVisible() // basic watch-style notification bar (temperature, new mail) - uiWatchBasic = UIBasicNotifier(player) + uiWatchBasic = UIBasicNotifier(playableActor) uiWatchBasic.setAsAlwaysVisible() uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0) - uiWatchTierOne = UITierOneWatch(player) + uiWatchTierOne = UITierOneWatch(playableActor) uiWatchTierOne.setAsAlwaysVisible() uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2) @@ -460,15 +414,15 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { if (!gameFullyLoaded) { if (gameLoadMode == GameLoadMode.CREATE_NEW) { - playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid()) + playableActor = PlayerBuilderSigrid() // go to spawn position - player.setPosition( + playableActor.setPosition( world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(), world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble() ) - addNewActor(player) + addNewActor(playableActor) } postInit() @@ -527,6 +481,8 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { } protected fun updateGame(delta: Float) { + val world = this.world as GameWorldExtension + particlesActive = 0 @@ -542,17 +498,17 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { BlockPropUtil.dynamicLumFuncTickClock() world.updateWorldTime(delta) //WorldSimulator(player, delta) - WeatherMixer.update(delta, player) + WeatherMixer.update(delta, playableActor) BlockStats.update() if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride) - world.globalLight = WeatherMixer.globalLightNow + gameworld.globalLight = WeatherMixer.globalLightNow //////////////////////////// // camera-related updates // //////////////////////////// FeaturesDrawer.update(delta) - WorldCamera.update(world, player) + WorldCamera.update(gameworld, playableActor) @@ -589,13 +545,13 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { private fun renderGame() { IngameRenderer.invoke( - world, + world as GameWorldExtension, actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer, - player, + playableActor, uiContainer ) } @@ -603,39 +559,32 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { private fun repossessActor() { // check if currently pocessed actor is removed from game - if (!theGameHasActor(player)) { + if (!theGameHasActor(playableActor)) { // re-possess canonical player - if (theGameHasActor(Player.PLAYER_REF_ID)) - changePossession(Player.PLAYER_REF_ID) + if (theGameHasActor(Terrarum.PLAYER_REF_ID)) + changePossession(Terrarum.PLAYER_REF_ID) else changePossession(0x51621D) // FIXME fallback debug mode (FIXME is there for a reminder visible in ya IDE) } } - private fun changePossession(newActor: PlayableActorDelegate) { - if (!theGameHasActor(player)) { + private fun changePossession(newActor: ActorHumanoid) { + if (!theGameHasActor(playableActor)) { throw IllegalArgumentException("No such actor in the game: $newActor") } - playableActorDelegate = newActor - WorldSimulator(player, Terrarum.deltaTime) + playableActor = newActor + WorldSimulator(playableActor, Terrarum.deltaTime) } private fun changePossession(refid: Int) { - // TODO prevent possessing other player on multiplayer + val actorToChange = getActorByID(refid) - if (!theGameHasActor(refid)) { - throw IllegalArgumentException( - "No such actor in the game: $refid (elemsActive: ${actorContainer.size}, " + - "elemsInactive: ${actorContainerInactive.size})") + if (actorToChange !is ActorHumanoid) { + throw Error("Unpossessable actor $refid: type expected ActorHumanoid, got ${actorToChange.javaClass.canonicalName}") } - // take care of old delegate - playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE - // accept new delegate - playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid) - playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC - WorldSimulator(player, Terrarum.deltaTime) + changePossession(getActorByID(refid) as ActorHumanoid) } /** Send message to notifier UI and toggle the UI as opened. */ @@ -709,11 +658,11 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { ThreadParallel.startAll() - playableActorDelegate?.update(delta) + playableActor.update(delta) } else { actorContainer.forEach { - if (it != playableActorDelegate?.actor) { + if (it != playableActor) { it.update(delta) if (it is Pocketed) { @@ -726,7 +675,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { } } } - playableActorDelegate?.update(delta) + playableActor.update(delta) //AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre) } } @@ -779,7 +728,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { * This is how remove function of [java.util.ArrayList] is defined. */ override fun removeActor(actor: Actor) { - if (actor.referenceID == player.referenceID || actor.referenceID == 0x51621D) // do not delete this magic + if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic throw RuntimeException("Attempted to remove player.") val indexToDelete = actorContainer.binarySearch(actor.referenceID!!) if (indexToDelete >= 0) { @@ -929,8 +878,6 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { */ override fun resize(width: Int, height: Int) { - BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) - LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) MegaRainGovernor.resize() diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 168280f05..0d3335b57 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -13,8 +13,9 @@ import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ParticleBase +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.worlddrawer.LightmapRenderer @@ -50,7 +51,7 @@ object IngameRenderer { private var initDone = false - private var player: ActorHumanoid? = null + private var player: ActorWithBody? = null var uiListToDraw = ArrayList() @@ -59,13 +60,13 @@ object IngameRenderer { private var debugMode = 0 operator fun invoke( - world: GameWorld, + world: GameWorldExtension, actorsRenderBehind: List? = null, actorsRenderMiddle: List? = null, actorsRenderMidTop: List? = null, actorsRenderFront : List? = null, particlesContainer: CircularArray? = null, - player: ActorHumanoid? = null, + player: ActorWithBody? = null, uisToDraw: ArrayList? = null ) { @@ -77,8 +78,6 @@ object IngameRenderer { this.player = player - - LightmapRenderer.fireRecalculateEvent() prepLightmapRGBA() @@ -141,7 +140,7 @@ object IngameRenderer { batch.fillRect(0f, 0f, 6f, 10f) batch.color = Color.LIME batch.fillRect(6f, 0f, 6f, 10f) - batch.color = Color.BLUE + batch.color = Color.ROYAL batch.fillRect(12f, 0f, 6f, 10f) batch.color = Color.WHITE } @@ -390,7 +389,7 @@ object IngameRenderer { } - private fun init(world: GameWorld) { + private fun init(world: GameWorldExtension) { if (!initDone) { batch = SpriteBatch() camera = OrthographicCamera(widthf, heightf) @@ -401,13 +400,13 @@ object IngameRenderer { resize(width, height) - LightmapRenderer.world = world - - - - initDone = true } + + + BlocksDrawer.world = world + LightmapRenderer.setWorld(world) + FeaturesDrawer.world = world } private fun clearBuffer() { @@ -513,6 +512,9 @@ object IngameRenderer { BlocksDrawer.resize(width, height) LightmapRenderer.resize(width, height) + + + //LightmapRenderer.fireRecalculateEvent() } private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() diff --git a/src/net/torvald/terrarum/modulebasegame/console/AVTracker.kt b/src/net/torvald/terrarum/modulebasegame/console/AVTracker.kt index 6c7c79f01..339f0c481 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/AVTracker.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/AVTracker.kt @@ -16,7 +16,7 @@ internal object AVTracker : ConsoleCommand { override fun execute(args: Array) { if (args.size < 2) { - jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).player)) + jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).playableActor)) } else { try { diff --git a/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt b/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt index 36291bdc8..3395fef18 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt @@ -16,7 +16,7 @@ internal object ExportAV : ConsoleCommand { if (args.size == 2) { try { JsonWriter.writeToFile( - (Terrarum.ingame!! as Ingame).player.actorValue, + (Terrarum.ingame!! as Ingame).playableActor.actorValue, Terrarum.defaultDir + "/Exports/" + args[1] + ".json") Echo("ExportAV: exported to " + args[1] + ".json") diff --git a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt index ef937b4dc..57b066b2d 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt @@ -62,7 +62,7 @@ internal object ExportMap : ConsoleCommand { } override fun execute(args: Array) { - val world = (Terrarum.ingame!! as Ingame).world + val world = (Terrarum.ingame!!.world) if (args.size == 2) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/GetAV.kt b/src/net/torvald/terrarum/modulebasegame/console/GetAV.kt index 54c3cde70..8ba567962 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/GetAV.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/GetAV.kt @@ -17,9 +17,9 @@ internal object GetAV : ConsoleCommand { val ingame = Terrarum.ingame!! as Ingame - if (args.size == 1 && ingame.player != null) { + if (args.size == 1 && ingame.playableActor != null) { // print all actorvalue of player - val av = ingame.player.actorValue + val av = ingame.playableActor.actorValue val keyset = av.keySet Echo("$ccW== ActorValue list for ${ccY}player $ccW==") @@ -37,14 +37,14 @@ internal object GetAV : ConsoleCommand { if (!args[1].isNum()) { // args[1] is ActorValue name Echo("${ccW}player.$ccM${args[1]} $ccW= " + ccG + - ingame.player.actorValue[args[1]] + + ingame.playableActor.actorValue[args[1]] + " $ccO" + - ingame.player.actorValue[args[1]]!!.javaClass.simpleName + ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName ) println("[GetAV] player.${args[1]} = " + - ingame.player.actorValue[args[1]] + + ingame.playableActor.actorValue[args[1]] + " " + - ingame.player.actorValue[args[1]]!!.javaClass.simpleName + ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName ) } else { diff --git a/src/net/torvald/terrarum/modulebasegame/console/GetFactioning.kt b/src/net/torvald/terrarum/modulebasegame/console/GetFactioning.kt index 930df3154..c5cc530e1 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/GetFactioning.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/GetFactioning.kt @@ -6,8 +6,7 @@ import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.gameactors.Factionable -import net.torvald.terrarum.modulebasegame.Ingame -import net.torvald.terrarum.modulebasegame.gameactors.Player +import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer import net.torvald.terrarumsansbitmap.gdx.GameFontBase /** @@ -29,8 +28,8 @@ internal object GetFactioning : ConsoleCommand { fun printOutFactioning(id: Int) { val a = Terrarum.ingame!!.getActorByID(id) if (a is Factionable) { - Echo("$ccW== Faction assignment for $ccY${if (id == Player.PLAYER_REF_ID) "player" else id.toString()} $ccW==") - println("[GetFactioning] == Faction assignment for '${if (id == Player.PLAYER_REF_ID) "player" else id.toString()}' ==") + Echo("$ccW== Faction assignment for $ccY${if (id == Terrarum.PLAYER_REF_ID) "player" else id.toString()} $ccW==") + println("[GetFactioning] == Faction assignment for '${if (id == Terrarum.PLAYER_REF_ID) "player" else id.toString()}' ==") // get all factioning data of player val factionSet = a.faction @@ -84,7 +83,7 @@ internal object GetFactioning : ConsoleCommand { } if (args.size == 1) { - printOutFactioning(Player.PLAYER_REF_ID) + printOutFactioning(Terrarum.PLAYER_REF_ID) } else { if (!args[1].isNum()) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/GetTime.kt b/src/net/torvald/terrarum/modulebasegame/console/GetTime.kt index 7556e42d6..9a5053a3c 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/GetTime.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/GetTime.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.console import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo -import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension /** * Created by minjaesong on 2016-03-20. @@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame internal object GetTime : ConsoleCommand { override fun execute(args: Array) { - val worldTime = (Terrarum.ingame!! as Ingame).world.time + val worldTime = (Terrarum.ingame!!.world as GameWorldExtension).time Echo(worldTime.getFormattedTime()) } diff --git a/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt b/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt index 81efd1a2f..47cca16f7 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt @@ -16,7 +16,7 @@ import java.io.IOException internal object GsonTest : ConsoleCommand { override fun execute(args: Array) { if (args.size == 2) { - val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).player) + val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).playableActor) val jsonString = avelem.toString() diff --git a/src/net/torvald/terrarum/modulebasegame/console/ImportLayerData.kt b/src/net/torvald/terrarum/modulebasegame/console/ImportLayerData.kt index 841274ae4..1dd7cb2b2 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ImportLayerData.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ImportLayerData.kt @@ -20,10 +20,10 @@ object ImportLayerData : ConsoleCommand { //val fis = GZIPInputStream(FileInputStream(args[1])) // this gzip is kaput val fis = FileInputStream(args[1]) - (Terrarum.ingame!! as Ingame).world = ReadLayerData(fis) - (Terrarum.ingame!! as Ingame).player.setPosition( - (Terrarum.ingame!! as Ingame).world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble(), - (Terrarum.ingame!! as Ingame).world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble() + (Terrarum.ingame!!.world) = ReadLayerData(fis) + (Terrarum.ingame!! as Ingame).playableActor.setPosition( + (Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(), + (Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble() ) fis.close() Echo("Successfully loaded ${args[1]}") diff --git a/src/net/torvald/terrarum/modulebasegame/console/Inventory.kt b/src/net/torvald/terrarum/modulebasegame/console/Inventory.kt index ee3d2affd..eb1aa58ee 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/Inventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/Inventory.kt @@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.EchoError -import net.torvald.terrarum.modulebasegame.gameactors.Player +import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.Ingame @@ -14,7 +14,7 @@ import net.torvald.terrarum.modulebasegame.Ingame */ internal object Inventory : ConsoleCommand { - private var target: Pocketed? = (Terrarum.ingame!! as Ingame).player + private var target: Pocketed? = (Terrarum.ingame!! as Ingame).playableActor override fun execute(args: Array) { if (args.size == 1) { @@ -48,7 +48,7 @@ internal object Inventory : ConsoleCommand { } } - private fun setTarget(actorRefId: Int = Player.PLAYER_REF_ID) { + private fun setTarget(actorRefId: Int = Terrarum.PLAYER_REF_ID) { val actor = Terrarum.ingame!!.getActorByID(actorRefId) if (actor !is Pocketed) { EchoError("Cannot edit inventory of incompatible actor: $actor") diff --git a/src/net/torvald/terrarum/modulebasegame/console/Seed.kt b/src/net/torvald/terrarum/modulebasegame/console/Seed.kt index c9a32dcfd..f00be304b 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/Seed.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/Seed.kt @@ -12,8 +12,8 @@ import net.torvald.terrarum.modulebasegame.Ingame internal object Seed : ConsoleCommand { override fun execute(args: Array) { - Echo("Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}") - println("[seed] Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}") + Echo("Map$ccW: $ccG${(Terrarum.ingame!!.world).generatorSeed}") + println("[seed] Map$ccW: $ccG${(Terrarum.ingame!!.world).generatorSeed}") // TODO display randomiser seed } diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetAV.kt b/src/net/torvald/terrarum/modulebasegame/console/SetAV.kt index 55647a94a..ac893e762 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetAV.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetAV.kt @@ -63,7 +63,7 @@ internal object SetAV : ConsoleCommand { return } - (Terrarum.ingame!! as Ingame).player.actorValue[args[1]] = newValue + (Terrarum.ingame!! as Ingame).playableActor.actorValue[args[1]] = newValue Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue") println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.") } diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetScale.kt b/src/net/torvald/terrarum/modulebasegame/console/SetScale.kt index 1f941f984..ccbead517 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetScale.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetScale.kt @@ -5,7 +5,7 @@ import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.modulebasegame.Ingame -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable /** * Created by minjaesong on 2017-01-20. @@ -14,13 +14,13 @@ internal object SetScale : ConsoleCommand { override fun execute(args: Array) { if (args.size == 2 || args.size == 3) { try { - val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).player.referenceID + val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).playableActor.referenceID val scale = args[if (args.size == 3) 2 else 1].toDouble() val target = Terrarum.ingame!!.getActorByID(targetID!!) - if (target !is ActorWithPhysics) { - EchoError("Target is not ActorWithPhysics") + if (target !is ActorWBMovable) { + EchoError("Target is not ActorWBMovable") } else { target.scale = scale diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetTime.kt b/src/net/torvald/terrarum/modulebasegame/console/SetTime.kt index aa2e83ac6..6225af778 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetTime.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetTime.kt @@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame */ internal object SetTime : ConsoleCommand { override fun execute(args: Array) { - val world = (Terrarum.ingame!! as Ingame).world + val world = (Terrarum.ingame!! as Ingame).gameworld if (args.size == 2) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetTimeDelta.kt b/src/net/torvald/terrarum/modulebasegame/console/SetTimeDelta.kt index 19e068118..0d76d2316 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetTimeDelta.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetTimeDelta.kt @@ -13,7 +13,7 @@ internal object SetTimeDelta : ConsoleCommand { val HARD_LIMIT = 60 override fun execute(args: Array) { - val world = (Terrarum.ingame!! as Ingame).world + val world = (Terrarum.ingame!! as Ingame).gameworld if (args.size == 2) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestBall.kt b/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestBall.kt index d4082ef72..c7ed7dc88 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestBall.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestBall.kt @@ -13,7 +13,7 @@ import org.dyn4j.geometry.Vector2 internal object SpawnPhysTestBall : ConsoleCommand { @Throws(Exception::class) override fun execute(args: Array) { - val world = (Terrarum.ingame!! as Ingame).world + val world = (Terrarum.ingame!!.world) val mouseX = Terrarum.mouseX diff --git a/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestLunarLander.kt b/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestLunarLander.kt index 3176fb261..da8c62faf 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestLunarLander.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SpawnPhysTestLunarLander.kt @@ -13,7 +13,7 @@ internal object SpawnPhysTestLunarLander : ConsoleCommand { override fun execute(args: Array) { val mouseX = Terrarum.mouseX val mouseY = Terrarum.mouseY - val lander = PhysTestLuarLander((Terrarum.ingame!! as Ingame).world) + val lander = PhysTestLuarLander((Terrarum.ingame!!.world)) lander.setPosition(mouseX, mouseY) diff --git a/src/net/torvald/terrarum/modulebasegame/console/SpawnTikiTorch.kt b/src/net/torvald/terrarum/modulebasegame/console/SpawnTikiTorch.kt index b57ca627a..8f068c2ac 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SpawnTikiTorch.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SpawnTikiTorch.kt @@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch */ internal object SpawnTikiTorch : ConsoleCommand { override fun execute(args: Array) { - val torch = FixtureTikiTorch((Terrarum.ingame!! as Ingame).world) + val torch = FixtureTikiTorch((Terrarum.ingame!!.world)) torch.setPosition(Terrarum.mouseX, Terrarum.mouseY) Terrarum.ingame!!.addNewActor(torch) diff --git a/src/net/torvald/terrarum/modulebasegame/console/Teleport.kt b/src/net/torvald/terrarum/modulebasegame/console/Teleport.kt index 9de9a4686..20d0548d6 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/Teleport.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/Teleport.kt @@ -6,7 +6,7 @@ import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.modulebasegame.Ingame -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable /** * Created by minjaesong on 2016-01-24. @@ -27,32 +27,32 @@ internal object Teleport : ConsoleCommand { return } - (Terrarum.ingame!! as Ingame).player.setPosition(x.toDouble(), y.toDouble()) + (Terrarum.ingame!! as Ingame).playableActor.setPosition(x.toDouble(), y.toDouble()) } else if (args.size == 4) { if (args[2].toLowerCase() != "to") { EchoError("missing 'to' on teleport command") return } - val fromActor: ActorWithPhysics - val targetActor: ActorWithPhysics + val fromActor: ActorWBMovable + val targetActor: ActorWBMovable try { val fromActorID = args[1].toInt() val targetActorID = if (args[3].toLowerCase() == "player") - (Terrarum.ingame!! as Ingame).player.referenceID!! + (Terrarum.ingame!! as Ingame).playableActor.referenceID!! else args[3].toInt() // if from == target, ignore the action if (fromActorID == targetActorID) return - if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWithPhysics || - Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWithPhysics) { + if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWBMovable || + Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWBMovable) { throw IllegalArgumentException() } else { - fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWithPhysics - targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWithPhysics + fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWBMovable + targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWBMovable } } catch (e: NumberFormatException) { @@ -75,7 +75,7 @@ internal object Teleport : ConsoleCommand { return } - val actor: ActorWithPhysics + val actor: ActorWBMovable val x: Int val y: Int try { @@ -83,11 +83,11 @@ internal object Teleport : ConsoleCommand { y = args[4].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2 val actorID = args[1].toInt() - if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWithPhysics) { + if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWBMovable) { throw IllegalArgumentException() } else { - actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWithPhysics + actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWBMovable } } catch (e: NumberFormatException) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/ToggleNoClip.kt b/src/net/torvald/terrarum/modulebasegame/console/ToggleNoClip.kt index 05ae44b44..f0edebb6d 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ToggleNoClip.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ToggleNoClip.kt @@ -10,9 +10,9 @@ import net.torvald.terrarum.modulebasegame.Ingame */ internal object ToggleNoClip : ConsoleCommand { override fun execute(args: Array) { - val status = (Terrarum.ingame!! as Ingame).player.isNoClip() + val status = (Terrarum.ingame!! as Ingame).playableActor.isNoClip - (Terrarum.ingame!! as Ingame).player.setNoClip(!status) + (Terrarum.ingame!! as Ingame).playableActor.isNoClip = !status Echo("Set no-clip status to " + (!status).toString()) } diff --git a/src/net/torvald/terrarum/modulebasegame/debuggerapp/ActorValueTracker.kt b/src/net/torvald/terrarum/modulebasegame/debuggerapp/ActorValueTracker.kt index d7f0e7eff..a66404e43 100644 --- a/src/net/torvald/terrarum/modulebasegame/debuggerapp/ActorValueTracker.kt +++ b/src/net/torvald/terrarum/modulebasegame/debuggerapp/ActorValueTracker.kt @@ -7,7 +7,7 @@ import net.torvald.terrarum.console.Echo import net.torvald.terrarum.modulebasegame.console.SetAV import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.modulebasegame.Ingame -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.worlddrawer.FeaturesDrawer import java.awt.BorderLayout import java.awt.GridLayout @@ -29,7 +29,7 @@ class ActorValueTracker constructor() : JFrame() { private val avPosArea = JTextArea() private val avPosScroller = JScrollPane(avPosArea) - private var actor: ActorWithPhysics? = null + private var actor: ActorWBMovable? = null private var actorValue: ActorValue? = null private val modavInputKey = JTextField() @@ -84,11 +84,11 @@ class ActorValueTracker constructor() : JFrame() { buttonChangeActor.addMouseListener(object : MouseAdapter() { override fun mousePressed(e: MouseEvent?) { if (actorIDField.text.toLowerCase() == "player") { - actor = (Terrarum.ingame!! as Ingame).player + actor = (Terrarum.ingame!! as Ingame).playableActor actorValue = actor!!.actorValue } else if (actorIDField.text.isNotBlank()) { - actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWithPhysics + actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWBMovable actorValue = actor!!.actorValue } } @@ -152,7 +152,7 @@ class ActorValueTracker constructor() : JFrame() { this.title = "AVTracker — $actor" - if (actor is ActorWithPhysics) { + if (actor is ActorWBMovable) { this.actor = actor } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index 4cbbd2347..11c67ed1f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -5,10 +5,7 @@ import com.badlogic.gdx.graphics.Color import com.jme3.math.FastMath import net.torvald.terrarum.Terrarum import net.torvald.terrarum.bipolarClamp -import net.torvald.terrarum.gameactors.Controllable -import net.torvald.terrarum.gameactors.Factionable -import net.torvald.terrarum.gameactors.Hitbox -import net.torvald.terrarum.gameactors.Luminous +import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.itemproperties.GameItem @@ -32,7 +29,7 @@ open class ActorHumanoid( birth: time_t, death: time_t? = null, usePhysics: Boolean = true -) : ActorWithPhysics(world, RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure { +) : ActorWBMovable(world, RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure { @@ -139,8 +136,6 @@ open class ActorHumanoid( @Transient private var prevHMoveKey = KEY_NULL @Transient private var prevVMoveKey = KEY_NULL - internal var noClip = false - @Transient private val AXIS_KEYBOARD = -13372f // leetz @Transient private val GAMEPAD_JUMP = 7 @@ -150,7 +145,7 @@ open class ActorHumanoid( protected var isRightDown = false protected var isJumpDown = false protected inline val isGamer: Boolean - get() = if (Terrarum.ingame == null) false else this == (Terrarum.ingame!! as Ingame).player + get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.playableActor private val nullItem = object : GameItem() { @@ -174,7 +169,7 @@ open class ActorHumanoid( override fun update(delta: Float) { super.update(delta) - if (vehicleRiding is Player) + if (vehicleRiding is IngamePlayer) throw Error("Attempted to 'ride' player object. ($vehicleRiding)") if (vehicleRiding != null && vehicleRiding == this) throw Error("Attempted to 'ride' itself. ($vehicleRiding)") @@ -188,7 +183,7 @@ open class ActorHumanoid( updateSprite(delta) - if (noClip) { + if (isNoClip) { //grounded = true } @@ -277,7 +272,7 @@ open class ActorHumanoid( } // ↑E // ↑D - if (isNoClip() && !isUpDown && !isDownDown) { + if (isNoClip && !isUpDown && !isDownDown) { walkVStop() prevVMoveKey = KEY_NULL } @@ -313,7 +308,7 @@ open class ActorHumanoid( /** * Up/Down movement */ - if (noClip || COLLISION_TEST_MODE) { + if (isNoClip || COLLISION_TEST_MODE) { if (hasController) { if (axisY != 0f) { walkVertical(axisY < 0, axisY.abs()) @@ -343,7 +338,7 @@ open class ActorHumanoid( * Jump control */ if (isJumpDown) { - if (!noClip) { + if (!isNoClip) { if (airJumpingAllowed || (!airJumpingAllowed && walledBottom)) { jumping = true @@ -385,7 +380,7 @@ open class ActorHumanoid( * this code base, ACCELERATION must be changed (in other words, we must deal with JERK) accordingly * to the FRICTION. * - * So I'm adding walkX/Y and getting the ActorWithPhysics.setNewNextHitbox to use the velocity value of + * So I'm adding walkX/Y and getting the ActorWBMovable.setNewNextHitbox to use the velocity value of * walkX/Y + velocity, which is stored in variable moveDelta. * * Be warned. @@ -608,18 +603,6 @@ open class ActorHumanoid( } } - fun isNoClip(): Boolean { - return noClip - } - - fun setNoClip(b: Boolean) { - noClip = b - - if (b) { - externalForce.zero() - controllerMoveDelta?.zero() - } - } fun Float.abs() = FastMath.abs(this) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index da2fd15ae..c87028fcc 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex @@ -60,10 +61,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode if (count < 0) throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" + "These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.") - if (item.originalID == Player.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic + if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic throw IllegalArgumentException("Attempted to put human player into the inventory.") if (((Terrarum.ingame as? Ingame)?.gameFullyLoaded ?: false) && - (item.originalID == (Terrarum.ingame as? Ingame)?.player?.referenceID)) + (item.originalID == (Terrarum.ingame as? Ingame)?.playableActor?.referenceID)) throw IllegalArgumentException("Attempted to put active player into the inventory.") if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1) throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count") diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt index 592f5a230..29eff59c3 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/CreatureBuilder.kt @@ -1,6 +1,8 @@ package net.torvald.terrarum.modulebasegame.gameactors +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Actor +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameworld.GameWorld @@ -13,8 +15,8 @@ object CreatureBuilder { /** * @Param jsonFileName with extension */ - operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWithPhysics { - val actor = ActorWithPhysics(world, Actor.RenderOrder.MIDDLE) + operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWBMovable { + val actor = ActorWBMovable(world, Actor.RenderOrder.MIDDLE) InjectCreatureRaw(actor.actorValue, module, jsonFileName) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/DecodeTapestry.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/DecodeTapestry.kt index 287d96cdc..b9c46f333 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/DecodeTapestry.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/DecodeTapestry.kt @@ -173,6 +173,6 @@ object DecodeTapestry { readCounter++ } - return TapestryObject((Terrarum.ingame!! as Ingame).world, outImageData, artName, authorName) + return TapestryObject((Terrarum.ingame!!.world), outImageData, artName, authorName) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt index 68917604f..1e1936187 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt @@ -4,12 +4,13 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2016-03-15. */ -open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWithPhysics(world, RenderOrder.MIDTOP) { +open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWBMovable(world, RenderOrder.MIDTOP) { init { if (item.dynamicID >= ItemCodex.ACTORID_MIN) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 23771b74e..d53c6e934 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -1,12 +1,13 @@ package net.torvald.terrarum.modulebasegame.gameactors +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2016-06-17. */ open class FixtureBase(world: GameWorld, physics: Boolean = true) : - ActorWithPhysics(world, RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) { + ActorWBMovable(world, RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) { /** * 0: Open * 1: Blocked diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt index 93d7f607b..823a2aa3a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import net.torvald.terrarum.ModMgr import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameworld.GameWorld diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/HumanoidNPC.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/HumanoidNPC.kt index e37d5c6f5..de423cbd1 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/HumanoidNPC.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/HumanoidNPC.kt @@ -2,11 +2,11 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.AIControlled +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.Material -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics.Companion.COLLISION_DYNAMIC import net.torvald.terrarum.modulebasegame.gameworld.time_t /** diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/Player.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt similarity index 53% rename from src/net/torvald/terrarum/modulebasegame/gameactors/Player.kt rename to src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt index 77c87e52c..84cc594a1 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/Player.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameactors -import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.time_t @@ -10,27 +11,17 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t * Created by minjaesong on 2015-12-31. */ -class Player(world: GameWorld, born: time_t) : ActorHumanoid(world, born) { - - companion object { - @Transient const val PLAYER_REF_ID: Int = 0x91A7E2 - } +class IngamePlayer(world: GameWorldExtension, born: time_t) : ActorHumanoid(world, born) { /** * Creates new Player instance with empty elements (sprites, actorvalue, etc.). * **Use PlayerFactory to build player!** - - * @throws SlickException */ init { - referenceID = PLAYER_REF_ID // forcibly set ID + referenceID = Terrarum.PLAYER_REF_ID // forcibly set ID density = BASE_DENSITY collisionType = COLLISION_KINEMATIC } - override fun update(delta: Float) { - super.update(delta) - } - } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/InjectCreatureRaw.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/InjectCreatureRaw.kt index f5df73b6d..e2335dfe8 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/InjectCreatureRaw.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/InjectCreatureRaw.kt @@ -5,6 +5,7 @@ import net.torvald.random.Fudge3 import net.torvald.terrarum.langpack.Lang import com.google.gson.JsonObject import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ActorValue import java.security.SecureRandom diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleBase.kt index 206bfb465..450b486b7 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleBase.kt @@ -4,14 +4,13 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.Second import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics.Companion.SI_TO_GAME_ACC +import net.torvald.terrarum.gameactors.ActorWBMovable.Companion.SI_TO_GAME_ACC import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.floorInt import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Hitbox -import net.torvald.terrarum.modulebasegame.Ingame import org.dyn4j.geometry.Vector2 /** @@ -48,7 +47,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision if (despawnUponCollision) { if (velocity.isZero || // simple stuck check - BlockCodex[(Terrarum.ingame!! as Ingame).world.getTileFromTerrain( + BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain( hitbox.canonicalX.div(TILE_SIZE).floorInt(), hitbox.canonicalY.div(TILE_SIZE).floorInt() ) ?: Block.STONE].isSolid) { @@ -62,7 +61,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision // gravity, winds, etc. (external forces) if (!isNoSubjectToGrav) { - velocity += (Terrarum.ingame!! as Ingame).world.gravitation / dragCoefficient * SI_TO_GAME_ACC + velocity += (Terrarum.ingame!!.world).gravitation / dragCoefficient * SI_TO_GAME_ACC } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt index c0884abc9..dfd090f20 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt @@ -7,6 +7,7 @@ import net.torvald.random.HQRNG import net.torvald.terrarum.ModMgr import net.torvald.terrarum.Second import net.torvald.terrarum.gameactors.Actor +import net.torvald.terrarum.gameactors.ActorWBMovable /** * Created by minjaesong on 2017-12-18. @@ -23,7 +24,7 @@ class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOr w, h ) - velocity.y = 11.5 * ActorWithPhysics.SI_TO_GAME_VEL + velocity.y = 11.5 * ActorWBMovable.SI_TO_GAME_VEL } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt index e74ddb1c3..6d7f9f6a0 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestBall.kt @@ -3,14 +3,14 @@ package net.torvald.terrarum.modulebasegame.gameactors import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameworld.GameWorld -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser /** * Created by minjaesong on 2016-03-05. */ -class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDDLE, immobileBody = true) { +class PhysTestBall(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDDLE, immobileBody = true) { private var color = Color.GOLD @@ -32,13 +32,13 @@ class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDDL ) it.circle( - hitbox.startX.toFloat() + (Terrarum.ingame!! as Ingame).world.width * TILE_SIZE - 1f, + hitbox.startX.toFloat() + (Terrarum.ingame!!.world).width * TILE_SIZE - 1f, hitbox.startY.toFloat() - 1f, hitbox.width.toFloat() ) it.circle( - hitbox.startX.toFloat() - (Terrarum.ingame!! as Ingame).world.width * TILE_SIZE - 1f, + hitbox.startX.toFloat() - (Terrarum.ingame!!.world).width * TILE_SIZE - 1f, hitbox.startY.toFloat() - 1f, hitbox.width.toFloat() ) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt index c4837123e..580e2757b 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PhysTestLuarLander.kt @@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.Controllable import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameworld.GameWorld @@ -13,7 +15,7 @@ import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2018-01-17. */ -class PhysTestLuarLander(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDTOP), Controllable { +class PhysTestLuarLander(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDTOP), Controllable { private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga")) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilder.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilder.kt index 97713be31..9754a79b7 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilder.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilder.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.modulebasegame.Ingame @@ -10,7 +11,9 @@ import net.torvald.terrarum.modulebasegame.Ingame object PlayerBuilder { operator fun invoke(): Actor { - val p: Actor = Player((Terrarum.ingame!! as Ingame).world, (Terrarum.ingame!! as Ingame).world.time.TIME_T) + val world = (Terrarum.ingame!! as Ingame).gameworld + + val p: Actor = IngamePlayer(world, world.time.TIME_T) InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") // attach sprite diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderCynthia.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderCynthia.kt index cadc161ad..eb2627110 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderCynthia.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderCynthia.kt @@ -2,8 +2,9 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.ModMgr import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ai.NullAI -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -12,10 +13,10 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack */ object PlayerBuilderCynthia { - operator fun invoke(): ActorWithPhysics { - //val p: Player = Player(GameDate(100, 143)) // random value thrown + operator fun invoke(): ActorWBMovable { + //val p: IngamePlayer = IngamePlayer(GameDate(100, 143)) // random value thrown val p: HumanoidNPC = HumanoidNPC( - (Terrarum.ingame!! as Ingame).world, + (Terrarum.ingame!!.world), NullAI(), -589141658L) // random value thrown InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt index 74d293100..fb04ca19e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt @@ -5,7 +5,9 @@ import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.faction.FactionFactory import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.blockproperties.Block +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -14,8 +16,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack object PlayerBuilderSigrid { - operator fun invoke(): Player { - val p = Player((Terrarum.ingame!! as Ingame).world, -9223372036854775807L) // XD + operator fun invoke(): IngamePlayer { + val p = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -9223372036854775807L) // XD p.referenceID = 0x51621D // the only constant of this procedural universe diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt index d3f587ffd..d6cd13b15 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderTestSubject1.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.ModMgr import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -10,8 +11,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack * Created by minjaesong on 2017-02-10. */ object PlayerBuilderTestSubject1 { - operator fun invoke(): Player { - val p: Player = Player((Terrarum.ingame!! as Ingame).world, -589141658L) // random value thrown + operator fun invoke(): IngamePlayer { + val p: IngamePlayer = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -589141658L) // random value thrown InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt index 03028fb06..89ccb8466 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt @@ -2,14 +2,14 @@ package net.torvald.terrarum.modulebasegame.gameactors import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameworld.GameWorld -import net.torvald.terrarum.modulebasegame.Ingame import org.dyn4j.geometry.Vector2 import java.util.* @@ -25,7 +25,7 @@ open class ProjectileSimple( private val type: Int, fromPoint: Vector2, // projected coord toPoint: Vector2 // arriving coord -) : ActorWithPhysics(world, RenderOrder.MIDTOP), Luminous, Projectile { +) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous, Projectile { val damage: Int val displayColour: Color @@ -77,7 +77,7 @@ open class ProjectileSimple( lifetimeCounter += delta if (walledTop || walledBottom || walledRight || walledLeft || lifetimeCounter >= lifetimeMax || // stuck check - BlockCodex[(Terrarum.ingame!! as Ingame).world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid + BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid ) { flagDespawn() } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/WeaponSwung.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/WeaponSwung.kt index 9019fa536..de5c4d0f7 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/WeaponSwung.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/WeaponSwung.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import com.badlogic.gdx.graphics.Color +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameworld.GameWorld @@ -8,7 +9,7 @@ import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2016-04-26. */ -class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWithPhysics(world, RenderOrder.MIDTOP), Luminous { +class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous { // just let the solver use AABB; it's cheap but works just enough /** diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ai/SmarterSlimes.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ai/SmarterSlimes.kt index 455784afe..9211e0a1a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ai/SmarterSlimes.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ai/SmarterSlimes.kt @@ -35,7 +35,7 @@ class SmarterSlimes : ActorAI { // TEST: just target player - val playerXPos = (Terrarum.ingame!! as Ingame).player.centrePosPoint.x + val playerXPos = (Terrarum.ingame!! as Ingame).playableActor.centrePosPoint.x val thisXPos = actor.centrePosPoint.x val xDiff = thisXPos - playerXPos diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/CollisionSolver.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/CollisionSolver.kt index 378a23dd3..81f7e8c6b 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/CollisionSolver.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/CollisionSolver.kt @@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors.physicssolver import net.torvald.terrarum.Terrarum import net.torvald.terrarum.modulebasegame.Ingame -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import java.util.* /** @@ -20,9 +20,9 @@ object CollisionSolver { private val collListX = ArrayList(COLL_LIST_SIZE) private val collListY = ArrayList(COLL_LIST_SIZE) - private val collCandidateX = ArrayList>(COLL_CANDIDATES_SIZE) - private val collCandidateY = ArrayList>(COLL_CANDIDATES_SIZE) - private var collCandidates = ArrayList>(COLL_FINAL_CANDIDATES_SIZE) + private val collCandidateX = ArrayList>(COLL_CANDIDATES_SIZE) + private val collCandidateY = ArrayList>(COLL_CANDIDATES_SIZE) + private var collCandidates = ArrayList>(COLL_FINAL_CANDIDATES_SIZE) private val collCandidateStack = Stack() @@ -40,7 +40,7 @@ object CollisionSolver { // mark list x (Terrarum.ingame!! as Ingame).actorContainer.forEach { it -> - if (it is ActorWithPhysics) { + if (it is ActorWBMovable) { collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it)) collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it)) } @@ -73,7 +73,7 @@ object CollisionSolver { // mark list y (Terrarum.ingame!! as Ingame).actorContainer.forEach { it -> - if (it is ActorWithPhysics) { + if (it is ActorWBMovable) { collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it)) collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it)) } @@ -89,7 +89,7 @@ object CollisionSolver { else if (it.kind == ENDPOINT) { val mark_this = it val mark_other = collCandidateStack.pop() - val collCandidate: Pair + val collCandidate: Pair // make sure actor with lower ID comes first if (mark_this.actor < mark_other.actor) collCandidate = Pair(mark_this.actor, mark_other.actor) @@ -137,7 +137,7 @@ object CollisionSolver { return indexOfEqFn(this, other) >= 0 } - private fun solveCollision(a: ActorWithPhysics, b: ActorWithPhysics) { + private fun solveCollision(a: ActorWBMovable, b: ActorWBMovable) { // some of the Pair(a, b) are either duplicates or erroneously reported. // e.g. (A, B), (B, C) and then (A, C); // in some situation (A, C) will not making any contact with each other @@ -173,11 +173,11 @@ object CollisionSolver { } } - private infix fun ActorWithPhysics.makesCollisionWith(other: ActorWithPhysics) = - this.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE && - other.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE + private infix fun ActorWBMovable.makesCollisionWith(other: ActorWBMovable) = + this.collisionType != ActorWBMovable.COLLISION_NOCOLLIDE && + other.collisionType != ActorWBMovable.COLLISION_NOCOLLIDE - private infix fun ActorWithPhysics.isCollidingWith(other: ActorWithPhysics): Boolean { + private infix fun ActorWBMovable.isCollidingWith(other: ActorWBMovable): Boolean { val ax = this.hitbox.centeredX val ay = this.hitbox.centeredY val bx = other.hitbox.centeredX @@ -208,7 +208,7 @@ object CollisionSolver { data class CollisionMarkings( val pos: Double, val kind: Int, - val actor: ActorWithPhysics + val actor: ActorWBMovable ) /** diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/VelocitySolver.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/VelocitySolver.kt index f6193fb4b..bf5248d0d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/VelocitySolver.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/physicssolver/VelocitySolver.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.modulebasegame.gameactors.physicssolver -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable /** * Created by minjaesong on 2016-05-01. @@ -11,7 +11,7 @@ object VelocitySolver { } - private fun applyGravity(actor: ActorWithPhysics) { + private fun applyGravity(actor: ActorWBMovable) { } diff --git a/src/net/torvald/terrarum/modulebasegame/gameworld/GameWorldExtension.kt b/src/net/torvald/terrarum/modulebasegame/gameworld/GameWorldExtension.kt new file mode 100644 index 000000000..123c20477 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameworld/GameWorldExtension.kt @@ -0,0 +1,46 @@ +package net.torvald.terrarum.modulebasegame.gameworld + +import com.badlogic.gdx.graphics.Color +import net.torvald.terrarum.gameworld.* +import kotlin.properties.Delegates + +/** + * Created by minjaesong on 2018-07-03. + */ +class GameWorldExtension(width: Int, height: Int): GameWorld(width, height) { + + val time: WorldTime + val economy = GameEconomy() + + // delegated properties // + /*val layerWall: MapLayer; get() = baseworld.layerWall + val layerTerrain: MapLayer; get() = baseworld.layerTerrain + val layerWire: MapLayer; get() = baseworld.layerWire + val layerWallLowBits: PairedMapLayer; get() = baseworld.layerWallLowBits + val layerTerrainLowBits: PairedMapLayer; get() = baseworld.layerTerrainLowBits + val layerHalfThermal: MapLayerHalfFloat; get() = baseworld.layerHalfThermal + var spawnX: Int; get() = baseworld.spawnX; set(v) { baseworld.spawnX = v } + var spawnY: Int; get() = baseworld.spawnY; set(v) { baseworld.spawnY = v } + val wallDamages: HashMap; get() = baseworld.wallDamages + val terrainDamages: HashMap; get() = baseworld.terrainDamages + var globalLight: Color; get() = baseworld.globalLight; set(v) { baseworld.globalLight = v } + var averageTemperature: Float; get() = baseworld.averageTemperature; set(v) { baseworld.averageTemperature = v } + var generatorSeed: Long; get() = baseworld.generatorSeed; set(v) { baseworld.generatorSeed = v } + val terrainArray: ByteArray; get() = baseworld.terrainArray + val wallArray: ByteArray; get() = baseworld.wallArray + val wireArray: ByteArray; get() = baseworld.wireArray + val damageDataArray: ByteArray; get() = baseworld.damageDataArray*/ + + init { + time = WorldTime( + 71 * WorldTime.DAY_LENGTH + + 7 * WorldTime.HOUR_SEC + + 30L * WorldTime.MINUTE_SEC + ) + } + + fun updateWorldTime(delta: Float) { + time.update(delta) + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt index e1c2c97d2..4f360ac9a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt @@ -38,7 +38,7 @@ object WorldSimulator { val colourNone = Color(0x808080FF.toInt()) val colourWater = Color(0x66BBFFFF.toInt()) - private val world = (Terrarum.ingame!! as Ingame).world + private val world = (Terrarum.ingame!!.world) operator fun invoke(p: ActorHumanoid?, delta: Float) { if (p != null) { diff --git a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt index 6d6ce28de..9380b8440 100644 --- a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt @@ -1,10 +1,10 @@ package net.torvald.terrarum.modulebasegame.items -import net.torvald.point.Point2d +import net.torvald.terrarum.Point2d import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.Block -import net.torvald.terrarum.modulebasegame.gameactors.AVKey -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemID @@ -38,27 +38,27 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() { val mouseTileY = Terrarum.mouseTileY val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble()) - val actorvalue = (Terrarum.ingame!! as Ingame).player.actorValue + val actorvalue = (Terrarum.ingame!! as Ingame).playableActor.actorValue using = true // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors Terrarum.ingame!!.actorContainer.forEach({ - if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) + if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint)) return false }) // return false if here's no tile - if (Block.AIR == (Terrarum.ingame!! as Ingame).world.getTileFromTerrain(mouseTileX, mouseTileY)) + if (Block.AIR == (Terrarum.ingame!!.world).getTileFromTerrain(mouseTileX, mouseTileY)) return false // filter passed, do the job val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!! - (Terrarum.ingame!! as Ingame).world.inflictTerrainDamage( + (Terrarum.ingame!!.world).inflictTerrainDamage( mouseTileX, mouseTileY, - Calculate.pickaxePower((Terrarum.ingame!! as Ingame).player, material) * swingDmgToFrameDmg + Calculate.pickaxePower((Terrarum.ingame!! as Ingame).playableActor, material) * swingDmgToFrameDmg ) return true @@ -67,7 +67,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() { override fun endPrimaryUse(delta: Float): Boolean { using = false // reset action timer to zero - (Terrarum.ingame!! as Ingame).player.actorValue.set(AVKey.__ACTION_TIMER, 0.0) + (Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__ACTION_TIMER, 0.0) return true } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/magiccontroller/TheMagicLanguage.kt b/src/net/torvald/terrarum/modulebasegame/magiccontroller/TheMagicLanguage.kt index 3b405b75b..d9e50fd68 100644 --- a/src/net/torvald/terrarum/modulebasegame/magiccontroller/TheMagicLanguage.kt +++ b/src/net/torvald/terrarum/modulebasegame/magiccontroller/TheMagicLanguage.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.modulebasegame.magiccontroller -import net.torvald.terrarum.modulebasegame.gameactors.AVKey +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Actor /** diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt index cfa2af29e..ebe3d3273 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt @@ -115,11 +115,11 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { if (player != null) { val playerPos = player.hIntTilewiseHitbox lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: - (Terrarum.ingame!! as Ingame).world.globalLight + (Terrarum.ingame!!.world).globalLight ) } else { - lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight + lightLevel = (Terrarum.ingame!!.world).globalLight } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt new file mode 100644 index 000000000..2f5e20523 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt @@ -0,0 +1,92 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.Second +import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.UIItemImageButton +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + +class UIBuildingMakerToolbox : UICanvas() { + + val toolsTexture = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/building_maker_toolbox.tga"), 16, 16) + val tools = Array(toolsTexture.verticalCount, { UIItemImageButton( + this, toolsTexture.get(0, it), + posX = 0, + posY = 20 * it, + highlightable = true + + ) }) + + override var width = 16 + override var height = 20 * tools.size - 4 + override var openCloseTime = 0f + + var selectedTool = 0; private set + + init { + setAsAlwaysVisible() + tools[selectedTool].highlighted = true + } + + override fun updateUI(delta: Float) { + tools.forEachIndexed { counter, it -> + it.update(delta) + + if (it.highlighted) selectedTool = counter + } + } + + override fun renderUI(batch: SpriteBatch, camera: Camera) { + tools.forEach { it.render(batch, camera) } + } + + override fun doOpening(delta: Float) { } + + override fun doClosing(delta: Float) { } + + override fun endOpening(delta: Float) { } + + override fun endClosing(delta: Float) { } + + override fun dispose() { + toolsTexture.dispose() + } + + override fun mouseMoved(screenX: Int, screenY: Int): Boolean { + return super.mouseMoved(screenX, screenY) + } + + override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { + return super.touchDragged(screenX, screenY, pointer) + } + + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + return super.touchDown(screenX, screenY, pointer, button) + } + + override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + return super.touchUp(screenX, screenY, pointer, button) + } + + override fun scrolled(amount: Int): Boolean { + return super.scrolled(amount) + } + + override fun keyDown(keycode: Int): Boolean { + return super.keyDown(keycode) + } + + override fun keyUp(keycode: Int): Boolean { + return super.keyUp(keycode) + } + + override fun keyTyped(character: Char): Boolean { + return super.keyTyped(character) + } + + override fun resize(width: Int, height: Int) { + super.resize(width, height) + } +} diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 2c6807199..c4ef425ce 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.ShapeRenderer import net.torvald.terrarum.* -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.Second @@ -91,7 +91,7 @@ class UIInventoryFull( UIItemInventoryEquippedView( this, actor!!.inventory, - actor as ActorWithPhysics, + actor as ActorWBMovable, internalWidth - UIItemInventoryEquippedView.width + (Terrarum.WIDTH - internalWidth) / 2, 109 + (Terrarum.HEIGHT - internalHeight) / 2 ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 47ca7a7b1..2c571dd0a 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.ui.UIItem @@ -16,7 +16,7 @@ import net.torvald.terrarum.ui.UIItem class UIItemInventoryEquippedView( parentUI: UIInventoryFull, val inventory: ActorInventory, - val theActor: ActorWithPhysics, + val theActor: ActorWBMovable, override var posX: Int, override var posY: Int ) : UIItem(parentUI) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt index 02fb69844..0bb4fb76f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt @@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.jme3.math.FastMath import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.gameactors.AVKey +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.Second import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.Ingame @@ -39,7 +39,7 @@ class UIPieMenu : UICanvas() { override fun updateUI(delta: Float) { if (selection >= 0) - (Terrarum.ingame!! as Ingame).player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = + (Terrarum.ingame!! as Ingame).playableActor.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = selection % slotCount @@ -83,7 +83,7 @@ class UIPieMenu : UICanvas() { // draw item - val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i) + val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i) if (itemPair != null) { val itemImage = ItemCodex.getItemImage(itemPair.item) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt index b4a34d5c4..1e92a03b0 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt @@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.gameactors.AVKey +import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.Second import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.itemproperties.ItemCodex @@ -28,8 +28,8 @@ class UIQuickBar : UICanvas() { private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2 private var selection: Int - get() = (Terrarum.ingame!! as Ingame).player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 - set(value) { (Terrarum.ingame!! as Ingame).player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) } + get() = (Terrarum.ingame!! as Ingame).playableActor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 + set(value) { (Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) } override fun updateUI(delta: Float) { } @@ -54,7 +54,7 @@ class UIQuickBar : UICanvas() { ) // draw item - val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i) + val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i) if (itemPair != null) { val itemImage = ItemCodex.getItemImage(itemPair.item) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt index 43d00c70e..1a204d57f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt @@ -8,6 +8,7 @@ import net.torvald.terrarum.* import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.Second import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.roundInt import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain @@ -40,7 +41,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() { private val lcdLitCol = Color(0x141414_ff) private val worldTime: WorldTime - get() = (Terrarum.ingame!! as Ingame).world.time + get() = (Terrarum.ingame!!.world as GameWorldExtension).time override fun updateUI(delta: Float) { @@ -70,11 +71,11 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() { if (player != null) { val playerPos = player.hIntTilewiseHitbox lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: - (Terrarum.ingame!! as Ingame).world.globalLight + (Terrarum.ingame!!.world).globalLight ) } else { - lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight + lightLevel = (Terrarum.ingame!!.world).globalLight } // backplate diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt index ebb18eaa2..2d10c4360 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt @@ -7,6 +7,7 @@ import net.torvald.random.HQRNG import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.LoadScreen import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.modulebasegame.BuildingMaker import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButtonList @@ -14,13 +15,14 @@ class UITitleRemoConRoot : UICanvas() { companion object { val remoConWidth = 240 + fun getRemoConHeight(menu: ArrayList) = 36 * menu.size.plus(1) fun getRemoConHeight(menu: Array) = 36 * menu.size.plus(1) val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt() } /** Contains STRING_IDs */ - val menuLabels = arrayOf( + val menuLabels = arrayListOf( "MENU_MODE_SINGLEPLAYER", "MENU_OPTIONS", "MENU_MODULES", @@ -29,6 +31,15 @@ class UITitleRemoConRoot : UICanvas() { "MENU_LABEL_QUIT" ) + init { + if (Terrarum.getConfigBoolean("__debug")) { + menuLabels.addAll(arrayOf( + " Development Tools $", + "Building Maker" + )) + } + } + override var width: Int = remoConWidth override var height: Int = getRemoConHeight(menuLabels) @@ -37,7 +48,7 @@ class UITitleRemoConRoot : UICanvas() { private val menubar = UIItemTextButtonList( this, - menuLabels, + menuLabels.toTypedArray(), 0, menubarOffY, this.width, this.height, textAreaWidth = this.width, @@ -104,6 +115,19 @@ class UITitleRemoConRoot : UICanvas() { remoConCredits.setAsOpen() } menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) } + + + if (Terrarum.getConfigBoolean("__debug")) { + + menubar.buttons[menuLabels.indexOf("Building Maker")].clickOnceListener = { _, _, _ -> + this.setAsClose() + Thread.sleep(50) + + val maker = BuildingMaker(Terrarum.batch) + Terrarum.ingame = maker + Terrarum.setScreen(maker) + } + } } override fun updateUI(delta: Float) { diff --git a/src/net/torvald/terrarum/weather/BaseModularWeather.kt b/src/net/torvald/terrarum/modulebasegame/weather/BaseModularWeather.kt similarity index 92% rename from src/net/torvald/terrarum/weather/BaseModularWeather.kt rename to src/net/torvald/terrarum/modulebasegame/weather/BaseModularWeather.kt index eb9ca09e3..0de2ab032 100644 --- a/src/net/torvald/terrarum/weather/BaseModularWeather.kt +++ b/src/net/torvald/terrarum/modulebasegame/weather/BaseModularWeather.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.weather +package net.torvald.terrarum.modulebasegame.weather import com.badlogic.gdx.graphics.Texture import net.torvald.terrarum.GdxColorMap diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt similarity index 95% rename from src/net/torvald/terrarum/weather/WeatherMixer.kt rename to src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt index 2bbfa05f6..ee5dacdfe 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.weather +package net.torvald.terrarum.modulebasegame.weather import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input @@ -10,8 +10,8 @@ import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain import net.torvald.terrarum.gamecontroller.KeyToggler -import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.worlddrawer.WorldCamera @@ -20,6 +20,8 @@ import java.io.File import java.util.* /** + * + * * Current, next are there for cross-fading two weathers * * @@ -29,7 +31,7 @@ import java.util.* * * Created by minjaesong on 2016-07-11. */ -object WeatherMixer { +internal object WeatherMixer { var weatherList: HashMap> var currentWeather: BaseModularWeather @@ -74,6 +76,9 @@ object WeatherMixer { nextWeather = getRandomWeather(WEATHER_GENERIC) } + /** + * Part of Ingame update + */ fun update(delta: Float, player: ActorWithBody) { currentWeather = weatherList[WEATHER_GENERIC]!![0] @@ -89,7 +94,7 @@ object WeatherMixer { ) (Terrarum.ingame!! as Ingame).addParticle(rainParticle) } - //globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!! as Ingame).world.time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f)) + //globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!!.world).time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f)) } } @@ -97,7 +102,10 @@ object WeatherMixer { //private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT * 0.75f // just an arb multiplier (266.66666 -> 200) private val parallaxDomainSize = WorldGenerator.TERRAIN_UNDULATION / 2f - fun render(camera: Camera, world: GameWorld) { + /** + * Sub-portion of IngameRenderer. You are not supposed to directly deal with this. + */ + internal fun render(camera: Camera, world: GameWorldExtension) { val parallaxZeroPos = (world.height / 3) * 0.75f // just an arb multiplier (266.66666 -> 200) diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/WorldGenerator.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/WorldGenerator.kt index 417a32b36..e836fd16f 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/WorldGenerator.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/WorldGenerator.kt @@ -605,7 +605,7 @@ object WorldGenerator { private fun fillMapByNoiseMap() { println("[mapgenerator] Shaping world...") - LoadScreen.addMessage("Shaping world...") + LoadScreen.addMessage("Reticulating splines...") // RETICULATING SPLINES // generate dirt-stone transition line // use catmull spline val dirtStoneLine = IntArray(WIDTH) diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt index 48b8246b8..0cbeedd87 100644 --- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt +++ b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi import org.luaj.vm2.Globals import org.luaj.vm2.LuaFunction import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import org.luaj.vm2.LuaTable import org.luaj.vm2.LuaValue @@ -23,7 +23,7 @@ class WorldInformationProvider(globals: Globals) { companion object { fun getWorldTimeInLuaFormat() : LuaTable { val t = LuaTable() - val time = if (Terrarum.ingame != null) (Terrarum.ingame!! as Ingame).world.time else WorldTime() + val time = if (Terrarum.ingame != null) (Terrarum.ingame!!.world as GameWorldExtension).time else WorldTime() // int Terrarum World Time format t["hour"] = time.hours @@ -42,7 +42,7 @@ class WorldInformationProvider(globals: Globals) { /** evaluate single C date format */ fun String.evalAsDate(): String { - val time = if (Terrarum.ingame != null) (Terrarum.ingame!! as Ingame).world.time else WorldTime() + val time = if (Terrarum.ingame != null) (Terrarum.ingame!!.world as GameWorldExtension).time else WorldTime() return when (this) { "%a" -> time.getDayNameShort() "%A" -> time.getDayNameFull() diff --git a/src/net/torvald/terrarum/serialise/ReadLayerData.kt b/src/net/torvald/terrarum/serialise/ReadLayerData.kt index a61468110..e9658d308 100644 --- a/src/net/torvald/terrarum/serialise/ReadLayerData.kt +++ b/src/net/torvald/terrarum/serialise/ReadLayerData.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.serialise import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import java.io.IOException import java.io.InputStream import java.lang.IllegalArgumentException @@ -13,7 +14,7 @@ import java.util.* internal object ReadLayerData { - internal operator fun invoke(inputStream: InputStream, inWorld: GameWorld? = null): GameWorld { + internal operator fun invoke(inputStream: InputStream, inWorld: GameWorldExtension? = null): GameWorldExtension { val magicBytes = ByteArray(4) val layerSizeBytes = ByteArray(1) val layerCountBytes = ByteArray(1) @@ -62,7 +63,7 @@ internal object ReadLayerData { // create world out of tiles data - val retWorld = inWorld ?: GameWorld(worldWidth, worldHeight) + val retWorld = inWorld ?: GameWorldExtension(worldWidth, worldHeight) retWorld.layerTerrain.data = terrainLayerMSB retWorld.layerWall.data = wallLayerMSB diff --git a/src/net/torvald/terrarum/serialise/WriteLayerData.kt b/src/net/torvald/terrarum/serialise/WriteLayerData.kt index a1846a50c..61e4b95f3 100644 --- a/src/net/torvald/terrarum/serialise/WriteLayerData.kt +++ b/src/net/torvald/terrarum/serialise/WriteLayerData.kt @@ -26,7 +26,7 @@ internal object WriteLayerData { internal operator fun invoke(saveDirectoryName: String): Boolean { val path = "${Terrarum.defaultSaveDir}/$saveDirectoryName/${META_FILENAME}" val tempPath = "${path}_bak" - val map = (Terrarum.ingame!! as Ingame).world + val map = (Terrarum.ingame!!.world) val parentDir = File("${Terrarum.defaultSaveDir}/$saveDirectoryName") if (!parentDir.exists()) { diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 88106e496..7249ee039 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.Terrarum.mouseTileX import net.torvald.terrarum.Terrarum.mouseTileY import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension /** * Created by minjaesong on 2016-03-14. @@ -28,9 +29,10 @@ class BasicDebugInfoWindow : UICanvas() { private var ydelta = 0.0 private val ingame = Terrarum.ingame!! as Ingame + private val world = ingame.world as GameWorldExtension override fun updateUI(delta: Float) { - val player = ingame.player + val player = ingame.playableActor val hitbox = player.hitbox xdelta = hitbox.canonicalX - prevPlayerX @@ -45,7 +47,7 @@ class BasicDebugInfoWindow : UICanvas() { fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL fun Int.rawB() = this % LightmapRenderer.MUL - val player = ingame.player + val player = ingame.playableActor batch.color = Color(0xFFEE88FF.toInt()) @@ -134,11 +136,11 @@ class BasicDebugInfoWindow : UICanvas() { //printLineColumn(batch, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested) //printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp) - printLineColumn(batch, 2, 5, "Time $ccG${ingame.world.time.todaySeconds.toString().padStart(5, '0')}" + - " (${ingame.world.time.getFormattedTime()})") + printLineColumn(batch, 2, 5, "Time $ccG${world.time.todaySeconds.toString().padStart(5, '0')}" + + " (${world.time.getFormattedTime()})") printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}") - printLineColumn(batch, 2, 7, "noClip $ccG${player.noClip}") + printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}") drawHistogram(batch, LightmapRenderer.histogram, diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index 5c4f2a8a9..7081d0680 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -21,34 +21,11 @@ import java.util.zip.GZIPInputStream /** - * Note: You can't just hamburger the three jobs; there's actor draw calls in-between the three jobs, like: - * -``` - BlocksDrawer.renderWall(batch) // JOB #0 - actorsRenderBehind.forEach { it.drawBody(batch) } - particlesContainer.forEach { it.drawBody(batch) } - BlocksDrawer.renderTerrain(batch) // JOB #1 - - ///////////////// - // draw actors // - ///////////////// - actorsRenderMiddle.forEach { it.drawBody(batch) } - actorsRenderMidTop.forEach { it.drawBody(batch) } - player.drawBody(batch) - actorsRenderFront.forEach { it.drawBody(batch) } - // --> Change of blend mode <-- introduced by childs of ActorWithBody // - - - ///////////////////////////// - // draw map related stuffs // - ///////////////////////////// - - BlocksDrawer.renderFront(batch, false) // JOB #2 - ``` + * Sub-portion of IngameRenderer. You are not supposed to directly deal with this. * * Created by minjaesong on 2016-01-19. */ -object BlocksDrawer { +internal object BlocksDrawer { lateinit var world: GameWorld @@ -376,7 +353,7 @@ object BlocksDrawer { // NO draw lightmap using colour filter, actors must also be hidden behind the darkness /////////////////////////////////////////// - fun renderWall(projectionMatrix: Matrix4) { + internal fun renderWall(projectionMatrix: Matrix4) { // blend normal Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) Gdx.gl.glEnable(GL20.GL_BLEND) @@ -386,7 +363,7 @@ object BlocksDrawer { renderUsingBuffer(WALL, projectionMatrix) } - fun renderTerrain(projectionMatrix: Matrix4) { + internal fun renderTerrain(projectionMatrix: Matrix4) { // blend normal Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) Gdx.gl.glEnable(GL20.GL_BLEND) @@ -396,7 +373,7 @@ object BlocksDrawer { renderUsingBuffer(TERRAIN, projectionMatrix) } - fun renderFront(projectionMatrix: Matrix4, drawWires: Boolean) { + internal fun renderFront(projectionMatrix: Matrix4, drawWires: Boolean) { // blend mul Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) Gdx.gl.glEnable(GL20.GL_BLEND) @@ -562,7 +539,7 @@ object BlocksDrawer { * * * @return binary [0-15] 1: up, 2: right, 4: down, 8: left */ - fun getNearbyTilesInfo(x: Int, y: Int, mode: Int, mark: Int?): Int { + internal fun getNearbyTilesInfo(x: Int, y: Int, mode: Int, mark: Int?): Int { val nearbyTiles = IntArray(4) nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: Block.NULL nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: Block.NULL @@ -580,7 +557,7 @@ object BlocksDrawer { return ret } - fun getNearbyTilesInfoNonSolid(x: Int, y: Int, mode: Int): Int { + internal fun getNearbyTilesInfoNonSolid(x: Int, y: Int, mode: Int): Int { val nearbyTiles = IntArray(4) nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: Block.NULL nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: Block.NULL @@ -603,7 +580,7 @@ object BlocksDrawer { return ret } - fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int { + internal fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int { val nearbyTiles = IntArray(4) val NEARBY_TILE_KEY_BACK = NEARBY_TILE_KEY_UP nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: Block.NULL @@ -637,7 +614,7 @@ object BlocksDrawer { } } - fun getNearbyTilesInfoPlatform(x: Int, y: Int): Int { + internal fun getNearbyTilesInfoPlatform(x: Int, y: Int): Int { val nearbyTiles = IntArray(4) nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: Block.NULL nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: Block.NULL diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index 1ac5fda7d..f6990e133 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -4,13 +4,12 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.blockproperties.BlockCodex import com.jme3.math.FastMath -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.fillRect import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.floorInt import net.torvald.terrarum.modulebasegame.IngameRenderer import java.util.* @@ -243,7 +242,7 @@ object LightmapRendererOld { lanternMap.clear() Terrarum.ingame?.let { it.actorContainer.forEach { it -> - if (it is Luminous && it is ActorWithPhysics) { + if (it is Luminous && it is ActorWBMovable) { // put lanterns to the area the luminantBox is occupying for (lightBox in it.lightBoxList) { val lightBoxX = it.hitbox.startX + lightBox.startX diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index 533eb08a6..8372f937f 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -8,19 +8,19 @@ import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.blockproperties.BlockCodex import com.jme3.math.FastMath -import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.* -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.ceilInt import net.torvald.terrarum.floorInt import net.torvald.terrarum.modulebasegame.IngameRenderer import java.util.* +import kotlin.system.measureNanoTime /** - * Warning: you are not going to store float value to the lightmap -- see RGB_HDR_LUT (beziĆ©r) + * Sub-portion of IngameRenderer. You are not supposed to directly deal with this. * * Created by minjaesong on 2016-01-25. */ @@ -29,9 +29,26 @@ import java.util.* // NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable -object LightmapRenderer { - lateinit var world: GameWorld +internal object LightmapRenderer { + private lateinit var world: GameWorld + fun setWorld(world: GameWorld) { + try { + if (this.world != world) { + for (y in 0 until LIGHTMAP_HEIGHT) { + for (x in 0 until LIGHTMAP_WIDTH) { + lightmap[y][x] = Color(0) + } + } + } + } + catch (e: UninitializedPropertyAccessException) { + // new init, do nothing + } + finally { + this.world = world + } + } // TODO if (VBO works on BlocksDrawer) THEN overscan of 256, utilise same technique in here @@ -86,7 +103,7 @@ object LightmapRenderer { * @param x world tile coord * @param y world tile coord */ - fun getLight(x: Int, y: Int): Color? { + internal fun getLight(x: Int, y: Int): Color? { val col = getLightInternal(x, y) if (col == null) { return null @@ -120,7 +137,15 @@ object LightmapRenderer { } } - fun fireRecalculateEvent() { + internal fun fireRecalculateEvent() { + try { + world.getTileFromTerrain(0, 0) // test inquiry + } + catch (e: UninitializedPropertyAccessException) { + return // quit prematually + } + + for_x_start = WorldCamera.x / TILE_SIZE // fix for premature lightmap rendering for_y_start = WorldCamera.y / TILE_SIZE // on topmost/leftmost side @@ -140,37 +165,47 @@ object LightmapRenderer { * for all lightmap[y][x] */ - buildLanternmap() + Terrarum.debugTimers["Renderer.Lanterns"] = measureNanoTime { + buildLanternmap() + } // O(36n) == O(n) where n is a size of the map. // Because of inevitable overlaps on the area, it only works with ADDITIVE blend (aka maxblend) // Round 1 - for (y in for_y_start - overscan_open..for_y_end) { - for (x in for_x_start - overscan_open..for_x_end) { - setLight(x, y, calculate(x, y, 1)) + Terrarum.debugTimers["Renderer.Light1"] = measureNanoTime { + for (y in for_y_start - overscan_open..for_y_end) { + for (x in for_x_start - overscan_open..for_x_end) { + setLight(x, y, calculate(x, y, 1)) + } } } // Round 2 - for (y in for_y_end + overscan_open downTo for_y_start) { - for (x in for_x_start - overscan_open..for_x_end) { - setLight(x, y, calculate(x, y, 2)) + Terrarum.debugTimers["Renderer.Light2"] = measureNanoTime { + for (y in for_y_end + overscan_open downTo for_y_start) { + for (x in for_x_start - overscan_open..for_x_end) { + setLight(x, y, calculate(x, y, 2)) + } } } // Round 3 - for (y in for_y_end + overscan_open downTo for_y_start) { - for (x in for_x_end + overscan_open downTo for_x_start) { - setLight(x, y, calculate(x, y, 3)) + Terrarum.debugTimers["Renderer.Light3"] = measureNanoTime { + for (y in for_y_end + overscan_open downTo for_y_start) { + for (x in for_x_end + overscan_open downTo for_x_start) { + setLight(x, y, calculate(x, y, 3)) + } } } // Round 4 - for (y in for_y_start - overscan_open..for_y_end) { - for (x in for_x_end + overscan_open downTo for_x_start) { - setLight(x, y, calculate(x, y, 4)) + Terrarum.debugTimers["Renderer.Light4"] = measureNanoTime { + for (y in for_y_start - overscan_open..for_y_end) { + for (x in for_x_end + overscan_open downTo for_x_start) { + setLight(x, y, calculate(x, y, 4)) + } } } } @@ -179,7 +214,7 @@ object LightmapRenderer { lanternMap.clear() Terrarum.ingame?.let { it.actorContainer.forEach { it -> - if (it is Luminous && it is ActorWithPhysics) { + if (it is Luminous && it is ActorWBMovable) { // put lanterns to the area the luminantBox is occupying for (lightBox in it.lightBoxList) { val lightBoxX = it.hitbox.startX + lightBox.startX @@ -314,7 +349,7 @@ object LightmapRenderer { private val colourNull = Color(0) - fun draw(batch: SpriteBatch) { + internal fun draw(batch: SpriteBatch) { val this_x_start = for_x_start// + overscan_open val this_x_end = for_x_end// + overscan_open @@ -643,7 +678,7 @@ object LightmapRenderer { 1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f // isn't it beautiful? ) /** To eliminated visible edge on the gradient when 255/1023 is exceeded */ - inline fun Color.normaliseToHDR() = Color( + internal inline fun Color.normaliseToHDR() = Color( hdr(this.r), hdr(this.g), hdr(this.b), diff --git a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt index 447bc3b4c..1d0be6a4a 100644 --- a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt +++ b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.worlddrawer import com.jme3.math.FastMath import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameworld.GameWorld -import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.floorInt /** @@ -29,7 +29,7 @@ object WorldCamera { inline val yCentre: Int get() = y + height.ushr(1) - fun update(world: GameWorld, player: ActorWithPhysics) { + fun update(world: GameWorld, player: ActorWBMovable) { width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f)) diff --git a/work_files/graphics/fonts/LatinExtA_variable.psd b/work_files/graphics/fonts/LatinExtA_variable.psd index 88cf62e51..3fadeacb0 100644 --- a/work_files/graphics/fonts/LatinExtA_variable.psd +++ b/work_files/graphics/fonts/LatinExtA_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7e855feac432c883abf7a13f6baa21938e821ef6672d97f7af729dfa4640de07 -size 173952 +oid sha256:1ed13d2ff05536c10bd44524ed06f83b0675fb30b331694f42c419dbeb317063 +size 174001 diff --git a/work_files/graphics/fonts/LatinExtB_variable.psd b/work_files/graphics/fonts/LatinExtB_variable.psd index afdcb1565..7674bb47c 100644 --- a/work_files/graphics/fonts/LatinExtB_variable.psd +++ b/work_files/graphics/fonts/LatinExtB_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f7a9576c89819d3c19d4cd5b6e704f90501e18258aa3e1ad3a21977cc60fd09 -size 271111 +oid sha256:754f5fe939a1aafbfdb357fb270b80026aea562dfe6254496e1bd500426d2316 +size 271311 diff --git a/work_files/graphics/fonts/ascii_variable_small.psd b/work_files/graphics/fonts/ascii_variable_small.psd new file mode 100644 index 000000000..a94d6a752 --- /dev/null +++ b/work_files/graphics/fonts/ascii_variable_small.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f692b302a0f76478c4c4ccb533b6f89b9d0bf5d09ce114b49cd731452cce337f +size 41313 diff --git a/work_files/graphics/fonts/ascii_variable_smallcaps.psd b/work_files/graphics/fonts/ascii_variable_smallcaps.psd new file mode 100644 index 000000000..963add4d5 --- /dev/null +++ b/work_files/graphics/fonts/ascii_variable_smallcaps.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e99e7153c6d25b61341ab91574571b1d772cedb23e2e0857264a9b85b80f44 +size 331420 diff --git a/work_files/graphics/fonts/cyrilic_bulgarian_variable.psd b/work_files/graphics/fonts/cyrilic_bulgarian_variable.psd index 729454941..4eae6134a 100644 --- a/work_files/graphics/fonts/cyrilic_bulgarian_variable.psd +++ b/work_files/graphics/fonts/cyrilic_bulgarian_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ca8f7bf4c9ad4ec9ad4d55a7fcf803435bb8055b8e884304c66b3c8f6775f7b -size 136274 +oid sha256:74f14e268c8e23679d34187e4915874e978ab95a7381719ab24e84ed065c5c5c +size 136813 diff --git a/work_files/graphics/fonts/cyrilic_serbian_variable.psd b/work_files/graphics/fonts/cyrilic_serbian_variable.psd index 3c7a4a6ba..5ece8dec9 100644 --- a/work_files/graphics/fonts/cyrilic_serbian_variable.psd +++ b/work_files/graphics/fonts/cyrilic_serbian_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:10de2f2404650577daaf81fd3a67daf371092a17841948b37e23ceec06f195a6 -size 155453 +oid sha256:0bc783efe056ea44069912d12f603100579c7d1aba690880080170b6bb5efcb0 +size 155972 diff --git a/work_files/graphics/fonts/cyrilic_variable.psd b/work_files/graphics/fonts/cyrilic_variable.psd index 791860ffd..2b07c2a7f 100644 --- a/work_files/graphics/fonts/cyrilic_variable.psd +++ b/work_files/graphics/fonts/cyrilic_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f1a169fb2382f03771a022a2d961920cc4a6df74c141473fb7b150920ba77e72 -size 410530 +oid sha256:1b8ba8605fd9049e277ba4c30f74c5a4004d3ec213dc27e2540d38d78608bb98 +size 410644 diff --git a/work_files/graphics/fonts/devanagari_bengali_variable.psd b/work_files/graphics/fonts/devanagari_bengali_variable.psd index 36460e67d..bca5e97af 100644 --- a/work_files/graphics/fonts/devanagari_bengali_variable.psd +++ b/work_files/graphics/fonts/devanagari_bengali_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6c18acefbb452ad6b5f557f02ab12f8d7a3b5e5efd1a39780e7a12e197ca7084 -size 268463 +oid sha256:2ca3b00d017df526b6458b88a592926b07fcad7e8026f9803d87376eeab2a702 +size 274200 diff --git a/work_files/graphics/fonts/devanagari_conjoiners.psd b/work_files/graphics/fonts/devanagari_conjoiners.psd new file mode 100644 index 000000000..071112087 --- /dev/null +++ b/work_files/graphics/fonts/devanagari_conjoiners.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1f43136dfc8c3380fc816b7a7ab551eac9af430f7a7675a17b90a9e303fc17a +size 262591 diff --git a/work_files/graphics/fonts/smallcaps_test.psd b/work_files/graphics/fonts/smallcaps_test.psd new file mode 100644 index 000000000..46061b29f --- /dev/null +++ b/work_files/graphics/fonts/smallcaps_test.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:297d71f12602a4cfb1b15b24eade8acc92931a5765c31a0903ba7974ca89dd8c +size 36188 diff --git a/work_files/graphics/fonts/terrarumsansbitmap_ascii_small.psd b/work_files/graphics/fonts/terrarumsansbitmap_ascii_small.psd deleted file mode 100644 index 7d6867966..000000000 --- a/work_files/graphics/fonts/terrarumsansbitmap_ascii_small.psd +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7a2230b55c6efdd1a7d993478670418968952d9914572a321d497aee47474a9c -size 35906 diff --git a/work_files/graphics/fonts/tsalagi_variable.psd b/work_files/graphics/fonts/tsalagi_variable.psd new file mode 100644 index 000000000..2154b163b --- /dev/null +++ b/work_files/graphics/fonts/tsalagi_variable.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:082a5268139f71295ceeae5c3bbe8cfb0d5c5cecf8facc6dbfa9c07294e5c7c6 +size 136080 diff --git a/work_files/graphics/fonts/unipunct_variable.psd b/work_files/graphics/fonts/unipunct_variable.psd index 45d75388f..feb9e0188 100644 --- a/work_files/graphics/fonts/unipunct_variable.psd +++ b/work_files/graphics/fonts/unipunct_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c88e1f9a381ceb601ec3769f528396e58408f2b8e08b65485c3aababee006eec -size 121155 +oid sha256:4d68c0c4adf6f51314e32586857bfb7e1ad1f51ebd3abec2f0e47592caed2375 +size 121173 diff --git a/work_files/kotlin_delegate_gen.lua b/work_files/kotlin_delegate_gen.lua new file mode 100644 index 000000000..fd476ebb9 --- /dev/null +++ b/work_files/kotlin_delegate_gen.lua @@ -0,0 +1,73 @@ +local names = { +"layerWall", +"layerTerrain", +"layerWire", +"layerWallLowBits", +"layerTerrainLowBits", +"layerThermal", +"spawnX", +"spawnY", +"wallDamages", +"terrainDamages", +"globalLight", +"averageTemperature", +"generatorSeed", +"terrainArray", +"wallArray", +"wireArray", +"damageDataArray" +} + +local valvar = { +"val", +"val", +"val", +"val", +"val", +"val", +"var", +"var", +"val", +"val", +"var", +"var", +"var", +"val", +"val", +"val", +"val" +} + +local types = { + "MapLayer", +"MapLayer", +"MapLayer", +"PairedMapLayer", +"PairedMapLayer", +"MapLayerFloat", +"Int", +"Int", +"HashMap", +"HashMap", +"Color", +"Float", +"Long", +"ByteArray", +"ByteArray", +"ByteArray", +"ByteArray" +} + + + +for i = 1, #types do + n = names[i] + v = valvar[i] + t = types[i] + + if (v == "val") then + print(string.format("%s %s: %s; get() = baseworld.%s", v, n, t, n)) + else + print(string.format("%s %s: %s; get() = baseworld.%s; set(v) { baseworld.%s = v }", v, n, t, n, n)) + end +end \ No newline at end of file