lightmap draw shift fixed; game will properly resize

This commit is contained in:
minjaesong
2017-10-16 22:47:16 +09:00
parent a66fcd2328
commit 06db25fb1a
7 changed files with 60 additions and 38 deletions

View File

@@ -1459,6 +1459,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
}
println("[Ingame] Resize event")
}
override fun dispose() {

View File

@@ -247,6 +247,7 @@ object Terrarum : Screen {
/** Actually just a mesh of four vertices, two triangles -- not a literal glQuad */
lateinit var fullscreenQuad: Mesh; private set
private var fullscreenQuadInit = false
val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime
@@ -321,6 +322,27 @@ object Terrarum : Screen {
}
val MINIMAL_GL_MAX_TEXTURE_SIZE = 4096
private fun initFullscreenQuad() {
if (!fullscreenQuadInit) {
fullscreenQuad = Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
fullscreenQuadInit = true
}
}
private fun updateFullscreenQuad(WIDTH: Int, HEIGHT: Int) {
initFullscreenQuad()
fullscreenQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
WIDTH.toFloat(), HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
}
override fun show() {
if (environment != RunningEnvironment.MOBILE) {
@@ -340,23 +362,7 @@ object Terrarum : Screen {
}
fullscreenQuad = Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
fullscreenQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
WIDTH.toFloat(), HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
updateFullscreenQuad(WIDTH, HEIGHT)
@@ -501,19 +507,12 @@ object Terrarum : Screen {
// re-calculate fullscreen quad
fullscreenQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
Terrarum.WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
updateFullscreenQuad(screenW, screenH)
//appLoader.resize(width, height)
//Gdx.graphics.setWindowedMode(width, height)
println("newsize: ${Gdx.graphics.width}x${Gdx.graphics.height}")
println("[Terrarum] newsize: ${Gdx.graphics.width}x${Gdx.graphics.height} | internal: ${width}x$height")
}
@@ -550,8 +549,9 @@ object Terrarum : Screen {
defaultSaveDir = defaultDir + "/Saves"
configDir = defaultDir + "/config.json"
println("[Terrarum] os.name = $OSName")
println("[Terrarum] os.name = $OSName (with identifier $OperationSystem)")
println("[Terrarum] os.version = $OSVersion")
println("[Terrarum] default directory: $defaultDir")
}
private fun createDirs() {

View File

@@ -178,7 +178,10 @@ public class TerrarumAppLoader implements ApplicationListener {
public void resize(int width, int height) {
//initViewPort(width, height);
Terrarum.INSTANCE.resize(width, height);
if (screen != null) screen.resize(width, height);
System.out.println("[AppLoader] Resize event");
}
@Override

View File

@@ -19,26 +19,34 @@ object JsonFetcher {
@Throws(java.io.IOException::class)
operator fun invoke(jsonFilePath: String): com.google.gson.JsonObject {
net.torvald.terrarum.utils.JsonFetcher.jsonString = StringBuffer() // reset buffer every time it called
net.torvald.terrarum.utils.JsonFetcher.readJsonFileAsString(jsonFilePath)
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFilePath)
println("[JsonFetcher] Reading JSON $jsonFilePath")
if (jsonString == null) {
throw Error("[JsonFetcher] jsonString is null!")
}
val jsonParser = com.google.gson.JsonParser()
val jsonObj = jsonParser.parse(net.torvald.terrarum.utils.JsonFetcher.jsonString!!.toString()).asJsonObject
val jsonObj = jsonParser.parse(jsonString.toString()).asJsonObject
return jsonObj
}
@Throws(java.io.IOException::class)
operator fun invoke(jsonFile: java.io.File): com.google.gson.JsonObject {
net.torvald.terrarum.utils.JsonFetcher.jsonString = StringBuffer() // reset buffer every time it called
net.torvald.terrarum.utils.JsonFetcher.readJsonFileAsString(jsonFile.canonicalPath)
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFile.canonicalPath)
println("[JsonFetcher] Reading JSON ${jsonFile.path}")
if (jsonString == null) {
throw Error("[JsonFetcher] jsonString is null!")
}
val jsonParser = com.google.gson.JsonParser()
val jsonObj = jsonParser.parse(net.torvald.terrarum.utils.JsonFetcher.jsonString!!.toString()).asJsonObject
val jsonObj = jsonParser.parse(jsonString.toString()).asJsonObject
return jsonObj
}
@@ -46,7 +54,7 @@ object JsonFetcher {
private fun readJsonFileAsString(path: String) {
try {
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
{ net.torvald.terrarum.utils.JsonFetcher.jsonString!!.append(it) }
{ jsonString!!.append(it) }
) // JSON does not require line break
}
catch (e: IOException) {

View File

@@ -802,6 +802,10 @@ object BlocksDrawer {
oldScreenW = screenW
oldScreenH = screenH
println("[BlocksDrawerNew] Resize event")
}
fun clampH(x: Int): Int {

View File

@@ -118,8 +118,8 @@ object LightmapRenderer {
}
fun fireRecalculateEvent() {
for_x_start = WorldCamera.x / TILE_SIZE - 1 // fix for premature lightmap rendering
for_y_start = WorldCamera.y / TILE_SIZE - 1 // on topmost/leftmost side
for_x_start = WorldCamera.x / TILE_SIZE // fix for premature lightmap rendering
for_y_start = WorldCamera.y / TILE_SIZE // on topmost/leftmost side
for_x_end = for_x_start + WorldCamera.width / TILE_SIZE + 3
for_y_end = for_y_start + WorldCamera.height / TILE_SIZE + 2 // same fix as above
@@ -565,6 +565,10 @@ object LightmapRenderer {
// make sure the BlocksDrawer is resized first!
lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGBA8888)
println("[LightmapRendererNew] Resize event")
}