Skip to content

Commit b59ffe8

Browse files
committed
dependency tweaks
1 parent 70d1b71 commit b59ffe8

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface ISimInfo : Automated {
6161
SimInfo(
6262
pos, state, targetState,
6363
targetState.getProcessingInfo(pos) ?: return,
64-
pov, concurrentResults, Stack(), this
64+
pov, Stack(), concurrentResults, this
6565
).takeIf { it.checkRequirements() }?.sim(null, simBuilder)
6666
}
6767

@@ -77,7 +77,7 @@ interface ISimInfo : Automated {
7777
SimInfo(
7878
pos, state, targetState,
7979
targetState.getProcessingInfo(pos) ?: return,
80-
pov, concurrentResults, dependencyStack, this
80+
pov, dependencyStack, concurrentResults, this
8181
).takeIf { it.checkRequirements() }?.sim(dependable, simBuilder)
8282
}
8383

@@ -96,8 +96,8 @@ data class SimInfo(
9696
override val targetState: TargetState,
9797
override val preProcessing: PreProcessingInfo,
9898
override val pov: Vec3d,
99-
override val concurrentResults: MutableSet<BuildResult>,
10099
override val dependencyStack: Stack<Dependable>,
100+
override val concurrentResults: MutableSet<BuildResult>,
101101
private val automated: Automated
102102
) : ISimInfo, Automated by automated
103103

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ annotation class SimCheckerDsl
4444

4545
@SimCheckerDsl
4646
abstract class SimChecker<T : BuildResult> {
47-
protected fun ISimInfo.checkDependent(caller: Dependable?): Boolean {
48-
if (caller == null) {
49-
dependencyStack.clear()
50-
return true
47+
protected suspend fun ISimInfo.withDependable(dependable: Dependable?, block: suspend () -> Unit) {
48+
if (dependable == null) dependencyStack.clear()
49+
else {
50+
if (dependencyStack.size >= maxSimDependencies) return
51+
dependencyStack.push(dependable)
5152
}
52-
if (dependencyStack.size >= maxSimDependencies) return false
53-
dependencyStack.push(caller)
54-
return true
53+
block()
54+
if (dependable != null) dependencyStack.pop()
5555
}
5656

5757
fun ISimInfo.result(result: GenericResult) = addResult(result)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ class BreakSim private constructor(simInfo: ISimInfo)
7878
context(automatedSafeContext: AutomatedSafeContext, dependable: Dependable?)
7979
suspend fun SimBuilder.simBreak() =
8080
BreakSim(this).run {
81-
if (!checkDependent(dependable)) return
82-
automatedSafeContext.checkBreaks()
81+
withDependable(dependable) {
82+
automatedSafeContext.simBreaks()
83+
}
8384
}
8485
}
8586

86-
private suspend fun AutomatedSafeContext.checkBreaks() {
87+
private suspend fun AutomatedSafeContext.simBreaks() {
8788
if (breakConfig.avoidSupporting) player.supportingBlockPos.getOrNull()?.let { support ->
8889
if (support != pos) return@let
8990
result(BreakResult.PlayerOnTop(pos, state))

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ class PlaceSim private constructor(simInfo: ISimInfo)
8181
@SimBuilderDsl
8282
suspend fun SimBuilder.simPlacement() =
8383
PlaceSim(this).run {
84-
if (!checkDependent(dependable)) return
85-
automatedSafeContext.checkPlacements()
84+
withDependable(dependable) {
85+
automatedSafeContext.simPlacements()
86+
}
8687
}
8788
}
8889

89-
private suspend fun AutomatedSafeContext.checkPlacements() =
90+
private suspend fun AutomatedSafeContext.simPlacements() =
9091
supervisorScope {
9192
preProcessing.sides.forEach { side ->
9293
launch {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ class PostProcessingSim private constructor(simInfo: ISimInfo)
5757
@SimBuilderDsl
5858
suspend fun SimBuilder.simPostProcessing() =
5959
PostProcessingSim(this).run {
60-
if (!checkDependent(dependable)) return
61-
automatedSafeContext.checkPostProcessing()
60+
withDependable(dependable) {
61+
automatedSafeContext.simPostProcessing()
62+
}
6263
}
6364
}
6465

65-
private suspend fun AutomatedSafeContext.checkPostProcessing() {
66+
private suspend fun AutomatedSafeContext.simPostProcessing() {
6667
val targetState = (targetState as? TargetState.State) ?: return
6768

6869
val mismatchedProperties = state.properties.filter { state.get(it) != targetState.blockState.get(it) }

0 commit comments

Comments
 (0)