mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
WorldCamera now holds tilewise positions
This commit is contained in:
BIN
assets/mods/basegame/ores/2.tga
LFS
BIN
assets/mods/basegame/ores/2.tga
LFS
Binary file not shown.
@@ -416,19 +416,27 @@ internal object BlocksDrawer {
|
||||
private var for_x_end = 0
|
||||
private var camX = 0
|
||||
private var camY = 0
|
||||
private var camTx = 0
|
||||
private var camTy = 0
|
||||
private var camDeltaTx = 0
|
||||
private var camDeltaTy = 0
|
||||
|
||||
private fun wrapCamera() {
|
||||
camX = WorldCamera.x
|
||||
camY = WorldCamera.y
|
||||
camTx = WorldCamera.tx
|
||||
camTy = WorldCamera.ty
|
||||
camDeltaTx = WorldCamera.deltaTx
|
||||
camDeltaTy = WorldCamera.deltaTy
|
||||
|
||||
// can't be "WorldCamera.y / TILE_SIZE":
|
||||
// ( 3 / 16) == 0
|
||||
// (-3 / 16) == -1 <-- We want it to be '-1', not zero
|
||||
// using cast and floor instead of IF on ints: the other way causes jitter artefact, which I don't fucking know why
|
||||
|
||||
for_y_start = (camY.toFloat() / TILE_SIZE).floorToInt()
|
||||
for_y_start = camTy
|
||||
for_y_end = for_y_start + hTilesInVertical - 1
|
||||
for_x_start = (camX.toFloat() / TILE_SIZE).floorToInt()
|
||||
for_x_start = camTx
|
||||
for_x_end = for_x_start + hTilesInHorizontal - 1
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,11 @@ package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.ceilToInt
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.sqr
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -26,6 +23,11 @@ object WorldCamera {
|
||||
var y: Int = 0 // top position
|
||||
private set
|
||||
|
||||
var tx: Int = 0 // tilewise left position
|
||||
private set
|
||||
var ty: Int = 0 // tilewise top position
|
||||
private set
|
||||
|
||||
var width: Int = 0
|
||||
private set
|
||||
var height: Int = 0
|
||||
@@ -67,6 +69,9 @@ object WorldCamera {
|
||||
var deltaX: Int = 0; private set
|
||||
var deltaY: Int = 0; private set
|
||||
|
||||
var deltaTx: Int = 0; private set
|
||||
var deltaTy: Int = 0; private set
|
||||
|
||||
private val nullVec = Vector2(0.0, 0.0)
|
||||
|
||||
/** World width in pixels */
|
||||
@@ -114,11 +119,14 @@ object WorldCamera {
|
||||
// val fpsRatio = App.UPDATE_RATE / Gdx.graphics.deltaTime // if FPS=32 & RATE=64, ratio will be 0.5
|
||||
val fpsRatio = App.TICK_SPEED.toFloat() / Gdx.graphics.framesPerSecond
|
||||
val oldX = x.toDouble()
|
||||
val oldTx = tx.toDouble()
|
||||
val oldY = y.toDouble()
|
||||
val newX1 = (player.hitbox.centeredX) - (width / 2) +
|
||||
if (App.getConfigBoolean("fx_streamerslayout")) App.scr.chatWidth / 2 else 0
|
||||
val newX1 = (player.hitbox.centeredX) - (width / 2) + if (App.getConfigBoolean("fx_streamerslayout")) App.scr.chatWidth / 2 else 0
|
||||
val newX2 = newX1 + worldWidth
|
||||
val newTx1 = newX1 / TILE_SIZE
|
||||
val newTx2 = newX2 / TILE_SIZE
|
||||
val newX = if (Math.abs(newX1 - oldX) < Math.abs(newX2 - oldX)) newX1 else newX2
|
||||
val newTx = if (Math.abs(newTx1 - oldTx) < Math.abs(newTx2 - oldTx)) newTx1 else newTx2
|
||||
val newY = player.hitbox.centeredY - (height / 2)
|
||||
|
||||
val pVecMagn = (player.externalV + player.controllerV).magnitude
|
||||
@@ -134,14 +142,23 @@ object WorldCamera {
|
||||
val finalX = FastMath.interpolateLinear(camSpeed, oldX.toFloat(), newX.toFloat()).roundToInt() fmod worldWidth
|
||||
val finalY = FastMath.interpolateLinear(camSpeed, oldY.toFloat(), newY.toFloat()).roundToInt().clampCameraY(world)
|
||||
|
||||
val finalTxnowrap = FastMath.interpolateLinear(camSpeed, oldTx.toFloat(), newTx.toFloat()).roundToInt()
|
||||
val finalTx = (finalX.toFloat() / TILE_SIZE).floorToInt()
|
||||
val finalTy = (finalY.toFloat() / TILE_SIZE).floorToInt()
|
||||
// println("finalX=$finalX, finalXnowrap=$finalXnowrap")
|
||||
|
||||
deltaX = if (finalX != finalXnowrap) finalXnowrap - x else finalX - x
|
||||
deltaY = finalY - y
|
||||
|
||||
deltaTx = if (finalTx != finalTxnowrap) finalTxnowrap - tx else finalTx - tx
|
||||
deltaTy = finalTy - ty
|
||||
|
||||
x = finalX
|
||||
y = finalY
|
||||
|
||||
tx = finalTx
|
||||
ty = finalTy
|
||||
|
||||
xEnd = x + width
|
||||
yEnd = y + height
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user