Skip to content

Commit 859e0d2

Browse files
committed
BreakInfo toString and more debug statements / edits
1 parent 03adc96 commit 859e0d2

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ abstract class DebugLogger(
6363
fun success(message: String) = log(message, LogType.Success)
6464
fun warning(message: String) = log(message, LogType.Warning)
6565
fun error(message: String) = log(message, LogType.Error)
66+
fun system(message: String) = log(message, LogType.System)
6667

6768
override fun ImGuiBuilder.buildLayout() {
6869
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
@@ -80,6 +81,7 @@ abstract class DebugLogger(
8081
LogType.Success -> textColored("[SUCCESS]", type.color)
8182
LogType.Warning -> textColored("[WARNING]", type.color)
8283
LogType.Error -> textColored("[ERROR]", type.color)
84+
LogType.System -> textColored("[SYSTEM]", type.color)
8385
}
8486

8587
sameLine()
@@ -102,20 +104,21 @@ abstract class DebugLogger(
102104
LogType.Success -> showSuccess
103105
LogType.Warning -> showWarning
104106
LogType.Error -> showError
107+
LogType.System -> true
105108
}
106109

107110
fun clear() = logs.clear()
108111

109-
110112
data class LogEntry(
111113
val message: String,
112114
val type: LogType
113115
)
114116

115117
enum class LogType(val color: Color) {
116-
Debug(Color.WHITE),
117-
Success(Color.GREEN),
118-
Warning(Color.YELLOW),
119-
Error(Color.RED)
118+
Debug(Color(255, 255, 255)),
119+
Success(Color(70, 255, 70)),
120+
Warning(Color(255, 255, 70)),
121+
Error(Color(255, 70, 70)),
122+
System(Color(70, 70, 255))
120123
}
121124
}

src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,6 @@ data class BreakInfo(
147147
sequence
148148
)
149149
}
150+
151+
override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}"
150152
}

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
4949
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak
5050
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary
5151
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Secondary
52+
import com.lambda.interaction.request.breaking.BreakManager.activeInfos
5253
import com.lambda.interaction.request.breaking.BreakManager.activeRequest
5354
import com.lambda.interaction.request.breaking.BreakManager.breakInfos
5455
import com.lambda.interaction.request.breaking.BreakManager.breaks
@@ -103,7 +104,12 @@ object BreakManager : RequestHandler<BreakRequest>(
103104
TickEvent.Input.Pre,
104105
TickEvent.Input.Post,
105106
TickEvent.Player.Post,
106-
onOpen = { processRequest(activeRequest); simulateAbandoned() },
107+
onOpen = {
108+
if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty())
109+
BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}")
110+
processRequest(activeRequest)
111+
simulateAbandoned()
112+
},
107113
onClose = { checkForCancels() }
108114
), PositionBlocking, Logger {
109115
private val breakInfos = arrayOfNulls<BreakInfo>(2)
@@ -178,6 +184,11 @@ object BreakManager : RequestHandler<BreakRequest>(
178184
override fun load(): String {
179185
super.load()
180186

187+
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
188+
if (activeInfos.isEmpty() && breaks.isEmpty() && instantBreaks.isEmpty()) return@listen
189+
logger.system("------------- New Tick -------------")
190+
}
191+
181192
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
182193
if (!swappedThisTick) {
183194
currentStack = player.mainHandStack
@@ -377,7 +388,7 @@ object BreakManager : RequestHandler<BreakRequest>(
377388
.forEach { info ->
378389
newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx ->
379390
if ((!info.updatedThisTick || info.type == RedundantSecondary) || info.abandoned) {
380-
logger.debug("Updating info for ${info.type}")
391+
logger.debug("Updating info for $info")
381392
if (info.type == RedundantSecondary)
382393
info.request.onStart?.invoke(info.context.blockPos)
383394
else if (info.abandoned) {
@@ -403,7 +414,7 @@ object BreakManager : RequestHandler<BreakRequest>(
403414
.filter { !it.instantBreak }
404415
.toMutableList()
405416

406-
logger.debug("${breaks.size} unprocessed instant breaks")
417+
logger.debug("${breaks.size} unprocessed breaks")
407418

408419
val breakConfig = request.config
409420
val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0)
@@ -429,7 +440,6 @@ object BreakManager : RequestHandler<BreakRequest>(
429440
activeInfos
430441
.filter { it.updatedThisTick }
431442
.let { infos ->
432-
if (infos.isNotEmpty()) logger.debug("Handling pre-processing")
433443
rotationRequest = infos.firstOrNull { info -> info.breakConfig.rotateForBreak }
434444
?.let { info ->
435445
val rotation = info.context.rotation
@@ -453,7 +463,7 @@ object BreakManager : RequestHandler<BreakRequest>(
453463
}
454464
logger.debug("Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID})")
455465
if (!hotbarRequest.done) {
456-
logger.debug("hotbar request failed (${hotbarRequest.requestID})")
466+
logger.warning("hotbar request failed (${hotbarRequest.requestID})")
457467
return false
458468
}
459469
if (minSwapTicks > 0) {
@@ -474,7 +484,7 @@ object BreakManager : RequestHandler<BreakRequest>(
474484
* @return false if a break could not be performed.
475485
*/
476486
private fun SafeContext.performInstantBreaks(request: BreakRequest): Boolean {
477-
if (instantBreaks.isNotEmpty()) logger.debug("Processing instant breaks")
487+
if (instantBreaks.isNotEmpty()) logger.debug("Processing instant breaks ${instantBreaks.size}")
478488
val iterator = instantBreaks.iterator()
479489
while (iterator.hasNext()) {
480490
if (breaksThisTick + 1 > maxBreaksThisTick) return false
@@ -503,7 +513,7 @@ object BreakManager : RequestHandler<BreakRequest>(
503513
* @see initNewBreak
504514
*/
505515
private fun SafeContext.processNewBreaks(request: BreakRequest): Boolean {
506-
if (breaks.isNotEmpty()) logger.debug("Processing new breaks")
516+
if (breaks.isNotEmpty()) logger.debug("Processing new breaks ${breaks.size}")
507517
val iterator = breaks.iterator()
508518
while (iterator.hasNext()) {
509519
val ctx = iterator.next()
@@ -538,6 +548,7 @@ object BreakManager : RequestHandler<BreakRequest>(
538548

539549
if (!primaryInfo.breaking) {
540550
secondaryBreak = breakInfo.apply { type = Secondary }
551+
logger.success("Initialized $secondaryBreak")
541552
return secondaryBreak
542553
}
543554

@@ -549,6 +560,7 @@ object BreakManager : RequestHandler<BreakRequest>(
549560

550561
primaryBreak = breakInfo
551562
setPendingConfigs(request.build)
563+
logger.success("Initialized $primaryBreak")
552564
return primaryBreak
553565
}
554566

@@ -632,7 +644,7 @@ object BreakManager : RequestHandler<BreakRequest>(
632644
}
633645

634646
private fun BreakInfo.updatePreProcessing(player: ClientPlayerEntity, world: BlockView) {
635-
logger.debug("Updating pre-processing for $type")
647+
logger.debug("Updating pre-processing for $this")
636648

637649
shouldProgress = !progressedThisTick
638650
&& tickStage in breakConfig.breakStageMask
@@ -661,20 +673,20 @@ object BreakManager : RequestHandler<BreakRequest>(
661673
if (type == RedundantSecondary || abandoned) return@runSafe
662674
when (type) {
663675
Primary -> {
664-
logger.debug("Cancelling $type")
676+
logger.warning("Cancelling ${this@cancelBreak}")
665677
nullify()
666678
setBreakingTextureStage(player, world, -1)
667679
abortBreakPacket(world, interaction)
668680
request.onCancel?.invoke(context.blockPos)
669681
}
670682
Secondary -> {
671683
if (breakConfig.unsafeCancels) {
672-
logger.warning("Making $type redundant")
684+
logger.warning("Making ${this@cancelBreak} redundant")
673685
type = RedundantSecondary
674686
setBreakingTextureStage(player, world, -1)
675687
request.onCancel?.invoke(context.blockPos)
676688
} else {
677-
logger.debug("Abandoning $type")
689+
logger.warning("Abandoning ${this@cancelBreak}")
678690
abandoned = true
679691
}
680692
}
@@ -774,7 +786,7 @@ object BreakManager : RequestHandler<BreakRequest>(
774786

775787
val swing = config.swing
776788
if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) {
777-
logger.success("Breaking ${info.type} ${info.context.cachedState}")
789+
logger.success("Breaking $info")
778790
if (info.type == Primary) {
779791
onBlockBreak(info)
780792
info.stopBreakPacket(world, interaction)

0 commit comments

Comments
 (0)