diff --git a/.idea/artifacts/TerrarumBuild.xml b/.idea/artifacts/TerrarumBuild.xml
index 803d9ce94..064909a98 100644
--- a/.idea/artifacts/TerrarumBuild.xml
+++ b/.idea/artifacts/TerrarumBuild.xml
@@ -5,7 +5,10 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/assets/item_kari_16.tga b/assets/item_kari_16.tga
new file mode 100644
index 000000000..d7e6489fd
--- /dev/null
+++ b/assets/item_kari_16.tga
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:87fc02f5eb945dde917c89f95a774ffdaa643201eea3fc6fe1b0b5c43d448d2a
+size 1068
diff --git a/assets/item_kari_32.tga b/assets/item_kari_32.tga
new file mode 100644
index 000000000..b38b0502f
--- /dev/null
+++ b/assets/item_kari_32.tga
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:dfa1ae066824a5faa265f2319f0041367774504ea1bdef04c1559d7d0bd69e3f
+size 4140
diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv
index ca4bcb817..66ac4d85a 100644
--- a/assets/mods/basegame/items/itemid.csv
+++ b/assets/mods/basegame/items/itemid.csv
@@ -4,3 +4,4 @@
"8450";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel"
"8466";"net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire"
"8467";"net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester"
+ "8468";"net.torvald.terrarum.modulebasegame.gameitems.ItemCraftingTable"
diff --git a/assets/mods/dwarventech/virtualcomputer/bfvm.kts b/assets/mods/dwarventech/virtualcomputer/bfvm.kts
index e4e0ec62c..8289634dc 100644
--- a/assets/mods/dwarventech/virtualcomputer/bfvm.kts
+++ b/assets/mods/dwarventech/virtualcomputer/bfvm.kts
@@ -1,3 +1,4 @@
+import sun.misc.Unsafe
import java.io.InputStream
import java.io.OutputStream
@@ -27,6 +28,13 @@ class BFVM(
) {
annotation class Unsigned
+ private val unsafe: Unsafe
+ init {
+ val unsafeConstructor = Unsafe::class.java.getDeclaredConstructor()
+ unsafeConstructor.isAccessible = true
+ unsafe = unsafeConstructor.newInstance()
+ }
+
private val DEBUG = true
@@ -77,8 +85,11 @@ class BFVM(
private var pc = 0 // Program Counter
private var ir = 0 // Instruction Register; does lookahead ahd lookbehind
- private val mem = ByteArray(memSize)
+ private val mem = UnsafePtr(unsafe.allocateMemory(memSize.toLong()), memSize.toLong(), unsafe)
+ init {
+ mem.fillWith(0.toByte())
+ }
/*
Input program is loaded into the memory from index zero.
@@ -189,6 +200,10 @@ class BFVM(
// END OF NOTE (INC_PC is implied)
+ fun quit() {
+ mem.destroy()
+ }
+
fun execute() {
dbgp("Now run...")
while (mem[pc] != CYA) {
@@ -324,6 +339,55 @@ class BFVM(
Optimise level
1 RLE, Set cell to zero
*/
+
+ private class UnsafePtr(pointer: Long, allocSize: Long, val unsafe: sun.misc.Unsafe) {
+ var destroyed = false
+ private set
+
+ var ptr: Long = pointer
+ private set
+
+ var size: Long = allocSize
+ private set
+
+ fun realloc(newSize: Long) {
+ ptr = unsafe.reallocateMemory(ptr, newSize)
+ }
+
+ fun destroy() {
+ if (!destroyed) {
+ unsafe.freeMemory(ptr)
+ destroyed = true
+ }
+ }
+
+ private inline fun checkNullPtr(index: Int) { // ignore what IDEA says and do inline this
+ // commenting out because of the suspected (or minor?) performance impact.
+ // You may break the glass and use this tool when some fucking incomprehensible bugs ("vittujen vitun bugit")
+ // appear (e.g. getting garbage values when it fucking shouldn't)
+ assert(destroyed) { throw NullPointerException("The pointer is already destroyed ($this)") }
+
+ // OOB Check: debugging purposes only -- comment out for the production
+ //if (index !in 0 until size) throw IndexOutOfBoundsException("Index: $index; alloc size: $size")
+ }
+
+ operator fun get(index: Int): Byte {
+ checkNullPtr(index)
+ return unsafe.getByte(ptr + index)
+ }
+
+ operator fun set(index: Int, value: Byte) {
+ checkNullPtr(index)
+ unsafe.putByte(ptr + index, value)
+ }
+
+ fun fillWith(byte: Byte) {
+ unsafe.setMemory(ptr, size, byte)
+ }
+
+ override fun toString() = "0x${ptr.toString(16)} with size $size"
+ override fun equals(other: Any?) = this.ptr == (other as UnsafePtr).ptr
+ }
}
@@ -343,6 +407,8 @@ val factorials = """
[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
"""
+// expected output: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
+
vm.loadProgram(factorials, optimizeLevel = 1)
vm.execute()
-
+vm.quit()
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
index 8f043e016..9d80dcae0 100644
--- a/src/META-INF/MANIFEST.MF
+++ b/src/META-INF/MANIFEST.MF
@@ -1,9 +1,3 @@
Manifest-Version: 1.0
-Class-Path: lib/commons-codec-1.10.jar lib/commons-csv-1.2.jar lib/gdx
- .jar lib/gdx-backend-lwjgl.jar lib/gdx-backend-lwjgl3.jar lib/gdx-bac
- kend-lwjgl-natives.jar lib/gdx-natives.jar lib/groovy-all-2.4.10-indy
- .jar lib/gson-2.5.jar lib/jnlp.jar lib/jogg-0.0.7.jar lib/jopus.jar l
- ib/jorbis-0.0.17.jar lib/kotlin-reflect.jar lib/kotlin-stdlib.jar lib
- /luaj-jse-3.0.1.jar lib/Terrarum_Joise.jar lib/TerrarumSansBitmap.jar
Main-Class: net.torvald.terrarum.AppLoader
diff --git a/src/net/torvald/terrarum/CommonResourcePool.kt b/src/net/torvald/terrarum/CommonResourcePool.kt
index dbea25e53..d09ce656a 100644
--- a/src/net/torvald/terrarum/CommonResourcePool.kt
+++ b/src/net/torvald/terrarum/CommonResourcePool.kt
@@ -19,16 +19,31 @@ object CommonResourcePool {
get() = loadCounter == 0
init {
+ addToLoadingList("itemplaceholder_16") {
+ val t = TextureRegion(Texture("assets/item_kari_16.tga"))
+ t.flip(false, true)
+ /*return*/t
+ }
addToLoadingList("itemplaceholder_24") {
val t = TextureRegion(Texture("assets/item_kari_24.tga"))
t.flip(false, true)
/*return*/t
}
+ addToLoadingList("itemplaceholder_32") {
+ val t = TextureRegion(Texture("assets/item_kari_32.tga"))
+ t.flip(false, true)
+ /*return*/t
+ }
addToLoadingList("itemplaceholder_48") {
val t = TextureRegion(Texture("assets/item_kari_48.tga"))
t.flip(false, true)
/*return*/t
}
+ addToLoadingList("test_texture") {
+ val t = TextureRegion(Texture("assets/test_texture.tga"))
+ t.flip(false, true)
+ /*return*/t
+ }
}
fun addToLoadingList(identifier: String, loadFunction: () -> Any) {
@@ -64,9 +79,10 @@ object CommonResourcePool {
return pool[identifier]!!
}
- fun getAsTextureRegionPack(identifier: String) = get(identifier) as TextureRegionPack
- fun getAsTextureRegion(identifier: String) = get(identifier) as TextureRegion
- fun getAsTexture(identifier: String) = get(identifier) as Texture
+ inline fun getAs(identifier: String) = get(identifier) as T
+ fun getAsTextureRegionPack(identifier: String) = getAs(identifier)
+ fun getAsTextureRegion(identifier: String) = getAs(identifier)
+ fun getAsTexture(identifier: String) = getAs(identifier)
fun dispose() {
pool.forEach { _, u ->
diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt
index a0eed89f3..8020e5eaf 100644
--- a/src/net/torvald/terrarum/DefaultConfig.kt
+++ b/src/net/torvald/terrarum/DefaultConfig.kt
@@ -71,7 +71,7 @@ object DefaultConfig {
jsonObject.addProperty("keymovementaux", Input.Keys.A) // movement-auxiliary, or hookshot
jsonObject.addProperty("keyinventory", Input.Keys.Q)
jsonObject.addProperty("keyinteract", Input.Keys.R)
- jsonObject.addProperty("keyclose", Input.Keys.C)
+ jsonObject.addProperty("keyclose", Input.Keys.C) // this or hard-coded ESC
jsonObject.addProperty("keygamemenu", Input.Keys.TAB)
jsonObject.addProperty("keyquicksel", Input.Keys.SHIFT_LEFT) // pie menu is now LShift because GDX does not read CapsLock
diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt
index 3d066105c..3d56f847b 100644
--- a/src/net/torvald/terrarum/IngameInstance.kt
+++ b/src/net/torvald/terrarum/IngameInstance.kt
@@ -24,6 +24,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
open var consoleHandler: ConsoleWindow = ConsoleWindow()
+ var paused: Boolean = false
+
init {
consoleHandler.setPosition(0, 0)
diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt
index 6492667d6..dbe197f51 100644
--- a/src/net/torvald/terrarum/TitleScreen.kt
+++ b/src/net/torvald/terrarum/TitleScreen.kt
@@ -116,7 +116,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var logo: TextureRegion
- val uiContainer = ArrayList()
+ val uiContainer = ArrayList()
private lateinit var uiMenu: UICanvas
private lateinit var worldFBO: FrameBuffer
@@ -226,7 +226,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// update UIs //
- uiContainer.forEach { it.update(delta) }
+ uiContainer.forEach { it?.update(delta) }
}
fun renderScreen() {
@@ -325,42 +325,42 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
class TitleScreenController(val screen: TitleScreen) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
+ screen.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) }
return true
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- screen.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
+ screen.uiContainer.forEach { it?.mouseMoved(screenX, screenY) }
return true
}
override fun keyTyped(character: Char): Boolean {
- screen.uiContainer.forEach { it.keyTyped(character) }
+ screen.uiContainer.forEach { it?.keyTyped(character) }
return true
}
override fun scrolled(amount: Int): Boolean {
- screen.uiContainer.forEach { it.scrolled(amount) }
+ screen.uiContainer.forEach { it?.scrolled(amount) }
return true
}
override fun keyUp(keycode: Int): Boolean {
- screen.uiContainer.forEach { it.keyUp(keycode) }
+ screen.uiContainer.forEach { it?.keyUp(keycode) }
return true
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
+ screen.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) }
return true
}
override fun keyDown(keycode: Int): Boolean {
- screen.uiContainer.forEach { it.keyDown(keycode) }
+ screen.uiContainer.forEach { it?.keyDown(keycode) }
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- screen.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
+ screen.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) }
return true
}
}
diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt
index a8483d88e..ea5ec1ed4 100644
--- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt
+++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt
@@ -56,17 +56,18 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (terrarumIngame.canPlayerControl) {
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
- if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
+ if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
+
+ if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
+ Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
- if (
- Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
- Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
terrarumIngame.worldPrimaryClickStart(AppLoader.UPDATE_RATE)
}
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary")) {
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE)
}*/
}
+
}
@@ -96,7 +97,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
}
- terrarumIngame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
+ terrarumIngame.uiContainer.forEach { it?.keyDown(keycode) } // for KeyboardControlled UIcanvases
// Debug UIs
if (keycode == Input.Keys.GRAVE) {
@@ -122,7 +123,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
terrarumIngame.uiQuickBar.setAsOpen()
}
- terrarumIngame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
+ terrarumIngame.uiContainer.forEach { it?.keyUp(keycode) } // for KeyboardControlled UIcanvases
// screenshot key
@@ -133,12 +134,12 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
override fun keyTyped(character: Char): Boolean {
- terrarumIngame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
+ terrarumIngame.uiContainer.forEach { if (it?.isVisible == true) it.keyTyped(character) }
return true
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- terrarumIngame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
+ terrarumIngame.uiContainer.forEach { it?.mouseMoved(screenX, screenY) }
return true
}
@@ -146,7 +147,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (terrarumIngame.canPlayerControl) {
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
- if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
+ if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if (
button == AppLoader.getConfigInt("mouseprimary") ||
@@ -160,7 +161,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
- terrarumIngame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
+ terrarumIngame.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
return true
}
@@ -176,17 +177,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
}
}
- terrarumIngame.uiContainer.forEach { it.scrolled(amount) }
+ terrarumIngame.uiContainer.forEach { it?.scrolled(amount) }
return true
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- terrarumIngame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
+ terrarumIngame.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) }
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- terrarumIngame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
+ terrarumIngame.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) }
return true
}
diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
index dca26843d..9c6be6d6b 100644
--- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
+++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
@@ -115,7 +115,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val uiPenMenu = UIBuildingMakerPenMenu(this)
- val uiContainer = ArrayList()
+ val uiContainer = ArrayList()
private val pensMustShowSelection = arrayOf(
PENMODE_MARQUEE, PENMODE_MARQUEE_ERASE
@@ -353,8 +353,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
actorNowPlaying?.update(delta)
var overwriteMouseOnUI = false
uiContainer.forEach {
- it.update(delta)
- if (it.isVisible && it.mouseUp) {
+ it?.update(delta)
+ if (it?.isVisible == true && it?.mouseUp == true) {
overwriteMouseOnUI = true
}
}
@@ -502,43 +502,43 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
+ screen.uiContainer.forEach { it?.touchUp(screenX, screenY, pointer, button) }
screen.tappedOnUI = false
return true
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- screen.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
+ screen.uiContainer.forEach { it?.mouseMoved(screenX, screenY) }
return true
}
override fun keyTyped(character: Char): Boolean {
- screen.uiContainer.forEach { it.keyTyped(character) }
+ screen.uiContainer.forEach { it?.keyTyped(character) }
return true
}
override fun scrolled(amount: Int): Boolean {
- screen.uiContainer.forEach { it.scrolled(amount) }
+ screen.uiContainer.forEach { it?.scrolled(amount) }
return true
}
override fun keyUp(keycode: Int): Boolean {
- screen.uiContainer.forEach { it.keyUp(keycode) }
+ screen.uiContainer.forEach { it?.keyUp(keycode) }
return true
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
+ screen.uiContainer.forEach { it?.touchDragged(screenX, screenY, pointer) }
return true
}
override fun keyDown(keycode: Int): Boolean {
- screen.uiContainer.forEach { it.keyDown(keycode) }
+ screen.uiContainer.forEach { it?.keyDown(keycode) }
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- screen.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
+ screen.uiContainer.forEach { it?.touchDown(screenX, screenY, pointer, button) }
return true
}
}
diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
index bb2b1d878..733797fe5 100644
--- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
+++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
@@ -60,7 +60,7 @@ object IngameRenderer : Disposable {
private var player: ActorWithBody? = null
- var uiListToDraw = ArrayList()
+ var uiListToDraw = ArrayList()
const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
@@ -186,7 +186,7 @@ object IngameRenderer : Disposable {
actorsRenderOverlay: List? = null,
particlesContainer : CircularArray? = null,
player: ActorWithBody? = null,
- uisToDraw: ArrayList? = null
+ uisToDraw: ArrayList? = null
) {
renderingActorsCount = (actorsRenderBehind?.size ?: 0) +
(actorsRenderMiddle?.size ?: 0) +
@@ -195,7 +195,7 @@ object IngameRenderer : Disposable {
(actorsRenderOverlay?.size ?: 0)
//renderingParticleCount = particlesContainer?.size ?: 0
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
- renderingUIsCount = ((uisToDraw?.map { it.isVisible.toInt() }) ?: listOf(0)).sum()
+ renderingUIsCount = ((uisToDraw?.map { (it?.isVisible ?: false).toInt() }) ?: listOf(0)).sum()
if (uisToDraw != null) {
@@ -327,7 +327,7 @@ object IngameRenderer : Disposable {
batch.color = Color.WHITE
uiListToDraw.forEach {
- it.render(batch, camera)
+ it?.render(batch, camera)
}
}
diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
index fc52ef317..b01197f84 100644
--- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
+++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
@@ -58,7 +58,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
//val actorContainerActive = ArrayList(ACTORCONTAINER_INITIAL_SIZE)
//val actorContainerInactive = ArrayList(ACTORCONTAINER_INITIAL_SIZE)
val particlesContainer = CircularArray(PARTICLES_MAX)
- val uiContainer = ArrayList()
+ val uiContainer = ArrayList()
private val actorsRenderBehind = ArrayList(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderMiddle = ArrayList(ACTORCONTAINER_INITIAL_SIZE)
@@ -105,11 +105,22 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiPieMenu: UICanvas
lateinit var uiQuickBar: UICanvas
lateinit var uiInventoryPlayer: UICanvas
+ // this will not allow multiple fixture UIs from popping up (does not prevent them actually being open)
+ // because UI updating and rendering is whitelist-operated
+ var uiFixture: UICanvas? = null
+ set(value) {
+ printdbg(this, "uiFixture change: $uiFixture -> $value")
+ field?.let { it.setAsClose() }
+ value?.let { uiFixturesHistory.add(it) }
+ field = value
+ }
lateinit var uiInventoryContainer: UICanvas
lateinit var uiVitalPrimary: UICanvas
lateinit var uiVitalSecondary: UICanvas
lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
+ private val uiFixturesHistory = HashSet()
+
private lateinit var uiBasicInfo: UICanvas
private lateinit var uiWatchTierOne: UICanvas
@@ -118,13 +129,13 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var uiCheatMotherfuckerNootNoot: UICheatDetected
// UI aliases
- lateinit var uiAliases: ArrayList
+ lateinit var uiAliases: ArrayList
private set
- lateinit var uiAliasesPausing: ArrayList
+ lateinit var uiAliasesPausing: ArrayList
private set
- inline val paused: Boolean
- get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
+ //var paused: Boolean = false
+ //get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
/**
* Set to false if UI is opened; set to true if UI is closed.
*/
@@ -313,7 +324,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiQuickBar.setPosition((AppLoader.screenW - uiQuickBar.width) / 2, AppLoader.getTvSafeGraphicsHeight())
// pie menu
- uiPieMenu = uiQuickslotPie()
+ uiPieMenu = UIQuickslotPie()
uiPieMenu.setPosition(AppLoader.halfScreenW, AppLoader.halfScreenH)
// vital metre
@@ -362,6 +373,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiAliasesPausing = arrayListOf(
uiInventoryPlayer,
//uiInventoryContainer,
+ uiFixture,
consoleHandler,
uiCheatMotherfuckerNootNoot
)
@@ -387,10 +399,38 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}// END enter
override fun worldPrimaryClickStart(delta: Float) {
- val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
- val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
- if (consumptionSuccessful)
- actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
+ // bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
+ var uiOpened = false
+ val actorsUnderMouse: List = WorldSimulator.getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance()
+ if (actorsUnderMouse.size > 1) {
+ AppLoader.printdbgerr(this, "Multiple fixtures at world coord ${Terrarum.mouseX}, ${Terrarum.mouseY}")
+ }
+ // scan for the one with non-null UI.
+ // what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
+ for (kk in 0 until actorsUnderMouse.size) {
+ actorsUnderMouse[kk].mainUI?.let {
+ uiOpened = true
+
+ println("ui = $it")
+
+ // whitelist the UI
+ // unlisting is done when renderGame() is called, in which, if the UI is 'isClosed', it'll be unlisted
+ uiFixture = it
+
+ it.setPosition(0, 0)
+ it.setAsOpen()
+ }
+ break
+ }
+
+
+ // don't want to open the UI and use the item at the same time, would ya?
+ if (!uiOpened) {
+ val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
+ val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
+ if (consumptionSuccessful)
+ actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
+ }
}
override fun worldPrimaryClickEnd(delta: Float) {
@@ -553,6 +593,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
AVTracker.update()
ActorsList.update()
}
+
+ //println("paused = $paused")
}
@@ -560,7 +602,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(getCanonicalTitle())
filterVisibleActors()
- uiContainer.forEach { it.update(Gdx.graphics.rawDeltaTime) }
+ uiContainer.forEach { it?.update(Gdx.graphics.rawDeltaTime) }
+ // deal with the uiFixture being closed
+ if (uiFixture?.isClosed == true) {
+ uiFixture = null
+ }
IngameRenderer.invoke(
paused,
@@ -911,11 +957,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
particlesContainer.add(particle)
}
- fun addUI(ui: UICanvas) {
+ fun addUI(ui: UICanvas?) {
// check for exact duplicates
if (uiContainer.contains(ui)) {
throw IllegalArgumentException(
- "Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
+ "Exact copy of the UI already exists: The instance of ${ui?.javaClass?.simpleName}"
)
}
@@ -954,7 +1000,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
override fun hide() {
- uiContainer.forEach { it.handler.dispose() }
+ uiContainer.forEach { it?.handler?.dispose() }
}
@@ -1014,6 +1060,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.forEach { it.dispose() }
uiContainer.forEach {
+ it?.handler?.dispose()
+ it?.dispose()
+ }
+ uiFixturesHistory.forEach {
it.handler.dispose()
it.dispose()
}
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt
index 67c539b9b..ecc17f053 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt
@@ -7,13 +7,19 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
+import net.torvald.terrarum.ui.UICanvas
/**
* Created by minjaesong on 2016-06-17.
*/
-open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0), renderOrder: RenderOrder = RenderOrder.MIDDLE) :
+open class FixtureBase(
+ blockBox0: BlockBox,
+ val blockBoxProps: BlockBoxProps = BlockBoxProps(0),
+ renderOrder: RenderOrder = RenderOrder.MIDDLE,
+ val mainUI: UICanvas? = null
+
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
- ActorWBMovable(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
+) : ActorWBMovable(renderOrder, immobileBody = true, usePhysics = false), CuedByTerrainChange {
var blockBox: BlockBox = blockBox0
protected set // something like TapestryObject will want to redefine this
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt
new file mode 100644
index 000000000..287a5db05
--- /dev/null
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt
@@ -0,0 +1,78 @@
+package net.torvald.terrarum.modulebasegame.gameactors
+
+import com.badlogic.gdx.Gdx
+import com.badlogic.gdx.Input
+import com.badlogic.gdx.graphics.Camera
+import com.badlogic.gdx.graphics.Color
+import com.badlogic.gdx.graphics.g2d.SpriteBatch
+import net.torvald.terrarum.AppLoader
+import net.torvald.terrarum.Second
+import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.gameactors.AVKey
+import net.torvald.terrarum.ui.UICanvas
+import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
+
+/**
+ * Created by minjaesong on 2019-07-08.
+ */
+internal class FixtureCraftingTable : FixtureBase(
+ BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
+ mainUI = UICraftingTable
+) {
+
+ init {
+ setHitboxDimension(16, 16, 0, 0)
+
+ makeNewSprite(TextureRegionPack(AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
+ sprite!!.setRowsAndFrames(1, 1)
+
+ actorValue[AVKey.BASEMASS] = MASS
+ }
+
+ companion object {
+ const val MASS = 2.0
+ }
+}
+
+
+internal object UICraftingTable : UICanvas() {
+ override var width = 512
+ override var height = 512
+ override var openCloseTime: Second = 0.05f
+
+ override fun updateUI(delta: Float) {
+
+ }
+
+ override fun renderUI(batch: SpriteBatch, camera: Camera) {
+ println("TurdTurdTurdTurd")
+
+ batch.color = Color.WHITE
+ batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
+
+
+ if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
+ handler.setAsClose()
+ }
+ }
+
+ override fun doOpening(delta: Float) {
+ Terrarum.ingame?.paused = true
+ println("You hit me!")
+ }
+
+ override fun doClosing(delta: Float) {
+ Terrarum.ingame?.paused = false
+ }
+
+ override fun endOpening(delta: Float) {
+ }
+
+ override fun endClosing(delta: Float) {
+ }
+
+
+
+ override fun dispose() {
+ }
+}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt
index f91344fec..7e7df8376 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt
@@ -34,6 +34,10 @@ internal class FixtureTikiTorch : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1,
makeNewSprite(TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32))
sprite!!.setRowsAndFrames(1, 1)
- actorValue[AVKey.BASEMASS] = 1.0
+ actorValue[AVKey.BASEMASS] = MASS
+ }
+
+ companion object {
+ const val MASS = 1.0
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt
index 8418a97ec..dd129acdf 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt
@@ -89,6 +89,7 @@ object PlayerBuilderSigrid {
inventory.add(8450) // steel pick
inventory.add(8466, 9995) // wire piece
inventory.add(8467, 385930603) // test tiki torch
+ inventory.add(8468, 95) // crafting table
inventory.add(9000) // TEST water bucket
inventory.add(9001) // TEST lava bucket
}
diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemCraftingTable.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemCraftingTable.kt
new file mode 100644
index 000000000..2cd81cf14
--- /dev/null
+++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemCraftingTable.kt
@@ -0,0 +1,40 @@
+package net.torvald.terrarum.modulebasegame.gameitems
+
+import com.badlogic.gdx.graphics.g2d.TextureRegion
+import net.torvald.terrarum.AppLoader
+import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.gameitem.GameItem
+import net.torvald.terrarum.gameitem.ItemID
+import net.torvald.terrarum.itemproperties.Material
+import net.torvald.terrarum.modulebasegame.gameactors.FixtureCraftingTable
+import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
+
+/**
+ * Created by minjaesong on 2019-07-08.
+ */
+class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
+
+ override var dynamicID: ItemID = originalID
+ override val originalName = "ITEM_CRAFTING_TABLE"
+ override var baseMass = FixtureTikiTorch.MASS
+ override var stackable = true
+ override var inventoryCategory = Category.FIXTURE
+ override val isUnique = false
+ override val isDynamic = false
+ override val material = Material()
+ override val itemImage: TextureRegion?
+ get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16")
+ override var baseToolSize: Double? = baseMass
+
+ init {
+ equipPosition = EquipPosition.HAND_GRIP
+ }
+
+ override fun startPrimaryUse(delta: Float): Boolean {
+ val item = FixtureCraftingTable()
+
+ return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
+ // return true when placed, false when cannot be placed
+ }
+
+}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt
index 372db0295..318734f02 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt
@@ -15,7 +15,7 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "Tiki Torch"
- override var baseMass = 1.0
+ override var baseMass = FixtureTikiTorch.MASS
override var stackable = true
override var inventoryCategory = Category.FIXTURE
override val isUnique = false
@@ -30,9 +30,9 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
}
override fun startPrimaryUse(delta: Float): Boolean {
- val torch = FixtureTikiTorch()
+ val item = FixtureTikiTorch()
- return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1)
+ return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed
}
diff --git a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt
index 326dd1ad1..7ec1d1797 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldSimulator.kt
@@ -70,7 +70,7 @@ object WorldSimulator {
operator fun invoke(player: ActorHumanoid?, delta: Float) {
// build the r-tree that will be used during a single frame of updating
actorsRTree = PRTree(actorMBRConverter, 24)
- actorsRTree.load(ingame.actorContainerActive.filter { it is ActorWithBody })
+ actorsRTree.load(ingame.actorContainerActive.filterIsInstance())
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
index b15c884df..45aaf4d86 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
@@ -48,6 +48,7 @@ class UICheatDetected : UICanvas() {
}
override fun doOpening(delta: Float) {
+ Terrarum.ingame?.paused = true
}
override fun doClosing(delta: Float) {
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
index 9ed9f3726..95ab245f4 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
@@ -544,10 +544,12 @@ class UIInventoryFull(
override fun doOpening(delta: Float) {
+ Terrarum.ingame?.paused = true
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
+ Terrarum.ingame?.paused = false
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
similarity index 99%
rename from src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt
rename to src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
index c99df42f4..bc7b5ef79 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
@@ -20,7 +20,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-07-20.
*/
-class uiQuickslotPie : UICanvas() {
+class UIQuickslotPie : UICanvas() {
private val cellSize = ItemSlotImageFactory.slotImage.tileW
private val slotCount = UIQuickslotBar.SLOT_COUNT
diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
index 2575f5838..6df2e5118 100644
--- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt
+++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
@@ -5,6 +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.AppLoader
+import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.CommandInterpreter
import net.torvald.terrarum.fillRect
@@ -186,6 +187,7 @@ class ConsoleWindow : UICanvas() {
}
override fun doOpening(delta: Float) {
+ Terrarum.ingame?.paused = true
/*openingTimeCounter += delta
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
-height.toFloat(), 0f
@@ -193,6 +195,7 @@ class ConsoleWindow : UICanvas() {
}
override fun doClosing(delta: Float) {
+ Terrarum.ingame?.paused = false
/*openingTimeCounter += delta
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
0f, -height.toFloat()
diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt
index 7cb12c28f..94dd4c02f 100644
--- a/src/net/torvald/terrarum/ui/UICanvas.kt
+++ b/src/net/torvald/terrarum/ui/UICanvas.kt
@@ -365,4 +365,5 @@ abstract class UICanvas(
}
}
+ override fun toString(): String = "${this.javaClass.simpleName}@${this.hashCode().toString(16)}"
}
diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt
index 8d5cd6ef8..34144f7d4 100644
--- a/src/net/torvald/terrarum/ui/UIHandler.kt
+++ b/src/net/torvald/terrarum/ui/UIHandler.kt
@@ -88,7 +88,7 @@ class UIHandler(//var UI: UICanvas,
fun addSubUI(ui: UICanvas) {
if (subUIs.contains(ui))
throw IllegalArgumentException(
- "Exact copy of the UI already exists: The instance of ${ui.javaClass.simpleName}"
+ "Exact copy of the UI already exists: The instance of $ui"
)
subUIs.add(ui)
@@ -136,6 +136,7 @@ class UIHandler(//var UI: UICanvas,
// println("UIHandler.opening ${UI.javaClass.simpleName}")
}
else {
+ ui.doOpening(0f)
ui.endOpening(delta)
isOpening = false
isClosing = false
@@ -156,6 +157,7 @@ class UIHandler(//var UI: UICanvas,
// println("UIHandler.closing ${UI.javaClass.simpleName}")
}
else {
+ ui.doClosing(0f)
ui.endClosing(delta)
isClosing = false
isOpening = false
@@ -218,7 +220,7 @@ class UIHandler(//var UI: UICanvas,
}
/**
- * Send OPEN signal to the attached UI.
+ * Send OPEN signal to the attached UI. The actual job is done when the handler is being updated.
*/
fun setAsOpen() {
if (alwaysVisible && !doNotWarnConstant) {
@@ -235,7 +237,7 @@ class UIHandler(//var UI: UICanvas,
}
/**
- * Send CLOSE signal to the attached UI.
+ * Send CLOSE signal to the attached UI. The actual job is done when the handler is being updated.
*/
fun setAsClose() {
if (alwaysVisible && !doNotWarnConstant) {
diff --git a/src/net/torvald/util/SortedArrayList.kt b/src/net/torvald/util/SortedArrayList.kt
index 3177fa6cb..e5ec86a24 100644
--- a/src/net/torvald/util/SortedArrayList.kt
+++ b/src/net/torvald/util/SortedArrayList.kt
@@ -10,7 +10,7 @@ import java.util.concurrent.locks.ReentrantLock
*/
class SortedArrayList>(initialSize: Int = 10) {
- private val arrayList = ArrayList(initialSize)
+ val arrayList = ArrayList(initialSize)
/**
*/
@@ -37,9 +37,9 @@ class SortedArrayList>(initialSize: Int = 10) {
val size: Int
get() = arrayList.size
- fun removeAt(index: Int) = arrayList.removeAt(index)
- fun remove(element: T) = arrayList.remove(element)
- fun removeLast() = arrayList.removeAt(arrayList.size - 1)
+ inline fun removeAt(index: Int) = arrayList.removeAt(index)
+ inline fun remove(element: T) = arrayList.remove(element)
+ inline fun removeLast() = arrayList.removeAt(arrayList.size - 1)
operator fun get(index: Int) = arrayList[index]
fun getOrNull(index: Int?) = if (index == null) null else get(index)
@@ -100,18 +100,21 @@ class SortedArrayList>(initialSize: Int = 10) {
*/
fun > searchFor(searchQuery: R, searchHow: (T) -> R): T? = getOrNull(searchForIndex(searchQuery, searchHow))
- fun iterator() = arrayList.iterator()
- fun forEach(action: (T) -> Unit) = arrayList.forEach(action)
- fun forEachIndexed(action: (Int, T) -> Unit) = arrayList.forEachIndexed(action)
+ inline fun iterator() = arrayList.iterator()
+ inline fun forEach(action: (T) -> Unit) = arrayList.forEach(action)
+ inline fun forEachIndexed(action: (Int, T) -> Unit) = arrayList.forEachIndexed(action)
- fun map(transformation: (T) -> R) = arrayList.map(transformation)
+ inline fun map(transformation: (T) -> R) = arrayList.map(transformation)
- fun filter(function: (T) -> Boolean): List {
+ /*fun filter(function: (T) -> Boolean): List {
val retList = ArrayList() // sorted-ness is preserved
this.arrayList.forEach { if (function(it)) retList.add(it as R) }
return retList
- }
+ }*/
+ inline fun filter(function: (T) -> Boolean) = arrayList.filter(function)
+
+ inline fun filterIsInstance() = arrayList.filterIsInstance()
/**
* Select one unsorted element from the array and put it onto the sorted spot.