Light fuck: At least I've figured out what the fuck was wrong with.

This commit is contained in:
minjaesong
2017-09-12 21:29:45 +09:00
parent 636b0ffe4f
commit 59270f2c40
15 changed files with 99 additions and 54 deletions

Binary file not shown.

View File

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

View File

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

View File

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

View File

@@ -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() {

View File

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

View File

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

View File

@@ -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<Int?>()
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<BlockProp?>()
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)])
}

View File

@@ -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()
//}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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