mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed a NaN bug caused by a zero-width/height hitbox
Also inventory is widened to 10x7 of prev 9x7
This commit is contained in:
Binary file not shown.
@@ -29,13 +29,6 @@ class CircularArray<T>(val size: Int) {
|
||||
}
|
||||
|
||||
inline fun forEach(action: (T) -> Unit) {
|
||||
/*if (tail >= head) { // queue not full
|
||||
(head..tail - 1).map { buffer[it] }.forEach { action(it) }
|
||||
}
|
||||
else { // queue full
|
||||
(0..size - 1).map { buffer[(it + head) % size] }.forEach { action(it) }
|
||||
}*/
|
||||
|
||||
// has slightly better iteration performance than lambda
|
||||
if (tail >= head) {
|
||||
for (i in head..tail - 1)
|
||||
@@ -47,6 +40,22 @@ class CircularArray<T>(val size: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME not working as intended
|
||||
inline fun <R> fold(initial: R, operation: (R, T) -> R): R {
|
||||
var accumulator = initial
|
||||
//for (element in buffer) accumulator = operation(accumulator, element)
|
||||
if (tail >= head) {
|
||||
for (i in head..tail - 1)
|
||||
operation(accumulator, buffer[i])
|
||||
}
|
||||
else {
|
||||
for (i in 0..size - 1)
|
||||
operation(accumulator, buffer[(i + head) % size])
|
||||
}
|
||||
|
||||
return accumulator
|
||||
}
|
||||
|
||||
inline fun forEachConcurrent(action: (T) -> Unit) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
|
||||
TextureRegionPack.Companion.setGlobalFlipY(true);
|
||||
fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false);
|
||||
fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.dataclass.ArrayListMap
|
||||
import net.torvald.dataclass.CircularArray
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.AppLoader.printdbgerr
|
||||
@@ -114,12 +115,29 @@ object Terrarum : Screen {
|
||||
lateinit var defaultSaveDir: String
|
||||
private set
|
||||
|
||||
val memInUse: Long
|
||||
get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() + Gdx.app.nativeHeap) shr 20
|
||||
val memTotal: Long
|
||||
get() = Runtime.getRuntime().totalMemory() shr 20
|
||||
val memXmx: Long
|
||||
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||
|
||||
|
||||
private val javaHeapCircularArray = CircularArray<Int>(128)
|
||||
private val nativeHeapCircularArray = CircularArray<Int>(128)
|
||||
|
||||
val memJavaHeap: Int
|
||||
get() {
|
||||
javaHeapCircularArray.add((Gdx.app.javaHeap shr 20).toInt())
|
||||
|
||||
var acc = 0
|
||||
javaHeapCircularArray.forEach { acc = maxOf(acc, it) }
|
||||
return acc
|
||||
}
|
||||
val memNativeHeap: Int
|
||||
get() {
|
||||
nativeHeapCircularArray.add((Gdx.app.javaHeap shr 20).toInt())
|
||||
|
||||
var acc = 0
|
||||
nativeHeapCircularArray.forEach { acc = maxOf(acc, it) }
|
||||
return acc
|
||||
}
|
||||
val memXmx: Int
|
||||
get() = (Runtime.getRuntime().maxMemory() shr 20).toInt()
|
||||
|
||||
var environment: RunningEnvironment
|
||||
private set
|
||||
|
||||
@@ -217,10 +217,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
fun updateScreen(delta: Float) {
|
||||
Gdx.graphics.setTitle(AppLoader.GAME_NAME +
|
||||
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
|
||||
)
|
||||
Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
|
||||
|
||||
demoWorld.globalLight = WeatherMixer.globalLightNow
|
||||
demoWorld.updateWorldTime(delta)
|
||||
|
||||
@@ -62,8 +62,8 @@ class UIItemInventoryCatBar(
|
||||
val iconIndex = arrayOf(12, 16, 17, 13)
|
||||
|
||||
|
||||
println(relativeStartX)
|
||||
println(posX)
|
||||
println("[UIItemInventoryCatBar] relativeStartX: $relativeStartX")
|
||||
println("[UIItemInventoryCatBar] posX: $posX")
|
||||
|
||||
sideButtons = Array(iconIndex.size, { index ->
|
||||
val iconPosX = if (index < 2)
|
||||
|
||||
@@ -288,6 +288,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
baseHitboxW = w
|
||||
hitboxTranslateX = tx
|
||||
hitboxTranslateY = ty
|
||||
hitbox.setDimension(w.toDouble(), h.toDouble())
|
||||
}
|
||||
|
||||
fun setPosition(pos: Point2d) = setPosition(pos.x, pos.y)
|
||||
@@ -1079,8 +1080,10 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
}*/
|
||||
|
||||
private inline val submergedRatio: Double
|
||||
get() = submergedHeight / hitbox.height
|
||||
|
||||
get() {
|
||||
if (hitbox.height == 0.0) throw RuntimeException("Hitbox.height is zero")
|
||||
return submergedHeight / hitbox.height
|
||||
}
|
||||
private inline val submergedVolume: Double
|
||||
get() = submergedHeight * hitbox.width * hitbox.width
|
||||
|
||||
@@ -1538,10 +1541,12 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
actorValue[AVKey.BASEMASS] = value
|
||||
}
|
||||
internal val avAcceleration: Double
|
||||
get() = actorValue.getAsDouble(AVKey.ACCEL)!! *
|
||||
get() { if (accelMultMovement.isNaN()) println("accelMultMovement: $accelMultMovement")
|
||||
return actorValue.getAsDouble(AVKey.ACCEL)!! *
|
||||
(actorValue.getAsDouble(AVKey.ACCELBUFF) ?: 1.0) *
|
||||
accelMultMovement *
|
||||
scale.sqrt()
|
||||
}
|
||||
internal val avSpeedCap: Double
|
||||
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
|
||||
(actorValue.getAsDouble(AVKey.SPEEDBUFF) ?: 1.0) *
|
||||
|
||||
@@ -71,6 +71,12 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
|
||||
|
||||
fun setPosition(x1: Double, y1: Double): Hitbox {
|
||||
hitboxStart = Point2d(x1, y1)
|
||||
|
||||
if (width == 0.0 || height == 0.0) {
|
||||
println("[Hitbox] width or height is zero, perhaps you want to check it out?")
|
||||
Thread.currentThread().stackTrace.forEach { println(it) }
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
fun setPosition(vector: Vector2) = setPosition(vector.x, vector.y)
|
||||
|
||||
@@ -110,10 +110,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
Gdx.graphics.setTitle("${AppLoader.GAME_NAME} Building Maker" +
|
||||
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
|
||||
)
|
||||
Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
|
||||
|
||||
|
||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||
|
||||
|
||||
@@ -79,6 +79,10 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
camera.update()
|
||||
batch.projectionMatrix = camera.combined
|
||||
}
|
||||
|
||||
fun getCanonicalTitle() = AppLoader.GAME_NAME +
|
||||
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: J${Terrarum.memJavaHeap}M / N${Terrarum.memNativeHeap}M / X${Terrarum.memXmx}M"
|
||||
}
|
||||
|
||||
|
||||
@@ -461,10 +465,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
|
||||
|
||||
Gdx.graphics.setTitle(AppLoader.GAME_NAME +
|
||||
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
|
||||
)
|
||||
Gdx.graphics.setTitle(getCanonicalTitle())
|
||||
|
||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||
|
||||
@@ -913,7 +914,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
*/
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
MegaRainGovernor.resize()
|
||||
// FIXME debugger is pointing at this thing, not sure it actually caused memleak
|
||||
//MegaRainGovernor.resize()
|
||||
|
||||
|
||||
IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||
|
||||
@@ -31,7 +31,7 @@ class UIInventoryFull(
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var height: Int = Terrarum.HEIGHT
|
||||
|
||||
val internalWidth: Int = 630
|
||||
val internalWidth: Int = 686
|
||||
val internalHeight: Int = 558 // grad_begin..grad_end..contents..grad_begin..grad_end
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.ArrayList
|
||||
*
|
||||
* Note: everything is pretty much fixed size.
|
||||
*
|
||||
* Dimension of the whole area: 496x384
|
||||
* Number of grids: 9x7
|
||||
* Dimension of the whole area: 552x384
|
||||
* Number of grids: 10x7
|
||||
* Number of lists: 2x7
|
||||
*
|
||||
* Created by minjaesong on 2017-10-21.
|
||||
@@ -79,9 +79,9 @@ class UIItemInventoryDynamicList(
|
||||
7 * 2, {
|
||||
UIItemInventoryElem(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (244 + listGap) * (it % 2),
|
||||
posX = this.posX + (272 + listGap) * (it % 2),
|
||||
posY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2),
|
||||
width = 244,
|
||||
width = 272,
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
@@ -93,11 +93,11 @@ class UIItemInventoryDynamicList(
|
||||
inactiveTextCol = defaultTextColour
|
||||
) })
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(
|
||||
7 * 9, {
|
||||
7 * 10, {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % 9),
|
||||
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / 9),
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % 10),
|
||||
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / 10),
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
|
||||
@@ -320,7 +320,7 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val remoConWidth = 280
|
||||
val remoConWidth = 304
|
||||
fun getRemoConHeight(menu: ArrayList<String>) = 36 * menu.size.plus(1)
|
||||
fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1)
|
||||
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt()
|
||||
|
||||
@@ -181,9 +181,9 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
(Terrarum.WIDTH - 2 - 6 * 8).toFloat(), 10f)
|
||||
|
||||
//g.color = GameFontBase.codeToCol["g"]
|
||||
Terrarum.fontSmallNumbers.draw(batch, "${Terrarum.memInUse}M",
|
||||
Terrarum.fontSmallNumbers.draw(batch, "${Terrarum.memJavaHeap}M",
|
||||
(Terrarum.WIDTH - 17 * 8 - 2).toFloat(), 2f)
|
||||
Terrarum.fontSmallNumbers.draw(batch, "/${Terrarum.memTotal}M/",
|
||||
Terrarum.fontSmallNumbers.draw(batch, "/${Terrarum.memNativeHeap}M/",
|
||||
(Terrarum.WIDTH - 12 * 8 - 2).toFloat(), 2f)
|
||||
//Terrarum.fontSmallNumbers.color = GameFontBase.codeToCol["m"]
|
||||
Terrarum.fontSmallNumbers.draw(batch, "${Terrarum.memXmx}M",
|
||||
|
||||
Reference in New Issue
Block a user