diff --git a/.gitignore b/.gitignore index 77ac9b319..b69f7764b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ out/* bin/* build/* .gradle/* +TerrarumBuild.jar # Java native errors hs_err_pid* diff --git a/TerrarumBuild.jar b/TerrarumBuild.jar deleted file mode 100644 index 065b98f1b..000000000 Binary files a/TerrarumBuild.jar and /dev/null differ diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index ea5ec1ed4..5bdd24883 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -56,7 +56,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 == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? + if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { @@ -97,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) { @@ -123,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 @@ -134,12 +134,12 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() { } override fun keyTyped(character: Char): Boolean { - terrarumIngame.uiContainer.forEach { if (it?.isVisible == true) it.keyTyped(character) } + terrarumIngame.uiContainer.forEach { if (it.isVisible) 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 } @@ -147,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 == true || it?.isOpened == true) && it?.mouseUp == true) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? + if (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? if ( button == AppLoader.getConfigInt("mouseprimary") || @@ -161,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 } @@ -177,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/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 733797fe5..db62a6133 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -21,6 +21,7 @@ import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.worlddrawer.* import net.torvald.util.CircularArray import javax.swing.JFileChooser +import kotlin.system.exitProcess /** * This will be rendered to a postprocessor FBO. @@ -60,7 +61,7 @@ object IngameRenderer : Disposable { private var player: ActorWithBody? = null - var uiListToDraw = ArrayList() + var uiListToDraw: List = arrayListOf() const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred @@ -112,19 +113,19 @@ object IngameRenderer : Disposable { if (!shaderBlendGlow.isCompiled) { Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log) - System.exit(1) + exitProcess(1) } if (AppLoader.getConfigBoolean("fxdither")) { if (!shaderBayer.isCompiled) { Gdx.app.log("shaderBayer", shaderBayer.log) - System.exit(1) + exitProcess(1) } if (!shaderSkyboxFill.isCompiled) { Gdx.app.log("shaderSkyboxFill", shaderSkyboxFill.log) - System.exit(1) + exitProcess(1) } } @@ -186,7 +187,7 @@ object IngameRenderer : Disposable { actorsRenderOverlay: List? = null, particlesContainer : CircularArray? = null, player: ActorWithBody? = null, - uisToDraw: ArrayList? = null + uisToDraw: List? = null ) { renderingActorsCount = (actorsRenderBehind?.size ?: 0) + (actorsRenderMiddle?.size ?: 0) + diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index b01197f84..e40088fbf 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,8 +105,15 @@ 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 + /** + * This is a dedicated property for the fixtures' UI. + * + * When it's not null, the UI will be updated and rendered; + * when the UI is closed, it'll be replaced with a null value. + * + * 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") @@ -129,9 +136,9 @@ 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 //var paused: Boolean = false @@ -373,7 +380,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { uiAliasesPausing = arrayListOf( uiInventoryPlayer, //uiInventoryContainer, - uiFixture, consoleHandler, uiCheatMotherfuckerNootNoot ) @@ -401,6 +407,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { override fun worldPrimaryClickStart(delta: Float) { // bring up the UIs of the fixtures (e.g. crafting menu from a crafting table) var uiOpened = false + + // TODO actorsUnderMouse: support ROUNDWORLD 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}") @@ -411,10 +419,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { 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 + // property 'uiFixture' is a dedicated property that the TerrarumIngame recognises. + // when it's not null, the UI will be updated and rendered + // when the UI is closed, it'll be replaced with a null value uiFixture = it it.setPosition(0, 0) @@ -559,7 +566,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { // determine whether the inactive actor should be activated wakeDormantActors() // determine whether the actor should keep being activated or be dormant - KillOrKnockdownActors() + killOrKnockdownActors() updateActors(delta) particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) } // TODO thread pool(?) @@ -602,11 +609,10 @@ 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) } + uiFixture?.update(Gdx.graphics.rawDeltaTime) // deal with the uiFixture being closed - if (uiFixture?.isClosed == true) { - uiFixture = null - } + if (uiFixture?.isClosed == true) { uiFixture = null } IngameRenderer.invoke( paused, @@ -617,7 +623,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { visibleActorsRenderOverlay, particlesContainer, actorNowPlaying, - uiContainer + uiContainer + uiFixture ) } @@ -689,7 +695,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { * If the actor must be dormant, the target actor will be put to the list specifically for them. * if the actor is not to be dormant, it will be just ignored. */ - fun KillOrKnockdownActors() { + fun killOrKnockdownActors() { var actorContainerSize = actorContainerActive.size var i = 0 while (i < actorContainerSize) { // loop through actorContainerActive @@ -957,11 +963,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}" ) } @@ -1000,7 +1006,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { } override fun hide() { - uiContainer.forEach { it?.handler?.dispose() } + uiContainer.forEach { it.handler.dispose() } } @@ -1060,8 +1066,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { actorsRenderOverlay.forEach { it.dispose() } uiContainer.forEach { - it?.handler?.dispose() - it?.dispose() + it.handler.dispose() + it.dispose() } uiFixturesHistory.forEach { it.handler.dispose() diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt index 287a5db05..f8f8a511e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt @@ -45,7 +45,6 @@ internal object UICraftingTable : UICanvas() { } override fun renderUI(batch: SpriteBatch, camera: Camera) { - println("TurdTurdTurdTurd") batch.color = Color.WHITE batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f) @@ -58,7 +57,6 @@ internal object UICraftingTable : UICanvas() { override fun doOpening(delta: Float) { Terrarum.ingame?.paused = true - println("You hit me!") } override fun doClosing(delta: Float) { diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index b7bbbeca7..64e9e424d 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -21,6 +21,7 @@ import net.torvald.terrarum.gameworld.BlockAddress import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.realestate.LandUtil +import kotlin.system.exitProcess /** * Sub-portion of IngameRenderer. You are not supposed to directly deal with this. @@ -467,7 +468,7 @@ object LightmapRenderer { } System.err.println("\nMINIMINIDUMP END") - System.exit(1) + exitProcess(1) } if (thisFluid.type != Fluid.NULL) {