fixed a bug where wires won't pop up as the camera moves

This commit is contained in:
minjaesong
2021-12-28 15:28:45 +09:00
parent 9810d0927c
commit c9b87492c2
6 changed files with 42 additions and 29 deletions

View File

@@ -318,17 +318,17 @@ open class ActorWithBody : Actor {
//@Transient private val CCD_TRY_MAX = 12800
// just some trivial magic numbers
@Transient private val A_PIXEL = 1.0
@Transient private val HALF_PIXEL = 0.5
@Transient val A_PIXEL = 1.0
@Transient val HALF_PIXEL = 0.5
@Transient private val COLLIDING_LEFT = 1
@Transient private val COLLIDING_BOTTOM = 2
@Transient private val COLLIDING_RIGHT = 4
@Transient private val COLLIDING_TOP = 8
@Transient val COLLIDING_LEFT = 1
@Transient val COLLIDING_BOTTOM = 2
@Transient val COLLIDING_RIGHT = 4
@Transient val COLLIDING_TOP = 8
@Transient private val COLLIDING_UD = 10
@Transient private val COLLIDING_LR = 5
@Transient private val COLLIDING_ALLSIDE = 15
@Transient val COLLIDING_UD = 10
@Transient val COLLIDING_LR = 5
@Transient val COLLIDING_ALLSIDE = 15
//@Transient private val COLLIDING_LEFT_EXTRA = 7
//@Transient private val COLLIDING_RIGHT_EXTRA = 7
@@ -1051,7 +1051,7 @@ open class ActorWithBody : Actor {
/**
* @see /work_files/hitbox_collision_detection_compensation.jpg
*/
private fun isWalled(hitbox: Hitbox, option: Int): Boolean {
fun isWalled(hitbox: Hitbox, option: Int): Boolean {
val x1: Double
val x2: Double
val y1: Double

View File

@@ -223,7 +223,7 @@ object IngameRenderer : Disposable {
if (!gamePaused || newWorldLoadedLatch) {
measureDebugTime("Renderer.ApparentLightRun") {
measureDebugTime("Renderer.LightRun*") {
// recalculate for even frames, or if the sign of the cam-x changed
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)

View File

@@ -48,6 +48,7 @@ import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer.LIGHTMAP_OVERRENDER
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.util.CircularArray
import org.khelekore.prtree.PRTree
@@ -798,15 +799,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
measureDebugTime("BlockStats.update") {
BlockStats.update()
}
// fill up visibleActorsRenderFront for wires, if:
// 0. Camera or player x position wrapped
// 1. new world has been loaded
// 2. something is cued on the wire change queue
// 3. wire renderclass changed
if (Math.abs(WorldCamera.x - oldCamX) >= worldWidth * 0.5 ||
Math.abs((actorNowPlaying?.hitbox?.canonicalX ?: 0.0) - oldPlayerX) >= worldWidth * 0.5 ||
newWorldLoadedLatch || wireChangeQueue.isNotEmpty() || selectedWireRenderClass != oldSelectedWireRenderClass) {
measureDebugTime("Ingame.FillUpWiresBuffer") {
// fill up visibleActorsRenderFront for wires but not on every update
measureDebugTime("Ingame.FillUpWiresBuffer*") {
if (WORLD_UPDATE_TIMER % 2 == 1) {
fillUpWiresBuffer()
}
}
@@ -894,11 +889,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
} }
private fun fillUpWiresBuffer() {
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt() - LIGHTMAP_OVERRENDER
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical + 2*LIGHTMAP_OVERRENDER
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt() - LIGHTMAP_OVERRENDER
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal + 2*LIGHTMAP_OVERRENDER
var wiringCounter = 0
for (y in for_y_start..for_y_end) {

View File

@@ -11,6 +11,7 @@ import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.worldgenerator.TWO_PI
/**
* Created by minjaesong on 2016-03-15.
@@ -55,6 +56,16 @@ open class DroppedItem : ActorWithBody {
)
setPosition(topLeftX + (hitbox.width / 2.0), topLeftY + hitbox.height)
// random horizontal movement
val magn = Math.random() * 1.3
externalV.x = if (isWalled(hitbox, COLLIDING_LEFT))
Math.cos(Math.random() * Math.PI / 2) * magn
else if (isWalled(hitbox, COLLIDING_RIGHT))
Math.cos(Math.random() * Math.PI / 2 + Math.PI / 2) * magn
else
Math.cos(Math.random() * Math.PI) * magn
}
override fun drawBody(batch: SpriteBatch) {
@@ -86,5 +97,6 @@ open class DroppedItem : ActorWithBody {
timeSinceSpawned += delta
// TODO merge into the already existing droppeditem with isStationary==true if one is detected
}
}

View File

@@ -67,7 +67,7 @@ object LightmapRenderer {
const val overscan_open: Int = 40
const val overscan_opaque: Int = 10
const val LIGHTMAP_OVERRENDER = 20
const val LIGHTMAP_OVERRENDER = 10
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
@@ -166,10 +166,10 @@ object LightmapRenderer {
if (WorldCamera.x < 0) for_draw_x_start -= 1 // edge case fix that light shift 1 tile to the left when WorldCamera.x < 0
//if (WorldCamera.x in -(TILE_SIZE - 1)..-1) for_draw_x_start -= 1 // another edge-case fix; we don't need this anymore?
for_x_end = for_x_start + WorldCamera.zoomedWidth / TILE_SIZE + 3
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 + 2*LIGHTMAP_OVERRENDER
for_draw_y_end = for_draw_y_start + WorldCamera.height / TILE_SIZE + 3 + 2*LIGHTMAP_OVERRENDER
for_x_end = for_x_start + WorldCamera.zoomedWidth / TILE_SIZE + 1
for_y_end = for_y_start + WorldCamera.zoomedHeight / TILE_SIZE + 1
for_draw_x_end = for_draw_x_start + WorldCamera.width / TILE_SIZE + 1 + 2*LIGHTMAP_OVERRENDER
for_draw_y_end = for_draw_y_start + WorldCamera.height / TILE_SIZE + 1 + 2*LIGHTMAP_OVERRENDER
camX = WorldCamera.x / TILE_SIZE
camY = WorldCamera.y / TILE_SIZE

View File

@@ -288,6 +288,12 @@ class Vector2 {
this.y = y
}
fun setPolar(magnitude: Double, direction: Double) {
this.x = Math.cos(direction) * magnitude
this.y = Math.sin(direction) * magnitude
}
/**
* Returns the x component of this [Vector2].
* @return [Vector2]