@@ -33,6 +33,10 @@ import com.lambda.interaction.BaritoneManager
3333import com.lambda.interaction.request.Logger
3434import com.lambda.interaction.request.RequestHandler
3535import com.lambda.interaction.request.rotating.Rotation.Companion.slerp
36+ import com.lambda.interaction.request.rotating.RotationManager.activeRequest
37+ import com.lambda.interaction.request.rotating.RotationManager.activeRotation
38+ import com.lambda.interaction.request.rotating.RotationManager.serverRotation
39+ import com.lambda.interaction.request.rotating.RotationManager.updateActiveRotation
3640import com.lambda.interaction.request.rotating.visibilty.lookAt
3741import com.lambda.module.hud.ManagerDebugLoggers.rotationManagerLogger
3842import com.lambda.threading.runGameScheduled
@@ -53,6 +57,9 @@ import kotlin.math.atan2
5357import kotlin.math.cos
5458import kotlin.math.sin
5559
60+ /* *
61+ * Manager designed to rotate the player and adjust movement input to match the camera's direction.
62+ */
5663object RotationManager : RequestHandler<RotationRequest>(
5764 1 ,
5865 TickEvent .Pre ,
@@ -62,8 +69,7 @@ object RotationManager : RequestHandler<RotationRequest>(
6269), Logger {
6370 var activeRotation = Rotation .ZERO
6471 var serverRotation = Rotation .ZERO
65- @JvmStatic
66- var prevServerRotation = Rotation .ZERO
72+ @JvmStatic var prevServerRotation = Rotation .ZERO
6773 var baritoneRequest: RotationRequest ? = null
6874
6975 var activeRequest: RotationRequest ? = null
@@ -138,6 +144,12 @@ object RotationManager : RequestHandler<RotationRequest>(
138144 return " Loaded Rotation Manager"
139145 }
140146
147+ /* *
148+ * If the [activeRequest] is from an older tick or null, and the [request]'s target rotation is not null,
149+ * the request is accepted and set as the [activeRequest]. The [activeRotation] is then updated.
150+ *
151+ * @see updateActiveRotation
152+ */
141153 override fun AutomatedSafeContext.handleRequest (request : RotationRequest ) {
142154 activeRequest?.let { if (it.age <= 0 ) return }
143155 if (request.target.targetRotation.value != null ) {
@@ -148,6 +160,11 @@ object RotationManager : RequestHandler<RotationRequest>(
148160 }
149161 }
150162
163+ /* *
164+ * If the rotation has not been changed this tick, the [activeRequest]'s target rotation is updated, and
165+ * likewise the [activeRotation]. The [activeRequest] is then updated, ticking the [RotationRequest.keepTicks]
166+ * and [RotationRequest.decayTicks].
167+ */
151168 @JvmStatic
152169 fun processRotations () = runSafe {
153170 if (activeRequest != null ) activeThisTick = true
@@ -171,6 +188,11 @@ object RotationManager : RequestHandler<RotationRequest>(
171188 }
172189 }
173190
191+ /* *
192+ * Calculates and sets the optimal movement input for moving in the direction the player is facing. This
193+ * is not the direction the rotation manager is rotated towards, but the underlying player rotation, typically
194+ * also the camera's rotation.
195+ */
174196 @JvmStatic
175197 fun redirectStrafeInputs (input : Input ) = runSafe {
176198 if (activeRequest == baritoneRequest) return @runSafe
@@ -263,11 +285,15 @@ object RotationManager : RequestHandler<RotationRequest>(
263285 }
264286 }
265287
288+ /* *
289+ * Updates the [activeRotation]. If [activeRequest] is null, the player's rotation is used.
290+ * Otherwise, the [serverRotation] is interpolated towards the [RotationRequest.target] rotation.
291+ */
266292 private fun SafeContext.updateActiveRotation () {
267293 activeRotation = activeRequest?.let { request ->
268294 val rotationTo = if (request.keepTicks >= 0 )
269295 request.target.targetRotation.value
270- ? : activeRotation // same context gets used again && the rotation is null this tick
296+ ? : activeRotation // the same context gets used again && the rotation is null this tick
271297 else player.rotation
272298
273299 val speedMultiplier = if (request.keepTicks < 0 ) 1.0 else request.speedMultiplier
0 commit comments