From 589f639b3ff2b42e4725ab6a480fc56aa05499cf Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Mon, 31 Jan 2022 08:37:15 -0600 Subject: [PATCH] untested evaluator operators --- .../common/casting/CastingHarness.kt | 2 +- .../common/casting/OperatorSideEffect.kt | 24 ++++++------ .../common/casting/RegisterPatterns.java | 2 + .../common/casting/operators/OpForEach.kt | 12 ------ .../casting/operators/{ => eval}/OpEval.kt | 11 ++++-- .../operators/{ => eval}/OpEvalDelay.kt | 2 +- .../casting/operators/eval/OpForEach.kt | 39 +++++++++++++++++++ 7 files changed, 62 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/OpForEach.kt rename src/main/java/at/petrak/hexcasting/common/casting/operators/{ => eval}/OpEval.kt (82%) rename src/main/java/at/petrak/hexcasting/common/casting/operators/{ => eval}/OpEvalDelay.kt (86%) create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpForEach.kt diff --git a/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt b/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt index d1bba3bf..0156bba7 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/CastingHarness.kt @@ -122,7 +122,7 @@ class CastingHarness private constructor( /** * Apply the functional update. */ - private fun applyFunctionalData(data: FunctionalData) { + fun applyFunctionalData(data: FunctionalData) { this.stack.clear() this.stack.addAll(data.stack) this.parenCount = data.parenCount diff --git a/src/main/java/at/petrak/hexcasting/common/casting/OperatorSideEffect.kt b/src/main/java/at/petrak/hexcasting/common/casting/OperatorSideEffect.kt index 008d01b3..c63d3272 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/OperatorSideEffect.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/OperatorSideEffect.kt @@ -63,18 +63,18 @@ sealed class OperatorSideEffect { harness.ctx.caster, Random.nextFloat() * 256f, Vec3.ZERO - ) t - harness.ctx.world.sendParticles( - DustParticleOptions(Vector3f(Vec3.fromRGB24(color)), 1f), - position.x, - position.y, - position.z, - 1, - 0.1, - 0.1, - 0.1, - 0.1, - ) + ) + harness.ctx.world.sendParticles( + DustParticleOptions(Vector3f(Vec3.fromRGB24(color)), 1f), + position.x, + position.y, + position.z, + 1, + 0.1, + 0.1, + 0.1, + 0.1, + ) } return false diff --git a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java index 02f60b30..2c36d95b 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java +++ b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java @@ -5,6 +5,8 @@ import at.petrak.hexcasting.api.Operator; import at.petrak.hexcasting.api.PatternRegistry; import at.petrak.hexcasting.api.SpellDatum; import at.petrak.hexcasting.common.casting.operators.*; +import at.petrak.hexcasting.common.casting.operators.eval.OpEvalDelay; +import at.petrak.hexcasting.common.casting.operators.eval.OpForEach; import at.petrak.hexcasting.common.casting.operators.lists.OpAppend; import at.petrak.hexcasting.common.casting.operators.lists.OpConcat; import at.petrak.hexcasting.common.casting.operators.lists.OpIndex; diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpForEach.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/OpForEach.kt deleted file mode 100644 index f3e2396d..00000000 --- a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpForEach.kt +++ /dev/null @@ -1,12 +0,0 @@ -package at.petrak.hexcasting.common.casting.operators - -import at.petrak.hexcasting.api.OperationResult -import at.petrak.hexcasting.api.Operator -import at.petrak.hexcasting.api.SpellDatum -import at.petrak.hexcasting.common.casting.CastingContext - -object OpForEach : Operator { - override fun operate(stack: MutableList>, ctx: CastingContext): OperationResult { - return OperationResult(stack, listOf()) - } -} \ No newline at end of file diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpEval.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEval.kt similarity index 82% rename from src/main/java/at/petrak/hexcasting/common/casting/operators/OpEval.kt rename to src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEval.kt index fca7999f..7eba7328 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpEval.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEval.kt @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.common.casting.operators +package at.petrak.hexcasting.common.casting.operators.eval import at.petrak.hexcasting.api.OperationResult import at.petrak.hexcasting.api.Operator @@ -18,14 +18,17 @@ object OpEval : Operator { harness.stack.addAll(stack) val sideEffects = mutableListOf() - /* + for (pat in instrs) { val res = harness.getUpdate(pat.tryGet(), ctx.world) sideEffects.addAll(res.sideEffects) - + if (res.sideEffects.any { it is OperatorSideEffect.Mishap }) { + break + } + harness.applyFunctionalData(res.newData) } stack.addAll(harness.stack) - */ + return OperationResult(harness.stack, sideEffects) } } \ No newline at end of file diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpEvalDelay.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEvalDelay.kt similarity index 86% rename from src/main/java/at/petrak/hexcasting/common/casting/operators/OpEvalDelay.kt rename to src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEvalDelay.kt index a01c29db..6947ffab 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/operators/OpEvalDelay.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpEvalDelay.kt @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.common.casting.operators +package at.petrak.hexcasting.common.casting.operators.eval import at.petrak.hexcasting.api.OperationResult import at.petrak.hexcasting.api.Operator diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpForEach.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpForEach.kt new file mode 100644 index 00000000..0aa87aca --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/eval/OpForEach.kt @@ -0,0 +1,39 @@ +package at.petrak.hexcasting.common.casting.operators.eval + +import at.petrak.hexcasting.api.OperationResult +import at.petrak.hexcasting.api.Operator +import at.petrak.hexcasting.api.Operator.Companion.getChecked +import at.petrak.hexcasting.api.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.CastingHarness +import at.petrak.hexcasting.common.casting.OperatorSideEffect + +object OpForEach : Operator { + override fun operate(stack: MutableList>, ctx: CastingContext): OperationResult { + val instrs: List> = stack.getChecked(stack.lastIndex - 1) + val datums: List> = stack.getChecked(stack.lastIndex) + stack.removeLastOrNull() + stack.removeLastOrNull() + + val out = mutableListOf>() + val sideEffects = mutableListOf() + + for (subdatum in datums) { + ctx.incDepth() + val harness = CastingHarness(ctx) + harness.stack.addAll(stack) + for (pat in instrs) { + val res = harness.getUpdate(pat.tryGet(), ctx.world) + sideEffects.addAll(res.sideEffects) + if (res.sideEffects.any { it is OperatorSideEffect.Mishap }) { + break + } + harness.applyFunctionalData(res.newData) + } + out.addAll(harness.stack) + } + stack.add(SpellDatum.make(out)) + + return OperationResult(stack, sideEffects) + } +} \ No newline at end of file