Guess it's fully working for titlescreen

This commit is contained in:
minjaesong
2017-09-13 18:10:03 +09:00
parent a048381cce
commit efe2e44957
2 changed files with 78 additions and 120 deletions

View File

@@ -29,7 +29,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
private val processBlurBatch = SpriteBatch()
// invert Y
fun initViewPort(width: Int, height: Int) {
@@ -197,7 +196,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
}
// render? just do it anyway
//LightmapRendererNew.fireRecalculateEvent()
renderScreen()
}
}
@@ -209,9 +207,10 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
)
demoWorld.globalLight = WeatherMixer.globalLightNow
//demoWorld.updateWorldTime(delta)
demoWorld.updateWorldTime(delta)
WeatherMixer.update(delta, cameraPlayer)
cameraPlayer.update(delta)
// worldcamera update AFTER cameraplayer in this case; the other way is just an exception for actual ingame SFX
WorldCamera.update(demoWorld, cameraPlayer)
@@ -233,10 +232,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
Gdx.gl.glClearColor(.64f, .754f, .84f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
//BlocksDrawer.renderWall(batch)
//BlocksDrawer.renderTerrain(batch)
//BlocksDrawer.renderFront(batch, false)
batch.inUse {
setCameraPosition(0f, 0f)
@@ -250,26 +245,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
renderMenus()
renderOverlayTexts()
}
/*batch.inUse {
setCameraPosition(0f, 0f)
batch.color = Color.WHITE
batch.shader = null
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
batch.color = Color.WHITE
blendNormal()
renderDemoWorld()
renderMenus()
renderOverlayTexts()
}*/
}
private fun renderDemoWorld() {
@@ -298,19 +273,18 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
setCameraPosition(0f, 0f)
//batch.shader = Terrarum.shaderBayer
//batch.shader.setUniformf("rcount", 64f)
//batch.shader.setUniformf("gcount", 64f)
//batch.shader.setUniformf("bcount", 64f) // de-banding
batch.shader = null
batch.shader = Terrarum.shaderBayer
batch.shader.setUniformf("rcount", 64f)
batch.shader.setUniformf("gcount", 64f)
batch.shader.setUniformf("bcount", 64f) // de-banding
//processBlur(LightmapRendererNew.DRAW_FOR_RGB)
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
blendMul()
//blendNormal()
batch.color = Color.WHITE
val xrem = -(WorldCamera.x % TILE_SIZEF)
@@ -337,11 +311,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
// FIXME failed test tells that something is interfering with SpriteBatch, which makes every draw call within
// the spritebatch all go black
}
private fun renderMenus() {

View File

@@ -17,19 +17,19 @@ import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIHandler
import net.torvald.terrarum.ui.UITitleRemoConRoot
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarum.worlddrawer.*
import java.io.FileInputStream
/**
* Created by minjaesong on 2017-09-02.
*/
class TitleScreen(val batch: SpriteBatch) : Screen {
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
// invert Y
fun initViewPort(width: Int, height: Int) {
// Set Y to point downwards
@@ -101,8 +101,9 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
private val lightFBOformat = Pixmap.Format.RGB888
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false)
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false)
lateinit var lightmapFboA: FrameBuffer
lateinit var lightmapFboB: FrameBuffer
private var lightmapInitialised = false // to avoid nullability of lightmapFBO
lateinit var logo: TextureRegion
@@ -111,6 +112,9 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private lateinit var worldFBO: FrameBuffer
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = TILE_SIZE.toFloat()
private fun loadThingsWhileIntroIsVisible() {
demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld")))
@@ -141,7 +145,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
demoWorld.time.timeDelta = 150
LightmapRenderer.world = demoWorld
LightmapRendererNew.world = demoWorld
BlocksDrawer.world = demoWorld
FeaturesDrawer.world = demoWorld
@@ -173,8 +177,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, Terrarum.WIDTH, Terrarum.HEIGHT, false)
}
private var blurWriteBuffer = lightmapFboA
private var blurReadBuffer = lightmapFboB
private val introUncoverTime: Second = 0.3f
private var introUncoverDeltaCounter = 0f
@@ -195,7 +197,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
// render? just do it anyway
renderScreen()
}
}
@@ -206,9 +207,10 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
)
demoWorld.globalLight = WeatherMixer.globalLightNow
//demoWorld.updateWorldTime(delta)
demoWorld.updateWorldTime(delta)
WeatherMixer.update(delta, cameraPlayer)
cameraPlayer.update(delta)
// worldcamera update AFTER cameraplayer in this case; the other way is just an exception for actual ingame SFX
WorldCamera.update(demoWorld, cameraPlayer)
@@ -217,25 +219,19 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
uiContainer.forEach { it.update(delta) }
if (TerrarumAppLoader.GLOBAL_RENDER_TIMER % 2 == 1) {
LightmapRenderer.fireRecalculateEvent()
}
LightmapRendererNew.fireRecalculateEvent() // don't half-frame update; it will jitter!
}
fun renderScreen() {
// render and blur lightmap
processBlur(LightmapRenderer.DRAW_FOR_RGB)
processBlur(LightmapRendererNew.DRAW_FOR_RGB)
//camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
// render world
Gdx.gl.glClearColor(.64f, .754f, .84f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
//BlocksDrawer.renderWall(batch)
//BlocksDrawer.renderTerrain(batch)
//BlocksDrawer.renderFront(batch, false)
batch.inUse {
setCameraPosition(0f, 0f)
@@ -247,28 +243,8 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
batch.shader = null
batch.color = Color.WHITE
renderMenus()
//renderOverlayTexts()
}
/*batch.inUse {
setCameraPosition(0f, 0f)
batch.color = Color.WHITE
batch.shader = null
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
batch.color = Color.WHITE
blendNormal()
renderDemoWorld()
renderMenus()
renderOverlayTexts()
}*/
}
}
private fun renderDemoWorld() {
@@ -281,32 +257,52 @@ class TitleScreen(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)
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
blendMul()
//blendNormal()
batch.color = Color.WHITE
val xrem = -(WorldCamera.x % TILE_SIZEF)
val yrem = -(WorldCamera.y % TILE_SIZEF)
batch.draw(lightTex,
0f, 0f,
xrem,
yrem,
lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample
//lightTex.width.toFloat(), lightTex.height.toFloat() // for debugging
)
//////////////////////
// Draw other shits //
//////////////////////
batch.shader = null
@@ -358,6 +354,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT)
BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
LightmapRendererNew.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
if (loadDone) {
// resize UI by re-creating it (!!)
@@ -365,11 +362,23 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
}
lightmapFboA.dispose()
lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false)
lightmapFboB.dispose()
lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false)
if (lightmapInitialised) {
lightmapFboA.dispose()
lightmapFboB.dispose()
}
lightmapFboA = FrameBuffer(
lightFBOformat,
LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
false
)
lightmapFboB = FrameBuffer(
lightFBOformat,
LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
false
)
lightmapInitialised = true // are you the first time?
}
override fun dispose() {
@@ -391,8 +400,8 @@ class TitleScreen(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 / Ingame.lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics
blurWriteBuffer = lightmapFboA
blurReadBuffer = lightmapFboB
var blurWriteBuffer = lightmapFboA
var blurReadBuffer = lightmapFboB
lightmapFboA.inAction(null, null) {
@@ -405,23 +414,13 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
if (mode == LightmapRenderer.DRAW_FOR_RGB) {
if (mode == LightmapRendererNew.DRAW_FOR_RGB) {
// 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 / Ingame.lightmapDownsample).round(),
(WorldCamera.gdxCamY / Ingame.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)
LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB)
}
}
}
@@ -429,19 +428,9 @@ class TitleScreen(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 / Ingame.lightmapDownsample).round(),
(WorldCamera.gdxCamY / Ingame.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)
LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_ALPHA)
}
}
}
@@ -482,7 +471,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
class TitleScreenController(val screen: TitleScreen) : InputAdapter() {
class TitleScreenController(val screen: FuckingWorldRenderer) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
return true