Skip to content

Commit d9408e3

Browse files
committed
aligned keep ticks timings
1 parent e47a99f commit d9408e3

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

common/src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class RotationSettings(
3737
override var rotationMode by c.setting("Mode", RotationMode.Sync, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera, NONE - No rotation", vis)
3838

3939
/** How many ticks to keep the rotation before resetting */
40-
override val keepTicks by c.setting("Keep Rotation", 3, 0..10, 1, "Ticks to keep rotation", " ticks") { rotate && vis() }
40+
override val keepTicks by c.setting("Keep Rotation", 1, 1..10, 1, "Ticks to keep rotation", " ticks") { rotate && vis() }
4141

4242
/** How many ticks to wait before resetting the rotation */
43-
override val decayTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks") { rotate && vis() }
43+
override val decayTicks by c.setting("Reset Rotation", 1, 1..10, 1, "Ticks before rotation is reset", " ticks") { rotate && vis() }
4444

4545
/**
4646
* At what sub-tick stages rotations can be performed

common/src/main/kotlin/com/lambda/interaction/request/RequestHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract class RequestHandler<R : Request>(
7171
* opens the handler for requests for the duration of the given event
7272
*/
7373
private inline fun <reified T : Event> openRequestsFor(instance: KClass<out T>, stage: T) {
74-
listen(instance, priority = Int.MAX_VALUE - (accumulatedManagerPriority - stagePriority)) {
74+
listen(instance, priority = (Int.MAX_VALUE - 1) - (accumulatedManagerPriority - stagePriority)) {
7575
tickStage = stage
7676
queuedRequest?.let { request ->
7777
handleRequest(request)
@@ -83,7 +83,7 @@ abstract class RequestHandler<R : Request>(
8383
preEvent()
8484
}
8585

86-
listen(instance, priority = Int.MIN_VALUE + stagePriority) {
86+
listen(instance, priority = (Int.MIN_VALUE + 1) + stagePriority) {
8787
onClose?.invoke(this)
8888
acceptingRequests = false
8989
}

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ object HotbarManager : RequestHandler<HotbarRequest>(
5858
override fun load(): String {
5959
super.load()
6060

61+
listen<TickEvent>(priority = Int.MAX_VALUE) {
62+
activeRequest?.let { activeInfo ->
63+
if (activeInfo.keepTicks <= 0) {
64+
activeRequest = null
65+
}
66+
}
67+
}
68+
6169
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
6270
swapsThisTick = 0
6371
if (swapDelay > 0) swapDelay--
6472
val activeInfo = activeRequest ?: return@listen
6573

66-
if (activeInfo.keepTicks <= 0) {
67-
activeRequest = null
68-
}
69-
7074
activeInfo.swapPauseAge++
7175
activeInfo.activeRequestAge++
7276
activeInfo.keepTicks--
@@ -80,12 +84,6 @@ object HotbarManager : RequestHandler<HotbarRequest>(
8084
}
8185

8286
override fun SafeContext.handleRequest(request: HotbarRequest) {
83-
activeRequest?.let { activeInfo ->
84-
if (activeInfo.keepTicks <= 0) {
85-
activeRequest = null
86-
}
87-
}
88-
8987
val config = request.hotbar
9088
maxSwapsThisTick = config.swapsPerTick
9189
swapDelay = swapDelay.coerceAtMost(config.swapDelay)
@@ -113,12 +111,12 @@ object HotbarManager : RequestHandler<HotbarRequest>(
113111

114112
private fun SafeContext.checkResetSwap() {
115113
activeRequest?.let { activeInfo ->
116-
if (activeInfo.keepTicks <= 0) {
117-
if (tickStage in activeInfo.hotbar.sequenceStageMask) {
118-
interaction.syncSelectedSlot()
119-
}
120-
activeRequest = null
114+
if (activeInfo.keepTicks > 0) return
115+
116+
if (tickStage in activeInfo.hotbar.sequenceStageMask) {
117+
interaction.syncSelectedSlot()
121118
}
119+
activeRequest = null
122120
}
123121
}
124122

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ object RotationManager : RequestHandler<RotationRequest>(
7373
override fun load(): String {
7474
super.load()
7575

76+
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
77+
activeRequest?.let {
78+
if (it.keepTicks <= 0 && it.decayTicks <= 0) {
79+
activeRequest = null
80+
}
81+
}
82+
}
83+
7684
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
7785
activeRequest?.let { request ->
7886
request.age++
@@ -116,9 +124,8 @@ object RotationManager : RequestHandler<RotationRequest>(
116124

117125
// Tick and reset the context
118126
activeRequest?.let {
119-
if (--it.keepTicks > 0) return@let
120-
if (--it.decayTicks >= 0) return@let
121-
activeRequest = null
127+
if (it.keepTicks-- > 0) return@let
128+
it.decayTicks--
122129
}
123130
}
124131

0 commit comments

Comments
 (0)