mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
fix: new world from world portal not updating world ref of IngameRenderer
This commit is contained in:
@@ -175,26 +175,29 @@ object IngameRenderer : Disposable {
|
|||||||
* - When the game make transition to the new world (advancing to the next level/entering or exiting the room)
|
* - When the game make transition to the new world (advancing to the next level/entering or exiting the room)
|
||||||
*/
|
*/
|
||||||
fun setRenderedWorld(world: GameWorld) {
|
fun setRenderedWorld(world: GameWorld) {
|
||||||
try {
|
printdbg(this, "Set new RenderedWorld (UUID=${world.worldIndex}) at time ${System.currentTimeMillis()}, called by:")
|
||||||
if (this.world != world) {
|
printStackTrace(this)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.world != world) {
|
||||||
// printdbg(this, "World change detected -- " +
|
// printdbg(this, "World change detected -- " +
|
||||||
// "old world: ${this.world.hashCode()}, " +
|
// "old world: ${this.world.hashCode()}, " +
|
||||||
// "new world: ${world.hashCode()}")
|
// "new world: ${world.hashCode()}")
|
||||||
|
|
||||||
// change worlds from internal methods
|
// change worlds from internal methods
|
||||||
this.world = world
|
|
||||||
LightmapRenderer.internalSetWorld(world)
|
|
||||||
BlocksDrawer.world = world
|
|
||||||
FeaturesDrawer.world = world
|
|
||||||
|
|
||||||
newWorldLoadedLatch = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e: UninitializedPropertyAccessException) {
|
|
||||||
// new init, do nothing
|
|
||||||
this.world = world
|
this.world = world
|
||||||
|
LightmapRenderer.internalSetWorld(world)
|
||||||
|
BlocksDrawer.world = world
|
||||||
|
FeaturesDrawer.world = world
|
||||||
|
|
||||||
|
newWorldLoadedLatch = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (e: UninitializedPropertyAccessException) {
|
||||||
|
// new init, do nothing
|
||||||
|
this.world = world
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var oldCamX = 0
|
private var oldCamX = 0
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
|
|||||||
|
|
||||||
previewPixmap.setColor(Color.BLACK)
|
previewPixmap.setColor(Color.BLACK)
|
||||||
previewPixmap.fill()
|
previewPixmap.fill()
|
||||||
|
|
||||||
|
IngameRenderer.setRenderedWorld(world)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
|
|||||||
@@ -201,12 +201,14 @@ internal object BlocksDrawer {
|
|||||||
}
|
}
|
||||||
catch (e: ClassCastException) { }
|
catch (e: ClassCastException) { }
|
||||||
|
|
||||||
measureDebugTime("Renderer.Tiling") {
|
if (!world.layerTerrain.ptrDestroyed) {
|
||||||
drawTiles(WALL)
|
measureDebugTime("Renderer.Tiling") {
|
||||||
drawTiles(TERRAIN) // regular tiles
|
drawTiles(WALL)
|
||||||
drawTiles(FLUID)
|
drawTiles(TERRAIN) // regular tiles
|
||||||
drawTiles(OCCLUSION)
|
drawTiles(FLUID)
|
||||||
//drawTiles(WIRE)
|
drawTiles(OCCLUSION)
|
||||||
|
//drawTiles(WIRE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,9 @@ object LightmapRenderer {
|
|||||||
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
|
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun recalculate(actorContainer: List<ActorWithBody>) = _recalculate(actorContainer, lightmap)
|
fun recalculate(actorContainer: List<ActorWithBody>) {
|
||||||
|
if (!world.layerTerrain.ptrDestroyed) _recalculate(actorContainer, lightmap)
|
||||||
|
}
|
||||||
|
|
||||||
private fun _recalculate(actorContainer: List<ActorWithBody>, lightmap: UnsafeCvecArray) {
|
private fun _recalculate(actorContainer: List<ActorWithBody>, lightmap: UnsafeCvecArray) {
|
||||||
try {
|
try {
|
||||||
@@ -661,35 +663,37 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
internal fun draw(): Texture {
|
internal fun draw(): Texture {
|
||||||
|
|
||||||
// when shader is not used: 0.5 ms on 6700K
|
if (!world.layerTerrain.ptrDestroyed) {
|
||||||
App.measureDebugTime("Renderer.LightToScreen") {
|
// when shader is not used: 0.5 ms on 6700K
|
||||||
|
App.measureDebugTime("Renderer.LightToScreen") {
|
||||||
|
|
||||||
val this_x_start = for_draw_x_start
|
val this_x_start = for_draw_x_start
|
||||||
val this_y_start = for_draw_y_start
|
val this_y_start = for_draw_y_start
|
||||||
val this_x_end = for_draw_x_end
|
val this_x_end = for_draw_x_end
|
||||||
val this_y_end = for_draw_y_end
|
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 =
|
||||||
lightBuffer.setColor(0)
|
Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)
|
||||||
lightBuffer.fill()
|
lightBuffer.setColor(0)
|
||||||
|
lightBuffer.fill()
|
||||||
|
|
||||||
|
|
||||||
// write to colour buffer
|
// write to colour buffer
|
||||||
for (y in this_y_start..this_y_end) {
|
for (y in this_y_start..this_y_end) {
|
||||||
//println("y: $y, this_y_start: $this_y_start")
|
//println("y: $y, this_y_start: $this_y_start")
|
||||||
//if (y == this_y_start && this_y_start == 0) {
|
//if (y == this_y_start && this_y_start == 0) {
|
||||||
// throw Error("Fuck hits again...")
|
// throw Error("Fuck hits again...")
|
||||||
//}
|
//}
|
||||||
|
|
||||||
for (x in this_x_start..this_x_end) {
|
for (x in this_x_start..this_x_end) {
|
||||||
|
|
||||||
val solidMultMagic = isSolid(x, y) // one of {1.2f, 1f, null}
|
val solidMultMagic = isSolid(x, y) // one of {1.2f, 1f, null}
|
||||||
|
|
||||||
val arrayX = x.convX()
|
val arrayX = x.convX()
|
||||||
val arrayY = y.convY()
|
val arrayY = y.convY()
|
||||||
|
|
||||||
val (red, grn, blu, uvl) = lightmap.getVec(arrayX, arrayY)
|
val (red, grn, blu, uvl) = lightmap.getVec(arrayX, arrayY)
|
||||||
// val redw = (red.sqrt() - 1f) * (7f / 24f)
|
// val redw = (red.sqrt() - 1f) * (7f / 24f)
|
||||||
// val grnw = (grn.sqrt() - 1f)
|
// val grnw = (grn.sqrt() - 1f)
|
||||||
// val bluw = (blu.sqrt() - 1f) * (7f / 72f)
|
// val bluw = (blu.sqrt() - 1f) * (7f / 72f)
|
||||||
@@ -698,13 +702,13 @@ object LightmapRenderer {
|
|||||||
// val uvlwg = (uvl.sqrt() - 1f) * (1f / 10f)
|
// val uvlwg = (uvl.sqrt() - 1f) * (1f / 10f)
|
||||||
// val uvlwb = (uvl.sqrt() - 1f) * (1f / 8f)
|
// val uvlwb = (uvl.sqrt() - 1f) * (1f / 8f)
|
||||||
|
|
||||||
if (solidMultMagic == null)
|
if (solidMultMagic == null)
|
||||||
lightBuffer.drawPixel(
|
lightBuffer.drawPixel(
|
||||||
x - this_x_start,
|
x - this_x_start,
|
||||||
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
/*lightBuffer.drawPixel(
|
/*lightBuffer.drawPixel(
|
||||||
x - this_x_start,
|
x - this_x_start,
|
||||||
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
||||||
@@ -713,28 +717,29 @@ object LightmapRenderer {
|
|||||||
(max(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
(max(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||||
(max(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
(max(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||||
)*/
|
)*/
|
||||||
lightBuffer.drawPixel(
|
lightBuffer.drawPixel(
|
||||||
x - this_x_start,
|
x - this_x_start,
|
||||||
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
||||||
(red * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
(red * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
||||||
(grn * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
(grn * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
||||||
(blu * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
(blu * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||||
(uvl * solidMultMagic).hdnorm().times(255f).roundToInt()
|
(uvl * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// draw to the batch
|
// draw to the batch
|
||||||
_lightBufferAsTex.dispose()
|
_lightBufferAsTex.dispose()
|
||||||
_lightBufferAsTex = Texture(lightBuffer)
|
_lightBufferAsTex = Texture(lightBuffer)
|
||||||
_lightBufferAsTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
_lightBufferAsTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
|
|
||||||
/*Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
/*Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||||
// we might not need shader here...
|
// we might not need shader here...
|
||||||
//batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat())
|
//batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat())
|
||||||
batch.draw(_lightBufferAsTex, 0f, 0f, _lightBufferAsTex.width * DRAW_TILE_SIZE, _lightBufferAsTex.height * DRAW_TILE_SIZE)
|
batch.draw(_lightBufferAsTex, 0f, 0f, _lightBufferAsTex.width * DRAW_TILE_SIZE, _lightBufferAsTex.height * DRAW_TILE_SIZE)
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _lightBufferAsTex
|
return _lightBufferAsTex
|
||||||
|
|||||||
Reference in New Issue
Block a user