mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
lightmap draw shift fixed; game will properly resize
This commit is contained in:
@@ -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() {
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user