mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
downsampling sorta works, ONLY WHEN (width or height % 4) is 0 or 1
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
screenshot_01.png
Normal file
BIN
screenshot_01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 376 KiB |
@@ -56,7 +56,7 @@ object DefaultConfig {
|
||||
jsonObject.addProperty("keyclose", Input.Keys.C)
|
||||
|
||||
jsonObject.addProperty("keygamemenu", Input.Keys.TAB)
|
||||
jsonObject.addProperty("keyquicksel", Input.Keys.SHIFT_LEFT) // pie menu (A) because GDX does not read CapsLock
|
||||
jsonObject.addProperty("keyquicksel", Input.Keys.SHIFT_LEFT) // pie menu is now LShift because GDX does not read CapsLock
|
||||
val keyquickselalt = JsonArray(); keyquickselalt.add(Input.Keys.BACKSPACE); keyquickselalt.add(Input.Keys.CONTROL_LEFT); keyquickselalt.add(Input.Keys.BACKSLASH)
|
||||
// Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command
|
||||
// so these keys are treated as the same.
|
||||
@@ -65,7 +65,7 @@ object DefaultConfig {
|
||||
|
||||
jsonObject.addProperty("keyjump", Input.Keys.SPACE)
|
||||
|
||||
val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0
|
||||
val keyquickbars = JsonArray(); for (i in Input.Keys.NUMPAD_1..Input.Keys.NUMPAD_9) keyquickbars.add(i); keyquickbars.add(Input.Keys.NUMPAD_0) // NUM_1 to NUM_0
|
||||
jsonObject.add("keyquickbars", keyquickbars)
|
||||
|
||||
jsonObject.addProperty("mouseprimary", Input.Buttons.LEFT) // left mouse
|
||||
|
||||
@@ -73,12 +73,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
val ZOOM_MINIMUM = 0.5f
|
||||
|
||||
companion object {
|
||||
val lightmapDownsample = 1f // have no fucking idea why downsampling wrecks camera and render
|
||||
val lightmapDownsample = 1f
|
||||
}
|
||||
|
||||
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
|
||||
var lightmapFboA = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(lightmapDownsample).ceilInt(), Gdx.graphics.height.div(lightmapDownsample).ceilInt(), false)
|
||||
var lightmapFboB = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(lightmapDownsample).ceilInt(), Gdx.graphics.height.div(lightmapDownsample).ceilInt(), false)
|
||||
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT, true)
|
||||
var lightmapFboA = FrameBuffer(Pixmap.Format.RGBA8888, TerrarumGDX.WIDTH.div(lightmapDownsample.toInt()), TerrarumGDX.HEIGHT.div(lightmapDownsample.toInt()), true)
|
||||
var lightmapFboB = FrameBuffer(Pixmap.Format.RGBA8888, TerrarumGDX.WIDTH.div(lightmapDownsample.toInt()), TerrarumGDX.HEIGHT.div(lightmapDownsample.toInt()), true)
|
||||
|
||||
|
||||
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
|
||||
@@ -129,10 +129,13 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
// GDX code //
|
||||
//////////////
|
||||
|
||||
var camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
var camera = OrthographicCamera(TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT.toFloat())
|
||||
|
||||
// invert Y
|
||||
fun initViewPort(width: Int, height: Int) {
|
||||
//val width = if (width % 1 == 1) width + 1 else width
|
||||
//val height = if (height % 1 == 1) height + 1 else width
|
||||
|
||||
// Set Y to point downwards
|
||||
camera.setToOrtho(true, width.toFloat(), height.toFloat())
|
||||
|
||||
@@ -146,7 +149,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
override fun show() {
|
||||
// Set up viewport on first load
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height)
|
||||
initViewPort(TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT)
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +158,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
Gdx.input.inputProcessor = GameController
|
||||
|
||||
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height)
|
||||
initViewPort(TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT)
|
||||
|
||||
|
||||
// load things when the game entered this "state"
|
||||
@@ -200,7 +203,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
notifier = UIHandler(Notification())
|
||||
notifier.UI.handler = notifier
|
||||
notifier.setPosition(
|
||||
(Gdx.graphics.width - notifier.UI.width) / 2, Gdx.graphics.height - notifier.UI.height)
|
||||
(TerrarumGDX.WIDTH - notifier.UI.width) / 2, TerrarumGDX.HEIGHT - notifier.UI.height)
|
||||
|
||||
|
||||
|
||||
@@ -210,7 +213,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
uiInventoryPlayer = UIHandler(
|
||||
UIInventory(player,
|
||||
width = 840,
|
||||
height = Gdx.graphics.height - 160,
|
||||
height = TerrarumGDX.HEIGHT - 160,
|
||||
categoryWidth = 210
|
||||
),
|
||||
toggleKey = TerrarumGDX.getConfigInt("keyinventory")
|
||||
@@ -243,11 +246,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
// basic watch-style notification bar (temperature, new mail)
|
||||
uiWatchBasic = UIHandler(UIBasicNotifier(player))
|
||||
uiWatchBasic.setAsAlwaysVisible()
|
||||
uiWatchBasic.setPosition(Gdx.graphics.width - uiWatchBasic.UI.width, 0)
|
||||
uiWatchBasic.setPosition(TerrarumGDX.WIDTH - uiWatchBasic.UI.width, 0)
|
||||
|
||||
uiWatchTierOne = UIHandler(UITierOneWatch(player))
|
||||
uiWatchTierOne.setAsAlwaysVisible()
|
||||
uiWatchTierOne.setPosition(Gdx.graphics.width - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2)
|
||||
uiWatchTierOne.setPosition(TerrarumGDX.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2)
|
||||
|
||||
|
||||
// batch-process uiAliases
|
||||
@@ -388,8 +391,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
///////////////////
|
||||
// blur lightmap //
|
||||
///////////////////
|
||||
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
||||
val blurRadius = 4f // (5, 4f); using low numbers for pixel-y aesthetics
|
||||
val blurIterations = 3 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
||||
val blurRadius = 4f / lightmapDownsample // (3, 4f); using low numbers for pixel-y aesthetics
|
||||
|
||||
|
||||
|
||||
@@ -403,6 +406,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
}
|
||||
|
||||
worldDrawFrameBuffer.inAction(null, null) {
|
||||
Gdx.gl.glClearColor(0f,0f,0f,0f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
}
|
||||
|
||||
|
||||
|
||||
var blurWriteBuffer = lightmapFboA
|
||||
@@ -415,7 +423,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
blurReadBuffer.inAction(camera, batch) {
|
||||
batch.inUse {
|
||||
// using custom code for camera; this is obscure and tricky
|
||||
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
|
||||
camera.position.set((WorldCamera.gdxCamX / lightmapDownsample).round(), (WorldCamera.gdxCamY / lightmapDownsample).round(), 0f) // make camara work
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
@@ -426,7 +434,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
}
|
||||
|
||||
if (TerrarumGDX.getConfigBoolean("smoothlighting")) {
|
||||
if (!KeyToggler.isOn(Input.Keys.F8)) {
|
||||
for (i in 0..blurIterations - 1) {
|
||||
blurWriteBuffer.inAction(camera, batch) {
|
||||
|
||||
@@ -468,13 +476,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
///////////////////////////
|
||||
|
||||
worldDrawFrameBuffer.inAction(camera, batch) {
|
||||
Gdx.gl.glClearColor(0f,0f,0f,0f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
|
||||
batch.inUse {
|
||||
batch.shader = null
|
||||
|
||||
|
||||
// using custom code for camera; this is obscure and tricky
|
||||
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
|
||||
camera.update()
|
||||
@@ -515,6 +521,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
setCameraPosition(0f, 0f)
|
||||
|
||||
val lightTex = blurWriteBuffer.colorBufferTexture // TODO zoom!
|
||||
lightTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
if (KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendNormal()
|
||||
else blendMul()
|
||||
batch.color = Color.WHITE
|
||||
@@ -547,7 +554,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
/////////////////////////
|
||||
// draw to main screen //
|
||||
/////////////////////////
|
||||
camera.setToOrtho(true, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
camera.setToOrtho(true, TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT.toFloat())
|
||||
batch.projectionMatrix = camera.combined
|
||||
batch.inUse {
|
||||
batch.shader = null
|
||||
@@ -565,6 +572,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
batch.color = Color.WHITE
|
||||
val worldTex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom!
|
||||
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
batch.draw(worldTex, 0f, 0f, worldTex.width.toFloat(), worldTex.height.toFloat())
|
||||
|
||||
|
||||
@@ -805,8 +813,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
// centre marker
|
||||
/*gwin.color = Color(0x00FFFF)
|
||||
gwin.lineWidth = 1f
|
||||
gwin.drawLine(Gdx.graphics.width / 2f, 0f, Gdx.graphics.width / 2f, Gdx.graphics.height.toFloat())
|
||||
gwin.drawLine(0f, Gdx.graphics.height / 2f, Gdx.graphics.width.toFloat(), Gdx.graphics.height / 2f)*/
|
||||
gwin.drawLine(TerrarumGDX.WIDTH / 2f, 0f, TerrarumGDX.WIDTH / 2f, TerrarumGDX.HEIGHT.toFloat())
|
||||
gwin.drawLine(0f, TerrarumGDX.HEIGHT / 2f, TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT / 2f)*/
|
||||
}
|
||||
|
||||
|
||||
@@ -967,8 +975,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
/** whether the actor is within screen */
|
||||
private fun ActorWithBody.inScreen() =
|
||||
distToCameraSqr(this) <=
|
||||
(Gdx.graphics.width.plus(this.hitbox.width.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr() +
|
||||
Gdx.graphics.height.plus(this.hitbox.height.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr())
|
||||
(TerrarumGDX.WIDTH.plus(this.hitbox.width.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr() +
|
||||
TerrarumGDX.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr())
|
||||
|
||||
|
||||
/** whether the actor is within update range */
|
||||
@@ -1195,11 +1203,11 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
worldDrawFrameBuffer.dispose()
|
||||
worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, width, height, false)
|
||||
worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, width, height, true)
|
||||
lightmapFboA.dispose()
|
||||
lightmapFboA = FrameBuffer(Pixmap.Format.RGBA8888, width.div(lightmapDownsample).ceilInt(), height.div(lightmapDownsample).ceilInt(), false)
|
||||
lightmapFboA = FrameBuffer(Pixmap.Format.RGBA8888, width.div(lightmapDownsample.toInt()), height.div(lightmapDownsample.toInt()), true)
|
||||
lightmapFboB.dispose()
|
||||
lightmapFboB = FrameBuffer(Pixmap.Format.RGBA8888, width.div(lightmapDownsample).ceilInt(), height.div(lightmapDownsample).ceilInt(), false)
|
||||
lightmapFboB = FrameBuffer(Pixmap.Format.RGBA8888, width.div(lightmapDownsample.toInt()), height.div(lightmapDownsample.toInt()), true)
|
||||
|
||||
|
||||
// Set up viewport when window is resized
|
||||
@@ -1220,7 +1228,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
|
||||
*/
|
||||
fun setCameraPosition(newX: Float, newY: Float) {
|
||||
camera.position.set(-newX + TerrarumGDX.HALFW, -newY + TerrarumGDX.HALFH, 0f)
|
||||
camera.position.set((-newX + TerrarumGDX.HALFW).round(), (-newY + TerrarumGDX.HALFH).round(), 0f)
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.ActorWithPhysics.Companion.TILE_SIZE
|
||||
import net.torvald.terrarum.gameactors.floor
|
||||
import net.torvald.terrarum.gamecontroller.GameController
|
||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
@@ -82,10 +84,16 @@ object TerrarumGDX : ApplicationAdapter() {
|
||||
var VSYNC = USE_VSYNC
|
||||
val VSYNC_TRIGGER_THRESHOLD = 56
|
||||
|
||||
|
||||
inline val WIDTH: Int
|
||||
get() = Gdx.graphics.width//if (Gdx.graphics.width % 1 == 1) Gdx.graphics.width + 1 else Gdx.graphics.width
|
||||
inline val HEIGHT: Int
|
||||
get() = Gdx.graphics.height//if (Gdx.graphics.height % 1 == 1) Gdx.graphics.height + 1 else Gdx.graphics.height
|
||||
|
||||
inline val HALFW: Int
|
||||
get() = Gdx.graphics.width.ushr(1)
|
||||
get() = WIDTH.ushr(1)
|
||||
inline val HALFH: Int
|
||||
get() = Gdx.graphics.height.ushr(1)
|
||||
get() = HEIGHT.ushr(1)
|
||||
|
||||
/**
|
||||
* To be used with physics simulator
|
||||
@@ -522,13 +530,16 @@ inline fun ShapeRenderer.inUse(shapeRendererType: ShapeRenderer.ShapeType = Shap
|
||||
inline fun FrameBuffer.inAction(camera: OrthographicCamera?, batch: SpriteBatch?, action: (FrameBuffer) -> Unit) {
|
||||
this.begin()
|
||||
camera?.setToOrtho(true, this.width.toFloat(), this.height.toFloat())
|
||||
camera?.position?.set(this.width / 2f, this.height / 2f, 0f) // are these actually needed?
|
||||
camera?.update() // are these actually needed?
|
||||
camera?.position?.set((this.width / 2f).round(), (this.height / 2f).round(), 0f) // TODO floor? ceil? round?
|
||||
camera?.update()
|
||||
batch?.projectionMatrix = camera?.combined
|
||||
action(this)
|
||||
this.end()
|
||||
}
|
||||
|
||||
fun Float.round(): Float {
|
||||
return Math.round(this).toFloat()
|
||||
}
|
||||
|
||||
|
||||
// ShapeRenderer alternative for rects
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
|
||||
|
||||
fun enter() {
|
||||
// init view port
|
||||
camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
camera = OrthographicCamera(TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT.toFloat())
|
||||
|
||||
|
||||
img = Texture("assets/test_texture.tga")
|
||||
@@ -55,14 +55,14 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
|
||||
blurFboA = FrameBuffer(Pixmap.Format.RGBA8888, img.width, img.height, false)
|
||||
blurFboB = FrameBuffer(Pixmap.Format.RGBA8888, img.width, img.height, false)
|
||||
|
||||
worldFbo = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
|
||||
worldFbo = FrameBuffer(Pixmap.Format.RGBA8888, TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT, false)
|
||||
|
||||
//blurShader.begin()
|
||||
//blurShader.setUniformf("iResolution", img.width.toFloat(), img.height.toFloat(), 0f)
|
||||
//blurShader.end()
|
||||
|
||||
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height)
|
||||
initViewPort(TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT)
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
@@ -133,7 +133,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
|
||||
batch.inUse {
|
||||
batch.shader = null
|
||||
|
||||
camera.position.set(Gdx.graphics.width / 2f - 50f, Gdx.graphics.height / 2f - 50f, 0f)
|
||||
camera.position.set(TerrarumGDX.WIDTH / 2f - 50f, TerrarumGDX.HEIGHT / 2f - 50f, 0f)
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
@@ -145,11 +145,11 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
|
||||
camera.setToOrtho(true, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
camera.setToOrtho(true, TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT.toFloat())
|
||||
batch.projectionMatrix = camera.combined
|
||||
batch.inUse {
|
||||
|
||||
camera.position.set(Gdx.graphics.width / 2f, Gdx.graphics.height / 2f, 0f)
|
||||
camera.position.set(TerrarumGDX.WIDTH / 2f, TerrarumGDX.HEIGHT / 2f, 0f)
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
@@ -166,7 +166,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height)
|
||||
initViewPort(TerrarumGDX.WIDTH, TerrarumGDX.HEIGHT)
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
@@ -199,7 +199,7 @@ object TestTestMain : ApplicationAdapter() {
|
||||
// culprit #4
|
||||
blurShader.begin()
|
||||
blurShader.setUniformf("dir", 0f, 0f); //direction of blur; nil for now
|
||||
blurShader.setUniformf("resolution", maxOf(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())) //size of FBO texture
|
||||
blurShader.setUniformf("resolution", maxOf(TerrarumGDX.WIDTH.toFloat(), TerrarumGDX.HEIGHT.toFloat())) //size of FBO texture
|
||||
blurShader.setUniformf("radius", 9f) //radius of blur
|
||||
blurShader.end()
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ object BlockStats {
|
||||
val map = TerrarumGDX.ingame!!.world
|
||||
val player = TerrarumGDX.ingame!!.player
|
||||
|
||||
val renderWidth = FastMath.ceil(Gdx.graphics.width.toFloat())
|
||||
val renderHeight = FastMath.ceil(Gdx.graphics.height.toFloat())
|
||||
val renderWidth = FastMath.ceil(TerrarumGDX.WIDTH.toFloat())
|
||||
val renderHeight = FastMath.ceil(TerrarumGDX.HEIGHT.toFloat())
|
||||
|
||||
val noZoomCameraX = Math.round(FastMath.clamp(
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
|
||||
|
||||
@@ -18,8 +18,8 @@ import net.torvald.terrarum.TerrarumGDX.mouseScreenY
|
||||
*/
|
||||
class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
override var width: Int = Gdx.graphics.width
|
||||
override var height: Int = Gdx.graphics.height
|
||||
override var width: Int = TerrarumGDX.WIDTH
|
||||
override var height: Int = TerrarumGDX.HEIGHT
|
||||
|
||||
override var openCloseTime: Float = 0f
|
||||
|
||||
@@ -142,8 +142,8 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
|
||||
drawHistogram(batch, LightmapRenderer.histogram,
|
||||
Gdx.graphics.width - histogramW - 30,
|
||||
Gdx.graphics.height - histogramH - 30
|
||||
TerrarumGDX.WIDTH - histogramW - 30,
|
||||
TerrarumGDX.HEIGHT - histogramH - 30
|
||||
)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
@@ -152,7 +152,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
drawGamepadAxis(batch,
|
||||
TerrarumGDX.controller!!.getAxisValue(3),
|
||||
TerrarumGDX.controller!!.getAxisValue(2),
|
||||
Gdx.graphics.width - 135,
|
||||
TerrarumGDX.WIDTH - 135,
|
||||
40
|
||||
)
|
||||
}
|
||||
@@ -162,32 +162,32 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
*/
|
||||
|
||||
//g.color = GameFontBase.codeToCol["y"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}MEM ", (Gdx.graphics.width - 21 * 8 - 2).toFloat(), 2f)
|
||||
//g.draw(batch, "${ccY}FPS $ccG${Terrarum.appgc.fps}", (Gdx.graphics.width - 6 * 8 - 2).toFloat(), 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}MEM ", (TerrarumGDX.WIDTH - 21 * 8 - 2).toFloat(), 2f)
|
||||
//g.draw(batch, "${ccY}FPS $ccG${Terrarum.appgc.fps}", (TerrarumGDX.WIDTH - 6 * 8 - 2).toFloat(), 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}CPUs ${if (TerrarumGDX.MULTITHREAD) ccG else ccR}${TerrarumGDX.THREADS}",
|
||||
(Gdx.graphics.width - 2 - 6*8).toFloat(), 10f)
|
||||
(TerrarumGDX.WIDTH - 2 - 6*8).toFloat(), 10f)
|
||||
|
||||
//g.color = GameFontBase.codeToCol["g"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${TerrarumGDX.memInUse}M",
|
||||
(Gdx.graphics.width - 17 * 8 - 2).toFloat(), 2f)
|
||||
(TerrarumGDX.WIDTH - 17 * 8 - 2).toFloat(), 2f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "/${TerrarumGDX.memTotal}M/",
|
||||
(Gdx.graphics.width - 12 * 8 - 2).toFloat(), 2f)
|
||||
(TerrarumGDX.WIDTH - 12 * 8 - 2).toFloat(), 2f)
|
||||
//TerrarumGDX.fontSmallNumbers.color = GameFontBase.codeToCol["m"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${TerrarumGDX.memXmx}M",
|
||||
(Gdx.graphics.width - 5 * 8 - 2).toFloat(), 2f)
|
||||
(TerrarumGDX.WIDTH - 5 * 8 - 2).toFloat(), 2f)
|
||||
|
||||
/**
|
||||
* Bottom left
|
||||
*/
|
||||
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${TerrarumGDX.ingame!!.actorContainer.size + TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
2f, Gdx.graphics.height - 10f)
|
||||
2f, TerrarumGDX.HEIGHT - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${TerrarumGDX.ingame!!.actorContainer.size}",
|
||||
(2 + 17*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
(2 + 17*8).toFloat(), TerrarumGDX.HEIGHT - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
(2 + 28*8).toFloat(), TerrarumGDX.HEIGHT - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${TerrarumGDX.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
(2 + 41*8).toFloat(), TerrarumGDX.HEIGHT - 10f)
|
||||
}
|
||||
|
||||
private fun printLine(batch: SpriteBatch, l: Int, s: String) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class ConsoleWindow : UICanvas, KeyControlled {
|
||||
private val LINE_HEIGHT = 20
|
||||
private val MESSAGES_DISPLAY_COUNT = 11
|
||||
|
||||
override var width: Int = Gdx.graphics.width
|
||||
override var width: Int = TerrarumGDX.WIDTH
|
||||
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
|
||||
|
||||
override var openCloseTime = 0f
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
object DrawUtil {
|
||||
fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) {
|
||||
val imageW = image.width
|
||||
val targetW = if (ui == null) Gdx.graphics.width else ui.width
|
||||
val targetW = if (ui == null) TerrarumGDX.WIDTH else ui.width
|
||||
|
||||
batch.draw(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat())
|
||||
}
|
||||
|
||||
@@ -98,13 +98,13 @@ interface UICanvas {
|
||||
).roundInt()
|
||||
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.width.toFloat(),
|
||||
Gdx.graphics.width - handler.UI.width.toFloat()
|
||||
TerrarumGDX.WIDTH.toFloat(),
|
||||
TerrarumGDX.WIDTH - handler.UI.width.toFloat()
|
||||
).roundInt()
|
||||
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.height.toFloat(),
|
||||
Gdx.graphics.height - handler.UI.height.toFloat()
|
||||
TerrarumGDX.HEIGHT.toFloat(),
|
||||
TerrarumGDX.HEIGHT - handler.UI.height.toFloat()
|
||||
).roundInt()
|
||||
}
|
||||
}
|
||||
@@ -122,13 +122,13 @@ interface UICanvas {
|
||||
).roundInt()
|
||||
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.width - handler.UI.width.toFloat(),
|
||||
Gdx.graphics.width.toFloat()
|
||||
TerrarumGDX.WIDTH - handler.UI.width.toFloat(),
|
||||
TerrarumGDX.WIDTH.toFloat()
|
||||
).roundInt()
|
||||
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
|
||||
handler.openCloseCounter / openCloseTime,
|
||||
Gdx.graphics.height - handler.UI.height.toFloat(),
|
||||
Gdx.graphics.height.toFloat()
|
||||
TerrarumGDX.HEIGHT - handler.UI.height.toFloat(),
|
||||
TerrarumGDX.HEIGHT.toFloat()
|
||||
).roundInt()
|
||||
}
|
||||
}
|
||||
@@ -136,16 +136,16 @@ interface UICanvas {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = 0
|
||||
Position.TOP -> handler!!.posY = 0
|
||||
Position.RIGHT -> handler!!.posX = Gdx.graphics.width - handler.UI.width
|
||||
Position.BOTTOM -> handler!!.posY = Gdx.graphics.height - handler.UI.height
|
||||
Position.RIGHT -> handler!!.posX = TerrarumGDX.WIDTH - handler.UI.width
|
||||
Position.BOTTOM -> handler!!.posY = TerrarumGDX.HEIGHT - handler.UI.height
|
||||
}
|
||||
}
|
||||
fun endClosingPopOut(handler: UIHandler?, position: Position) {
|
||||
when (position) {
|
||||
Position.LEFT -> handler!!.posX = -handler.UI.width
|
||||
Position.TOP -> handler!!.posY = -handler.UI.height
|
||||
Position.RIGHT -> handler!!.posX = Gdx.graphics.width
|
||||
Position.BOTTOM -> handler!!.posY = Gdx.graphics.height
|
||||
Position.RIGHT -> handler!!.posX = TerrarumGDX.WIDTH
|
||||
Position.BOTTOM -> handler!!.posY = TerrarumGDX.HEIGHT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ object WeatherMixer {
|
||||
kotlin.repeat(4) {
|
||||
// 4 seems good
|
||||
val rainParticle = ParticleTestRain(
|
||||
playerPos.x + HQRNG().nextInt(Gdx.graphics.width) - TerrarumGDX.HALFW,
|
||||
playerPos.x + HQRNG().nextInt(TerrarumGDX.WIDTH) - TerrarumGDX.HALFW,
|
||||
playerPos.y - TerrarumGDX.HALFH
|
||||
)
|
||||
TerrarumGDX.ingame!!.addParticle(rainParticle)
|
||||
@@ -121,8 +121,8 @@ object WeatherMixer {
|
||||
TerrarumGDX.inShapeRenderer {
|
||||
it.rect(
|
||||
0f, 0f,
|
||||
Gdx.graphics.width.toFloat(),
|
||||
Gdx.graphics.height.toFloat(),
|
||||
TerrarumGDX.WIDTH.toFloat(),
|
||||
TerrarumGDX.HEIGHT.toFloat(),
|
||||
getGradientColour(skyboxColourMap, 1, timeNow),
|
||||
getGradientColour(skyboxColourMap, 1, timeNow),
|
||||
getGradientColour(skyboxColourMap, 0, timeNow),
|
||||
|
||||
@@ -47,7 +47,7 @@ object FeaturesDrawer {
|
||||
* usually targeted for the environmental temperature (desert/winterland), hence the name.
|
||||
*/
|
||||
fun drawEnvOverlay(batch: SpriteBatch) {
|
||||
val onscreen_tiles_max = FastMath.ceil(Gdx.graphics.height * Gdx.graphics.width / FastMath.sqr (TILE_SIZE.toFloat())) * 2
|
||||
val onscreen_tiles_max = FastMath.ceil(TerrarumGDX.HEIGHT * TerrarumGDX.WIDTH / FastMath.sqr (TILE_SIZE.toFloat())) * 2
|
||||
val onscreen_tiles_cap = onscreen_tiles_max / 4f
|
||||
val onscreen_cold_tiles = BlockStats.getCount(*TILES_COLD).toFloat()
|
||||
val onscreen_warm_tiles = BlockStats.getCount(*TILES_WARM).toFloat()
|
||||
@@ -62,8 +62,8 @@ object FeaturesDrawer {
|
||||
batch.color = ColourTemp(colTemp)
|
||||
batch.fillRect(WorldCamera.x * zoom,
|
||||
WorldCamera.y * zoom,
|
||||
Gdx.graphics.width * if (zoom < 1) 1f / zoom else zoom,
|
||||
Gdx.graphics.height * if (zoom < 1) 1f / zoom else zoom
|
||||
TerrarumGDX.WIDTH * if (zoom < 1) 1f / zoom else zoom,
|
||||
TerrarumGDX.HEIGHT * if (zoom < 1) 1f / zoom else zoom
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ object LightmapRenderer {
|
||||
|
||||
// TODO resize(int, int) -aware
|
||||
|
||||
val LIGHTMAP_WIDTH = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(Gdx.graphics.width)
|
||||
val LIGHTMAP_WIDTH = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(TerrarumGDX.WIDTH)
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
val LIGHTMAP_HEIGHT = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(Gdx.graphics.height)
|
||||
val LIGHTMAP_HEIGHT = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(TerrarumGDX.HEIGHT)
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
|
||||
/**
|
||||
@@ -351,7 +351,7 @@ object LightmapRenderer {
|
||||
(x * DRAW_TILE_SIZE).round().toFloat(),
|
||||
(y * DRAW_TILE_SIZE).round().toFloat(),
|
||||
(DRAW_TILE_SIZE.ceil() * sameLevelCounter).toFloat(),
|
||||
DRAW_TILE_SIZE.ceil().toFloat()
|
||||
DRAW_TILE_SIZE.ceil().toFloat() + 1f
|
||||
)
|
||||
|
||||
x += sameLevelCounter - 1
|
||||
|
||||
@@ -3,7 +3,12 @@ package net.torvald.terrarum.worlddrawer
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.ceilInt
|
||||
import net.torvald.terrarum.gameactors.floor
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.round
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-12-30.
|
||||
@@ -34,26 +39,21 @@ object WorldCamera {
|
||||
|
||||
val player = TerrarumGDX.ingame!!.player
|
||||
|
||||
width = FastMath.ceil(Gdx.graphics.width / TerrarumGDX.ingame!!.screenZoom) // div, not mul
|
||||
height = FastMath.ceil(Gdx.graphics.height / TerrarumGDX.ingame!!.screenZoom)
|
||||
width = FastMath.ceil(TerrarumGDX.WIDTH / TerrarumGDX.ingame!!.screenZoom) // div, not mul
|
||||
height = FastMath.ceil(TerrarumGDX.HEIGHT / TerrarumGDX.ingame!!.screenZoom)
|
||||
|
||||
// position - (WH / 2)
|
||||
x = Math.round(// X only: ROUNDWORLD implementation
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2)
|
||||
y = Math.round(FastMath.clamp(
|
||||
x = (// X only: ROUNDWORLD implementation
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).roundInt()
|
||||
y = (FastMath.clamp(
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
||||
TILE_SIZE.toFloat(),
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
))
|
||||
)).roundInt()
|
||||
|
||||
|
||||
gdxCamX = Math.round(// X only: ROUNDWORLD implementation
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f)).toFloat()
|
||||
gdxCamY = Math.round(FastMath.clamp(
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f),
|
||||
TILE_SIZE.toFloat(),
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
)).toFloat()
|
||||
gdxCamX = x + (width / 2f).round()
|
||||
gdxCamY = y + (height / 2f).round()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user