Skip to content

Commit fb1ded1

Browse files
committed
Add render setting functionalities
1 parent c65dfb5 commit fb1ded1

File tree

5 files changed

+48
-25
lines changed

5 files changed

+48
-25
lines changed

common/src/main/kotlin/com/lambda/command/commands/PathCommand.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import com.lambda.brigadier.execute
2424
import com.lambda.brigadier.required
2525
import com.lambda.command.LambdaCommand
2626
import com.lambda.module.modules.movement.Pathfinder
27+
import com.lambda.util.Communication.info
2728
import com.lambda.util.extension.CommandBuilder
2829
import com.lambda.util.world.fastVectorOf
30+
import com.lambda.util.world.string
2931

3032
object PathCommand : LambdaCommand(
3133
name = "path",
@@ -41,10 +43,25 @@ object PathCommand : LambdaCommand(
4143
val dirty = fastVectorOf(x().value(), y().value(), z().value())
4244
Pathfinder.graph.markDirty(dirty)
4345
Pathfinder.graph.updateDirtyNode(dirty)
46+
this@PathCommand.info("Marked ${dirty.string} as dirty")
4447
}
4548
}
4649
}
4750
}
4851
}
52+
53+
required(literal("reset")) {
54+
execute {
55+
Pathfinder.graph.clear()
56+
this@PathCommand.info("Reset graph")
57+
}
58+
}
59+
60+
required(literal("update")) {
61+
execute {
62+
Pathfinder.needsUpdate = true
63+
this@PathCommand.info("Updating graph")
64+
}
65+
}
4966
}
5067
}

common/src/main/kotlin/com/lambda/module/modules/movement/Pathfinder.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import com.lambda.util.player.MovementUtils.buildMovementInput
5151
import com.lambda.util.player.MovementUtils.mergeFrom
5252
import com.lambda.util.world.FastVector
5353
import com.lambda.util.world.WorldUtils.hasSupport
54-
import com.lambda.util.world.WorldUtils.isPathClear
5554
import com.lambda.util.world.dist
5655
import com.lambda.util.world.fastVectorOf
5756
import com.lambda.util.world.toBlockPos
@@ -89,7 +88,7 @@ object Pathfinder : Module(
8988
private var currentTarget: Vec3d? = null
9089
private var integralError = Vec3d.ZERO
9190
private var lastError = Vec3d.ZERO
92-
private var needsUpdate = false
91+
var needsUpdate = false
9392
private var currentStart = BlockPos.ORIGIN.toFastVec()
9493

9594
private fun heuristic(u: FastVector): Double =
@@ -119,7 +118,8 @@ object Pathfinder : Module(
119118
listen<TickEvent.Pre> {
120119
val playerPos = player.blockPos
121120
val currentPos = playerPos.toFastVec()
122-
if (player.isOnGround && hasSupport(playerPos) && currentPos dist currentStart > pathing.tolerance) {
121+
val positionOutdated = currentPos dist currentStart > pathing.tolerance
122+
if (player.isOnGround && hasSupport(playerPos) && positionOutdated) {
123123
currentStart = currentPos
124124
needsUpdate = true
125125
}
@@ -177,7 +177,7 @@ object Pathfinder : Module(
177177
if (pathing.renderCoarsePath) coarsePath.render(event.renderer, Color.YELLOW)
178178
if (pathing.renderRefinedPath) refinedPath.render(event.renderer, Color.GREEN)
179179
if (pathing.renderGoal) event.renderer.buildFilled(Box(target.toBlockPos()), Color.PINK.setAlpha(0.25))
180-
if (pathing.renderGraph) graph.render(event.renderer, pathing.maxRenderObjects)
180+
graph.render(event.renderer, pathing)
181181
}
182182

183183
listen<RenderEvent.World> {
@@ -186,7 +186,7 @@ object Pathfinder : Module(
186186
Matrices.push {
187187
val c = mc.gameRenderer.camera.pos.negate()
188188
translate(c.x, c.y, c.z)
189-
graph.buildDebugInfoRenderer(pathing.maxRenderObjects)
189+
graph.buildDebugInfoRenderer(pathing)
190190
}
191191
}
192192
}

common/src/main/kotlin/com/lambda/pathing/PathingConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface PathingConfig {
4343
val renderRefinedPath: Boolean
4444
val renderGoal: Boolean
4545
val renderGraph: Boolean
46-
val renderWeights: Boolean
46+
val renderCost: Boolean
4747
val renderPositions: Boolean
4848
val maxRenderObjects: Int
4949
val assumeJesus: Boolean

common/src/main/kotlin/com/lambda/pathing/PathingSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PathingSettings(
5252
override val renderRefinedPath by c.setting("Render Refined Path", true) { vis() && page == Page.Misc }
5353
override val renderGoal by c.setting("Render Goal", true) { vis() && page == Page.Misc }
5454
override val renderGraph by c.setting("Render Graph", false) { vis() && page == Page.Misc }
55-
override val renderWeights by c.setting("Render Weights", false) { vis() && page == Page.Misc && renderGraph }
55+
override val renderCost by c.setting("Render Cost", false) { vis() && page == Page.Misc && renderGraph }
5656
override val renderPositions by c.setting("Render Positions", false) { vis() && page == Page.Misc && renderGraph }
5757
override val maxRenderObjects by c.setting("Max Render Objects", 1000, 0..100_000) { vis() && page == Page.Misc && renderGraph }
5858
override val assumeJesus by c.setting("Assume Jesus", false) { vis() && page == Page.Misc }

common/src/main/kotlin/com/lambda/pathing/dstar/LazyGraph.kt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.lambda.graphics.renderer.esp.builders.buildOutline
2525
import com.lambda.graphics.renderer.esp.global.StaticESP
2626
import com.lambda.graphics.renderer.gui.FontRenderer
2727
import com.lambda.graphics.renderer.gui.FontRenderer.drawString
28+
import com.lambda.pathing.PathingSettings
2829
import com.lambda.util.math.Vec2d
2930
import com.lambda.util.math.div
3031
import com.lambda.util.math.plus
@@ -105,37 +106,42 @@ class LazyGraph(
105106
predecessors.clear()
106107
}
107108

108-
fun render(renderer: StaticESP, maxElements: Int = 1000) {
109-
successors.entries.take(maxElements).forEach { (origin, neighbors) ->
109+
fun render(renderer: StaticESP, config: PathingSettings) {
110+
if (!config.renderGraph) return
111+
successors.entries.take(config.maxRenderObjects).forEach { (origin, neighbors) ->
110112
neighbors.forEach { (neighbor, _) ->
111113
renderer.buildLine(origin.toCenterVec3d(), neighbor.toCenterVec3d(), Color.PINK)
112114
}
113115
}
114-
dirtyNodes.take(maxElements).forEach { node ->
116+
dirtyNodes.take(config.maxRenderObjects).forEach { node ->
115117
renderer.buildOutline(Box.of(node.toCenterVec3d(), 0.2, 0.2, 0.2), Color.RED)
116118
}
117119
}
118120

119-
fun buildDebugInfoRenderer(maxElements: Int = 1000) {
120-
successors.entries.take(maxElements).forEach { (v, u) ->
121+
fun buildDebugInfoRenderer(config: PathingSettings) {
122+
successors.entries.take(config.maxRenderObjects).forEach { (v, u) ->
121123
val mode = Matrices.ProjRotationMode.TO_CAMERA
122124
val scale = 0.4
123-
val pos = v.toCenterVec3d()
124-
val nodeProjection = buildWorldProjection(pos, scale, mode)
125-
withVertexTransform(nodeProjection) {
126-
val msg = v.string
127-
drawString(msg, Vec2d(-FontRenderer.getWidth(msg) * 0.5, 0.0))
128-
}
129-
u.forEach { (neighbor, cost) ->
130-
val centerV = v.toCenterVec3d()
131-
val centerN = neighbor.toCenterVec3d()
132-
val center = (centerV + centerN) / 2.0
133-
val projection = buildWorldProjection(center, scale, mode)
134-
withVertexTransform(projection) {
135-
val msg = "c: %.3f".format(cost)
125+
if (config.renderPositions) {
126+
val pos = v.toCenterVec3d()
127+
val nodeProjection = buildWorldProjection(pos, scale, mode)
128+
withVertexTransform(nodeProjection) {
129+
val msg = v.string
136130
drawString(msg, Vec2d(-FontRenderer.getWidth(msg) * 0.5, 0.0))
137131
}
138132
}
133+
if (config.renderCost) {
134+
u.forEach { (neighbor, cost) ->
135+
val centerV = v.toCenterVec3d()
136+
val centerN = neighbor.toCenterVec3d()
137+
val center = (centerV + centerN) / 2.0
138+
val projection = buildWorldProjection(center, scale, mode)
139+
withVertexTransform(projection) {
140+
val msg = "c: %.3f".format(cost)
141+
drawString(msg, Vec2d(-FontRenderer.getWidth(msg) * 0.5, 0.0))
142+
}
143+
}
144+
}
139145
}
140146
}
141147
}

0 commit comments

Comments
 (0)