mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
light calc area shrinks when zoomed in
This commit is contained in:
@@ -238,16 +238,16 @@ object Terrarum : Disposable {
|
|||||||
|
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
val mouseX: Double
|
val mouseX: Double
|
||||||
get() = WorldCamera.x + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
val mouseY: Double
|
val mouseY: Double
|
||||||
get() = WorldCamera.y + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
val oldMouseX: Double
|
val oldMouseX: Double
|
||||||
get() = WorldCamera.x + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
val oldMouseY: Double
|
val oldMouseY: Double
|
||||||
get() = WorldCamera.y + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
@JvmStatic val mouseTileX: Int
|
@JvmStatic val mouseTileX: Int
|
||||||
get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt()
|
get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt()
|
||||||
|
|||||||
@@ -119,8 +119,12 @@ object LightmapRenderer {
|
|||||||
internal var for_y_start = 0
|
internal var for_y_start = 0
|
||||||
internal var for_x_end = 0
|
internal var for_x_end = 0
|
||||||
internal var for_y_end = 0
|
internal var for_y_end = 0
|
||||||
internal var for_x = 0
|
internal var for_draw_x_start = 0
|
||||||
internal var for_y = 0
|
internal var for_draw_y_start = 0
|
||||||
|
internal var for_draw_x_end = 0
|
||||||
|
internal var for_draw_y_end = 0
|
||||||
|
//internal var for_x = 0
|
||||||
|
//internal var for_y = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param x world coord
|
* @param x world coord
|
||||||
@@ -174,19 +178,23 @@ object LightmapRenderer {
|
|||||||
if (world.worldIndex == -1) return
|
if (world.worldIndex == -1) return
|
||||||
|
|
||||||
|
|
||||||
for_x_start = WorldCamera.x / TILE_SIZE // fix for premature lightmap rendering
|
for_x_start = WorldCamera.zoomedX / TILE_SIZE // fix for premature lightmap rendering
|
||||||
for_y_start = WorldCamera.y / TILE_SIZE // on topmost/leftmost side
|
for_y_start = WorldCamera.zoomedY / TILE_SIZE // on topmost/leftmost side
|
||||||
|
for_draw_x_start = WorldCamera.x / TILE_SIZE
|
||||||
|
for_draw_y_start = WorldCamera.y / TILE_SIZE
|
||||||
|
|
||||||
if (for_x_start < 0) for_x_start -= 1 // to fix that the light shifts 1 tile to the left when WorldCamera < 0
|
if (for_x_start < 0) for_x_start -= 1 // to fix that the light shifts 1 tile to the left when WorldCamera < 0
|
||||||
//if (for_y_start < 0) for_y_start -= 1 // not needed when we only wrap at x axis
|
//if (for_y_start < 0) for_y_start -= 1 // not needed when we only wrap at x axis
|
||||||
|
|
||||||
if (WorldCamera.x in -(TILE_SIZE - 1)..-1) for_x_start -= 1 // another edge-case fix
|
if (WorldCamera.x in -(TILE_SIZE - 1)..-1) for_x_start -= 1 // another edge-case fix
|
||||||
|
|
||||||
for_x_end = for_x_start + WorldCamera.width / TILE_SIZE + 3
|
for_x_end = for_x_start + WorldCamera.zoomedWidth / TILE_SIZE + 3
|
||||||
for_y_end = for_y_start + WorldCamera.height / TILE_SIZE + 3 // same fix as above
|
for_y_end = for_y_start + WorldCamera.zoomedHeight / TILE_SIZE + 3 // same fix as above
|
||||||
|
for_draw_x_end = for_draw_x_start + WorldCamera.width / TILE_SIZE + 3
|
||||||
|
for_draw_y_end = for_draw_y_start + WorldCamera.height / TILE_SIZE + 3
|
||||||
|
|
||||||
for_x = for_x_start + (for_x_end - for_x_start) / 2
|
//for_x = for_x_start + (for_x_end - for_x_start) / 2
|
||||||
for_y = for_y_start + (for_y_end - for_y_start) / 2
|
//for_y = for_y_start + (for_y_end - for_y_start) / 2
|
||||||
|
|
||||||
//println("$for_x_start..$for_x_end, $for_x\t$for_y_start..$for_y_end, $for_y")
|
//println("$for_x_start..$for_x_end, $for_x\t$for_y_start..$for_y_end, $for_y")
|
||||||
|
|
||||||
@@ -609,10 +617,10 @@ object LightmapRenderer {
|
|||||||
// when shader is not used: 0.5 ms on 6700K
|
// when shader is not used: 0.5 ms on 6700K
|
||||||
AppLoader.measureDebugTime("Renderer.LightToScreen") {
|
AppLoader.measureDebugTime("Renderer.LightToScreen") {
|
||||||
|
|
||||||
val this_x_start = for_x_start// + overscan_open
|
val this_x_start = for_draw_x_start
|
||||||
val this_x_end = for_x_end// + overscan_open
|
val this_y_start = for_draw_y_start
|
||||||
val this_y_start = for_y_start// + overscan_open
|
val this_x_end = for_draw_x_end
|
||||||
val this_y_end = for_y_end// + overscan_open
|
val this_y_end = for_draw_y_end
|
||||||
|
|
||||||
// wipe out beforehand. You DO need this
|
// wipe out beforehand. You DO need this
|
||||||
lightBuffer.blending = Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)
|
lightBuffer.blending = Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.torvald.terrarum.worlddrawer
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.ceilInt
|
||||||
import net.torvald.terrarum.floorInt
|
import net.torvald.terrarum.floorInt
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -21,18 +23,37 @@ object WorldCamera {
|
|||||||
private set
|
private set
|
||||||
var y: Int = 0 // top position
|
var y: Int = 0 // top position
|
||||||
private set
|
private set
|
||||||
var xEnd: Int = 0 // right position
|
|
||||||
private set
|
|
||||||
var yEnd: Int = 0 // bottom position
|
|
||||||
private set
|
|
||||||
inline val gdxCamX: Float // centre position
|
|
||||||
get() = xCentre.toFloat()
|
|
||||||
inline val gdxCamY: Float// centre position
|
|
||||||
get() = yCentre.toFloat()
|
|
||||||
var width: Int = 0
|
var width: Int = 0
|
||||||
private set
|
private set
|
||||||
var height: Int = 0
|
var height: Int = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
private var zoom = 1f
|
||||||
|
private var zoomSamplePoint = 0f
|
||||||
|
|
||||||
|
// zoomed coords. Currently only being used by the lightmaprenderer.
|
||||||
|
// What about others? We just waste 3/4 of the framebuffer
|
||||||
|
val zoomedX: Int
|
||||||
|
get() = x + (width * zoomSamplePoint).toInt()
|
||||||
|
val zoomedY: Int
|
||||||
|
get() = y + (height * zoomSamplePoint).toInt()
|
||||||
|
|
||||||
|
val zoomedWidth: Int
|
||||||
|
get() = (width / zoom).ceilInt()
|
||||||
|
val zoomedHeight: Int
|
||||||
|
get() = (height / zoom).ceilInt()
|
||||||
|
|
||||||
|
var xEnd: Int = 0 // right position
|
||||||
|
private set
|
||||||
|
var yEnd: Int = 0 // bottom position
|
||||||
|
private set
|
||||||
|
|
||||||
|
inline val gdxCamX: Float // centre position
|
||||||
|
get() = xCentre.toFloat()
|
||||||
|
inline val gdxCamY: Float// centre position
|
||||||
|
get() = yCentre.toFloat()
|
||||||
|
|
||||||
inline val xCentre: Int
|
inline val xCentre: Int
|
||||||
get() = x + width.ushr(1)
|
get() = x + width.ushr(1)
|
||||||
inline val yCentre: Int
|
inline val yCentre: Int
|
||||||
@@ -45,6 +66,8 @@ object WorldCamera {
|
|||||||
|
|
||||||
width = AppLoader.screenW//FastMath.ceil(AppLoader.screenW / zoom) // div, not mul
|
width = AppLoader.screenW//FastMath.ceil(AppLoader.screenW / zoom) // div, not mul
|
||||||
height = AppLoader.screenH//FastMath.ceil(AppLoader.screenH / zoom)
|
height = AppLoader.screenH//FastMath.ceil(AppLoader.screenH / zoom)
|
||||||
|
zoom = Terrarum.ingame?.screenZoom ?: 1f
|
||||||
|
zoomSamplePoint = (1f - 1f / zoom) / 2f // will never quite exceed 0.5
|
||||||
|
|
||||||
// TOP-LEFT position of camera border
|
// TOP-LEFT position of camera border
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user