allow non-pointers

This commit is contained in:
2026-10-12 23:13:49 +01:00
parent b7f83169e2
commit 23e3630491
18 changed files with 577 additions and 488 deletions
+45 -45
View File
@@ -12,7 +12,7 @@ use crate::{
#[derive(Clone, Debug)]
pub struct PointInterpreter<'csg> {
value_map: Vec<Value>,
csg: &'csg SSATape,
csg: &'csg SSATape,
}
impl PointInterpreter<'_> {
@@ -79,28 +79,28 @@ impl<'csg> PointInterpreter<'csg> {
match instruction.opcode.opcode {
SSAReturn => {
return self.load(instruction.inputs[0]);
},
}
SSAPosition => {
self.store(instruction.outputs[0], px);
self.store(instruction.outputs[1], py);
self.store(instruction.outputs[2], pz);
self.store(instruction.outputs[3], time);
},
}
SSAAdd => {
self.param_two(instruction, |val_a, val_b| val_a + val_b);
},
}
SSASub => {
self.param_two(instruction, |val_a, val_b| val_a - val_b);
},
}
SSAMul => {
self.param_two(instruction, |val_a, val_b| val_a * val_b);
},
}
SSADiv => {
self.param_two(instruction, |val_a, val_b| val_a / val_b);
},
}
SSAMod => {
self.param_two(instruction, |val_a, val_b| val_a % val_b);
},
}
SSAAtan2 => self.param_two(instruction, |val_a, val_b| {
let mut val_a = val_a.to_array();
let val_b = val_b.to_array();
@@ -111,11 +111,11 @@ impl<'csg> PointInterpreter<'csg> {
}),
SSAMin => {
self.param_two(instruction, |val_a, val_b| val_a.simd_min(val_b));
},
}
SSAMinMaterial => todo!(),
SSAMax => {
self.param_two(instruction, |val_a, val_b| val_a.simd_max(val_b));
},
}
SSAMaxMaterial => todo!(),
SSADot => {
let val_a = (0..instruction.opcode.size)
@@ -133,17 +133,17 @@ impl<'csg> PointInterpreter<'csg> {
(val_a[0] * val_b[0])
+ (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2])
},
}
4 => {
(val_a[0] * val_b[0])
+ (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2])
+ (val_a[3] * val_b[3])
},
}
_ => unreachable!(),
},
);
},
}
SSALength => {
let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize]))
@@ -165,7 +165,7 @@ impl<'csg> PointInterpreter<'csg> {
_ => unreachable!(),
},
);
},
}
SSADistance => {
let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize]))
@@ -194,97 +194,97 @@ impl<'csg> PointInterpreter<'csg> {
_ => unreachable!(),
},
);
},
}
SSANegate => {
self.param_one(instruction, |val_a| -val_a);
},
}
SSARound => {
self.param_one(instruction, |val_a| val_a.round());
},
}
SSAAbs => {
self.param_one(instruction, |val_a| val_a.abs());
},
}
SSAFloor => {
self.param_one(instruction, |val_a| val_a.floor());
},
}
SSACeil => {
self.param_one(instruction, |val_a| val_a.ceil());
},
}
SSAFract => {
self.param_one(instruction, glfract);
},
}
SSASin => {
self.param_one(instruction, |val_a| val_a.sin());
},
}
SSACos => {
self.param_one(instruction, |val_a| val_a.cos());
},
}
SSATan => {
self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.tan()))
});
},
}
SSAAsin => {
self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.asin()))
});
},
}
SSAAcos => {
self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.acos()))
});
},
}
SSAAtan => {
self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.atan()))
});
},
}
SSAExp => {
self.param_one(instruction, |val_a| val_a.exp());
},
}
SSALog => {
self.param_one(instruction, |val_a| val_a.ln());
},
}
SSASqrt => {
self.param_one(instruction, |val_a| val_a.sqrt());
},
}
SSASquare => {
self.param_one(instruction, |val_a| val_a * val_a);
},
}
SSACube => {
self.param_one(instruction, |val_a| val_a * val_a * val_a);
},
}
SSASmoothMin => {
self.param_three(instruction, |d1, d2, k| {
let h =
(VALUE_05 + (VALUE_05 * (d2 - d1) / k)).simd_clamp(VALUE_0, VALUE_1);
((d2 * (VALUE_1 - h)) + (d1 * h)) - k * h * (VALUE_1 - h)
});
},
}
SSASmoothMax => {
self.param_three(instruction, |d1, d2, k| {
let h =
(VALUE_05 - (VALUE_05 * (d2 + d1) / k)).simd_clamp(VALUE_0, VALUE_1);
((d2 * (VALUE_1 - h)) + (-d1 * h)) + k * h * (VALUE_1 - h)
});
},
}
SSASmoothMinMaterial => todo!(),
SSASmoothMaxMaterial => todo!(),
SSAClamp => {
self.param_three(instruction, |val_a, val_b, val_c| {
val_a.simd_clamp(val_b, val_c)
});
},
}
SSAMix => {
self.param_three(instruction, |val_a, val_b, val_c| {
(val_a * (VALUE_1 - val_c)) + (val_b * val_c)
});
},
}
SSAFMA => {
self.param_three(instruction, |val_a, val_b, val_c| {
val_a.mul_add(val_b, val_c)
});
},
}
SSASDFSphere => {
let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]);
@@ -294,7 +294,7 @@ impl<'csg> PointInterpreter<'csg> {
instruction.outputs[0],
((pos_x * pos_x) + (pos_y * pos_y) + (pos_z * pos_z)).sqrt() - radius,
);
},
}
SSASDFBox => {
let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]);
@@ -313,7 +313,7 @@ impl<'csg> PointInterpreter<'csg> {
((qxmax * qxmax) + (qymax * qymax) + (qzmax * qzmax)).sqrt()
+ qx.simd_max(qy.simd_max(qz)).simd_min(VALUE_0),
);
},
}
SSASDFTorus => {
let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]);
@@ -325,32 +325,32 @@ impl<'csg> PointInterpreter<'csg> {
instruction.outputs[0],
((q * q) + (pos_y * pos_y)).sqrt() - radius2,
);
},
}
SSACompare => {
self.param_two(instruction, |val_a, val_b| {
val_a
.simd_gt(val_b)
.select(VALUE_1, val_a.simd_lt(val_b).select(VALUE_M1, VALUE_0))
});
},
}
SSAAnd => {
self.param_two(instruction, |val_a, val_b| {
val_a.simd_eq(VALUE_0).select(val_a, val_b)
});
},
}
SSAOr => {
self.param_two(instruction, |val_a, val_b| {
val_a.simd_eq(VALUE_0).select(val_b, val_a)
});
},
}
SSARecip => {
self.param_one(instruction, |val_a| val_a.recip());
},
}
SSANot => {
self.param_one(instruction, |val_a| {
val_a.simd_eq(VALUE_0).select(VALUE_1, VALUE_0)
});
},
}
SSAStop => return VALUE_0,
}
}