mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
finally working floating head on the minimap
This commit is contained in:
@@ -110,8 +110,6 @@ object MinimapComposer : Disposable {
|
|||||||
val tlx = x - (MINIMAP_TILE_WIDTH / 2)
|
val tlx = x - (MINIMAP_TILE_WIDTH / 2)
|
||||||
val tly = y - (MINIMAP_TILE_HEIGHT / 2)
|
val tly = y - (MINIMAP_TILE_HEIGHT / 2)
|
||||||
|
|
||||||
// printdbg(this, "queue render - c($x,$y), tl($tlx,$tlx)")
|
|
||||||
|
|
||||||
// make the queueing work
|
// make the queueing work
|
||||||
// enqueue first
|
// enqueue first
|
||||||
spiralIndices.forEachIndexed { index, i ->
|
spiralIndices.forEachIndexed { index, i ->
|
||||||
@@ -124,27 +122,6 @@ object MinimapComposer : Disposable {
|
|||||||
// printdbg(this, "Queueing tilemap update ($tx,$ty) from queue[$i]")
|
// printdbg(this, "Queueing tilemap update ($tx,$ty) from queue[$i]")
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume the queue
|
|
||||||
/*for (k in currentThreads.indices) {
|
|
||||||
if (currentThreads[k].state == Thread.State.TERMINATED && !updaterQueue.isEmpty) {
|
|
||||||
currentThreads[k] = Thread(updaterQueue.removeFirst(), "MinimapLivetilePainter")
|
|
||||||
printdbg(this, "Consuming from queue; queue size now: ${updaterQueue.size}")
|
|
||||||
}
|
|
||||||
if (currentThreads[k].state == Thread.State.NEW) {
|
|
||||||
currentThreads[k].start()
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*updaterQueue.forEachIndexed { k, runnable ->
|
|
||||||
if (runnable != null) {
|
|
||||||
currentThreads[k] = Thread(runnable, "MinimapLivetilePainter")
|
|
||||||
printdbg(this, "Consuming from queue[$k]")
|
|
||||||
currentThreads[k].start()
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
threadExecutor.renew()
|
threadExecutor.renew()
|
||||||
threadExecutor.submitAll(updaterQueue.filterNotNull())
|
threadExecutor.submitAll(updaterQueue.filterNotNull())
|
||||||
Thread { threadExecutor.join() }.start()
|
Thread { threadExecutor.join() }.start()
|
||||||
@@ -180,8 +157,8 @@ object MinimapComposer : Disposable {
|
|||||||
oobColBtm
|
oobColBtm
|
||||||
else if (colTerr.a > 0.1f) colTerr else colWall
|
else if (colTerr.a > 0.1f) colTerr else colWall
|
||||||
|
|
||||||
if (index % 2 == 1) outCol.lerp(Color.BLACK, 0.2f)
|
// if (index % 2 == 1) outCol.lerp(Color.BLACK, 0.2f)
|
||||||
else if (index != (SQUARE_SIZE.sqr() - 1) / 2) outCol.lerp(Color.FIREBRICK, 0.12f)
|
// else if (index != (SQUARE_SIZE.sqr() - 1) / 2) outCol.lerp(Color.FIREBRICK, 0.12f)
|
||||||
|
|
||||||
pixmap.blending = Pixmap.Blending.None
|
pixmap.blending = Pixmap.Blending.None
|
||||||
pixmap.setColor(outCol)
|
pixmap.setColor(outCol)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
|||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_HEIGHT
|
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_HEIGHT
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_WIDTH
|
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_WIDTH
|
||||||
@@ -33,7 +34,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
|
val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
private val debugvals = true
|
// private val debugvals = true
|
||||||
|
|
||||||
override var width: Int = Toolkit.drawWidth
|
override var width: Int = Toolkit.drawWidth
|
||||||
override var height: Int = App.scr.height
|
override var height: Int = App.scr.height
|
||||||
@@ -68,6 +69,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
val cellOffY = INVENTORY_CELLS_OFFSET_Y()
|
val cellOffY = INVENTORY_CELLS_OFFSET_Y()
|
||||||
|
val worldWidth = INGAME.world.width
|
||||||
|
|
||||||
var mdx = 0f
|
var mdx = 0f
|
||||||
var mdy = 0f
|
var mdy = 0f
|
||||||
@@ -93,7 +95,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
minimapDrawOffX += mdx
|
minimapDrawOffX += mdx
|
||||||
minimapDrawOffY += mdy
|
minimapDrawOffY += mdy
|
||||||
|
|
||||||
minimapPanX = minimapPanX fmod INGAME.world.width.toFloat()
|
minimapPanX = minimapPanX fmod worldWidth.toFloat()
|
||||||
|
|
||||||
dragStatus = 1
|
dragStatus = 1
|
||||||
}
|
}
|
||||||
@@ -173,45 +175,68 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
((INGAME.actorContainerInactive + INGAME.actorContainerActive).filter { it is IngamePlayer } as List<IngamePlayer>).forEach {
|
((INGAME.actorContainerInactive + INGAME.actorContainerActive + listOf(INGAME.actorNowPlaying)).filterIsInstance<IngamePlayer>()).forEach {
|
||||||
it.getSpriteHead()?.let { t ->
|
it.getSpriteHead()?.let { t ->
|
||||||
val ox = 0.5f * MINIMAP_TILE_WIDTH
|
val sf = it.scale.toFloat()
|
||||||
val oy = 0.5f * MINIMAP_TILE_HEIGHT
|
val headHeight = 6
|
||||||
|
val ox = MINIMAP_TILE_WIDTH / 2f
|
||||||
|
val oy = MINIMAP_TILE_HEIGHT / 2f
|
||||||
val tx = (minimapDrawOffX - ox)
|
val tx = (minimapDrawOffX - ox)
|
||||||
val ty = (minimapDrawOffY - oy)
|
val ty = (minimapDrawOffY - oy)
|
||||||
val worldPos = it.intTilewiseHitbox
|
val worldPos = it.hitbox
|
||||||
val cw = it.scale.toFloat() * t.regionWidth
|
val cw = t.regionWidth * sf
|
||||||
val ch = it.scale.toFloat() * t.regionHeight
|
val ch = t.regionHeight * sf
|
||||||
val cx = worldPos.centeredX.round().toFloat()
|
val cx = worldPos.centeredX.div(TILE_SIZEF).round().toFloat()
|
||||||
val cy = worldPos.startY.round().toFloat()
|
val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).round().toFloat()
|
||||||
val dx = cx - oldPanX
|
val dx = cx - oldPanX
|
||||||
val dy = cy - oldPanY
|
val dy = cy - oldPanY
|
||||||
|
|
||||||
// tx/ty corresponds to world coord minimapPanXY
|
// drawing "crosshair"
|
||||||
|
val x1 = (tx + dx + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW
|
||||||
|
val x2 = (tx + dx + worldWidth + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW
|
||||||
|
val x3 = (tx + dx - worldWidth + MINIMAP_TILE_WIDTH / 2f) * minimapZoom + MINIMAP_HALFW
|
||||||
|
val y = (ty + dy + MINIMAP_TILE_HEIGHT / 2f) * minimapZoom + MINIMAP_HALFH
|
||||||
|
|
||||||
val x = (tx + dx) * minimapZoom + MINIMAP_HALFW
|
// how do I actually centre the head?
|
||||||
val y = (ty + dy) * minimapZoom + MINIMAP_HALFH
|
val doffx = -cw / 2f
|
||||||
|
val doffy = -ch / 2f
|
||||||
|
|
||||||
printdbg(this, "map pan: ($minimapPanX,$minimapPanY);draw pos: ($x,$y)")
|
// throwing three static images instead of one won't hurt anything
|
||||||
|
if (it.sprite?.flipHorizontal == false) {
|
||||||
|
batch.draw(t, x1 + doffx, y + doffy, cw, ch)
|
||||||
|
batch.draw(t, x2 + doffx, y + doffy, cw, ch)
|
||||||
|
batch.draw(t, x3 + doffx, y + doffy, cw, ch)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
batch.draw(t, x1 + doffx + cw, y + doffy, -cw, ch)
|
||||||
|
batch.draw(t, x2 + doffx + cw, y + doffy, -cw, ch)
|
||||||
|
batch.draw(t, x3 + doffx + cw, y + doffy, -cw, ch)
|
||||||
|
}
|
||||||
|
|
||||||
if (it.sprite?.flipHorizontal == false)
|
/*
|
||||||
batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), x, y, cw, ch)
|
val xi = x.roundToInt()
|
||||||
else
|
val yi = y.roundToInt()
|
||||||
batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), x + cw, y, -cw, ch)
|
batch.color = Color.LIME
|
||||||
|
Toolkit.drawBoxBorder(batch, x + doffx, y + doffy, cw, ch)
|
||||||
|
batch.color = Color.CORAL
|
||||||
|
Toolkit.drawStraightLine(batch, xi-10, yi, xi+10, 1, false)
|
||||||
|
Toolkit.drawStraightLine(batch, xi, yi-10, yi+10, 1, true)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batch.begin()
|
batch.begin()
|
||||||
|
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
val minimapDrawX = (width - MINIMAP_WIDTH) / 2
|
val minimapDrawX = (width - MINIMAP_WIDTH) / 2
|
||||||
val minimapDrawY = (height - cellOffY - App.scr.tvSafeGraphicsHeight - MINIMAP_HEIGHT - 72) / 2 + cellOffY * 1f
|
val minimapDrawY = (height - cellOffY - App.scr.tvSafeGraphicsHeight - MINIMAP_HEIGHT - 72) / 2 + cellOffY * 1f
|
||||||
|
|
||||||
if (debugvals) {
|
if (App.IS_DEVELOPMENT_BUILD) {
|
||||||
App.fontSmallNumbers.draw(batch, "Pan: ($minimapPanX,$minimapPanY) old ($oldPanX,$oldPanY); Trans: ($minimapDrawOffX,$minimapDrawOffY); x$minimapZoom", minimapDrawX, minimapDrawY - 16f)
|
App.fontSmallNumbers.draw(batch, "Pan: ($minimapPanX,$minimapPanY) old ($oldPanX,$oldPanY); Trans: ($minimapDrawOffX,$minimapDrawOffY); x$minimapZoom", minimapDrawX, minimapDrawY - 16f)
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
|
|
||||||
// border
|
// border
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Disposable
|
|||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,6 +120,9 @@ object Toolkit : Disposable {
|
|||||||
fillArea(batch, x, y, thickness, otherEnd - y)
|
fillArea(batch, x, y, thickness, otherEnd - y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun drawBoxBorder(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) =
|
||||||
|
drawBoxBorder(batch, x.roundToInt(), y.roundToInt(), w.roundToInt(), h.roundToInt())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters are THAT OF THE BOX, the border will be drawn OUTSIDE of the params you specified!
|
* Parameters are THAT OF THE BOX, the border will be drawn OUTSIDE of the params you specified!
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user