From d5450cd128f7d028c4d8178d3fbdcbb8ada7bf8c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 12 Sep 2017 21:29:45 +0900 Subject: [PATCH] Light fuck: At least I've figured out what the fuck was wrong with. --- assets/graphics/fonts/milky.tga | 4 +- assets/modules/basegame/items/testpick.groovy | 2 +- .../torvald/terrarum/FuckingWorldRenderer.kt | 32 +++++++------- src/net/torvald/terrarum/Ingame.kt | 4 +- src/net/torvald/terrarum/Terrarum.kt | 9 +--- .../torvald/terrarum/TerrarumAppLoader.java | 11 +++++ src/net/torvald/terrarum/TitleScreen.kt | 2 +- .../terrarum/gameactors/ActorWithPhysics.kt | 29 ++++++++----- .../gameactors/PlayableActorDelegate.kt | 4 +- .../terrarum/itemproperties/ItemCodex.kt | 4 +- .../modulebasegame/items/PickaxeGeneric.kt | 2 +- .../torvald/terrarum/ui/UIBasicNotifier.kt | 4 +- src/net/torvald/terrarum/ui/UITierOneWatch.kt | 2 +- .../terrarum/worlddrawer/BlocksDrawerNew.kt | 1 + .../worlddrawer/LightmapRendererNew.kt | 43 +++++++++++++++---- 15 files changed, 99 insertions(+), 54 deletions(-) diff --git a/assets/graphics/fonts/milky.tga b/assets/graphics/fonts/milky.tga index 40e14918e..ddb8adb0b 100644 --- a/assets/graphics/fonts/milky.tga +++ b/assets/graphics/fonts/milky.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f3a07103f014cbe18bc3e10f71358462fb12a35aca32395c2b605add96e16b59 -size 65554 +oid sha256:37d21a17f16be7b1d70a51fcae88c94859dfe5f9182df6d9c04bfba0900139d5 +size 98348 diff --git a/assets/modules/basegame/items/testpick.groovy b/assets/modules/basegame/items/testpick.groovy index 6c3ebb2e6..4c7914368 100644 --- a/assets/modules/basegame/items/testpick.groovy +++ b/assets/modules/basegame/items/testpick.groovy @@ -67,7 +67,7 @@ class TestPick extends GameItem { // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors Terrarum.ingame.actorContainer.forEach({ - if (it instanceof ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) + if (it instanceof ActorWithPhysics && it.getHIntTilewiseHitbox.intersects(mousePoint)) return false }) diff --git a/src/net/torvald/terrarum/FuckingWorldRenderer.kt b/src/net/torvald/terrarum/FuckingWorldRenderer.kt index 5657b142a..05af18d5d 100644 --- a/src/net/torvald/terrarum/FuckingWorldRenderer.kt +++ b/src/net/torvald/terrarum/FuckingWorldRenderer.kt @@ -216,7 +216,8 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { uiContainer.forEach { it.update(delta) } - if (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1) { + + if (TerrarumAppLoader.GLOBAL_RENDER_TIMER % 2 == 1) { LightmapRendererNew.fireRecalculateEvent() } } @@ -224,7 +225,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { fun renderScreen() { // render and blur lightmap - processBlur(LightmapRendererNew.DRAW_FOR_RGB) + ///////////processBlur(LightmapRendererNew.DRAW_FOR_RGB) //camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) // render world @@ -246,7 +247,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { batch.shader = null batch.color = Color.WHITE renderMenus() - //renderOverlayTexts() + renderOverlayTexts() } @@ -280,33 +281,34 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen { // draw tiles // - - blendNormal() - - BlocksDrawer.renderWall(batch) BlocksDrawer.renderTerrain(batch) + Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + + FeaturesDrawer.drawEnvOverlay(batch) // draw lightmap // setCameraPosition(0f, 0f) - batch.shader = Terrarum.shaderBayer - batch.shader.setUniformf("rcount", 64f) - batch.shader.setUniformf("gcount", 64f) - batch.shader.setUniformf("bcount", 64f) // de-banding - val lightTex = blurWriteBuffer.colorBufferTexture - lightTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) + //batch.shader = Terrarum.shaderBayer + //batch.shader.setUniformf("rcount", 64f) + //batch.shader.setUniformf("gcount", 64f) + //batch.shader.setUniformf("bcount", 64f) // de-banding + //val lightTex = blurWriteBuffer.colorBufferTexture + //lightTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) //blendMul() blendNormal() + batch.shader = null batch.color = Color.WHITE - batch.draw(logo.texture,//lightTex, + /*batch.draw(lightTex, 0f, 0f, //lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample lightTex.width.toFloat(), lightTex.height.toFloat() - ) + )*/ + LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB) batch.shader = null diff --git a/src/net/torvald/terrarum/Ingame.kt b/src/net/torvald/terrarum/Ingame.kt index 7ed664166..147c7ac9b 100644 --- a/src/net/torvald/terrarum/Ingame.kt +++ b/src/net/torvald/terrarum/Ingame.kt @@ -74,7 +74,7 @@ class Ingame(val batch: SpriteBatch) : Screen { val ZOOM_MINIMUM = 0.5f companion object { - val lightmapDownsample = 2f //2f: still has choppy look when the camera moves but unnoticeable when blurred + val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred /** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */ @@ -540,7 +540,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 (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1)) { + if (Terrarum.getConfigBoolean("fullframelightupdate") or (TerrarumAppLoader.GLOBAL_RENDER_TIMER % 2 == 1)) { LightmapRenderer.fireRecalculateEvent() } diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 63d7644e6..7cdae5f8d 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -117,12 +117,6 @@ object Terrarum : Screen { val TARGET_INTERNAL_FPS: Double = 60.0 - /** - * For the events depends on rendering frame (e.g. flicker on post-hit invincibility) - */ - var GLOBAL_RENDER_TIMER = Random().nextInt(1020) + 1 - - @@ -458,7 +452,8 @@ object Terrarum : Screen { override fun render(delta: Float) { //appLoader.screen.render(deltaTime) - GLOBAL_RENDER_TIMER += 1 + //GLOBAL_RENDER_TIMER += 1 + // moved to TerrarumAppLoader; global event must be place at the apploader to prevent ACCIDENTAL forgot-to-update type of bug. } override fun pause() { diff --git a/src/net/torvald/terrarum/TerrarumAppLoader.java b/src/net/torvald/terrarum/TerrarumAppLoader.java index 22b70e968..d7e625ce8 100644 --- a/src/net/torvald/terrarum/TerrarumAppLoader.java +++ b/src/net/torvald/terrarum/TerrarumAppLoader.java @@ -12,6 +12,8 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram; import net.torvald.terrarumsansbitmap.gdx.GameFontBase; import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack; +import java.util.Random; + /** * Created by minjaesong on 2017-08-01. */ @@ -49,6 +51,12 @@ public class TerrarumAppLoader implements ApplicationListener { public static GameFontBase fontGame; + /** + * For the events depends on rendering frame (e.g. flicker on post-hit invincibility) + */ + public static int GLOBAL_RENDER_TIMER = new Random().nextInt(1020) + 1; + + public static void main(String[] args) { appConfig = new LwjglApplicationConfiguration(); appConfig.vSyncEnabled = false; @@ -160,6 +168,9 @@ public class TerrarumAppLoader implements ApplicationListener { else { screen.render(Gdx.graphics.getDeltaTime()); } + + + GLOBAL_RENDER_TIMER += 1; } @Override diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index 93a0b1905..7d67d11e8 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -217,7 +217,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { uiContainer.forEach { it.update(delta) } - if (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1) { + if (TerrarumAppLoader.GLOBAL_RENDER_TIMER % 2 == 1) { LightmapRenderer.fireRecalculateEvent() } } diff --git a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt index 6ae62819b..573f3d821 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt @@ -59,12 +59,21 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val */ override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double; - val tilewiseHitbox: Hitbox + /** half integer tilewise hitbox */ // got the idea from gl_FragCoord + val hIntTilewiseHitbox: Hitbox + get() = Hitbox.fromTwoPoints( + hitbox.startX.div(TILE_SIZE).floor() + 0.5f, + hitbox.startY.div(TILE_SIZE).floor() + 0.5f, + hitbox.endX.div(TILE_SIZE).floor() + 0.5f, + hitbox.endY.div(TILE_SIZE).floor() + 0.5f + ) + + val intTilewiseHitbox: Hitbox get() = Hitbox.fromTwoPoints( hitbox.startX.div(TILE_SIZE).floor(), hitbox.startY.div(TILE_SIZE).floor(), - hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(), - hitbox.endY.minus(0.00001).div(TILE_SIZE).floor() + hitbox.endX.div(TILE_SIZE).floor(), + hitbox.endY.div(TILE_SIZE).floor() ) /** @@ -301,7 +310,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val inline val feetPosPoint: Point2d get() = Point2d(hitbox.centeredX, hitbox.endY) inline val feetPosTile: IntArray - get() = intArrayOf(tilewiseHitbox.centeredX.floorInt(), tilewiseHitbox.endY.floorInt()) + get() = intArrayOf(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt()) override fun run() = update(updateDelta) @@ -1287,8 +1296,8 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) { val tiles = ArrayList() - for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) { - for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { + for (y in hIntTilewiseHitbox.startY.toInt()..hIntTilewiseHitbox.endY.toInt()) { + for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) { tiles.add(world.getTileFromTerrain(x, y)) } } @@ -1298,8 +1307,8 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) { val tileProps = ArrayList() - for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) { - for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { + for (y in hIntTilewiseHitbox.startY.toInt()..hIntTilewiseHitbox.endY.toInt()) { + for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) { tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)]) } } @@ -1331,7 +1340,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val // offset 1 pixel to the down so that friction would work val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt() - for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { + for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) { tiles.add(world.getTileFromTerrain(x, y)) } @@ -1344,7 +1353,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val // offset 1 pixel to the down so that friction would work val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt() - for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) { + for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) { tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)]) } diff --git a/src/net/torvald/terrarum/gameactors/PlayableActorDelegate.kt b/src/net/torvald/terrarum/gameactors/PlayableActorDelegate.kt index 45d0ef606..9aa5ce3d2 100644 --- a/src/net/torvald/terrarum/gameactors/PlayableActorDelegate.kt +++ b/src/net/torvald/terrarum/gameactors/PlayableActorDelegate.kt @@ -17,12 +17,12 @@ class PlayableActorDelegate(val actor: ActorHumanoid) { fun update(delta: Float) { - //val oldTilewisePos = actor.tilewiseHitbox + //val oldTilewisePos = actor.hIntTilewiseHitbox actor.update(delta) // fire lightmap recalculate event upon tilewise pos change - //val newTilewisePos = actor.tilewiseHitbox + //val newTilewisePos = actor.hIntTilewiseHitbox //if (oldTilewisePos != newTilewisePos) { // LightmapRenderer.fireRecalculateEvent() //} diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 0206b772c..866235dd3 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -70,7 +70,7 @@ object ItemCodex { // check for collision with actors (BLOCK only) if (this.inventoryCategory == Category.BLOCK) { Terrarum.ingame!!.actorContainer.forEach { - if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) + if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) return false } } @@ -138,7 +138,7 @@ object ItemCodex { // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors Terrarum.ingame!!.actorContainer.forEach { - if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) + if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) return false } diff --git a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt index b0318aa03..665eb9b7b 100644 --- a/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/items/PickaxeGeneric.kt @@ -44,7 +44,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() { // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // return false if hitting actors Terrarum.ingame!!.actorContainer.forEach({ - if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) + if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint)) return false }) diff --git a/src/net/torvald/terrarum/ui/UIBasicNotifier.kt b/src/net/torvald/terrarum/ui/UIBasicNotifier.kt index 6ff0ba552..6d772ca3c 100644 --- a/src/net/torvald/terrarum/ui/UIBasicNotifier.kt +++ b/src/net/torvald/terrarum/ui/UIBasicNotifier.kt @@ -47,7 +47,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { private val temperature: Int get() { if (player != null) { - val playerTilePos = player.tilewiseHitbox + val playerTilePos = player.hIntTilewiseHitbox val tempCelsius = -273f + (Terrarum.ingame?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f) return if (Terrarum.getConfigBoolean("useamericanunit")) { tempCelsius.times(1.8f).plus(32f).roundInt() @@ -111,7 +111,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { val lightLevel: Color if (player != null) { - val playerPos = player.tilewiseHitbox + val playerPos = player.hIntTilewiseHitbox lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: Terrarum.ingame!!.world.globalLight ) diff --git a/src/net/torvald/terrarum/ui/UITierOneWatch.kt b/src/net/torvald/terrarum/ui/UITierOneWatch.kt index adb25ce77..4e8ec115e 100644 --- a/src/net/torvald/terrarum/ui/UITierOneWatch.kt +++ b/src/net/torvald/terrarum/ui/UITierOneWatch.kt @@ -66,7 +66,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() { val lightLevel: Color if (player != null) { - val playerPos = player.tilewiseHitbox + val playerPos = player.hIntTilewiseHitbox lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?: Terrarum.ingame!!.world.globalLight ) diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index b220ff2bb..51372dba0 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -754,6 +754,7 @@ object BlocksDrawer { shader.setUniformi("atlasTexSize", tileAtlas.texture.width, tileAtlas.texture.height) //depends on the tile atlas tilesQuad.render(shader, GL20.GL_TRIANGLES) shader.end() + tilesBufferAsTex.dispose() } diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index 92042a5db..0597d2d31 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -1,6 +1,8 @@ package net.torvald.terrarum.worlddrawer +import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -8,6 +10,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex import com.jme3.math.FastMath import net.torvald.terrarum.Ingame import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.TerrarumAppLoader import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.* @@ -306,15 +309,20 @@ object LightmapRendererNew { lateinit var lightBuffer: Pixmap fun draw(batch: SpriteBatch, drawMode: Int) { + val this_x_start = for_x_start// + overscan_open val this_x_end = for_x_end// + overscan_open val this_y_start = for_y_start// + overscan_open val this_y_end = for_y_end// + overscan_open - // write to colour buffer for (y in this_y_start..this_y_end) { + //println("y: $y, this_y_start: $this_y_start") + if (y == this_y_start && this_y_start == 0) { + //throw Error("Fuck hits again...") + } + for (x in this_x_start..this_x_end) { val color = if (drawMode == DRAW_FOR_RGB) { @@ -328,21 +336,40 @@ object LightmapRendererNew { } - //lightBuffer.setColor(color) - lightBuffer.setColor(Color.ORANGE) - lightBuffer.drawPixel(x - this_x_start, y - this_y_start) + lightBuffer.setColor(color) + + //lightBuffer.drawPixel(x - this_x_start, y - this_y_start) + + lightBuffer.drawPixel(x - this_x_start, lightBuffer.height - 1 - y + this_y_start) // flip Y } } + //println() + + // FIXME FUCKS SAKE: this_y_start is sometimes fixed at zero, which fucked old light sys with black screen + // -> recalculate event not being fired + + + // so this code actually works now... + /*for (y in 0 until lightBuffer.height) { + for (x in 0 until lightBuffer.width) { + val rnd = Math.random().toFloat() + lightBuffer.setColor(Color(rnd, rnd, rnd, 1f)) + lightBuffer.drawPixel(x, y) + } + }*/ // draw to the batch val lightBufferAsTex = Texture(lightBuffer) lightBufferAsTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) - // we might not need shader here... - batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width * DRAW_TILE_SIZE, lightBufferAsTex.height * DRAW_TILE_SIZE) - lightBufferAsTex.dispose() + Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + // we might not need shader here... + batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat()) + //batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width * DRAW_TILE_SIZE, lightBufferAsTex.height * TILE_SIZE.toFloat()) + + //lightBufferAsTex.dispose() @@ -537,7 +564,7 @@ object LightmapRendererNew { fun resize(width: Int, height: Int) { // make sure the BlocksDrawer is resized first! - lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGB888) + lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGBA8888) }