progress (cleaning up math.h/c)

This commit is contained in:
ed
2025-02-05 19:39:19 -05:00
parent 21c8d90f5d
commit 6f9b96fefa
10 changed files with 621 additions and 539 deletions
+116
View File
@@ -0,0 +1,116 @@
#pragma region _Generic Macros
// ____ _ ______ _ _ ____ _ __ _
// / ___} (_) | ____} | | (_) / __ \ | | | |(_)
// | | ___ ___ _ __ ___ _ __ _ ___ | |__ _ _ _ __ ___| |_ _ ___ _ __ | | | |_ _____ _ __ | | ___ __ _ __| | _ _ __ __ _
// | |{__ |/ _ \ '_ \ / _ \ '__} |/ __| | __} | | | '_ \ / __} __} |/ _ \| '_ \ | | | \ \ / / _ \ '_ }| |/ _ \ / _` |/ _` || | '_ \ / _` |
// | |__j | __/ | | | __/ | | | (__ | | | |_| | | | | (__| l_| | (_) | | | | | l__| |\ V / __/ | | | (_) | (_| | (_| || | | | | (_| |
// \____/ \___}_l l_l\___}_l l_l\___| l_l \__,_l_l l_l\___}\__}_l\___/l_l l_l \____/ \_/ \___}_l l_l\___/ \__,_l\__,_l|_|_| |_|\__, |
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in: __| |
// https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md {___/
// It was choosen over the more novel implementations to keep the macros as easy to understand and unobfuscated as possible.
#define MD_COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly.
// Helper macros for argument selection
#define MD_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
#define MD_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
#define MD_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
#define MD_GENERIC_SEL_ENTRY_TYPE MD_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
#define MD_GENERIC_SEL_ENTRY_FUNCTION MD_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
#define MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER MD_SELECT_ARG_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','.
#define MD_RESOLVED_FUNCTION_CALL // Just used to indicate where the call "occurs"
// ----------------------------------------------------------------------------------------------------------------------------------
// MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name).
// It takes advantage of the fact that if the macro is defined, then the expanded text will contain a comma.
// Expands to ',' if it can find (type): (function) <comma_operator: ',' >
// Where MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
#define MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, MD_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): MD_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) MD_COMMA_OPERATOR, , )
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
// The slot won't exist if that comma is not found.
// For the occastion where an expression didn't resolve to a selection option the "default: <value>" will be set to:
typedef struct METADESK_NO_RESOLVED_GENERIC_SELECTION METADESK_NO_RESOLVED_GENERIC_SELECTION;
struct METADESK_NO_RESOLVED_GENERIC_SELECTION {
void* _THE_VOID_SLOT_;
};
METADESK_NO_RESOLVED_GENERIC_SELECTION const MD_generic_selection_fail = {0};
// Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer
// ----------------------------------------------------------------------------------------------------------------------------------
// Below are generated on demand for an overlaod depdendent on a type:
// ----------------------------------------------------------------------------------------------------------------------------------
#define MD_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
(selector_arg), /* Select Via Expression*/ \
/* Extendibility slots: */ \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \
default: MD_generic_selection_fail \
) MD_RESOLVED_FUNCTION_CALL( selector_arg )
// ----------------------------------------------------------------------------------------------------------------------------------
// Then each definiton of a function has an associated define:
#// #define GENERIC_SLOT_<#>_<generic identifier> <typename>, <function_to_resolve>
// Then somehwere later on
// <etc> <return_type> <function_id> ( <arguments> ) { <implementation> }
// Concrete example:
// To add support for long:
#define GENERIC_SLOT_1_MD_example_hash long, MD_example_hash__P_long
size_t MD_example_hash__P_long( long val ) { return val * 2654435761ull; }
// To add support for long long:
#define GENERIC_SLOT_2_MD_example_hash long long, MD_example_hash__P_long_long
size_t MD_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
// If using an Editor with support for syntax hightlighting macros:
// GENERIC_SLOT_1_MD_example_hash and GENERIC_SLOT_2_MD_example_hash should show color highlighting indicating the slot is enabled,
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
#define MD_hash_example( function_arguments ) _Generic( \
(function_arguments), /* Select Via Expression*/ \
/* Extendibility slots: */ \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_3_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_4_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_5_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_6_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_7_MD_example_hash ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_8_MD_example_hash ) \
default: MD_generic_selection_fail \
) MD_RESOLVED_FUNCTION_CALL( function_arguments )
// Additional Variations:
// If the function takes more than one argument the following is used:
#define MD_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \
(selector_arg), \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(GENERIC_SLOT_N__function_sig ) \
default: MD_generic_selection_fail \
) MD_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ )
// If the function does not take the arugment as a parameter:
#define MD_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \
( MD_TYPE_TO_EXP(selector_arg) ), \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(GENERIC_SLOT_N__function_sig ) \
default: MD_generic_selection_fail \
) MD_RESOLVED_FUNCTION_CALL()
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
#define MD_TYPE_TO_EXP(type) (* (type*)NULL)
// Instead of using this macro, you'll see it directly expanded by the code generation.
// typedef void* MD_GenericExampleType;
// MD_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( MD_GenericExampleType );
#pragma endregion _Generic Macros
-113
View File
@@ -4,120 +4,7 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: Scalar Ops //~ rjf: Scalar Ops
internal F32
mix_1f32(F32 a, F32 b, F32 t)
{
F32 c = (a + (b-a) * Clamp(0.f, t, 1.f));
return c;
}
internal F64
mix_1f64(F64 a, F64 b, F64 t)
{
F64 c = (a + (b-a) * Clamp(0.0, t, 1.0));
return c;
}
////////////////////////////////
//~ rjf: Vector Ops
internal Vec2F32 vec_2f32(F32 x, F32 y) {Vec2F32 v = {x, y}; return v;}
internal Vec2F32 add_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2F32 sub_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2F32 mul_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2F32 div_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2F32 scale_2f32(Vec2F32 v, F32 s) {Vec2F32 c = {v.x*s, v.y*s}; return c;}
internal F32 dot_2f32(Vec2F32 a, Vec2F32 b) {F32 c = a.x*b.x + a.y*b.y; return c;}
internal F32 length_squared_2f32(Vec2F32 v) {F32 c = v.x*v.x + v.y*v.y; return c;}
internal F32 length_2f32(Vec2F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y); return c;}
internal Vec2F32 normalize_2f32(Vec2F32 v) {v = scale_2f32(v, 1.f/length_2f32(v)); return v;}
internal Vec2F32 mix_2f32(Vec2F32 a, Vec2F32 b, F32 t) {Vec2F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t)}; return c;}
internal Vec2S64 vec_2s64(S64 x, S64 y) {Vec2S64 v = {x, y}; return v;}
internal Vec2S64 add_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2S64 sub_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2S64 mul_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2S64 div_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2S64 scale_2s64(Vec2S64 v, S64 s) {Vec2S64 c = {v.x*s, v.y*s}; return c;}
internal S64 dot_2s64(Vec2S64 a, Vec2S64 b) {S64 c = a.x*b.x + a.y*b.y; return c;}
internal S64 length_squared_2s64(Vec2S64 v) {S64 c = v.x*v.x + v.y*v.y; return c;}
internal S64 length_2s64(Vec2S64 v) {S64 c = (S64)sqrt_f64((F64)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S64 normalize_2s64(Vec2S64 v) {v = scale_2s64(v, (S64)(1.f/length_2s64(v))); return v;}
internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t) {Vec2S64 c = {(S64)mix_1f32((F32)a.x, (F32)b.x, t), (S64)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S32 vec_2s32(S32 x, S32 y) {Vec2S32 v = {x, y}; return v;}
internal Vec2S32 add_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2S32 sub_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2S32 mul_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2S32 div_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2S32 scale_2s32(Vec2S32 v, S32 s) {Vec2S32 c = {v.x*s, v.y*s}; return c;}
internal S32 dot_2s32(Vec2S32 a, Vec2S32 b) {S32 c = a.x*b.x + a.y*b.y; return c;}
internal S32 length_squared_2s32(Vec2S32 v) {S32 c = v.x*v.x + v.y*v.y; return c;}
internal S32 length_2s32(Vec2S32 v) {S32 c = (S32)sqrt_f32((F32)v.x*(F32)v.x + (F32)v.y*(F32)v.y); return c;}
internal Vec2S32 normalize_2s32(Vec2S32 v) {v = scale_2s32(v, (S32)(1.f/length_2s32(v))); return v;}
internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t) {Vec2S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S16 vec_2s16(S16 x, S16 y) {Vec2S16 v = {x, y}; return v;}
internal Vec2S16 add_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x+b.x), (S16)(a.y+b.y)}; return c;}
internal Vec2S16 sub_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x-b.x), (S16)(a.y-b.y)}; return c;}
internal Vec2S16 mul_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x*b.x), (S16)(a.y*b.y)}; return c;}
internal Vec2S16 div_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x/b.x), (S16)(a.y/b.y)}; return c;}
internal Vec2S16 scale_2s16(Vec2S16 v, S16 s) {Vec2S16 c = {(S16)(v.x*s), (S16)(v.y*s)}; return c;}
internal S16 dot_2s16(Vec2S16 a, Vec2S16 b) {S16 c = a.x*b.x + a.y*b.y; return c;}
internal S16 length_squared_2s16(Vec2S16 v) {S16 c = v.x*v.x + v.y*v.y; return c;}
internal S16 length_2s16(Vec2S16 v) {S16 c = (S16)sqrt_f32((F32)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S16 normalize_2s16(Vec2S16 v) {v = scale_2s16(v, (S16)(1.f/length_2s16(v))); return v;}
internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t) {Vec2S16 c = {(S16)mix_1f32((F32)a.x, (F32)b.x, t), (S16)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z) {Vec3F32 v = {x, y, z}; return v;}
internal Vec3F32 add_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;}
internal Vec3F32 sub_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x-b.x, a.y-b.y, a.z-b.z}; return c;}
internal Vec3F32 mul_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x*b.x, a.y*b.y, a.z*b.z}; return c;}
internal Vec3F32 div_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x/b.x, a.y/b.y, a.z/b.z}; return c;}
internal Vec3F32 scale_3f32(Vec3F32 v, F32 s) {Vec3F32 c = {v.x*s, v.y*s, v.z*s}; return c;}
internal F32 dot_3f32(Vec3F32 a, Vec3F32 b) {F32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;}
internal F32 length_squared_3f32(Vec3F32 v) {F32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;}
internal F32 length_3f32(Vec3F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y + v.z*v.z); return c;}
internal Vec3F32 normalize_3f32(Vec3F32 v) {v = scale_3f32(v, 1.f/length_3f32(v)); return v;}
internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t) {Vec3F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t)}; return c;}
internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z) {Vec3S32 v = {x, y, z}; return v;}
internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;}
internal Vec3S32 sub_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x-b.x, a.y-b.y, a.z-b.z}; return c;}
internal Vec3S32 mul_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x*b.x, a.y*b.y, a.z*b.z}; return c;}
internal Vec3S32 div_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x/b.x, a.y/b.y, a.z/b.z}; return c;}
internal Vec3S32 scale_3s32(Vec3S32 v, S32 s) {Vec3S32 c = {v.x*s, v.y*s, v.z*s}; return c;}
internal S32 dot_3s32(Vec3S32 a, Vec3S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;}
internal S32 length_squared_3s32(Vec3S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;}
internal S32 length_3s32(Vec3S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z)); return c;}
internal Vec3S32 normalize_3s32(Vec3S32 v) {v = scale_3s32(v, (S32)(1.f/length_3s32(v))); return v;}
internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t) {Vec3S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t)}; return c;}
internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
internal Vec4F32 vec_4f32(F32 x, F32 y, F32 z, F32 w) {Vec4F32 v = {x, y, z, w}; return v;}
internal Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w}; return c;}
internal Vec4F32 sub_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w}; return c;}
internal Vec4F32 mul_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w}; return c;}
internal Vec4F32 div_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w}; return c;}
internal Vec4F32 scale_4f32(Vec4F32 v, F32 s) {Vec4F32 c = {v.x*s, v.y*s, v.z*s, v.w*s}; return c;}
internal F32 dot_4f32(Vec4F32 a, Vec4F32 b) {F32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;}
internal F32 length_squared_4f32(Vec4F32 v) {F32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;}
internal F32 length_4f32(Vec4F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); return c;}
internal Vec4F32 normalize_4f32(Vec4F32 v) {v = scale_4f32(v, 1.f/length_4f32(v)); return v;}
internal Vec4F32 mix_4f32(Vec4F32 a, Vec4F32 b, F32 t) {Vec4F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t), mix_1f32(a.w, b.w, t)}; return c;}
internal Vec4S32 vec_4s32(S32 x, S32 y, S32 z, S32 w) {Vec4S32 v = {x, y, z, w}; return v;}
internal Vec4S32 add_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w}; return c;}
internal Vec4S32 sub_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w}; return c;}
internal Vec4S32 mul_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w}; return c;}
internal Vec4S32 div_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w}; return c;}
internal Vec4S32 scale_4s32(Vec4S32 v, S32 s) {Vec4S32 c = {v.x*s, v.y*s, v.z*s, v.w*s}; return c;}
internal S32 dot_4s32(Vec4S32 a, Vec4S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;}
internal S32 length_squared_4s32(Vec4S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;}
internal S32 length_4s32(Vec4S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w)); return c;}
internal Vec4S32 normalize_4s32(Vec4S32 v) {v = scale_4s32(v, (S32)(1.f/length_4s32(v))); return v;}
internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t) {Vec4S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t), (S32)mix_1f32((F32)a.w, (F32)b.w, t)}; return c;}
//////////////////////////////// ////////////////////////////////
//~ rjf: Matrix Ops //~ rjf: Matrix Ops
+149 -93
View File
@@ -3,6 +3,7 @@
# include "context_cracking.h" # include "context_cracking.h"
# include "linkage.h" # include "linkage.h"
# include "macros.h" # include "macros.h"
# include "generic_macros.h"
#endif #endif
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 2024 Epic Games Tools
@@ -367,12 +368,15 @@ struct Rng1S64Array
#define floor_f32(v) floorf(v) #define floor_f32(v) floorf(v)
#define round_f32(v) roundf(v) #define round_f32(v) roundf(v)
#define abs_f32(v) fabsf(v) #define abs_f32(v) fabsf(v)
#define radians_from_turns_f32(v) ((v) * 2 * 3.1415926535897f) #define radians_from_turns_f32(v) ((v) * 2 * 3.1415926535897f)
#define turns_from_radians_f32(v) ((v) / 2 * 3.1415926535897f) #define turns_from_radians_f32(v) ((v) / 2 * 3.1415926535897f)
#define degrees_from_turns_f32(v) ((v) * 360.f) #define degrees_from_turns_f32(v) ((v) * 360.f)
#define turns_from_degrees_f32(v) ((v) / 360.f) #define turns_from_degrees_f32(v) ((v) / 360.f)
#define degrees_from_radians_f32(v) (degrees_from_turns_f32(turns_from_radians_f32(v))) #define degrees_from_radians_f32(v) (degrees_from_turns_f32(turns_from_radians_f32(v)))
#define radians_from_degrees_f32(v) (radians_from_turns_f32(turns_from_degrees_f32(v))) #define radians_from_degrees_f32(v) (radians_from_turns_f32(turns_from_degrees_f32(v)))
#define sin_f32(v) sinf( radians_from_turns_f32(v) ) #define sin_f32(v) sinf( radians_from_turns_f32(v) )
#define cos_f32(v) cosf( radians_from_turns_f32(v) ) #define cos_f32(v) cosf( radians_from_turns_f32(v) )
#define tan_f32(v) tanf( radians_from_turns_f32(v) ) #define tan_f32(v) tanf( radians_from_turns_f32(v) )
@@ -384,127 +388,173 @@ struct Rng1S64Array
#define floor_f64(v) floor(v) #define floor_f64(v) floor(v)
#define round_f64(v) round(v) #define round_f64(v) round(v)
#define abs_f64(v) fabs(v) #define abs_f64(v) fabs(v)
#define radians_from_turns_f64(v) ((v) * 2 * 3.1415926535897) #define radians_from_turns_f64(v) ((v) * 2 * 3.1415926535897)
#define turns_from_radians_f64(v) ((v) / 2 * 3.1415926535897) #define turns_from_radians_f64(v) ((v) / 2 * 3.1415926535897)
#define degrees_from_turns_f64(v) ((v) * 360.0) #define degrees_from_turns_f64(v) ((v) * 360.0)
#define turns_from_degrees_f64(v) ((v) / 360.0) #define turns_from_degrees_f64(v) ((v) / 360.0)
#define degrees_from_radians_f64(v) (degrees_from_turns_f64(turns_from_radians_f64(v))) #define degrees_from_radians_f64(v) (degrees_from_turns_f64(turns_from_radians_f64(v)))
#define radians_from_degrees_f64(v) (radians_from_turns_f64(turns_from_degrees_f64(v))) #define radians_from_degrees_f64(v) (radians_from_turns_f64(turns_from_degrees_f64(v)))
#define sin_f64(v) sin(radians_from_turns_f64(v)) #define sin_f64(v) sin(radians_from_turns_f64(v))
#define cos_f64(v) cos(radians_from_turns_f64(v)) #define cos_f64(v) cos(radians_from_turns_f64(v))
#define tan_f64(v) tan(radians_from_turns_f64(v)) #define tan_f64(v) tan(radians_from_turns_f64(v))
internal F32 mix_1f32(F32 a, F32 b, F32 t); inline F32 mix_1f32(F32 a, F32 b, F32 t) { F32 c = (a + (b - a) * Clamp(0.f, t, 1.f)); return c; }
internal F64 mix_1f64(F64 a, F64 b, F64 t); inline F64 mix_1f64(F64 a, F64 b, F64 t) { F64 c = (a + (b - a) * Clamp(0.0, t, 1.0)); return c; }
//////////////////////////////// ////////////////////////////////
//~ rjf: Vector Ops //~ rjf: Vector Ops
// ==================== 2D Vectors ====================
#define v2f32(x, y) vec_2f32((x), (y)) #define v2f32(x, y) vec_2f32((x), (y))
internal Vec2F32 vec_2f32(F32 x, F32 y); inline Vec2F32 vec_2f32 (F32 x, F32 y) { Vec2F32 v = {x, y}; return v; }
internal Vec2F32 add_2f32(Vec2F32 a, Vec2F32 b); inline Vec2F32 add_2f32 (Vec2F32 a, Vec2F32 b) { Vec2F32 c = {a.x + b.x, a.y + b.y}; return c; }
internal Vec2F32 sub_2f32(Vec2F32 a, Vec2F32 b); inline Vec2F32 sub_2f32 (Vec2F32 a, Vec2F32 b) { Vec2F32 c = {a.x - b.x, a.y - b.y}; return c; }
internal Vec2F32 mul_2f32(Vec2F32 a, Vec2F32 b); inline Vec2F32 mul_2f32 (Vec2F32 a, Vec2F32 b) { Vec2F32 c = {a.x * b.x, a.y * b.y}; return c; }
internal Vec2F32 div_2f32(Vec2F32 a, Vec2F32 b); inline Vec2F32 div_2f32 (Vec2F32 a, Vec2F32 b) { Vec2F32 c = {a.x / b.x, a.y / b.y}; return c; }
internal Vec2F32 scale_2f32(Vec2F32 v, F32 s); inline Vec2F32 scale_2f32 (Vec2F32 v, F32 s) { Vec2F32 c = {v.x * s, v.y * s }; return c; }
internal F32 dot_2f32(Vec2F32 a, Vec2F32 b); inline F32 dot_2f32 (Vec2F32 a, Vec2F32 b) { F32 c = a.x * b.x + a.y * b.y; return c; }
internal F32 length_squared_2f32(Vec2F32 v); inline F32 length_squared_2f32(Vec2F32 v) { F32 c = v.x * v.x + v.y * v.y; return c; }
internal F32 length_2f32(Vec2F32 v); inline F32 length_2f32 (Vec2F32 v) { F32 c = sqrt_f32(v.x*v.x + v.y*v.y); return c; }
internal Vec2F32 normalize_2f32(Vec2F32 v); inline Vec2F32 normalize_2f32 (Vec2F32 v) { v = scale_2f32(v, 1.f / length_2f32(v)); return v; }
internal Vec2F32 mix_2f32(Vec2F32 a, Vec2F32 b, F32 t); inline Vec2F32 mix_2f32 (Vec2F32 a, Vec2F32 b, F32 t) { Vec2F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t)}; return c; }
#define v2s64(x, y) vec_2s64((x), (y)) #define v2s64(x, y) vec_2s64((x), (y))
internal Vec2S64 vec_2s64(S64 x, S64 y); inline Vec2S64 vec_2s64 (S64 x, S64 y) { Vec2S64 v = {x, y}; return v; }
internal Vec2S64 add_2s64(Vec2S64 a, Vec2S64 b); inline Vec2S64 add_2s64 (Vec2S64 a, Vec2S64 b) { Vec2S64 c = {a.x + b.x, a.y + b.y}; return c; }
internal Vec2S64 sub_2s64(Vec2S64 a, Vec2S64 b); inline Vec2S64 sub_2s64 (Vec2S64 a, Vec2S64 b) { Vec2S64 c = {a.x - b.x, a.y - b.y}; return c; }
internal Vec2S64 mul_2s64(Vec2S64 a, Vec2S64 b); inline Vec2S64 mul_2s64 (Vec2S64 a, Vec2S64 b) { Vec2S64 c = {a.x * b.x, a.y * b.y}; return c; }
internal Vec2S64 div_2s64(Vec2S64 a, Vec2S64 b); inline Vec2S64 div_2s64 (Vec2S64 a, Vec2S64 b) { Vec2S64 c = {a.x / b.x, a.y / b.y}; return c; }
internal Vec2S64 scale_2s64(Vec2S64 v, S64 s); inline Vec2S64 scale_2s64 (Vec2S64 v, S64 s) { Vec2S64 c = {v.x * s, v.y * s }; return c; }
internal S64 dot_2s64(Vec2S64 a, Vec2S64 b); inline S64 dot_2s64 (Vec2S64 a, Vec2S64 b) { S64 c = a.x * b.x + a.y * b.y; return c; }
internal S64 length_squared_2s64(Vec2S64 v); inline S64 length_squared_2s64(Vec2S64 v) { S64 c = v.x * v.x + v.y * v.y; return c; }
internal S64 length_2s64(Vec2S64 v); inline S64 length_2s64 (Vec2S64 v) { S64 c = (S64)sqrt_f64((F64)(v.x*v.x + v.y*v.y)); return c; }
internal Vec2S64 normalize_2s64(Vec2S64 v); inline Vec2S64 normalize_2s64 (Vec2S64 v) { v = scale_2s64(v, (S64)(1.f / length_2s64(v))); return v; }
internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t); inline Vec2S64 mix_2s64 (Vec2S64 a, Vec2S64 b, F32 t) { Vec2S64 c = {(S64)mix_1f32((F32)a.x, (F32)b.x, t), (S64)mix_1f32((F32)a.y, (F32)b.y, t)}; return c; }
#define v2s32(x, y) vec_2s32((x), (y)) #define v2s32(x, y) vec_2s32((x), (y))
internal Vec2S32 vec_2s32(S32 x, S32 y); inline Vec2S32 vec_2s32(S32 x, S32 y) { Vec2S32 v = {x, y}; return v; }
internal Vec2S32 add_2s32(Vec2S32 a, Vec2S32 b); inline Vec2S32 add_2s32(Vec2S32 a, Vec2S32 b) { Vec2S32 c = {a.x + b.x, a.y + b.y}; return c; }
internal Vec2S32 sub_2s32(Vec2S32 a, Vec2S32 b); inline Vec2S32 sub_2s32(Vec2S32 a, Vec2S32 b) { Vec2S32 c = {a.x - b.x, a.y - b.y}; return c; }
internal Vec2S32 mul_2s32(Vec2S32 a, Vec2S32 b); inline Vec2S32 mul_2s32(Vec2S32 a, Vec2S32 b) { Vec2S32 c = {a.x * b.x, a.y * b.y}; return c; }
internal Vec2S32 div_2s32(Vec2S32 a, Vec2S32 b); inline Vec2S32 div_2s32(Vec2S32 a, Vec2S32 b) { Vec2S32 c = {a.x / b.x, a.y / b.y}; return c; }
internal Vec2S32 scale_2s32(Vec2S32 v, S32 s); inline Vec2S32 scale_2s32(Vec2S32 v, S32 s) { Vec2S32 c = {v.x * s, v.y * s }; return c; }
internal S32 dot_2s32(Vec2S32 a, Vec2S32 b); inline S32 dot_2s32 (Vec2S32 a, Vec2S32 b) { S32 c = a.x * b.x + a.y * b.y; return c; }
internal S32 length_squared_2s32(Vec2S32 v); inline S32 length_squared_2s32(Vec2S32 v) { S32 c = v.x * v.x + v.y * v.y; return c; }
internal S32 length_2s32(Vec2S32 v); inline S32 length_2s32 (Vec2S32 v) { S32 c = (S32)sqrt_f32((F32)v.x*(F32)v.x + (F32)v.y*(F32)v.y); return c; }
internal Vec2S32 normalize_2s32(Vec2S32 v); inline Vec2S32 normalize_2s32(Vec2S32 v) { v = scale_2s32(v, (S32)(1.f / length_2s32(v))); return v; }
internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t); inline Vec2S32 mix_2s32 (Vec2S32 a, Vec2S32 b, F32 t) { Vec2S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t)}; return c; }
#define v2s16(x, y) vec_2s16((x), (y)) #define v2s16(x, y) vec_2s16((x), (y))
internal Vec2S16 vec_2s16(S16 x, S16 y); inline Vec2S16 vec_2s16(S16 x, S16 y) { Vec2S16 v = {x, y}; return v; }
internal Vec2S16 add_2s16(Vec2S16 a, Vec2S16 b); inline Vec2S16 add_2s16(Vec2S16 a, Vec2S16 b) { Vec2S16 c = {(S16)(a.x + b.x), (S16)(a.y + b.y)}; return c; }
internal Vec2S16 sub_2s16(Vec2S16 a, Vec2S16 b); inline Vec2S16 sub_2s16(Vec2S16 a, Vec2S16 b) { Vec2S16 c = {(S16)(a.x - b.x), (S16)(a.y - b.y)}; return c; }
internal Vec2S16 mul_2s16(Vec2S16 a, Vec2S16 b); inline Vec2S16 mul_2s16(Vec2S16 a, Vec2S16 b) { Vec2S16 c = {(S16)(a.x * b.x), (S16)(a.y * b.y)}; return c; }
internal Vec2S16 div_2s16(Vec2S16 a, Vec2S16 b); inline Vec2S16 div_2s16(Vec2S16 a, Vec2S16 b) { Vec2S16 c = {(S16)(a.x / b.x), (S16)(a.y / b.y)}; return c; }
internal Vec2S16 scale_2s16(Vec2S16 v, S16 s); inline Vec2S16 scale_2s16(Vec2S16 v, S16 s) { Vec2S16 c = {(S16)(v.x * s), (S16)(v.y * s )}; return c; }
internal S16 dot_2s16(Vec2S16 a, Vec2S16 b); inline S16 dot_2s16 (Vec2S16 a, Vec2S16 b) { S16 c = a.x * b.x + a.y * b.y; return c; }
internal S16 length_squared_2s16(Vec2S16 v); inline S16 length_squared_2s16(Vec2S16 v) { S16 c = v.x * v.x + v.y * v.y; return c; }
internal S16 length_2s16(Vec2S16 v); inline S16 length_2s16 (Vec2S16 v) { S16 c = (S16)sqrt_f32((F32)(v.x*v.x + v.y*v.y)); return c; }
internal Vec2S16 normalize_2s16(Vec2S16 v); inline Vec2S16 normalize_2s16(Vec2S16 v) { v = scale_2s16(v, (S16)(1.f / length_2s16(v))); return v; }
internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t); inline Vec2S16 mix_2s16 (Vec2S16 a, Vec2S16 b, F32 t) { Vec2S16 c = {(S16)mix_1f32((F32)a.x, (F32)b.x, t), (S16)mix_1f32((F32)a.y, (F32)b.y, t)}; return c; }
#define vec2(a, b) _Generic(a, S16: vec_2s16, S32: vec_2s32, S64: vec_2s64, F32: vec_2f32 )((a), (b))
#define add_vec2(a, b) _Generic(a, S16: add_2s16, S32: add_2s32, S64: add_2s64, F32: add_2f32 )((a), (b))
#define sub_vec2(a, b) _Generic(a, S16: sub_2s16, S32: sub_2s32, S64: sub_2s64, F32: sub_2f32 )((a), (b))
#define mul_vec2(a, b) _Generic(a, S16: mul_2s16, S32: mul_2s32, S64: mul_2s64, F32: mul_2f32 )((a), (b))
#define div_vec2(a, b) _Generic(a, S16: div_2s16, S32: div_2s32, S64: div_2s64, F32: div_2f32 )((a), (b))
#define scale_vec2(v, s) _Generic(v, S16: scale_2s16, S32: scale_2s32, S64: scale_2s64, F32: scale_2f32 )((v), (s))
#define dot_vec2(a, b) _Generic(a, S16: dot_2s16, S32: dot_2s32, S64: dot_2s64, F32: dot_2f32 )((a), (b))
#define length_squared_vec2(v) _Generic(v, S16: length_squared_2s16, S32: length_squared_2s32, S64: length_squared_2s64, F32: length_squared_2f32)((v))
#define length_vec2(v) _Generic(v, S16: length_2s16, S32: length_2s32, S64: length_2s64, F32: length_2f32 )((v))
#define normalize_vec2(v) _Generic(v, S16: normalize_2s16, S32: normalize_2s32, S64: normalize_2s64, F32: normalize_2f32 )((v))
#define mix_vec2(a, b, t) _Generic(a, S16: mix_2s16, S32: mix_2s32, S64: mix_2s64, F32: mix_2f32 )((a), (b), (t))
// ==================== 3D Vectors ====================
#define v3f32(x, y, z) vec_3f32((x), (y), (z)) #define v3f32(x, y, z) vec_3f32((x), (y), (z))
internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z); inline Vec3F32 vec_3f32 (F32 x, F32 y, F32 z) { Vec3F32 v = {x, y, z}; return v; }
internal Vec3F32 add_3f32(Vec3F32 a, Vec3F32 b); inline Vec3F32 add_3f32 (Vec3F32 a, Vec3F32 b) { Vec3F32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
internal Vec3F32 sub_3f32(Vec3F32 a, Vec3F32 b); inline Vec3F32 sub_3f32 (Vec3F32 a, Vec3F32 b) { Vec3F32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
internal Vec3F32 mul_3f32(Vec3F32 a, Vec3F32 b); inline Vec3F32 mul_3f32 (Vec3F32 a, Vec3F32 b) { Vec3F32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
internal Vec3F32 div_3f32(Vec3F32 a, Vec3F32 b); inline Vec3F32 div_3f32 (Vec3F32 a, Vec3F32 b) { Vec3F32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
internal Vec3F32 scale_3f32(Vec3F32 v, F32 s); inline Vec3F32 scale_3f32 (Vec3F32 v, F32 s) { Vec3F32 c = {v.x * s, v.y * s, v.z * s}; return c; }
internal F32 dot_3f32(Vec3F32 a, Vec3F32 b); inline F32 dot_3f32 (Vec3F32 a, Vec3F32 b) { F32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
internal F32 length_squared_3f32(Vec3F32 v); inline F32 length_squared_3f32(Vec3F32 v) { F32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
internal F32 length_3f32(Vec3F32 v); inline F32 length_3f32 (Vec3F32 v) { F32 c = sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z); return c; }
internal Vec3F32 normalize_3f32(Vec3F32 v); inline Vec3F32 normalize_3f32 (Vec3F32 v) { v = scale_3f32(v, 1.f / length_3f32(v)); return v; }
internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t); inline Vec3F32 mix_3f32 (Vec3F32 a, Vec3F32 b, F32 t) { Vec3F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t)}; return c; }
internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b); inline Vec3F32 cross_3f32 (Vec3F32 a, Vec3F32 b) { Vec3F32 c = {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; return c; }
#define v3s32(x, y, z) vec_3s32((x), (y), (z)) #define v3s32(x, y, z) vec_3s32((x), (y), (z))
internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z); inline Vec3S32 vec_3s32 (S32 x, S32 y, S32 z) { Vec3S32 v = {x, y, z}; return v; }
internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b); inline Vec3S32 add_3s32 (Vec3S32 a, Vec3S32 b) { Vec3S32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
internal Vec3S32 sub_3s32(Vec3S32 a, Vec3S32 b); inline Vec3S32 sub_3s32 (Vec3S32 a, Vec3S32 b) { Vec3S32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
internal Vec3S32 mul_3s32(Vec3S32 a, Vec3S32 b); inline Vec3S32 mul_3s32 (Vec3S32 a, Vec3S32 b) { Vec3S32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
internal Vec3S32 div_3s32(Vec3S32 a, Vec3S32 b); inline Vec3S32 div_3s32 (Vec3S32 a, Vec3S32 b) { Vec3S32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
internal Vec3S32 scale_3s32(Vec3S32 v, S32 s); inline Vec3S32 scale_3s32 (Vec3S32 v, S32 s) { Vec3S32 c = {v.x * s, v.y * s, v.z * s }; return c; }
internal S32 dot_3s32(Vec3S32 a, Vec3S32 b); inline S32 dot_3s32 (Vec3S32 a, Vec3S32 b) { S32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
internal S32 length_squared_3s32(Vec3S32 v); inline S32 length_squared_3s32(Vec3S32 v) { S32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
internal S32 length_3s32(Vec3S32 v); inline S32 length_3s32 (Vec3S32 v) { S32 c = (S32)sqrt_f32((F32)(v.x * v.x + v.y * v.y + v.z * v.z)); return c; }
internal Vec3S32 normalize_3s32(Vec3S32 v); inline Vec3S32 normalize_3s32 (Vec3S32 v) { v = scale_3s32(v, (S32)(1.f / length_3s32(v))); return v; }
internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t); inline Vec3S32 mix_3s32 (Vec3S32 a, Vec3S32 b, F32 t) { Vec3S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t)}; return c; }
internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b); inline Vec3S32 cross_3s32 (Vec3S32 a, Vec3S32 b) { Vec3S32 c = {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; return c; }
#define vec3(a, b, c) _Generic(a, S32: vec_3s32, F32: vec_3f32 )((a), (b), (c))
#define add_vec3(a, b) _Generic(a, S32: add_3s32, F32: add_3f32 )((a), (b))
#define sub_vec3(a, b) _Generic(a, S32: sub_3s32, F32: sub_3f32 )((a), (b))
#define mul_vec3(a, b) _Generic(a, S32: mul_3s32, F32: mul_3f32 )((a), (b))
#define div_vec3(a, b) _Generic(a, S32: div_3s32, F32: div_3f32 )((a), (b))
#define scale_vec3(v, s) _Generic(v, S32: scale_3s32, F32: scale_3f32 )((v), (s))
#define dot_vec3(a, b) _Generic(a, S32: dot_3s32, F32: dot_3f32 )((a), (b))
#define length_squared_vec3(v) _Generic(v, S32: length_squared_3s32, F32: length_squared_3f32)((v))
#define length_vec3(v) _Generic(v, S32: length_3s32, F32: length_3f32 )((v))
#define normalize_vec3(v) _Generic(v, S32: normalize_3s32, F32: normalize_3f32 )((v))
#define mix_vec3(a, b, t) _Generic(a, S32: mix_3s32, F32: mix_3f32 )((a), (b), (t))
#define cross_vec3(a, b) _Generic(a, S32: cross_3s32, F32: cross_3f32 )((a), (b))
// ==================== 4D Vectors ====================
#define v4f32(x, y, z, w) vec_4f32((x), (y), (z), (w)) #define v4f32(x, y, z, w) vec_4f32((x), (y), (z), (w))
internal Vec4F32 vec_4f32(F32 x, F32 y, F32 z, F32 w); internal Vec4F32 vec_4f32(F32 x, F32 y, F32 z, F32 w) { Vec4F32 v = {x, y, z, w}; return v; }
internal Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b); internal Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b) { Vec4F32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
internal Vec4F32 sub_4f32(Vec4F32 a, Vec4F32 b); internal Vec4F32 sub_4f32(Vec4F32 a, Vec4F32 b) { Vec4F32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
internal Vec4F32 mul_4f32(Vec4F32 a, Vec4F32 b); internal Vec4F32 mul_4f32(Vec4F32 a, Vec4F32 b) { Vec4F32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
internal Vec4F32 div_4f32(Vec4F32 a, Vec4F32 b); internal Vec4F32 div_4f32(Vec4F32 a, Vec4F32 b) { Vec4F32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
internal Vec4F32 scale_4f32(Vec4F32 v, F32 s); internal Vec4F32 scale_4f32(Vec4F32 v, F32 s) { Vec4F32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
internal F32 dot_4f32(Vec4F32 a, Vec4F32 b); internal F32 dot_4f32(Vec4F32 a, Vec4F32 b) { F32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
internal F32 length_squared_4f32(Vec4F32 v); internal F32 length_squared_4f32(Vec4F32 v) { F32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
internal F32 length_4f32(Vec4F32 v); internal F32 length_4f32(Vec4F32 v) { F32 c = sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); return c; }
internal Vec4F32 normalize_4f32(Vec4F32 v); internal Vec4F32 normalize_4f32(Vec4F32 v) { v = scale_4f32(v, 1.f / length_4f32(v)); return v; }
internal Vec4F32 mix_4f32(Vec4F32 a, Vec4F32 b, F32 t); internal Vec4F32 mix_4f32(Vec4F32 a, Vec4F32 b, F32 t) { Vec4F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t), mix_1f32(a.w, b.w, t)}; return c; }
#define v4s32(x, y, z, w) vec_4s32((x), (y), (z), (w)) #define v4s32(x, y, z, w) vec_4s32((x), (y), (z), (w))
internal Vec4S32 vec_4s32(S32 x, S32 y, S32 z, S32 w); internal Vec4S32 vec_4s32(S32 x, S32 y, S32 z, S32 w) { Vec4S32 v = {x, y, z, w}; return v; }
internal Vec4S32 add_4s32(Vec4S32 a, Vec4S32 b); internal Vec4S32 add_4s32(Vec4S32 a, Vec4S32 b) { Vec4S32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
internal Vec4S32 sub_4s32(Vec4S32 a, Vec4S32 b); internal Vec4S32 sub_4s32(Vec4S32 a, Vec4S32 b) { Vec4S32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
internal Vec4S32 mul_4s32(Vec4S32 a, Vec4S32 b); internal Vec4S32 mul_4s32(Vec4S32 a, Vec4S32 b) { Vec4S32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
internal Vec4S32 div_4s32(Vec4S32 a, Vec4S32 b); internal Vec4S32 div_4s32(Vec4S32 a, Vec4S32 b) { Vec4S32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
internal Vec4S32 scale_4s32(Vec4S32 v, S32 s); internal Vec4S32 scale_4s32(Vec4S32 v, S32 s) { Vec4S32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
internal S32 dot_4s32(Vec4S32 a, Vec4S32 b); internal S32 dot_4s32(Vec4S32 a, Vec4S32 b) { S32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
internal S32 length_squared_4s32(Vec4S32 v); internal S32 length_squared_4s32(Vec4S32 v) { S32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
internal S32 length_4s32(Vec4S32 v); internal S32 length_4s32(Vec4S32 v) { S32 c = (S32)sqrt_f32((F32)(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w)); return c; }
internal Vec4S32 normalize_4s32(Vec4S32 v); internal Vec4S32 normalize_4s32(Vec4S32 v) { v = scale_4s32(v, (S32)(1.f / length_4s32(v))); return v; }
internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t); internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t) { Vec4S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t), (S32)mix_1f32((F32)a.w, (F32)b.w, t)}; return c; }
#define vec4(a, b, c, d) _Generic(a, S32: vec_4s32, F32: vec_4f32 )((a), (b), (c), (d))
#define add_vec4(a, b) _Generic(a, S32: add_4s32, F32: add_4f32 )((a), (b))
#define sub_vec4(a, b) _Generic(a, S32: sub_4s32, F32: sub_4f32 )((a), (b))
#define mul_vec4(a, b) _Generic(a, S32: mul_4s32, F32: mul_4f32 )((a), (b))
#define div_vec4(a, b) _Generic(a, S32: div_4s32, F32: div_4f32 )((a), (b))
#define scale_vec4(v, s) _Generic(v, S32: scale_4s32, F32: scale_4f32 )((v), (s))
#define dot_vec4(a, b) _Generic(a, S32: dot_4s32, F32: dot_4f32 )((a), (b))
#define length_squared_vec4(v) _Generic(v, S32: length_squared_4s32, F32: length_squared_4f32)((v))
#define length_vec4(v) _Generic(v, S32: length_4s32, F32: length_4f32 )((v))
#define normalize_vec4(v) _Generic(v, S32: normalize_4s32, F32: normalize_4f32 )((v))
#define mix_vec4(a, b, t) _Generic(a, S32: mix_4s32, F32: mix_4f32 )((a), (b), (t))
//////////////////////////////// ////////////////////////////////
//~ rjf: Matrix Ops //~ rjf: Matrix Ops
@@ -642,7 +692,13 @@ internal Vec4F32 rgba_from_hsva(Vec4F32 hsva);
internal Vec4F32 rgba_from_u32 (U32 hex); internal Vec4F32 rgba_from_u32 (U32 hex);
internal U32 u32_from_rgba (Vec4F32 rgba); internal U32 u32_from_rgba (Vec4F32 rgba);
#define rgba_from_u32_lit_comp(h) { (((h)&0xff000000)>>24)/255.f, (((h)&0x00ff0000)>>16)/255.f, (((h)&0x0000ff00)>> 8)/255.f, (((h)&0x000000ff)>> 0)/255.f } #define rgba_from_u32_lit_comp(h) \
{ \
(((h) & 0xff000000) >> 24) / 255.f, \
(((h) & 0x00ff0000) >> 16) / 255.f, \
(((h) & 0x0000ff00) >> 8 ) / 255.f, \
(((h) & 0x000000ff) >> 0 ) / 255.f \
}
//////////////////////////////// ////////////////////////////////
//~ rjf: List Type Functions //~ rjf: List Type Functions
+3
View File
@@ -232,6 +232,9 @@ void* alloc_align( AllocatorInfo a, SSIZE size, SSIZE alignment ) {
inline inline
void* alloc( AllocatorInfo a, SSIZE size ) { void* alloc( AllocatorInfo a, SSIZE size ) {
if (a.proc == nullptr) {
a = default_allocator();
}
return alloc_align( a, size, MD_DEFAULT_MEMORY_ALIGNMENT ); return alloc_align( a, size, MD_DEFAULT_MEMORY_ALIGNMENT );
} }
+17 -2
View File
@@ -398,8 +398,9 @@ str8_skip_chop_whitespace(String8 string){
//////////////////////////////// ////////////////////////////////
//~ rjf: String Formatting & Copying //~ rjf: String Formatting & Copying
internal String8 String8
push_str8_cat(Arena *arena, String8 s1, String8 s2){ push_str8_cat(Arena* arena, String8 s1, String8 s2)
{
String8 str; String8 str;
str.size = s1.size + s2.size; str.size = s1.size + s2.size;
str.str = push_array_no_zero(arena, U8, str.size + 1); str.str = push_array_no_zero(arena, U8, str.size + 1);
@@ -441,6 +442,20 @@ push_str8f(Arena *arena, char *fmt, ...){
return(result); return(result);
} }
// String8
// str8__cat(String8 s1, String8 s2, AllocatorInfo ainfo)
// {
// String8 str;
// str.size = s1.size + s2.size;
// str.str = alloc_array(ainfo, U8, str.size + 1);
// memory_copy(str.str, s1.str, s1.size);
// memory_copy(str.str + s1.size, s2.str, s2.size);
// str.str[str.size] = 0;
// return str;
// }
//////////////////////////////// ////////////////////////////////
//~ rjf: String <=> Integer Conversions //~ rjf: String <=> Integer Conversions
+3
View File
@@ -229,6 +229,9 @@ internal String8 push_str8_copy(Arena *arena, String8 s);
internal String8 push_str8fv (Arena* arena, char* fmt, va_list args); internal String8 push_str8fv (Arena* arena, char* fmt, va_list args);
internal String8 push_str8f (Arena* arena, char* fmt, ...); internal String8 push_str8f (Arena* arena, char* fmt, ...);
// String8 str8__cat(String8 s1, String8 s2, AllocatorInfo a);
// #define str8_cat(s1, s2, ...) str8__cat(s1, s2, (AllocatorInfo) {__VA_ARGS__})
//////////////////////////////// ////////////////////////////////
//~ rjf: String <=> Integer Conversions //~ rjf: String <=> Integer Conversions
+2
View File
@@ -9,6 +9,7 @@
#include "base/context_cracking.h" #include "base/context_cracking.h"
#include "base/linkage.h" #include "base/linkage.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/generic_macros.h"
#include "base/platform.h" #include "base/platform.h"
#include "base/namespace.h" #include "base/namespace.h"
@@ -20,6 +21,7 @@ MD_NS_BEGIN
#include "base/memory_substrate.h" #include "base/memory_substrate.h"
#include "base/arena.h" #include "base/arena.h"
#include "base/space.h" #include "base/space.h"
#include "base/math.h"
#include "base/toolchain.h" #include "base/toolchain.h"
#include "base/strings.h" #include "base/strings.h"
#include "base/text.h" #include "base/text.h"