-
Notifications
You must be signed in to change notification settings - Fork 37
Improvement: Manager and build sim docs #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9315d3f
4a6bd89
dccb0a8
0ca4d9e
3676ccf
675bd77
ee95c8b
2812266
1c80aaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,22 @@ import kotlinx.coroutines.runBlocking | |
| import kotlinx.coroutines.supervisorScope | ||
| import net.minecraft.util.math.Vec3d | ||
|
|
||
| /** | ||
| * The public API for simulating a blueprint. | ||
| */ | ||
| object BuildSimulator : Sim<PostSimResult>() { | ||
| /** | ||
| * Iterates over the blueprint and performs the best suited simulation. Each simulation adds [BuildResult]s to | ||
| * the provided concurrent set. This method uses coroutines to perform the simulations in parallel. The results | ||
| * will likely not be returned in the same order they were simulated due to the parallel nature of the simulations. | ||
| * | ||
| * @return A set of [BuildResult]s | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x |
||
| * | ||
| * @see ISimInfo.sim | ||
| * @see simPostProcessing | ||
| * @see simPlacement | ||
| * @see simBreak | ||
| */ | ||
| context(automatedSafeContext: AutomatedSafeContext) | ||
| fun Blueprint.simulate( | ||
| pov: Vec3d = automatedSafeContext.player.eyePos | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,11 +41,40 @@ import kotlin.math.pow | |
| @DslMarker | ||
| annotation class SimDsl | ||
|
|
||
| /** | ||
| * A class designed to simulate transforming a BlockState at a specified BlockPos to | ||
| * a TargetState. | ||
| * | ||
| * Some [Sim]s might need to call other sims as an intermediary between the current BlockState | ||
| * and the TargetState. In this case, we use a dependency system to ensure type safety. | ||
| * All sims must only return either [GenericResult]s or typed [BuildResult]s. For example, the BreakSim | ||
| * must only return BreakResults. For this reason, each type has its own Dependency result. | ||
| * To make sure that the results added are of the correct type, each [Sim] must be called from another [Sim]. | ||
| * Assuming the dependency stack has not reached max capacity, the original sim is then added to the dependency stack | ||
| * kept within the [SimInfo] object. Each [BuildResult] added is then iterated over the dependency stack, calling | ||
| * [dependentUpon] on each one. By the end, the result will be a nested group, with your initial [BuildResult] at | ||
| * the very bottom, which is then added to the [ISimInfo.concurrentResults] set. After a sim is completed, the dependency | ||
| * is then popped from the stack. | ||
| * | ||
| * @param T The type of [BuildResult] this sim produces. | ||
| * | ||
| * @see com.lambda.interaction.construction.result.Dependent | ||
| * @see dependentUpon | ||
| * @see withDependent | ||
| */ | ||
| @SimDsl | ||
| abstract class Sim<T : BuildResult> : Results<T> { | ||
| /** | ||
| * Can be overridden to return a typed Dependent result with the initial [buildResult] nested inside. | ||
| * | ||
| * @see com.lambda.interaction.construction.result.Dependent | ||
| */ | ||
| @SimDsl | ||
| open fun dependentUpon(buildResult: BuildResult): BuildResult = buildResult | ||
|
|
||
| /** | ||
| * Pushes and pops the [dependent] onto and off of the dependency stack unless the [maxSimDependencies] is reached. | ||
| */ | ||
| protected suspend fun ISimInfo.withDependent(dependent: Sim<*>, block: suspend () -> Unit) { | ||
| // +1 because the build sim counts as a dependent | ||
| if (dependencyStack.size >= maxSimDependencies + 1) return | ||
|
|
@@ -54,6 +83,11 @@ abstract class Sim<T : BuildResult> : Results<T> { | |
| dependencyStack.pop() | ||
| } | ||
|
|
||
| /** | ||
| * Scans a [voxelShape] on the given [sides] at the [pos] from the [pov]. | ||
| * | ||
| * @return A set of [CheckedHit] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x |
||
| */ | ||
| suspend fun ISimInfo.scanShape( | ||
| pov: Vec3d, | ||
| voxelShape: VoxelShape, | ||
|
|
@@ -91,7 +125,7 @@ abstract class Sim<T : BuildResult> : Results<T> { | |
| } | ||
|
|
||
| if (hit.blockPos != pos || hit.side != side) return@scanSurfaces | ||
| val checked = CheckedHit(hit, newRotation, buildConfig.interactReach) | ||
| val checked = CheckedHit(hit, newRotation) | ||
|
|
||
| validHits.add(checked) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,9 @@ class PostProcessingSim private constructor(simInfo: ISimInfo) | |
| InteractResult.Dependency(pos, buildResult) | ||
|
|
||
| companion object { | ||
| /** | ||
| * Public [SimDsl] API. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x |
||
| context(automatedSafeContext: AutomatedSafeContext, dependent: Sim<*>) | ||
| @SimDsl | ||
| suspend fun SimInfo.simPostProcessing() = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x