From 7359519982cf031092e264a05f80126059c8b9d7 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 5 Mar 2019 17:45:41 +0900 Subject: [PATCH] ingamerenderer: things won't update when the game is paused (e.g. UI open) --- src/net/torvald/terrarum/LoadScreen.kt | 2 +- src/net/torvald/terrarum/PostProcessor.kt | 2 +- src/net/torvald/terrarum/Terrarum.kt | 2 +- src/net/torvald/terrarum/TitleScreen.kt | 4 +- .../terrarum/blockproperties/BlockPropUtil.kt | 6 +-- .../terrarum/blockstats/MinimapComposer.kt | 47 ++++++++++++++++--- .../terrarum/modulebasegame/BuildingMaker.kt | 4 +- .../torvald/terrarum/modulebasegame/Ingame.kt | 3 +- .../terrarum/modulebasegame/IngameRenderer.kt | 16 ++++--- .../modulebasegame/ui/UIInventoryFull.kt | 24 ++++------ 10 files changed, 69 insertions(+), 41 deletions(-) diff --git a/src/net/torvald/terrarum/LoadScreen.kt b/src/net/torvald/terrarum/LoadScreen.kt index 95707a143..d2ca8d060 100644 --- a/src/net/torvald/terrarum/LoadScreen.kt +++ b/src/net/torvald/terrarum/LoadScreen.kt @@ -120,7 +120,7 @@ object LoadScreen : ScreenAdapter() { private var messageForegroundColour = Color.WHITE override fun render(delta: Float) { - val delta = Gdx.graphics.deltaTime + val delta = Gdx.graphics.rawDeltaTime glideDispY = Terrarum.HEIGHT - 100f - Terrarum.fontGame.lineHeight arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt index 25bee1e60..f1094ecb4 100644 --- a/src/net/torvald/terrarum/PostProcessor.kt +++ b/src/net/torvald/terrarum/PostProcessor.kt @@ -65,7 +65,7 @@ object PostProcessor { } - debugUI.update(Gdx.graphics.deltaTime) + debugUI.update(Gdx.graphics.rawDeltaTime) AppLoader.measureDebugTime("Renderer.PostProcessor") { diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index cc8165b7f..9a5c8af0e 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -496,7 +496,7 @@ object Terrarum : Screen { get() = Gdx.input.deltaY /** Delta converted as it it was a FPS */ inline val updateRate: Double - get() = 1.0 / Gdx.graphics.deltaTime + get() = 1.0 / Gdx.graphics.rawDeltaTime /** * Usage: * diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index ece697eeb..e7eaa345c 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -205,7 +205,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { override fun render(delta: Float) { // async update and render - val dt = Gdx.graphics.deltaTime + val dt = Gdx.graphics.rawDeltaTime updateAkku += dt var i = 0L @@ -252,7 +252,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { gdxClearAndSetBlend(.64f, .754f, .84f, 1f) - IngameRenderer.invoke(world = demoWorld, uisToDraw = uiContainer) + IngameRenderer.invoke(gamePaused = false, world = demoWorld, uisToDraw = uiContainer) batch.inUse { diff --git a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt index d410fa5da..0cde2a6c5 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt @@ -63,9 +63,9 @@ object BlockPropUtil { internal fun dynamicLumFuncTickClock() { // FPS-time compensation if (Gdx.graphics.framesPerSecond > 0) { - flickerFuncX += Gdx.graphics.deltaTime * 1000f - breathFuncX += Gdx.graphics.deltaTime * 1000f - pulsateFuncX += Gdx.graphics.deltaTime * 1000f + flickerFuncX += Gdx.graphics.rawDeltaTime * 1000f + breathFuncX += Gdx.graphics.rawDeltaTime * 1000f + pulsateFuncX += Gdx.graphics.rawDeltaTime * 1000f } // flicker-related vars diff --git a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt index e0dfe0405..d56161686 100644 --- a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt +++ b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt @@ -1,10 +1,12 @@ package net.torvald.terrarum.blockstats import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import net.torvald.terrarum.AppLoader import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.worlddrawer.toRGBA object MinimapComposer { @@ -29,22 +31,53 @@ object MinimapComposer { } } - val tempTex = Array(4) { Texture(1,1,Pixmap.Format.RGBA8888) } + var tempTex = Texture(1,1,Pixmap.Format.RGBA8888) + val minimap = Pixmap(Gdx.files.internal("./assets/testimage.png")) // total size of the minimap. Remember: textures can be mosaic-ed to display full map. var totalWidth = 0 var totalHeight = 0 + /** World coord for top-left side of the tileslot. ALWAYS multiple of LIVETILE_SIZE */ + var topLeftCoordX = 0 + /** World coord for top-left side of the tileslot. ALWAYS multiple of LIVETILE_SIZE */ + var topLeftCoordY = 0 + + const val LIVETILE_SIZE = 64 + const val DISPLAY_CANVAS_WIDTH = 2048 + const val DISPLAY_CANVAS_HEIGHT = 1024 + const val TILES_IN_X = DISPLAY_CANVAS_WIDTH / LIVETILE_SIZE + const val TILES_IN_Y = DISPLAY_CANVAS_HEIGHT / LIVETILE_SIZE + private val displayPixmap = Pixmap(DISPLAY_CANVAS_WIDTH, DISPLAY_CANVAS_HEIGHT, Pixmap.Format.RGBA8888) + // numbers inside of it will change a lot + private val tileSlot = Array(TILES_IN_Y) { IntArray(TILES_IN_X) } + // pixmaps inside of this will never be redefined + private val liveTiles = Array(TILES_IN_X * TILES_IN_Y) { Pixmap(LIVETILE_SIZE, LIVETILE_SIZE, Pixmap.Format.RGBA8888) } + + init { - repeat(4) { - tempTex[it] = Texture(Gdx.files.internal("./assets/testimage.png")) + totalWidth = minimap.width + totalHeight = minimap.height + } + + fun update() { + + } + + private fun createUpdater(tileSlotIndexX: Int, tileSlotIndexY: Int) = Runnable { + val pixmap = liveTiles[tileSlot[tileSlotIndexY][tileSlotIndexX]] + val topLeftX = topLeftCoordX + LIVETILE_SIZE * tileSlotIndexX + val topLeftY = topLeftCoordY + LIVETILE_SIZE * tileSlotIndexY + + for (y in topLeftY until topLeftY + LIVETILE_SIZE) { + for (x in if (tileSlotIndexY >= TILES_IN_X / 2) (topLeftX + LIVETILE_SIZE - 1) downTo topLeftX else topLeftX until topLeftX + LIVETILE_SIZE) { + val color = Color.WHITE // TODO + pixmap.drawPixel(x - topLeftX, y - topLeftY, color.toRGBA()) + } } - totalWidth = tempTex[0].width * 2 - totalHeight = tempTex[0].height * 2 } fun dispose() { - // tempTex.forEach { it.dispose } - // minimapPixmaps.forEach { it.dispose } + liveTiles.forEach { it.dispose() } } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index 0e32e4b7e..4aba4d4a8 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -324,7 +324,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { // ASYNCHRONOUS UPDATE AND RENDER // - val dt = Gdx.graphics.deltaTime + val dt = Gdx.graphics.rawDeltaTime updateAkku += dt var i = 0L @@ -392,7 +392,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { private fun renderGame() { _testMarkerDrawCalls = 0L - IngameRenderer.invoke(world as GameWorldExtension, actorsRenderOverlay = if (showSelection) actorsRenderOverlay + essentialOverlays else essentialOverlays, uisToDraw = uiContainer) + IngameRenderer.invoke(false, world as GameWorldExtension, actorsRenderOverlay = if (showSelection) actorsRenderOverlay + essentialOverlays else essentialOverlays, uisToDraw = uiContainer) AppLoader.setDebugTime("Test.MarkerDrawCalls", _testMarkerDrawCalls) } diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 1473ba81f..2b721e3ec 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -449,7 +449,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { // ASYNCHRONOUS UPDATE AND RENDER // /** UPDATE CODE GOES HERE */ - val dt = Gdx.graphics.deltaTime + val dt = Gdx.graphics.rawDeltaTime updateAkku += dt var i = 0L @@ -543,6 +543,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { filterVisibleActors() IngameRenderer.invoke( + paused, world as GameWorldExtension, visibleActorsRenderBehind, visibleActorsRenderMiddle, diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 4679f7085..8f51827fa 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -62,6 +62,7 @@ object IngameRenderer { private var debugMode = 0 operator fun invoke( + gamePaused: Boolean, world: GameWorldExtension, actorsRenderBehind : List? = null, actorsRenderMiddle : List? = null, @@ -89,14 +90,15 @@ object IngameRenderer { this.player = player - LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay) - - prepLightmapRGBA() - BlocksDrawer.renderData() - drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) - drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) - drawOverlayActors(actorsRenderOverlay) + if (!gamePaused) { + LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay) + prepLightmapRGBA() + BlocksDrawer.renderData() + drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) + drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) + drawOverlayActors(actorsRenderOverlay) + } // clear main or whatever super-FBO being used //clearBuffer() gdxClearAndSetBlend(.64f, .754f, .84f, 0f) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 2666b7052..e08453667 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShapeRenderer -import com.jme3.math.Vector2f import net.torvald.terrarum.* import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.Terrarum.gamepadLabelEast @@ -246,7 +245,7 @@ class UIInventoryFull( } if (transitionOngoing) { - transitionTimer += Gdx.graphics.deltaTime + transitionTimer += Gdx.graphics.rawDeltaTime currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) @@ -347,7 +346,7 @@ class UIInventoryFull( private var minimapZoom = 1f private var minimapPanX = -MinimapComposer.totalWidth / 2f private var minimapPanY = -MinimapComposer.totalHeight / 2f - private val MINIMAP_ZOOM_MIN = 0.25f + private val MINIMAP_ZOOM_MIN = 0.5f private val MINIMAP_ZOOM_MAX = 8f private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false) private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT) @@ -396,9 +395,8 @@ class UIInventoryFull( batch.end() minimapFBO.inAction(minimapCamera, batch) { // whatever. - val t = MinimapComposer.tempTex - t.forEach { it.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat) } - + MinimapComposer.tempTex.dispose() + MinimapComposer.tempTex = Texture(MinimapComposer.minimap) batch.inUse { @@ -408,22 +406,16 @@ class UIInventoryFull( // // https://www.wolframalpha.com/input/?i=%7B%7B1,0,0%7D,%7B0,1,0%7D,%7Bp_x,p_y,1%7D%7D+*+%7B%7Bs,0,0%7D,%7B0,s,0%7D,%7Bw%2F2,h%2F2,1%7D%7D - val halfWindow = Vector2f(0.5f * MINIMAP_WIDTH, 0.5f * MINIMAP_HEIGHT) - val p = arrayOf( - Vector2f(minimapPanX, minimapPanY).mult(minimapZoom).add(halfWindow), - Vector2f(minimapPanX + t[0].width, minimapPanY).mult(minimapZoom).add(halfWindow), - Vector2f(minimapPanX, minimapPanY + t[0].height).mult(minimapZoom).add(halfWindow), - Vector2f(minimapPanX + t[0].width, minimapPanY + t[0].height).mult(minimapZoom).add(halfWindow) - ) + val tx = minimapPanX * minimapZoom + 0.5f * MINIMAP_WIDTH + val ty = minimapPanY * minimapZoom + 0.5f * MINIMAP_HEIGHT // sky background batch.color = MINIMAP_SKYCOL batch.fillRect(0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT) // the actual image batch.color = Color.WHITE - repeat(4) { - batch.draw(t[it], p[it].x, p[it].y + t[it].height * minimapZoom, t[it].width * minimapZoom, -t[it].height * minimapZoom) - } + batch.draw(MinimapComposer.tempTex, tx, ty + MinimapComposer.totalHeight * minimapZoom, MinimapComposer.totalWidth * minimapZoom, -MinimapComposer.totalHeight * minimapZoom) + } } batch.begin()