mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
minimap is working but update is slow
This commit is contained in:
@@ -14,6 +14,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.BlockStats
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.console.AVTracker
|
||||
import net.torvald.terrarum.console.ActorsList
|
||||
import net.torvald.terrarum.console.Authenticator
|
||||
@@ -146,6 +147,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
val SIZE_LARGE = Point2i(13500, 2970)
|
||||
val SIZE_HUGE = Point2i(22500, 4500)
|
||||
val WORLDSIZE = arrayOf(SIZE_SMALL, SIZE_NORMAL, SIZE_LARGE, SIZE_HUGE)
|
||||
|
||||
val worldgenThreadExecutor = ThreadExecutor()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||
|
||||
private var minimapRerenderTimer = 0f
|
||||
private val minimapRerenderInterval = 5f // seconds
|
||||
private val minimapRerenderInterval = 0.5f // seconds
|
||||
|
||||
private var dragStatus = 0
|
||||
|
||||
@@ -69,16 +69,14 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
val mdx = Terrarum.mouseDeltaX * 2f / minimapZoom
|
||||
val mdy = Terrarum.mouseDeltaY * 2f / minimapZoom
|
||||
|
||||
minimapPanX += mdx
|
||||
minimapPanY += mdy
|
||||
minimapPanX -= mdx
|
||||
minimapPanY -= mdy
|
||||
minimapTranslateX += mdx
|
||||
minimapTranslateY += mdy
|
||||
|
||||
dragStatus = 1
|
||||
}
|
||||
else if (dragStatus == 1 && !Terrarum.mouseDown) {
|
||||
dragStatus = 2
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.NUM_1)) {
|
||||
@@ -109,7 +107,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
// render minimap
|
||||
batch.end()
|
||||
|
||||
if (dragStatus == 2 || minimapRerenderTimer >= minimapRerenderInterval) {
|
||||
if (!Terrarum.mouseDown && (dragStatus == 1 || minimapRerenderTimer >= minimapRerenderInterval)) {
|
||||
dragStatus = 0
|
||||
minimapRerenderTimer = 0f
|
||||
|
||||
@@ -121,6 +119,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
|
||||
|
||||
minimapFBO.inActionF(minimapCamera, batch) {
|
||||
gdxClearAndSetBlend(MINIMAP_SKYCOL)
|
||||
|
||||
batch.inUse {
|
||||
|
||||
// [ 1 0 0 ] [ s 0 0 ] [ s 0 0 ]
|
||||
@@ -130,17 +130,16 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
// https://www.wolframalpha.com/input/?i=%7B%7B1,0,0%7D,%7B0,1,0%7D,%7Bp_x,p_y,1%7D%7D+*+%7B%7Bs,0,0%7D,%7B0,s,0%7D,%7Bw%2F2,h%2F2,1%7D%7D
|
||||
|
||||
// sky background
|
||||
batch.color = MINIMAP_SKYCOL
|
||||
Toolkit.fillArea(batch, 0f, 0f, MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||
batch.color = Color.WHITE
|
||||
|
||||
MinimapComposer.pixmaps.forEachIndexed { index, pixmap ->
|
||||
renderTextures[index].dispose()
|
||||
renderTextures[index] = Texture(pixmap)
|
||||
renderTextures[MinimapComposer.pixmaps.lastIndex - index].dispose()
|
||||
renderTextures[MinimapComposer.pixmaps.lastIndex - index] = Texture(pixmap)
|
||||
|
||||
val ix = index % 3; val iy = index / 3
|
||||
|
||||
val ox = (ix - 1) * MINIMAP_TILE_WIDTH
|
||||
val oy = (iy - 1) * MINIMAP_TILE_HEIGHT
|
||||
val ox = (ix - 0.5f) * MINIMAP_TILE_WIDTH
|
||||
val oy = (iy - 0.5f) * MINIMAP_TILE_HEIGHT
|
||||
|
||||
val tx = (minimapTranslateX - ox) * minimapZoom + 0.5f * MINIMAP_WIDTH
|
||||
val ty = (minimapTranslateY - oy) * minimapZoom + 0.5f * MINIMAP_HEIGHT
|
||||
@@ -156,7 +155,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
val minimapDrawY = (height - cellOffY - App.scr.tvSafeGraphicsHeight - MINIMAP_HEIGHT - 72) / 2 + cellOffY * 1f
|
||||
|
||||
if (debugvals) {
|
||||
App.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapDrawX, minimapDrawY - 16f)
|
||||
App.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; $minimapTranslateX, $minimapTranslateY; x$minimapZoom", minimapDrawX, minimapDrawY - 16f)
|
||||
}
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.concurrent.sliceEvenly
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
@@ -19,15 +20,17 @@ import kotlin.math.sin
|
||||
*/
|
||||
class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
||||
|
||||
private val genSlices = maxOf(ThreadExecutor.threadCount, world.width / 8)
|
||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
||||
|
||||
private val genSlices = maxOf(threadExecutor.threadCount, world.width / 8)
|
||||
|
||||
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||
|
||||
override fun getDone() {
|
||||
ThreadExecutor.renew()
|
||||
threadExecutor.renew()
|
||||
(0 until world.width).sliceEvenly(genSlices).map { xs ->
|
||||
ThreadExecutor.submit {
|
||||
threadExecutor.submit {
|
||||
val localJoise = getGenerator(seed, params as BiomegenParams)
|
||||
for (x in xs) {
|
||||
for (y in 0 until world.height) {
|
||||
@@ -45,7 +48,7 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
}
|
||||
}
|
||||
|
||||
ThreadExecutor.join()
|
||||
threadExecutor.join()
|
||||
|
||||
App.printdbg(this, "Waking up Worldgen")
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.concurrent.sliceEvenly
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
@@ -16,7 +17,9 @@ import kotlin.math.sin
|
||||
*/
|
||||
class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
||||
|
||||
private val genSlices = maxOf(ThreadExecutor.threadCount, world.width / 8)
|
||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
||||
|
||||
private val genSlices = maxOf(threadExecutor.threadCount, world.width / 8)
|
||||
|
||||
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||
@@ -25,9 +28,9 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
private val stoneSlateDitherSize = 4
|
||||
|
||||
override fun getDone() {
|
||||
ThreadExecutor.renew()
|
||||
threadExecutor.renew()
|
||||
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
||||
ThreadExecutor.submit {
|
||||
threadExecutor.submit {
|
||||
val localJoise = getGenerator(seed, params as TerragenParams)
|
||||
for (x in xs) {
|
||||
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
||||
@@ -37,7 +40,7 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
}
|
||||
}
|
||||
|
||||
ThreadExecutor.join()
|
||||
threadExecutor.join()
|
||||
|
||||
printdbg(this, "Waking up Worldgen")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user