mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
fixed a bug where player input can be ignored when framerate is significantly faster than update rate, which causes gameupdate to be called less often
This commit is contained in:
@@ -66,7 +66,62 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
private val mouseStatus = BitSet(8)
|
private val mouseStatus = BitSet(8)
|
||||||
private val controllerButtonStatus = BitSet(64)
|
private val controllerButtonStatus = BitSet(64)
|
||||||
|
|
||||||
fun update(delta: Float) {
|
private fun updateKeyboard() {
|
||||||
|
/////////////////////
|
||||||
|
// GAMEPAD CONTROL //
|
||||||
|
/////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// KEYBOARD CONTROL //
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
|
//KeyToggler.update(terrarumIngame.canPlayerControl)
|
||||||
|
//printdbg(this, terrarumIngame.canPlayerControl)
|
||||||
|
|
||||||
|
// control key events
|
||||||
|
var noKeyHeldDown = true
|
||||||
|
for (key in 1..Input.Keys.MAX_KEYCODE) {
|
||||||
|
val keyDown = Gdx.input.isKeyPressed(key)
|
||||||
|
|
||||||
|
noKeyHeldDown = noKeyHeldDown and keyDown
|
||||||
|
|
||||||
|
if (keyDown && !keyStatus[key])
|
||||||
|
tKeyDown(key)
|
||||||
|
else if (!keyDown && keyStatus[key])
|
||||||
|
tKeyUp(key)
|
||||||
|
|
||||||
|
keyStatus[key] = keyDown
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (key == Input.Keys.ENTER && keyDown) {
|
||||||
|
printdbg(this, "ENTER down")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// control mouse/touch events
|
||||||
|
val newmx = Gdx.input.x
|
||||||
|
val newmy = Gdx.input.y
|
||||||
|
for (touch in 0..4) {
|
||||||
|
val touchDown = Gdx.input.isButtonPressed(touch)
|
||||||
|
|
||||||
|
if (touchDown && !mouseStatus[touch])
|
||||||
|
tTouchDown(newmx, newmy, 0, touch)
|
||||||
|
else if (!touchDown && keyStatus[touch])
|
||||||
|
tTouchUp(newmx, newmy, 0, touch)
|
||||||
|
|
||||||
|
if (touchDown && mouseStatus.bitCount() != 0) {
|
||||||
|
tTouchDragged(newmx, newmy, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
mouseStatus[touch] = touchDown
|
||||||
|
}
|
||||||
|
|
||||||
|
inputMouseX = newmx
|
||||||
|
inputMouseY = newmy
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update() {
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// MOUSE CONTROL //
|
// MOUSE CONTROL //
|
||||||
@@ -100,52 +155,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
updateKeyboard()
|
||||||
// GAMEPAD CONTROL //
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////
|
|
||||||
// KEYBOARD CONTROL //
|
|
||||||
//////////////////////
|
|
||||||
|
|
||||||
//KeyToggler.update(terrarumIngame.canPlayerControl)
|
|
||||||
//printdbg(this, terrarumIngame.canPlayerControl)
|
|
||||||
|
|
||||||
// control key events
|
|
||||||
var noKeyHeldDown = true
|
|
||||||
for (key in 1..Input.Keys.MAX_KEYCODE) {
|
|
||||||
val keyDown = Gdx.input.isKeyPressed(key)
|
|
||||||
|
|
||||||
noKeyHeldDown = noKeyHeldDown and keyDown
|
|
||||||
|
|
||||||
if (keyDown && !keyStatus[key])
|
|
||||||
tKeyDown(key)
|
|
||||||
else if (!keyDown && keyStatus[key])
|
|
||||||
tKeyUp(key)
|
|
||||||
|
|
||||||
keyStatus[key] = keyDown
|
|
||||||
}
|
|
||||||
// control mouse/touch events
|
|
||||||
val newmx = Gdx.input.x
|
|
||||||
val newmy = Gdx.input.y
|
|
||||||
for (touch in 0..4) {
|
|
||||||
val touchDown = Gdx.input.isButtonPressed(touch)
|
|
||||||
|
|
||||||
if (touchDown && !mouseStatus[touch])
|
|
||||||
tTouchDown(newmx, newmy, 0, touch)
|
|
||||||
else if (!touchDown && keyStatus[touch])
|
|
||||||
tTouchUp(newmx, newmy, 0, touch)
|
|
||||||
|
|
||||||
if (touchDown && mouseStatus.bitCount() != 0) {
|
|
||||||
tTouchDragged(newmx, newmy, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseStatus[touch] = touchDown
|
|
||||||
}
|
|
||||||
|
|
||||||
inputMouseX = newmx
|
|
||||||
inputMouseY = newmy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var f12Down = false
|
private var f12Down = false
|
||||||
|
|||||||
@@ -516,6 +516,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
gameFullyLoaded = true
|
gameFullyLoaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ingameController.update()
|
||||||
|
|
||||||
|
|
||||||
// define custom update rate
|
// define custom update rate
|
||||||
val updateRate = if (KeyToggler.isOn(Input.Keys.APOSTROPHE)) 1f / 8f else AppLoader.UPDATE_RATE
|
val updateRate = if (KeyToggler.isOn(Input.Keys.APOSTROPHE)) 1f / 8f else AppLoader.UPDATE_RATE
|
||||||
|
|
||||||
@@ -554,7 +558,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// synchronised Ingame Input Updater
|
// synchronised Ingame Input Updater
|
||||||
// will also queue up the block/wall/wire placed events
|
// will also queue up the block/wall/wire placed events
|
||||||
ingameController.update(delta)
|
ingameController.update()
|
||||||
|
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import net.torvald.terrarum.imagefont.TinyAlphNum
|
|||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory
|
||||||
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
@@ -163,7 +164,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
|
|
||||||
val wireCount = wires?.size?.toString() ?: "no"
|
val wireCount = wires?.size?.toString() ?: "no"
|
||||||
|
|
||||||
printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX, $mtY)")
|
printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX,$mtY;$ccO${LandUtil.getBlockAddr(ingame!!.world, mouseTileX, mouseTileY)}$ccY)")
|
||||||
printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f")
|
printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user