Very basic current world tick stats
parent
eff53837a3
commit
70f68202a6
@ -0,0 +1,66 @@
|
||||
package net.idylls.tickle
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
import net.runelite.api.World
|
||||
import net.runelite.api.Client
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
const val IDEAL_TICK_MS = 600
|
||||
const val BAD_TICK_THRESHOLD_MS = 60
|
||||
|
||||
class WorldStats {
|
||||
var tickCount = 0
|
||||
var badTickCount = 0
|
||||
|
||||
var averageTickTime = 0.0
|
||||
var worstTickDeviation = 0
|
||||
var lastTickTime = 0
|
||||
|
||||
fun track(tickTimeMs: Int) {
|
||||
this.averageTickTime = (
|
||||
(tickTimeMs + (this.averageTickTime * this.tickCount))
|
||||
/ (this.tickCount + 1)
|
||||
)
|
||||
|
||||
this.tickCount += 1
|
||||
this.lastTickTime = tickTimeMs
|
||||
|
||||
val tickDeviation = abs(tickTimeMs - IDEAL_TICK_MS)
|
||||
|
||||
if (this.worstTickDeviation < tickDeviation) {
|
||||
this.worstTickDeviation = tickDeviation
|
||||
}
|
||||
|
||||
if (tickDeviation > BAD_TICK_THRESHOLD_MS) {
|
||||
this.badTickCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typealias WorldId = Int
|
||||
|
||||
class WorldsStats
|
||||
@Inject constructor(
|
||||
val client: Client,
|
||||
) {
|
||||
val data = mutableMapOf<WorldId, WorldStats>()
|
||||
|
||||
fun current(): WorldStats? {
|
||||
val world = client.getWorld()
|
||||
if (world == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return this.get(world)
|
||||
}
|
||||
|
||||
fun get(worldId: WorldId): WorldStats {
|
||||
if (!data.contains(worldId)) {
|
||||
data.put(worldId, WorldStats())
|
||||
}
|
||||
|
||||
return data.get(worldId)!!
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue