[cleanup] Usages of LinkedList

This commit is contained in:
Xiaro 2021-01-10 20:59:44 -05:00
parent 721997d5a7
commit 4ea6fd9d63
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
4 changed files with 18 additions and 12 deletions

View File

@ -13,6 +13,7 @@ import org.kamiblue.commons.extension.floorToInt
import org.lwjgl.input.Mouse
import org.lwjgl.opengl.GL11.*
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max
open class ListWindow(
@ -24,7 +25,7 @@ open class ListWindow(
saveToConfig: SettingGroup,
vararg childrenIn: Component
) : TitledWindow(name, posX, posY, width, height, saveToConfig) {
val children = LinkedList<Component>()
val children = ArrayList<Component>()
override val minWidth = 80.0f
override val minHeight = 200.0f

View File

@ -6,6 +6,7 @@ import me.zeroeightsix.kami.util.math.Vec2f
import me.zeroeightsix.kami.util.threads.safeListener
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.math.abs
import kotlin.math.roundToInt
import kotlin.math.sign
@ -29,8 +30,8 @@ object ViewLock : Module(
private var yawSnap = 0
private var pitchSnap = 0
private val deltaXQueue = LinkedList<Pair<Float, Long>>()
private val deltaYQueue = LinkedList<Pair<Float, Long>>()
private val deltaXQueue = ArrayDeque<Pair<Float, Long>>()
private val deltaYQueue = ArrayDeque<Pair<Float, Long>>()
private var pitchSliceAngle = 1.0f
private var yawSliceAngle = 1.0f
@ -66,7 +67,7 @@ object ViewLock : Module(
)
}
private fun handleDelta(delta: Float, list: LinkedList<Pair<Float, Long>>, slice: Float): Int {
private fun handleDelta(delta: Float, list: ArrayDeque<Pair<Float, Long>>, slice: Float): Int {
val currentTime = System.currentTimeMillis()
list.add(Pair(delta * 0.15f, currentTime))
@ -75,8 +76,8 @@ object ViewLock : Module(
list.clear()
sign(sum).toInt()
} else {
while (list.peek().second < currentTime - 500) {
list.remove()
while (list.first().second < currentTime - 500) {
list.removeFirstOrNull()
}
0
}

View File

@ -9,6 +9,7 @@ import net.minecraft.util.math.Vec3d
import net.minecraft.world.World
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.*
import kotlin.collections.ArrayDeque
/**
* Tracking the motion of an Entity tick by tick
@ -21,7 +22,7 @@ class MotionTracker(targetIn: Entity?, private val trackLength: Int = 20) {
field = value
}
}
private val motionLog = LinkedList<Vec3d>()
private val motionLog = ArrayDeque<Vec3d>()
private var prevMotion = Vec3d(0.0, 0.0, 0.0)
private var motion = Vec3d(0.0, 0.0, 0.0)
private val lockObject = Any()
@ -32,7 +33,7 @@ class MotionTracker(targetIn: Entity?, private val trackLength: Int = 20) {
synchronized(lockObject) {
target?.let { target ->
motionLog.add(calcActualMotion(target))
while (motionLog.size > trackLength) motionLog.pollFirst()
while (motionLog.size > trackLength) motionLog.removeFirstOrNull()
prevMotion = motion
motion = calcAverageMotion()
}

View File

@ -7,12 +7,11 @@ import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import org.lwjgl.opengl.GL11.*
import org.lwjgl.opengl.GL12.*
import java.util.*
object GlStateUtils {
private val mc = Wrapper.minecraft
private var lastScissor: Quad<Int, Int, Int, Int>? = null
private val scissorList = LinkedList<Quad<Int, Int, Int, Int>>()
private val scissorList = ArrayList<Quad<Int, Int, Int, Int>>()
fun scissor(x: Int, y: Int, width: Int, height: Int) {
lastScissor = Quad(x, y, width, height)
@ -20,11 +19,15 @@ object GlStateUtils {
}
fun pushScissor() {
lastScissor?.let { scissorList.add(it) }
lastScissor?.let {
scissorList.add(it)
}
}
fun popScissor() {
scissorList.pollLast()?.let { scissor(it.first, it.second, it.third, it.fourth) }
scissorList.removeLastOrNull()?.let {
scissor(it.first, it.second, it.third, it.fourth)
}
}
@JvmStatic