From cc00e1eff9f41aec29370548d536c11ca0b813fa Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 5 Feb 2024 01:26:27 +0900 Subject: [PATCH] I fixed the ingamerender-not-rendering bug?? --- src/net/torvald/terrarum/App.java | 3 ++- .../terrarum/modulebasegame/BuildingMaker.kt | 2 ++ .../terrarum/modulebasegame/IngameRenderer.kt | 22 +++++++++---------- .../terrarum/modulebasegame/TerrarumIngame.kt | 3 +++ .../terrarum/modulebasegame/TitleScreen.kt | 2 ++ .../modulebasegame/ui/UISoundControlPanel.kt | 3 +-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index eec97158f..0e4ca885b 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -1246,7 +1246,7 @@ public class App implements ApplicationListener { printdbg(this, "PostInit done; took "+tms+" seconds"); } - public static void renewAudioProcessor(int bufferSize) { + public static void reloadAudioProcessor(int bufferSize) { // copy music tracks var dynaicTracks = audioMixer.getDynamicTracks(); var staticTracks = audioMixer.getTracks(); @@ -1280,6 +1280,7 @@ public class App implements ApplicationListener { e.printStackTrace(); } }*/ + } diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index 01d34d517..d451c4f24 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -306,6 +306,8 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { var mousePrimaryJustDown = false; private set override fun render(updateRate: Float) { + IngameRenderer.setRenderedWorld(gameWorld) + super.render(updateRate) diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 6c89fed34..9e363f09d 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -180,27 +180,27 @@ object IngameRenderer : Disposable { * - When the game make transition to the new world (advancing to the next level/entering or exiting the room) */ fun setRenderedWorld(world: GameWorld) { - printdbg(this, "Set new RenderedWorld (UUID=${world.worldIndex}) at time ${System.currentTimeMillis()}, called by:") - printStackTrace(this) +// printdbg(this, "Set new RenderedWorld (UUID=${world.worldIndex}) at time ${System.currentTimeMillis()} (disposed: ${world.disposed}), called by:") +// printStackTrace(this) try { + + // change worlds from internal methods + this.world = world + LightmapRenderer.internalSetWorld(world) + BlocksDrawer.world = world + FeaturesDrawer.world = world + if (this.world != world) { // printdbg(this, "World change detected -- " + // "old world: ${this.world.hashCode()}, " + // "new world: ${world.hashCode()}") - - // change worlds from internal methods - this.world = world - LightmapRenderer.internalSetWorld(world) - BlocksDrawer.world = world - FeaturesDrawer.world = world - newWorldLoadedLatch = true } } - catch (e: UninitializedPropertyAccessException) { + catch (e: Throwable) { + e.printStackTrace() // new init, do nothing - this.world = world } } diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 2c3de822f..59fdafa45 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -810,6 +810,9 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { gameFullyLoaded = true } + else { + IngameRenderer.setRenderedWorld(world) // this doesn't slow down the game and prevents world-changing related bugs + } super.render(updateRate) diff --git a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt index 95abe5726..887d38382 100644 --- a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt @@ -309,6 +309,8 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) { private var introUncoverDeltaCounter = 0f override fun render(updateRate: Float) { + IngameRenderer.setRenderedWorld(demoWorld) + super.render(updateRate) // async update and render gameUpdateGovernor.update(Gdx.graphics.deltaTime, App.UPDATE_RATE, updateScreen, renderScreen) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt index 4c2b5ad8f..770d11c03 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt @@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.App -import net.torvald.terrarum.audio.AudioMixer import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.ui.UICanvas @@ -48,7 +47,7 @@ class UISoundControlPanel(remoCon: UIRemoCon?) : UICanvas() { if (it != oldBufferSize) { oldBufferSize = it - App.renewAudioProcessor(it) + App.reloadAudioProcessor(it) } } }