From ffd470f2b4f2b350983c484f0e52826c34f8e7f0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 16 Feb 2024 17:10:53 +0900 Subject: [PATCH] fix: code for staircase climbing would interfere with hold-left/right-and-jump manoeuvre --- src/net/torvald/terrarum/CheckUpdate.kt | 23 +++++++++---- .../terrarum/gameactors/ActorWithBody.kt | 9 ++++- .../gameactors/ActorHumanoid.kt | 33 +++++++++++-------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/net/torvald/terrarum/CheckUpdate.kt b/src/net/torvald/terrarum/CheckUpdate.kt index 86eba7604..970f6ec03 100644 --- a/src/net/torvald/terrarum/CheckUpdate.kt +++ b/src/net/torvald/terrarum/CheckUpdate.kt @@ -11,6 +11,11 @@ import java.net.URL import java.net.http.HttpClient import java.net.http.HttpRequest import java.net.http.HttpResponse +import java.util.concurrent.Callable +import java.util.concurrent.Executors +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException /** * Created by minjaesong on 2023-10-03. @@ -35,14 +40,18 @@ object CheckUpdate { var ret: String? = null var fail: Throwable? = null - try { - // check the http connection before we do anything to the fs - val client = HttpClient.newBuilder().build() - val request = HttpRequest.newBuilder().uri(URI.create(url)).build() - val response = client.send(request, HttpResponse.BodyHandlers.ofString()) - ret = if (response.statusCode() >= 400) null else response.body() - printdbg(this, "HTTP ${response.statusCode()}") + try { + val callable = Callable { + // check the http connection before we do anything to the fs + val client = HttpClient.newBuilder().build() + val request = HttpRequest.newBuilder().uri(URI.create(url)).build() + val response = client.send(request, HttpResponse.BodyHandlers.ofString()) + ret = if (response.statusCode() >= 400) null else response.body() + printdbg(this, "HTTP ${response.statusCode()}") + } + val exec = Executors.newSingleThreadExecutor() + exec.submit(callable).get(5L, TimeUnit.SECONDS) } catch (e: Throwable) { fail = e diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 43390591c..a62300fca 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -1207,6 +1207,8 @@ open class ActorWithBody : Actor { IMPORTANT AF NOTE: things are ASYMMETRIC! */ + val canUseStairs = option and COLLIDING_LR != 0 && (externalV + (controllerV ?: Vector2())).y.absoluteValue < 1.0 + if (option.popcnt() == 1) { val (x1, x2, y1, y2) = hitbox.getWallDetection(option) @@ -1215,7 +1217,12 @@ open class ActorWithBody : Actor { val tyStart = y1/*.plus(HALF_PIXEL)*/.floorToInt() val tyEnd = y2/*.plus(HALF_PIXEL)*/.floorToInt() - return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, option == COLLIDING_BOTTOM).first == 2 + return isCollidingInternalStairs(txStart, tyStart, txEnd, tyEnd, option == COLLIDING_BOTTOM).first.let { status -> + if (canUseStairs) + status == 2 + else + status > 0 + } } else if (option == COLLIDING_ALLSIDE) { return isWalled(hitbox, COLLIDING_LEFT) || isWalled(hitbox, COLLIDING_RIGHT) || diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index 6eb591ea5..41234f067 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -482,6 +482,8 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L * @author minjaesong */ private fun walkHorizontal(left: Boolean, absAxisVal: Float) { + // Heading flag + walkHeading = if (left) LEFT else RIGHT if (avAcceleration.isNaN()) { @@ -489,30 +491,33 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L } - if (left && walledLeft || !left && walledRight) return + if (left && walledLeft || !left && walledRight) { + walkHStop() + controllerV?.x = 0.0 + } + else { + isWalkingH = true - readonly_totalX = + readonly_totalX = if (absAxisVal == AXIS_KEYBOARD) avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f) else avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f) * absAxisVal - if (absAxisVal != AXIS_KEYBOARD) - controllerV?.x?.let { controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap * absAxisVal) } - else - controllerV?.x?.let { controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap) } + if (absAxisVal != AXIS_KEYBOARD) + controllerV?.x?.let { + controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap * absAxisVal) + } + else + controllerV?.x?.let { controllerV!!.x = controllerV!!.x.plus(readonly_totalX).bipolarClamp(avSpeedCap) } - if (walkCounterX <= WALK_FRAMES_TO_MAX_ACCEL) { - walkCounterX += 1 + + if (walkCounterX <= WALK_FRAMES_TO_MAX_ACCEL) { + walkCounterX += 1 + } } - isWalkingH = true - - - - // Heading flag - walkHeading = if (left) LEFT else RIGHT } /**