mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
trying to make fixtures with UIs working, was not successful
This commit is contained in:
5
.idea/artifacts/TerrarumBuild.xml
generated
5
.idea/artifacts/TerrarumBuild.xml
generated
@@ -5,7 +5,10 @@
|
||||
<element id="directory" name="META-INF">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
|
||||
</element>
|
||||
<element id="module-output" name="Terrarum_renewed" />
|
||||
<element id="library" level="project" name="KotlinJavaRuntime" />
|
||||
<element id="library" level="project" name="lib" />
|
||||
<element id="module-output" name="ingamemodule_basegame" />
|
||||
<element id="module-output" name="terrarum" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
BIN
assets/item_kari_16.tga
LFS
Normal file
BIN
assets/item_kari_16.tga
LFS
Normal file
Binary file not shown.
BIN
assets/item_kari_32.tga
LFS
Normal file
BIN
assets/item_kari_32.tga
LFS
Normal file
Binary file not shown.
@@ -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"
|
||||
|
||||
|
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 <reified T> getAs(identifier: String) = get(identifier) as T
|
||||
fun getAsTextureRegionPack(identifier: String) = getAs<TextureRegionPack>(identifier)
|
||||
fun getAsTextureRegion(identifier: String) = getAs<TextureRegion>(identifier)
|
||||
fun getAsTexture(identifier: String) = getAs<Texture>(identifier)
|
||||
|
||||
fun dispose() {
|
||||
pool.forEach { _, u ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
lateinit var logo: TextureRegion
|
||||
|
||||
val uiContainer = ArrayList<UICanvas>()
|
||||
val uiContainer = ArrayList<UICanvas?>()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
val uiPenMenu = UIBuildingMakerPenMenu(this)
|
||||
|
||||
|
||||
val uiContainer = ArrayList<UICanvas>()
|
||||
val uiContainer = ArrayList<UICanvas?>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ object IngameRenderer : Disposable {
|
||||
|
||||
private var player: ActorWithBody? = null
|
||||
|
||||
var uiListToDraw = ArrayList<UICanvas>()
|
||||
var uiListToDraw = ArrayList<UICanvas?>()
|
||||
|
||||
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<ActorWithBody>? = null,
|
||||
particlesContainer : CircularArray<ParticleBase>? = null,
|
||||
player: ActorWithBody? = null,
|
||||
uisToDraw: ArrayList<UICanvas>? = null
|
||||
uisToDraw: ArrayList<UICanvas?>? = 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
//val actorContainerActive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
||||
val uiContainer = ArrayList<UICanvas>()
|
||||
val uiContainer = ArrayList<UICanvas?>()
|
||||
|
||||
private val actorsRenderBehind = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
private val actorsRenderMiddle = ArrayList<ActorWithBody>(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<UICanvas>()
|
||||
|
||||
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<UICanvas>
|
||||
lateinit var uiAliases: ArrayList<UICanvas?>
|
||||
private set
|
||||
lateinit var uiAliasesPausing: ArrayList<UICanvas>
|
||||
lateinit var uiAliasesPausing: ArrayList<UICanvas?>
|
||||
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<FixtureBase> = WorldSimulator.getActorsAt(Terrarum.mouseX, Terrarum.mouseY).filterIsInstance<FixtureBase>()
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ActorWithBody>())
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class UICheatDetected : UICanvas() {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.paused = true
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
@@ -365,4 +365,5 @@ abstract class UICanvas(
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = "${this.javaClass.simpleName}@${this.hashCode().toString(16)}"
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.concurrent.locks.ReentrantLock
|
||||
*/
|
||||
class SortedArrayList<T: Comparable<T>>(initialSize: Int = 10) {
|
||||
|
||||
private val arrayList = ArrayList<T>(initialSize)
|
||||
val arrayList = ArrayList<T>(initialSize)
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -37,9 +37,9 @@ class SortedArrayList<T: Comparable<T>>(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<T: Comparable<T>>(initialSize: Int = 10) {
|
||||
*/
|
||||
fun <R: Comparable<R>> 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 <R> map(transformation: (T) -> R) = arrayList.map(transformation)
|
||||
inline fun <reified R> map(transformation: (T) -> R) = arrayList.map(transformation)
|
||||
|
||||
fun <R> filter(function: (T) -> Boolean): List<R> {
|
||||
/*fun <R> filter(function: (T) -> Boolean): List<R> {
|
||||
val retList = ArrayList<R>() // 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 <reified R> filterIsInstance() = arrayList.filterIsInstance<R>()
|
||||
|
||||
/**
|
||||
* Select one unsorted element from the array and put it onto the sorted spot.
|
||||
|
||||
Reference in New Issue
Block a user