Skip to main content

luaur_bytecode/methods/
bytecode_builder_add_constant_vector.rs

1use crate::enums::r#type::Type;
2use crate::records::bytecode_builder::BytecodeBuilder;
3use crate::records::constant::Constant;
4use crate::records::constant_key::ConstantKey;
5
6impl BytecodeBuilder {
7    pub fn add_constant_vector(&mut self, x: f32, y: f32, z: f32, w: f32) -> i32 {
8        let mut c = Constant {
9            r#type: Type::Type_Vector,
10            value: unsafe { core::mem::zeroed() },
11        };
12        // Store the actual components: the original left c.value zeroed, so vector
13        // constants always read back as (0,0,0,0), breaking vector-component folding.
14        c.value.valueVector = [x, y, z, w];
15
16        let mut k = ConstantKey {
17            r#type: Type::Type_Vector,
18            value: 0,
19            extra: 0,
20        };
21
22        k.value = x.to_bits() as u64;
23        k.value |= (y.to_bits() as u64) << 32;
24
25        k.extra = z.to_bits() as u64;
26        k.extra |= (w.to_bits() as u64) << 32;
27
28        self.add_constant(k, c)
29    }
30}