removed visual artefacts caused by the new camera coords

This commit is contained in:
minjaesong
2021-09-16 23:37:26 +09:00
parent c3481fd47d
commit 6e9b388534
2 changed files with 19 additions and 32 deletions

View File

@@ -3,11 +3,9 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.spriteanimation.SpriteAnimation import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.App.printdbgerr
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
@@ -1625,41 +1623,30 @@ open class ActorWithBody : Actor {
val offsetX = hitboxTranslateX * scale val offsetX = hitboxTranslateX * scale
val offsetY = sprite.cellHeight * scale - hitbox.height - hitboxTranslateY * scale - 1 val offsetY = sprite.cellHeight * scale - hitbox.height - hitboxTranslateY * scale - 1
// it would be great if you can eliminate the try-catch because it may hurt the performance when there's too many actors on screen to draw
// FIXME test me: this extra IF statement is supposed to not draw actors that's outside of the camera. // try {
// basic code without offsetX/Y DOES work, but obviously offsets are not tested. if (Math.abs(WorldCamera.x - hitbox.startX) > App.scr.halfw) {
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) { sprite.render(batch,
// camera center neg, actor center pos (hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZEF,
sprite.render(batch, (hitbox.startY - offsetY).toFloat(),
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZE, (scale).toFloat()
(hitbox.startY - offsetY).toFloat(), )
(scale).toFloat() }
) else {
}
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
// camera center pos, actor center neg
sprite.render(batch,
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZE,
(hitbox.startY - offsetY).toFloat(),
(scale).toFloat()
)
}
else {
try {
sprite.render(batch, sprite.render(batch,
(hitbox.startX - offsetX).toFloat(), (hitbox.startX - offsetX).toFloat(),
(hitbox.startY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
catch (e: UninitializedPropertyAccessException) { // }
printdbgerr(this, this.javaClass.simpleName) // catch (e: UninitializedPropertyAccessException) {
printdbgerr(this, actorValue.getAsString(AVKey.NAME)) // printdbgerr(this, this.javaClass.simpleName)
printdbgerr(this, if (this is HasAssembledSprite) this.animDescPath else "(not HasAssembledSprite)") // printdbgerr(this, actorValue.getAsString(AVKey.NAME))
printdbgerr(this, e) // printdbgerr(this, if (this is HasAssembledSprite) this.animDescPath else "(not HasAssembledSprite)")
throw e // printdbgerr(this, e)
} // throw e
} // }
} }
override fun onActorValueChange(key: String, value: Any?) { override fun onActorValueChange(key: String, value: Any?) {

View File

@@ -207,7 +207,7 @@ object IngameRenderer : Disposable {
if (!gamePaused || newWorldLoadedLatch) { if (!gamePaused || newWorldLoadedLatch) {
measureDebugTime("Renderer.ApparentLightRun") { measureDebugTime("Renderer.ApparentLightRun") {
// recalculate for even frames, or if the sign of the cam-x changed // recalculate for even frames, or if the sign of the cam-x changed
if (App.GLOBAL_RENDER_TIMER % 3 == 0 || WorldCamera.x * oldCamX <= 0 || newWorldLoadedLatch) { if (App.GLOBAL_RENDER_TIMER % 3 == 0 || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) {
LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay) LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay)
} }
oldCamX = WorldCamera.x oldCamX = WorldCamera.x