mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 00:26:07 +09:00
LibGDX, here I am.
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendScreen
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-14.
|
||||
*/
|
||||
class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var height: Int = Terrarum.HEIGHT
|
||||
override var width: Int = Gdx.graphics.width
|
||||
override var height: Int = Gdx.graphics.height
|
||||
|
||||
override var openCloseTime: Int = 0
|
||||
override var openCloseTime: Float = 0f
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
@@ -31,18 +30,16 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
private var xdelta = 0.0
|
||||
private var ydelta = 0.0
|
||||
|
||||
val ccW = GameFontBase.colToCode["w"]
|
||||
val ccG = GameFontBase.colToCode["g"]
|
||||
val ccY = GameFontBase.colToCode["y"]
|
||||
val ccR = GameFontBase.colToCode["r"]
|
||||
val ccM = GameFontBase.colToCode["m"]
|
||||
val ccW = 0.toChar()//GameFontBase.colToCode["w"]
|
||||
val ccG = 0.toChar()//GameFontBase.colToCode["g"]
|
||||
val ccY = 0.toChar()//GameFontBase.colToCode["y"]
|
||||
val ccR = 0.toChar()//GameFontBase.colToCode["r"]
|
||||
val ccM = 0.toChar()//GameFontBase.colToCode["m"]
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
val player = Terrarum.ingame!!.player!!
|
||||
override fun update(delta: Float) {
|
||||
val player = TerrarumGDX.ingame!!.player!!
|
||||
val hitbox = player.hitbox
|
||||
|
||||
xdelta = hitbox.canonicalX - prevPlayerX
|
||||
@@ -52,18 +49,19 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
prevPlayerY = hitbox.canonicalY
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
override fun render(batch: SpriteBatch) {
|
||||
fun Int.rawR() = this / LightmapRenderer.MUL_2
|
||||
fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL
|
||||
fun Int.rawB() = this % LightmapRenderer.MUL
|
||||
|
||||
val player = Terrarum.ingame!!.player
|
||||
val player = TerrarumGDX.ingame!!.player
|
||||
|
||||
val mouseTileX = ((WorldCamera.x + gc.input.mouseX / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((WorldCamera.y + gc.input.mouseY / Terrarum.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileX = ((WorldCamera.x + TerrarumGDX.mouseX / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((WorldCamera.y + TerrarumGDX.mouseY / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
|
||||
g.font = Terrarum.fontSmallNumbers
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
//g.color = GameFontBase.codeToCol["y"]
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
val hitbox = player?.hitbox
|
||||
|
||||
@@ -71,42 +69,42 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
* First column
|
||||
*/
|
||||
|
||||
printLineColumn(g, 1, 1, "startX "
|
||||
printLineColumn(batch, 1, 1, "startX "
|
||||
+ ccG
|
||||
+ "${hitbox?.startX}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.startX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 2, 1, "endX "
|
||||
printLineColumn(batch, 2, 1, "endX "
|
||||
+ ccG
|
||||
+ "${hitbox?.endX}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.endX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 1, 2, "startY "
|
||||
printLineColumn(batch, 1, 2, "startY "
|
||||
+ ccG
|
||||
+ "${hitbox?.startY}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.startY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLineColumn(g, 2, 2, "endY "
|
||||
printLineColumn(batch, 2, 2, "endY "
|
||||
+ ccG
|
||||
+ "${hitbox?.endY}"
|
||||
+ " ("
|
||||
+ "${(hitbox?.endY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
|
||||
printLine(g, 3, "veloX reported $ccG${player?.externalForce?.x}")
|
||||
printLine(g, 4, "veloY reported $ccG${player?.externalForce?.y}")
|
||||
printLine(batch, 3, "veloX reported $ccG${player?.externalForce?.x}")
|
||||
printLine(batch, 4, "veloY reported $ccG${player?.externalForce?.y}")
|
||||
|
||||
printLine(g, 5, "p_WalkX $ccG${player?.controllerMoveDelta?.x}")
|
||||
printLine(g, 6, "p_WalkY $ccG${player?.controllerMoveDelta?.y}")
|
||||
printLine(batch, 5, "p_WalkX $ccG${player?.controllerMoveDelta?.x}")
|
||||
printLine(batch, 6, "p_WalkY $ccG${player?.controllerMoveDelta?.y}")
|
||||
|
||||
printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}")
|
||||
printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}")
|
||||
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
|
||||
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
|
||||
|
||||
if (player != null) {
|
||||
printLineColumn(g, 1, 7,
|
||||
printLineColumn(batch, 1, 7,
|
||||
"walled " +
|
||||
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
|
||||
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
|
||||
@@ -118,7 +116,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
|
||||
|
||||
//printLine(g, 7, "jump $ccG${player.jumpAcc}")
|
||||
//printLine(batch, 7, "jump $ccG${player.jumpAcc}")
|
||||
|
||||
val lightVal: String
|
||||
val mtX = mouseTileX.toString()
|
||||
@@ -133,35 +131,35 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
rawR.toString() + " " +
|
||||
rawG.toString() + " " +
|
||||
rawB.toString() + ")"
|
||||
printLine(g, 8, "light@cursor $ccG$lightVal")
|
||||
printLine(batch, 8, "light@cursor $ccG$lightVal")
|
||||
|
||||
val tileNum = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
val tileNum = TerrarumGDX.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||
|
||||
printLine(g, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
|
||||
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
|
||||
|
||||
/**
|
||||
* Second column
|
||||
*/
|
||||
|
||||
//printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
//printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
//printLineColumn(batch, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
//printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
|
||||
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
|
||||
" (${Terrarum.ingame!!.world.time.getFormattedTime()})")
|
||||
printLineColumn(g, 2, 6, "Mass $ccG${player?.mass}")
|
||||
printLineColumn(batch, 2, 5, "Time $ccG${TerrarumGDX.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
|
||||
" (${TerrarumGDX.ingame!!.world.time.getFormattedTime()})")
|
||||
printLineColumn(batch, 2, 6, "Mass $ccG${player?.mass}")
|
||||
|
||||
printLineColumn(g, 2, 7, "noClip $ccG${player?.noClip}")
|
||||
printLineColumn(batch, 2, 7, "noClip $ccG${player?.noClip}")
|
||||
|
||||
|
||||
drawHistogram(g, LightmapRenderer.histogram,
|
||||
Terrarum.WIDTH - histogramW - 30,
|
||||
Terrarum.HEIGHT - histogramH - 30
|
||||
drawHistogram(batch, LightmapRenderer.histogram,
|
||||
Gdx.graphics.width - histogramW - 30,
|
||||
Gdx.graphics.height - histogramH - 30
|
||||
)
|
||||
if (Terrarum.controller != null) {
|
||||
drawGamepadAxis(g,
|
||||
Terrarum.controller!!.getAxisValue(3),
|
||||
Terrarum.controller!!.getAxisValue(2),
|
||||
Terrarum.WIDTH - 135,
|
||||
if (TerrarumGDX.controller != null) {
|
||||
drawGamepadAxis(batch,
|
||||
TerrarumGDX.controller!!.getAxisValue(3),
|
||||
TerrarumGDX.controller!!.getAxisValue(2),
|
||||
Gdx.graphics.width - 135,
|
||||
40
|
||||
)
|
||||
}
|
||||
@@ -170,65 +168,69 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
* Top right
|
||||
*/
|
||||
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
g.drawString("${ccY}MEM ", (Terrarum.WIDTH - 21 * 8 - 2).toFloat(), 2f)
|
||||
//g.drawString("${ccY}FPS $ccG${Terrarum.appgc.fps}", (Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 10f)
|
||||
g.drawString("${ccY}CPUs ${if (Terrarum.MULTITHREAD) ccG else ccR}${Terrarum.THREADS}",
|
||||
(Terrarum.WIDTH - 2 - 6*8).toFloat(), 10f)
|
||||
//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}CPUs ${if (TerrarumGDX.MULTITHREAD) ccG else ccR}${TerrarumGDX.THREADS}",
|
||||
(Gdx.graphics.width - 2 - 6*8).toFloat(), 10f)
|
||||
|
||||
g.color = GameFontBase.codeToCol["g"]
|
||||
g.drawString("${Terrarum.memInUse}M",
|
||||
(Terrarum.WIDTH - 17 * 8 - 2).toFloat(), 2f)
|
||||
g.drawString("/${Terrarum.memTotal}M/",
|
||||
(Terrarum.WIDTH - 12 * 8 - 2).toFloat(), 2f)
|
||||
g.color = GameFontBase.codeToCol["m"]
|
||||
g.drawString("${Terrarum.memXmx}M",
|
||||
(Terrarum.WIDTH - 5 * 8 - 2).toFloat(), 2f)
|
||||
//g.color = GameFontBase.codeToCol["g"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${TerrarumGDX.memInUse}M",
|
||||
(Gdx.graphics.width - 17 * 8 - 2).toFloat(), 2f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "/${TerrarumGDX.memTotal}M/",
|
||||
(Gdx.graphics.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)
|
||||
|
||||
/**
|
||||
* Bottom left
|
||||
*/
|
||||
|
||||
g.drawString("${ccY}Actors total $ccG${Terrarum.ingame!!.actorContainer.size + Terrarum.ingame!!.actorContainerInactive.size}",
|
||||
2f, Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccY}Active $ccG${Terrarum.ingame!!.actorContainer.size}",
|
||||
(2 + 17*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccY}Dormant $ccG${Terrarum.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
g.drawString("${ccM}Particles $ccG${Terrarum.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Terrarum.HEIGHT - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${TerrarumGDX.ingame!!.actorContainer.size + TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
2f, Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${TerrarumGDX.ingame!!.actorContainer.size}",
|
||||
(2 + 17*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${TerrarumGDX.ingame!!.actorContainerInactive.size}",
|
||||
(2 + 28*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${TerrarumGDX.ingame!!.particlesActive}",
|
||||
(2 + 41*8).toFloat(), Gdx.graphics.height - 10f)
|
||||
}
|
||||
|
||||
private fun printLine(g: Graphics, l: Int, s: String) {
|
||||
g.drawString(s, 10f, line(l))
|
||||
private fun printLine(batch: SpriteBatch, l: Int, s: String) {
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
s, 10f, line(l)
|
||||
)
|
||||
}
|
||||
|
||||
private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) {
|
||||
g.drawString(s, (10 + column(col)), line(row))
|
||||
private fun printLineColumn(batch: SpriteBatch, col: Int, row: Int, s: String) {
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
s, (10 + column(col)), line(row)
|
||||
)
|
||||
}
|
||||
|
||||
val histogramW = 256
|
||||
val histogramH = 200
|
||||
|
||||
private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
||||
val uiColour = Color(0x80000000.toInt())
|
||||
val barR = Color(0xDD0000)
|
||||
val barG = Color(0x00DD00)
|
||||
val barB = Color(0x0000DD)
|
||||
private fun drawHistogram(batch: SpriteBatch, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
|
||||
val uiColour = Color(0x000000_80.toInt())
|
||||
val barR = Color(0xDD0000_FF.toInt())
|
||||
val barG = Color(0x00DD00_FF.toInt())
|
||||
val barB = Color(0x0000DD_FF.toInt())
|
||||
val barColour = arrayOf(barR, barG, barB)
|
||||
val w = histogramW.toFloat()
|
||||
val h = histogramH.toFloat()
|
||||
val range = histogram.range
|
||||
val histogramMax = histogram.screen_tiles.toFloat()
|
||||
|
||||
g.color = uiColour
|
||||
g.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
g.color = Color.gray
|
||||
g.drawString("0", x.toFloat(), y.toFloat() + h + 2)
|
||||
g.drawString("255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||
g.drawString("Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
||||
batch.color = uiColour
|
||||
batch.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
batch.color = Color.GRAY
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "0", x.toFloat(), y.toFloat() + h + 2)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
|
||||
|
||||
blendScreen()
|
||||
//blendScreen()
|
||||
for (c in 0..2) {
|
||||
for (i in 0..255) {
|
||||
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
|
||||
@@ -243,14 +245,14 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
val bar_y = y + (h / histogramMax) - bar_h + h
|
||||
val bar_w = 1f
|
||||
|
||||
g.color = barColour[c]
|
||||
g.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||
batch.color = barColour[c]
|
||||
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||
}
|
||||
}
|
||||
blendNormal()
|
||||
//blendNormal()
|
||||
}
|
||||
|
||||
private fun drawGamepadAxis(g: Graphics, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
||||
private fun drawGamepadAxis(batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
|
||||
val uiColour = Color(0xAA000000.toInt())
|
||||
val w = 128f
|
||||
val h = 128f
|
||||
@@ -260,36 +262,41 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
val pointDX = axisX * halfW
|
||||
val pointDY = axisY * halfH
|
||||
|
||||
val padName = if (Terrarum.controller!!.name.isEmpty()) "Gamepad"
|
||||
else Terrarum.controller!!.name
|
||||
val padName = if (TerrarumGDX.controller!!.name.isEmpty()) "Gamepad"
|
||||
else TerrarumGDX.controller!!.name
|
||||
|
||||
blendNormal()
|
||||
|
||||
g.color = uiColour
|
||||
g.fillRect(uiX.toFloat(), uiY.toFloat(), w, h)
|
||||
g.color = Color.white
|
||||
g.drawLine(uiX + halfW, uiY + halfH, uiX + halfW + pointDX, uiY + halfH + pointDY)
|
||||
g.color = Color.gray
|
||||
g.drawString(padName, uiX + w / 2 - (padName.length) * 4, uiY.toFloat() + h + 2)
|
||||
batch.end()
|
||||
TerrarumGDX.inShapeRenderer {
|
||||
it.color = uiColour
|
||||
it.rect(uiX.toFloat(), uiY.toFloat(), w, h)
|
||||
it.color = Color.WHITE
|
||||
it.line(uiX + halfW, uiY + halfH, uiX + halfW + pointDX, uiY + halfH + pointDY)
|
||||
it.color = Color.GRAY
|
||||
}
|
||||
batch.begin()
|
||||
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch, padName, uiX + w / 2 - (padName.length) * 4, uiY.toFloat() + h + 2)
|
||||
|
||||
}
|
||||
|
||||
private fun line(i: Int): Float = i * 10f
|
||||
|
||||
private fun column(i: Int): Float = 300f * (i - 1)
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun processInput(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user