ingamerenderer: things won't update when the game is paused (e.g. UI open)

This commit is contained in:
minjaesong
2019-03-05 17:45:41 +09:00
parent aaa745ff94
commit 7359519982
10 changed files with 69 additions and 41 deletions

View File

@@ -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

View File

@@ -65,7 +65,7 @@ object PostProcessor {
}
debugUI.update(Gdx.graphics.deltaTime)
debugUI.update(Gdx.graphics.rawDeltaTime)
AppLoader.measureDebugTime("Renderer.PostProcessor") {

View File

@@ -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:
*

View File

@@ -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 {

View File

@@ -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

View File

@@ -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() }
}
}

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -62,6 +62,7 @@ object IngameRenderer {
private var debugMode = 0
operator fun invoke(
gamePaused: Boolean,
world: GameWorldExtension,
actorsRenderBehind : List<ActorWithBody>? = null,
actorsRenderMiddle : List<ActorWithBody>? = 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)

View File

@@ -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()