diff --git a/.idea/markdown-exported-files.xml b/.idea/markdown-exported-files.xml new file mode 100644 index 000000000..5d1f1293c --- /dev/null +++ b/.idea/markdown-exported-files.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3e53d74a6..8409d10a9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -38,7 +38,7 @@ - + \ No newline at end of file diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 7c01c707e..ca708d1e1 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -13,20 +13,19 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.ScreenUtils; import com.github.strikerx3.jxinput.XInputDevice; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import net.torvald.getcpuname.GetCpuName; -import net.torvald.terrarum.blockstats.MinimapComposer; import net.torvald.terrarum.controller.GdxControllerAdapter; import net.torvald.terrarum.controller.TerrarumController; import net.torvald.terrarum.controller.XinputControllerAdapter; import net.torvald.terrarum.gamecontroller.KeyToggler; import net.torvald.terrarum.imagefont.TinyAlphNum; import net.torvald.terrarum.modulebasegame.Ingame; -import net.torvald.terrarum.modulebasegame.IngameRenderer; import net.torvald.terrarum.utils.JsonFetcher; import net.torvald.terrarum.utils.JsonWriter; import net.torvald.terrarum.worlddrawer.BlocksDrawer; @@ -286,6 +285,7 @@ public class AppLoader implements ApplicationListener { public static CommonResourcePool resourcePool; public static HashSet tempFilePool = new HashSet(); + public static HashSet disposableSingletonsPool = new HashSet(); @Override public void create() { @@ -517,11 +517,12 @@ public class AppLoader implements ApplicationListener { screen.dispose(); } - IngameRenderer.INSTANCE.dispose(); - PostProcessor.INSTANCE.dispose(); - MinimapComposer.INSTANCE.dispose(); + //IngameRenderer.INSTANCE.dispose(); + //PostProcessor.INSTANCE.dispose(); + //MinimapComposer.INSTANCE.dispose(); + //FloatDrawer.INSTANCE.dispose(); - Terrarum.INSTANCE.dispose(); + //Terrarum.INSTANCE.dispose(); shaderBayerSkyboxFill.dispose(); shaderHicolour.dispose(); @@ -539,6 +540,8 @@ public class AppLoader implements ApplicationListener { textureWhiteCircle.dispose(); logo.getTexture().dispose(); + disposableSingletonsPool.forEach(Disposable::dispose); + ModMgr.INSTANCE.disposeMods(); deleteTempfiles(); diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt index a08cca457..e3b90b3e4 100644 --- a/src/net/torvald/terrarum/PostProcessor.kt +++ b/src/net/torvald/terrarum/PostProcessor.kt @@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.math.Matrix4 +import com.badlogic.gdx.utils.Disposable import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.ui.BasicDebugInfoWindow import net.torvald.terrarum.worlddrawer.BlocksDrawer @@ -18,7 +19,7 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer /** * Must be called by the App Loader */ -object PostProcessor { +object PostProcessor : Disposable { private lateinit var batch: SpriteBatch // not nulling to save some lines of code private lateinit var shapeRenderer: ShapeRenderer @@ -40,7 +41,11 @@ object PostProcessor { private var functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png")) - fun dispose() { + init { + AppLoader.disposableSingletonsPool.add(this) + } + + override fun dispose() { batch.dispose() shapeRenderer.dispose() try { diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 3faf2e78a..22f24a9d6 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShapeRenderer +import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.GdxRuntimeException import com.jme3.math.FastMath import net.torvald.random.HQRNG @@ -37,7 +38,7 @@ typealias RGBA8888 = Int * * LibGDX Version Created by minjaesong on 2017-06-15. */ -object Terrarum : Screen { +object Terrarum : Screen, Disposable { /** * All singleplayer "Player" must have this exact reference ID. @@ -212,6 +213,9 @@ object Terrarum : Screen { setGamepadButtonLabels() + + AppLoader.disposableSingletonsPool.add(this) + } private fun setGamepadButtonLabels() { diff --git a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt index 86de07651..edf11fb54 100644 --- a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt +++ b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.blockstats import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.GdxRuntimeException import com.badlogic.gdx.utils.Queue import net.torvald.terrarum.AppLoader @@ -12,7 +13,7 @@ import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.CreateTileAtlas -object MinimapComposer { +object MinimapComposer : Disposable { // strategy: mosaic the textures, maximum texture size is 4 096. @@ -66,6 +67,8 @@ object MinimapComposer { init { totalWidth = minimap.width totalHeight = minimap.height + + AppLoader.disposableSingletonsPool.add(this) } fun update() { @@ -147,7 +150,7 @@ object MinimapComposer { } } - fun dispose() { + override fun dispose() { liveTiles.forEach { it.dispose() } minimap.dispose() try { diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 6ca824bb2..366e247f5 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -602,10 +602,16 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { } /** Send message to notifier UI and toggle the UI as opened. */ - fun sendNotification(msg1: String, msg2: String? = null) { - (notifier as Notification).sendNotification(if (msg2 != null) arrayOf(msg1, msg2) else arrayOf(msg1)) + fun sendNotification(messages: Array) { + (notifier as Notification).sendNotification(messages.toList()) } + fun sendNotification(messages: List) { + (notifier as Notification).sendNotification(messages) + } + + fun sendNotification(singleMessage: String) = sendNotification(listOf(singleMessage)) + fun wakeDormantActors() { var actorContainerSize = actorContainerInactive.size var i = 0 diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index f9bbc865c..565a366e5 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.FrameBuffer +import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.ScreenUtils import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.ActorWithBody @@ -23,7 +24,7 @@ import javax.swing.JFileChooser * * For the entire render path, see AppLoader. */ -object IngameRenderer { +object IngameRenderer : Disposable { /** for non-private use, use with care! */ lateinit var batch: SpriteBatch private lateinit var camera: OrthographicCamera @@ -61,6 +62,10 @@ object IngameRenderer { private var debugMode = 0 + init { + AppLoader.disposableSingletonsPool.add(this) + } + operator fun invoke( gamePaused: Boolean, world: GameWorldExtension, @@ -604,7 +609,7 @@ object IngameRenderer { private val TILE_SIZEF = CreateTileAtlas.TILE_SIZE.toFloat() - fun dispose() { + override fun dispose() { fboRGB.dispose() fboA.dispose() fboRGB_lightMixed.dispose() diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt b/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt index e66dc5989..f541469d9 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt @@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.console import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.ConsoleCommand -import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.Ingame /** @@ -10,19 +9,14 @@ import net.torvald.terrarum.modulebasegame.Ingame */ internal object SetBulletin : ConsoleCommand { override fun execute(args: Array) { - send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"]) + //send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"]) + + (Terrarum.ingame!! as Ingame).sendNotification(args.sliceArray(1..args.lastIndex)) + println("sent notifinator") } override fun printUsage() { } - /** - * Actually send notifinator - * @param message real message - */ - fun send(msg1: String, msg2: String? = null) { - (Terrarum.ingame!! as Ingame).sendNotification(msg1, msg2) - println("sent notifinator") - } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/FloatDrawer.kt b/src/net/torvald/terrarum/modulebasegame/ui/FloatDrawer.kt new file mode 100644 index 000000000..aa907fdc7 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/FloatDrawer.kt @@ -0,0 +1,43 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.utils.Disposable +import net.torvald.terrarum.AppLoader +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + +/** + * Created by minjaesong on 2019-05-24. + */ +object FloatDrawer : Disposable { + + val tile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 8, 8) + + init { + AppLoader.disposableSingletonsPool.add(this) + } + + /** + * Draws the Float at given position in given size. The size is that of the centre area, excluding the edges. Size of the edges are 8x8 pixels. + */ + operator fun invoke(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) { + // centre area + batch.draw(tile.get(1, 1), x, y, w, h) + + // edges + batch.draw(tile.get(1, 0), x, y - tile.tileH, w, tile.tileH.toFloat()) + batch.draw(tile.get(1, 2), x, y + h, w, tile.tileH.toFloat()) + batch.draw(tile.get(0, 1), x - tile.tileW, y, tile.tileW.toFloat(), h) + batch.draw(tile.get(2, 1), x + w, y, tile.tileW.toFloat(), h) + + // corners + batch.draw(tile.get(0, 0), x - tile.tileW, y - tile.tileH) + batch.draw(tile.get(2, 0), x + w, y - tile.tileH) + batch.draw(tile.get(2, 2), x + w, y + h) + batch.draw(tile.get(0, 2), x - tile.tileW, y + h) + } + + override fun dispose() { + tile.dispose() + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt index 5a5fb482c..538aabd70 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt @@ -8,15 +8,12 @@ import net.torvald.terrarum.Second import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blendNormal import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** * Created by minjaesong on 2016-01-23. */ class Notification : UICanvas() { - private val segment = SEGMENT_BLACK - private var fontCol: Color = Color.WHITE // assuming alpha of 1.0 override var openCloseTime: Second = OPEN_CLOSE_TIME @@ -28,14 +25,14 @@ class Notification : UICanvas() { override var width: Int = 500 - override var height: Int = segment.tileH + override var height: Int = 0 private val visibleTime = Math.min( AppLoader.getConfigInt("notificationshowuptime"), SHOWUP_MAX ) / 1000f private var displayTimer = 0f - internal var message: Array = Array(MESSAGES_DISPLAY) { "" } + internal var message: List = listOf("") init { @@ -51,9 +48,6 @@ class Notification : UICanvas() { } } - private val textAreaHeight = 48f - private val imageToTextAreaDelta = (segment.tileH - textAreaHeight) / 2 - private val drawColor = Color(1f,1f,1f,1f) override fun renderUI(batch: SpriteBatch, camera: Camera) { @@ -64,26 +58,22 @@ class Notification : UICanvas() { val realTextWidth = 12 + if (message.size == 1) Terrarum.fontGame.getWidth(message[0]) else - maxOf(Terrarum.fontGame.getWidth(message[0]), Terrarum.fontGame.getWidth(message[1])) + message.map { Terrarum.fontGame.getWidth(it) }.sorted().last() val displayedTextWidth = maxOf(240, realTextWidth) // force the UI to the centre of the screen this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2 + val textHeight = message.size * Terrarum.fontGame.lineHeight batch.color = drawColor - batch.draw(segment.get(0, 0), -segment.tileW.toFloat(), 0f) - batch.draw(segment.get(1, 0), 0f, 0f, displayedTextWidth.toFloat(), segment.tileH.toFloat()) - batch.draw(segment.get(2, 0), displayedTextWidth.toFloat(), 0f) + FloatDrawer(batch, 0f, -textHeight, displayedTextWidth.toFloat(), textHeight) batch.color = fontCol message.forEachIndexed { index, s -> val xoff = 6 + (displayedTextWidth - realTextWidth) / 2 - val y = if (message.size == 1) - -2 + imageToTextAreaDelta + 0.5f * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 - else - -1 + imageToTextAreaDelta + index * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 + val y = -textHeight + Terrarum.fontGame.lineHeight * index Terrarum.fontGame.draw(batch, s, LRmargin + xoff, y) } @@ -109,7 +99,7 @@ class Notification : UICanvas() { endClosingFade(this) } - fun sendNotification(message: Array) { + fun sendNotification(message: List) { this.message = message handler.openCloseCounter = 0f handler.opacity = 0f @@ -121,12 +111,6 @@ class Notification : UICanvas() { companion object { // private int messagesShowingIndex = 0; - val MESSAGES_DISPLAY = 2 val OPEN_CLOSE_TIME = 0.16f - - - // will be disposed by Terrarum (application main instance) - val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56) - val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56) } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt index 259b13b48..24cc21d86 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt @@ -2,12 +2,10 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.Second import net.torvald.terrarum.Terrarum import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** * Created by minjaesong on 2017-11-25. @@ -22,38 +20,33 @@ class UITooltip : UICanvas() { msgWidth = font.getWidth(value) } - private val textures = TextureRegionPack("assets/graphics/gui/tooltip_black.tga", 8, 36) - private val font = Terrarum.fontGame private var msgWidth = 0 val textMarginX = 4 override var width: Int - get() = msgWidth + (textMarginX + textures.tileW) * 2 + get() = msgWidth + (textMarginX + FloatDrawer.tile.tileW) * 2 set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") } override var height: Int - get() = textures.tileH + get() = FloatDrawer.tile.tileH * 2 + font.lineHeight.toInt() set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") } - - init { - textures.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) - } - override fun renderUI(batch: SpriteBatch, camera: Camera) { val mouseX = 4f val mouseY = 6f - val tooltipY = mouseY - textures.tileH + val tooltipY = mouseY - height val txtW = msgWidth + 2f * textMarginX batch.color = Color.WHITE - batch.draw(textures.get(0, 0), mouseX, tooltipY) - batch.draw(textures.get(1, 0), mouseX + textures.tileW, tooltipY, txtW, height.toFloat()) - batch.draw(textures.get(2, 0), mouseX + textures.tileW + txtW, tooltipY) - font.draw(batch, message, mouseX + textures.tileW + textMarginX, mouseY - textures.tileH + (textures.tileH - font.lineHeight) / 2) + + FloatDrawer(batch, mouseX - textMarginX, tooltipY, txtW, font.lineHeight) + font.draw(batch, message, + mouseX, + mouseY - height + ) } override fun updateUI(delta: Float) { @@ -73,7 +66,6 @@ class UITooltip : UICanvas() { } override fun dispose() { - textures.dispose() } } \ No newline at end of file diff --git a/terrarum.iml b/terrarum.iml index a872860e4..325aeaaa0 100644 --- a/terrarum.iml +++ b/terrarum.iml @@ -2,10 +2,10 @@ - + - @@ -16,7 +16,7 @@ - +