Fix line flickering in ancestral spade solver

This commit is contained in:
Linnea Gräf
2024-11-02 12:55:51 +01:00
parent 8b410fbdf2
commit c516c4b947
3 changed files with 89 additions and 90 deletions

View File

@@ -1,4 +1,3 @@
package moe.nea.firmament.features.diana package moe.nea.firmament.features.diana
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
@@ -23,109 +22,109 @@ import moe.nea.firmament.util.render.RenderInWorldContext
import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyBlockId
object AncestralSpadeSolver : SubscriptionOwner { object AncestralSpadeSolver : SubscriptionOwner {
var lastDing = TimeMark.farPast() var lastDing = TimeMark.farPast()
private set private set
private val pitches = mutableListOf<Float>() private val pitches = mutableListOf<Float>()
val particlePositions = mutableListOf<Vec3d>() val particlePositions = mutableListOf<Vec3d>()
var nextGuess: Vec3d? = null var nextGuess: Vec3d? = null
private set private set
val ancestralSpadeId = SkyblockId("ANCESTRAL_SPADE") val ancestralSpadeId = SkyblockId("ANCESTRAL_SPADE")
private var lastTeleportAttempt = TimeMark.farPast() private var lastTeleportAttempt = TimeMark.farPast()
fun isEnabled() = fun isEnabled() =
DianaWaypoints.TConfig.ancestralSpadeSolver DianaWaypoints.TConfig.ancestralSpadeSolver
&& SBData.skyblockLocation == SkyBlockIsland.HUB && SBData.skyblockLocation == SkyBlockIsland.HUB
&& MC.player?.inventory?.containsAny { it.skyBlockId == ancestralSpadeId } == true // TODO: add a reactive property here && MC.player?.inventory?.containsAny { it.skyBlockId == ancestralSpadeId } == true // TODO: add a reactive property here
@Subscribe @Subscribe
fun onKeyBind(event: WorldKeyboardEvent) { fun onKeyBind(event: WorldKeyboardEvent) {
if (!isEnabled()) return if (!isEnabled()) return
if (!event.matches(DianaWaypoints.TConfig.ancestralSpadeTeleport)) return if (!event.matches(DianaWaypoints.TConfig.ancestralSpadeTeleport)) return
if (lastTeleportAttempt.passedTime() < 3.seconds) return if (lastTeleportAttempt.passedTime() < 3.seconds) return
WarpUtil.teleportToNearestWarp(SkyBlockIsland.HUB, nextGuess ?: return) WarpUtil.teleportToNearestWarp(SkyBlockIsland.HUB, nextGuess ?: return)
lastTeleportAttempt = TimeMark.now() lastTeleportAttempt = TimeMark.now()
} }
@Subscribe @Subscribe
fun onParticleSpawn(event: ParticleSpawnEvent) { fun onParticleSpawn(event: ParticleSpawnEvent) {
if (!isEnabled()) return if (!isEnabled()) return
if (event.particleEffect != ParticleTypes.DRIPPING_LAVA) return if (event.particleEffect != ParticleTypes.DRIPPING_LAVA) return
if (event.offset.x != 0.0F || event.offset.y != 0F || event.offset.z != 0F) if (event.offset.x != 0.0F || event.offset.y != 0F || event.offset.z != 0F)
return return
particlePositions.add(event.position) particlePositions.add(event.position)
if (particlePositions.size > 20) { if (particlePositions.size > 20) {
particlePositions.removeFirst() particlePositions.removeFirst()
} }
} }
@Subscribe @Subscribe
fun onPlaySound(event: SoundReceiveEvent) { fun onPlaySound(event: SoundReceiveEvent) {
if (!isEnabled()) return if (!isEnabled()) return
if (!SoundEvents.BLOCK_NOTE_BLOCK_HARP.matchesId(event.sound.value().id)) return if (!SoundEvents.BLOCK_NOTE_BLOCK_HARP.matchesId(event.sound.value().id)) return
if (lastDing.passedTime() > 1.seconds) { if (lastDing.passedTime() > 1.seconds) {
particlePositions.clear() particlePositions.clear()
pitches.clear() pitches.clear()
} }
lastDing = TimeMark.now() lastDing = TimeMark.now()
pitches.add(event.pitch) pitches.add(event.pitch)
if (pitches.size > 20) { if (pitches.size > 20) {
pitches.removeFirst() pitches.removeFirst()
} }
if (particlePositions.size < 3) { if (particlePositions.size < 3) {
return return
} }
val averagePitchDelta = val averagePitchDelta =
if (pitches.isEmpty()) return if (pitches.isEmpty()) return
else pitches else pitches
.zipWithNext { a, b -> b - a } .zipWithNext { a, b -> b - a }
.average() .average()
val soundDistanceEstimate = (Math.E / averagePitchDelta) - particlePositions.first().distanceTo(event.position) val soundDistanceEstimate = (Math.E / averagePitchDelta) - particlePositions.first().distanceTo(event.position)
if (soundDistanceEstimate > 1000) { if (soundDistanceEstimate > 1000) {
return return
} }
val lastParticleDirection = particlePositions val lastParticleDirection = particlePositions
.takeLast(3) .takeLast(3)
.let { (a, _, b) -> b.subtract(a) } .let { (a, _, b) -> b.subtract(a) }
.normalize() .normalize()
nextGuess = event.position.add(lastParticleDirection.multiply(soundDistanceEstimate)) nextGuess = event.position.add(lastParticleDirection.multiply(soundDistanceEstimate))
} }
@Subscribe @Subscribe
fun onWorldRender(event: WorldRenderLastEvent) { fun onWorldRender(event: WorldRenderLastEvent) {
if (!isEnabled()) return if (!isEnabled()) return
RenderInWorldContext.renderInWorld(event) { RenderInWorldContext.renderInWorld(event) {
nextGuess?.let { nextGuess?.let {
color(1f, 1f, 0f, 0.5f) color(1f, 1f, 0f, 0.5f)
tinyBlock(it, 1f) tinyBlock(it, 1f)
color(1f, 1f, 0f, 1f) color(1f, 1f, 0f, 1f)
tracer(it, lineWidth = 3f) tracer(it, lineWidth = 3f)
} }
if (particlePositions.size > 2 && lastDing.passedTime() < 10.seconds && nextGuess != null) { if (particlePositions.size > 2 && lastDing.passedTime() < 10.seconds && nextGuess != null) {
color(0f, 1f, 0f, 0.7f) color(0f, 1f, 0f, 0.7f)
line(particlePositions) line(particlePositions)
} }
} }
} }
@Subscribe @Subscribe
fun onSwapWorld(event: WorldReadyEvent) { fun onSwapWorld(event: WorldReadyEvent) {
nextGuess = null nextGuess = null
particlePositions.clear() particlePositions.clear()
pitches.clear() pitches.clear()
lastDing = TimeMark.farPast() lastDing = TimeMark.farPast()
} }
override val delegateFeature: FirmamentFeature override val delegateFeature: FirmamentFeature
get() = DianaWaypoints get() = DianaWaypoints
} }

View File

@@ -172,7 +172,7 @@ class RenderInWorldContext private constructor(
points.zipWithNext().forEach { (a, b) -> points.zipWithNext().forEach { (a, b) ->
val normal = Vector3f(b.x.toFloat(), b.y.toFloat(), b.z.toFloat()) val normal = Vector3f(b.x.toFloat(), b.y.toFloat(), b.z.toFloat())
.sub(a.x.toFloat(), a.y.toFloat(), a.z.toFloat()) .sub(a.x.toFloat(), a.y.toFloat(), a.z.toFloat())
// .normalize() .normalize()
val lastNormal0 = lastNormal ?: normal val lastNormal0 = lastNormal ?: normal
lastNormal = normal lastNormal = normal
buffer.vertex(matrix.positionMatrix, a.x.toFloat(), a.y.toFloat(), a.z.toFloat()) buffer.vertex(matrix.positionMatrix, a.x.toFloat(), a.y.toFloat(), a.z.toFloat())

View File

@@ -37,7 +37,7 @@ void main() {
gl_Position = vec4(-2.0, -2.0, -2.0, 1.0); gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
return; // I don't care for these people return; // I don't care for these people
} }
if (linePosStartBehind || linePosEndBehind) { if ((linePosStartBehind || linePosEndBehind) && false) {
ndc1.z = 0.0; ndc1.z = 0.0;
ndc2.z = 0.0; ndc2.z = 0.0;
linePosStart.w = 1.0; linePosStart.w = 1.0;