instead of dealing with delta, we'll just update multiple times, THIS TIME IN CORRECT WAY

(because it really works :p)
This commit is contained in:
minjaesong
2019-01-22 02:44:05 +09:00
parent afba402c6c
commit ded9cb1a10
12 changed files with 111 additions and 153 deletions

View File

@@ -207,6 +207,8 @@ public class AppLoader implements ApplicationListener {
Gdx.gl20.glViewport(0, 0, width, height);
}
public static final double UPDATE_RATE = 1.0 / 61.0; // TODO set it like 1/100, because apparent framerate is limited by update rate
private float loadTimer = 0f;
private final float showupTime = 100f / 1000f;
@@ -235,7 +237,7 @@ public class AppLoader implements ApplicationListener {
updateFullscreenQuad(appConfig.width, appConfig.height);
}
private static double _kalman_xhat_k = 1.0 / 60.0;
private static double _kalman_xhat_k = UPDATE_RATE;
private static double _kalman_return_value = _kalman_xhat_k;
private static double _kalman_p_k = 1.0;
private static final double _kalman_R = 0.2; // 0.2: empirical value
@@ -254,7 +256,7 @@ public class AppLoader implements ApplicationListener {
}
public static void resetDeltaSmoothingHistory() {
_kalman_xhat_k = 1.0 / 60.0;
_kalman_xhat_k = UPDATE_RATE;
_kalman_p_k = 1.0;
}
@@ -365,7 +367,7 @@ public class AppLoader implements ApplicationListener {
}
// draw the screen
else {
screen.render(((float) getSmoothDelta()));
screen.render((float) UPDATE_RATE);
}
// nested FBOs are just not a thing in GL!

View File

@@ -74,22 +74,12 @@ object Terrarum : Screen {
get() = HEIGHT.ushr(1)
/**
* To be used with physics simulator
* To be used with physics simulator. This is a magic number.
*/
val PHYS_TIME_FRAME: Double = 26.0 + (2.0 / 3.0)
val PHYS_CONST_MULT: Double = 60.0 / (26.0 + (2.0 / 3.0))
val PHYS_REF_FPS: Double = 60.0
// 26.0 + (2.0 / 3.0) // lower value == faster gravity response (IT WON'T HOTSWAP!!)
// protip: using METER, game unit and SI unit will have same number
/**
* To be used with render, to achieve smooth frame drawing
* TARGET_INTERNAL_FPS > PHYS_TIME_FRAME for smooth frame drawing
*/
val TARGET_INTERNAL_FPS: Double = 60.0
var previousScreen: Screen? = null // to be used with temporary states like StateMonitorCheck
@@ -483,13 +473,9 @@ object Terrarum : Screen {
get() = Gdx.input.x
inline val mouseScreenY: Int
get() = Gdx.input.y
/** Bigger than 1.0 */
/** Delta converted as it it was a FPS */
inline val updateRate: Double
get() = 1.0 / AppLoader.getSmoothDelta()
/** Smaller than 1.0 */
val renderRate = 1.0 / TARGET_INTERNAL_FPS
val renderRateStr = TARGET_INTERNAL_FPS.toString()
/**
* Usage:
*

View File

@@ -199,23 +199,11 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private val introUncoverTime: Second = 0.3f
private var introUncoverDeltaCounter = 0f
private var updateDeltaCounter = 0.0
protected val renderRate = Terrarum.renderRate
override fun render(delta: Float) {
// async update
updateDeltaCounter += delta
if (delta < 1f / 10f) { // discard async if measured FPS <= 10
var updateTries = 0
while (updateDeltaCounter >= renderRate && updateTries < 6) {
updateScreen(delta)
updateDeltaCounter -= renderRate
updateTries++
}
}
else {
updateScreen(delta)
}
// TODO async update
updateScreen(delta)
// render? just do it anyway
renderScreen()
}

View File

@@ -95,7 +95,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
)
/**
* TODO Pixels per 1/60 seconds.
* Unit: Pixels per 1/60 (or AppLoader.UPDATE_RATE) seconds.
*
* 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.
@@ -109,15 +109,21 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
* Acceleration: used in code like:
* veloY += 3.0
* +3.0 is acceleration. You __accumulate__ acceleration to the velocity.
*
* V for Velocity!
*/
internal val externalForce = Vector2(0.0, 0.0)
internal val externalV = Vector2(0.0, 0.0)
@Transient private val VELO_HARD_LIMIT = 100.0
/**
* Unit: Pixels per 1/60 (or AppLoader.UPDATE_RATE) seconds.
*
* for "Controllable" actors
*
* V for Velocity!
*/
var controllerMoveDelta: Vector2? = if (this is Controllable) Vector2() else null
var controllerV: Vector2? = if (this is Controllable) Vector2() else null
// not sure we need this...
//var jumpable = true // this is kind of like "semaphore"
@@ -348,23 +354,17 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
* @param acc : Acceleration in Vector2
*/
fun applyForce(acc: Vector2) {
externalForce += acc * speedMultByTile
externalV += acc * speedMultByTile
}
private val bounceDampenVelThreshold = 0.5
override fun update(fdelta: Float) {
override fun update(delta: Float) {
if (isUpdate && !flagDespawn) {
//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(fdelta)
if (spriteGlow != null) spriteGlow!!.update(fdelta)
if (sprite != null) sprite!!.update(delta)
if (spriteGlow != null) spriteGlow!!.update(delta)
// make NoClip work for player
if (true) {//this == Terrarum.ingame!!.actorNowPlaying) {
@@ -381,7 +381,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
////////////////////////////////////////////////////////////////
// Codes that modifies velocity (moveDelta and externalForce) //
// Codes that modifies velocity (moveDelta and externalV) //
////////////////////////////////////////////////////////////////
// --> Apply more forces <-- //
@@ -396,8 +396,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
}
// hard limit velocity
externalForce.x = externalForce.x.bipolarClamp(VELO_HARD_LIMIT) // displaceHitbox SHOULD use moveDelta
externalForce.y = externalForce.y.bipolarClamp(VELO_HARD_LIMIT)
externalV.x = externalV.x.bipolarClamp(VELO_HARD_LIMIT) // displaceHitbox SHOULD use moveDelta
externalV.y = externalV.y.bipolarClamp(VELO_HARD_LIMIT)
if (!isChronostasis) {
///////////////////////////////////////////////////
@@ -410,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(delta)
displaceHitbox(delta.toDouble())
}
else {
val vecSum = externalForce + (controllerMoveDelta ?: Vector2(0.0, 0.0))
hitbox.translate(vecSum * (Terrarum.PHYS_REF_FPS * delta))
val vecSum = externalV + (controllerV ?: Vector2(0.0, 0.0))
hitbox.translate(vecSum)
}
//////////////////////////////////////////////////////////////
@@ -428,7 +428,7 @@ 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(delta) // friction SHOULD use and alter externalForce
setHorizontalFriction(delta) // friction SHOULD use and alter externalV
//if (isNoClip) { // TODO also hanging on the rope, etc.
setVerticalFriction(delta)
//}
@@ -470,33 +470,33 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
if (!(isWalled(hitbox, COLLIDING_LEFT) && walkX < 0)
|| !(isWalled(hitbox, COLLIDING_RIGHT) && walkX > 0)
) {
moveDelta.x = externalForce.x + walkX
moveDelta.x = externalV.x + walkX
}
// decide whether to ignore walkY
if (!(isWalled(hitbox, COLLIDING_TOP) && walkY < 0)
|| !(isWalled(hitbox, COLLIDING_BOTTOM) && walkY > 0)
) {
moveDelta.y = externalForce.y + walkY
moveDelta.y = externalV.y + walkY
}
}
else {
if (!isWalled(hitbox, COLLIDING_LEFT)
|| !isWalled(hitbox, COLLIDING_RIGHT)
) {
moveDelta.x = externalForce.x
moveDelta.x = externalV.x
}
// decide whether to ignore walkY
if (!isWalled(hitbox, COLLIDING_TOP)
|| !isWalled(hitbox, COLLIDING_BOTTOM)
) {
moveDelta.y = externalForce.y
moveDelta.y = externalV.y
}
}
}*/
fun getDrag(delta: Double, externalForce: Vector2): Vector2 {
fun getDrag(delta: Float, externalForce: Vector2): Vector2 {
/**
* weight; gravitational force in action
* W = mass * G (9.8 [m/s^2])
@@ -514,7 +514,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
val V: Vector2 = (W - D) / Terrarum.PHYS_TIME_FRAME * SI_TO_GAME_ACC
return V * (Terrarum.PHYS_REF_FPS * delta).sqrt()
return V
// FIXME v * const, where const = 1.0 for FPS=60, sqrt(2.0) for FPS=30, etc.
// this is "close enough" solution and not perfect.
@@ -535,11 +535,11 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
*
* Apply only if not grounded; normal force is precessed separately.
*/
private fun applyGravitation(delta: Double) {
private fun applyGravitation(delta: Float) {
if (!isNoSubjectToGrav && !(gravitation.y > 0 && walledBottom || gravitation.y < 0 && walledTop)) {
//if (!isWalled(hitbox, COLLIDING_BOTTOM)) {
applyForce(getDrag(delta, externalForce))
applyForce(getDrag(delta, externalV))
//}
}
}
@@ -587,7 +587,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
// if not touching:
// do nothing
// [Friction]:
// deform vector "externalForce"
// deform vector "externalV"
// if isControllable:
// also alter walkX/Y
// translate ((nextHitbox)) hitbox by moveDelta (forces), this consumes force
@@ -637,7 +637,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
fun Double.modTileDelta() = this - this.modTile()
val vectorSum = (externalForce + controllerMoveDelta) * (Terrarum.PHYS_REF_FPS * delta)
val vectorSum = (externalV + controllerV)
val ccdSteps = minOf(16, (vectorSum.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
@@ -838,20 +838,20 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
// bounce X/Y
if (bounceX) {
externalForce.x *= elasticity
controllerMoveDelta?.let { controllerMoveDelta!!.x *= elasticity }
externalV.x *= elasticity
controllerV?.let { controllerV!!.x *= elasticity }
}
if (bounceY) {
externalForce.y *= elasticity
controllerMoveDelta?.let { controllerMoveDelta!!.y *= elasticity }
externalV.y *= elasticity
controllerV?.let { controllerV!!.y *= elasticity }
}
if (zeroX) {
externalForce.x = 0.0
controllerMoveDelta?.let { controllerMoveDelta!!.x = 0.0 }
externalV.x = 0.0
controllerV?.let { controllerV!!.x = 0.0 }
}
if (zeroY) {
externalForce.y = 0.0
controllerMoveDelta?.let { controllerMoveDelta!!.y = 0.0 }
externalV.y = 0.0
controllerV?.let { controllerV!!.y = 0.0 }
}
@@ -1012,11 +1012,11 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
(BlockCodex[tile].isSolid) ||
// platforms, moving downward AND not "going down"
(this is ActorHumanoid && BlockCodex[tile].isPlatform &&
externalForce.y + (controllerMoveDelta?.y ?: 0.0) >= 0.0 &&
externalV.y + (controllerV?.y ?: 0.0) >= 0.0 &&
!this.isDownDown && this.axisY <= 0f) ||
// platforms, moving downward
(this !is ActorHumanoid && BlockCodex[tile].isPlatform &&
externalForce.y + (controllerMoveDelta?.y ?: 0.0) >= 0.0)
externalV.y + (controllerV?.y ?: 0.0) >= 0.0)
// TODO: as for the platform, only apply it when it's a feet tile
@@ -1071,7 +1071,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
/** about stopping
* for about get moving, see updateMovementControl */
private fun setHorizontalFriction(delta: Double) {
private fun setHorizontalFriction(delta: Float) {
val friction = if (isNoClip)
BASE_FRICTION * BlockCodex[Block.STONE].friction.frictionToMult()
else {
@@ -1079,50 +1079,50 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
BASE_FRICTION * if (grounded) feetFriction else bodyFriction
}
if (externalForce.x < 0) {
externalForce.x += friction
if (externalForce.x > 0) externalForce.x = 0.0 // compensate overshoot
if (externalV.x < 0) {
externalV.x += friction
if (externalV.x > 0) externalV.x = 0.0 // compensate overshoot
}
else if (externalForce.x > 0) {
externalForce.x -= friction
if (externalForce.x < 0) externalForce.x = 0.0 // compensate overshoot
else if (externalV.x > 0) {
externalV.x -= friction
if (externalV.x < 0) externalV.x = 0.0 // compensate overshoot
}
if (this is Controllable) {
if (controllerMoveDelta!!.x < 0) {
controllerMoveDelta!!.x += friction
if (controllerMoveDelta!!.x > 0) controllerMoveDelta!!.x = 0.0
if (controllerV!!.x < 0) {
controllerV!!.x += friction
if (controllerV!!.x > 0) controllerV!!.x = 0.0
}
else if (controllerMoveDelta!!.x > 0) {
controllerMoveDelta!!.x -= friction
if (controllerMoveDelta!!.x < 0) controllerMoveDelta!!.x = 0.0
else if (controllerV!!.x > 0) {
controllerV!!.x -= friction
if (controllerV!!.x < 0) controllerV!!.x = 0.0
}
}
}
private fun setVerticalFriction(delta: Double) {
private fun setVerticalFriction(delta: Float) {
val friction = if (isNoClip)
BASE_FRICTION * BlockCodex[Block.STONE].friction.frictionToMult()
else
BASE_FRICTION * bodyFriction
if (externalForce.y < 0) {
externalForce.y += friction
if (externalForce.y > 0) externalForce.y = 0.0 // compensate overshoot
if (externalV.y < 0) {
externalV.y += friction
if (externalV.y > 0) externalV.y = 0.0 // compensate overshoot
}
else if (externalForce.y > 0) {
externalForce.y -= friction
if (externalForce.y < 0) externalForce.y = 0.0 // compensate overshoot
else if (externalV.y > 0) {
externalV.y -= friction
if (externalV.y < 0) externalV.y = 0.0 // compensate overshoot
}
if (this is Controllable) {
if (controllerMoveDelta!!.y < 0) {
controllerMoveDelta!!.y += friction
if (controllerMoveDelta!!.y > 0) controllerMoveDelta!!.y = 0.0
if (controllerV!!.y < 0) {
controllerV!!.y += friction
if (controllerV!!.y > 0) controllerV!!.y = 0.0
}
else if (controllerMoveDelta!!.y > 0) {
controllerMoveDelta!!.y -= friction
if (controllerMoveDelta!!.y < 0) controllerMoveDelta!!.y = 0.0
else if (controllerV!!.y > 0) {
controllerV!!.y -= friction
if (controllerV!!.y < 0) controllerV!!.y = 0.0
}
}
}
@@ -1443,8 +1443,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
field = value
if (value) {
externalForce.zero()
controllerMoveDelta?.zero()
externalV.zero()
controllerV?.zero()
}
}

View File

@@ -46,7 +46,7 @@ import org.luaj.vm2.*
*/
fun composeActorObject(actor: ActorWBMovable): LuaTable {
val t: LuaTable = LuaTable()
val moveDelta = actor.externalForce + actor.controllerMoveDelta
val moveDelta = actor.externalV + actor.controllerV
t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
t["startX"] = actor.hitbox.centeredX.toLua()

View File

@@ -120,9 +120,6 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
}
protected var updateDeltaCounter = 0.0
protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS
private val actorsRenderOverlay = ArrayList<ActorWithBody>()
init {
@@ -161,19 +158,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
// ASYNCHRONOUS UPDATE AND RENDER //
// async update
updateDeltaCounter += delta
if (delta < 1f / 10f) { // discard async if measured FPS <= 10
var updateTries = 0
while (updateDeltaCounter >= updateRate) {
updateGame(delta)
updateDeltaCounter -= updateRate
updateTries++
}
}
else {
updateGame(delta)
}
// TODO async update
updateGame(delta)
// render? just do it anyway
renderGame()

View File

@@ -82,7 +82,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
fun getCanonicalTitle() = AppLoader.GAME_NAME +
" — F: ${Gdx.graphics.framesPerSecond}" +
if (AppLoader.IS_DEVELOPMENT_BUILD)
"t${Terrarum.updateRateStr} / RT${Terrarum.renderRateStr})" +
"F${Terrarum.updateRateStr})" +
" — M: J${Terrarum.memJavaHeap}M / N${Terrarum.memNativeHeap}M / X${Terrarum.memXmx}M"
else
""
@@ -379,6 +379,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
LightmapRenderer.fireRecalculateEvent()
AppLoader.debugTimers["Ingame.updateCounter"] = 0
@@ -408,8 +409,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
itemOnGrip?.endSecondaryUse(delta)
}
protected val renderRate = Terrarum.renderRate
private var firstTimeRun = true
///////////////
@@ -422,6 +421,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
private var countdownToDeltaReset = 15 // number of frames
private var updateAkku = 0.0
override fun render(delta: Float) {
// Q&D solution for LoadScreen and Ingame, where while LoadScreen is working, Ingame now no longer has GL Context
@@ -443,7 +443,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
if (countdownToDeltaReset >= 0) {3
if (countdownToDeltaReset >= 0) {
if (countdownToDeltaReset == 0) {
AppLoader.resetDeltaSmoothingHistory()
}
@@ -456,20 +456,15 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/** UPDATE CODE GOES HERE */
updateAkku += AppLoader.getSmoothDelta()
if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements)
if (firstTimeRun || updateThreadWrapper.state == Thread.State.TERMINATED) {
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
updateThreadWrapper.start()
if (firstTimeRun) firstTimeRun = false
}
// else, NOP;
}
else {
var i = 0L
while (updateAkku >= delta) {
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateAkku -= delta
i += 1
}
AppLoader.debugTimers["Ingame.updateCounter"] = i
/** RENDER CODE GOES HERE */
@@ -543,6 +538,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun renderGame() {
Gdx.graphics.setTitle(getCanonicalTitle())
IngameRenderer.invoke(
world as GameWorldExtension,
actorsRenderBehind,

View File

@@ -406,9 +406,9 @@ open class ActorHumanoid(
avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f) * absAxisVal
if (absAxisVal != AXIS_KEYBOARD)
controllerMoveDelta?.x?.let { controllerMoveDelta!!.x = controllerMoveDelta!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap * absAxisVal) }
controllerV?.x?.let { controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap * absAxisVal) }
else
controllerMoveDelta?.x?.let { controllerMoveDelta!!.x = controllerMoveDelta!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap) }
controllerV?.x?.let { controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap) }
if (walkCounterX < 1000000) {
walkCounterX += 1
@@ -444,9 +444,9 @@ open class ActorHumanoid(
avAcceleration * applyVelo(walkCounterY) * (if (up) -1f else 1f) * absAxisVal
if (absAxisVal != AXIS_KEYBOARD)
controllerMoveDelta?.y?.let { controllerMoveDelta!!.y = controllerMoveDelta!!.y.plus(readonly_totalY).bipolarClamp(avSpeedCap * absAxisVal) }
controllerV?.y?.let { controllerV!!.y = controllerV!!.y.plus(readonly_totalY).bipolarClamp(avSpeedCap * absAxisVal) }
else
controllerMoveDelta?.y?.let { controllerMoveDelta!!.y = controllerMoveDelta!!.y.plus(readonly_totalY).bipolarClamp(avSpeedCap) }
controllerV?.y?.let { controllerV!!.y = controllerV!!.y.plus(readonly_totalY).bipolarClamp(avSpeedCap) }
if (walkCounterY < 1000000) {
walkCounterY += 1
@@ -489,6 +489,7 @@ open class ActorHumanoid(
private var oldJUMPPOWERBUFF = -1.0 // init
private var oldScale = -1.0
private var oldDragCoefficient = -1.0
// used by some AIs
var jumpAirTime: Double = -1.0
get() {
// compare all the affecting variables
@@ -519,7 +520,7 @@ open class ActorHumanoid(
val timedJumpCharge = jumpFunc(MAX_JUMP_LENGTH, jmpCtr)
forceVec.y -= getJumpAcc(jumpPower, timedJumpCharge)
forceVec.y += getDrag(1.0 / Terrarum.PHYS_REF_FPS, forceVec).y
forceVec.y += getDrag(AppLoader.UPDATE_RATE.toFloat(), forceVec).y
simYPos += forceVec.y // ignoring all the fluid drag OTHER THAN THE AIR
@@ -564,7 +565,7 @@ open class ActorHumanoid(
jumpAcc = getJumpAcc(jumpPower, timedJumpCharge)
controllerMoveDelta?.y?.let { controllerMoveDelta!!.y -= jumpAcc } // feed negative value to the vector
controllerV?.y?.let { controllerV!!.y -= jumpAcc } // feed negative value to the vector
// do not think of resetting this to zero when counter hit the ceiling; that's HOW NOT
// newtonian physics work, stupid myself :(
@@ -609,7 +610,7 @@ open class ActorHumanoid(
sprite?.update(delta)
spriteGlow?.update(delta)
if (walledBottom && controllerMoveDelta?.x != 0.0) {
if (walledBottom && controllerV?.x != 0.0) {
//switch row
sprite?.switchRow(SPRITE_ROW_WALK)
spriteGlow?.switchRow(SPRITE_ROW_WALK)
@@ -617,8 +618,8 @@ open class ActorHumanoid(
// set anim frame delay
// 4f of the divider is a magic number, empirically decided
if (this is HasAssembledSprite) {
sprite?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerMoveDelta?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
spriteGlow?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerMoveDelta?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
sprite?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerV?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
spriteGlow?.delays?.set(SPRITE_ROW_WALK, scale.sqrt().toFloat() / (4f * (controllerV?.x ?: 0.0001).abs().toFloat())) // FIXME empirical value
}

View File

@@ -10,7 +10,6 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Controllable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2018-01-17.
@@ -37,7 +36,7 @@ class PhysTestLuarLander : ActorWBMovable(RenderOrder.MIDTOP), Controllable {
super.update(delta)
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
controllerMoveDelta!!.y = avSpeedCap
controllerV!!.y = avSpeedCap
}
}

View File

@@ -9,7 +9,6 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld
import org.dyn4j.geometry.Vector2
import java.util.*
@@ -54,7 +53,7 @@ open class ProjectileSimple(
posPre = Point2d(fromPoint.x, fromPoint.y)
// lightbox sized 8x8 centered to the bullet
lightBoxList.add(Hitbox(-4.0, -4.0, 8.0, 8.0))
//this.externalForce.set(velocity)
//this.externalV.set(velocity)
damage = bulletDatabase[type][OFFSET_DAMAGE] as Int
displayColour = bulletDatabase[type][OFFSET_COL] as Color
@@ -64,7 +63,7 @@ open class ProjectileSimple(
setHitboxDimension(2, 2, 0, 0) // should be following sprite's properties if there IS one
externalForce.set((fromPoint to toPoint).setMagnitude(speed.toDouble()))
externalV.set((fromPoint to toPoint).setMagnitude(speed.toDouble()))

View File

@@ -150,8 +150,8 @@ object CollisionSolver {
// if they actually makes collision (e.g. player vs ball), solve it
if (a makesCollisionWith b) {
val a_moveDelta = a.externalForce + a.controllerMoveDelta
val b_moveDelta = b.externalForce + b.controllerMoveDelta
val a_moveDelta = a.externalV + a.controllerV
val b_moveDelta = b.externalV + b.controllerV
val ux_1 = a_moveDelta.x
val ux_2 = b_moveDelta.x

View File

@@ -108,11 +108,11 @@ class BasicDebugInfoWindow : UICanvas() {
+ ccG
+ "${WorldCamera.y}")
printLine(batch, 3, "veloX reported $ccG${player.externalForce.x}")
printLine(batch, 4, "veloY reported $ccG${player.externalForce.y}")
printLine(batch, 3, "veloX reported $ccG${player.externalV.x}")
printLine(batch, 4, "veloY reported $ccG${player.externalV.y}")
printLine(batch, 5, "p_WalkX $ccG${player.controllerMoveDelta?.x}")
printLine(batch, 6, "p_WalkY $ccG${player.controllerMoveDelta?.y}")
printLine(batch, 5, "p_WalkX $ccG${player.controllerV?.x}")
printLine(batch, 6, "p_WalkY $ccG${player.controllerV?.y}")
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")