issue #16: walking fixed, jump not

This commit is contained in:
minjaesong
2019-01-19 16:44:59 +09:00
parent 5bf8b6cad7
commit d1a2e6b8f2
6 changed files with 41 additions and 65 deletions

View File

@@ -163,11 +163,9 @@ class SpriteAnimation(val parentActor: ActorWBMovable) {
}
fun switchRow(newRow: Int) {
currentRow = newRow % nRows
//if beyond the frame index then reset
if (currentFrame > nFrames[currentRow]) {
reset()
if (newRow != currentRow) {
currentRow = newRow
currentFrame = 1
}
}

View File

@@ -77,6 +77,8 @@ object Terrarum : Screen {
* To be used with physics simulator
*/
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
@@ -86,9 +88,6 @@ object Terrarum : Screen {
*/
val TARGET_INTERNAL_FPS: Double = 60.0
internal val UPDATE_CATCHUP_MAX_TRIES = 1 // this feature does more harm than good...

View File

@@ -204,16 +204,17 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
override fun render(delta: Float) {
// async update
updateDeltaCounter += delta
var updateTries = 0
while (updateDeltaCounter >= renderRate) {
updateScreen(delta)
updateDeltaCounter -= renderRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
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)
}
// render? just do it anyway
renderScreen()

View File

@@ -1,11 +1,13 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.Terrarum.PHYS_REF_FPS
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockProp
@@ -352,6 +354,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
override fun update(delta: Float) {
if (isUpdate && !flagDespawn) {
val ddelta = Gdx.graphics.deltaTime.toDouble()
if (!assertPrinted) assertInit()
if (sprite != null) sprite!!.update(delta)
@@ -401,7 +404,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
* This body is NON-STATIC and the other body is STATIC
*/
if (!isNoCollideWorld) {
displaceHitbox()
displaceHitbox(ddelta)
}
else {
hitbox.translate(externalForce)
@@ -559,7 +562,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
}
}*/
private fun displaceHitbox() {
private fun displaceHitbox(delta: Double) {
// // HOW IT SHOULD WORK // //
// ////////////////////////
// combineVeloToMoveDelta now
@@ -625,7 +628,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
fun Double.modTileDelta() = this - this.modTile()
val vectorSum = externalForce + controllerMoveDelta
val vectorSum = (externalForce + controllerMoveDelta) * PHYS_REF_FPS * delta //* PHYS_CONST_MULT
val ccdSteps = minOf(16, (vectorSum.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive

View File

@@ -161,35 +161,22 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
// ASYNCHRONOUS UPDATE AND RENDER //
/** UPDATE CODE GOES HERE */
// async update
updateDeltaCounter += delta
if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements)
// else, NOP;
}
else {
if (delta < 1f / 10f) { // discard async if measured FPS <= 10
var updateTries = 0
while (updateDeltaCounter >= updateRate) {
//updateGame(delta)
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateGame(delta)
updateDeltaCounter -= updateRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
}
else {
updateGame(delta)
}
/** RENDER CODE GOES HERE */
//renderGame(batch)
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
// render? just do it anyway
renderGame()
}
private fun updateGame(delta: Float) {

View File

@@ -418,16 +418,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
///////////////
private class ThreadIngameUpdate(val ingame: Ingame): Runnable {
override fun run() {
var updateTries = 0
while (ingame.updateDeltaCounter >= ingame.renderRate) {
ingame.updateGame(Terrarum.deltaTime)
ingame.updateDeltaCounter -= ingame.renderRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
TODO()
}
}
@@ -469,27 +460,24 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// else, NOP;
}
else {
var updateTries = 0
val oldDeltaCtr = updateDeltaCounter
while (updateDeltaCounter >= renderRate) {
//updateGame(delta)
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateDeltaCounter -= renderRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
//printdbg(this, "Update couldn't catch up -- delta-T buildup was $oldDeltaCtr seconds")
break
updateDeltaCounter += delta
/*if (delta < 1f / 10f) { // discard async if measured FPS <= 10
var updateTries = 0
while (updateDeltaCounter >= renderRate && updateTries < 6) {
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateDeltaCounter -= renderRate
updateTries++
}
}
else {
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
}*/
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
}
/** RENDER CODE GOES HERE */
//renderGame(batch)
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
AppLoader.debugTimers["Ingame.render-Light"] =
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightTotal"] as? Long) ?: 0)