Use castle for vecmath (doesn't work fully yet)

This commit is contained in:
2026-01-04 17:13:58 +01:00
parent 21c1d2e139
commit fed1e982d2
23 changed files with 424 additions and 1894 deletions

View File

@@ -1,25 +1,19 @@
const std = @import("std");
const math = @import("math.zig");
const Vector2 = math.Vector2;
const Vector2x8 = math.Vector2x8;
const f32x8 = math.f32x8;
const i32x8 = math.i32x8;
const ps = math.ps;
const vm = @import("vecmath");
const Noise = struct {
horizontal_scale: f32,
value_median: f32,
value_amplitude: f32,
pub fn sample(self: Noise, seed: u64, pos: Vector2) f32 {
pub fn sample(self: Noise, seed: u64, pos: vm.Vector2) f32 {
return math.noise2(seed, pos.divScalar(self.horizontal_scale)) * self.value_amplitude + self.value_median;
}
pub fn samplev(self: Noise, seed: u64, pos: Vector2x8) f32x8 {
return math.noise2x8(seed, pos.divScalar(self.horizontal_scale)) * ps(self.value_amplitude) + ps(self.value_median);
pub fn samplev(self: Noise, seed: u64, pos: vm.Vector2x8) vm.f32x8 {
return math.noise2x8(seed, pos.divScalarSingle(self.horizontal_scale)) * vm.ps(self.value_amplitude) + vm.ps(self.value_median);
}
};
@@ -35,22 +29,22 @@ const noise_secondary: Noise = .{
.value_amplitude = 0.5,
};
pub fn heightF(seed: u64, pos: Vector2) f32 {
pub fn heightF(seed: u64, pos: vm.Vector2) f32 {
const main = noise_main.sample(seed, pos);
const secondary = noise_secondary.sample(seed, pos);
return @round(main + secondary);
}
pub fn heightFv(seed: u64, pos: Vector2x8) f32x8 {
pub fn heightFv(seed: u64, pos: vm.Vector2x8) vm.f32x8 {
const main = noise_main.samplev(seed, pos);
const secondary = noise_secondary.samplev(seed, pos);
return @round(main + secondary);
}
pub fn heightI(seed: u64, pos: Vector2) i32 {
pub fn heightI(seed: u64, pos: vm.Vector2) i32 {
return @intFromFloat(heightF(seed, pos));
}
pub fn heightIv(seed: u64, pos: Vector2x8) i32x8 {
pub fn heightIv(seed: u64, pos: vm.Vector2x8) vm.i32x8 {
return @intFromFloat(heightFv(seed, pos));
}