lightmap draw shift fixed; game will properly resize

This commit is contained in:
minjaesong
2017-10-16 22:47:16 +09:00
parent 83b9f74100
commit 6df79b96dd
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) uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2) uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
} }
println("[Ingame] Resize event")
} }
override fun dispose() { 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 */ /** Actually just a mesh of four vertices, two triangles -- not a literal glQuad */
lateinit var fullscreenQuad: Mesh; private set lateinit var fullscreenQuad: Mesh; private set
private var fullscreenQuadInit = false
val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime
@@ -321,6 +322,27 @@ object Terrarum : Screen {
} }
val MINIMAL_GL_MAX_TEXTURE_SIZE = 4096 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() { override fun show() {
if (environment != RunningEnvironment.MOBILE) { if (environment != RunningEnvironment.MOBILE) {
@@ -340,23 +362,7 @@ object Terrarum : Screen {
} }
updateFullscreenQuad(WIDTH, HEIGHT)
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))
@@ -501,19 +507,12 @@ object Terrarum : Screen {
// re-calculate fullscreen quad // re-calculate fullscreen quad
fullscreenQuad.setVertices(floatArrayOf( updateFullscreenQuad(screenW, screenH)
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))
//appLoader.resize(width, height) //appLoader.resize(width, height)
//Gdx.graphics.setWindowedMode(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" defaultSaveDir = defaultDir + "/Saves"
configDir = defaultDir + "/config.json" configDir = defaultDir + "/config.json"
println("[Terrarum] os.name = $OSName") println("[Terrarum] os.name = $OSName (with identifier $OperationSystem)")
println("[Terrarum] os.version = $OSVersion") println("[Terrarum] os.version = $OSVersion")
println("[Terrarum] default directory: $defaultDir")
} }
private fun createDirs() { private fun createDirs() {

View File

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

View File

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

View File

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

View File

@@ -118,8 +118,8 @@ object LightmapRenderer {
} }
fun fireRecalculateEvent() { fun fireRecalculateEvent() {
for_x_start = WorldCamera.x / TILE_SIZE - 1 // fix for premature lightmap rendering for_x_start = WorldCamera.x / TILE_SIZE // fix for premature lightmap rendering
for_y_start = WorldCamera.y / TILE_SIZE - 1 // on topmost/leftmost side for_y_start = WorldCamera.y / TILE_SIZE // on topmost/leftmost side
for_x_end = for_x_start + WorldCamera.width / TILE_SIZE + 3 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 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! // make sure the BlocksDrawer is resized first!
lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGBA8888) lightBuffer = Pixmap(BlocksDrawer.tilesInHorizontal, BlocksDrawer.tilesInVertical, Pixmap.Format.RGBA8888)
println("[LightmapRendererNew] Resize event")
} }