title screen using IngameRenderer

This commit is contained in:
minjaesong
2018-07-01 01:38:07 +09:00
parent cf04b7d22a
commit 1250bb49c4
5 changed files with 1395 additions and 590 deletions

View File

@@ -78,7 +78,7 @@ public class AppLoader implements ApplicationListener {
*
* e.g. 0x02010034 can be translated as 2.1.52
*/
public static final int VERSION_RAW = 0x00_02_0226;
public static final int VERSION_RAW = 0x00_02_0270;
public static final String getVERSION_STRING() {
return String.format("%d.%d.%d", VERSION_RAW >>> 24, (VERSION_RAW & 0xff0000) >>> 16, VERSION_RAW & 0xFFFF);
}

File diff suppressed because it is too large Load Diff

View File

@@ -105,10 +105,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private val gradWhiteTop = Color(0xf8f8f8ff.toInt())
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
private val lightFBOformat = Pixmap.Format.RGBA8888
lateinit var lightmapFboA: FrameBuffer
lateinit var lightmapFboB: FrameBuffer
private var lightmapInitialised = false // to avoid nullability of lightmapFBO
lateinit var logo: TextureRegion
@@ -241,7 +237,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
fun renderScreen() {
processBlur(LightmapRenderer.DRAW_FOR_RGB)
//camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
// render world
@@ -249,99 +244,17 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
IngameRenderer.invoke(world = demoWorld, uisToDraw = uiContainer)
batch.inUse {
setCameraPosition(0f, 0f)
batch.shader = null
Gdx.gl.glEnable(GL20.GL_BLEND)
renderDemoWorld()
batch.shader = null
batch.color = Color.WHITE
renderMenus()
renderOverlayTexts()
}
}
private fun renderDemoWorld() {
//println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}")
//println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}")
//println()
// draw skybox //
setCameraPosition(0f, 0f)
batch.color = Color.WHITE
blendNormal()
WeatherMixer.render(camera, demoWorld)
// draw tiles //
BlocksDrawer.renderWall(batch.projectionMatrix)
BlocksDrawer.renderTerrain(batch.projectionMatrix)
BlocksDrawer.renderFront(batch.projectionMatrix, false)
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 = 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.toFloat() fmod TILE_SIZEF)
val yrem = -(WorldCamera.y.toFloat() fmod TILE_SIZEF)
batch.draw(lightTex,
xrem,
yrem,
lightTex.width * IngameRenderer.lightmapDownsample, lightTex.height * IngameRenderer.lightmapDownsample
//lightTex.width.toFloat(), lightTex.height.toFloat() // for debugging
)
//////////////////////
// Draw other shits //
//////////////////////
batch.shader = null
// move camera back to its former position
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
}
private fun renderMenus() {
setCameraPosition(0f, 0f)
blendNormal()
batch.shader = null
uiContainer.forEach { it.render(batch, camera) }
}
private fun renderOverlayTexts() {
setCameraPosition(0f, 0f)
blendNormal()
@@ -385,29 +298,13 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
// 2: The UI is coded shit
}
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?
IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
}
override fun dispose() {
logo.texture.dispose()
lightmapFboA.dispose()
lightmapFboB.dispose()
IngameRenderer.dispose()
uiMenu.dispose()
}
@@ -419,84 +316,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
fun processBlur(mode: Int) {
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
val blurRadius = 4f / IngameRenderer.lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics
var blurWriteBuffer = lightmapFboA
var blurReadBuffer = lightmapFboB
lightmapFboA.inAction(null, null) {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
Gdx.gl.glDisable(GL20.GL_BLEND)
}
lightmapFboB.inAction(null, null) {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
Gdx.gl.glDisable(GL20.GL_BLEND)
}
if (mode == LightmapRenderer.DRAW_FOR_RGB) {
// initialise readBuffer with untreated lightmap
blurReadBuffer.inAction(camera, batch) {
batch.inUse {
//blendNormal(batch)
blendDisable(batch)
batch.color = Color.WHITE
LightmapRenderer.draw(batch)
}
}
}
else {
// initialise readBuffer with untreated lightmap
blurReadBuffer.inAction(camera, batch) {
batch.inUse {
//blendNormal(batch)
blendDisable(batch)
batch.color = Color.WHITE
LightmapRenderer.draw(batch)
}
}
}
for (i in 0 until blurIterations) {
blurWriteBuffer.inAction(camera, batch) {
batch.inUse {
val texture = blurReadBuffer.colorBufferTexture
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
batch.shader = Terrarum.shaderBlur
batch.shader.setUniformf("iResolution",
blurWriteBuffer.width.toFloat(), blurWriteBuffer.height.toFloat())
batch.shader.setUniformf("flip", 1f)
if (i % 2 == 0)
batch.shader.setUniformf("direction", blurRadius, 0f)
else
batch.shader.setUniformf("direction", 0f, blurRadius)
batch.color = Color.WHITE
batch.draw(texture, 0f, 0f)
// swap
val t = blurWriteBuffer
blurWriteBuffer = blurReadBuffer
blurReadBuffer = t
}
}
}
}
class TitleScreenController(val screen: TitleScreen) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {

View File

@@ -584,6 +584,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun renderGame() {
IngameRenderer.invoke(
world,
actorsRenderBehind,
actorsRenderMiddle,
actorsRenderMidTop,

View File

@@ -9,6 +9,7 @@ import net.torvald.dataclass.CircularArray
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameactors.ParticleBase
@@ -49,8 +50,7 @@ object IngameRenderer {
private var initDone = false
private val world = (Terrarum.ingame as Ingame).world
private lateinit var player: ActorHumanoid
private var player: ActorHumanoid? = null
var uiListToDraw = ArrayList<UICanvas>()
@@ -59,12 +59,13 @@ object IngameRenderer {
private var debugMode = 0
operator fun invoke(
actorsRenderBehind: List<ActorWithBody>,
actorsRenderMiddle: List<ActorWithBody>,
actorsRenderMidTop: List<ActorWithBody>,
actorsRenderFront : List<ActorWithBody>,
particlesContainer: CircularArray<ParticleBase>,
player: ActorHumanoid,
world: GameWorld,
actorsRenderBehind: List<ActorWithBody>? = null,
actorsRenderMiddle: List<ActorWithBody>? = null,
actorsRenderMidTop: List<ActorWithBody>? = null,
actorsRenderFront : List<ActorWithBody>? = null,
particlesContainer: CircularArray<ParticleBase>? = null,
player: ActorHumanoid? = null,
uisToDraw: ArrayList<UICanvas>? = null
) {
@@ -72,7 +73,7 @@ object IngameRenderer {
uiListToDraw = uisToDraw
}
init()
init(world)
this.player = player
@@ -214,11 +215,11 @@ object IngameRenderer {
}
private fun drawToRGB(
actorsRenderBehind: List<ActorWithBody>,
actorsRenderMiddle: List<ActorWithBody>,
actorsRenderMidTop: List<ActorWithBody>,
actorsRenderFront : List<ActorWithBody>,
particlesContainer: CircularArray<ParticleBase>
actorsRenderBehind: List<ActorWithBody>?,
actorsRenderMiddle: List<ActorWithBody>?,
actorsRenderMidTop: List<ActorWithBody>?,
actorsRenderFront : List<ActorWithBody>?,
particlesContainer: CircularArray<ParticleBase>?
) {
fboRGB.inAction(null, null) { clearBuffer() }
fboRGB_lightMixed.inAction(null, null) { clearBuffer() }
@@ -235,8 +236,8 @@ object IngameRenderer {
batch.inUse {
moveCameraToWorldCoord()
actorsRenderBehind.forEach { it.drawBody(batch) }
particlesContainer.forEach { it.drawBody(batch) }
actorsRenderBehind?.forEach { it.drawBody(batch) }
particlesContainer?.forEach { it.drawBody(batch) }
}
setCameraPosition(0f, 0f)
@@ -247,10 +248,10 @@ object IngameRenderer {
// draw actors //
/////////////////
moveCameraToWorldCoord()
actorsRenderMiddle.forEach { it.drawBody(batch) }
actorsRenderMidTop.forEach { it.drawBody(batch) }
player.drawBody(batch)
actorsRenderFront.forEach { it.drawBody(batch) }
actorsRenderMiddle?.forEach { it.drawBody(batch) }
actorsRenderMidTop?.forEach { it.drawBody(batch) }
player?.drawBody(batch)
actorsRenderFront?.forEach { it.drawBody(batch) }
// --> Change of blend mode <-- introduced by children of ActorWithBody //
}
@@ -299,11 +300,11 @@ object IngameRenderer {
}
private fun drawToA(
actorsRenderBehind: List<ActorWithBody>,
actorsRenderMiddle: List<ActorWithBody>,
actorsRenderMidTop: List<ActorWithBody>,
actorsRenderFront : List<ActorWithBody>,
particlesContainer: CircularArray<ParticleBase>
actorsRenderBehind: List<ActorWithBody>?,
actorsRenderMiddle: List<ActorWithBody>?,
actorsRenderMidTop: List<ActorWithBody>?,
actorsRenderFront : List<ActorWithBody>?,
particlesContainer: CircularArray<ParticleBase>?
) {
fboA.inAction(null, null) {
clearBuffer()
@@ -325,8 +326,8 @@ object IngameRenderer {
batch.inUse {
moveCameraToWorldCoord()
actorsRenderBehind.forEach { it.drawGlow(batch) }
particlesContainer.forEach { it.drawGlow(batch) }
actorsRenderBehind?.forEach { it.drawGlow(batch) }
particlesContainer?.forEach { it.drawGlow(batch) }
}
setCameraPosition(0f, 0f)
@@ -337,10 +338,10 @@ object IngameRenderer {
// draw actors //
/////////////////
moveCameraToWorldCoord()
actorsRenderMiddle.forEach { it.drawGlow(batch) }
actorsRenderMidTop.forEach { it.drawGlow(batch) }
player.drawGlow(batch)
actorsRenderFront.forEach { it.drawGlow(batch) }
actorsRenderMiddle?.forEach { it.drawGlow(batch) }
actorsRenderMidTop?.forEach { it.drawGlow(batch) }
player?.drawGlow(batch)
actorsRenderFront?.forEach { it.drawGlow(batch) }
// --> Change of blend mode <-- introduced by children of ActorWithBody //
}
}
@@ -382,7 +383,7 @@ object IngameRenderer {
}
private fun init() {
private fun init(world: GameWorld) {
if (!initDone) {
batch = SpriteBatch()
camera = OrthographicCamera(widthf, heightf)