tilemap update is now done once in every 3 frame

This commit is contained in:
minjaesong
2024-08-30 13:55:37 +09:00
parent 85a4c46240
commit d405302c9d
2 changed files with 23 additions and 8 deletions

View File

@@ -264,11 +264,14 @@ internal object BlocksDrawer {
if (doTilemapUpdate) {
wrapCamera()
camTransX = WorldCamera.x fmod TILE_SIZE
camTransY = WorldCamera.y fmod TILE_SIZE
}
else {
camTransX += WorldCamera.deltaX
camTransY += WorldCamera.deltaY
}
camTransX = WorldCamera.x - camX
camTransY = WorldCamera.y - camY
if (doTilemapUpdate) {
// rendering tilemap only updates every three frame
measureDebugTime("Renderer.Tiling*") {
@@ -1176,7 +1179,7 @@ internal object BlocksDrawer {
private val occlusionIntensity = 0.25f // too low value and dark-coloured walls won't darken enough
private val doTilemapUpdate: Boolean
get() = (!world.layerTerrain.ptrDestroyed && App.GLOBAL_RENDER_TIMER % 30 == 0L)
get() = (!world.layerTerrain.ptrDestroyed && App.GLOBAL_RENDER_TIMER % 3 == 0L)
private var camTransX = 0
private var camTransY = 0

View File

@@ -64,6 +64,9 @@ object WorldCamera {
inline val yCentre: Int
get() = y + height.ushr(1)
var deltaX: Int = 0; private set
var deltaY: Int = 0; private set
private val nullVec = Vector2(0.0, 0.0)
/** World width in pixels */
@@ -106,7 +109,7 @@ object WorldCamera {
// val fpsRatio = App.UPDATE_RATE / Gdx.graphics.deltaTime // if FPS=32 & RATE=64, ratio will be 0.5
val fpsRatio = 64f / Gdx.graphics.framesPerSecond
val fpsRatio = App.TICK_SPEED.toFloat() / Gdx.graphics.framesPerSecond
val oldX = x.toDouble()
val oldY = y.toDouble()
val newX1 = (player.hitbox.centeredX) - (width / 2) +
@@ -124,8 +127,17 @@ object WorldCamera {
val camSpeed = (1f - (1f / (2f * fpsRatio))).coerceIn(0.5f, 1f)
x = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt() fmod worldWidth
y = FastMath.interpolateLinear(camSpeed, oldY.toFloat(), newY.toFloat()).roundToInt().clampCameraY(world)
val finalXnowrap = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt()
val finalX = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt() fmod worldWidth
val finalY = FastMath.interpolateLinear(camSpeed, oldY.toFloat(), newY.toFloat()).roundToInt().clampCameraY(world)
// println("finalX=$finalX, finalXnowrap=$finalXnowrap")
deltaX = if (finalX != finalXnowrap) finalXnowrap - x else finalX - x
deltaY = finalY - y
x = finalX
y = finalY
xEnd = x + width
yEnd = y + height