mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
replacing min/max usage with kotlin's
This commit is contained in:
@@ -800,28 +800,6 @@ final public class FastMath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a float input and clamp it between min and max.
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @param min
|
|
||||||
* @param max
|
|
||||||
* @return clamped input
|
|
||||||
*/
|
|
||||||
public static float clamp(float input, float min, float max) {
|
|
||||||
return (input < min) ? min : (input > max) ? max : input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clamps the given float to be between 0 and 1.
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @return input clamped between 0 and 1.
|
|
||||||
*/
|
|
||||||
public static float saturate(float input) {
|
|
||||||
return clamp(input, 0f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a single precision (32 bit) floating point value
|
* Converts a single precision (32 bit) floating point value
|
||||||
* into half precision (16 bit).
|
* into half precision (16 bit).
|
||||||
@@ -876,31 +854,6 @@ final public class FastMath {
|
|||||||
| ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00)
|
| ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00)
|
||||||
| ((f >> 13) & 0x03ff));
|
| ((f >> 13) & 0x03ff));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float min(float... f) {
|
|
||||||
float min = f[0];
|
|
||||||
for (int i = 1; i < f.length; i++) min = (f[i] < min) ? f[i] : min;
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float max(float... f) {
|
|
||||||
float max = f[0];
|
|
||||||
for (int i = 1; i < f.length; i++) max = (f[i] > max) ? f[i] : max;
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int min(int... f) {
|
|
||||||
int min = f[0];
|
|
||||||
for (int i = 1; i < f.length; i++) min = (f[i] < min) ? f[i] : min;
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int max(int... f) {
|
|
||||||
int max = f[0];
|
|
||||||
for (int i = 1; i < f.length; i++) max = (f[i] > max) ? f[i] : max;
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getGCD(int a, int b) {
|
public static int getGCD(int a, int b) {
|
||||||
while (a != b) {
|
while (a != b) {
|
||||||
if (a > b) a = a-b;
|
if (a > b) a = a-b;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ fun Color.toXYZ(): CIEXYZ = RGB(this).toXYZ()
|
|||||||
}
|
}
|
||||||
val step = value.clampOne() * 255f // 0.0 .. 255.0
|
val step = value.clampOne() * 255f // 0.0 .. 255.0
|
||||||
val intStep = step.toInt() // 0 .. 255
|
val intStep = step.toInt() // 0 .. 255
|
||||||
val NeXTSTEP = minOf(intStep + 1, 255) // 1 .. 255
|
val NeXTSTEP = min(intStep + 1, 255) // 1 .. 255
|
||||||
|
|
||||||
out[i] = interpolateLinear(step - intStep, rgbLinLUT[intStep], rgbLinLUT[NeXTSTEP])
|
out[i] = interpolateLinear(step - intStep, rgbLinLUT[intStep], rgbLinLUT[NeXTSTEP])
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ fun RGB.linearise(): RGB {
|
|||||||
}
|
}
|
||||||
val step = value.clampOne() * 255f // 0.0 .. 255.0
|
val step = value.clampOne() * 255f // 0.0 .. 255.0
|
||||||
val intStep = step.toInt() // 0 .. 255
|
val intStep = step.toInt() // 0 .. 255
|
||||||
val NeXTSTEP = minOf(intStep + 1, 255) // 1 .. 255
|
val NeXTSTEP = min(intStep + 1, 255) // 1 .. 255
|
||||||
|
|
||||||
out[i] = interpolateLinear(step - intStep, rgbUnLinLUT[intStep], rgbUnLinLUT[NeXTSTEP])
|
out[i] = interpolateLinear(step - intStep, rgbUnLinLUT[intStep], rgbUnLinLUT[NeXTSTEP])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.torvald.colourutil
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OBSOLETE; use CIELchUtil for natural-looking colour
|
* OBSOLETE; use CIELchUtil for natural-looking colour
|
||||||
@@ -75,8 +77,8 @@ object HSVUtil {
|
|||||||
val g = color.g
|
val g = color.g
|
||||||
val b = color.b
|
val b = color.b
|
||||||
|
|
||||||
val rgbMin = FastMath.min(r, g, b)
|
val rgbMin = min(min(r, g), b)
|
||||||
val rgbMax = FastMath.max(r, g, b)
|
val rgbMax = max(max(r, g), b)
|
||||||
|
|
||||||
var h: Float
|
var h: Float
|
||||||
val s: Float
|
val s: Float
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class HUSLColorConverter {
|
|||||||
float x = intersectLineLine(line, new float[]{-1 / m1, 0});
|
float x = intersectLineLine(line, new float[]{-1 / m1, 0});
|
||||||
float length = distanceFromPole(new float[]{x, b1 + x * m1});
|
float length = distanceFromPole(new float[]{x, b1 + x * m1});
|
||||||
|
|
||||||
min = FastMath.min(min, length);
|
min = Math.min(min, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return min;
|
return min;
|
||||||
@@ -125,7 +125,7 @@ public class HUSLColorConverter {
|
|||||||
for (float[] bound : bounds) {
|
for (float[] bound : bounds) {
|
||||||
Length length = lengthOfRayUntilIntersect(hrad, bound);
|
Length length = lengthOfRayUntilIntersect(hrad, bound);
|
||||||
if (length.greaterEqualZero) {
|
if (length.greaterEqualZero) {
|
||||||
min = FastMath.min(min, length.length);
|
min = Math.min(min, length.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,10 @@ internal class UnsafeCvecArray(val width: Int, val height: Int) {
|
|||||||
// operators
|
// operators
|
||||||
fun max(x: Int, y: Int, other: Cvec) {
|
fun max(x: Int, y: Int, other: Cvec) {
|
||||||
val a = toAddr(x, y)
|
val a = toAddr(x, y)
|
||||||
array.setFloat(a + 0, maxOf(array.getFloat(a + 0), other.r))
|
array.setFloat(a + 0, kotlin.math.max(array.getFloat(a + 0), other.r))
|
||||||
array.setFloat(a + 1, maxOf(array.getFloat(a + 1), other.g))
|
array.setFloat(a + 1, kotlin.math.max(array.getFloat(a + 1), other.g))
|
||||||
array.setFloat(a + 2, maxOf(array.getFloat(a + 2), other.b))
|
array.setFloat(a + 2, kotlin.math.max(array.getFloat(a + 2), other.b))
|
||||||
array.setFloat(a + 3, maxOf(array.getFloat(a + 3), other.a))
|
array.setFloat(a + 3, kotlin.math.max(array.getFloat(a + 3), other.a))
|
||||||
}
|
}
|
||||||
fun mul(x: Int, y: Int, scalar: Float) {
|
fun mul(x: Int, y: Int, scalar: Float) {
|
||||||
val a = toAddr(x, y)
|
val a = toAddr(x, y)
|
||||||
@@ -202,10 +202,10 @@ internal class TestCvecArr(val width: Int, val height: Int) {
|
|||||||
|
|
||||||
// operators
|
// operators
|
||||||
inline fun max(x: Int, y: Int, other: Cvec) {
|
inline fun max(x: Int, y: Int, other: Cvec) {
|
||||||
setR(x, y, maxOf(getR(x, y), other.r))
|
setR(x, y, kotlin.math.max(getR(x, y), other.r))
|
||||||
setG(x, y, maxOf(getG(x, y), other.g))
|
setG(x, y, kotlin.math.max(getG(x, y), other.g))
|
||||||
setB(x, y, maxOf(getB(x, y), other.b))
|
setB(x, y, kotlin.math.max(getB(x, y), other.b))
|
||||||
setA(x, y, maxOf(getA(x, y), other.a))
|
setA(x, y, kotlin.math.max(getA(x, y), other.a))
|
||||||
}
|
}
|
||||||
inline fun mul(x: Int, y: Int, scalar: Float) {
|
inline fun mul(x: Int, y: Int, scalar: Float) {
|
||||||
setR(x, y, getR(x, y) * scalar)
|
setR(x, y, getR(x, y) * scalar)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.random
|
package net.torvald.random
|
||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.floorInt
|
import net.torvald.terrarum.floorToInt
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@ class TileableValueNoise(
|
|||||||
try {
|
try {
|
||||||
for (x in 0..width) {
|
for (x in 0..width) {
|
||||||
val thisSampleStart: Int = // 0-256 -> 0-4 -> 0-256(qnt)
|
val thisSampleStart: Int = // 0-256 -> 0-4 -> 0-256(qnt)
|
||||||
(x / width.toFloat() * samples).floorInt() * (width / samples)
|
(x / width.toFloat() * samples).floorToInt() * (width / samples)
|
||||||
val nextSampleStart: Int =
|
val nextSampleStart: Int =
|
||||||
(x / width.toFloat() * samples).floorInt().plus(1) * (width / samples)
|
(x / width.toFloat() * samples).floorToInt().plus(1) * (width / samples)
|
||||||
val stepWithinWindow: Int = x % (nextSampleStart - thisSampleStart)
|
val stepWithinWindow: Int = x % (nextSampleStart - thisSampleStart)
|
||||||
val windowScale: Float = stepWithinWindow.toFloat() / (width / samples)
|
val windowScale: Float = stepWithinWindow.toFloat() / (width / samples)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.terrarum.ItemCodex
|
import net.torvald.terrarum.ItemCodex
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.floor
|
import net.torvald.terrarum.floorToFloat
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||||
@@ -122,8 +122,8 @@ class AssembledSpriteAnimation(
|
|||||||
val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0)
|
val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0)
|
||||||
val w = image.regionWidth * scale
|
val w = image.regionWidth * scale
|
||||||
val h = image.regionHeight * scale
|
val h = image.regionHeight * scale
|
||||||
val fposX = posX.floor() + drawPos.x * scale
|
val fposX = posX.floorToFloat() + drawPos.x * scale
|
||||||
val fposY = posY.floor() + drawPos.y * scale - h
|
val fposY = posY.floorToFloat() + drawPos.y * scale - h
|
||||||
|
|
||||||
// draw
|
// draw
|
||||||
if (flipHorizontal && flipVertical)
|
if (flipHorizontal && flipVertical)
|
||||||
@@ -146,8 +146,8 @@ class AssembledSpriteAnimation(
|
|||||||
val drawPos = adp.origin + bodypartPos - imgCentre
|
val drawPos = adp.origin + bodypartPos - imgCentre
|
||||||
val w = image.regionWidth * scale
|
val w = image.regionWidth * scale
|
||||||
val h = image.regionHeight * scale
|
val h = image.regionHeight * scale
|
||||||
val fposX = posX.floor() + drawPos.x * scale
|
val fposX = posX.floorToFloat() + drawPos.x * scale
|
||||||
val fposY = posY.floor() + drawPos.y * scale
|
val fposY = posY.floorToFloat() + drawPos.y * scale
|
||||||
|
|
||||||
if (flipHorizontal && flipVertical)
|
if (flipHorizontal && flipVertical)
|
||||||
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
|
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ object GlslTilingTest : ApplicationAdapter() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
val tilesInHorizontal = (Gdx.graphics.width.toFloat() / TILING_SIZE).ceil() + 1f
|
val tilesInHorizontal = (Gdx.graphics.width.toFloat() / TILING_SIZE).ceilToFloat() + 1f
|
||||||
val tilesInVertical = (Gdx.graphics.height.toFloat() / TILING_SIZE).ceil() + 1f
|
val tilesInVertical = (Gdx.graphics.height.toFloat() / TILING_SIZE).ceilToFloat() + 1f
|
||||||
|
|
||||||
tilesQuad = Mesh(
|
tilesQuad = Mesh(
|
||||||
true, 4, 6,
|
true, 4, 6,
|
||||||
@@ -129,8 +129,8 @@ object GlslTilingTest : ApplicationAdapter() {
|
|||||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
|
||||||
val tilesInHorizontal = (Gdx.graphics.width.toFloat() / TILING_SIZE).ceil() + 1f
|
val tilesInHorizontal = (Gdx.graphics.width.toFloat() / TILING_SIZE).ceilToFloat() + 1f
|
||||||
val tilesInVertical = (Gdx.graphics.height.toFloat() / TILING_SIZE).ceil() + 1f
|
val tilesInVertical = (Gdx.graphics.height.toFloat() / TILING_SIZE).ceilToFloat() + 1f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.nio.file.StandardCopyOption
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.locks.Lock
|
import java.util.concurrent.locks.Lock
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Although the game (as product) can have infinitely many stages/planets/etc., those stages must be manually managed by YOU;
|
* Although the game (as product) can have infinitely many stages/planets/etc., those stages must be manually managed by YOU;
|
||||||
@@ -490,7 +491,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
|||||||
val dist2 = (p.getOrd(0) - (t.hitbox.centeredX - world.width * TILE_SIZE)).sqr() + (p.getOrd(1) - t.hitbox.centeredY).sqr()
|
val dist2 = (p.getOrd(0) - (t.hitbox.centeredX - world.width * TILE_SIZE)).sqr() + (p.getOrd(1) - t.hitbox.centeredY).sqr()
|
||||||
val dist3 = (p.getOrd(0) - (t.hitbox.centeredX + world.width * TILE_SIZE)).sqr() + (p.getOrd(1) - t.hitbox.centeredY).sqr()
|
val dist3 = (p.getOrd(0) - (t.hitbox.centeredX + world.width * TILE_SIZE)).sqr() + (p.getOrd(1) - t.hitbox.centeredY).sqr()
|
||||||
|
|
||||||
minOf(dist1, dist2, dist3)
|
min(min(dist1, dist2), dist3)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.jme3.math.FastMath
|
|||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-07-13.
|
* Created by minjaesong on 2017-07-13.
|
||||||
@@ -46,7 +47,7 @@ object SanicLoadScreen : LoadScreenBase() {
|
|||||||
|
|
||||||
textFbo = FrameBuffer(
|
textFbo = FrameBuffer(
|
||||||
Pixmap.Format.RGBA4444,
|
Pixmap.Format.RGBA4444,
|
||||||
maxOf(
|
max(
|
||||||
App.fontGame.getWidth(Lang["MENU_IO_LOADING"]),
|
App.fontGame.getWidth(Lang["MENU_IO_LOADING"]),
|
||||||
App.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"])
|
App.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"])
|
||||||
),
|
),
|
||||||
@@ -61,7 +62,7 @@ object SanicLoadScreen : LoadScreenBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val textX: Float; get() = (App.scr.width * 0.72f).floor()
|
val textX: Float; get() = (App.scr.width * 0.72f).floorToFloat()
|
||||||
|
|
||||||
private var genuineSonic = false // the "NOW LOADING..." won't appear unless the arrow first run passes it
|
private var genuineSonic = false // the "NOW LOADING..." won't appear unless the arrow first run passes it
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.JsonReader
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
@@ -26,13 +25,9 @@ import net.torvald.terrarum.gameworld.fmod
|
|||||||
import net.torvald.terrarum.itemproperties.CraftingCodex
|
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
|
||||||
import net.torvald.terrarum.savegame.DiskSkimmer
|
import net.torvald.terrarum.savegame.DiskSkimmer
|
||||||
import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO
|
|
||||||
import net.torvald.terrarum.serialise.Common
|
import net.torvald.terrarum.serialise.Common
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.utils.JsonFetcher
|
|
||||||
import net.torvald.terrarum.utils.forEachSiblings
|
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
||||||
import net.torvald.unsafe.UnsafeHelper
|
import net.torvald.unsafe.UnsafeHelper
|
||||||
@@ -40,10 +35,7 @@ import net.torvald.util.CircularArray
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.*
|
||||||
import kotlin.math.round
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typealias RGBA8888 = Int
|
typealias RGBA8888 = Int
|
||||||
@@ -238,16 +230,16 @@ object Terrarum : Disposable {
|
|||||||
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).times(scr.magn.toDouble())
|
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).times(scr.magn.toDouble())
|
||||||
/** Position of the cursor in the world, rounded */
|
/** Position of the cursor in the world, rounded */
|
||||||
@JvmStatic val mouseTileX: Int
|
@JvmStatic val mouseTileX: Int
|
||||||
get() = (mouseX / TILE_SIZE).floorInt()
|
get() = (mouseX / TILE_SIZE).floorToInt()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
@JvmStatic val mouseTileY: Int
|
@JvmStatic val mouseTileY: Int
|
||||||
get() = (mouseY / TILE_SIZE).floorInt()
|
get() = (mouseY / TILE_SIZE).floorToInt()
|
||||||
/** Position of the cursor in the world, rounded */
|
/** Position of the cursor in the world, rounded */
|
||||||
@JvmStatic val oldMouseTileX: Int
|
@JvmStatic val oldMouseTileX: Int
|
||||||
get() = (oldMouseX / TILE_SIZE).floorInt()
|
get() = (oldMouseX / TILE_SIZE).floorToInt()
|
||||||
/** Position of the cursor in the world */
|
/** Position of the cursor in the world */
|
||||||
@JvmStatic val oldMouseTileY: Int
|
@JvmStatic val oldMouseTileY: Int
|
||||||
get() = (oldMouseY / TILE_SIZE).floorInt()
|
get() = (oldMouseY / TILE_SIZE).floorToInt()
|
||||||
inline val mouseScreenX: Int
|
inline val mouseScreenX: Int
|
||||||
get() = Gdx.input.x.div(scr.magn).roundToInt()
|
get() = Gdx.input.x.div(scr.magn).roundToInt()
|
||||||
inline val mouseScreenY: Int
|
inline val mouseScreenY: Int
|
||||||
@@ -321,8 +313,8 @@ object Terrarum : Disposable {
|
|||||||
|
|
||||||
val mx = mouseX
|
val mx = mouseX
|
||||||
val my = mouseY
|
val my = mouseY
|
||||||
val mtx = (mouseX / TILE_SIZE).floorInt()
|
val mtx = (mouseX / TILE_SIZE).floorToInt()
|
||||||
val mty = (mouseY / TILE_SIZE).floorInt()
|
val mty = (mouseY / TILE_SIZE).floorToInt()
|
||||||
val msx = mx fmod TILE_SIZED
|
val msx = mx fmod TILE_SIZED
|
||||||
val msy = my fmod TILE_SIZED
|
val msy = my fmod TILE_SIZED
|
||||||
val vector = if (msx < SMALLGAP) { // X to the left
|
val vector = if (msx < SMALLGAP) { // X to the left
|
||||||
@@ -402,7 +394,7 @@ inline fun FrameBuffer.inAction(camera: OrthographicCamera?, batch: SpriteBatch?
|
|||||||
val oldCamPos = camera?.position?.cpy()
|
val oldCamPos = camera?.position?.cpy()
|
||||||
|
|
||||||
camera?.setToOrtho(true, this.width.toFloat(), this.height.toFloat())
|
camera?.setToOrtho(true, this.width.toFloat(), this.height.toFloat())
|
||||||
camera?.position?.set((this.width / 2f).round(), (this.height / 2f).round(), 0f) // TODO floor? ceil? round?
|
camera?.position?.set((this.width / 2f).roundToFloat(), (this.height / 2f).roundToFloat(), 0f) // TODO floor? ceil? round?
|
||||||
camera?.update()
|
camera?.update()
|
||||||
batch?.projectionMatrix = camera?.combined
|
batch?.projectionMatrix = camera?.combined
|
||||||
|
|
||||||
@@ -427,7 +419,7 @@ inline fun FrameBuffer.inActionF(camera: OrthographicCamera?, batch: SpriteBatch
|
|||||||
val oldCamPos = camera?.position?.cpy()
|
val oldCamPos = camera?.position?.cpy()
|
||||||
|
|
||||||
camera?.setToOrtho(false, this.width.toFloat(), this.height.toFloat())
|
camera?.setToOrtho(false, this.width.toFloat(), this.height.toFloat())
|
||||||
camera?.position?.set((this.width / 2f).round(), (this.height / 2f).round(), 0f) // TODO floor? ceil? round?
|
camera?.position?.set((this.width / 2f).roundToFloat(), (this.height / 2f).roundToFloat(), 0f) // TODO floor? ceil? round?
|
||||||
camera?.update()
|
camera?.update()
|
||||||
batch?.projectionMatrix = camera?.combined
|
batch?.projectionMatrix = camera?.combined
|
||||||
|
|
||||||
@@ -617,28 +609,28 @@ val emphVerb = TerrarumSansBitmap.toColorCode(0xFFF6)
|
|||||||
|
|
||||||
typealias Second = Float
|
typealias Second = Float
|
||||||
|
|
||||||
fun Int.sqr(): Int = this * this
|
inline fun Double.floorToInt() = floor(this).toInt()
|
||||||
fun Double.floorInt() = Math.floor(this).toInt()
|
inline fun Float.floorToInt() = FastMath.floor(this)
|
||||||
fun Float.floorInt() = FastMath.floor(this)
|
inline fun Double.ceilToInt() = Math.ceil(this).toInt()
|
||||||
fun Float.floor() = FastMath.floor(this).toFloat()
|
inline fun Float.ceilToFloat(): Float = FastMath.ceil(this).toFloat()
|
||||||
fun Double.ceilInt() = Math.ceil(this).toInt()
|
inline fun Float.ceilToInt() = FastMath.ceil(this)
|
||||||
fun Float.ceil(): Float = FastMath.ceil(this).toFloat()
|
inline fun Float.floorToFloat() = FastMath.floor(this).toFloat()
|
||||||
fun Float.ceilInt() = FastMath.ceil(this)
|
inline fun Float.roundToFloat(): Float = round(this)
|
||||||
fun Float.round(): Float = round(this)
|
//inline fun Double.round() = Math.round(this).toDouble()
|
||||||
fun Double.round() = Math.round(this).toDouble()
|
inline fun Double.floorToDouble() = floor(this)
|
||||||
fun Double.floor() = Math.floor(this)
|
inline fun Double.ceilToDouble() = ceil(this)
|
||||||
fun Double.ceil() = this.floor() + 1.0
|
inline fun Int.sqr(): Int = this * this
|
||||||
fun Double.abs() = Math.abs(this)
|
inline fun Double.sqr() = this * this
|
||||||
fun Double.sqr() = this * this
|
inline fun Float.sqr() = this * this
|
||||||
fun Float.sqr() = this * this
|
inline fun Double.sqrt() = Math.sqrt(this)
|
||||||
fun Double.sqrt() = Math.sqrt(this)
|
inline fun Float.sqrt() = FastMath.sqrt(this)
|
||||||
fun Float.sqrt() = FastMath.sqrt(this)
|
inline fun Int.abs() = this.absoluteValue
|
||||||
fun Int.abs() = this.absoluteValue
|
inline fun Double.abs() = this.absoluteValue
|
||||||
fun Double.bipolarClamp(limit: Double) = this.coerceIn(-limit, limit)
|
inline fun Double.bipolarClamp(limit: Double) = this.coerceIn(-limit, limit)
|
||||||
fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0
|
inline fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0
|
||||||
fun Boolean.toLong(shift: Int = 0) = if (this) 1L.shl(shift) else 0L
|
inline fun Boolean.toLong(shift: Int = 0) = if (this) 1L.shl(shift) else 0L
|
||||||
fun Int.bitCount() = java.lang.Integer.bitCount(this)
|
inline fun Int.bitCount() = java.lang.Integer.bitCount(this)
|
||||||
fun Long.bitCount() = java.lang.Long.bitCount(this)
|
inline fun Long.bitCount() = java.lang.Long.bitCount(this)
|
||||||
|
|
||||||
|
|
||||||
fun absMax(left: Double, right: Double): Double {
|
fun absMax(left: Double, right: Double): Double {
|
||||||
@@ -657,7 +649,6 @@ fun absMax(left: Double, right: Double): Double {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr()
|
fun Double.magnSqr() = if (this >= 0.0) this.sqr() else -this.sqr()
|
||||||
fun Double.sign() = if (this > 0.0) 1.0 else if (this < 0.0) -1.0 else 0.0
|
|
||||||
fun interpolateLinear(scale: Double, startValue: Double, endValue: Double): Double {
|
fun interpolateLinear(scale: Double, startValue: Double, endValue: Double): Double {
|
||||||
if (startValue == endValue) {
|
if (startValue == endValue) {
|
||||||
return startValue
|
return startValue
|
||||||
|
|||||||
@@ -168,11 +168,11 @@ object TerrarumPostProcessor : Disposable {
|
|||||||
val average = tallies.average()
|
val average = tallies.average()
|
||||||
|
|
||||||
val halfPos = 0.5f * INGAME.deltaTeeBenchmarks.size
|
val halfPos = 0.5f * INGAME.deltaTeeBenchmarks.size
|
||||||
val halfInd = halfPos.floorInt()
|
val halfInd = halfPos.floorToInt()
|
||||||
val low5pos = 0.05f * INGAME.deltaTeeBenchmarks.size
|
val low5pos = 0.05f * INGAME.deltaTeeBenchmarks.size
|
||||||
val low5ind = low5pos.floorInt()
|
val low5ind = low5pos.floorToInt()
|
||||||
val low1pos = 0.01f * INGAME.deltaTeeBenchmarks.size
|
val low1pos = 0.01f * INGAME.deltaTeeBenchmarks.size
|
||||||
val low1ind = low1pos.floorInt()
|
val low1ind = low1pos.floorToInt()
|
||||||
|
|
||||||
val median = FastMath.interpolateLinear(halfPos - halfInd, tallies[halfInd], tallies[halfInd + 1])
|
val median = FastMath.interpolateLinear(halfPos - halfInd, tallies[halfInd], tallies[halfInd + 1])
|
||||||
val low5 = FastMath.interpolateLinear(low5pos - low5ind, tallies[low5ind], tallies[low5ind + 1])
|
val low5 = FastMath.interpolateLinear(low5pos - low5ind, tallies[low5ind], tallies[low5ind + 1])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum
|
package net.torvald.terrarum
|
||||||
|
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
|
class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
|
||||||
@@ -39,7 +40,7 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
|
|||||||
var windowH: Int = 0; private set
|
var windowH: Int = 0; private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setDimension(maxOf(minimumW, scrw), maxOf(minimumH, scrh), App.getConfigDouble("screenmagnifying").toFloat())
|
setDimension(max(minimumW, scrw), max(minimumH, scrh), App.getConfigDouble("screenmagnifying").toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setDimension(scrw: Int, scrh: Int, magn: Float,) {
|
fun setDimension(scrw: Int, scrh: Int, magn: Float,) {
|
||||||
@@ -56,8 +57,8 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
|
|||||||
|
|
||||||
this.magn = magn
|
this.magn = magn
|
||||||
|
|
||||||
windowW = (scrw * magn).ceilInt() and 0x7FFFFFFE
|
windowW = (scrw * magn).ceilToInt() and 0x7FFFFFFE
|
||||||
windowH = (scrh * magn).ceilInt() and 0x7FFFFFFE
|
windowH = (scrh * magn).ceilToInt() and 0x7FFFFFFE
|
||||||
|
|
||||||
|
|
||||||
printdbg(this, "Window dim: $windowW x $windowH, called by:")
|
printdbg(this, "Window dim: $windowW x $windowH, called by:")
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class UIItemInventoryCatBar(
|
|||||||
// set up underlined indicator
|
// set up underlined indicator
|
||||||
init {
|
init {
|
||||||
// procedurally generate texture
|
// procedurally generate texture
|
||||||
val pixmap = Pixmap(catIcons.tileW + buttonGapSize.floorInt(), 1, Pixmap.Format.RGBA8888)
|
val pixmap = Pixmap(catIcons.tileW + buttonGapSize.floorToInt(), 1, Pixmap.Format.RGBA8888)
|
||||||
for (x in 0 until pixmap.width.plus(1).ushr(1)) { // eqv. of ceiling the half-int
|
for (x in 0 until pixmap.width.plus(1).ushr(1)) { // eqv. of ceiling the half-int
|
||||||
val col = /*if (x == 0)*/ /*0xffffff_80.toInt()*/
|
val col = /*if (x == 0)*/ /*0xffffff_80.toInt()*/
|
||||||
/*else if (x == 1)*/ /*0xffffff_c0.toInt()*/
|
/*else if (x == 1)*/ /*0xffffff_c0.toInt()*/
|
||||||
|
|||||||
@@ -19,11 +19,12 @@ import net.torvald.terrarum.toInt
|
|||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
object MinimapComposer : Disposable {
|
object MinimapComposer : Disposable {
|
||||||
|
|
||||||
private val threadExecutor = ThreadExecutor(maxOf(1, App.THREAD_COUNT.times(2).div(3)))
|
private val threadExecutor = ThreadExecutor(max(1, App.THREAD_COUNT.times(2).div(3)))
|
||||||
|
|
||||||
const val SQUARE_SIZE = 13 // preferably in odd number
|
const val SQUARE_SIZE = 13 // preferably in odd number
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
@@ -442,7 +443,7 @@ open class ActorWithBody : Actor {
|
|||||||
@Transient val feetPosPoint: Point2d = Point2d(0.0,0.0)
|
@Transient val feetPosPoint: Point2d = Point2d(0.0,0.0)
|
||||||
//get() = Point2d(hitbox.centeredX, hitbox.endY)
|
//get() = Point2d(hitbox.centeredX, hitbox.endY)
|
||||||
@Transient val feetPosTile: Point2i = Point2i(0,0)
|
@Transient val feetPosTile: Point2i = Point2i(0,0)
|
||||||
//get() = Point2i(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
//get() = Point2i(hIntTilewiseHitbox.centeredX.floorToInt(), hIntTilewiseHitbox.endY.floorToInt())
|
||||||
|
|
||||||
override fun run() = update(App.UPDATE_RATE)
|
override fun run() = update(App.UPDATE_RATE)
|
||||||
|
|
||||||
@@ -474,23 +475,23 @@ open class ActorWithBody : Actor {
|
|||||||
hitbox.reassign(newHitbox)
|
hitbox.reassign(newHitbox)
|
||||||
|
|
||||||
hIntTilewiseHitbox.setFromTwoPoints(
|
hIntTilewiseHitbox.setFromTwoPoints(
|
||||||
hitbox.startX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.startX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.startY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.startY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.endX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.endX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.endY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5
|
hitbox.endY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5
|
||||||
)
|
)
|
||||||
intTilewiseHitbox.setFromTwoPoints(
|
intTilewiseHitbox.setFromTwoPoints(
|
||||||
hitbox.startX.div(TILE_SIZE).floor(),
|
hitbox.startX.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.startY.div(TILE_SIZE).floor(),
|
hitbox.startY.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor()
|
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble()
|
||||||
)
|
)
|
||||||
|
|
||||||
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
||||||
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
||||||
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
||||||
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
||||||
feetPosTile.set(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
feetPosTile.set(hIntTilewiseHitbox.centeredX.floorToInt(), hIntTilewiseHitbox.endY.floorToInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
@@ -618,23 +619,23 @@ open class ActorWithBody : Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hIntTilewiseHitbox.setFromTwoPoints(
|
hIntTilewiseHitbox.setFromTwoPoints(
|
||||||
hitbox.startX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.startX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.startY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.startY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.endX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
hitbox.endX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5,
|
||||||
hitbox.endY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5
|
hitbox.endY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble() + 0.5
|
||||||
)
|
)
|
||||||
intTilewiseHitbox.setFromTwoPoints(
|
intTilewiseHitbox.setFromTwoPoints(
|
||||||
hitbox.startX.div(TILE_SIZE).floor(),
|
hitbox.startX.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.startY.div(TILE_SIZE).floor(),
|
hitbox.startY.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor()
|
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble()
|
||||||
)
|
)
|
||||||
|
|
||||||
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
||||||
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
||||||
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
||||||
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
||||||
feetPosTile.set(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
feetPosTile.set(hIntTilewiseHitbox.centeredX.floorToInt(), hIntTilewiseHitbox.endY.floorToInt())
|
||||||
|
|
||||||
|
|
||||||
if (mouseUp && this.tooltipText != null) INGAME.setTooltipMessage(this.tooltipText)
|
if (mouseUp && this.tooltipText != null) INGAME.setTooltipMessage(this.tooltipText)
|
||||||
@@ -746,23 +747,23 @@ open class ActorWithBody : Actor {
|
|||||||
fun BlockAddress.isFeetTile(hitbox: Hitbox): Boolean {
|
fun BlockAddress.isFeetTile(hitbox: Hitbox): Boolean {
|
||||||
val (x, y) = LandUtil.resolveBlockAddr(world!!, this)
|
val (x, y) = LandUtil.resolveBlockAddr(world!!, this)
|
||||||
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
||||||
hitbox.startX.div(TILE_SIZE).floor(),
|
hitbox.startX.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.startY.div(TILE_SIZE).floor(),
|
hitbox.startY.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
// offset 1 pixel to the down so that friction would work
|
// offset 1 pixel to the down so that friction would work
|
||||||
val yMatch = if (gravitation.y >= 0.0)
|
val yMatch = if (gravitation.y >= 0.0)
|
||||||
hitbox.endY.plus(A_PIXEL).div(TILE_SIZE).floorInt()
|
hitbox.endY.plus(A_PIXEL).div(TILE_SIZE).floorToInt()
|
||||||
else
|
else
|
||||||
hitbox.startY.minus(A_PIXEL).div(TILE_SIZE).floorInt()
|
hitbox.startY.minus(A_PIXEL).div(TILE_SIZE).floorToInt()
|
||||||
return y == yMatch && // copied from forEachFeetTileNum
|
return y == yMatch && // copied from forEachFeetTileNum
|
||||||
(x in newTilewiseHitbox.startX.toInt()..newTilewiseHitbox.endX.toInt()) // copied from forEachOccupyingTilePos
|
(x in newTilewiseHitbox.startX.toInt()..newTilewiseHitbox.endX.toInt()) // copied from forEachOccupyingTilePos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Double.modTile() = this.div(TILE_SIZE).floorInt().times(TILE_SIZE)
|
fun Double.modTile() = this.div(TILE_SIZE).floorToInt().times(TILE_SIZE)
|
||||||
fun Double.modTileDelta() = this - this.modTile()
|
fun Double.modTileDelta() = this - this.modTile()
|
||||||
|
|
||||||
|
|
||||||
@@ -776,7 +777,7 @@ open class ActorWithBody : Actor {
|
|||||||
// the job of the ccd is that the "next hitbox" would not dig into the terrain greater than the tile size,
|
// the job of the ccd is that the "next hitbox" would not dig into the terrain greater than the tile size,
|
||||||
// in which the modTileDelta returns a wrong value
|
// in which the modTileDelta returns a wrong value
|
||||||
val vectorSum = (externalV + controllerV)
|
val vectorSum = (externalV + controllerV)
|
||||||
val ccdSteps = (vectorSum.magnitude / TILE_SIZE).floorInt().coerceIn(2, 16) // adaptive
|
val ccdSteps = (vectorSum.magnitude / TILE_SIZE).floorToInt().coerceIn(2, 16) // adaptive
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -906,15 +907,15 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||||
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
val offendingTileWorldX = if (selfCollisionStatus in listOf(6, 12))
|
||||||
newHitbox.endX.div(TILE_SIZE).floor() * TILE_SIZE - PHYS_EPSILON_DIST
|
newHitbox.endX.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST
|
||||||
else
|
else
|
||||||
newHitbox.startX.div(TILE_SIZE).ceil() * TILE_SIZE
|
newHitbox.startX.div(TILE_SIZE).ceilToDouble() * TILE_SIZE
|
||||||
|
|
||||||
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
// points to the EDGE of the tile in world dimension (don't use this directly to get tilewise coord!!)
|
||||||
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
val offendingTileWorldY = if (selfCollisionStatus in listOf(3, 6))
|
||||||
newHitbox.endY.div(TILE_SIZE).floor() * TILE_SIZE - PHYS_EPSILON_DIST
|
newHitbox.endY.div(TILE_SIZE).floorToDouble() * TILE_SIZE - PHYS_EPSILON_DIST
|
||||||
else
|
else
|
||||||
newHitbox.startY.div(TILE_SIZE).ceil() * TILE_SIZE
|
newHitbox.startY.div(TILE_SIZE).ceilToDouble() * TILE_SIZE
|
||||||
|
|
||||||
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
val offendingHitboxPointX = if (selfCollisionStatus in listOf(6, 12))
|
||||||
newHitbox.endX
|
newHitbox.endX
|
||||||
@@ -1136,10 +1137,10 @@ open class ActorWithBody : Actor {
|
|||||||
val y2 = hitbox.endY - A_PIXEL
|
val y2 = hitbox.endY - A_PIXEL
|
||||||
// this commands and the commands on isWalled WILL NOT match (1 px gap on endX/Y). THIS IS INTENTIONAL!
|
// this commands and the commands on isWalled WILL NOT match (1 px gap on endX/Y). THIS IS INTENTIONAL!
|
||||||
|
|
||||||
val txStart = x1.plus(HALF_PIXEL).floorInt()
|
val txStart = x1.plus(HALF_PIXEL).floorToInt()
|
||||||
val txEnd = x2.plus(HALF_PIXEL).floorInt()
|
val txEnd = x2.plus(HALF_PIXEL).floorToInt()
|
||||||
val tyStart = y1.plus(HALF_PIXEL).floorInt()
|
val tyStart = y1.plus(HALF_PIXEL).floorToInt()
|
||||||
val tyEnd = y2.plus(HALF_PIXEL).floorInt()
|
val tyEnd = y2.plus(HALF_PIXEL).floorToInt()
|
||||||
|
|
||||||
return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, feet).first > 0
|
return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, feet).first > 0
|
||||||
}
|
}
|
||||||
@@ -1203,10 +1204,10 @@ open class ActorWithBody : Actor {
|
|||||||
}
|
}
|
||||||
else throw IllegalArgumentException()
|
else throw IllegalArgumentException()
|
||||||
|
|
||||||
val txStart = x1.plus(HALF_PIXEL).floorInt()
|
val txStart = x1.plus(HALF_PIXEL).floorToInt()
|
||||||
val txEnd = x2.plus(HALF_PIXEL).floorInt()
|
val txEnd = x2.plus(HALF_PIXEL).floorToInt()
|
||||||
val tyStart = y1.plus(HALF_PIXEL).floorInt()
|
val tyStart = y1.plus(HALF_PIXEL).floorToInt()
|
||||||
val tyEnd = y2.plus(HALF_PIXEL).floorInt()
|
val tyEnd = y2.plus(HALF_PIXEL).floorToInt()
|
||||||
|
|
||||||
return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, option == COLLIDING_BOTTOM).first == 2
|
return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, option == COLLIDING_BOTTOM).first == 2
|
||||||
}
|
}
|
||||||
@@ -1258,27 +1259,27 @@ open class ActorWithBody : Actor {
|
|||||||
y2 = hitbox.endY - A_PIXEL
|
y2 = hitbox.endY - A_PIXEL
|
||||||
}
|
}
|
||||||
else if (option == COLLIDING_ALLSIDE) {
|
else if (option == COLLIDING_ALLSIDE) {
|
||||||
return maxOf(maxOf(isWalledStairs(hitbox, COLLIDING_LEFT).first,
|
return max(max(isWalledStairs(hitbox, COLLIDING_LEFT).first,
|
||||||
isWalledStairs(hitbox, COLLIDING_RIGHT).first),
|
isWalledStairs(hitbox, COLLIDING_RIGHT).first),
|
||||||
maxOf(isWalledStairs(hitbox, COLLIDING_BOTTOM).first,
|
max(isWalledStairs(hitbox, COLLIDING_BOTTOM).first,
|
||||||
isWalledStairs(hitbox, COLLIDING_TOP).first)) to 0
|
isWalledStairs(hitbox, COLLIDING_TOP).first)) to 0
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (option == COLLIDING_LR) {
|
else if (option == COLLIDING_LR) {
|
||||||
val v1 = isWalledStairs(hitbox, COLLIDING_LEFT)
|
val v1 = isWalledStairs(hitbox, COLLIDING_LEFT)
|
||||||
val v2 = isWalledStairs(hitbox, COLLIDING_RIGHT)
|
val v2 = isWalledStairs(hitbox, COLLIDING_RIGHT)
|
||||||
return maxOf(v1.first, v2.first) to maxOf(v2.first, v2.second)
|
return max(v1.first, v2.first) to max(v2.first, v2.second)
|
||||||
}
|
}
|
||||||
else if (option == COLLIDING_UD) {
|
else if (option == COLLIDING_UD) {
|
||||||
return maxOf(isWalledStairs(hitbox, COLLIDING_BOTTOM).first,
|
return max(isWalledStairs(hitbox, COLLIDING_BOTTOM).first,
|
||||||
isWalledStairs(hitbox, COLLIDING_TOP).first) to 0
|
isWalledStairs(hitbox, COLLIDING_TOP).first) to 0
|
||||||
}
|
}
|
||||||
else throw IllegalArgumentException("$option")
|
else throw IllegalArgumentException("$option")
|
||||||
|
|
||||||
val pxStart = x1.plus(0.5f).floorInt()
|
val pxStart = x1.plus(0.5f).floorToInt()
|
||||||
val pxEnd = x2.plus(0.5f).floorInt()
|
val pxEnd = x2.plus(0.5f).floorToInt()
|
||||||
val pyStart = y1.plus(0.5f).floorInt()
|
val pyStart = y1.plus(0.5f).floorToInt()
|
||||||
val pyEnd = y2.plus(0.5f).floorInt()
|
val pyEnd = y2.plus(0.5f).floorToInt()
|
||||||
|
|
||||||
return isCollidingInternalStairs(pxStart, pyStart, pxEnd, pyEnd, gravitation.y >= 0.0 && option == COLLIDING_BOTTOM || gravitation.y < 0.0 && option == COLLIDING_TOP)
|
return isCollidingInternalStairs(pxStart, pyStart, pxEnd, pyEnd, gravitation.y >= 0.0 && option == COLLIDING_BOTTOM || gravitation.y < 0.0 && option == COLLIDING_TOP)
|
||||||
}
|
}
|
||||||
@@ -1890,10 +1891,10 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
|
|
||||||
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
val newTilewiseHitbox = Hitbox.fromTwoPoints(
|
||||||
hitbox.startX.div(TILE_SIZE).floor(),
|
hitbox.startX.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.startY.div(TILE_SIZE).floor(),
|
hitbox.startY.div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floorToDouble(),
|
||||||
true
|
true
|
||||||
) // NOT the same as intTilewiseHitbox !!
|
) // NOT the same as intTilewiseHitbox !!
|
||||||
|
|
||||||
@@ -1914,7 +1915,7 @@ open class ActorWithBody : Actor {
|
|||||||
val tiles = ArrayList<ItemID?>()
|
val tiles = ArrayList<ItemID?>()
|
||||||
|
|
||||||
// offset 1 pixel to the down so that friction would work
|
// offset 1 pixel to the down so that friction would work
|
||||||
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
|
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorToInt()
|
||||||
|
|
||||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||||
tiles.add(world!!.getTileFromTerrain(x, y))
|
tiles.add(world!!.getTileFromTerrain(x, y))
|
||||||
@@ -1930,7 +1931,7 @@ open class ActorWithBody : Actor {
|
|||||||
val tileProps = ArrayList<BlockProp?>()
|
val tileProps = ArrayList<BlockProp?>()
|
||||||
|
|
||||||
// offset 1 pixel to the down so that friction would work
|
// offset 1 pixel to the down so that friction would work
|
||||||
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
|
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorToInt()
|
||||||
|
|
||||||
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
for (x in hIntTilewiseHitbox.startX.toInt()..hIntTilewiseHitbox.endX.toInt()) {
|
||||||
tileProps.add(BlockCodex[world!!.getTileFromTerrain(x, y)])
|
tileProps.add(BlockCodex[world!!.getTileFromTerrain(x, y)])
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import net.torvald.terrarum.ItemCodex
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.controller.TerrarumController
|
import net.torvald.terrarum.controller.TerrarumController
|
||||||
import net.torvald.terrarum.floorInt
|
import net.torvald.terrarum.floorToInt
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
@@ -42,10 +42,10 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
get() = WorldCamera.y + Gdx.input.y / (terrarumIngame.screenZoom)
|
get() = WorldCamera.y + Gdx.input.y / (terrarumIngame.screenZoom)
|
||||||
/** currently pointing tile coordinate */
|
/** currently pointing tile coordinate */
|
||||||
val mouseTileX: Int
|
val mouseTileX: Int
|
||||||
get() = (mouseX / TILE_SIZE).floorInt()
|
get() = (mouseX / TILE_SIZE).floorToInt()
|
||||||
/** currently pointing tile coordinate */
|
/** currently pointing tile coordinate */
|
||||||
val mouseTileY: Int
|
val mouseTileY: Int
|
||||||
get() = (mouseY / TILE_SIZE).floorInt()
|
get() = (mouseY / TILE_SIZE).floorToInt()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.torvald.terrarum.savegame.ByteArray64
|
|||||||
import net.torvald.terrarum.utils.HashArray
|
import net.torvald.terrarum.utils.HashArray
|
||||||
import net.torvald.terrarum.utils.ZipCodedStr
|
import net.torvald.terrarum.utils.ZipCodedStr
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
typealias ItemID = String
|
typealias ItemID = String
|
||||||
|
|
||||||
@@ -388,7 +389,7 @@ fun mouseInInteractableRange(actor: ActorWithBody, action: () -> Long): Long {
|
|||||||
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
val actorPos = actor.centrePosVector
|
val actorPos = actor.centrePosVector
|
||||||
val dist = minOf(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2), actorPos.distanceSquared(mousePos3))
|
val dist = min(min(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2)), actorPos.distanceSquared(mousePos3))
|
||||||
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale // perform some error checking here
|
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale // perform some error checking here
|
||||||
if (dist <= distMax.sqr()) return action() else return -1
|
if (dist <= distMax.sqr()) return action() else return -1
|
||||||
}
|
}
|
||||||
@@ -409,13 +410,13 @@ fun mouseInInteractableRangeTools(actor: ActorWithBody, item: GameItem?, reachMu
|
|||||||
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
val actorPos = actor.centrePosVector
|
val actorPos = actor.centrePosVector
|
||||||
val dist = minOf(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2), actorPos.distanceSquared(mousePos3))
|
val dist = min(min(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2)), actorPos.distanceSquared(mousePos3))
|
||||||
|
|
||||||
val reachBonus = (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale
|
val reachBonus = (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale
|
||||||
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * reachBonus // perform some error checking here
|
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * reachBonus // perform some error checking here
|
||||||
val toolDistMax = (TILE_SIZED * reachMultiplierInTiles(item?.material?.toolReach ?: Int.MAX_VALUE)) * reachBonus
|
val toolDistMax = (TILE_SIZED * reachMultiplierInTiles(item?.material?.toolReach ?: Int.MAX_VALUE)) * reachBonus
|
||||||
|
|
||||||
if (dist <= minOf(toolDistMax, distMax).sqr()) return action() else return false
|
if (dist <= min(toolDistMax, distMax).sqr()) return action() else return false
|
||||||
}
|
}
|
||||||
//fun IntRange.pickRandom() = HQRNG().nextInt(this.last - this.first + 1) + this.first // count() on 200 million entries? Se on vitun hyvää idea
|
//fun IntRange.pickRandom() = HQRNG().nextInt(this.last - this.first + 1) + this.first // count() on 200 million entries? Se on vitun hyvää idea
|
||||||
//fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
|
//fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
|
|||||||
if (velocity.isZero ||
|
if (velocity.isZero ||
|
||||||
// simple stuck check
|
// simple stuck check
|
||||||
BlockCodex[(INGAME.world).getTileFromTerrain(
|
BlockCodex[(INGAME.world).getTileFromTerrain(
|
||||||
hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorInt(),
|
hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorToInt(),
|
||||||
hitbox.startY.div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
|
hitbox.startY.div(TerrarumAppConfiguration.TILE_SIZE).floorToInt()
|
||||||
)].isSolid ||
|
)].isSolid ||
|
||||||
BlockCodex[(INGAME.world).getTileFromTerrain(
|
BlockCodex[(INGAME.world).getTileFromTerrain(
|
||||||
hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorInt(),
|
hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorToInt(),
|
||||||
hitbox.endY.div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
|
hitbox.endY.div(TerrarumAppConfiguration.TILE_SIZE).floorToInt()
|
||||||
)].isSolid) {
|
)].isSolid) {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
|||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.inUpdateRange
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.inUpdateRange
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.*
|
import net.torvald.terrarum.modulebasegame.gameactors.*
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,10 +121,10 @@ object WorldSimulator {
|
|||||||
|
|
||||||
// kill grasses surrounded by dirts in cruciform formation
|
// kill grasses surrounded by dirts in cruciform formation
|
||||||
// NOPE this part would not work; environment-depending degrassing must be done by the "grass spread simulator"
|
// NOPE this part would not work; environment-depending degrassing must be done by the "grass spread simulator"
|
||||||
/*val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
|
/*val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorToInt()
|
||||||
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1
|
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1
|
||||||
|
|
||||||
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
|
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorToInt()
|
||||||
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1
|
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1
|
||||||
for (y in for_y_start..for_y_end) {
|
for (y in for_y_start..for_y_end) {
|
||||||
for (x in for_x_start..for_x_end) {
|
for (x in for_x_start..for_x_end) {
|
||||||
@@ -354,7 +355,7 @@ object WorldSimulator {
|
|||||||
if (flow > minFlow) {
|
if (flow > minFlow) {
|
||||||
flow *= 0.5f // leads to smoother flow
|
flow *= 0.5f // leads to smoother flow
|
||||||
}
|
}
|
||||||
flow = flow.coerceIn(0f, minOf(maxSpeed, remainingMass))
|
flow = flow.coerceIn(0f, min(maxSpeed, remainingMass))
|
||||||
|
|
||||||
fluidNewMap[y][x] -= flow
|
fluidNewMap[y][x] -= flow
|
||||||
fluidNewMap[y + 1][x] += flow
|
fluidNewMap[y + 1][x] += flow
|
||||||
@@ -404,7 +405,7 @@ object WorldSimulator {
|
|||||||
if (flow > minFlow) {
|
if (flow > minFlow) {
|
||||||
flow *= 0.5f
|
flow *= 0.5f
|
||||||
}
|
}
|
||||||
flow = flow.coerceIn(0f, minOf(maxSpeed, remainingMass))
|
flow = flow.coerceIn(0f, min(maxSpeed, remainingMass))
|
||||||
|
|
||||||
fluidNewMap[y][x] -= flow
|
fluidNewMap[y][x] -= flow
|
||||||
fluidNewMap[y - 1][x] += flow
|
fluidNewMap[y - 1][x] += flow
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.Batch
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
||||||
import net.torvald.terrarum.round
|
import net.torvald.terrarum.roundToFloat
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,8 +41,8 @@ object TinyAlphNum : BitmapFont() {
|
|||||||
colMain = batch.color.cpy()
|
colMain = batch.color.cpy()
|
||||||
colShadow = colMain.cpy().mul(0.5f, 0.5f, 0.5f, 1f)
|
colShadow = colMain.cpy().mul(0.5f, 0.5f, 0.5f, 1f)
|
||||||
|
|
||||||
val x = x.round()
|
val x = x.roundToFloat()
|
||||||
val y = y.round()
|
val y = y.roundToFloat()
|
||||||
|
|
||||||
var charsPrinted = 0
|
var charsPrinted = 0
|
||||||
text.forEachIndexed { index, c ->
|
text.forEachIndexed { index, c ->
|
||||||
@@ -56,13 +56,13 @@ object TinyAlphNum : BitmapFont() {
|
|||||||
}
|
}
|
||||||
else if (c in 0.toChar()..255.toChar()) {
|
else if (c in 0.toChar()..255.toChar()) {
|
||||||
batch.color = colShadow
|
batch.color = colShadow
|
||||||
batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W + 1, y)
|
batch.draw(fontSheet.get(c.code % 16, c.code / 16), x + charsPrinted * W + 1, y)
|
||||||
batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W, y + 1)
|
batch.draw(fontSheet.get(c.code % 16, c.code / 16), x + charsPrinted * W, y + 1)
|
||||||
batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W + 1, y + 1)
|
batch.draw(fontSheet.get(c.code % 16, c.code / 16), x + charsPrinted * W + 1, y + 1)
|
||||||
|
|
||||||
|
|
||||||
batch.color = colMain
|
batch.color = colMain
|
||||||
batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W, y)
|
batch.draw(fontSheet.get(c.code % 16, c.code / 16), x + charsPrinted * W, y)
|
||||||
|
|
||||||
charsPrinted += 1
|
charsPrinted += 1
|
||||||
}
|
}
|
||||||
@@ -80,8 +80,8 @@ object TinyAlphNum : BitmapFont() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun isColourCodeHigh(c: Char) = c.toInt() in 0b110110_1111000000..0b110110_1111111111
|
private fun isColourCodeHigh(c: Char) = c.code in 0b110110_1111000000..0b110110_1111111111
|
||||||
private fun isColourCodeLow(c: Char) = c.toInt() in 0b110111_0000000000..0b110111_1111111111
|
private fun isColourCodeLow(c: Char) = c.code in 0b110111_0000000000..0b110111_1111111111
|
||||||
|
|
||||||
private fun getColour(charHigh: Char, charLow: Char): Color { // input: 0x10ARGB, out: RGBA8888
|
private fun getColour(charHigh: Char, charLow: Char): Color { // input: 0x10ARGB, out: RGBA8888
|
||||||
val codePoint = Character.toCodePoint(charHigh, charLow)
|
val codePoint = Character.toCodePoint(charHigh, charLow)
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
|
|||||||
|
|
||||||
App.batch.inUse { val it = it as FlippingSpriteBatch
|
App.batch.inUse { val it = it as FlippingSpriteBatch
|
||||||
it.color = Color.WHITE
|
it.color = Color.WHITE
|
||||||
val previewX = (drawWidth - previewWidth).div(2f).round()
|
val previewX = (drawWidth - previewWidth).div(2f).roundToFloat()
|
||||||
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
|
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).roundToFloat()
|
||||||
Toolkit.drawBoxBorder(it, previewX.toInt() - 1, previewY.toInt() - 1, previewWidth + 2, previewHeight + 2)
|
Toolkit.drawBoxBorder(it, previewX.toInt() - 1, previewY.toInt() - 1, previewWidth + 2, previewHeight + 2)
|
||||||
it.drawFlipped(previewTexture, previewX, previewY)
|
it.drawFlipped(previewTexture, previewX, previewY)
|
||||||
val text = messages.getHeadElem() ?: ""
|
val text = messages.getHeadElem() ?: ""
|
||||||
App.fontGame.draw(it,
|
App.fontGame.draw(it,
|
||||||
text,
|
text,
|
||||||
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
|
(drawWidth - App.fontGame.getWidth(text)).div(2f).roundToFloat(),
|
||||||
previewY + previewHeight + 98 - App.fontGame.lineHeight
|
previewY + previewHeight + 98 - App.fontGame.lineHeight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -680,7 +680,7 @@ object IngameRenderer : Disposable {
|
|||||||
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
|
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
|
||||||
*/
|
*/
|
||||||
private fun setCameraPosition(newX: Float, newY: Float) {
|
private fun setCameraPosition(newX: Float, newY: Float) {
|
||||||
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
|
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import org.khelekore.prtree.PRTree
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
companion object {
|
companion object {
|
||||||
/** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */
|
/** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */
|
||||||
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||||
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
|
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
@@ -111,20 +112,20 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
val ACTOR_UPDATE_RANGE = 4096
|
val ACTOR_UPDATE_RANGE = 4096
|
||||||
|
|
||||||
fun distToActorSqr(world: GameWorld, a: ActorWithBody, p: ActorWithBody) =
|
fun distToActorSqr(world: GameWorld, a: ActorWithBody, p: ActorWithBody) =
|
||||||
minOf(// take min of normal position and wrapped (x < 0) position
|
min(// take min of normal position and wrapped (x < 0) position
|
||||||
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() +
|
min((a.hitbox.centeredX - p.hitbox.centeredX).sqr() +
|
||||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
||||||
((a.hitbox.centeredX + world.width * TILE_SIZE) - p.hitbox.centeredX).sqr() +
|
((a.hitbox.centeredX + world.width * TILE_SIZE) - p.hitbox.centeredX).sqr() +
|
||||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()),
|
||||||
((a.hitbox.centeredX - world.width * TILE_SIZE) - p.hitbox.centeredX).sqr() +
|
((a.hitbox.centeredX - world.width * TILE_SIZE) - p.hitbox.centeredX).sqr() +
|
||||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
||||||
)
|
)
|
||||||
fun distToCameraSqr(world: GameWorld, a: ActorWithBody) =
|
fun distToCameraSqr(world: GameWorld, a: ActorWithBody) =
|
||||||
minOf(
|
min(
|
||||||
(a.hitbox.centeredX - WorldCamera.xCentre).sqr() +
|
min((a.hitbox.centeredX - WorldCamera.xCentre).sqr() +
|
||||||
(a.hitbox.centeredY - WorldCamera.yCentre).sqr(),
|
(a.hitbox.centeredY - WorldCamera.yCentre).sqr(),
|
||||||
((a.hitbox.centeredX + world.width * TILE_SIZE) - WorldCamera.xCentre).sqr() +
|
((a.hitbox.centeredX + world.width * TILE_SIZE) - WorldCamera.xCentre).sqr() +
|
||||||
(a.hitbox.centeredY - WorldCamera.yCentre).sqr(),
|
(a.hitbox.centeredY - WorldCamera.yCentre).sqr()),
|
||||||
((a.hitbox.centeredX - world.width * TILE_SIZE) - WorldCamera.xCentre).sqr() +
|
((a.hitbox.centeredX - world.width * TILE_SIZE) - WorldCamera.xCentre).sqr() +
|
||||||
(a.hitbox.centeredY - WorldCamera.yCentre).sqr()
|
(a.hitbox.centeredY - WorldCamera.yCentre).sqr()
|
||||||
)
|
)
|
||||||
@@ -1035,10 +1036,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
} }
|
} }
|
||||||
|
|
||||||
private fun fillUpWiresBuffer() {
|
private fun fillUpWiresBuffer() {
|
||||||
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt() - LIGHTMAP_OVERRENDER
|
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorToInt() - LIGHTMAP_OVERRENDER
|
||||||
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical + 2*LIGHTMAP_OVERRENDER
|
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical + 2*LIGHTMAP_OVERRENDER
|
||||||
|
|
||||||
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt() - LIGHTMAP_OVERRENDER
|
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorToInt() - LIGHTMAP_OVERRENDER
|
||||||
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal + 2*LIGHTMAP_OVERRENDER
|
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal + 2*LIGHTMAP_OVERRENDER
|
||||||
|
|
||||||
var wiringCounter = 0
|
var wiringCounter = 0
|
||||||
@@ -1421,7 +1422,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// }
|
// }
|
||||||
// else, punch a block
|
// else, punch a block
|
||||||
else if (canAttackOrDig) {
|
else if (canAttackOrDig) {
|
||||||
val punchBlockSize = punchSize.div(TILE_SIZED).floorInt()
|
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
|
||||||
if (punchBlockSize > 0) {
|
if (punchBlockSize > 0) {
|
||||||
PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize)
|
PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
val ww = TILE_SIZEF * demoWorld.width
|
val ww = TILE_SIZEF * demoWorld.width
|
||||||
val x = px % ww
|
val x = px % ww
|
||||||
|
|
||||||
val indexThis = ((x / ww * cameraNodes.size).floorInt())
|
val indexThis = ((x / ww * cameraNodes.size).floorToInt())
|
||||||
val xwstart: Double = indexThis.toDouble() / cameraNodes.size * ww
|
val xwstart: Double = indexThis.toDouble() / cameraNodes.size * ww
|
||||||
val xwend: Double = ((indexThis + 1).toDouble() / cameraNodes.size) * ww
|
val xwend: Double = ((indexThis + 1).toDouble() / cameraNodes.size) * ww
|
||||||
val xw: Double = xwend - xwstart
|
val xw: Double = xwend - xwstart
|
||||||
@@ -182,7 +182,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// construct camera nodes
|
// construct camera nodes
|
||||||
val nodeCount = demoWorld.width / cameraNodeWidth
|
val nodeCount = demoWorld.width / cameraNodeWidth
|
||||||
cameraNodes = kotlin.FloatArray(nodeCount) {
|
cameraNodes = kotlin.FloatArray(nodeCount) {
|
||||||
val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorInt()
|
val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorToInt()
|
||||||
var travelDownCounter = 0
|
var travelDownCounter = 0
|
||||||
while (travelDownCounter < demoWorld.height &&
|
while (travelDownCounter < demoWorld.height &&
|
||||||
!BlockCodex[demoWorld.getTileFromTerrain(tileXPos, travelDownCounter)].isSolid
|
!BlockCodex[demoWorld.getTileFromTerrain(tileXPos, travelDownCounter)].isSolid
|
||||||
|
|||||||
@@ -70,14 +70,14 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
|
|||||||
|
|
||||||
App.batch.inUse { val it = it as FlippingSpriteBatch
|
App.batch.inUse { val it = it as FlippingSpriteBatch
|
||||||
it.color = Color.WHITE
|
it.color = Color.WHITE
|
||||||
val previewX = (drawWidth - previewWidth).div(2f).round()
|
val previewX = (drawWidth - previewWidth).div(2f).roundToFloat()
|
||||||
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
|
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).roundToFloat()
|
||||||
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
|
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
|
||||||
it.drawFlipped(previewTexture, previewX, previewY)
|
it.drawFlipped(previewTexture, previewX, previewY)
|
||||||
val text = messages.getHeadElem() ?: ""
|
val text = messages.getHeadElem() ?: ""
|
||||||
App.fontGame.draw(it,
|
App.fontGame.draw(it,
|
||||||
text,
|
text,
|
||||||
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
|
(drawWidth - App.fontGame.getWidth(text)).div(2f).roundToFloat(),
|
||||||
previewY + previewHeight + 98 - App.fontGame.lineHeight
|
previewY + previewHeight + 98 - App.fontGame.lineHeight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
|||||||
|
|
||||||
if (hasPlatformOnTheFeet) {
|
if (hasPlatformOnTheFeet) {
|
||||||
// equation copied verbatim from the ActorWthBody.forEachFeetTile
|
// equation copied verbatim from the ActorWthBody.forEachFeetTile
|
||||||
val y = hitbox.endY.plus(1.0).div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
|
val y = hitbox.endY.plus(1.0).div(TerrarumAppConfiguration.TILE_SIZE).floorToInt()
|
||||||
var wxStart = hIntTilewiseHitbox.startX.toInt()
|
var wxStart = hIntTilewiseHitbox.startX.toInt()
|
||||||
var wxEnd = wxStart
|
var wxEnd = wxStart
|
||||||
// scan to the left
|
// scan to the left
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ internal class FixtureTapestry : FixtureBase {
|
|||||||
Pixmap(ModMgr.getGdxFilesFromEveryMod("tapestries/common/canvas.tga").last().second)
|
Pixmap(ModMgr.getGdxFilesFromEveryMod("tapestries/common/canvas.tga").last().second)
|
||||||
} as Pixmap
|
} as Pixmap
|
||||||
|
|
||||||
tilewiseHitboxWidth = pixmap.width.div(TILE_SIZEF).ceilInt()
|
tilewiseHitboxWidth = pixmap.width.div(TILE_SIZEF).ceilToInt()
|
||||||
tilewiseHitboxHeight = pixmap.height.div(TILE_SIZEF).ceilInt()
|
tilewiseHitboxHeight = pixmap.height.div(TILE_SIZEF).ceilToInt()
|
||||||
|
|
||||||
// blend canvas texture
|
// blend canvas texture
|
||||||
for (y in 0 until pixmap.height) { for (x in 0 until pixmap.width) {
|
for (y in 0 until pixmap.height) { for (x in 0 until pixmap.width) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors.physicssolver
|
package net.torvald.terrarum.modulebasegame.gameactors.physicssolver
|
||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.abs
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
|
import net.torvald.terrarum.sqr
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,9 +204,6 @@ object CollisionSolver {
|
|||||||
return (t_ax.sqr() + t_ay.sqr()) < actor_dist_t_sqr
|
return (t_ax.sqr() + t_ay.sqr()) < actor_dist_t_sqr
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Double.abs() = if (this < 0) -this else this
|
|
||||||
fun Double.sqr() = this * this
|
|
||||||
|
|
||||||
data class CollisionMarkings(
|
data class CollisionMarkings(
|
||||||
val pos: Double,
|
val pos: Double,
|
||||||
val kind: Int,
|
val kind: Int,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.torvald.random.HQRNG
|
|||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +22,7 @@ object WeaponMeleeCore {
|
|||||||
private fun getAttackMomentum(weapon: WeaponMeleeBase, actor: ActorHumanoid) =
|
private fun getAttackMomentum(weapon: WeaponMeleeBase, actor: ActorHumanoid) =
|
||||||
weapon.mass * weapon.material.density * weapon.velocityMod * actor.scale.pow(SQRT2) // TODO multiply racial strength from RaceCodex
|
weapon.mass * weapon.material.density * weapon.velocityMod * actor.scale.pow(SQRT2) // TODO multiply racial strength from RaceCodex
|
||||||
fun getAttackPower(weapon: WeaponMeleeBase, actor: ActorHumanoid, actee: ActorHumanoid) =
|
fun getAttackPower(weapon: WeaponMeleeBase, actor: ActorHumanoid, actee: ActorHumanoid) =
|
||||||
getAttackMomentum(weapon, actor) * randomise() * maxOf(1.0, (actee.hitbox.endY - actor.hitbox.startY) / actee.hitbox.height)
|
getAttackMomentum(weapon, actor) * randomise() * max(1.0, (actee.hitbox.endY - actor.hitbox.startY) / actee.hitbox.height)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.magiccontroller
|
|||||||
|
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Data Type" describing magical force
|
* "Data Type" describing magical force
|
||||||
@@ -33,13 +34,13 @@ class TheMagicLanguage(vm: TheMagicMachine) {
|
|||||||
if (power >= 0) {
|
if (power >= 0) {
|
||||||
// pour out positive power without inversion; result is positive power
|
// pour out positive power without inversion; result is positive power
|
||||||
if (value >= 0) {
|
if (value >= 0) {
|
||||||
val value = minOf(power, value)
|
val value = min(power, value)
|
||||||
other.pourIn(value)
|
other.pourIn(value)
|
||||||
power -= value
|
power -= value
|
||||||
}
|
}
|
||||||
// pour out positive power with inversion; result is negative power
|
// pour out positive power with inversion; result is negative power
|
||||||
else {
|
else {
|
||||||
val value = minOf(-power, value)
|
val value = min(-power, value)
|
||||||
other.pourIn(value)
|
other.pourIn(value)
|
||||||
power += value
|
power += value
|
||||||
}
|
}
|
||||||
@@ -47,12 +48,12 @@ class TheMagicLanguage(vm: TheMagicMachine) {
|
|||||||
else {
|
else {
|
||||||
// pour out negative power without inversion; result is negative power
|
// pour out negative power without inversion; result is negative power
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
val value = minOf(power, value)
|
val value = min(power, value)
|
||||||
other.pourIn(-value)
|
other.pourIn(-value)
|
||||||
}
|
}
|
||||||
// pour out negative power with inversion; result is positive power
|
// pour out negative power with inversion; result is positive power
|
||||||
else {
|
else {
|
||||||
val value = minOf(-power, value)
|
val value = min(-power, value)
|
||||||
other.pourIn(-value)
|
other.pourIn(-value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.Second
|
|||||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
import net.torvald.terrarum.blendNormalStraightAlpha
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-01-23.
|
* Created by minjaesong on 2016-01-23.
|
||||||
@@ -56,7 +57,7 @@ class Notification : UICanvas() {
|
|||||||
App.fontGame.getWidth(message[0])
|
App.fontGame.getWidth(message[0])
|
||||||
else
|
else
|
||||||
message.map { App.fontGame.getWidth(it) }.sorted().last()
|
message.map { App.fontGame.getWidth(it) }.sorted().last()
|
||||||
val displayedTextWidth = maxOf(240, realTextWidth)
|
val displayedTextWidth = max(240, realTextWidth)
|
||||||
|
|
||||||
// force the UI to the centre of the screen
|
// force the UI to the centre of the screen
|
||||||
this.posX = (App.scr.width - displayedTextWidth) / 2
|
this.posX = (App.scr.width - displayedTextWidth) / 2
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import net.torvald.terrarum.ui.UIItemSpinner
|
|||||||
import net.torvald.terrarum.ui.UIItemTextButton
|
import net.torvald.terrarum.ui.UIItemTextButton
|
||||||
import net.torvald.unicode.getKeycapPC
|
import net.torvald.unicode.getKeycapPC
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This UI has inventory, but it's just there to display all craftable items and should not be serialised.
|
* This UI has inventory, but it's just there to display all craftable items and should not be serialised.
|
||||||
@@ -498,7 +500,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
|||||||
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||||
1f
|
1f
|
||||||
else // make sure 1px is always be seen
|
else // make sure 1px is always be seen
|
||||||
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||||
UIInventoryFull.controlHelpHeight - 6f
|
UIInventoryFull.controlHelpHeight - 6f
|
||||||
)
|
)
|
||||||
// debug text
|
// debug text
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.ceilInt
|
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
|
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import net.torvald.unicode.TIMES
|
import net.torvald.unicode.TIMES
|
||||||
@@ -214,7 +212,7 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
||||||
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
|
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
|
||||||
|
|
||||||
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilInt()}$TIMES${App.scr.windowH}"
|
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilToInt()}$TIMES${App.scr.windowH}"
|
||||||
|
|
||||||
App.fontGame.draw(batch, overlayResTxt,
|
App.fontGame.draw(batch, overlayResTxt,
|
||||||
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),
|
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
||||||
1f
|
1f
|
||||||
else // make sure 1px is always be seen
|
else // make sure 1px is always be seen
|
||||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
|
min(weightBarWidth, max(1f, weightBarWidth * encumbrancePerc)),
|
||||||
controlHelpHeight - 5f
|
controlHelpHeight - 5f
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -347,7 +347,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
itemPageCount = maxOf(1, 1 + (inventorySortList.size.minus(1) / items.size))
|
itemPageCount = max(1, 1 + (inventorySortList.size.minus(1) / items.size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.
|
|||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
internal class UIInventoryCells(
|
internal class UIInventoryCells(
|
||||||
val full: UIInventoryFull
|
val full: UIInventoryFull
|
||||||
@@ -125,7 +127,7 @@ internal class UIInventoryCells(
|
|||||||
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||||
1f
|
1f
|
||||||
else // make sure 1px is always be seen
|
else // make sure 1px is always be seen
|
||||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
|
min(weightBarWidth, max(1f, weightBarWidth * encumbrancePerc)),
|
||||||
controlHelpHeight - 6f
|
controlHelpHeight - 6f
|
||||||
)
|
)
|
||||||
// debug text
|
// debug text
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
|
||||||
minimapZoom = 1f
|
minimapZoom = 1f
|
||||||
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.round()?.toFloat() ?: (INGAME.world.width / 2f)
|
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.roundToInt()?.toFloat() ?: (INGAME.world.width / 2f)
|
||||||
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.round()?.toFloat() ?: (INGAME.world.height / 2f)
|
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.roundToInt()?.toFloat() ?: (INGAME.world.height / 2f)
|
||||||
dragStatus = 1
|
dragStatus = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,8 +185,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
val worldPos = it.hitbox
|
val worldPos = it.hitbox
|
||||||
val cw = t.regionWidth * sf
|
val cw = t.regionWidth * sf
|
||||||
val ch = t.regionHeight * sf
|
val ch = t.regionHeight * sf
|
||||||
val cx = worldPos.centeredX.div(TILE_SIZEF).round().toFloat()
|
val cx = worldPos.centeredX.div(TILE_SIZEF).roundToInt().toFloat()
|
||||||
val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).round().toFloat()
|
val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).roundToInt().toFloat()
|
||||||
val dx = cx - oldPanX
|
val dx = cx - oldPanX
|
||||||
val dy = cy - oldPanY
|
val dy = cy - oldPanY
|
||||||
|
|
||||||
@@ -255,8 +255,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
|||||||
override fun doClosing(delta: Float) {}
|
override fun doClosing(delta: Float) {}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.round()?.toFloat() ?: (INGAME.world.width / 2f)
|
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.roundToInt()?.toFloat() ?: (INGAME.world.width / 2f)
|
||||||
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.round()?.toFloat() ?: (INGAME.world.height / 2f)
|
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.roundToInt()?.toFloat() ?: (INGAME.world.height / 2f)
|
||||||
|
|
||||||
minimapRerenderInterval = 0.25f
|
minimapRerenderInterval = 0.25f
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import net.torvald.terrarum.App.printdbg
|
|||||||
import net.torvald.terrarum.CraftingRecipeCodex
|
import net.torvald.terrarum.CraftingRecipeCodex
|
||||||
import net.torvald.terrarum.ItemCodex
|
import net.torvald.terrarum.ItemCodex
|
||||||
import net.torvald.terrarum.UIItemInventoryCatBar
|
import net.torvald.terrarum.UIItemInventoryCatBar
|
||||||
import net.torvald.terrarum.ceilInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.gameitems.GameItem
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
import net.torvald.terrarum.itemproperties.CraftingCodex
|
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class UIItemCraftingCandidateGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilToInt()
|
||||||
|
|
||||||
rebuildList = false
|
rebuildList = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
|||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UIItem
|
import net.torvald.terrarum.ui.UIItem
|
||||||
import net.torvald.terrarum.ui.UIItemImageButton
|
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
@@ -443,7 +441,7 @@ open class UIItemInventoryItemGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilToInt()
|
||||||
|
|
||||||
|
|
||||||
// ¤ 42g
|
// ¤ 42g
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||||
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
|
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||||
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
|
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.ceilInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
@@ -225,7 +225,7 @@ class UIPerformanceControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
||||||
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
|
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
|
||||||
|
|
||||||
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilInt()}$TIMES${App.scr.windowH}"
|
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilToInt()}$TIMES${App.scr.windowH}"
|
||||||
|
|
||||||
App.fontGame.draw(batch, overlayResTxt,
|
App.fontGame.draw(batch, overlayResTxt,
|
||||||
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),
|
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getWidth
|
|||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.unicode.getKeycapPC
|
import net.torvald.unicode.getKeycapPC
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2019-07-08.
|
* Created by minjaesong on 2019-07-08.
|
||||||
@@ -219,7 +221,7 @@ internal class UIStorageChest : UICanvas(
|
|||||||
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||||
1f
|
1f
|
||||||
else // make sure 1px is always be seen
|
else // make sure 1px is always be seen
|
||||||
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||||
UIInventoryFull.controlHelpHeight - 6f
|
UIInventoryFull.controlHelpHeight - 6f
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.ui.Toolkit
|
|||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
|
class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
private val localeSecondHalf = localeList.subList(ceil(localeList.size / 2f).toInt(), localeList.size)
|
private val localeSecondHalf = localeList.subList(ceil(localeList.size / 2f).toInt(), localeList.size)
|
||||||
|
|
||||||
override var width = 480
|
override var width = 480
|
||||||
override var height = maxOf(localeFirstHalf.size, localeSecondHalf.size) * textButtonLineHeight
|
override var height = max(localeFirstHalf.size, localeSecondHalf.size) * textButtonLineHeight
|
||||||
|
|
||||||
|
|
||||||
private val textArea1 = UIItemTextButtonList(this,
|
private val textArea1 = UIItemTextButtonList(this,
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||||
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
|
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
|
||||||
camera.update()
|
camera.update()
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class UIVitalMetre(
|
|||||||
g.lineWidth = 2f
|
g.lineWidth = 2f
|
||||||
|
|
||||||
|
|
||||||
val ratio = minOf(1f, vitalGetterVal()!! / vitalGetterMax()!!)
|
val ratio = min(1f, vitalGetterVal()!! / vitalGetterMax()!!)
|
||||||
|
|
||||||
// background
|
// background
|
||||||
g.color = backColor
|
g.color = backColor
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
|||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.unicode.getKeycapPC
|
import net.torvald.unicode.getKeycapPC
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||||
|
|
||||||
@@ -211,7 +213,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
|||||||
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||||
1f
|
1f
|
||||||
else // make sure 1px is always be seen
|
else // make sure 1px is always be seen
|
||||||
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||||
UIInventoryFull.controlHelpHeight - 6f
|
UIInventoryFull.controlHelpHeight - 6f
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
batch.color = barBack
|
batch.color = barBack
|
||||||
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, memoryGaugeWidth, buttonHeight)
|
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, memoryGaugeWidth, buttonHeight)
|
||||||
batch.color = barCol
|
batch.color = barCol
|
||||||
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (chunksUsed / chunksMax.toFloat())).ceilInt(), buttonHeight)
|
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (chunksUsed / chunksMax.toFloat())).ceilToInt(), buttonHeight)
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
if (selected?.worldInfo != null) {
|
if (selected?.worldInfo != null) {
|
||||||
@@ -396,7 +396,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
App.fontGame.draw(batch, str, textXpos + 6f, y + thumbh + 3+10 + textualListHeight * index - 2f)
|
App.fontGame.draw(batch, str, textXpos + 6f, y + thumbh + 3+10 + textualListHeight * index - 2f)
|
||||||
}
|
}
|
||||||
// size indicator on the memory gauge
|
// size indicator on the memory gauge
|
||||||
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (selected?.worldInfo!!.dimensionInChunks / chunksMax.toFloat())).ceilInt(), buttonHeight)
|
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (selected?.worldInfo!!.dimensionInChunks / chunksMax.toFloat())).ceilToInt(), buttonHeight)
|
||||||
|
|
||||||
// thumbnail
|
// thumbnail
|
||||||
selected?.worldInfo?.screenshot?.let {
|
selected?.worldInfo?.screenshot?.let {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
|||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,7 +20,7 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
||||||
|
|
||||||
private val genSlices = maxOf(threadExecutor.threadCount, world.width / 8)
|
private val genSlices = max(threadExecutor.threadCount, world.width / 8)
|
||||||
|
|
||||||
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||||
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.concurrent.sliceEvenly
|
|||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,7 +20,7 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
||||||
|
|
||||||
private val genSlices = maxOf(threadExecutor.threadCount, world.width / 8)
|
private val genSlices = max(threadExecutor.threadCount, world.width / 8)
|
||||||
|
|
||||||
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||||
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import java.io.*
|
|||||||
import java.nio.channels.ClosedChannelException
|
import java.nio.channels.ClosedChannelException
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
import java.nio.charset.UnsupportedCharsetException
|
import java.nio.charset.UnsupportedCharsetException
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +67,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
__data[index.toBankNumber()][index.toBankOffset()] = value
|
__data[index.toBankNumber()][index.toBankOffset()] = value
|
||||||
size = maxOf(size, index + 1)
|
size = max(size, index + 1)
|
||||||
}
|
}
|
||||||
catch (e: IndexOutOfBoundsException) {
|
catch (e: IndexOutOfBoundsException) {
|
||||||
val msg = "index: $index -> bank ${index.toBankNumber()} offset ${index.toBankOffset()}\n" +
|
val msg = "index: $index -> bank ${index.toBankNumber()} offset ${index.toBankOffset()}\n" +
|
||||||
@@ -115,7 +117,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
|||||||
// 3. Copy over the remaining bytes
|
// 3. Copy over the remaining bytes
|
||||||
|
|
||||||
// 1.
|
// 1.
|
||||||
var actualBytesToCopy = minOf(remainingBytesToCopy, remainingInHeadBank) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
var actualBytesToCopy = min(remainingBytesToCopy, remainingInHeadBank) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||||
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], bankOffset, actualBytesToCopy)
|
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], bankOffset, actualBytesToCopy)
|
||||||
remainingBytesToCopy -= actualBytesToCopy
|
remainingBytesToCopy -= actualBytesToCopy
|
||||||
srcCursor += actualBytesToCopy
|
srcCursor += actualBytesToCopy
|
||||||
@@ -124,7 +126,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
|||||||
// 2. and 3.
|
// 2. and 3.
|
||||||
while (remainingBytesToCopy > 0) {
|
while (remainingBytesToCopy > 0) {
|
||||||
currentBankNumber += 1
|
currentBankNumber += 1
|
||||||
actualBytesToCopy = minOf(remainingBytesToCopy, BANK_SIZE) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
actualBytesToCopy = min(remainingBytesToCopy, BANK_SIZE) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||||
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], 0, actualBytesToCopy)
|
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], 0, actualBytesToCopy)
|
||||||
remainingBytesToCopy -= actualBytesToCopy
|
remainingBytesToCopy -= actualBytesToCopy
|
||||||
srcCursor += actualBytesToCopy
|
srcCursor += actualBytesToCopy
|
||||||
@@ -535,7 +537,7 @@ open class ByteArray64Reader(val ba: ByteArray64, val charset: Charset) : Reader
|
|||||||
surrogateLeftover = ' '
|
surrogateLeftover = ' '
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val bbuf = (0 until minOf(4L, remaining)).map { ba[readCursor + it] }
|
val bbuf = (0 until min(4L, remaining)).map { ba[readCursor + it] }
|
||||||
val charLen = utf8GetCharLen(bbuf[0])
|
val charLen = utf8GetCharLen(bbuf[0])
|
||||||
val codePoint = utf8decode(bbuf.subList(0, charLen))
|
val codePoint = utf8decode(bbuf.subList(0, charLen))
|
||||||
|
|
||||||
@@ -573,7 +575,7 @@ open class ByteArray64Reader(val ba: ByteArray64, val charset: Charset) : Reader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Charset.forName("CP437") -> {
|
Charset.forName("CP437") -> {
|
||||||
for (i in 0 until minOf(len.toLong(), remaining)) {
|
for (i in 0 until min(len.toLong(), remaining)) {
|
||||||
cbuf[(off + i).toInt()] = ba[readCursor].toChar()
|
cbuf[(off + i).toInt()] = ba[readCursor].toChar()
|
||||||
readCursor += 1
|
readCursor += 1
|
||||||
readCount += 1
|
readCount += 1
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.zip.GZIPInputStream
|
|||||||
import java.util.zip.GZIPOutputStream
|
import java.util.zip.GZIPOutputStream
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import kotlin.experimental.and
|
import kotlin.experimental.and
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily disabling on-disk compression; it somehow does not work, compress the files by yourself!
|
* Temporarily disabling on-disk compression; it somehow does not work, compress the files by yourself!
|
||||||
@@ -667,7 +668,7 @@ fun magicMismatch(magic: ByteArray, array: ByteArray): Boolean {
|
|||||||
fun String.toEntryName(length: Int, charset: Charset): ByteArray {
|
fun String.toEntryName(length: Int, charset: Charset): ByteArray {
|
||||||
val buf = ByteArray(length)
|
val buf = ByteArray(length)
|
||||||
val stringByteArray = this.toByteArray(charset)
|
val stringByteArray = this.toByteArray(charset)
|
||||||
System.arraycopy(stringByteArray, 0, buf, 0, minOf(length, stringByteArray.size))
|
System.arraycopy(stringByteArray, 0, buf, 0, min(length, stringByteArray.size))
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
fun ByteArray.toCanonicalString(charset: Charset): String {
|
fun ByteArray.toCanonicalString(charset: Charset): String {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.logging.Level
|
|||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
import javax.swing.table.AbstractTableModel
|
import javax.swing.table.AbstractTableModel
|
||||||
import javax.swing.text.DefaultCaret
|
import javax.swing.text.DefaultCaret
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,7 +620,7 @@ EntryID: ${file.entryID}
|
|||||||
ParentID: ${file.parentEntryID}""" + if (file.contents is EntryFile) """
|
ParentID: ${file.parentEntryID}""" + if (file.contents is EntryFile) """
|
||||||
|
|
||||||
Contents:
|
Contents:
|
||||||
${String(file.contents.bytes.sliceArray64(0L..minOf(PREVIEW_MAX_BYTES, file.contents.bytes.size) - 1).toByteArray(), sysCharset)}""" else ""
|
${String(file.contents.bytes.sliceArray64(0L..min(PREVIEW_MAX_BYTES, file.contents.bytes.size) - 1).toByteArray(), sysCharset)}""" else ""
|
||||||
}
|
}
|
||||||
private fun setWindowTitleWithName(name: String) {
|
private fun setWindowTitleWithName(name: String) {
|
||||||
this.title = "$appName - $name"
|
this.title = "$appName - $name"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.InputStream
|
|||||||
import java.io.Reader
|
import java.io.Reader
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
internal data class Joint(val name: String, val position: ADPropertyObject.Vector2i) {
|
internal data class Joint(val name: String, val position: ADPropertyObject.Vector2i) {
|
||||||
override fun toString() = "$name $position"
|
override fun toString() = "$name $position"
|
||||||
@@ -144,13 +145,13 @@ class ADProperties {
|
|||||||
// if animFrames does not have our entry, add it.
|
// if animFrames does not have our entry, add it.
|
||||||
// otherwise, max() against the existing value
|
// otherwise, max() against the existing value
|
||||||
if (animFrames.containsKey(animName)) {
|
if (animFrames.containsKey(animName)) {
|
||||||
animFrames[animName] = maxOf(animFrames[animName]!!, frameNumber)
|
animFrames[animName] = max(animFrames[animName]!!, frameNumber)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
animFrames[animName] = frameNumber
|
animFrames[animName] = frameNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
maxColFinder = maxOf(maxColFinder, frameNumber)
|
maxColFinder = max(maxColFinder, frameNumber)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// populate skeletons and animations
|
// populate skeletons and animations
|
||||||
@@ -176,7 +177,7 @@ class ADProperties {
|
|||||||
Skeleton(skeletonName, skeletonDef.toJoints())
|
Skeleton(skeletonName, skeletonDef.toJoints())
|
||||||
)
|
)
|
||||||
|
|
||||||
maxRowFinder = maxOf(maxRowFinder, animations[s]!!.row)
|
maxRowFinder = max(maxRowFinder, animations[s]!!.row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
|||||||
import net.torvald.terrarum.worlddrawer.toRGBA
|
import net.torvald.terrarum.worlddrawer.toRGBA
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
testTex.blending = Pixmap.Blending.None
|
testTex.blending = Pixmap.Blending.None
|
||||||
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
|
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
genSlices = maxOf(threadExecutor.threadCount, testTex.width / 8)
|
genSlices = max(threadExecutor.threadCount, testTex.width / 8)
|
||||||
|
|
||||||
println("Init done")
|
println("Init done")
|
||||||
}
|
}
|
||||||
@@ -342,7 +343,7 @@ internal object AccidentalCave {
|
|||||||
fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) {
|
fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) {
|
||||||
// simple one-source draw
|
// simple one-source draw
|
||||||
/*val c = noiseValue[0].toFloat()
|
/*val c = noiseValue[0].toFloat()
|
||||||
val selector = c.minus(0.0001).floorInt() fmod notationColours.size
|
val selector = c.minus(0.0001).floorToInt() fmod notationColours.size
|
||||||
val selecteeColour = Color(c - selector, c - selector, c - selector, 1f)
|
val selecteeColour = Color(c - selector, c - selector, c - selector, 1f)
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
outTex.setColor(-c, 0f, 0f, 1f)
|
outTex.setColor(-c, 0f, 0f, 1f)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
|||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.sign
|
import kotlin.math.sign
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +118,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
val windowWidth = Toolkit.drawWidth
|
val windowWidth = Toolkit.drawWidth
|
||||||
val player = ingame?.actorNowPlaying
|
val player = ingame?.actorNowPlaying
|
||||||
val hitbox = player?.hitbox
|
val hitbox = player?.hitbox
|
||||||
val updateCount = maxOf(1L, (App.debugTimers["Ingame.UpdateCounter"] ?: 1L) as Long)
|
val updateCount = max(1L, (App.debugTimers["Ingame.UpdateCounter"] ?: 1L))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top Left
|
* Top Left
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.App
|
|||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
@@ -346,7 +347,7 @@ abstract class UICanvas(
|
|||||||
const val OPENCLOSE_GENERIC = 0.0666f
|
const val OPENCLOSE_GENERIC = 0.0666f
|
||||||
|
|
||||||
fun doOpeningFade(ui: UICanvas, openCloseTime: Second) {
|
fun doOpeningFade(ui: UICanvas, openCloseTime: Second) {
|
||||||
ui.handler.opacity = maxOf(0f, ui.handler.openCloseCounter - 0.02f) / openCloseTime // fade start 1/50 sec late, it's intended
|
ui.handler.opacity = max(0f, ui.handler.openCloseCounter - 0.02f) / openCloseTime // fade start 1/50 sec late, it's intended
|
||||||
}
|
}
|
||||||
fun doClosingFade(ui: UICanvas, openCloseTime: Second) {
|
fun doClosingFade(ui: UICanvas, openCloseTime: Second) {
|
||||||
ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime
|
ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.ceilInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal properties, namely initialValue, min, max, step; have the type of [Double] regardless of their input type.
|
* Internal properties, namely initialValue, min, max, step; have the type of [Double] regardless of their input type.
|
||||||
@@ -44,7 +44,7 @@ class UIItemSpinner(
|
|||||||
var selectionChangeListener: (Number) -> Unit = {}
|
var selectionChangeListener: (Number) -> Unit = {}
|
||||||
|
|
||||||
// to alleviate floating point errors adding up as the spinner is being used
|
// to alleviate floating point errors adding up as the spinner is being used
|
||||||
private val values = DoubleArray(1 + ((max.toDouble() - min.toDouble()).div(step.toDouble())).ceilInt()) {
|
private val values = DoubleArray(1 + ((max.toDouble() - min.toDouble()).div(step.toDouble())).ceilToInt()) {
|
||||||
// printdbg(this, "$min..$max step $step; index [$it] = ${min.toDouble() + (step.toDouble() * it)}")
|
// printdbg(this, "$min..$max step $step; index [$it] = ${min.toDouble() + (step.toDouble() * it)}")
|
||||||
min.toDouble() + (step.toDouble() * it)
|
min.toDouble() + (step.toDouble() * it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package net.torvald.terrarum.ui
|
|||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.floor
|
import net.torvald.terrarum.roundToFloat
|
||||||
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class UIItemTextArea(
|
class UIItemTextArea(
|
||||||
parentUI: UICanvas,
|
parentUI: UICanvas,
|
||||||
@@ -33,14 +34,14 @@ class UIItemTextArea(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
|
for (i in scrollPos until min(lineCount + scrollPos, entireText.size)) {
|
||||||
val yPtr = i - scrollPos
|
val yPtr = i - scrollPos
|
||||||
|
|
||||||
val textWidth = App.fontGame.getWidth(entireText[i])
|
val textWidth = App.fontGame.getWidth(entireText[i])
|
||||||
|
|
||||||
when (align) {
|
when (align) {
|
||||||
Alignment.LEFT -> App.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
Alignment.LEFT -> App.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||||
Alignment.CENTRE -> App.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
Alignment.CENTRE -> App.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).roundToFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||||
Alignment.RIGHT -> App.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
Alignment.RIGHT -> App.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (App.fontGame.lineHeight + lineGap))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.torvald.terrarum.gamecontroller.*
|
|||||||
import net.torvald.terrarum.utils.Clipboard
|
import net.torvald.terrarum.utils.Clipboard
|
||||||
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
||||||
import net.torvald.unicode.toJavaString
|
import net.torvald.unicode.toJavaString
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
|
|
||||||
data class InputLenCap(val count: Int, val unit: CharLenUnit) {
|
data class InputLenCap(val count: Int, val unit: CharLenUnit) {
|
||||||
@@ -194,7 +195,7 @@ class UIItemTextLineInput(
|
|||||||
private fun moveCursorBack(delta: Int) {
|
private fun moveCursorBack(delta: Int) {
|
||||||
cursorDrawX -= delta
|
cursorDrawX -= delta
|
||||||
if (cursorDrawX < 0) {
|
if (cursorDrawX < 0) {
|
||||||
val stride = -cursorDrawX + minOf(256, fbo.width * 40 / 100) // + lookbehind term
|
val stride = -cursorDrawX + min(256, fbo.width * 40 / 100) // + lookbehind term
|
||||||
cursorDrawX += stride
|
cursorDrawX += stride
|
||||||
cursorDrawScroll -= stride
|
cursorDrawScroll -= stride
|
||||||
}
|
}
|
||||||
@@ -610,7 +611,7 @@ class UIItemTextLineInput(
|
|||||||
|
|
||||||
val textWidths = localCandidates.map { App.fontGame.getWidth(CodepointSequence(it)) }
|
val textWidths = localCandidates.map { App.fontGame.getWidth(CodepointSequence(it)) }
|
||||||
val candidatesMax = ime.config.candidates.toInt()
|
val candidatesMax = ime.config.candidates.toInt()
|
||||||
val candidatesCount = minOf(candidatesMax, localCandidates.size)
|
val candidatesCount = min(candidatesMax, localCandidates.size)
|
||||||
val isOnecolumn = (candidatesCount <= 3)
|
val isOnecolumn = (candidatesCount <= 3)
|
||||||
val halfcount = if (isOnecolumn) candidatesCount else FastMath.ceil(candidatesCount / 2f)
|
val halfcount = if (isOnecolumn) candidatesCount else FastMath.ceil(candidatesCount / 2f)
|
||||||
val candidateWinH = halfcount * 20 // using hard-coded 20 instead of the actual font height of 24
|
val candidateWinH = halfcount * 20 // using hard-coded 20 instead of the actual font height of 24
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nextstep-themed menu bar with mandatory title line
|
* Nextstep-themed menu bar with mandatory title line
|
||||||
@@ -38,7 +39,7 @@ class UINSMenu(
|
|||||||
val tree = treeRepresentation.parseAsYamlInvokable()
|
val tree = treeRepresentation.parseAsYamlInvokable()
|
||||||
override var width = 0
|
override var width = 0
|
||||||
override var height = 0
|
override var height = 0
|
||||||
//override var width = maxOf(minimumWidth, tree.getLevelData(1).map { AppLoader.fontGame.getWidth(it ?: "") }.max() ?: 0)
|
//override var width = max(minimumWidth, tree.getLevelData(1).map { AppLoader.fontGame.getWidth(it ?: "") }.max() ?: 0)
|
||||||
//override var height = LINE_HEIGHT * (tree.children.size + 1)
|
//override var height = LINE_HEIGHT * (tree.children.size + 1)
|
||||||
|
|
||||||
|
|
||||||
@@ -90,8 +91,8 @@ class UINSMenu(
|
|||||||
tree.children[it].data?.first + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
|
tree.children[it].data?.first + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
|
||||||
}
|
}
|
||||||
|
|
||||||
val listWidth = maxOf(
|
val listWidth = max(
|
||||||
App.fontGame.getWidth(menuTitle), minimumWidth,
|
max(App.fontGame.getWidth(menuTitle), minimumWidth),
|
||||||
stringsFromTree.map { App.fontGame.getWidth(it) }.maxOrNull() ?: 0
|
stringsFromTree.map { App.fontGame.getWidth(it) }.maxOrNull() ?: 0
|
||||||
)
|
)
|
||||||
val uiWidth = listWidth + (2 * TEXT_OFFSETX.toInt())
|
val uiWidth = listWidth + (2 * TEXT_OFFSETX.toInt())
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
world.worldTime.getSolarElevationAt(world.worldTime.ordinalDay, forceTimeAt!!)
|
world.worldTime.getSolarElevationAt(world.worldTime.ordinalDay, forceTimeAt!!)
|
||||||
else
|
else
|
||||||
world.worldTime.solarElevationDeg
|
world.worldTime.solarElevationDeg
|
||||||
val degThis = deg.floor()
|
val degThis = deg.floorToDouble()
|
||||||
val degNext = degThis + if (timeNow < HALF_DAY) 1 else -1 // Skybox.get has internal coerceIn
|
val degNext = degThis + if (timeNow < HALF_DAY) 1 else -1 // Skybox.get has internal coerceIn
|
||||||
|
|
||||||
val texture1 = Skybox[degThis, turbidity]
|
val texture1 = Skybox[degThis, turbidity]
|
||||||
@@ -255,7 +255,7 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
fun getGradientColour2(colorMap: GdxColorMap, solarAngleInDeg: Double, timeOfDay: Int): Cvec {
|
fun getGradientColour2(colorMap: GdxColorMap, solarAngleInDeg: Double, timeOfDay: Int): Cvec {
|
||||||
val pNowRaw = (solarAngleInDeg + 75.0) / 150.0 * colorMap.width
|
val pNowRaw = (solarAngleInDeg + 75.0) / 150.0 * colorMap.width
|
||||||
|
|
||||||
val pStartRaw = pNowRaw.floorInt()
|
val pStartRaw = pNowRaw.floorToInt()
|
||||||
val pNextRaw = pStartRaw + 1
|
val pNextRaw = pStartRaw + 1
|
||||||
|
|
||||||
val pSx: Int; val pSy: Int; val pNx: Int; val pNy: Int
|
val pSx: Int; val pSy: Int; val pNx: Int; val pNy: Int
|
||||||
|
|||||||
@@ -293,10 +293,10 @@ internal object BlocksDrawer {
|
|||||||
// the window frame which should NOT be MUL'd)
|
// the window frame which should NOT be MUL'd)
|
||||||
|
|
||||||
|
|
||||||
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
|
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorToInt()
|
||||||
val for_y_end = for_y_start + tilesBuffer.height - 1
|
val for_y_end = for_y_start + tilesBuffer.height - 1
|
||||||
|
|
||||||
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
|
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorToInt()
|
||||||
val for_x_end = for_x_start + tilesBuffer.width - 1
|
val for_x_end = for_x_start + tilesBuffer.width - 1
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
@@ -657,11 +657,11 @@ internal object BlocksDrawer {
|
|||||||
var tilesInVertical = -1; private set
|
var tilesInVertical = -1; private set
|
||||||
|
|
||||||
fun resize(screenW: Int, screenH: Int) {
|
fun resize(screenW: Int, screenH: Int) {
|
||||||
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1
|
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1
|
||||||
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1
|
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1
|
||||||
|
|
||||||
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilInt() + 1
|
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilToInt() + 1
|
||||||
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilInt() + 1
|
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilToInt() + 1
|
||||||
|
|
||||||
// only update if it's really necessary
|
// only update if it's really necessary
|
||||||
if (oldTH != tilesInHorizontal || oldTV != tilesInVertical) {
|
if (oldTH != tilesInHorizontal || oldTV != tilesInVertical) {
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ package net.torvald.terrarum.worlddrawer
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.colourutil.ColourTemp
|
import net.torvald.colourutil.ColourTemp
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||||
import net.torvald.terrarum.blendMul
|
|
||||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockstats.TileSurvey
|
import net.torvald.terrarum.blockstats.TileSurvey
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -32,26 +29,16 @@ object FeaturesDrawer {
|
|||||||
var colTemp: Int = 0
|
var colTemp: Int = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private val TILES_COLD = arrayOf(
|
|
||||||
Block.ICE_MAGICAL
|
|
||||||
, Block.ICE_FRAGILE
|
|
||||||
, Block.ICE_NATURAL
|
|
||||||
, Block.SNOW)
|
|
||||||
|
|
||||||
private val TILES_WARM = arrayOf(
|
|
||||||
Block.SAND_DESERT
|
|
||||||
, Block.SAND_RED)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
TileSurvey.submitProposal(
|
TileSurvey.submitProposal(
|
||||||
TileSurvey.SurveyProposal(
|
TileSurvey.SurveyProposal(
|
||||||
"basegame.FeaturesDrawer.coldTiles", 72, 48, 2, 2
|
"basegame.FeaturesDrawer.coldTiles", 72, 48, 2, 2
|
||||||
) { world, x, y -> TILES_COLD.contains(world.getTileFromTerrain(x, y)) }
|
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].tags.contains("COLD") }
|
||||||
)
|
)
|
||||||
TileSurvey.submitProposal(
|
TileSurvey.submitProposal(
|
||||||
TileSurvey.SurveyProposal(
|
TileSurvey.SurveyProposal(
|
||||||
"basegame.FeaturesDrawer.warmTiles", 72, 48, 2, 2
|
"basegame.FeaturesDrawer.warmTiles", 72, 48, 2, 2
|
||||||
) { world, x, y -> TILES_WARM.contains(world.getTileFromTerrain(x, y)) }
|
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].tags.contains("WARM") }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +79,6 @@ object FeaturesDrawer {
|
|||||||
private fun colTempLinearFunc(x: Float): Int {
|
private fun colTempLinearFunc(x: Float): Int {
|
||||||
val colTempMedian = (ENV_COLTEMP_HIGHEST + ENV_COLTEMP_LOWEST) / 2
|
val colTempMedian = (ENV_COLTEMP_HIGHEST + ENV_COLTEMP_LOWEST) / 2
|
||||||
|
|
||||||
return Math.round((ENV_COLTEMP_HIGHEST - ENV_COLTEMP_LOWEST) / 2 * FastMath.clamp(x, -1f, 1f) + colTempMedian)
|
return ((ENV_COLTEMP_HIGHEST - ENV_COLTEMP_LOWEST) / 2 * x.coerceIn(-1f, 1f) + colTempMedian).roundToInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,8 @@ import net.torvald.terrarum.modulebasegame.IngameRenderer
|
|||||||
import net.torvald.terrarum.modulebasegame.ui.abs
|
import net.torvald.terrarum.modulebasegame.ui.abs
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,8 +68,8 @@ object LightmapRenderer {
|
|||||||
const val overscan_opaque: Int = 10
|
const val overscan_opaque: Int = 10
|
||||||
const val LIGHTMAP_OVERRENDER = 10
|
const val LIGHTMAP_OVERRENDER = 10
|
||||||
|
|
||||||
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||||
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||||
|
|
||||||
//private val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
|
//private val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
|
||||||
|
|
||||||
@@ -257,8 +259,8 @@ object LightmapRenderer {
|
|||||||
*/
|
*/
|
||||||
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
||||||
swipeLight(
|
swipeLight(
|
||||||
maxOf(1, i - LIGHTMAP_HEIGHT + 4), maxOf(1, LIGHTMAP_HEIGHT - 2 - i),
|
max(1, i - LIGHTMAP_HEIGHT + 4), max(1, LIGHTMAP_HEIGHT - 2 - i),
|
||||||
minOf(LIGHTMAP_WIDTH - 2, i + 1), minOf(LIGHTMAP_HEIGHT - 2, (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) - i),
|
min(LIGHTMAP_WIDTH - 2, i + 1), min(LIGHTMAP_HEIGHT - 2, (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) - i),
|
||||||
1, 1,
|
1, 1,
|
||||||
lightmap
|
lightmap
|
||||||
)
|
)
|
||||||
@@ -291,8 +293,8 @@ object LightmapRenderer {
|
|||||||
*/
|
*/
|
||||||
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
for (i in 0 until LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 5) {
|
||||||
swipeLight(
|
swipeLight(
|
||||||
maxOf(1, i - LIGHTMAP_HEIGHT + 4), minOf(LIGHTMAP_HEIGHT - 2, i + 1),
|
max(1, i - LIGHTMAP_HEIGHT + 4), min(LIGHTMAP_HEIGHT - 2, i + 1),
|
||||||
minOf(LIGHTMAP_WIDTH - 2, i + 1), maxOf(1, (LIGHTMAP_HEIGHT - 2) - (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 6) + i),
|
min(LIGHTMAP_WIDTH - 2, i + 1), max(1, (LIGHTMAP_HEIGHT - 2) - (LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT - 6) + i),
|
||||||
1, -1,
|
1, -1,
|
||||||
lightmap
|
lightmap
|
||||||
)
|
)
|
||||||
@@ -355,10 +357,10 @@ object LightmapRenderer {
|
|||||||
val lightBoxY = it.hitbox.startY + (lightBox.startY * scale)
|
val lightBoxY = it.hitbox.startY + (lightBox.startY * scale)
|
||||||
val lightBoxW = lightBox.width * scale - 1
|
val lightBoxW = lightBox.width * scale - 1
|
||||||
val lightBoxH = lightBox.height * scale - 1
|
val lightBoxH = lightBox.height * scale - 1
|
||||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
for (y in lightBoxY.div(TILE_SIZE).floorToInt()
|
||||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorToInt()) {
|
||||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
for (x in lightBoxX.div(TILE_SIZE).floorToInt()
|
||||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorToInt()) {
|
||||||
|
|
||||||
val oldLight = lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
val oldLight = lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
||||||
val actorLight = colour
|
val actorLight = colour
|
||||||
@@ -374,10 +376,10 @@ object LightmapRenderer {
|
|||||||
val lightBoxY = it.hitbox.startY + (shadeBox.startY * scale)
|
val lightBoxY = it.hitbox.startY + (shadeBox.startY * scale)
|
||||||
val lightBoxW = shadeBox.width * scale - 1
|
val lightBoxW = shadeBox.width * scale - 1
|
||||||
val lightBoxH = shadeBox.height * scale - 1
|
val lightBoxH = shadeBox.height * scale - 1
|
||||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
for (y in lightBoxY.div(TILE_SIZE).floorToInt()
|
||||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorToInt()) {
|
||||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
for (x in lightBoxX.div(TILE_SIZE).floorToInt()
|
||||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorToInt()) {
|
||||||
|
|
||||||
val oldLight = shadowMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
val oldLight = shadowMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
|
||||||
val actorLight = colour
|
val actorLight = colour
|
||||||
@@ -706,10 +708,10 @@ object LightmapRenderer {
|
|||||||
/*lightBuffer.drawPixel(
|
/*lightBuffer.drawPixel(
|
||||||
x - this_x_start,
|
x - this_x_start,
|
||||||
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
lightBuffer.height - 1 - y + this_y_start, // flip Y
|
||||||
(maxOf(red,grnw,bluw,uvlwr) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
(max(red,grnw,bluw,uvlwr) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(24) or
|
||||||
(maxOf(redw,grn,bluw,uvlwg) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
(max(redw,grn,bluw,uvlwg) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(16) or
|
||||||
(maxOf(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
(max(redw,grnw,blu,uvlwb) * solidMultMagic).hdnorm().times(255f).roundToInt().shl(8) or
|
||||||
(maxOf(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
(max(bluwv,uvl) * solidMultMagic).hdnorm().times(255f).roundToInt()
|
||||||
)*/
|
)*/
|
||||||
lightBuffer.drawPixel(
|
lightBuffer.drawPixel(
|
||||||
x - this_x_start,
|
x - this_x_start,
|
||||||
@@ -809,10 +811,10 @@ object LightmapRenderer {
|
|||||||
private fun Cvec.maxAndAssign(other: Cvec): Cvec {
|
private fun Cvec.maxAndAssign(other: Cvec): Cvec {
|
||||||
// TODO investigate: if I use assignment instead of set(), it blackens like the vector branch. --Torvald, 2019-06-07
|
// TODO investigate: if I use assignment instead of set(), it blackens like the vector branch. --Torvald, 2019-06-07
|
||||||
// that was because you forgot 'this.r/g/b/a = ' part, bitch. --Torvald, 2019-06-07
|
// that was because you forgot 'this.r/g/b/a = ' part, bitch. --Torvald, 2019-06-07
|
||||||
this.r = if (this.r > other.r) this.r else other.r
|
this.r = max(this.r, other.r)
|
||||||
this.g = if (this.g > other.g) this.g else other.g
|
this.g = max(this.g, other.g)
|
||||||
this.b = if (this.b > other.b) this.b else other.b
|
this.b = max(this.b, other.b)
|
||||||
this.a = if (this.a > other.a) this.a else other.a
|
this.a = max(this.a, other.a)
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -825,8 +827,8 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// input: 0..1 for int 0..1023
|
// input: 0..1 for int 0..1023
|
||||||
fun hdr(intensity: Float): Float {
|
fun hdr(intensity: Float): Float {
|
||||||
val intervalStart = (intensity / 4f * LightmapHDRMap.size).floorInt()
|
val intervalStart = (intensity / 4f * LightmapHDRMap.size).floorToInt()
|
||||||
val intervalEnd = (intensity / 4f * LightmapHDRMap.size).floorInt() + 1
|
val intervalEnd = (intensity / 4f * LightmapHDRMap.size).floorToInt() + 1
|
||||||
|
|
||||||
if (intervalStart == intervalEnd) return LightmapHDRMap[intervalStart]
|
if (intervalStart == intervalEnd) return LightmapHDRMap[intervalStart]
|
||||||
|
|
||||||
@@ -849,11 +851,11 @@ object LightmapRenderer {
|
|||||||
// copied from BlocksDrawer, duh!
|
// copied from BlocksDrawer, duh!
|
||||||
// FIXME 'lightBuffer' is not zoomable in this way
|
// FIXME 'lightBuffer' is not zoomable in this way
|
||||||
|
|
||||||
val tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
val tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilToInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||||
val tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
val tilesInVertical = (App.scr.hf / TILE_SIZE).ceilToInt() + 1 + LIGHTMAP_OVERRENDER * 2
|
||||||
|
|
||||||
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||||
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
|
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilToInt() + overscan_open * 2 + 3
|
||||||
|
|
||||||
if (_init) {
|
if (_init) {
|
||||||
lightBuffer.dispose()
|
lightBuffer.dispose()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.jme3.math.FastMath
|
|||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.ceilInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
@@ -42,9 +42,9 @@ object WorldCamera {
|
|||||||
get() = y + (height * zoomSamplePoint).toInt()
|
get() = y + (height * zoomSamplePoint).toInt()
|
||||||
|
|
||||||
val zoomedWidth: Int
|
val zoomedWidth: Int
|
||||||
get() = (width / zoom).ceilInt()
|
get() = (width / zoom).ceilToInt()
|
||||||
val zoomedHeight: Int
|
val zoomedHeight: Int
|
||||||
get() = (height / zoom).ceilInt()
|
get() = (height / zoom).ceilToInt()
|
||||||
|
|
||||||
var xEnd: Int = 0 // right position
|
var xEnd: Int = 0 // right position
|
||||||
private set
|
private set
|
||||||
@@ -89,14 +89,14 @@ object WorldCamera {
|
|||||||
else
|
else
|
||||||
nullVec
|
nullVec
|
||||||
|
|
||||||
x = ((player.hitbox.centeredX - pVecSum.x).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
x = ((player.hitbox.centeredX - pVecSum.x).toFloat() - (width / 2)).floorToInt() // X only: ROUNDWORLD implementation
|
||||||
|
|
||||||
|
|
||||||
y = (FastMath.clamp(
|
y = (FastMath.clamp(
|
||||||
(player.hitbox.centeredY - pVecSum.y).toFloat() - height / 2,
|
(player.hitbox.centeredY - pVecSum.y).toFloat() - height / 2,
|
||||||
TILE_SIZEF,
|
TILE_SIZEF,
|
||||||
world.height * TILE_SIZE - height - TILE_SIZEF
|
world.height * TILE_SIZE - height - TILE_SIZEF
|
||||||
)).floorInt().clampCameraY(world)*/
|
)).floorToInt().clampCameraY(world)*/
|
||||||
|
|
||||||
|
|
||||||
// val fpsRatio = App.UPDATE_RATE / Gdx.graphics.deltaTime // if FPS=32 & RATE=64, ratio will be 0.5
|
// val fpsRatio = App.UPDATE_RATE / Gdx.graphics.deltaTime // if FPS=32 & RATE=64, ratio will be 0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user