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

@@ -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
}
}