mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
ingamerenderer: things won't update when the game is paused (e.g. UI open)
This commit is contained in:
@@ -120,7 +120,7 @@ object LoadScreen : ScreenAdapter() {
|
|||||||
private var messageForegroundColour = Color.WHITE
|
private var messageForegroundColour = Color.WHITE
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
val delta = Gdx.graphics.deltaTime
|
val delta = Gdx.graphics.rawDeltaTime
|
||||||
|
|
||||||
glideDispY = Terrarum.HEIGHT - 100f - Terrarum.fontGame.lineHeight
|
glideDispY = Terrarum.HEIGHT - 100f - Terrarum.fontGame.lineHeight
|
||||||
arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH
|
arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ object PostProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
debugUI.update(Gdx.graphics.deltaTime)
|
debugUI.update(Gdx.graphics.rawDeltaTime)
|
||||||
|
|
||||||
|
|
||||||
AppLoader.measureDebugTime("Renderer.PostProcessor") {
|
AppLoader.measureDebugTime("Renderer.PostProcessor") {
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ object Terrarum : Screen {
|
|||||||
get() = Gdx.input.deltaY
|
get() = Gdx.input.deltaY
|
||||||
/** Delta converted as it it was a FPS */
|
/** Delta converted as it it was a FPS */
|
||||||
inline val updateRate: Double
|
inline val updateRate: Double
|
||||||
get() = 1.0 / Gdx.graphics.deltaTime
|
get() = 1.0 / Gdx.graphics.rawDeltaTime
|
||||||
/**
|
/**
|
||||||
* Usage:
|
* Usage:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
// async update and render
|
// async update and render
|
||||||
|
|
||||||
val dt = Gdx.graphics.deltaTime
|
val dt = Gdx.graphics.rawDeltaTime
|
||||||
updateAkku += dt
|
updateAkku += dt
|
||||||
|
|
||||||
var i = 0L
|
var i = 0L
|
||||||
@@ -252,7 +252,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
gdxClearAndSetBlend(.64f, .754f, .84f, 1f)
|
gdxClearAndSetBlend(.64f, .754f, .84f, 1f)
|
||||||
|
|
||||||
|
|
||||||
IngameRenderer.invoke(world = demoWorld, uisToDraw = uiContainer)
|
IngameRenderer.invoke(gamePaused = false, world = demoWorld, uisToDraw = uiContainer)
|
||||||
|
|
||||||
|
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ object BlockPropUtil {
|
|||||||
internal fun dynamicLumFuncTickClock() {
|
internal fun dynamicLumFuncTickClock() {
|
||||||
// FPS-time compensation
|
// FPS-time compensation
|
||||||
if (Gdx.graphics.framesPerSecond > 0) {
|
if (Gdx.graphics.framesPerSecond > 0) {
|
||||||
flickerFuncX += Gdx.graphics.deltaTime * 1000f
|
flickerFuncX += Gdx.graphics.rawDeltaTime * 1000f
|
||||||
breathFuncX += Gdx.graphics.deltaTime * 1000f
|
breathFuncX += Gdx.graphics.rawDeltaTime * 1000f
|
||||||
pulsateFuncX += Gdx.graphics.deltaTime * 1000f
|
pulsateFuncX += Gdx.graphics.rawDeltaTime * 1000f
|
||||||
}
|
}
|
||||||
|
|
||||||
// flicker-related vars
|
// flicker-related vars
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package net.torvald.terrarum.blockstats
|
package net.torvald.terrarum.blockstats
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
import net.torvald.terrarum.worlddrawer.toRGBA
|
||||||
|
|
||||||
object MinimapComposer {
|
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.
|
// total size of the minimap. Remember: textures can be mosaic-ed to display full map.
|
||||||
var totalWidth = 0
|
var totalWidth = 0
|
||||||
var totalHeight = 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 {
|
init {
|
||||||
repeat(4) {
|
totalWidth = minimap.width
|
||||||
tempTex[it] = Texture(Gdx.files.internal("./assets/testimage.png"))
|
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() {
|
fun dispose() {
|
||||||
// tempTex.forEach { it.dispose }
|
liveTiles.forEach { it.dispose() }
|
||||||
// minimapPixmaps.forEach { it.dispose }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -324,7 +324,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||||
|
|
||||||
val dt = Gdx.graphics.deltaTime
|
val dt = Gdx.graphics.rawDeltaTime
|
||||||
updateAkku += dt
|
updateAkku += dt
|
||||||
|
|
||||||
var i = 0L
|
var i = 0L
|
||||||
@@ -392,7 +392,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
private fun renderGame() {
|
private fun renderGame() {
|
||||||
_testMarkerDrawCalls = 0L
|
_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)
|
AppLoader.setDebugTime("Test.MarkerDrawCalls", _testMarkerDrawCalls)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||||
|
|
||||||
/** UPDATE CODE GOES HERE */
|
/** UPDATE CODE GOES HERE */
|
||||||
val dt = Gdx.graphics.deltaTime
|
val dt = Gdx.graphics.rawDeltaTime
|
||||||
updateAkku += dt
|
updateAkku += dt
|
||||||
|
|
||||||
var i = 0L
|
var i = 0L
|
||||||
@@ -543,6 +543,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
filterVisibleActors()
|
filterVisibleActors()
|
||||||
|
|
||||||
IngameRenderer.invoke(
|
IngameRenderer.invoke(
|
||||||
|
paused,
|
||||||
world as GameWorldExtension,
|
world as GameWorldExtension,
|
||||||
visibleActorsRenderBehind,
|
visibleActorsRenderBehind,
|
||||||
visibleActorsRenderMiddle,
|
visibleActorsRenderMiddle,
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ object IngameRenderer {
|
|||||||
private var debugMode = 0
|
private var debugMode = 0
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
|
gamePaused: Boolean,
|
||||||
world: GameWorldExtension,
|
world: GameWorldExtension,
|
||||||
actorsRenderBehind : List<ActorWithBody>? = null,
|
actorsRenderBehind : List<ActorWithBody>? = null,
|
||||||
actorsRenderMiddle : List<ActorWithBody>? = null,
|
actorsRenderMiddle : List<ActorWithBody>? = null,
|
||||||
@@ -89,14 +90,15 @@ object IngameRenderer {
|
|||||||
this.player = player
|
this.player = player
|
||||||
|
|
||||||
|
|
||||||
LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, 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)
|
|
||||||
|
|
||||||
|
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
|
// clear main or whatever super-FBO being used
|
||||||
//clearBuffer()
|
//clearBuffer()
|
||||||
gdxClearAndSetBlend(.64f, .754f, .84f, 0f)
|
gdxClearAndSetBlend(.64f, .754f, .84f, 0f)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.*
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.jme3.math.Vector2f
|
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.Terrarum.gamepadLabelEast
|
import net.torvald.terrarum.Terrarum.gamepadLabelEast
|
||||||
@@ -246,7 +245,7 @@ class UIInventoryFull(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (transitionOngoing) {
|
if (transitionOngoing) {
|
||||||
transitionTimer += Gdx.graphics.deltaTime
|
transitionTimer += Gdx.graphics.rawDeltaTime
|
||||||
|
|
||||||
currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
||||||
|
|
||||||
@@ -347,7 +346,7 @@ class UIInventoryFull(
|
|||||||
private var minimapZoom = 1f
|
private var minimapZoom = 1f
|
||||||
private var minimapPanX = -MinimapComposer.totalWidth / 2f
|
private var minimapPanX = -MinimapComposer.totalWidth / 2f
|
||||||
private var minimapPanY = -MinimapComposer.totalHeight / 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 MINIMAP_ZOOM_MAX = 8f
|
||||||
private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
||||||
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||||
@@ -396,9 +395,8 @@ class UIInventoryFull(
|
|||||||
batch.end()
|
batch.end()
|
||||||
minimapFBO.inAction(minimapCamera, batch) {
|
minimapFBO.inAction(minimapCamera, batch) {
|
||||||
// whatever.
|
// whatever.
|
||||||
val t = MinimapComposer.tempTex
|
MinimapComposer.tempTex.dispose()
|
||||||
t.forEach { it.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat) }
|
MinimapComposer.tempTex = Texture(MinimapComposer.minimap)
|
||||||
|
|
||||||
|
|
||||||
batch.inUse {
|
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
|
// 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 tx = minimapPanX * minimapZoom + 0.5f * MINIMAP_WIDTH
|
||||||
val p = arrayOf(
|
val ty = minimapPanY * minimapZoom + 0.5f * MINIMAP_HEIGHT
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
// sky background
|
// sky background
|
||||||
batch.color = MINIMAP_SKYCOL
|
batch.color = MINIMAP_SKYCOL
|
||||||
batch.fillRect(0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
batch.fillRect(0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||||
// the actual image
|
// the actual image
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
repeat(4) {
|
batch.draw(MinimapComposer.tempTex, tx, ty + MinimapComposer.totalHeight * minimapZoom, MinimapComposer.totalWidth * minimapZoom, -MinimapComposer.totalHeight * minimapZoom)
|
||||||
batch.draw(t[it], p[it].x, p[it].y + t[it].height * minimapZoom, t[it].width * minimapZoom, -t[it].height * minimapZoom)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batch.begin()
|
batch.begin()
|
||||||
|
|||||||
Reference in New Issue
Block a user