untested evaluator operators

This commit is contained in:
gamma-delta 2022-01-31 08:37:15 -06:00
parent a70b5b70c1
commit 589f639b3f
7 changed files with 62 additions and 30 deletions

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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<SpellDatum<*>>, ctx: CastingContext): OperationResult {
return OperationResult(stack, listOf())
}
}

View file

@ -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<OperatorSideEffect>()
/*
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)
}
}

View file

@ -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

View file

@ -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<SpellDatum<*>>, ctx: CastingContext): OperationResult {
val instrs: List<SpellDatum<*>> = stack.getChecked(stack.lastIndex - 1)
val datums: List<SpellDatum<*>> = stack.getChecked(stack.lastIndex)
stack.removeLastOrNull()
stack.removeLastOrNull()
val out = mutableListOf<SpellDatum<*>>()
val sideEffects = mutableListOf<OperatorSideEffect>()
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)
}
}