mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
issue #16: walking fixed, jump not
This commit is contained in:
@@ -163,11 +163,9 @@ class SpriteAnimation(val parentActor: ActorWBMovable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun switchRow(newRow: Int) {
|
fun switchRow(newRow: Int) {
|
||||||
currentRow = newRow % nRows
|
if (newRow != currentRow) {
|
||||||
|
currentRow = newRow
|
||||||
//if beyond the frame index then reset
|
currentFrame = 1
|
||||||
if (currentFrame > nFrames[currentRow]) {
|
|
||||||
reset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ object Terrarum : Screen {
|
|||||||
* To be used with physics simulator
|
* To be used with physics simulator
|
||||||
*/
|
*/
|
||||||
val PHYS_TIME_FRAME: Double = 26.0 + (2.0 / 3.0)
|
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!!)
|
// 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
|
// 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
|
val TARGET_INTERNAL_FPS: Double = 60.0
|
||||||
|
|
||||||
internal val UPDATE_CATCHUP_MAX_TRIES = 1 // this feature does more harm than good...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -204,16 +204,17 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
// async update
|
// async update
|
||||||
updateDeltaCounter += delta
|
updateDeltaCounter += delta
|
||||||
var updateTries = 0
|
if (delta < 1f / 10f) { // discard async if measured FPS <= 10
|
||||||
while (updateDeltaCounter >= renderRate) {
|
var updateTries = 0
|
||||||
updateScreen(delta)
|
while (updateDeltaCounter >= renderRate && updateTries < 6) {
|
||||||
updateDeltaCounter -= renderRate
|
updateScreen(delta)
|
||||||
updateTries++
|
updateDeltaCounter -= renderRate
|
||||||
|
updateTries++
|
||||||
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
updateScreen(delta)
|
||||||
|
}
|
||||||
|
|
||||||
// render? just do it anyway
|
// render? just do it anyway
|
||||||
renderScreen()
|
renderScreen()
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package net.torvald.terrarum.gameactors
|
package net.torvald.terrarum.gameactors
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
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.spriteanimation.SpriteAnimation
|
import net.torvald.spriteanimation.SpriteAnimation
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
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.Block
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.blockproperties.BlockProp
|
import net.torvald.terrarum.blockproperties.BlockProp
|
||||||
@@ -352,6 +354,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
if (isUpdate && !flagDespawn) {
|
if (isUpdate && !flagDespawn) {
|
||||||
|
|
||||||
|
val ddelta = Gdx.graphics.deltaTime.toDouble()
|
||||||
if (!assertPrinted) assertInit()
|
if (!assertPrinted) assertInit()
|
||||||
|
|
||||||
if (sprite != null) sprite!!.update(delta)
|
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
|
* This body is NON-STATIC and the other body is STATIC
|
||||||
*/
|
*/
|
||||||
if (!isNoCollideWorld) {
|
if (!isNoCollideWorld) {
|
||||||
displaceHitbox()
|
displaceHitbox(ddelta)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
hitbox.translate(externalForce)
|
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 // //
|
// // HOW IT SHOULD WORK // //
|
||||||
// ////////////////////////
|
// ////////////////////////
|
||||||
// combineVeloToMoveDelta now
|
// combineVeloToMoveDelta now
|
||||||
@@ -625,7 +628,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
fun Double.modTileDelta() = this - this.modTile()
|
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
|
val ccdSteps = minOf(16, (vectorSum.magnitudeSquared / TILE_SIZE.sqr()).floorInt() + 1) // adaptive
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -161,35 +161,22 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||||
|
|
||||||
|
|
||||||
/** UPDATE CODE GOES HERE */
|
// async update
|
||||||
updateDeltaCounter += delta
|
updateDeltaCounter += delta
|
||||||
|
if (delta < 1f / 10f) { // discard async if measured FPS <= 10
|
||||||
|
|
||||||
|
|
||||||
if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements)
|
|
||||||
// else, NOP;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var updateTries = 0
|
var updateTries = 0
|
||||||
while (updateDeltaCounter >= updateRate) {
|
while (updateDeltaCounter >= updateRate) {
|
||||||
|
updateGame(delta)
|
||||||
//updateGame(delta)
|
|
||||||
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
|
||||||
|
|
||||||
updateDeltaCounter -= updateRate
|
updateDeltaCounter -= updateRate
|
||||||
updateTries++
|
updateTries++
|
||||||
|
|
||||||
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
updateGame(delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
// render? just do it anyway
|
||||||
|
renderGame()
|
||||||
/** RENDER CODE GOES HERE */
|
|
||||||
//renderGame(batch)
|
|
||||||
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateGame(delta: Float) {
|
private fun updateGame(delta: Float) {
|
||||||
|
|||||||
@@ -418,16 +418,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
///////////////
|
///////////////
|
||||||
private class ThreadIngameUpdate(val ingame: Ingame): Runnable {
|
private class ThreadIngameUpdate(val ingame: Ingame): Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
var updateTries = 0
|
TODO()
|
||||||
while (ingame.updateDeltaCounter >= ingame.renderRate) {
|
|
||||||
ingame.updateGame(Terrarum.deltaTime)
|
|
||||||
ingame.updateDeltaCounter -= ingame.renderRate
|
|
||||||
updateTries++
|
|
||||||
|
|
||||||
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,27 +460,24 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
// else, NOP;
|
// else, NOP;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var updateTries = 0
|
updateDeltaCounter += delta
|
||||||
val oldDeltaCtr = updateDeltaCounter
|
/*if (delta < 1f / 10f) { // discard async if measured FPS <= 10
|
||||||
while (updateDeltaCounter >= renderRate) {
|
var updateTries = 0
|
||||||
|
while (updateDeltaCounter >= renderRate && updateTries < 6) {
|
||||||
//updateGame(delta)
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
updateDeltaCounter -= renderRate
|
||||||
|
updateTries++
|
||||||
updateDeltaCounter -= renderRate
|
|
||||||
updateTries++
|
|
||||||
|
|
||||||
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
|
|
||||||
//printdbg(this, "Update couldn't catch up -- delta-T buildup was $oldDeltaCtr seconds")
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
|
}*/
|
||||||
|
|
||||||
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** RENDER CODE GOES HERE */
|
/** RENDER CODE GOES HERE */
|
||||||
//renderGame(batch)
|
|
||||||
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
||||||
AppLoader.debugTimers["Ingame.render-Light"] =
|
AppLoader.debugTimers["Ingame.render-Light"] =
|
||||||
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightTotal"] as? Long) ?: 0)
|
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightTotal"] as? Long) ?: 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user