mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
tilemap update is now done once in every 3 frame
This commit is contained in:
@@ -264,11 +264,14 @@ internal object BlocksDrawer {
|
|||||||
|
|
||||||
if (doTilemapUpdate) {
|
if (doTilemapUpdate) {
|
||||||
wrapCamera()
|
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) {
|
if (doTilemapUpdate) {
|
||||||
// rendering tilemap only updates every three frame
|
// rendering tilemap only updates every three frame
|
||||||
measureDebugTime("Renderer.Tiling*") {
|
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 occlusionIntensity = 0.25f // too low value and dark-coloured walls won't darken enough
|
||||||
|
|
||||||
private val doTilemapUpdate: Boolean
|
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 camTransX = 0
|
||||||
private var camTransY = 0
|
private var camTransY = 0
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ object WorldCamera {
|
|||||||
inline val yCentre: Int
|
inline val yCentre: Int
|
||||||
get() = y + height.ushr(1)
|
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)
|
private val nullVec = Vector2(0.0, 0.0)
|
||||||
|
|
||||||
/** World width in pixels */
|
/** 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 = 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 oldX = x.toDouble()
|
||||||
val oldY = y.toDouble()
|
val oldY = y.toDouble()
|
||||||
val newX1 = (player.hitbox.centeredX) - (width / 2) +
|
val newX1 = (player.hitbox.centeredX) - (width / 2) +
|
||||||
@@ -124,8 +127,17 @@ object WorldCamera {
|
|||||||
|
|
||||||
val camSpeed = (1f - (1f / (2f * fpsRatio))).coerceIn(0.5f, 1f)
|
val camSpeed = (1f - (1f / (2f * fpsRatio))).coerceIn(0.5f, 1f)
|
||||||
|
|
||||||
x = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt() fmod worldWidth
|
val finalXnowrap = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt()
|
||||||
y = FastMath.interpolateLinear(camSpeed, oldY.toFloat(), newY.toFloat()).roundToInt().clampCameraY(world)
|
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
|
xEnd = x + width
|
||||||
yEnd = y + height
|
yEnd = y + height
|
||||||
|
|||||||
Reference in New Issue
Block a user