diff --git a/src/net/torvald/terrarum/FuckingWorldRenderer.kt b/src/net/torvald/terrarum/FuckingWorldRenderer.kt index c4cf47479..27559484d 100644 --- a/src/net/torvald/terrarum/FuckingWorldRenderer.kt +++ b/src/net/torvald/terrarum/FuckingWorldRenderer.kt @@ -145,7 +145,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { //demoWorld.time.timeDelta = 150 - LightmapRendererNew.world = demoWorld + LightmapRenderer.world = demoWorld BlocksDrawer.world = demoWorld FeaturesDrawer.world = demoWorld @@ -220,12 +220,12 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { - LightmapRendererNew.fireRecalculateEvent() // don't half-frame update; it will jitter! + LightmapRenderer.fireRecalculateEvent() // don't half-frame update; it will jitter! } fun renderScreen() { - processBlur(LightmapRendererNew.DRAW_FOR_RGB) + processBlur(LightmapRenderer.DRAW_FOR_RGB) //camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) // render world @@ -360,7 +360,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) - LightmapRendererNew.resize(Terrarum.WIDTH, Terrarum.HEIGHT) + LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) if (loadDone) { // resize UI by re-creating it (!!) @@ -374,14 +374,14 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { } lightmapFboA = FrameBuffer( lightFBOformat, - LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), - LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), false ) lightmapFboB = FrameBuffer( lightFBOformat, - LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), - LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), false ) lightmapInitialised = true // are you the first time? @@ -420,13 +420,13 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { } - if (mode == LightmapRendererNew.DRAW_FOR_RGB) { + if (mode == LightmapRenderer.DRAW_FOR_RGB) { // initialise readBuffer with untreated lightmap blurReadBuffer.inAction(camera, batch) { batch.inUse { blendNormal(batch) batch.color = Color.WHITE - LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB) + LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_RGB) } } } @@ -436,7 +436,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { batch.inUse { blendNormal(batch) batch.color = Color.WHITE - LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_ALPHA) + LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_ALPHA) } } } diff --git a/src/net/torvald/terrarum/Ingame.kt b/src/net/torvald/terrarum/Ingame.kt index 147c7ac9b..9fdc68143 100644 --- a/src/net/torvald/terrarum/Ingame.kt +++ b/src/net/torvald/terrarum/Ingame.kt @@ -32,6 +32,7 @@ import javax.swing.JOptionPane import com.badlogic.gdx.graphics.OrthographicCamera import net.torvald.random.HQRNG +import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.ui.* import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser import net.torvald.terrarum.worldgenerator.WorldGenerator @@ -93,13 +94,11 @@ class Ingame(val batch: SpriteBatch) : Screen { var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false) var worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false) // RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit - var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false) - var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false) + private lateinit var lightmapFboA: FrameBuffer + private lateinit var lightmapFboB: FrameBuffer init { - println("worldDrawFrameBuffer.colorBufferTexture.textureData.format: ${worldDrawFrameBuffer.colorBufferTexture.textureData.format}") - println("lightmapFboB.colorBufferTexture.textureData.format: ${lightmapFboB.colorBufferTexture.textureData.format}") } @@ -157,6 +156,8 @@ class Ingame(val batch: SpriteBatch) : Screen { private set + private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() + ////////////// // GDX code // ////////////// @@ -523,9 +524,6 @@ class Ingame(val batch: SpriteBatch) : Screen { } - private var blurWriteBuffer = lightmapFboA - private var blurReadBuffer = lightmapFboB - private fun renderGame(batch: SpriteBatch) { Gdx.gl.glClearColor(.094f, .094f, .094f, 0f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) @@ -539,10 +537,7 @@ class Ingame(val batch: SpriteBatch) : Screen { - // update lightmap on every other frames, OR full-frame if the option is true - if (Terrarum.getConfigBoolean("fullframelightupdate") or (TerrarumAppLoader.GLOBAL_RENDER_TIMER % 2 == 1)) { - LightmapRenderer.fireRecalculateEvent() - } + LightmapRenderer.fireRecalculateEvent() @@ -608,17 +603,20 @@ class Ingame(val batch: SpriteBatch) : Screen { batch.shader.setUniformf("gcount", 64f) batch.shader.setUniformf("bcount", 64f) // de-banding - val lightTex = blurWriteBuffer.colorBufferTexture // TODO zoom! - - lightTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) + val lightTex = lightmapFboB.colorBufferTexture // A or B? flipped in Y means you chose wrong buffer; use one that works correctly + lightTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) // blocky feeling for A E S T H E T I C S if (KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendNormal() else blendMul() batch.color = Color.WHITE + val xrem = -(WorldCamera.x.toFloat() fmod TILE_SIZEF) + val yrem = -(WorldCamera.y.toFloat() fmod TILE_SIZEF) batch.draw(lightTex, - 0f, 0f, - lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample + xrem, + yrem, + lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample + //lightTex.width.toFloat(), lightTex.height.toFloat() // for debugging ) } @@ -677,17 +675,20 @@ class Ingame(val batch: SpriteBatch) : Screen { batch.shader.setUniformf("gcount", 64f) batch.shader.setUniformf("bcount", 64f) // de-banding - val lightTex = blurWriteBuffer.colorBufferTexture // TODO zoom! - - lightTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) + val lightTex = lightmapFboB.colorBufferTexture // A or B? flipped in Y means you chose wrong buffer; use one that works correctly + lightTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) // blocky feeling for A E S T H E T I C S if (KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendNormal() else blendMul() batch.color = Color.WHITE + val xrem = -(WorldCamera.x.toFloat() fmod TILE_SIZEF) + val yrem = -(WorldCamera.y.toFloat() fmod TILE_SIZEF) batch.draw(lightTex, - 0f, 0f, - lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample + xrem, + yrem, + lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample + //lightTex.width.toFloat(), lightTex.height.toFloat() // for debugging ) } @@ -856,8 +857,8 @@ class Ingame(val batch: SpriteBatch) : Screen { val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image val blurRadius = 4f / lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics - blurWriteBuffer = lightmapFboA - blurReadBuffer = lightmapFboB + var blurWriteBuffer = lightmapFboA + var blurReadBuffer = lightmapFboB lightmapFboA.inAction(null, null) { @@ -874,17 +875,7 @@ class Ingame(val batch: SpriteBatch) : Screen { // initialise readBuffer with untreated lightmap blurReadBuffer.inAction(camera, batch) { batch.inUse { - // using custom code for camera; this is obscure and tricky - camera.position.set( - (WorldCamera.gdxCamX / lightmapDownsample).round(), - (WorldCamera.gdxCamY / lightmapDownsample).round(), - 0f - ) // make camara work - camera.update() - batch.projectionMatrix = camera.combined - - - blendNormal() + blendNormal(batch) batch.color = Color.WHITE LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_RGB) } @@ -894,17 +885,7 @@ class Ingame(val batch: SpriteBatch) : Screen { // initialise readBuffer with untreated lightmap blurReadBuffer.inAction(camera, batch) { batch.inUse { - // using custom code for camera; this is obscure and tricky - camera.position.set( - (WorldCamera.gdxCamX / lightmapDownsample).round(), - (WorldCamera.gdxCamY / lightmapDownsample).round(), - 0f - ) // make camara work - camera.update() - batch.projectionMatrix = camera.combined - - - blendNormal() + blendNormal(batch) batch.color = Color.WHITE LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_ALPHA) } @@ -1346,6 +1327,10 @@ class Ingame(val batch: SpriteBatch) : Screen { dispose() } + + + private var lightmapInitialised = false // to avoid nullability of lightmapFBO + /** * @param width same as Terrarum.WIDTH * @param height same as Terrarum.HEIGHT @@ -1354,6 +1339,7 @@ class Ingame(val batch: SpriteBatch) : Screen { override fun resize(width: Int, height: Int) { BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) + LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) worldDrawFrameBuffer.dispose() worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false) @@ -1361,10 +1347,24 @@ class Ingame(val batch: SpriteBatch) : Screen { worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false) worldBlendFrameBuffer.dispose() worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false) - lightmapFboA.dispose() - lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false) - lightmapFboB.dispose() - lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false) + + if (lightmapInitialised) { + lightmapFboA.dispose() + lightmapFboB.dispose() + } + lightmapFboA = FrameBuffer( + lightFBOformat, + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + false + ) + lightmapFboB = FrameBuffer( + lightFBOformat, + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + false + ) + lightmapInitialised = true // are you the first time? // Set up viewport when window is resized diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 3fe164f73..1b026e36b 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -442,8 +442,8 @@ object Terrarum : Screen { // title screen - //appLoader.setScreen(TitleScreen(batch)) - appLoader.setScreen(FuckingWorldRenderer(batch)) + appLoader.setScreen(TitleScreen(batch)) + //appLoader.setScreen(FuckingWorldRenderer(batch)) } internal fun setScreen(screen: Screen) { diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index 3c07a7db6..a2c483b47 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -136,7 +136,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { setHitboxDimension(2, 2, 0, 0) hitbox.setPosition( HQRNG().nextInt(demoWorld.width) * FeaturesDrawer.TILE_SIZE.toDouble(), - 0.0 // placeholder; camera AI will take it over + 0.0 // Y pos: placeholder; camera AI will take it over ) noClip = true } @@ -145,7 +145,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { demoWorld.time.timeDelta = 150 - LightmapRendererNew.world = demoWorld + LightmapRenderer.world = demoWorld BlocksDrawer.world = demoWorld FeaturesDrawer.world = demoWorld @@ -201,7 +201,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } fun updateScreen(delta: Float) { - Gdx.graphics.setTitle(TerrarumAppLoader.GAME_NAME + + Gdx.graphics.setTitle("WorldRenderTest" + " — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" + " — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" ) @@ -220,12 +220,12 @@ class TitleScreen(val batch: SpriteBatch) : Screen { - LightmapRendererNew.fireRecalculateEvent() // don't half-frame update; it will jitter! + LightmapRenderer.fireRecalculateEvent() // don't half-frame update; it will jitter! } fun renderScreen() { - processBlur(LightmapRendererNew.DRAW_FOR_RGB) + processBlur(LightmapRenderer.DRAW_FOR_RGB) //camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) // render world @@ -248,6 +248,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } private fun renderDemoWorld() { + // draw skybox // setCameraPosition(0f, 0f) @@ -354,7 +355,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) - LightmapRendererNew.resize(Terrarum.WIDTH, Terrarum.HEIGHT) + LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) if (loadDone) { // resize UI by re-creating it (!!) @@ -368,14 +369,14 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } lightmapFboA = FrameBuffer( lightFBOformat, - LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), - LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), false ) lightmapFboB = FrameBuffer( lightFBOformat, - LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), - LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), + LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), false ) lightmapInitialised = true // are you the first time? @@ -414,13 +415,13 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } - if (mode == LightmapRendererNew.DRAW_FOR_RGB) { + if (mode == LightmapRenderer.DRAW_FOR_RGB) { // initialise readBuffer with untreated lightmap blurReadBuffer.inAction(camera, batch) { batch.inUse { blendNormal(batch) batch.color = Color.WHITE - LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB) + LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_RGB) } } } @@ -430,7 +431,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { batch.inUse { blendNormal(batch) batch.color = Color.WHITE - LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_ALPHA) + LightmapRenderer.draw(batch, LightmapRenderer.DRAW_FOR_ALPHA) } } } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index a1979354c..b4334bf9b 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -55,10 +55,6 @@ object BlocksDrawer { private val TILE_SIZE = FeaturesDrawer.TILE_SIZE private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() - // TODO modular - //val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "blocks/terrain.tga.gz"), TILE_SIZE, TILE_SIZE) // 64 MB - //val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "blocks/wire.tga.gz"), TILE_SIZE, TILE_SIZE) // 4 MB - val tilesTerrain: TextureRegionPack val tilesWire: TextureRegionPack val tileItemWall: TextureRegionPack diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index 713768e90..9c8f866ec 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -23,7 +23,7 @@ import java.util.* // NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable -object LightmapRenderer { +object LightmapRendererOld { lateinit var world: GameWorld diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index b293fa71d..2dce2e6c9 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -26,7 +26,7 @@ import java.util.* // NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable -object LightmapRendererNew { +object LightmapRenderer { lateinit var world: GameWorld