mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
the entire game will use new smooth delta
This commit is contained in:
@@ -358,12 +358,14 @@ public class AppLoader implements ApplicationListener {
|
||||
loadTimer += Gdx.graphics.getRawDeltaTime();
|
||||
|
||||
if (loadTimer >= showupTime) {
|
||||
// hand over the scene control to this single class; Terrarum must call
|
||||
// 'AppLoader.getINSTANCE().screen.render(delta)', this is not redundant at all!
|
||||
setScreen(Terrarum.INSTANCE);
|
||||
}
|
||||
}
|
||||
// draw the screen
|
||||
else {
|
||||
screen.render(Gdx.graphics.getDeltaTime());
|
||||
screen.render(((float) getSmoothDelta()));
|
||||
}
|
||||
|
||||
// nested FBOs are just not a thing in GL!
|
||||
|
||||
@@ -464,7 +464,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
override fun run() {
|
||||
var updateTries = 0
|
||||
while (ingame.updateDeltaCounter >= ingame.updateRate) {
|
||||
ingame.updateGame(Terrarum.deltaTime)
|
||||
ingame.updateGame(AppLoader.getSmoothDelta().toFloat())
|
||||
ingame.updateDeltaCounter -= ingame.updateRate
|
||||
updateTries++
|
||||
|
||||
@@ -1090,7 +1090,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
playableActorDelegate = newActor
|
||||
WorldSimulator(player, Terrarum.deltaTime)
|
||||
WorldSimulator(player, AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
|
||||
private fun changePossession(refid: Int) {
|
||||
@@ -1107,7 +1107,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
// accept new delegate
|
||||
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
|
||||
playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC
|
||||
WorldSimulator(player, Terrarum.deltaTime)
|
||||
WorldSimulator(player, AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
|
||||
/** Send message to notifier UI and toggle the UI as opened. */
|
||||
|
||||
@@ -212,8 +212,6 @@ object Terrarum : Screen {
|
||||
val fullscreenQuad = AppLoader.fullscreenQuad
|
||||
|
||||
|
||||
val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime
|
||||
|
||||
|
||||
lateinit var assetManager: AssetManager // TODO
|
||||
|
||||
@@ -413,9 +411,7 @@ object Terrarum : Screen {
|
||||
override fun render(delta: Float) {
|
||||
AppLoader.debugTimers["GDX.rawDelta"] = Gdx.graphics.rawDeltaTime.times(1000_000_000f).toLong()
|
||||
AppLoader.debugTimers["GDX.smtDelta"] = AppLoader.getSmoothDelta().times(1000_000_000f).toLong()
|
||||
AppLoader.getINSTANCE().screen.render(deltaTime)
|
||||
//GLOBAL_RENDER_TIMER += 1
|
||||
// moved to AppLoader; global event must be place at the apploader to prevent ACCIDENTAL forgot-to-update type of bug.
|
||||
AppLoader.getINSTANCE().screen.render(delta)
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
@@ -489,7 +485,7 @@ object Terrarum : Screen {
|
||||
get() = Gdx.input.y
|
||||
/** Bigger than 1.0 */
|
||||
inline val updateRate: Double
|
||||
get() = 1.0 / Gdx.graphics.deltaTime
|
||||
get() = 1.0 / AppLoader.getSmoothDelta()
|
||||
/** Smaller than 1.0 */
|
||||
val renderRate = 1.0 / TARGET_INTERNAL_FPS
|
||||
val renderRateStr = TARGET_INTERNAL_FPS.toString()
|
||||
|
||||
@@ -4,11 +4,12 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-16.
|
||||
@@ -63,9 +64,9 @@ object BlockPropUtil {
|
||||
internal fun dynamicLumFuncTickClock() {
|
||||
// FPS-time compensation
|
||||
if (Gdx.graphics.framesPerSecond > 0) {
|
||||
flickerFuncX += Terrarum.deltaTime * 1000f
|
||||
breathFuncX += Terrarum.deltaTime * 1000f
|
||||
pulsateFuncX += Terrarum.deltaTime * 1000f
|
||||
flickerFuncX += AppLoader.getSmoothDelta().toFloat() * 1000f
|
||||
breathFuncX += AppLoader.getSmoothDelta().toFloat() * 1000f
|
||||
pulsateFuncX += AppLoader.getSmoothDelta().toFloat() * 1000f
|
||||
}
|
||||
|
||||
// flicker-related vars
|
||||
|
||||
@@ -100,6 +100,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
* When the engine resolves this value, the framerate must be accounted for. E.g.:
|
||||
* 3.0 is resolved as 3.0 if FPS is 60, but the same value should be resolved as 6.0 if FPS is 30.
|
||||
* v_resolved = v * (60/FPS) or, v * (60 * delta_t)
|
||||
* (Use this code verbatim: '(Terrarum.PHYS_REF_FPS * delta)')
|
||||
*
|
||||
*
|
||||
* Elevators/Movingwalks/etc.: edit hitbox manually!
|
||||
*
|
||||
@@ -271,10 +273,6 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
internal var walledBottom = false // UNUSED; only for BasicDebugInfoWindow
|
||||
internal var colliding = false
|
||||
|
||||
protected inline val updateDelta: Float
|
||||
get() = Terrarum.deltaTime
|
||||
|
||||
|
||||
var isWalkingH = false
|
||||
var isWalkingV = false
|
||||
|
||||
@@ -340,7 +338,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
inline val feetPosTile: IntArray
|
||||
get() = intArrayOf(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
||||
|
||||
override fun run() = update(updateDelta)
|
||||
override fun run() = update(AppLoader.getSmoothDelta().toFloat())
|
||||
|
||||
/**
|
||||
* Add vector value to the velocity, in the time unit of single frame.
|
||||
@@ -355,18 +353,18 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
|
||||
private val bounceDampenVelThreshold = 0.5
|
||||
|
||||
override fun update(delta: Float) {
|
||||
override fun update(fdelta: Float) {
|
||||
if (isUpdate && !flagDespawn) {
|
||||
|
||||
//val ddelta = Gdx.graphics.rawDeltaTime.toDouble()
|
||||
val ddelta = AppLoader.getSmoothDelta()
|
||||
//val delta = Gdx.graphics.rawDeltaTime.toDouble()
|
||||
val delta = AppLoader.getSmoothDelta()
|
||||
//println("${Gdx.graphics.rawDeltaTime.toDouble()}\t${AppLoader.getSmoothDelta()}")
|
||||
|
||||
|
||||
if (!assertPrinted) assertInit()
|
||||
|
||||
if (sprite != null) sprite!!.update(delta)
|
||||
if (spriteGlow != null) spriteGlow!!.update(delta)
|
||||
if (sprite != null) sprite!!.update(fdelta)
|
||||
if (spriteGlow != null) spriteGlow!!.update(fdelta)
|
||||
|
||||
// make NoClip work for player
|
||||
if (true) {//this == Terrarum.ingame!!.actorNowPlaying) {
|
||||
@@ -391,7 +389,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
// Actors are subject to the gravity and the buoyancy if they are not levitating
|
||||
|
||||
if (!isNoSubjectToGrav) {
|
||||
applyGravitation(ddelta)
|
||||
applyGravitation(delta)
|
||||
}
|
||||
|
||||
//applyBuoyancy()
|
||||
@@ -412,11 +410,11 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
* This body is NON-STATIC and the other body is STATIC
|
||||
*/
|
||||
if (!isNoCollideWorld) {
|
||||
displaceHitbox(ddelta)
|
||||
displaceHitbox(delta)
|
||||
}
|
||||
else {
|
||||
val vecSum = externalForce + (controllerMoveDelta ?: Vector2(0.0, 0.0))
|
||||
hitbox.translate(vecSum * (Terrarum.PHYS_REF_FPS * ddelta))
|
||||
hitbox.translate(vecSum * (Terrarum.PHYS_REF_FPS * delta))
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
@@ -430,9 +428,9 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
// TODO less friction for non-animating objects (make items glide far more on ice)
|
||||
|
||||
// FIXME asymmetry on friction
|
||||
setHorizontalFriction() // friction SHOULD use and alter externalForce
|
||||
setHorizontalFriction(delta) // friction SHOULD use and alter externalForce
|
||||
//if (isNoClip) { // TODO also hanging on the rope, etc.
|
||||
setVerticalFriction()
|
||||
setVerticalFriction(delta)
|
||||
//}
|
||||
|
||||
|
||||
@@ -1073,7 +1071,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
|
||||
/** about stopping
|
||||
* for about get moving, see updateMovementControl */
|
||||
private fun setHorizontalFriction() {
|
||||
private fun setHorizontalFriction(delta: Double) {
|
||||
val friction = if (isNoClip)
|
||||
BASE_FRICTION * BlockCodex[Block.STONE].friction.frictionToMult()
|
||||
else {
|
||||
@@ -1102,7 +1100,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
}
|
||||
}
|
||||
|
||||
private fun setVerticalFriction() {
|
||||
private fun setVerticalFriction(delta: Double) {
|
||||
val friction = if (isNoClip)
|
||||
BASE_FRICTION * BlockCodex[Block.STONE].friction.frictionToMult()
|
||||
else
|
||||
|
||||
@@ -131,10 +131,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (button == AppLoader.getConfigInt("mouseprimary")) {
|
||||
ingame.worldPrimaryClickEnd(Terrarum.deltaTime)
|
||||
ingame.worldPrimaryClickEnd(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickEnd(Terrarum.deltaTime)
|
||||
ingame.worldSecondaryClickEnd(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,10 +172,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (button == AppLoader.getConfigInt("mouseprimary")) {
|
||||
ingame.worldPrimaryClickStart(Terrarum.deltaTime)
|
||||
ingame.worldPrimaryClickStart(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickStart(Terrarum.deltaTime)
|
||||
ingame.worldSecondaryClickStart(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
actorNowPlaying = newActor
|
||||
//WorldSimulator(actorNowPlaying, Terrarum.deltaTime)
|
||||
//WorldSimulator(actorNowPlaying, AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
|
||||
private fun changePossession(refid: Int) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
@@ -210,7 +211,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
actor.avStrength / 1000.0
|
||||
else
|
||||
1.0 // TODO variable: scale, strength
|
||||
val swingDmgToFrameDmg = Terrarum.deltaTime.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = AppLoader.getSmoothDelta().toFloat().toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
// damage the item
|
||||
newItem.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
@@ -22,7 +23,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
|
||||
/** Will NOT actually delete from the CircularArray */
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun run() = update(Terrarum.deltaTime)
|
||||
override fun run() = update(AppLoader.getSmoothDelta().toFloat())
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
@@ -28,7 +28,7 @@ interface Pocketed {
|
||||
}
|
||||
|
||||
inventory.itemEquipped[item.equipPosition] = null
|
||||
item.effectOnUnequip(Terrarum.deltaTime)
|
||||
item.effectOnUnequip(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
|
||||
// no need for equipSlot(Int)
|
||||
@@ -50,7 +50,7 @@ interface Pocketed {
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item
|
||||
item.effectWhenEquipped(Terrarum.deltaTime)
|
||||
item.effectWhenEquipped(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
// else do nothing
|
||||
}
|
||||
@@ -69,13 +69,13 @@ interface Pocketed {
|
||||
|
||||
|
||||
fun consumePrimary(item: GameItem) {
|
||||
if (item.startPrimaryUse(Terrarum.deltaTime)) {
|
||||
if (item.startPrimaryUse(AppLoader.getSmoothDelta().toFloat())) {
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
}
|
||||
|
||||
fun consumeSecondary(item: GameItem) {
|
||||
if (item.startSecondaryUse(Terrarum.deltaTime))
|
||||
if (item.startSecondaryUse(AppLoader.getSmoothDelta().toFloat()))
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
@@ -9,13 +10,13 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
||||
override fun run() {
|
||||
for (i in startIndex..endIndex) {
|
||||
val it = Terrarum.ingame!!.actorContainer[i]
|
||||
it.update(Terrarum.deltaTime)
|
||||
it.update(AppLoader.getSmoothDelta().toFloat())
|
||||
|
||||
if (it is Pocketed) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
inventoryEntry.item.effectWhileInPocket(Terrarum.deltaTime)
|
||||
inventoryEntry.item.effectWhileInPocket(AppLoader.getSmoothDelta().toFloat())
|
||||
if (it.equipped(inventoryEntry.item)) {
|
||||
inventoryEntry.item.effectWhenEquipped(Terrarum.deltaTime)
|
||||
inventoryEntry.item.effectWhenEquipped(AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ import org.luaj.vm2.lib.*
|
||||
private val spriteBuffer = ImageBuffer(VSprite.width * 2, VSprite.height)
|
||||
|
||||
fun render(g: Graphics) {
|
||||
cursorBlinkTimer += Terrarum.deltaTime
|
||||
cursorBlinkTimer += AppLoader.getSmoothDelta().toFloat()
|
||||
if (cursorBlinkTimer > cursorBlinkTime) {
|
||||
cursorBlinkTimer -= cursorBlinkTime
|
||||
cursorBlinkOn = !cursorBlinkOn
|
||||
|
||||
Reference in New Issue
Block a user