basic frametime is back

This commit is contained in:
2025-10-15 19:43:02 -04:00
parent fa25081d63
commit bc742b2116
5 changed files with 184 additions and 100 deletions

View File

@@ -13,6 +13,8 @@ import "base:intrinsics"
import "core:math"
import la "core:math/linalg"
@private IS_NUMERIC :: intrinsics.type_is_numeric
Axis2 :: enum i32 {
Invalid = -1,
X = 0,
@@ -48,7 +50,7 @@ is_power_of_two_u32 :: #force_inline proc "contextless" (value: u32) -> b32 { re
mov_avg_exp_f32 := #force_inline proc "contextless" (alpha, delta_interval, last_value: f32) -> f32 { return (delta_interval * alpha) + (delta_interval * (1.0 - alpha)) }
mov_avg_exp_f64 := #force_inline proc "contextless" (alpha, delta_interval, last_value: f64) -> f64 { return (delta_interval * alpha) + (delta_interval * (1.0 - alpha)) }
Q_F4 :: quaternion128
Quat_F4 :: quaternion128
V2_S4 :: [2]i32
V3_S4 :: [3]i32
@@ -68,10 +70,25 @@ sub_r2f4 :: #force_inline proc "contextless" (a, b: R2_F4) -> R2_F4 { return r
equal_r2f4 :: #force_inline proc "contextless" (a, b: R2_F4) -> b32 { result := a.p0 == b.p0 && a.p1 == b.p1; return b32(result) }
// Will resolve the largest range possible given a & b.
join_r2f4 :: #force_inline proc "contextless" (a, b: R2_F4) -> (joined : R2_F4) { joined.p0 = min( a.min, b.min ); joined.p1 = max( a.max, b.max ); return }
size_range2 :: #force_inline proc "contextless" (value: R2_F4) -> V2_F4 { return { abs( value.p1.x - value.p0.x ), abs( value.p0.y - value.p1.y ) } }
join_r2f4 :: #force_inline proc "contextless" (a, b: R2_F4) -> (joined : R2_F4) { joined.p0 = min(a.p0, b.p0); joined.p1 = max(a.p1, b.p1); return }
size_r2f4 :: #force_inline proc "contextless" (value: R2_F4) -> V2_F4 { return {abs(value.p1.x - value.p0.x), abs(value.p0.y - value.p1.y) }}
cross_s :: la.scalar_cross
min :: la.min
max :: la.max
sqrt :: la.sqrt
sdot :: la.scalar_dot
vdot :: la.vector_dot
qdot_f2 :: la.quaternion64_dot
qdot_f4 :: la.quaternion128_dot
qdot_f8 :: la.quaternion256_dot
inner_product :: dot
outer_product :: intrinsics.outer_product
cross_s :: la.scalar_cross
cross_v2 :: la.vector_cross2
cross_v3 :: la.vector_cross3
/*
V2_F2: 2D Vector (4-Byte Float) 4D Extension (x, y, z : 0, w : 0)
@@ -92,24 +109,6 @@ v2f4_from_scalar :: #force_inline proc "contextless" (scalar: f32 ) -> V2_F4 {
v2f4_from_v2s4 :: #force_inline proc "contextless" (v2i: V2_S4) -> V2_F4 { return {f32(v2i.x), f32(v2i.y)}}
v2s4_from_v2f4 :: #force_inline proc "contextless" (v2: V2_F4) -> V2_S4 { return {i32(v2.x), i32(v2.y) }}
// vec2_64_from_vec2 :: #force_inline proc "contextless" ( v2 : Vec2 ) -> Vec2_64 { return { f64(v2.x), f64(v2.y) }}
// dot_v2f4 :: #force_inline proc "contextless" (a, b: V2_F4) -> (s: f32) {
// x := a.x * b.x
// y := a.y + b.y
// s = x + y
// return
// }
sdot :: la.scalar_dot
vdot :: la.vector_dot
qdot_f2 :: la.quaternion64_dot
qdot_f4 :: la.quaternion128_dot
qdot_f8 :: la.quaternion256_dot
inner_product :: dot
outer_product :: intrinsics.outer_product
cross_v2 :: la.vector_cross2
/*
PointFlat2 : CGA: 2D flat point (x, y, z)
Line : PGA: 2D line (x, y, z)
@@ -119,9 +118,6 @@ P2_F4 :: distinct V2_F4
PF2_F4 :: distinct V3_F4
L2_F4 :: distinct V3_F4
//endregion PGA 2
//region PGA 3
/*
V3_F4: 3D Vector (x, y, z) (3x1) 4D Expression : (x, y, z, 0)
BiV3_F4: 3D Bivector (yz, zx, xy) (3x1)
@@ -165,31 +161,29 @@ v3f4_via_f32s :: #force_inline proc "contextless" (x, y, z: f32) -> V3_F4 { retu
// complement_vec3 :: #force_inline proc "contextless" ( v : Vec3 ) -> Bivec3 {return transmute(Bivec3) v}
cross_v3 :: la.vector_cross3
inverse_mag_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (result : f32) { square := pow2_v3f4(v); result = inverse_sqrt_f32( square ); return }
magnitude_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (mag: f32) { square := pow2_v3f4(v); mag = sqrt(square); return }
normalize_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (unit_v: UV3_F4) { unit_v = transmute(UnitVec3) (v * inverse_mag_v3f4(v)); return }
normalize_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (unit_v: UV3_F4) { unit_v = transmute(UV3_F4) (v * inverse_mag_v3f4(v)); return }
pow2_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (s: f32) { return dot_v3f4(v, v) }
pow2_v3f4 :: #force_inline proc "contextless" (v: V3_F4) -> (s: f32) { return vdot(v, v) }
project_v3f4 :: proc "contextless" (a, b: V3_F4) -> (a_to_b: V3_F4) { panic_contextless("not implemented"); return }
reject_v3f4 :: proc "contextless" (a, b: V3_F4 ) -> (a_from_b: V3_F4) { panic_contextless("not implemented"); return }
project_v3f4 :: proc "contextless" (a, b: V3_F4) -> (a_to_b: V3_F4) { panic_contextless("not implemented") }
reject_v3f4 :: proc "contextless" (a, b: V3_F4 ) -> (a_from_b: V3_F4) { panic_contextless("not implemented") }
project_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> (v_to_u: V3_F4) { inner := dot_v3f4(v, u); v_to_u = (transmute(V3_F4) u) * inner; return }
project_uv3f4_v3f4 :: #force_inline proc "contextless" (u : UV3_F4, v : V3_F4) -> (u_to_v: V3_F4) { inner := dot_v3f4(u, v); u_to_v = v * inner; return }
project_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> (v_to_u: V3_F4) { inner := vdot(v, v3(u)); v_to_u = v3(u) * inner; return }
project_uv3f4_v3f4 :: #force_inline proc "contextless" (u: UV3_F4, v: V3_F4) -> (u_to_v: V3_F4) { inner := vdot(v3(u), v); u_to_v = v * inner; return }
// Anti-wedge of vectors
regress_v3f4 :: #force_inline proc "contextless" (a, b : V3_F4) -> f32 { return a.x * b.y - a.y * b.x }
reject_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> ( v_from_u: V3_F4) { inner := dot_v3f4(v, u); v_from_u = (v - (transmute(Vec3) u)) * inner; return }
reject_uv3f4_v3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> ( u_from_v: V3_F4) { inner := dot_v3f4(u, v); u_from_v = ((transmute(Vec3) u) - v) * inner; return }
reject_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> ( v_from_u: V3_F4) { inner := vdot(v, v3(u)); v_from_u = (v - v3(u)) * inner; return }
reject_uv3f4_v3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> ( u_from_v: V3_F4) { inner := vdot(v3(u), v); u_from_v = (v3(u) - v) * inner; return }
// Combines the deimensions that are present in a & b
wedge_v3f4 :: #force_inline proc "contextless" (a, b: V3_F4) -> (bv : BiV3_F4) {
yzx_zxy := a.yzx * b.zxy
zxy_yzx := a.zxy * b.yzx
bv = transmute(Bivec3) (yzx_zxy - zxy_yzx)
bv = transmute(BiV3_F4) (yzx_zxy - zxy_yzx)
return
}
@@ -198,7 +192,7 @@ wedge_v3f4 :: #force_inline proc "contextless" (a, b: V3_F4) -> (bv : BiV3_F4) {
//region Bivec3
biv3f4_via_f32s :: #force_inline proc "contextless" (yz, zx, xy : f32) -> BiV3_F4 {return { xyz = {yz, zx, xy} }}
complement_biv3f4 :: #force_inline proc "contextless" (b : BiV3_F4) -> BiV3_F4 {return transmute(BiV3_F4) b.xyz}
complement_biv3f4 :: #force_inline proc "contextless" (b : BiV3_F4) -> BiV3_F4 {return transmute(BiV3_F4) b.xyz} // TODO(Ed): Review this.
//region Operations isomoprhic to vectors
negate_biv3f4 :: #force_inline proc "contextless" (b : BiV3_F4) -> BiV3_F4 {return transmute(BiV3_F4) -b.xyz}
@@ -208,10 +202,10 @@ mul_biv3f4 :: #force_inline proc "contextless" (a, b: BiV3_F4)
mul_biv3f4_f32 :: #force_inline proc "contextless" (b: BiV3_F4, s: f32) -> BiV3_F4 {return transmute(BiV3_F4) (b.xyz * s)}
mul_f32_biv3f4 :: #force_inline proc "contextless" (s: f32, b: BiV3_F4) -> BiV3_F4 {return transmute(BiV3_F4) (s * b.xyz)}
div_biv3f4_f32 :: #force_inline proc "contextless" (b: BiV3_F4, s: f32) -> BiV3_F4 {return transmute(BiV3_F4) (b.xyz / s)}
inverse_mag_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return inverse_mag_vec3(b.xyz)}
magnitude_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return magnitude_vec3 (b.xyz)}
normalize_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> UBiV3_F4 {return transmute(UBiV3_F4) normalize_vec3(b.xyz)}
squared_mag_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return pow2_vec3(b.xyz)}
inverse_mag_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return inverse_mag_v3f4(b.xyz)}
magnitude_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return magnitude_v3f4 (b.xyz)}
normalize_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> UBiV3_F4 {return transmute(UBiV3_F4) normalize_v3f4(b.xyz)}
squared_mag_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4) -> f32 {return pow2_v3f4(b.xyz)}
//endregion Operations isomoprhic to vectors
// The wedge of a bi-vector in 3D vector space results in a Trivector represented as a scalar.
@@ -219,23 +213,23 @@ squared_mag_biv3f4 :: #force_inline proc "contextless" (b: BiV3_F4)
wedge_biv3f4 :: #force_inline proc "contextless" (a, b: BiV3_F4) -> f32 { s := a.yz + b.yz + a.zx + b.zx + a.xy + b.xy; return s }
// anti-wedge (Combines dimensions that are absent from a & b)
regress_biv3f4 :: #force_inline proc "contextless" (a, b: BiV3_F4) -> V3_F4 {return wedge_vec3(vec3(a), vec3(b))}
regress_biv3f4_v3f4 :: #force_inline proc "contextless" (b: BiV3_F4, v: V3_F4) -> f32 {return regress_vec3(b.xyz, v)}
regress_v3_biv3f4 :: #force_inline proc "contextless" (v: V3_F4, b: BiV3_F4) -> f32 {return regress_vec3(b.xyz, v)}
regress_biv3f4 :: #force_inline proc "contextless" (a, b: BiV3_F4) -> V3_F4 {return wedge_v3f4(v3(a), v3(b))}
regress_biv3f4_v3f4 :: #force_inline proc "contextless" (b: BiV3_F4, v: V3_F4) -> f32 {return regress_v3f4(b.xyz, v)}
regress_v3_biv3f4 :: #force_inline proc "contextless" (v: V3_F4, b: BiV3_F4) -> f32 {return regress_v3f4(b.xyz, v)}
//endregion biv3f4
//region Rotor3
rotor3f4_via_comps_f4 :: proc "contextless" (yz, zx, xy, scalar : f32) -> Rotor3_F4 { return Rotor3 {biv3f4_via_f32s(yz, zx, xy), scalar} }
rotor3f4_via_comps_f4 :: proc "contextless" (yz, zx, xy, scalar : f32) -> Rotor3_F4 { return Rotor3_F4 {biv3f4_via_f32s(yz, zx, xy), scalar} }
rotor3f4_via_bv_s_f4 :: #force_inline proc "contextless" (bv: BiV3_F4, scalar: f32) -> (rotor : Rotor3_F4) { return Rotor3_F4 {bv, scalar} }
rotor3f4_via_bv_s_f4 :: #force_inline proc "contextless" (bv: BiV3_F4, scalar: f32) -> (rotor : Rotor3_F4) { return Rotor3_F4 {bv, scalar} }
// rotor3f4_via_from_to_v3f4 :: #force_inline proc "contextless" (from, to: V3_F4) -> (rotor : Rotor3_F4) { rotor.scalar := 1 + dot( from, to ); return }
inverse_mag_rotor3f4 :: proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic("not implemented"); return }
magnitude_rotor3f4 :: proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic("not implemented"); return }
squared_mag_f4 :: proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic("not implemented"); return }
reverse_rotor3_f4 :: proc "contextless" (rotor : Rotor3_F4) -> (reversed : Rotor3_F4) { reversed = { negate_biv3f4(rotor.bv), rotor.s }; return }
inverse_mag_rotor3f4 :: #force_inline proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic_contextless("not implemented") }
magnitude_rotor3f4 :: #force_inline proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic_contextless("not implemented") }
squared_mag_f4 :: #force_inline proc "contextless" (rotor : Rotor3_F4) -> (s : f32) { panic_contextless("not implemented") }
reverse_rotor3_f4 :: #force_inline proc "contextless" (rotor : Rotor3_F4) -> (reversed : Rotor3_F4) { reversed = { negate_biv3f4(rotor.bv), rotor.s }; return }
//endregion Rotor3
@@ -243,26 +237,26 @@ reverse_rotor3_f4 :: proc "contextless" (rotor : Rotor3_F4) -> (reversed : Ro
Point3_F4 :: distinct V3_F4
PointFlat3_F4 :: distinct V4_F4
Line3_F4 :: struct {
weight : V3_F4,
bulk : BiV3_F4,
Line3_F4 :: struct {
weight: V3_F4,
bulk: BiV3_F4,
}
Plane3_F4 :: distinct V4_F4 // 4D Anti-vector
// aka: wedge operation for points
join_point3_f4 :: proc "contextless" (p, q : Point3_F4) -> (l : Line3_F4) {
weight := sub(q, p)
bulk := wedge(vec3(p), vec3(q))
weight := v3(q) - v3(p)
bulk := wedge(v3(p), v3(q))
l = {weight, bulk}
return
}
join_pointflat3_f4 :: proc "contextless" (p, q : PointFlat3_F4) -> (l : Line3_F4) {
weight := vec3(
weight := v3f4(
p.w * q.x - p.x * q.w,
p.w * q.y - p.y * q.w,
p.w * q.z - p.z * q.w
)
bulk := wedge(vec3(p), vec3(q))
bulk := wedge(v3(p), v3(q))
l = { weight, bulk}
return
}
@@ -272,10 +266,10 @@ sub_point3_f4 :: #force_inline proc "contextless" (a, b : Point3_F4) -> (v : V3_
//region Rational Trig
quadrance :: proc "contextless" (a, b : Point3_F4) -> (q : f32) { q = pow2( sub(a, b)); return }
quadrance :: #force_inline proc "contextless" (a, b: Point3_F4) -> (q : f32) { q = pow2_v3f4(v3(a) - v3(b)); return }
// Assumes the weight component is normalized.
spread :: proc "contextless" (l, m : Line3_F4) -> (s : f32) { s = dot(l.weight, m.weight); return }
spread :: #force_inline proc "contextless" (l, m: Line3_F4) -> (s : f32) { s = vdot(l.weight, m.weight); return }
//endregion Rational Trig
@@ -283,23 +277,23 @@ spread :: proc "contextless" (l, m : Line3_F4) -> (s : f32) { s = dot(l.weight,
// A dump of equivalent symbol generatioon (because the toolchain can't do it yet)
// Symbol alias tables are in grim.odin
v3f4_to_biv3f4 :: #force_inline proc "contextless" (v: V3_F4) -> BiV3_F4 {return transmute(Bivec3) v }
biv3f4_to_v3f4 :: #force_inline proc "contextless" (bv: BiV3_F4) -> V3_F4 {return transmute(Vec3) bv }
quatf4_from_rotor3f4 :: #force_inline proc "contextless" (rotor: Rotor3_F4) -> Q_F4 {return transmute(Quat128) rotor}
uv3f4_to_v3f4 :: #force_inline proc "contextless" (v: UV3_F4) -> V3_F4 {return transmute(Vec3) v }
uv4f4_to_v4f4 :: #force_inline proc "contextless" (v: UV4_F4) -> V4_F4 {return transmute(Vec4) v }
v3f4_to_biv3f4 :: #force_inline proc "contextless" (v: V3_F4) -> BiV3_F4 {return transmute(BiV3_F4) v }
biv3f4_to_v3f4 :: #force_inline proc "contextless" (bv: BiV3_F4) -> V3_F4 {return transmute(V3_F4) bv }
quatf4_from_rotor3f4 :: #force_inline proc "contextless" (rotor: Rotor3_F4) -> Quat_F4 {return transmute(Quat_F4) rotor }
uv3f4_to_v3f4 :: #force_inline proc "contextless" (v: UV3_F4) -> V3_F4 {return transmute(V3_F4) v }
uv4f4_to_v4f4 :: #force_inline proc "contextless" (v: UV4_F4) -> V4_F4 {return transmute(V4_F4) v }
// plane_to_v4f4 :: #force_inline proc "contextless" (p : Plane3_F4) -> V4_F4 {return transmute(V4_F4) p}
point3f4_to_v3f4 :: #force_inline proc "contextless" (p: Point3_F4) -> V3_F4 {return transmute(Vec3) p}
pointflat3f4_to_v3f4 :: #force_inline proc "contextless" (p: PointFlat3_F4) -> V3_F4 {return { p.x, p.y, p.z }}
v3f4_to_point3f4 :: #force_inline proc "contextless" (v: V3_F4) -> Point3_F4 {return transmute(Point3) v}
point3f4_to_v3f4 :: #force_inline proc "contextless" (p: Point3_F4) -> V3_F4 {return {p.x, p.y, p.z} }
pointflat3f4_to_v3f4 :: #force_inline proc "contextless" (p: PointFlat3_F4) -> V3_F4 {return {p.x, p.y, p.z} }
v3f4_to_point3f4 :: #force_inline proc "contextless" (v: V3_F4) -> Point3_F4 {return {v.x, v.y, v.z} }
cross_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> V3_F4 {return cross_v3f4(v, transmute(Vec3) u)}
cross_u3f4_v3f4 :: #force_inline proc "contextless" (u: UV3_F4, v: V3_F4) -> V3_F4 {return cross_v3f4(transmute(Vec3) u, v)}
cross_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, u: UV3_F4) -> V3_F4 {return cross_v3(v, transmute(V3_F4) u)}
cross_u3f4_v3f4 :: #force_inline proc "contextless" (u: UV3_F4, v: V3_F4) -> V3_F4 {return cross_v3(transmute(V3_F4) u, v)}
dot_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, unit_v: UV3_F4) -> f32 {return dot_v3f4(v, transmute(Vec3) unit_v)}
dot_uv3f4_vs :: #force_inline proc "contextless" (unit_v: UV3_F4, v: V3_F4) -> f32 {return dot_v3f4(v, transmute(Vec3) unit_v)}
dot_v3f4_uv3f4 :: #force_inline proc "contextless" (v: V3_F4, unit_v: UV3_F4) -> f32 {return vdot(v, transmute(V3_F4) unit_v)}
dot_uv3f4_v3f4 :: #force_inline proc "contextless" (unit_v: UV3_F4, v: V3_F4) -> f32 {return vdot(v, transmute(V3_F4) unit_v)}
wedge_v3f4_uv3f4 :: #force_inline proc "contextless" (v : V3_F4, unit_v: UV3_F4) -> BiV3_F4 {return wedge_v3f4(v, transmute(Vec3) unit_v)}
wedge_uv3f4_vs :: #force_inline proc "contextless" (unit_v: UV3_F4, v: V3_F4) -> BiV3_F4 {return wedge_v3f4(transmute(Vec3) unit_v, v)}
wedge_v3f4_uv3f4 :: #force_inline proc "contextless" (v : V3_F4, unit_v: UV3_F4) -> BiV3_F4 {return wedge_v3f4(v, v3(unit_v))}
wedge_uv3f4_vs :: #force_inline proc "contextless" (unit_v: UV3_F4, v: V3_F4) -> BiV3_F4 {return wedge_v3f4(v3(unit_v), v)}
//endregion Grime