Skip to content

Commit 90271c8

Browse files
committed
big build sim performance increase
1 parent c91ed77 commit 90271c8

File tree

11 files changed

+168
-94
lines changed

11 files changed

+168
-94
lines changed

src/main/kotlin/com/lambda/config/AutomationConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ open class AutomationConfig(
7272
fun automationConfig(name: String, edits: (AutomationConfig.() -> Unit)? = null): AutomationConfig =
7373
AutomationConfig("Default $name Automation Config").apply { edits?.invoke(this) }
7474

75-
object DEFAULT : AutomationConfig("Default Automation Config") {
75+
object DEFAULT : AutomationConfig("Default") {
7676
val renders by setting("Render", false).group(Group.Render)
7777
val avoidDesync by setting("Avoid Desync", true, "Cancels incoming inventory update packets if they match previous actions").group(Group.Debug)
7878
val desyncTimeout by setting("Desync Timeout", 30, 1..30, 1, unit = " ticks", description = "Time to store previous inventory actions before dropping the cache") { avoidDesync }.group(Group.Debug)

src/main/kotlin/com/lambda/gui/MenuBar.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.Lambda
2121
import com.lambda.Lambda.REPO_URL
2222
import com.lambda.Lambda.mc
2323
import com.lambda.command.CommandRegistry
24+
import com.lambda.config.AutomationConfig
2425
import com.lambda.config.Configuration
2526
import com.lambda.config.Configuration.Companion.configurables
2627
import com.lambda.config.UserAutomationConfig
@@ -34,6 +35,8 @@ import com.lambda.gui.components.HudGuiLayout
3435
import com.lambda.gui.components.QuickSearch
3536
import com.lambda.gui.components.SettingsWidget.buildConfigSettingsContext
3637
import com.lambda.gui.dsl.ImGuiBuilder
38+
import com.lambda.gui.dsl.ImGuiBuilder.popupContextItem
39+
import com.lambda.gui.dsl.ImGuiBuilder.selectable
3740
import com.lambda.interaction.BaritoneManager
3841
import com.lambda.module.ModuleRegistry
3942
import com.lambda.module.ModuleRegistry.moduleNameMap
@@ -73,7 +76,7 @@ object MenuBar {
7376
menu("HUD") { buildHudMenu() }
7477
menu("GUI") { buildGuiMenu() }
7578
menu("Modules") { buildModulesMenu() }
76-
menu("Automation Presets") { buildConfigPresetsMenu() }
79+
menu("Automation Configs") { buildConfigPresetsMenu() }
7780
menu("Minecraft") { buildMinecraftMenu() }
7881
menu("Help") { buildHelpMenu() }
7982
buildGitHubReference()
@@ -303,9 +306,15 @@ object MenuBar {
303306

304307
UserAutomationConfigs.configurables.forEach { config ->
305308
if (config !is UserAutomationConfig) throw java.lang.IllegalStateException("All configurables within UserAutomationConfigs must be UserAutomationConfigs!")
306-
selectable(config.name)
309+
buildAutomationConfigSelectable(config)
310+
}
311+
buildAutomationConfigSelectable(AutomationConfig.Companion.DEFAULT)
312+
}
307313

308-
popupContextItem("##automation-config-popup-${config.name}") {
314+
private fun buildAutomationConfigSelectable(config: AutomationConfig) {
315+
selectable(config.name)
316+
popupContextItem("##automation-config-popup-${config.name}") {
317+
if (config is UserAutomationConfig) {
309318
with(config.linkedModules) { buildLayout() }
310319
button("Delete") {
311320
config.linkedModules.value.forEach {
@@ -316,8 +325,8 @@ object MenuBar {
316325
UserAutomationConfigs.configurables.remove(config)
317326
}
318327
separator()
319-
buildConfigSettingsContext(config)
320328
}
329+
buildConfigSettingsContext(config)
321330
}
322331
}
323332

src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object BuildSimulator : Sim<PostSimResult>() {
4848
context(automatedSafeContext: AutomatedSafeContext)
4949
fun Structure.simulate(
5050
pov: Vec3d = automatedSafeContext.player.eyePos
51-
) : Set<BuildResult> = runBlocking(Dispatchers.Default) {
51+
): Set<BuildResult> = runBlocking(Dispatchers.Default) {
5252
supervisorScope {
5353
val concurrentSet = ConcurrentSet<BuildResult>()
5454

src/main/kotlin/com/lambda/interaction/construction/simulation/Sim.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.lambda.interaction.construction.result.BuildResult
2222
import com.lambda.interaction.construction.result.results.GenericResult
2323
import com.lambda.interaction.request.rotating.Rotation.Companion.rotationTo
2424
import com.lambda.interaction.request.rotating.visibilty.VisibilityChecker.CheckedHit
25+
import com.lambda.interaction.request.rotating.visibilty.VisibilityChecker.getClosestPoints
2526
import com.lambda.interaction.request.rotating.visibilty.VisibilityChecker.getVisibleSurfaces
2627
import com.lambda.interaction.request.rotating.visibilty.VisibilityChecker.scanSurfaces
2728
import com.lambda.util.math.distSq
@@ -102,26 +103,31 @@ abstract class Sim<T : BuildResult> : Results<T> {
102103
supervisorScope {
103104
boxes.forEach { box ->
104105
launch {
105-
val sides = if (buildConfig.checkSideVisibility || buildConfig.strictRayCast) {
106+
val sides = if (buildConfig.checkSideVisibility || buildConfig.strictRayCast)
106107
sides.intersect(box.getVisibleSurfaces(pov))
107-
} else sides
108-
109-
scanSurfaces(box, sides, buildConfig.resolution, preProcessing.surfaceScan) { side, vec ->
108+
else sides
109+
110+
if (!buildConfig.strictRayCast) {
111+
box.getClosestPoints(pov, sides, preProcessing.surfaceScan, placeConfig.airPlace.isEnabled) { vec, side ->
112+
if (pov distSq vec > reachSq)
113+
misses.add(Pair(vec, side))
114+
else {
115+
validHits.add(
116+
CheckedHit(
117+
BlockHitResult(vec, side, pos, false),
118+
pov.rotationTo(vec)
119+
)
120+
)
121+
}
122+
}
123+
} else box.scanSurfaces(sides, buildConfig.resolution, preProcessing.surfaceScan, false) { side, vec ->
110124
if (pov distSq vec > reachSq) {
111125
misses.add(Pair(vec, side))
112126
return@scanSurfaces
113127
}
114128

115129
val newRotation = pov.rotationTo(vec)
116-
117-
val hit = if (buildConfig.strictRayCast) {
118-
newRotation.rayCast(buildConfig.interactReach, pov)?.blockResult ?: return@scanSurfaces
119-
} else {
120-
val hitVec =
121-
if (buildConfig.checkSideVisibility) newRotation.castBox(box, buildConfig.interactReach, pov) ?: return@scanSurfaces
122-
else vec
123-
BlockHitResult(hitVec, side, pos, false)
124-
}
130+
val hit = newRotation.rayCast(buildConfig.interactReach, pov)?.blockResult ?: return@scanSurfaces
125131

126132
if (hit.blockPos != pos || hit.side != side) return@scanSurfaces
127133
val checked = CheckedHit(hit, newRotation)

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BreakSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
129129
val validHits = scanShape(pov, shape, pos, Direction.entries.toSet(), preProcessing) ?: return
130130

131131
val bestHit = buildConfig.pointSelection.select(validHits) ?: return
132-
val target = lookAt(bestHit.targetRotation)
132+
val target = lookAt(bestHit.rotation)
133133
val rotationRequest = RotationRequest(target, this)
134134

135135
val breakContext = BreakContext(

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PlaceSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
216216
val currentDirIsValid = testPlaceState(context) != null
217217

218218
if (!placeConfig.axisRotate) {
219-
fakePlayer.rotation = checkedHit.targetRotation
219+
fakePlayer.rotation = checkedHit.rotation
220220
return testPlaceState(context)?.let { RotatePlaceTest(it, currentDirIsValid, fakePlayer.rotation) }
221221
}
222222

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PostProcessingSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class PostProcessingSim private constructor(simInfo: ISimInfo)
151151
) {
152152
buildConfig.pointSelection.select(validHits)?.let { checkedHit ->
153153
val checkedResult = checkedHit.hit.blockResult ?: return
154-
val rotationTarget = lookAt(checkedHit.targetRotation)
154+
val rotationTarget = lookAt(checkedHit.rotation)
155155
val context = InteractContext(
156156
checkedResult,
157157
RotationRequest(rotationTarget, this),

src/main/kotlin/com/lambda/interaction/request/rotating/visibilty/PointSelection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum class PointSelection(
3333
"By Rotation",
3434
"Choose the point that needs the least rotation from your current view (minimal camera turn).",
3535
select = { hits ->
36-
hits.minByOrNull { RotationManager.activeRotation dist it.targetRotation }
36+
hits.minByOrNull { RotationManager.activeRotation dist it.rotation }
3737
}
3838
),
3939
Optimum(

src/main/kotlin/com/lambda/interaction/request/rotating/visibilty/RotationTargets.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ fun Automated.lookAtEntity(entity: LivingEntity): RotationTarget {
108108
player.eyePos,
109109
ALL_SIDES,
110110
SurfaceScan.DEFAULT,
111+
false,
111112
InteractionMask.Entity
112-
) { requestedHit.verifyHit(hit) }?.targetRotation
113+
) { requestedHit.verifyHit(hit) }?.rotation
113114
}
114115
}
115116
}
@@ -138,8 +139,9 @@ fun Automated.lookAtBlock(
138139
player.eyePos,
139140
sides,
140141
surfaceScan,
142+
false,
141143
InteractionMask.Block
142-
) { requestedHit.verifyHit(hit) }?.targetRotation
144+
) { requestedHit.verifyHit(hit) }?.rotation
143145
}
144146
}
145147
}

0 commit comments

Comments
 (0)