WIP: corrections/formatting post prefix addition

This commit is contained in:
2025-02-12 15:11:20 -05:00
parent 0ab226f739
commit 4a6a6b2290
17 changed files with 352 additions and 360 deletions
+3 -3
View File
@@ -68,12 +68,12 @@ md_arena_push(MD_Arena* arena, MD_SSIZE size, MD_SSIZE align)
MD_B32 vmem_chain = is_virtual && (arena->flags & MD_ArenaFlag_NoChainVirtual);
if (vmem_chain) {
MD_SPTR const varena_header_size = md_align_pow2(size_of(MD_VArena), MD_DEFAULT_MEMORY_ALIGNMENT);
MD_SPTR const md_arena_block_size = MD_VARENA_DEFAULT_RESERVE - varena_header_size;
MD_SPTR const varena_header_size = md_align_pow2(size_of(MD_VArena), MD_DEFAULT_MEMORY_ALIGNMENT);
MD_SPTR const md_arena_block_size = MD_VARENA_DEFAULT_RESERVE - varena_header_size;
MD_VArena* vcurrent = md_rcast(MD_VArena*, arena->backing.data);
MD_VArena* new_vm = md_varena_alloc(.reserve_size = vcurrent->reserve, .commit_size = vcurrent->commit_size);
MD_VArena* new_vm = md_varena_alloc(.reserve_size = vcurrent->reserve, .commit_size = vcurrent->commit_size);
new_block = md_arena_alloc(.backing = md_varena_allocator(new_vm), .block_size = md_arena_block_size);
}
else {
+6 -6
View File
@@ -84,15 +84,15 @@ md_extract_arena(MD_AllocatorInfo ainfo) {
//- rjf: arena creation/destruction
MD_API MD_Arena* md_arena__alloc(MD_ArenaParams* params);
#define md_arena_alloc(...) md_arena__alloc( &(MD_ArenaParams){ __VA_ARGS__ } )
#define md_arena_alloc(...) md_arena__alloc( &(MD_ArenaParams){ __VA_ARGS__ } )
void md_arena_release(MD_Arena *arena);
//- rjf: arena push/pop/pos core functions
MD_API void* md_arena_push (MD_Arena* arena, MD_SSIZE size, MD_SSIZE align);
MD_U64 md_arena_pos (MD_Arena* arena);
MD_API void md_arena_pop_to(MD_Arena* arena, MD_SSIZE pos);
MD_API void* md_arena_push (MD_Arena* arena, MD_SSIZE size, MD_SSIZE align);
MD_U64 md_arena_pos (MD_Arena* arena);
MD_API void md_arena_pop_to(MD_Arena* arena, MD_SSIZE pos);
//- rjf: arena push/pop helpers
@@ -102,7 +102,7 @@ void md_arena_pop (MD_Arena* arena, MD_SSIZE amt);
//- rjf: temporary arena scopes
MD_TempArena temp_arena_begin(MD_Arena* arena);
void temp_arena_end(MD_TempArena temp);
void temp_arena_end(MD_TempArena temp);
//- rjf: push helper macros
@@ -167,7 +167,7 @@ md_default_allocator()
md_local_persist md_thread_local MD_Arena* arena = md_nullptr;
if (arena == md_nullptr) {
MD_VArena* backing_vmem = md_varena_alloc(.flags = 0, .base_addr = 0x0, .reserve_size = MD_VARENA_DEFAULT_RESERVE, .commit_size = MD_VARENA_DEFAULT_COMMIT);
arena = md_arena_alloc(.backing = md_varena_allocator(backing_vmem), .block_size = MD_VARENA_DEFAULT_RESERVE);
arena = md_arena_alloc(.backing = md_varena_allocator(backing_vmem), .block_size = MD_VARENA_DEFAULT_RESERVE);
}
MD_AllocatorInfo info = { md_arena_allocator_proc, arena };
return info;
+5 -7
View File
@@ -36,9 +36,9 @@ md_cmd_line_opt_from_slot(MD_CmdLineOpt** slot, MD_String8 string) {
MD_CmdLineOpt*
md_cmd_line_insert_opt__ainfo(MD_AllocatorInfo ainfo, MD_CmdLine* cmd_line, MD_String8 string, MD_String8List values)
{
MD_CmdLineOpt *var = 0;
MD_CmdLineOpt **slot = md_cmd_line_slot_from_string(cmd_line, string);
MD_CmdLineOpt *existing_var = md_cmd_line_opt_from_slot(slot, string);
MD_CmdLineOpt* var = 0;
MD_CmdLineOpt** slot = md_cmd_line_slot_from_string(cmd_line, string);
MD_CmdLineOpt* existing_var = md_cmd_line_opt_from_slot(slot, string);
if(existing_var != 0)
{
var = existing_var;
@@ -63,8 +63,6 @@ md_cmd_line_insert_opt__ainfo(MD_AllocatorInfo ainfo, MD_CmdLine* cmd_line, MD_S
return var;
}
MD_CmdLine
md_cmd_line_from_string_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List command_line)
{
@@ -89,7 +87,7 @@ md_cmd_line_from_string_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List comma
// a flag option. All arguments after a single "--" (with no trailing string
// on the command line will be considered as input files.
MD_B32 is_option = 1;
if(after_passthrough_option == 0)
if (after_passthrough_option == 0)
{
if (md_str8_match(node->string, md_str8_lit("--"), 0)) {
after_passthrough_option = 1;
@@ -111,7 +109,7 @@ md_cmd_line_from_string_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List comma
}
// NOTE(rjf): This string is an option.
if(is_option)
if (is_option)
{
MD_B32 has_arguments = 0;
MD_U64 arg_signifier_position1 = md_str8_find_needle(option_name, 0, md_str8_lit(":"), 0);
+9 -9
View File
@@ -44,7 +44,7 @@ struct MD_CmdLine
MD_U64 md_cmd_line_hash_from_string(MD_String8 string);
MD_API MD_CmdLineOpt** md_cmd_line_slot_from_string(MD_CmdLine* cmd_line, MD_String8 string);
MD_API MD_CmdLineOpt* md_cmd_line_opt_from_slot (MD_CmdLineOpt** slot, MD_String8 string);
void md_cmd_line_push_opt (MD_CmdLineOptList* list, MD_CmdLineOpt* var);
void md_cmd_line_push_opt (MD_CmdLineOptList* list, MD_CmdLineOpt* var);
MD_CmdLineOpt* md_cmd_line_opt_from_string (MD_CmdLine* cmd_line, MD_String8 name);
MD_String8List md_cmd_line_strings (MD_CmdLine* cmd_line, MD_String8 name);
@@ -58,16 +58,16 @@ inline MD_CmdLine md_cmd_line_from_string_list__arena(MD_Arena* aren
MD_API MD_CmdLine md_cmd_line_from_string_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List arguments);
#define md_cmd_line_insert_opt(allocator, cmd_line, string, values) \
_Generic(allocator, \
MD_Arena*: md_cmd_line_insert_opt__arena, \
MD_AllocatorInfo: md_cmd_line_insert_opt__ainfo, \
default: md_assert_generic_sel_fail \
_Generic(allocator, \
MD_Arena*: md_cmd_line_insert_opt__arena, \
MD_AllocatorInfo: md_cmd_line_insert_opt__ainfo, \
default: md_assert_generic_sel_fail \
) md_generic_call(allocator, cmd_line, string, values)
#define md_cmd_line_from_string_list(allocator, arguments) \
_Generic(allocator, \
MD_Arena*: md_cmd_line_from_string_list__arena, \
MD_AllocatorInfo: md_cmd_line_from_string_list__ainfo, \
_Generic(allocator, \
MD_Arena*: md_cmd_line_from_string_list__arena, \
MD_AllocatorInfo: md_cmd_line_from_string_list__ainfo, \
default: md_assert_generic_sel_fail \
) md_generic_call(allocator, arguments)
@@ -81,7 +81,7 @@ md_cmd_line_hash_from_string(MD_String8 string) {
}
md_force_inline MD_CmdLineOpt* md_cmd_line_insert_opt__arena (MD_Arena* arena, MD_CmdLine* cmd_line, MD_String8 string, MD_String8List values) { return md_cmd_line_insert_opt__ainfo (md_arena_allocator(arena), cmd_line, string, values); }
md_force_inline MD_CmdLine md_cmd_line_from_string_list__arena(MD_Arena* arena, MD_String8List command_line) { return md_cmd_line_from_string_list__ainfo(md_arena_allocator(arena), command_line); }
md_force_inline MD_CmdLine md_cmd_line_from_string_list__arena(MD_Arena* arena, MD_String8List command_line) { return md_cmd_line_from_string_list__ainfo(md_arena_allocator(arena), command_line); }
inline MD_CmdLineOpt* md_cmd_line_opt_from_string(MD_CmdLine *cmd_line, MD_String8 name) { return md_cmd_line_opt_from_slot(md_cmd_line_slot_from_string(cmd_line, name), name); }
inline MD_B32 md_cmd_line_has_flag (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0); }
-2
View File
@@ -6,8 +6,6 @@
# include "base_types.h"
#endif
// TODO(Ed): Review this
////////////////////////////////
//~ rjf: Asserts
+38 -38
View File
@@ -43,7 +43,7 @@
// 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_generic_selector_defined_include_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
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
// The slot won't exist if that comma is not found.
#endif
@@ -58,12 +58,12 @@ MD_UNRESOLVED_GENERIC_SELECTION const md_assert_generic_sel_fail = {0};
// Below are generated on demand for an overlaod depdendent on a type:
// ----------------------------------------------------------------------------------------------------------------------------------
#define function_generic_example( selector_arg ) _Generic( \
(selector_arg), /* Select Via Expression*/ \
/* Extendibility slots: */ \
#define function_generic_example( selector_arg ) _Generic( \
(selector_arg), /* Select Via Expression*/ \
/* Extendibility slots: */ \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
default: md_assert_generic_sel_fail \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_call( selector_arg )
// ----------------------------------------------------------------------------------------------------------------------------------
@@ -80,46 +80,46 @@ MD_UNRESOLVED_GENERIC_SELECTION const md_assert_generic_sel_fail = {0};
size_t md_generic_example_hash__P_long( long val ) { return val * 2654435761ull; }
// To add support for long long:
#define GENERIC_SLOT_2__example_hash long long, md_generic_example_hash__P_long_long
#define MD_GENERIC_SLOT_2__example_hash long long, md_generic_example_hash__P_long_long
size_t md_generic_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
// If using an Editor with support for syntax hightlighting macros:
// MD_GENERIC_SLOT_1__example_hash and GENERIC_SLOT_2__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 generic_example_hash( function_arguments ) _Generic( \
(function_arguments), /* Select Via Expression*/ \
/* Extendibility slots: */ \
#define generic_example_hash( function_arguments ) _Generic( \
(function_arguments), /* Select Via Expression*/ \
/* Extendibility slots: */ \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_3__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_4__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_5__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_6__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_7__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_8__example_hash ) \
default: md_assert_generic_sel_fail \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_2__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_3__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_4__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_5__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_6__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_7__example_hash ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_8__example_hash ) \
default: md_assert_generic_sel_fail \
) md_generic_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_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
#define md_function_generic_example_varadic( selector_arg, ... ) _Generic( \
(selector_arg), \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_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_expression(selector_arg) ), \
#define md_function_generic_example_direct_type( selector_arg ) _Generic( \
( md_type_to_expression(selector_arg) ), \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
/* ... */ \
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_call(selector_arg)
@@ -134,12 +134,12 @@ size_t md_generic_example_hash__P_long_long( long long val ) { return val * 2654
#define example_with__l2(expr) _Generic( \
(expr), \
MD_S64 : example_with_s64, \
default: md_assert_generic_sel_fail \
MD_S64 : example_with_s64, \
default: md_assert_generic_sel_fail \
)
#define example_with(expr) \
_Generic((expr), \
MD_SSIZE : example_with_SSIZEZ \
MD_SSIZE : example_with_SSIZEZ \
default : example_with_not_SSIZE(allocator, in) \
) md_generic_call(allocator, in)
@@ -150,10 +150,10 @@ _Generic((expr), \
#define example_with_generic_layers(expr) \
_Generic( (expr), \
MD_S64 : example_with_s64, \
MD_S64 : example_with_s64, \
_Generic_L2((expr), \
MD_SSIZE: example_with_SSIZZE \
default: md_assert_generic_sel_fail \
MD_SSIZE: example_with_SSIZZE \
default: md_assert_generic_sel_fail \
), \
) md_generic_call(expr)
@@ -163,7 +163,7 @@ _Generic_L2((expr), \
#undef example_with_generic_layers
#undef function_generic_example
#undef MD_GENERIC_SLOT_1__example_hash
#undef GENERIC_SLOT_2__example_hash
#undef MD_GENERIC_SLOT_2__example_hash
#undef generic_example_hash
#undef md_function_generic_example_varadic
#undef md_function_generic_example_direct_type
+3 -3
View File
@@ -48,9 +48,9 @@ struct MD_Log
////////////////////////////////
//~ rjf: MD_Log Creation/Selection
MD_Log* md_log_alloc(MD_AllocatorInfo ainfo, MD_U64 md_arena_block_size);
void md_log_release(MD_Log* log);
MD_API void md_log_select (MD_Log* log);
MD_Log* md_log_alloc(MD_AllocatorInfo ainfo, MD_U64 md_arena_block_size);
void md_log_release(MD_Log* log);
MD_API void md_log_select (MD_Log* log);
inline MD_Log*
md_log_alloc(MD_AllocatorInfo ainfo, MD_U64 md_arena_block_size) {
+9 -9
View File
@@ -158,30 +158,30 @@
#define md_src_line_str md_stringify(__LINE__)
#ifndef md_do_once
#define md_do_once() \
#define md_do_once() \
md_local_persist int __do_once_counter_##md_src_line_str = 0; \
for(; __do_once_counter_##md_src_line_str != 1; __do_once_counter_##md_src_line_str = 1 ) \
#define md_do_once_defer( expression ) \
#define md_do_once_defer( expression ) \
md_local_persist int __do_once_counter_##md_src_line_str = 0; \
for(;__do_once_counter_##md_src_line_str != 1; __do_once_counter_##md_src_line_str = 1, (expression)) \
#define md_do_once_start \
#define md_do_once_start \
do \
{ \
md_local_persist \
md_local_persist \
bool done = false; \
if ( done ) \
break; \
done = true;
#define md_do_once_end \
} \
#define md_do_once_end \
} \
while(0);
#endif
#define ct_if(expr, then, else) _Generic( \
(&(char[1 + !!(EXPR)]){0}), \
char (*)[2]: (THEN), \
char (*)[1]: (ELSE) \
(&(char[1 + !!(expr)]){0}), \
char (*)[2]: (then), \
char (*)[1]: (else) \
)
+173 -173
View File
@@ -432,55 +432,55 @@ inline MD_F64 md_mix_1f64(MD_F64 a, MD_F64 b, MD_F64 t) { MD_F64 c = (a + (b - a
// ==================== 2D Vectors ====================
#define md_v2f32(x, y) md_vec_2f32((x), (y))
inline MD_Vec2F32 md_vec_2f32 (MD_F32 x, MD_F32 y) { MD_Vec2F32 v = { x, y }; return v; }
inline MD_Vec2F32 md_add_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2F32 md_sub_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2F32 md_mul_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2F32 md_div_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2F32 md_scale_2f32 (MD_Vec2F32 v, MD_F32 s) { MD_Vec2F32 c = {v.x * s, v.y * s }; return c; }
inline MD_F32 md_dot_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_F32 c = a.x * b.x + a.y * b.y; return c; }
inline MD_F32 md_length_squared_2f32(MD_Vec2F32 v) { MD_F32 c = v.x * v.x + v.y * v.y; return c; }
inline MD_F32 md_length_2f32 (MD_Vec2F32 v) { MD_F32 c = md_sqrt_f32(v.x*v.x + v.y*v.y); return c; }
inline MD_Vec2F32 md_normalize_2f32 (MD_Vec2F32 v) { v = md_scale_2f32(v, 1.f / md_length_2f32(v)); return v; }
inline MD_Vec2F32 md_vec_2f32 (MD_F32 x, MD_F32 y) { MD_Vec2F32 v = { x, y }; return v; }
inline MD_Vec2F32 md_add_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2F32 md_sub_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2F32 md_mul_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2F32 md_div_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_Vec2F32 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2F32 md_scale_2f32 (MD_Vec2F32 v, MD_F32 s) { MD_Vec2F32 c = {v.x * s, v.y * s }; return c; }
inline MD_F32 md_dot_2f32 (MD_Vec2F32 a, MD_Vec2F32 b) { MD_F32 c = a.x * b.x + a.y * b.y; return c; }
inline MD_F32 md_length_squared_2f32(MD_Vec2F32 v) { MD_F32 c = v.x * v.x + v.y * v.y; return c; }
inline MD_F32 md_length_2f32 (MD_Vec2F32 v) { MD_F32 c = md_sqrt_f32(v.x*v.x + v.y*v.y); return c; }
inline MD_Vec2F32 md_normalize_2f32 (MD_Vec2F32 v) { v = md_scale_2f32(v, 1.f / md_length_2f32(v)); return v; }
inline MD_Vec2F32 md_mix_2f32 (MD_Vec2F32 a, MD_Vec2F32 b, MD_F32 t) { MD_Vec2F32 c = {md_mix_1f32(a.x, b.x, t), md_mix_1f32(a.y, b.y, t)}; return c; }
#define md_v2s64(x, y) md_vec_2s64((x), (y))
inline MD_Vec2S64 md_vec_2s64 (MD_S64 x, MD_S64 y) { MD_Vec2S64 v = { x, y }; return v; }
inline MD_Vec2S64 md_add_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2S64 md_sub_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2S64 md_mul_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2S64 md_div_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2S64 md_scale_2s64 (MD_Vec2S64 v, MD_S64 s) { MD_Vec2S64 c = {v.x * s, v.y * s }; return c; }
inline MD_S64 md_dot_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_S64 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S64 md_length_squared_2s64(MD_Vec2S64 v) { MD_S64 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S64 md_length_2s64 (MD_Vec2S64 v) { MD_S64 c = (MD_S64)md_sqrt_f64((MD_F64)(v.x*v.x + v.y*v.y)); return c; }
inline MD_Vec2S64 md_normalize_2s64 (MD_Vec2S64 v) { v = md_scale_2s64(v, (MD_S64)(1.f / md_length_2s64(v))); return v; }
inline MD_Vec2S64 md_vec_2s64 (MD_S64 x, MD_S64 y) { MD_Vec2S64 v = { x, y }; return v; }
inline MD_Vec2S64 md_add_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2S64 md_sub_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2S64 md_mul_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2S64 md_div_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_Vec2S64 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2S64 md_scale_2s64 (MD_Vec2S64 v, MD_S64 s) { MD_Vec2S64 c = {v.x * s, v.y * s }; return c; }
inline MD_S64 md_dot_2s64 (MD_Vec2S64 a, MD_Vec2S64 b) { MD_S64 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S64 md_length_squared_2s64(MD_Vec2S64 v) { MD_S64 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S64 md_length_2s64 (MD_Vec2S64 v) { MD_S64 c = (MD_S64)md_sqrt_f64((MD_F64)(v.x*v.x + v.y*v.y)); return c; }
inline MD_Vec2S64 md_normalize_2s64 (MD_Vec2S64 v) { v = md_scale_2s64(v, (MD_S64)(1.f / md_length_2s64(v))); return v; }
inline MD_Vec2S64 md_mix_2s64 (MD_Vec2S64 a, MD_Vec2S64 b, MD_F32 t) { MD_Vec2S64 c = {(MD_S64)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S64)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t)}; return c; }
#define md_v2s32(x, y) md_vec_2s32((x), (y))
inline MD_Vec2S32 md_vec_2s32 (MD_S32 x, MD_S32 y) { MD_Vec2S32 v = { x, y }; return v; }
inline MD_Vec2S32 md_add_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2S32 md_sub_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2S32 md_mul_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2S32 md_div_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2S32 md_scale_2s32 (MD_Vec2S32 v, MD_S32 s) { MD_Vec2S32 c = {v.x * s, v.y * s }; return c; }
inline MD_S32 md_dot_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_S32 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S32 md_length_squared_2s32(MD_Vec2S32 v) { MD_S32 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S32 md_length_2s32 (MD_Vec2S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)v.x*(MD_F32)v.x + (MD_F32)v.y*(MD_F32)v.y); return c; }
inline MD_Vec2S32 md_normalize_2s32 (MD_Vec2S32 v) { v = md_scale_2s32(v, (MD_S32)(1.f / md_length_2s32(v))); return v; }
inline MD_Vec2S32 md_vec_2s32 (MD_S32 x, MD_S32 y) { MD_Vec2S32 v = { x, y }; return v; }
inline MD_Vec2S32 md_add_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x + b.x, a.y + b.y}; return c; }
inline MD_Vec2S32 md_sub_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x - b.x, a.y - b.y}; return c; }
inline MD_Vec2S32 md_mul_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x * b.x, a.y * b.y}; return c; }
inline MD_Vec2S32 md_div_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_Vec2S32 c = {a.x / b.x, a.y / b.y}; return c; }
inline MD_Vec2S32 md_scale_2s32 (MD_Vec2S32 v, MD_S32 s) { MD_Vec2S32 c = {v.x * s, v.y * s }; return c; }
inline MD_S32 md_dot_2s32 (MD_Vec2S32 a, MD_Vec2S32 b) { MD_S32 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S32 md_length_squared_2s32(MD_Vec2S32 v) { MD_S32 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S32 md_length_2s32 (MD_Vec2S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)v.x*(MD_F32)v.x + (MD_F32)v.y*(MD_F32)v.y); return c; }
inline MD_Vec2S32 md_normalize_2s32 (MD_Vec2S32 v) { v = md_scale_2s32(v, (MD_S32)(1.f / md_length_2s32(v))); return v; }
inline MD_Vec2S32 md_mix_2s32 (MD_Vec2S32 a, MD_Vec2S32 b, MD_F32 t) { MD_Vec2S32 c = {(MD_S32)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S32)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t)}; return c; }
#define md_v2s16(x, y) md_vec_2s16((x), (y))
inline MD_Vec2S16 md_vec_2s16 (MD_S16 x, MD_S16 y) { MD_Vec2S16 v = { x, y }; return v; }
inline MD_Vec2S16 md_add_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x + b.x), (MD_S16)(a.y + b.y)}; return c; }
inline MD_Vec2S16 md_sub_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x - b.x), (MD_S16)(a.y - b.y)}; return c; }
inline MD_Vec2S16 md_mul_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x * b.x), (MD_S16)(a.y * b.y)}; return c; }
inline MD_Vec2S16 md_div_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x / b.x), (MD_S16)(a.y / b.y)}; return c; }
inline MD_Vec2S16 md_scale_2s16 (MD_Vec2S16 v, MD_S16 s) { MD_Vec2S16 c = {(MD_S16)(v.x * s ), (MD_S16)(v.y * s )}; return c; }
inline MD_S16 md_dot_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_S16 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S16 md_length_squared_2s16(MD_Vec2S16 v) { MD_S16 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S16 md_length_2s16 (MD_Vec2S16 v) { MD_S16 c = (MD_S16)md_sqrt_f32((MD_F32)(v.x*v.x + v.y*v.y)); return c; }
inline MD_Vec2S16 md_normalize_2s16 (MD_Vec2S16 v) { v = md_scale_2s16(v, (MD_S16)(1.f / md_length_2s16(v))); return v; }
inline MD_Vec2S16 md_vec_2s16 (MD_S16 x, MD_S16 y) { MD_Vec2S16 v = { x, y }; return v; }
inline MD_Vec2S16 md_add_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x + b.x), (MD_S16)(a.y + b.y)}; return c; }
inline MD_Vec2S16 md_sub_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x - b.x), (MD_S16)(a.y - b.y)}; return c; }
inline MD_Vec2S16 md_mul_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x * b.x), (MD_S16)(a.y * b.y)}; return c; }
inline MD_Vec2S16 md_div_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_Vec2S16 c = {(MD_S16)(a.x / b.x), (MD_S16)(a.y / b.y)}; return c; }
inline MD_Vec2S16 md_scale_2s16 (MD_Vec2S16 v, MD_S16 s) { MD_Vec2S16 c = {(MD_S16)(v.x * s ), (MD_S16)(v.y * s )}; return c; }
inline MD_S16 md_dot_2s16 (MD_Vec2S16 a, MD_Vec2S16 b) { MD_S16 c = a.x * b.x + a.y * b.y; return c; }
inline MD_S16 md_length_squared_2s16(MD_Vec2S16 v) { MD_S16 c = v.x * v.x + v.y * v.y; return c; }
inline MD_S16 md_length_2s16 (MD_Vec2S16 v) { MD_S16 c = (MD_S16)md_sqrt_f32((MD_F32)(v.x*v.x + v.y*v.y)); return c; }
inline MD_Vec2S16 md_normalize_2s16 (MD_Vec2S16 v) { v = md_scale_2s16(v, (MD_S16)(1.f / md_length_2s16(v))); return v; }
inline MD_Vec2S16 md_mix_2s16 (MD_Vec2S16 a, MD_Vec2S16 b, MD_F32 t) { MD_Vec2S16 c = {(MD_S16)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S16)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t)}; return c; }
#define md_vec2(a, b) _Generic(a, MD_S16: md_vec_2s16, MD_S32: md_vec_2s32, MD_S64: md_vec_2s64, MD_F32: md_vec_2f32 )((a), (b))
@@ -499,31 +499,31 @@ inline MD_Vec2S16 md_mix_2s16 (MD_Vec2S16 a, MD_Vec2S16 b, MD_F32 t) {
#define md_v3f32(x, y, z) md_vec_3f32((x), (y), (z))
inline MD_Vec3F32 md_vec_3f32 (MD_F32 x, MD_F32 y, MD_F32 z) { MD_Vec3F32 v = {x, y, z}; return v; }
inline MD_Vec3F32 md_add_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
inline MD_Vec3F32 md_sub_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
inline MD_Vec3F32 md_mul_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
inline MD_Vec3F32 md_div_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
inline MD_Vec3F32 md_scale_3f32 (MD_Vec3F32 v, MD_F32 s) { MD_Vec3F32 c = {v.x * s, v.y * s, v.z * s}; return c; }
inline MD_F32 md_dot_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_F32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
inline MD_F32 md_length_squared_3f32(MD_Vec3F32 v) { MD_F32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
inline MD_F32 md_length_3f32 (MD_Vec3F32 v) { MD_F32 c = md_sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z); return c; }
inline MD_Vec3F32 md_normalize_3f32 (MD_Vec3F32 v) { v = md_scale_3f32(v, 1.f / md_length_3f32(v)); return v; }
inline MD_Vec3F32 md_add_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
inline MD_Vec3F32 md_sub_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
inline MD_Vec3F32 md_mul_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
inline MD_Vec3F32 md_div_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_Vec3F32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
inline MD_Vec3F32 md_scale_3f32 (MD_Vec3F32 v, MD_F32 s) { MD_Vec3F32 c = {v.x * s, v.y * s, v.z * s}; return c; }
inline MD_F32 md_dot_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_F32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
inline MD_F32 md_length_squared_3f32(MD_Vec3F32 v) { MD_F32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
inline MD_F32 md_length_3f32 (MD_Vec3F32 v) { MD_F32 c = md_sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z); return c; }
inline MD_Vec3F32 md_normalize_3f32 (MD_Vec3F32 v) { v = md_scale_3f32(v, 1.f / md_length_3f32(v)); return v; }
inline MD_Vec3F32 md_mix_3f32 (MD_Vec3F32 a, MD_Vec3F32 b, MD_F32 t) { MD_Vec3F32 c = {md_mix_1f32(a.x, b.x, t), md_mix_1f32(a.y, b.y, t), md_mix_1f32(a.z, b.z, t)}; return c; }
inline MD_Vec3F32 md_cross_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_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; }
inline MD_Vec3F32 md_cross_3f32 (MD_Vec3F32 a, MD_Vec3F32 b) { MD_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 md_v3s32(x, y, z) md_vec_3s32((x), (y), (z))
inline MD_Vec3S32 md_vec_3s32 (MD_S32 x, MD_S32 y, MD_S32 z) { MD_Vec3S32 v = {x, y, z}; return v; }
inline MD_Vec3S32 md_add_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
inline MD_Vec3S32 md_sub_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
inline MD_Vec3S32 md_mul_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
inline MD_Vec3S32 md_div_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
inline MD_Vec3S32 md_scale_3s32 (MD_Vec3S32 v, MD_S32 s) { MD_Vec3S32 c = {v.x * s, v.y * s, v.z * s }; return c; }
inline MD_S32 md_dot_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_S32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
inline MD_S32 md_length_squared_3s32(MD_Vec3S32 v) { MD_S32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
inline MD_S32 md_length_3s32 (MD_Vec3S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)(v.x * v.x + v.y * v.y + v.z * v.z)); return c; }
inline MD_Vec3S32 md_normalize_3s32 (MD_Vec3S32 v) { v = md_scale_3s32(v, (MD_S32)(1.f / md_length_3s32(v))); return v; }
inline MD_Vec3S32 md_add_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x + b.x, a.y + b.y, a.z + b.z}; return c; }
inline MD_Vec3S32 md_sub_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x - b.x, a.y - b.y, a.z - b.z}; return c; }
inline MD_Vec3S32 md_mul_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x * b.x, a.y * b.y, a.z * b.z}; return c; }
inline MD_Vec3S32 md_div_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_Vec3S32 c = {a.x / b.x, a.y / b.y, a.z / b.z}; return c; }
inline MD_Vec3S32 md_scale_3s32 (MD_Vec3S32 v, MD_S32 s) { MD_Vec3S32 c = {v.x * s, v.y * s, v.z * s }; return c; }
inline MD_S32 md_dot_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_S32 c = a.x * b.x + a.y * b.y + a.z * b.z; return c; }
inline MD_S32 md_length_squared_3s32(MD_Vec3S32 v) { MD_S32 c = v.x * v.x + v.y * v.y + v.z * v.z; return c; }
inline MD_S32 md_length_3s32 (MD_Vec3S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)(v.x * v.x + v.y * v.y + v.z * v.z)); return c; }
inline MD_Vec3S32 md_normalize_3s32 (MD_Vec3S32 v) { v = md_scale_3s32(v, (MD_S32)(1.f / md_length_3s32(v))); return v; }
inline MD_Vec3S32 md_mix_3s32 (MD_Vec3S32 a, MD_Vec3S32 b, MD_F32 t) { MD_Vec3S32 c = {(MD_S32)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S32)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t), (MD_S32)md_mix_1f32((MD_F32)a.z, (MD_F32)b.z, t)}; return c; }
inline MD_Vec3S32 md_cross_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_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; }
inline MD_Vec3S32 md_cross_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD_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 md_vec3(a, b, c) _Generic(a, MD_S32: md_vec_3s32, MD_F32: md_vec_3f32 )((a), (b), (c))
#define md_add_vec3(a, b) _Generic(a, MD_S32: md_add_3s32, MD_F32: md_add_3f32 )((a), (b))
@@ -541,30 +541,30 @@ inline MD_Vec3S32 md_cross_3s32 (MD_Vec3S32 a, MD_Vec3S32 b) { MD
// ==================== 4D Vectors ====================
#define md_v4f32(x, y, z, w) md_vec_4f32((x), (y), (z), (w))
inline MD_Vec4F32 md_vec_4f32 (MD_F32 x, MD_F32 y, MD_F32 z, MD_F32 w) { MD_Vec4F32 v = {x, y, z, w}; return v; }
inline MD_Vec4F32 md_add_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
inline MD_Vec4F32 md_sub_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
inline MD_Vec4F32 md_mul_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
inline MD_Vec4F32 md_div_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
inline MD_Vec4F32 md_scale_4f32 (MD_Vec4F32 v, MD_F32 s) { MD_Vec4F32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
inline MD_F32 md_dot_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_F32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
inline MD_F32 md_length_squared_4f32(MD_Vec4F32 v) { MD_F32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
inline MD_F32 md_length_4f32 (MD_Vec4F32 v) { MD_F32 c = md_sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); return c; }
inline MD_Vec4F32 md_normalize_4f32 (MD_Vec4F32 v) { v = md_scale_4f32(v, 1.f / md_length_4f32(v)); return v; }
inline MD_Vec4F32 md_mix_4f32 (MD_Vec4F32 a, MD_Vec4F32 b, MD_F32 t) { MD_Vec4F32 c = {md_mix_1f32(a.x, b.x, t), md_mix_1f32(a.y, b.y, t), md_mix_1f32(a.z, b.z, t), md_mix_1f32(a.w, b.w, t)}; return c; }
inline MD_Vec4F32 md_vec_4f32 (MD_F32 x, MD_F32 y, MD_F32 z, MD_F32 w) { MD_Vec4F32 v = {x, y, z, w}; return v; }
inline MD_Vec4F32 md_add_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
inline MD_Vec4F32 md_sub_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
inline MD_Vec4F32 md_mul_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
inline MD_Vec4F32 md_div_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_Vec4F32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
inline MD_Vec4F32 md_scale_4f32 (MD_Vec4F32 v, MD_F32 s) { MD_Vec4F32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
inline MD_F32 md_dot_4f32 (MD_Vec4F32 a, MD_Vec4F32 b) { MD_F32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
inline MD_F32 md_length_squared_4f32(MD_Vec4F32 v) { MD_F32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
inline MD_F32 md_length_4f32 (MD_Vec4F32 v) { MD_F32 c = md_sqrt_f32(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); return c; }
inline MD_Vec4F32 md_normalize_4f32 (MD_Vec4F32 v) { v = md_scale_4f32(v, 1.f / md_length_4f32(v)); return v; }
inline MD_Vec4F32 md_mix_4f32 (MD_Vec4F32 a, MD_Vec4F32 b, MD_F32 t) { MD_Vec4F32 c = {md_mix_1f32(a.x, b.x, t), md_mix_1f32(a.y, b.y, t), md_mix_1f32(a.z, b.z, t), md_mix_1f32(a.w, b.w, t)}; return c; }
#define v4s32(x, y, z, w) md_vec_4s32((x), (y), (z), (w))
inline MD_Vec4S32 md_vec_4s32 (MD_S32 x, MD_S32 y, MD_S32 z, MD_S32 w) { MD_Vec4S32 v = {x, y, z, w}; return v; }
inline MD_Vec4S32 md_add_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
inline MD_Vec4S32 md_sub_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
inline MD_Vec4S32 md_mul_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
inline MD_Vec4S32 md_div_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
inline MD_Vec4S32 md_scale_4s32 (MD_Vec4S32 v, MD_S32 s) { MD_Vec4S32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
inline MD_S32 md_dot_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_S32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
inline MD_S32 md_length_squared_4s32(MD_Vec4S32 v) { MD_S32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
inline MD_S32 md_length_4s32 (MD_Vec4S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w)); return c; }
inline MD_Vec4S32 md_normalize_4s32 (MD_Vec4S32 v) { v = md_scale_4s32(v, (MD_S32)(1.f / md_length_4s32(v))); return v; }
inline MD_Vec4S32 md_mix_4s32 (MD_Vec4S32 a, MD_Vec4S32 b, MD_F32 t) { MD_Vec4S32 c = {(MD_S32)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S32)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t), (MD_S32)md_mix_1f32((MD_F32)a.z, (MD_F32)b.z, t), (MD_S32)md_mix_1f32((MD_F32)a.w, (MD_F32)b.w, t)}; return c; }
inline MD_Vec4S32 md_vec_4s32 (MD_S32 x, MD_S32 y, MD_S32 z, MD_S32 w) { MD_Vec4S32 v = {x, y, z, w}; return v; }
inline MD_Vec4S32 md_add_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; return c; }
inline MD_Vec4S32 md_sub_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; return c; }
inline MD_Vec4S32 md_mul_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w}; return c; }
inline MD_Vec4S32 md_div_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_Vec4S32 c = {a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w}; return c; }
inline MD_Vec4S32 md_scale_4s32 (MD_Vec4S32 v, MD_S32 s) { MD_Vec4S32 c = {v.x * s, v.y * s, v.z * s, v.w * s }; return c; }
inline MD_S32 md_dot_4s32 (MD_Vec4S32 a, MD_Vec4S32 b) { MD_S32 c = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return c; }
inline MD_S32 md_length_squared_4s32(MD_Vec4S32 v) { MD_S32 c = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; return c; }
inline MD_S32 md_length_4s32 (MD_Vec4S32 v) { MD_S32 c = (MD_S32)md_sqrt_f32((MD_F32)(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w)); return c; }
inline MD_Vec4S32 md_normalize_4s32 (MD_Vec4S32 v) { v = md_scale_4s32(v, (MD_S32)(1.f / md_length_4s32(v))); return v; }
inline MD_Vec4S32 md_mix_4s32 (MD_Vec4S32 a, MD_Vec4S32 b, MD_F32 t) { MD_Vec4S32 c = {(MD_S32)md_mix_1f32((MD_F32)a.x, (MD_F32)b.x, t), (MD_S32)md_mix_1f32((MD_F32)a.y, (MD_F32)b.y, t), (MD_S32)md_mix_1f32((MD_F32)a.z, (MD_F32)b.z, t), (MD_S32)md_mix_1f32((MD_F32)a.w, (MD_F32)b.w, t)}; return c; }
#define md_vec4(a, b, c, d) _Generic(a, MD_S32: md_vec_4s32, MD_F32: md_vec_4f32 )((a), (b), (c), (d))
#define md_add_vec4(a, b) _Generic(a, MD_S32: md_add_4s32, MD_F32: md_add_4f32 )((a), (b))
@@ -583,18 +583,18 @@ inline MD_Vec4S32 md_mix_4s32 (MD_Vec4S32 a, MD_Vec4S32 b, MD_F32 t) {
// ==================== 3x3 Matrix ====================
inline MD_Mat3x3F32 md_mat_3x3f32 (MD_F32 diag) { MD_Mat3x3F32 res = {0}; res.v[0][0] = diag; res.v[1][1] = diag; res.v[2][2] = diag; return res; }
inline MD_Mat3x3F32 md_make_translate_3x3f32(MD_Vec2F32 delta) { MD_Mat3x3F32 mat = md_mat_3x3f32(1.f); mat.v[2][0] = delta.x; mat.v[2][1] = delta.y; return mat; }
inline MD_Mat3x3F32 md_make_scale_3x3f32 (MD_Vec2F32 scale) { MD_Mat3x3F32 mat = md_mat_3x3f32(1.f); mat.v[0][0] = scale.x; mat.v[1][1] = scale.y; return mat; }
inline MD_Mat3x3F32 md_mat_3x3f32 (MD_F32 diag) { MD_Mat3x3F32 res = {0}; res.v[0][0] = diag; res.v[1][1] = diag; res.v[2][2] = diag; return res; }
inline MD_Mat3x3F32 md_make_translate_3x3f32(MD_Vec2F32 delta) { MD_Mat3x3F32 mat = md_mat_3x3f32(1.f); mat.v[2][0] = delta.x; mat.v[2][1] = delta.y; return mat; }
inline MD_Mat3x3F32 md_make_scale_3x3f32 (MD_Vec2F32 scale) { MD_Mat3x3F32 mat = md_mat_3x3f32(1.f); mat.v[0][0] = scale.x; mat.v[1][1] = scale.y; return mat; }
inline MD_Mat3x3F32 md_mul_3x3f32 (MD_Mat3x3F32 a, MD_Mat3x3F32 b) { MD_Mat3x3F32 c = {0}; for(int j = 0; j < 3; j += 1) for(int i = 0; i < 3; i += 1) { c.v[i][j] = (a.v[0][j]*b.v[i][0] + a.v[1][j] * b.v[i][1] + a.v[2][j] * b.v[i][2]); } return c; }
inline MD_Mat4x4F32 md_mat_4x4f32 (MD_F32 diag) { MD_Mat4x4F32 res = {0}; res.v[0][0] = diag; res.v[1][1] = diag; res.v[2][2] = diag; res.v[3][3] = diag; return res; }
inline MD_Mat4x4F32 md_mat_4x4f32 (MD_F32 diag) { MD_Mat4x4F32 res = {0}; res.v[0][0] = diag; res.v[1][1] = diag; res.v[2][2] = diag; res.v[3][3] = diag; return res; }
inline MD_Mat4x4F32 md_make_translate_4x4f32(MD_Vec3F32 delta) { MD_Mat4x4F32 res = md_mat_4x4f32(1.f); res.v[3][0] = delta.x; res.v[3][1] = delta.y; res.v[3][2] = delta.z; return res; }
inline MD_Mat4x4F32 md_make_scale_4x4f32 (MD_Vec3F32 scale) { MD_Mat4x4F32 res = md_mat_4x4f32(1.f); res.v[0][0] = scale.x; res.v[1][1] = scale.y; res.v[2][2] = scale.z; return res; }
// ==================== 4x4 Matrix ====================
MD_Mat4x4F32 md_make_perspective_4x4f32 (MD_F32 fov, MD_F32 aspect_ratio, MD_F32 near_z, MD_F32 far_z);
MD_Mat4x4F32 md_make_perspective_4x4f32 (MD_F32 fov, MD_F32 aspect_ratio, MD_F32 near_z, MD_F32 far_z);
MD_Mat4x4F32 md_make_orthographic_4x4f32(MD_F32 left, MD_F32 right, MD_F32 bottom, MD_F32 top, MD_F32 near_z, MD_F32 far_z);
MD_Mat4x4F32 md_make_look_at_4x4f32 (MD_Vec3F32 eye, MD_Vec3F32 center, MD_Vec3F32 up);
MD_Mat4x4F32 md_make_rotate_4x4f32 (MD_Vec3F32 axis, MD_F32 turns);
@@ -642,16 +642,16 @@ md_make_look_at_4x4f32(MD_Vec3F32 eye, MD_Vec3F32 center, MD_Vec3F32 up) {
MD_Vec3F32 f = md_normalize_3f32(md_sub_3f32(eye, center));
MD_Vec3F32 s = md_normalize_3f32(md_cross_3f32(f, up));
MD_Vec3F32 u = md_cross_3f32(s, f);
result.v[0][0] = s.x; result.v[0][1] = u.x; result.v[0][2] = -f.x; result.v[0][3] = 0.0f;
result.v[1][0] = s.y; result.v[1][1] = u.y; result.v[1][2] = -f.y; result.v[1][3] = 0.0f;
result.v[2][0] = s.z; result.v[2][1] = u.z; result.v[2][2] = -f.z; result.v[2][3] = 0.0f;
result.v[0][0] = s.x; result.v[0][1] = u.x; result.v[0][2] = -f.x; result.v[0][3] = 0.0f;
result.v[1][0] = s.y; result.v[1][1] = u.y; result.v[1][2] = -f.y; result.v[1][3] = 0.0f;
result.v[2][0] = s.z; result.v[2][1] = u.z; result.v[2][2] = -f.z; result.v[2][3] = 0.0f;
result.v[3][0] = -md_dot_3f32(s, eye); result.v[3][1] = -md_dot_3f32(u, eye); result.v[3][2] = md_dot_3f32(f, eye); result.v[3][3] = 1.0f;
return result;
}
inline MD_Mat4x4F32
md_make_rotate_4x4f32(MD_Vec3F32 axis, MD_F32 turns) {
axis = md_normalize_3f32(axis);
axis = md_normalize_3f32(axis);
MD_F32 sin_theta = md_sin_f32(turns);
MD_F32 cos_theta = md_cos_f32(turns);
MD_F32 cos_value = 1.f - cos_theta;
@@ -725,8 +725,8 @@ md_inverse_4x4f32(MD_Mat4x4F32 m) {
MD_Vec4F32 fac4 = { coef16, coef16, coef18, coef19 };
MD_Vec4F32 fac5 = { coef20, coef20, coef22, coef23 };
MD_Vec4F32 vec0 = { m.v[1][0], m.v[0][0], m.v[0][0], m.v[0][0] };
MD_Vec4F32 vec1 = { m.v[1][1], m.v[0][1], m.v[0][1], m.v[0][1] };
MD_Vec4F32 vec0 = { m.v[1][0], m.v[0][0], m.v[0][0], m.v[0][0] };
MD_Vec4F32 vec1 = { m.v[1][1], m.v[0][1], m.v[0][1], m.v[0][1] };
MD_Vec4F32 md_vec2 = { m.v[1][2], m.v[0][2], m.v[0][2], m.v[0][2] };
MD_Vec4F32 md_vec3 = { m.v[1][3], m.v[0][3], m.v[0][3], m.v[0][3] };
@@ -774,97 +774,97 @@ md_derotate_4x4f32(MD_Mat4x4F32 mat) {
// ==================== 1D Ranges ====================
#define md_r1u32(md_min, md_max) md_rng_1u32((md_min), (md_max))
inline MD_Rng1U32 md_rng_1u32 (MD_U32 md_min, MD_U32 md_max) { MD_Rng1U32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_U32, r.md_min, r.md_max); } return r; }
inline MD_Rng1U32 md_shift_1u32 (MD_Rng1U32 r, MD_U32 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1U32 md_pad_1u32 (MD_Rng1U32 r, MD_U32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_U32 md_center_1u32 (MD_Rng1U32 r) { MD_U32 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1u32 (MD_Rng1U32 r, MD_U32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_U32 md_dim_1u32 (MD_Rng1U32 r) { MD_U32 c = r.md_max - r.md_min; return c; }
inline MD_Rng1U32 md_union_1u32 (MD_Rng1U32 a, MD_Rng1U32 b) { MD_Rng1U32 c = {md_min(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_Rng1U32 md_intersect_1u32(MD_Rng1U32 a, MD_Rng1U32 b) { MD_Rng1U32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_U32 md_clamp_1u32 (MD_Rng1U32 r, MD_U32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
inline MD_Rng1U32 md_rng_1u32 (MD_U32 md_min, MD_U32 md_max) { MD_Rng1U32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_U32, r.md_min, r.md_max); } return r; }
inline MD_Rng1U32 md_shift_1u32 (MD_Rng1U32 r, MD_U32 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1U32 md_pad_1u32 (MD_Rng1U32 r, MD_U32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_U32 md_center_1u32 (MD_Rng1U32 r) { MD_U32 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1u32 (MD_Rng1U32 r, MD_U32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_U32 md_dim_1u32 (MD_Rng1U32 r) { MD_U32 c = r.md_max - r.md_min; return c; }
inline MD_Rng1U32 md_union_1u32 (MD_Rng1U32 a, MD_Rng1U32 b) { MD_Rng1U32 c = {md_min(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_Rng1U32 md_intersect_1u32(MD_Rng1U32 a, MD_Rng1U32 b) { MD_Rng1U32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_U32 md_clamp_1u32 (MD_Rng1U32 r, MD_U32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
#define md_r1s32(md_min, md_max) md_rng_1s32((md_min), (md_max))
inline MD_Rng1S32 md_rng_1s32 (MD_S32 md_min, MD_S32 md_max) { MD_Rng1S32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_S32, r.md_min, r.md_max); } return r; }
inline MD_Rng1S32 md_shift_1s32 (MD_Rng1S32 r, MD_S32 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1S32 md_pad_1s32 (MD_Rng1S32 r, MD_S32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_S32 md_center_1s32 (MD_Rng1S32 r) { MD_S32 c = (r.md_min+r.md_max) / 2; return c; }
inline MD_B32 md_contains_1s32 (MD_Rng1S32 r, MD_S32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_S32 md_dim_1s32 (MD_Rng1S32 r) { MD_S32 c = r.md_max-r.md_min; return c; }
inline MD_Rng1S32 md_union_1s32 (MD_Rng1S32 a, MD_Rng1S32 b) { MD_Rng1S32 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline MD_Rng1S32 md_intersect_1s32(MD_Rng1S32 a, MD_Rng1S32 b) { MD_Rng1S32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_S32 md_clamp_1s32 (MD_Rng1S32 r, MD_S32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
inline MD_Rng1S32 md_rng_1s32 (MD_S32 md_min, MD_S32 md_max) { MD_Rng1S32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_S32, r.md_min, r.md_max); } return r; }
inline MD_Rng1S32 md_shift_1s32 (MD_Rng1S32 r, MD_S32 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1S32 md_pad_1s32 (MD_Rng1S32 r, MD_S32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_S32 md_center_1s32 (MD_Rng1S32 r) { MD_S32 c = (r.md_min+r.md_max) / 2; return c; }
inline MD_B32 md_contains_1s32 (MD_Rng1S32 r, MD_S32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_S32 md_dim_1s32 (MD_Rng1S32 r) { MD_S32 c = r.md_max-r.md_min; return c; }
inline MD_Rng1S32 md_union_1s32 (MD_Rng1S32 a, MD_Rng1S32 b) { MD_Rng1S32 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline MD_Rng1S32 md_intersect_1s32(MD_Rng1S32 a, MD_Rng1S32 b) { MD_Rng1S32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_S32 md_clamp_1s32 (MD_Rng1S32 r, MD_S32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
#define md_r1u64(md_min, md_max) md_rng_1u64((md_min), (md_max))
inline MD_Rng1U64 md_rng_1u64 (MD_U64 md_min, MD_U64 md_max) { MD_Rng1U64 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_U64, r.md_min, r.md_max); } return r; }
inline MD_Rng1U64 md_shift_1u64 (MD_Rng1U64 r, MD_U64 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1U64 md_pad_1u64 (MD_Rng1U64 r, MD_U64 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_U64 md_center_1u64 (MD_Rng1U64 r) { MD_U64 c = (r.md_min + r.md_max)/2; return c; }
inline MD_B32 md_contains_1u64 (MD_Rng1U64 r, MD_U64 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_U64 md_dim_1u64 (MD_Rng1U64 r) { MD_U64 c = r.md_max-r.md_min; return c; }
inline MD_Rng1U64 md_union_1u64 (MD_Rng1U64 a, MD_Rng1U64 b) { MD_Rng1U64 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline MD_Rng1U64 md_intersect_1u64(MD_Rng1U64 a, MD_Rng1U64 b) { MD_Rng1U64 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_U64 md_clamp_1u64 (MD_Rng1U64 r, MD_U64 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
inline MD_Rng1U64 md_rng_1u64 (MD_U64 md_min, MD_U64 md_max) { MD_Rng1U64 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_U64, r.md_min, r.md_max); } return r; }
inline MD_Rng1U64 md_shift_1u64 (MD_Rng1U64 r, MD_U64 x) { r.md_min += x; r.md_max += x; return r; }
inline MD_Rng1U64 md_pad_1u64 (MD_Rng1U64 r, MD_U64 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_U64 md_center_1u64 (MD_Rng1U64 r) { MD_U64 c = (r.md_min + r.md_max)/2; return c; }
inline MD_B32 md_contains_1u64 (MD_Rng1U64 r, MD_U64 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_U64 md_dim_1u64 (MD_Rng1U64 r) { MD_U64 c = r.md_max-r.md_min; return c; }
inline MD_Rng1U64 md_union_1u64 (MD_Rng1U64 a, MD_Rng1U64 b) { MD_Rng1U64 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline MD_Rng1U64 md_intersect_1u64(MD_Rng1U64 a, MD_Rng1U64 b) { MD_Rng1U64 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_U64 md_clamp_1u64 (MD_Rng1U64 r, MD_U64 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
#define md_r1s64(md_min, md_max) md_rng_1s64((md_min), (md_max))
inline Rng1S64 md_rng_1s64 (MD_S64 md_min, MD_S64 md_max) { Rng1S64 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_S64, r.md_min, r.md_max); } return r; }
inline Rng1S64 md_shift_1s64 (Rng1S64 r, MD_S64 x) { r.md_min += x; r.md_max += x; return r; }
inline Rng1S64 md_pad_1s64 (Rng1S64 r, MD_S64 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_S64 md_center_1s64 (Rng1S64 r) { MD_S64 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1s64 (Rng1S64 r, MD_S64 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_S64 md_dim_1s64 (Rng1S64 r) { MD_S64 c = r.md_max - r.md_min; return c; }
inline Rng1S64 md_union_1s64 (Rng1S64 a, Rng1S64 b) { Rng1S64 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline Rng1S64 md_intersect_1s64(Rng1S64 a, Rng1S64 b) { Rng1S64 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_S64 md_clamp_1s64 (Rng1S64 r, MD_S64 v) { v = md_clamp(r.md_min, v, r.md_max); return v;}
inline Rng1S64 md_rng_1s64 (MD_S64 md_min, MD_S64 md_max) { Rng1S64 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_S64, r.md_min, r.md_max); } return r; }
inline Rng1S64 md_shift_1s64 (Rng1S64 r, MD_S64 x) { r.md_min += x; r.md_max += x; return r; }
inline Rng1S64 md_pad_1s64 (Rng1S64 r, MD_S64 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_S64 md_center_1s64 (Rng1S64 r) { MD_S64 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1s64 (Rng1S64 r, MD_S64 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_S64 md_dim_1s64 (Rng1S64 r) { MD_S64 c = r.md_max - r.md_min; return c; }
inline Rng1S64 md_union_1s64 (Rng1S64 a, Rng1S64 b) { Rng1S64 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline Rng1S64 md_intersect_1s64(Rng1S64 a, Rng1S64 b) { Rng1S64 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_S64 md_clamp_1s64 (Rng1S64 r, MD_S64 v) { v = md_clamp(r.md_min, v, r.md_max); return v;}
#define md_r1f32(md_min, md_max) md_rng_1f32((md_min), (md_max))
inline Rng1F32 md_rng_1f32 (MD_F32 md_min, MD_F32 md_max) { Rng1F32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_F32, r.md_min, r.md_max); } return r; }
inline Rng1F32 md_shift_1f32 (Rng1F32 r, MD_F32 x) { r.md_min += x; r.md_max += x; return r; }
inline Rng1F32 md_pad_1f32 (Rng1F32 r, MD_F32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_F32 md_center_1f32 (Rng1F32 r) { MD_F32 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1f32 (Rng1F32 r, MD_F32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_F32 md_dim_1f32 (Rng1F32 r) { MD_F32 c = r.md_max - r.md_min; return c; }
inline Rng1F32 md_union_1f32 (Rng1F32 a, Rng1F32 b) { Rng1F32 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline Rng1F32 md_intersect_1f32(Rng1F32 a, Rng1F32 b) { Rng1F32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_F32 md_clamp_1f32 (Rng1F32 r, MD_F32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
inline Rng1F32 md_rng_1f32 (MD_F32 md_min, MD_F32 md_max) { Rng1F32 r = {md_min, md_max}; if(r.md_min > r.md_max) { md_swap(MD_F32, r.md_min, r.md_max); } return r; }
inline Rng1F32 md_shift_1f32 (Rng1F32 r, MD_F32 x) { r.md_min += x; r.md_max += x; return r; }
inline Rng1F32 md_pad_1f32 (Rng1F32 r, MD_F32 x) { r.md_min -= x; r.md_max += x; return r; }
inline MD_F32 md_center_1f32 (Rng1F32 r) { MD_F32 c = (r.md_min + r.md_max) / 2; return c; }
inline MD_B32 md_contains_1f32 (Rng1F32 r, MD_F32 x) { MD_B32 c = (r.md_min <= x && x < r.md_max); return c; }
inline MD_F32 md_dim_1f32 (Rng1F32 r) { MD_F32 c = r.md_max - r.md_min; return c; }
inline Rng1F32 md_union_1f32 (Rng1F32 a, Rng1F32 b) { Rng1F32 c = {md_min(a.md_min, b.md_min), md_max(a.md_max, b.md_max)}; return c; }
inline Rng1F32 md_intersect_1f32(Rng1F32 a, Rng1F32 b) { Rng1F32 c = {md_max(a.md_min, b.md_min), md_min(a.md_max, b.md_max)}; return c; }
inline MD_F32 md_clamp_1f32 (Rng1F32 r, MD_F32 v) { v = md_clamp(r.md_min, v, r.md_max); return v; }
// ==================== 2D Ranges ====================
#define md_r2s16(md_min, md_max) md_rng_2s16((md_min), (md_max))
#define md_r2s16p(x, y, z, w) md_r2s16(md_v2s16((x), (y)), md_v2s16((z), (w)))
inline MD_Rng2S16 md_rng_2s16 (MD_Vec2S16 md_min, MD_Vec2S16 md_max) { MD_Rng2S16 r = {md_min, md_max}; return r; }
inline MD_Rng2S16 md_shift_2s16 (MD_Rng2S16 r, MD_Vec2S16 x) { r.md_min = md_add_2s16(r.md_min, x); r.md_max = md_add_2s16(r.md_max, x); return r; }
inline MD_Rng2S16 md_pad_2s16 (MD_Rng2S16 r, MD_S16 x) { MD_Vec2S16 xv = {x, x}; r.md_min = md_sub_2s16(r.md_min, xv); r.md_max = md_add_2s16(r.md_max, xv); return r; }
inline MD_Vec2S16 md_center_2s16 (MD_Rng2S16 r) { MD_Vec2S16 c = {(MD_S16)((r.md_min.x + r.md_max.x) / 2), (MD_S16)((r.md_min.y + r.md_max.y) / 2)}; return c; }
inline MD_B32 md_contains_2s16 (MD_Rng2S16 r, MD_Vec2S16 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S16 md_dim_2s16 (MD_Rng2S16 r) { MD_Vec2S16 dim = {(MD_S16)(r.md_max.x - r.md_min.x), (MD_S16)(r.md_max.y - r.md_min.y)}; return dim; }
inline MD_Rng2S16 md_union_2s16 (MD_Rng2S16 a, MD_Rng2S16 b) { MD_Rng2S16 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S16 md_intersect_2s16(MD_Rng2S16 a, MD_Rng2S16 b) { MD_Rng2S16 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S16 md_clamp_2s16 (MD_Rng2S16 r, MD_Vec2S16 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
inline MD_Rng2S16 md_rng_2s16 (MD_Vec2S16 md_min, MD_Vec2S16 md_max) { MD_Rng2S16 r = {md_min, md_max}; return r; }
inline MD_Rng2S16 md_shift_2s16 (MD_Rng2S16 r, MD_Vec2S16 x) { r.md_min = md_add_2s16(r.md_min, x); r.md_max = md_add_2s16(r.md_max, x); return r; }
inline MD_Rng2S16 md_pad_2s16 (MD_Rng2S16 r, MD_S16 x) { MD_Vec2S16 xv = {x, x}; r.md_min = md_sub_2s16(r.md_min, xv); r.md_max = md_add_2s16(r.md_max, xv); return r; }
inline MD_Vec2S16 md_center_2s16 (MD_Rng2S16 r) { MD_Vec2S16 c = {(MD_S16)((r.md_min.x + r.md_max.x) / 2), (MD_S16)((r.md_min.y + r.md_max.y) / 2)}; return c; }
inline MD_B32 md_contains_2s16 (MD_Rng2S16 r, MD_Vec2S16 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S16 md_dim_2s16 (MD_Rng2S16 r) { MD_Vec2S16 dim = {(MD_S16)(r.md_max.x - r.md_min.x), (MD_S16)(r.md_max.y - r.md_min.y)}; return dim; }
inline MD_Rng2S16 md_union_2s16 (MD_Rng2S16 a, MD_Rng2S16 b) { MD_Rng2S16 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S16 md_intersect_2s16(MD_Rng2S16 a, MD_Rng2S16 b) { MD_Rng2S16 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S16 md_clamp_2s16 (MD_Rng2S16 r, MD_Vec2S16 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
#define md_r2s32(md_min, md_max) md_rng_2s32((md_min), (md_max))
#define md_r2s32p(x, y, z, w) md_r2s32(md_v2s32((x), (y)), md_v2s32((z), (w)))
inline MD_Rng2S32 md_rng_2s32 (MD_Vec2S32 md_min, MD_Vec2S32 md_max) { MD_Rng2S32 r = {md_min, md_max}; return r; }
inline MD_Rng2S32 md_shift_2s32 (MD_Rng2S32 r, MD_Vec2S32 x) { r.md_min = md_add_2s32(r.md_min, x); r.md_max = md_add_2s32(r.md_max, x); return r; }
inline MD_Rng2S32 md_pad_2s32 (MD_Rng2S32 r, MD_S32 x) { MD_Vec2S32 xv = {x, x}; r.md_min = md_sub_2s32(r.md_min, xv); r.md_max = md_add_2s32(r.md_max, xv); return r; }
inline MD_Vec2S32 md_center_2s32 (MD_Rng2S32 r) { MD_Vec2S32 c = {(r.md_min.x + r.md_max.x) / 2, (r.md_min.y + r.md_max.y) / 2}; return c; }
inline MD_B32 md_contains_2s32 (MD_Rng2S32 r, MD_Vec2S32 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S32 md_dim_2s32 (MD_Rng2S32 r) { MD_Vec2S32 dim = {r.md_max.x - r.md_min.x, r.md_max.y - r.md_min.y}; return dim; }
inline MD_Rng2S32 md_union_2s32 (MD_Rng2S32 a, MD_Rng2S32 b) { MD_Rng2S32 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S32 md_intersect_2s32(MD_Rng2S32 a, MD_Rng2S32 b) { MD_Rng2S32 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S32 md_clamp_2s32 (MD_Rng2S32 r, MD_Vec2S32 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
inline MD_Rng2S32 md_rng_2s32 (MD_Vec2S32 md_min, MD_Vec2S32 md_max) { MD_Rng2S32 r = {md_min, md_max}; return r; }
inline MD_Rng2S32 md_shift_2s32 (MD_Rng2S32 r, MD_Vec2S32 x) { r.md_min = md_add_2s32(r.md_min, x); r.md_max = md_add_2s32(r.md_max, x); return r; }
inline MD_Rng2S32 md_pad_2s32 (MD_Rng2S32 r, MD_S32 x) { MD_Vec2S32 xv = {x, x}; r.md_min = md_sub_2s32(r.md_min, xv); r.md_max = md_add_2s32(r.md_max, xv); return r; }
inline MD_Vec2S32 md_center_2s32 (MD_Rng2S32 r) { MD_Vec2S32 c = {(r.md_min.x + r.md_max.x) / 2, (r.md_min.y + r.md_max.y) / 2}; return c; }
inline MD_B32 md_contains_2s32 (MD_Rng2S32 r, MD_Vec2S32 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S32 md_dim_2s32 (MD_Rng2S32 r) { MD_Vec2S32 dim = {r.md_max.x - r.md_min.x, r.md_max.y - r.md_min.y}; return dim; }
inline MD_Rng2S32 md_union_2s32 (MD_Rng2S32 a, MD_Rng2S32 b) { MD_Rng2S32 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S32 md_intersect_2s32(MD_Rng2S32 a, MD_Rng2S32 b) { MD_Rng2S32 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S32 md_clamp_2s32 (MD_Rng2S32 r, MD_Vec2S32 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
#define md_r2s64(md_min, md_max) md_rng_2s64((md_min), (md_max))
#define md_r2s64p(x, y, z, w) md_r2s64(md_v2s64((x), (y)), md_v2s64((z), (w)))
inline MD_Rng2S64 md_rng_2s64 (MD_Vec2S64 md_min, MD_Vec2S64 md_max) { MD_Rng2S64 r = {md_min, md_max}; return r; }
inline MD_Rng2S64 md_shift_2s64 (MD_Rng2S64 r, MD_Vec2S64 x) { r.md_min = md_add_2s64(r.md_min, x); r.md_max = md_add_2s64(r.md_max, x); return r; }
inline MD_Rng2S64 md_pad_2s64 (MD_Rng2S64 r, MD_S64 x) { MD_Vec2S64 xv = {x, x}; r.md_min = md_sub_2s64(r.md_min, xv); r.md_max = md_add_2s64(r.md_max, xv); return r; }
inline MD_Vec2S64 md_center_2s64 (MD_Rng2S64 r) { MD_Vec2S64 c = {(r.md_min.x + r.md_max.x) / 2, (r.md_min.y + r.md_max.y) / 2}; return c; }
inline MD_B32 md_contains_2s64 (MD_Rng2S64 r, MD_Vec2S64 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S64 md_dim_2s64 (MD_Rng2S64 r) { MD_Vec2S64 dim = {r.md_max.x - r.md_min.x, r.md_max.y - r.md_min.y}; return dim; }
inline MD_Rng2S64 md_union_2s64 (MD_Rng2S64 a, MD_Rng2S64 b) { MD_Rng2S64 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S64 md_intersect_2s64(MD_Rng2S64 a, MD_Rng2S64 b) { MD_Rng2S64 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S64 md_clamp_2s64 (MD_Rng2S64 r, MD_Vec2S64 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
inline MD_Rng2S64 md_rng_2s64 (MD_Vec2S64 md_min, MD_Vec2S64 md_max) { MD_Rng2S64 r = {md_min, md_max}; return r; }
inline MD_Rng2S64 md_shift_2s64 (MD_Rng2S64 r, MD_Vec2S64 x) { r.md_min = md_add_2s64(r.md_min, x); r.md_max = md_add_2s64(r.md_max, x); return r; }
inline MD_Rng2S64 md_pad_2s64 (MD_Rng2S64 r, MD_S64 x) { MD_Vec2S64 xv = {x, x}; r.md_min = md_sub_2s64(r.md_min, xv); r.md_max = md_add_2s64(r.md_max, xv); return r; }
inline MD_Vec2S64 md_center_2s64 (MD_Rng2S64 r) { MD_Vec2S64 c = {(r.md_min.x + r.md_max.x) / 2, (r.md_min.y + r.md_max.y) / 2}; return c; }
inline MD_B32 md_contains_2s64 (MD_Rng2S64 r, MD_Vec2S64 x) { MD_B32 c = (r.md_min.x <= x.x && x.x < r.md_max.x && r.md_min.y <= x.y && x.y < r.md_max.y); return c; }
inline MD_Vec2S64 md_dim_2s64 (MD_Rng2S64 r) { MD_Vec2S64 dim = {r.md_max.x - r.md_min.x, r.md_max.y - r.md_min.y}; return dim; }
inline MD_Rng2S64 md_union_2s64 (MD_Rng2S64 a, MD_Rng2S64 b) { MD_Rng2S64 c; c.p0.x = md_min(a.md_min.x, b.md_min.x); c.p0.y = md_min(a.md_min.y, b.md_min.y); c.p1.x = md_max(a.md_max.x, b.md_max.x); c.p1.y = md_max(a.md_max.y, b.md_max.y); return c; }
inline MD_Rng2S64 md_intersect_2s64(MD_Rng2S64 a, MD_Rng2S64 b) { MD_Rng2S64 c; c.p0.x = md_max(a.md_min.x, b.md_min.x); c.p0.y = md_max(a.md_min.y, b.md_min.y); c.p1.x = md_min(a.md_max.x, b.md_max.x); c.p1.y = md_min(a.md_max.y, b.md_max.y); return c; }
inline MD_Vec2S64 md_clamp_2s64 (MD_Rng2S64 r, MD_Vec2S64 v) { v.x = md_clamp(r.md_min.x, v.x, r.md_max.x); v.y = md_clamp(r.md_min.y, v.y, r.md_max.y); return v; }
////////////////////////////////
//~ rjf: Miscellaneous Ops
@@ -967,15 +967,15 @@ md_u32_from_rgba(MD_Vec4F32 rgba)
////////////////////////////////
//~ rjf: List Type Functions
void md_rng1s64_list_push__arena (MD_Arena* arena, MD_Rng1S64List* list, Rng1S64 rng);
void md_rng1s64_list_push__ainfo (MD_AllocatorInfo ainfo, MD_Rng1S64List* list, Rng1S64 rng);
void md_rng1s64_list_push__arena (MD_Arena* arena, MD_Rng1S64List* list, Rng1S64 rng);
void md_rng1s64_list_push__ainfo (MD_AllocatorInfo ainfo, MD_Rng1S64List* list, Rng1S64 rng);
MD_Rng1S64Array md_rng1s64_array_from_list_push__arena(MD_Arena* arena, MD_Rng1S64List* list);
MD_Rng1S64Array md_rng1s64_array_from_list_push__ainfo(MD_AllocatorInfo ainfo, MD_Rng1S64List* list);
#define rng1s64_list_push(allocator, list, rng) _Generic(allocator, MD_Arena*: md_rng1s64_list_push__arena, MD_AllocatorInfo: md_rng1s64_list_push__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, list, rng)
#define rng1s64_list_push(allocator, list, rng) _Generic(allocator, MD_Arena*: md_rng1s64_list_push__arena, MD_AllocatorInfo: md_rng1s64_list_push__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, list, rng)
#define md_rng1s64_array_from_list_push(allocator, list) _Generic(allocator, MD_Arena*: md_rng1s64_array_from_list_push__arena, MD_AllocatorInfo: md_rng1s64_array_from_list_push__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, list)
md_force_inline void md_rng1s64_list_push__arena (MD_Arena* arena, MD_Rng1S64List* list, Rng1S64 rng) { md_rng1s64_list_push__ainfo (md_arena_allocator(arena), list, rng); }
md_force_inline void md_rng1s64_list_push__arena (MD_Arena* arena, MD_Rng1S64List* list, Rng1S64 rng) { md_rng1s64_list_push__ainfo (md_arena_allocator(arena), list, rng); }
md_force_inline MD_Rng1S64Array md_rng1s64_array_from_list_push__arena(MD_Arena* arena, MD_Rng1S64List* list) { return md_rng1s64_array_from_list_push__ainfo(md_arena_allocator(arena), list); }
inline void
@@ -989,10 +989,10 @@ md_rng1s64_list_alloc(MD_AllocatorInfo ainfo, MD_Rng1S64List* list, Rng1S64 rng)
inline MD_Rng1S64Array
md_rng1s64_array_from_list_alloc(MD_AllocatorInfo ainfo, MD_Rng1S64List* list) {
MD_Rng1S64Array
arr = {0};
arr.count = list->count;
arr.v = md_alloc_array_no_zero(ainfo, Rng1S64, arr.count);
MD_U64 idx = 0;
arr = {0};
arr.count = list->count;
arr.v = md_alloc_array_no_zero(ainfo, Rng1S64, arr.count);
MD_U64 idx = 0;
for (MD_Rng1S64Node* n = list->first; n != 0; n = n->next) {
arr.v[idx] = n->v;
idx += 1;
+74 -74
View File
@@ -93,16 +93,16 @@
__movsb((unsigned char*)dest, (const unsigned char*)src, count);
return dest;
}
# define md_memory_copy(dst, src, size) memcpy_intrinsic((dst), (src), (size))
# define md_memory_copy(dst, src, size) memcpy_intrinsic((dst), (src), (size))
# else
# define md_memory_copy(dst, src, size) memmove((dst), (src), (size))
# define md_memory_copy(dst, src, size) memmove((dst), (src), (size))
# endif
#endif
#ifndef md_memory_set
# if USE_VENDOR_MEMORY_OPS
# define md_memory_set(dst, byte, size) memset((dst), (byte), (size))
# define md_memory_set(dst, byte, size) memset((dst), (byte), (size))
# else
# define md_memory_set(dst, byte, size) md_mem_set((dst), (byte), (size))
# define md_memory_set(dst, byte, size) md_mem_set((dst), (byte), (size))
# endif
#endif
#ifndef md_memory_compare
@@ -431,25 +431,25 @@ md_dll__insert_npz(
#define md_dll_insert_npz(nil, f, l, p, n, next, prev) md_dll__insert_npz(nil, &f, &f->prev, &l, &l->next, p, &p->next, &p->next->prev, n, &n->prev, &n->next)
#else
// insert next-previous with nil
#define md_dll_insert_npz(nil, f, l, p, n, next, prev) \
#define md_dll_insert_npz(nil, f, l, p, n, next, prev) \
( \
md_check_nil(nil, f) ? ( \
md_check_nil(nil, f) ? ( \
(f) = (l) = (n), \
md_set_nil(nil, (n)->next), \
md_set_nil(nil, (n)->prev) \
md_set_nil(nil, (n)->next), \
md_set_nil(nil, (n)->prev) \
) \
: ( \
md_check_nil(nil, p) ? ( \
md_check_nil(nil, p) ? ( \
(n)->next = (f), \
(f)->prev = (n), \
(f) = (n), \
md_set_nil(nil,(n)->prev) \
md_set_nil(nil,(n)->prev) \
) \
: ((p) == (l)) ? ( \
(l)->next = (n), \
(n)->prev = (l), \
(l) = (n), \
md_set_nil(nil, (n)->next) \
md_set_nil(nil, (n)->next) \
) \
: ( \
( \
@@ -508,27 +508,27 @@ md_dll__remove_npz(
#else
// remove next-previous with nil
#define md_dll_remove_npz(nil, f, l, n, next, prev) \
( \
( \
(n) == (f) ? \
(f) = (n)->next \
: (0) \
), \
( \
(n) == (l) ? \
(l) = (l)->prev \
: (0) \
), \
( \
( \
( \
(n) == (f) ? \
(f) = (n)->next \
: (0) \
), \
( \
(n) == (l) ? \
(l) = (l)->prev \
: (0) \
), \
( \
md_check_nil(nil,(n)->prev) ? \
(0) \
: ((n)->prev->next = (n)->next) \
), \
( \
(0) \
: ((n)->prev->next = (n)->next) \
), \
( \
md_check_nil(nil,(n)->next) ? \
(0) \
: ((n)->next->prev = (n)->prev) \
) \
(0) \
: ((n)->next->prev = (n)->prev) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
@@ -563,16 +563,16 @@ md_sll__queue_push_nz(
#define md_sll_queue_push_nz(nil, f, l, n, next) md_sll__queue_push_nz(nil, &f, &l, &l->next, n, &n->next)
#else
#define md_sll_queue_push_nz(nil, f, l, n, next) \
( \
( \
md_check_nil(nil, f) ? ( \
(f) = (l) = (n), \
(f) = (l) = (n), \
md_set_nil(nil, (n)->next) \
) \
: ( \
(l)->next=(n), \
(l) = (n), \
) \
: ( \
(l)->next=(n), \
(l) = (n), \
md_set_nil(nil,(n)->next) \
) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
@@ -598,15 +598,15 @@ md_sll__queue_push_front_nz(void* nil, void** f, void** l, void* n, void** n_nex
#define md_sll_queue_push_front_nz(nil, f, l, n, next) md_sll__queue_push_front_nz(nil, &f, &l, n, &n->next)
#else
#define md_sll_queue_push_front_nz(nil, f, l, n, next) \
( \
( \
md_check_nil(nil, f) ? ( \
(f) = (l) = (n), \
(f) = (l) = (n), \
md_set_nil(nil,(n)->next) \
) \
: ( \
(n)->next = (f), \
(f) = (n) \
) \
) \
: ( \
(n)->next = (f), \
(f) = (n) \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
@@ -630,14 +630,14 @@ md_sll__queue_pop_nz(void* nil, void** f, void* f_next, void** l)
#define md_sll_queue_pop_nz(nil, f, l, next) md_sll__queue_pop_nz(nil, &f, f->next, &l)
#else
#define md_sll_queue_pop_nz(nil, f, l, next) \
( \
(f) == (l) ? ( \
( \
(f) == (l) ? ( \
md_set_nil(nil,f), \
md_set_nil(nil,l) \
) \
: ( \
(f)=(f)->next \
) \
) \
: ( \
(f)=(f)->next \
) \
)
// ! MD_LINKED_LIST_PURE_MACRO
#endif
@@ -777,7 +777,7 @@ md_sll__queue_pop_nz(void* nil, void** f, void* f_next, void** l)
#endif
#ifndef md_compose_64bit
#define md_compose_64bit(a,b) ((((MD_U64)a) << 32) | ((MD_U64)b));
#define md_compose_64bit(a,b) ((((MD_U64)a) << 32) | ((MD_U64)b));
#endif
#ifndef md_align_pow2
#define md_align_pow2(x,b) (((x) + (b) - 1) & ( ~((b) - 1)))
@@ -910,18 +910,18 @@ md_u64_up_to_pow2(MD_U64 x) {
inline MD_S32
md_extend_sign32(MD_U32 x, MD_U32 size) {
MD_U32 high_bit = size * 8;
MD_U32 shift = 32 - high_bit;
MD_S32 result = ((MD_S32)x << shift) >> shift;
return result;
MD_U32 high_bit = size * 8;
MD_U32 shift = 32 - high_bit;
MD_S32 result = ((MD_S32)x << shift) >> shift;
return result;
}
inline MD_S64
md_extend_sign64(MD_U64 x, MD_U64 size) {
MD_U64 high_bit = size * 8;
MD_U64 shift = 64 - high_bit;
MD_S64 result = ((MD_S64)x << shift) >> shift;
return result;
MD_U64 high_bit = size * 8;
MD_U64 shift = 64 - high_bit;
MD_S64 result = ((MD_S64)x << shift) >> shift;
return result;
}
inline MD_F32 md_inf32 (void) { union { MD_U32 u; MD_F32 f; } x; x.u = MD_EXPONENT32; return(x.f); }
@@ -930,19 +930,19 @@ inline MD_F32 md_neg_inf32(void) { union { MD_U32 u; MD_F32 f; } x; x.u = MD_SIG
inline MD_U16
md_bswap_u16(MD_U16 x)
{
MD_U16 result = (((x & 0xFF00) >> 8) |
((x & 0x00FF) << 8));
return result;
MD_U16 result = (((x & 0xFF00) >> 8) |
((x & 0x00FF) << 8));
return result;
}
inline MD_U32
md_bswap_u32(MD_U32 x)
{
MD_U32 result = (((x & 0xFF000000) >> 24) |
((x & 0x00FF0000) >> 8) |
((x & 0x0000FF00) << 8) |
((x & 0x000000FF) << 24));
return result;
MD_U32 result = (((x & 0xFF000000) >> 24) |
((x & 0x00FF0000) >> 8) |
((x & 0x0000FF00) << 8) |
((x & 0x000000FF) << 24));
return result;
}
inline MD_U64
@@ -950,13 +950,13 @@ md_bswap_u64(MD_U64 x)
{
// TODO(nick): naive bswap, replace with something that is faster like an intrinsic
MD_U64 result = (((x & 0xFF00000000000000ULL) >> 56) |
((x & 0x00FF000000000000ULL) >> 40) |
((x & 0x0000FF0000000000ULL) >> 24) |
((x & 0x000000FF00000000ULL) >> 8) |
((x & 0x00000000FF000000ULL) << 8) |
((x & 0x0000000000FF0000ULL) << 24) |
((x & 0x000000000000FF00ULL) << 40) |
((x & 0x00000000000000FFULL) << 56));
((x & 0x00FF000000000000ULL) >> 40) |
((x & 0x0000FF0000000000ULL) >> 24) |
((x & 0x000000FF00000000ULL) >> 8) |
((x & 0x00000000FF000000ULL) << 8) |
((x & 0x0000000000FF0000ULL) << 24) |
((x & 0x000000000000FF00ULL) << 40) |
((x & 0x00000000000000FFULL) << 56));
return result;
}
+7 -7
View File
@@ -138,7 +138,7 @@ md_heap_allocator_proc( void* allocator_data, MD_AllocatorMode mode, MD_SSIZE si
case MD_AllocatorMode_Resize:
{
MD_AllocatorInfo a = md_heap();
ptr = md_default_resize_align( a, old_memory, old_size, size, alignment );
ptr = md_default_resize_align( a, old_memory, old_size, size, alignment );
}
break;
@@ -267,7 +267,7 @@ md_varena__alloc(MD_VArenaParams params)
MD_SPTR header_size = md_align_pow2(size_of(MD_VArena), MD_DEFAULT_MEMORY_ALIGNMENT);
md_asan_unpoison_memory_region(base, header_size);
MD_VArena* vm = md_rcast(MD_VArena*, base);
MD_VArena* vm = md_rcast(MD_VArena*, base);
vm->reserve_start = md_rcast(MD_SPTR, base) + header_size;
vm->reserve = reserve_size;
vm->commit_size = params.commit_size;
@@ -321,7 +321,7 @@ md_varena_allocator_proc(void* allocator_data, MD_AllocatorMode mode, MD_SSIZE r
}
if (next_commit_size) {
void* next_commit_start = md_rcast(void*, md_rcast(MD_UPTR, vm) + vm->committed);
MD_B32 commit_result = md_os_commit(next_commit_start, next_commit_size);
MD_B32 commit_result = md_os_commit(next_commit_start, next_commit_size);
if (commit_result == false) {
break;
}
@@ -373,7 +373,7 @@ md_varena_allocator_proc(void* allocator_data, MD_AllocatorMode mode, MD_SSIZE r
MD_B32 needs_more_commited = commit_left < size_to_allocate;
if (needs_more_commited)
{
MD_SPTR reserve_left = vm->reserve - vm->committed;
MD_SPTR reserve_left = vm->reserve - vm->committed;
MD_UPTR next_commit_size;
if (vm->flags & MD_VArenaFlag_LargePages) {
next_commit_size = reserve_left > 0 ? vm->commit_size : md_scast(MD_UPTR, md_align_pow2( -reserve_left, md_os_get_system_info()->large_page_size));
@@ -430,7 +430,7 @@ farena_allocator_proc(void* allocator_data, MD_AllocatorMode mode, MD_SSIZE size
}
allocated_mem = md_scast(void*, end);
arena->used += total_size;
arena->used += total_size;
}
break;
@@ -462,8 +462,8 @@ farena_allocator_proc(void* allocator_data, MD_AllocatorMode mode, MD_SSIZE size
MD_B32 requested_shrink = size >= old_size;
if (requested_shrink) {
arena->used -= size;
allocated_mem = old_memory;
arena->used -= size;
allocated_mem = old_memory;
break;
}
+2 -2
View File
@@ -102,14 +102,14 @@ void* md_resize_align( MD_AllocatorInfo a, void* ptr, MD_SSIZE old_size, MD_SSIZ
// Allocate memory for an item.
#define md_alloc_item(allocator, Type) (Type*)md_memory_zero(md_alloc(allocator, size_of(Type)), size_of(Type))
// Allocate memory for an item.
#define md_alloc_item_no_zero( allocator, Type ) (Type*) md_alloc(allocator, size_of(Type))
#define md_alloc_item_no_zero( allocator, Type ) (Type*) md_alloc(allocator, size_of(Type))
#endif
#ifndef md_alloc_array
// Allocate memory for an array of items.
#define md_alloc_array( allocator_, Type, count ) (Type*)md_memory_zero(md_alloc( allocator_, size_of(Type) * (count) ), size_of(Type) * (count))
// Allocate memory for an array of items. (Don't zero initialize)
#define md_alloc_array_no_zero( allocator_, Type, count ) (Type*) md_alloc( allocator_, size_of(Type) * (count) )
#define md_alloc_array_no_zero( allocator_, Type, count ) (Type*) md_alloc( allocator_, size_of(Type) * (count) )
#endif
// Allocate/Resize memory using default options.
+4 -4
View File
@@ -19,12 +19,12 @@ inline MD_U64
md_ring_write(MD_U8* md_ring_base, MD_U64 md_ring_size, MD_U64 md_ring_pos, void* src_data, MD_U64 src_data_size) {
md_assert(src_data_size <= md_ring_size);
{
MD_U64 md_ring_off = md_ring_pos % md_ring_size;
MD_U64 md_ring_off = md_ring_pos % md_ring_size;
MD_U64 bytes_before_split = md_ring_size - md_ring_off;
MD_U64 pre_split_bytes = md_min(bytes_before_split, src_data_size);
MD_U64 pst_split_bytes = src_data_size - pre_split_bytes;
void* pre_split_data = src_data;
void* pst_split_data = ((MD_U8*)src_data + pre_split_bytes);
void* pre_split_data = src_data;
void* pst_split_data = ((MD_U8*)src_data + pre_split_bytes);
md_memory_copy(md_ring_base + md_ring_off, pre_split_data, pre_split_bytes);
md_memory_copy(md_ring_base + 0, pst_split_data, pst_split_bytes);
}
@@ -35,7 +35,7 @@ inline MD_U64
md_ring_read(MD_U8* md_ring_base, MD_U64 md_ring_size, MD_U64 md_ring_pos, void* dst_data, MD_U64 read_size) {
md_assert(read_size <= md_ring_size);
{
MD_U64 md_ring_off = md_ring_pos % md_ring_size;
MD_U64 md_ring_off = md_ring_pos % md_ring_size;
MD_U64 bytes_before_split = md_ring_size-md_ring_off;
MD_U64 pre_split_bytes = md_min(bytes_before_split, read_size);
MD_U64 pst_split_bytes = read_size - pre_split_bytes;
+1 -1
View File
@@ -57,7 +57,7 @@ enum MD_Dir2
MD_Dir2_COUNT
};
#define md_axis2_from_dir2(d) (((d) & 1) ? MD_Axis2_Y : MD_Axis2_X)
#define md_axis2_from_dir2(d) (((d) & 1) ? MD_Axis2_Y : MD_Axis2_X)
#define md_side_from_dir2(d) (((d) < MD_Dir2_Right) ? MD_Side_Min : MD_Side_Max)
////////////////////////////////
+14 -14
View File
@@ -54,7 +54,7 @@ md_str8_find_needle(MD_String8 string, MD_U64 start_pos, MD_String8 needle, MD_S
MD_U8* stop_p = string.str + stop_offset;
if (needle.size > 0)
{
MD_U8* md_string_opl = string.str + string.size;
MD_U8* md_string_opl = string.str + string.size;
MD_String8 needle_tail = md_str8_skip(needle, 1);
MD_StringMatchFlags adjusted_flags = flags | MD_StringMatchFlag_RightSideSloppy;
MD_U8 needle_first_char_adjusted = needle.str[0];
@@ -292,7 +292,7 @@ md_str8_from_u64__ainfo(MD_AllocatorInfo ainfo, MD_U64 u64, MD_U32 radix, MD_U8
needed_digits += 1;
}
}
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
MD_U64 needed_separators = 0;
if (digit_group_separator != 0)
{
@@ -407,10 +407,10 @@ md_f64_from_str8(MD_String8 string)
void
md_str8_list_concat_in_place(MD_String8List* list, MD_String8List* to_push) {
if(to_push->md_node_count != 0)
if(to_push->node_count != 0)
{
if (list->last) {
list->md_node_count += to_push->md_node_count;
list->node_count += to_push->node_count;
list->total_size += to_push->total_size;
list->last->next = to_push->first;
list->last = to_push->last;
@@ -441,7 +441,7 @@ md_str8_list_aligner__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list, MD_U64
md_assert(increase_size <= md_array_count(zeroes_buffer));
md_sll_queue_push(list->first, list->last, node);
list->md_node_count += 1;
list->node_count += 1;
list->total_size = new_size;
node->string.str = (MD_U8*)zeroes_buffer;
node->string.size = increase_size;
@@ -506,8 +506,8 @@ md_str8_list_join__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list, MD_String
md_memory_copy_struct(&join, optional_params);
}
MD_U64 sep_count = 0;
if (list->md_node_count > 0){
sep_count = list->md_node_count - 1;
if (list->node_count > 0){
sep_count = list->node_count - 1;
}
MD_String8 result;
@@ -1079,7 +1079,7 @@ md_try_guid_from_string(MD_String8 string, MD_Guid* md_guid_out)
MD_B32 is_parsed = 0;
MD_String8List list = md_str8_split_by_string_chars(scratch.arena, string, md_str8_lit("-"), MD_StringSplitFlag_KeepEmpties);
if(list.md_node_count == 5)
if(list.node_count == 5)
{
MD_String8 data1_str = list.first->string;
MD_String8 data2_str = list.first->next->string;
@@ -1294,7 +1294,7 @@ md_wrapped_lines_from_string__ainfo(MD_AllocatorInfo ainfo, MD_String8 string, M
MD_String8 substr = md_str8_substr(string, candidate_line_range);
MD_U64 width_this_line = max_width-wrapped_indent_level;
if (list.md_node_count == 0) {
if (list.node_count == 0) {
width_this_line = first_line_max_width;
}
if (substr.size > width_this_line)
@@ -1355,7 +1355,7 @@ md_fuzzy_match_find__ainfo(MD_AllocatorInfo ainfo, MD_String8 needle, MD_String8
MD_String8List needles = md_str8_split(scratch.arena, needle, (MD_U8*)" ", 1, 0);
MD_FuzzyMatchRangeList
result = {0};
result.needle_part_count = needles.md_node_count;
result.needle_part_count = needles.node_count;
for(MD_String8Node* needle_n = needles.first; needle_n != 0; needle_n = needle_n->next)
{
MD_U64 find_pos = 0;
@@ -1511,10 +1511,10 @@ MD_U64
md_str8_deserial_read_cstr(MD_String8 string, MD_U64 off, MD_String8* cstr_out) {
MD_U64 cstr_size = 0;
if (off < string.size) {
MD_U8* ptr = string.str + off;
MD_U8* cap = string.str + string.size;
*cstr_out = md_str8_cstring_capped(ptr, cap);
cstr_size = (cstr_out->size + 1);
MD_U8* ptr = string.str + off;
MD_U8* cap = string.str + string.size;
*cstr_out = md_str8_cstring_capped(ptr, cap);
cstr_size = (cstr_out->size + 1);
}
return cstr_size;
}
+1 -1
View File
@@ -66,7 +66,7 @@ struct MD_String8List
{
MD_String8Node* first;
MD_String8Node* last;
MD_U64 md_node_count;
MD_U64 node_count;
MD_U64 total_size;
};